From patchwork Wed Aug 7 05:51:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cade Richard X-Patchwork-Id: 1969784 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=xKhMM+yx; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=BVBELSRK; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WdzpG6T0Rz1yfC for ; Wed, 7 Aug 2024 15:52:04 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Message-Id:MIME-Version:Subject: Date:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=uUxFFOD1wXhVAcVsRuOg93U6aUvueKPbRoRdJoTfrMs=; b=xKhMM+yxfIPdXR LkQYbPXMKP6kOQq8qEJkA6HbXbAyAZ3e+wASvkRqP2r3Sn1X1Vya1FQcL5NMATYjlAq5/pZrUgns8 Wfu3OGDf0GOAmYcQJSB+uwUzDUlycxO14VZbzK2j3alX/LrO8qlZ0g+wdzmlt35+4lveUpq0snU5H rGw9/LuPwkd66RdlSAYeYtayAl23Hyp1d2Kl1uPb8WbXzdbUFvsPrX1DIjv3BvrGBOkM9oOe91qQF dhwSmKiSLF7XoTgyJUVZdZn5yvidXKtXZiMAxNx+3lsdhqlbZzvVudNE6K/UoYD+GDp5Q5r/AAQ3y KP8GanBeaFlNC3NKU6bA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbZab-00000003vag-3JTg; Wed, 07 Aug 2024 05:52:01 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbZaZ-00000003vZi-0T71 for kvm-riscv@lists.infradead.org; Wed, 07 Aug 2024 05:52:00 +0000 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1fda7fa60a9so12368325ad.3 for ; Tue, 06 Aug 2024 22:51:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723009917; x=1723614717; darn=lists.infradead.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=1/Oho0iTqPPJRoT61a5Yt6PpA0jED4M0jYCoDmrS4rI=; b=BVBELSRKLU9xKFKyhNpDyfnkoF3M6duxTbwcB7lt3AbgGWj5qwlrsJvn1lL0vGz1YY NYfsNPuK6oJCQMCk2DZYJH9Cv6hK+NcBvjDLBNtx3I+cw/arCVgghrSl3v53BukDojUR OUdGhEsdog3ytbq+hSV09tAQZhdTbmetxJfAxYhjRXyXO0BfA1A0YUNGQCSQayVoTV8A 1ZJTFRIhC3LfECzz8mjMVOMx5O31rRVKr/AyGgS5dsu2AiTCCald5oPlYzyc+N16MaUH qiu+uJSa8uE6agmDNnmuMem+w2hTcE6IQ8cy4ENMNHaukmDyb1MrlRkgQ5TUd9L/7eyB nrjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723009917; x=1723614717; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1/Oho0iTqPPJRoT61a5Yt6PpA0jED4M0jYCoDmrS4rI=; b=mitOfmuqeYuqzc56kHGRoT+cXyiyr6/yxCZOtV1zyaw6KSIDsrwsj0vA3IBYzu6rjA XJc4mt3lx73Cqrhd2wJ6RN4HBMrJTQnZ1OvCgk8KTJDlNbFI4dRlrCSf8opd6MwhBBRD f0IT/6fvoXO10hGAX5tDrNzPG+STMZhyodDNLzLKWi1TSTslgoC3NmyPpfEwsrAtr+oC BkVZYchQrKOhS2tfnkfp2tn14/eggtOXSNxgDV2DDV3ZEumKOo9E9QCGcdaYLrmGWMiG KAWg6r9T1CH+SDzHDR7GOK+EA3uWyUmFaY+4TOxN8+nDajv/nKYE1yy3bI37lph/SnBL mBIw== X-Forwarded-Encrypted: i=1; AJvYcCVEWY7L9p6cOwEFE3I0+1Xynrp+1usmcQHH5VRL1guljX0COAEIle7ALqTpnkMfGW7MTkJuAcxkbey207rdftNIpUGEknBww190S+/7cA== X-Gm-Message-State: AOJu0Yz6ipljHrWod1hc1NRpHHNIDydF3gi3hDvrhgQjpEpcT6YW99bu bL3UCBcp8BkLpy6Srg9jjl4BnZ86DnekGjYSlgZtDotTrEc/Ysa+jrhLuaMd X-Google-Smtp-Source: AGHT+IGS9uK48cOCO7ThOVtSIe/ls4yatHBhz3+Hqj6W7TxDPzsa1CtoE7PIs7OTraZURH0RsAU2dg== X-Received: by 2002:a17:903:230f:b0:1fd:6766:6877 with SMTP id d9443c01a7336-1ff57254180mr235158635ad.2.1723009917122; Tue, 06 Aug 2024 22:51:57 -0700 (PDT) Received: from [127.0.1.1] (c-73-185-75-144.hsd1.ca.comcast.net. [73.185.75.144]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff58f5a47esm97155345ad.110.2024.08.06.22.51.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 22:51:56 -0700 (PDT) From: Cade Richard X-Google-Original-From: Cade Richard Date: Tue, 06 Aug 2024 22:51:54 -0700 Subject: [PATCH kvm-unit-tests] riscv: sbi: add dbcn write test MIME-Version: 1.0 Message-Id: <20240806-sbi-dbcn-write-test-v1-1-7f198bb55525@berkeley.edu> X-B4-Tracking: v=1; b=H4sIAHkLs2YC/x3MPQqAMAxA4atIZgOp/3gVcdA2apYqTVFBvLvF8 Rvee0A5CCv02QOBT1HZfYLJM7Db5FdGcclQUFFRRw3qLOhm6/EKEhkja8SWXEm1q42xC6TyCLz I/V+H8X0/uERI5mUAAAA= To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: andrew.jones@linux.dev, atishp@rivosinc.com, cade.richard@berkeley.edu, jamestiotio@gmail.com X-Mailer: b4 0.13.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_225159_197915_FCEB3B99 X-CRM114-Status: GOOD ( 13.21 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: --- Added a unit test for the RISC-V SBI debug console write() and write_byte() functions. The output of the tests must be inspected manually to verify that the correct bytes are written. For write(), [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:630 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [cade.richard(at)gmail.com] X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org --- Added a unit test for the RISC-V SBI debug console write() and write_byte() functions. The output of the tests must be inspected manually to verify that the correct bytes are written. For write(), the expected output is 'DBCN_WRITE_TEST_STRING'. For write_byte(), the expected output is 'a'. Signed-off-by: Cade Richard --- lib/riscv/asm/sbi.h | 7 ++++++ riscv/sbi.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) --- base-commit: 1878b4b663fd50b87de7ba2b1c90614e2703542f change-id: 20240806-sbi-dbcn-write-test-70d305d511cf Best regards, diff --git a/lib/riscv/asm/sbi.h b/lib/riscv/asm/sbi.h index 73ab5438..47e91025 100644 --- a/lib/riscv/asm/sbi.h +++ b/lib/riscv/asm/sbi.h @@ -19,6 +19,7 @@ enum sbi_ext_id { SBI_EXT_TIME = 0x54494d45, SBI_EXT_HSM = 0x48534d, SBI_EXT_SRST = 0x53525354, + SBI_EXT_DBCN = 0x4442434E, }; enum sbi_ext_base_fid { @@ -42,6 +43,12 @@ enum sbi_ext_time_fid { SBI_EXT_TIME_SET_TIMER = 0, }; +enum sbi_ext_dbcn_fid { + SBI_EXT_DBCN_CONSOLE_WRITE = 0, + SBI_EXT_DBCN_CONSOLE_READ, + SBI_EXT_DBCN_CONSOLE_WRITE_BYTE, +}; + struct sbiret { long error; long value; diff --git a/riscv/sbi.c b/riscv/sbi.c index 2438c497..61993f08 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -15,6 +15,10 @@ #include #include #include +#include + +#define DBCN_WRITE_TEST_STRING "DBCN_WRITE_TEST_STRING\n" +#define DBCN_WRITE_BYTE_TEST_BYTE (u8)'a' static void help(void) { @@ -32,6 +36,11 @@ static struct sbiret __time_sbi_ecall(unsigned long stime_value) return sbi_ecall(SBI_EXT_TIME, SBI_EXT_TIME_SET_TIMER, stime_value, 0, 0, 0, 0, 0); } +static struct sbiret __dbcn_sbi_ecall(int fid, unsigned long arg0, unsigned long arg1, unsigned long arg2) +{ + return sbi_ecall(SBI_EXT_DBCN, fid, arg0, arg1, arg2, 0, 0, 0); +} + static bool env_or_skip(const char *env) { if (!getenv(env)) { @@ -248,6 +257,62 @@ static void check_time(void) report_prefix_pop(); } +static void check_dbcn(void) +{ + + struct sbiret ret; + unsigned long num_bytes, base_addr_lo, base_addr_hi; + int num_calls = 0; + + num_bytes = strlen(DBCN_WRITE_TEST_STRING); + phys_addr_t p = virt_to_phys((void *)&DBCN_WRITE_TEST_STRING); + base_addr_lo = (unsigned long)p; + base_addr_hi = (unsigned long)(p >> __riscv_xlen); + + report_prefix_push("dbcn"); + + ret = __base_sbi_ecall(SBI_EXT_BASE_PROBE_EXT, SBI_EXT_DBCN); + if (!ret.value) { + report_skip("DBCN extension unavailable"); + report_prefix_pop(); + return; + } + + report_prefix_push("write"); + + do { + ret = __dbcn_sbi_ecall(SBI_EXT_DBCN_CONSOLE_WRITE, num_bytes, base_addr_lo, base_addr_hi); + num_bytes -= ret.value; + base_addr_lo += ret.value; + num_calls++; + } while (num_bytes != 0 && ret.error == SBI_SUCCESS) ; + report(ret.error == SBI_SUCCESS, "write success"); + report_info("%d sbi calls made", num_calls); + + /* + Bytes are read from memory and written to the console + */ + if (env_or_skip("INVALID_READ_ADDR")) { + phys_addr_t p = strtoull(getenv("INVALID_READ_ADDR"), NULL, 0); + base_addr_lo = (unsigned long)p; + base_addr_hi = (unsigned long)(p >> __riscv_xlen); + ret = __dbcn_sbi_ecall(SBI_EXT_DBCN_CONSOLE_WRITE, 1, base_addr_lo, base_addr_hi); + report(ret.error == SBI_ERR_INVALID_PARAM, "invalid parameter: address"); + }; + + report_prefix_pop(); + + report_prefix_push("write_byte"); + + puts("DBCN_WRITE TEST CHAR: "); + ret = __dbcn_sbi_ecall(SBI_EXT_DBCN_CONSOLE_WRITE_BYTE, (u8)DBCN_WRITE_BYTE_TEST_BYTE, 0, 0); + puts("\n"); + report(ret.error == SBI_SUCCESS, "write success"); + report(ret.value == 0, "expected ret.value"); + + report_prefix_pop(); +} + int main(int argc, char **argv) { @@ -259,6 +324,7 @@ int main(int argc, char **argv) report_prefix_push("sbi"); check_base(); check_time(); + check_dbcn(); return report_summary(); }