From patchwork Sat Jul 6 23:55:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cade Richard X-Patchwork-Id: 1957643 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=EEBdI1QP; 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=MeT0aVXI; 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 4WGnMZ2TKZz1xrJ for ; Sun, 7 Jul 2024 09:55:54 +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=UE7YLkXzoFCMexMk9iEq9tpPAo1+1zfDW0whDThwc2k=; b=EEBdI1QPA3tDi6 EGCiwlay2uB//7kTG0mkSGkUbYWKIvYrOewdce1wudYR3paXjo5o84vwup2k8CBFtEcdVtC0gIYqp zWQKsw8cl0q18zlR3A1uaVSVv6ntsw4ZZhsvS7lshH7xJWJsTj2nx530HxjpBIO0iZCej4oLeWpVQ 4STDpsjJWRsBnyfNhzJP/0UG0iPcGtxNbTdYfDeV3Wftk3qtxO74y4gKFle9zKxRc5CAPTqq8vvzi h55FsX+ppziRbN6LgHzlA2zMpC8qFt1W9yMGHMq8WEBL+p91GTnLVdITbPzwpRqWpiiRaxPguTH2f aDtXBinP6G2hd8+S6HvA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sQFFw-000000015iG-36iB; Sat, 06 Jul 2024 23:55:52 +0000 Received: from mail-il1-x132.google.com ([2607:f8b0:4864:20::132]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sQFFu-000000015hX-1rHt for kvm-riscv@lists.infradead.org; Sat, 06 Jul 2024 23:55:52 +0000 Received: by mail-il1-x132.google.com with SMTP id e9e14a558f8ab-376012bcc33so10246715ab.2 for ; Sat, 06 Jul 2024 16:55:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720310147; x=1720914947; 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=sFlf0L5XX0a9h/dBp7DCCe84ms07x6tR5xCf+BcEWz4=; b=MeT0aVXIFkiU4HBqoAxibjxF7HwRdFVoenkqRqLkUB02C79Rh04VEiHsAmdDrYP0AE 4sZMHGupRx9Vgc5cVEuR04G5nVnf4ZkrKG8VcPQUx1ZqyubpvT+Re+gLz/1ezaKgNccU KhVLYcyLo8J9yNx36EidZHwOM9JCkMlkgkYMmu5YZB6QPey0CSTpnETgjS0uQjEMzuDd ULeUKydycMebR3D9bWxrMY4KDB2R2LvmJD8WV+3OEjNnp0Yp1JJvkBuSdjO750WXuIma nfknemiAk5uXideqveSqyTdHYl6wp0eH5QHTe/2fUMNTnHfqaJoiMqUhirk9FP7fgI0c r8cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720310147; x=1720914947; 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=sFlf0L5XX0a9h/dBp7DCCe84ms07x6tR5xCf+BcEWz4=; b=jr/D+lroIin9fZULfVAtWC7FuQbygh7EwtUa1LDsAT3i12bwB8SppNMHk+5eLmelIV kr1QO4akS2SGnaEetPsWlP8B9EU1oD3hWXAHRudyzwfoBZlOFC9dn5UsxjaVosbxLM75 NxpZY4YF8yBb9y9xI6YhasgmywEtNiMWhulFJF4Ie8EOdx5wjnkSO65a1f9iyFjhdvz4 AupypdeQK9swV69qHdjbr7821GY6js6EL0FVmfzLgHT5HROgABQU5HkdBArHwTwGP/so FqK+vxuppD0WQkT1GjMK5gWVM1yE3FbfPGMIh4lInI8BcU5eeBTdKL8wvMOyv9N7oqTF NazQ== X-Forwarded-Encrypted: i=1; AJvYcCVEdYDSxHJ88OI13x4v8b9FeSZNjMrY+7rGFaudMaSKdziV7RVn6SiaErNdwXdFMMtCh1d9rAi/xCvcFX+bAMD+zh6Oy3578fYfBOUr5A== X-Gm-Message-State: AOJu0YxLvtPuCP2kW4GD9AmapSJvZQheyBgKBRleFsA4LziGFewwjEiQ t9bRhNcbBFucutngNET09ADnsIb7Pl0c5m09+KHWRNhwD7+v9yXd X-Google-Smtp-Source: AGHT+IHiaX5QJ9J//GYKvGwR9qyvXoCAdoDj2aGpqvxjLw105fRjf1N532bcU4lO6i3I+pyjTJfRMw== X-Received: by 2002:a05:6e02:144f:b0:375:be9e:34c3 with SMTP id e9e14a558f8ab-38398710698mr122037125ab.12.1720310147632; Sat, 06 Jul 2024 16:55:47 -0700 (PDT) Received: from [127.0.1.1] (23-93-181-73.fiber.dynamic.sonic.net. [23.93.181.73]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fb2523f6fbsm62715065ad.181.2024.07.06.16.55.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jul 2024 16:55:47 -0700 (PDT) From: Cade Richard X-Google-Original-From: Cade Richard Date: Sat, 06 Jul 2024 16:55:46 -0700 Subject: [PATCH kvm-unit-tests v2] riscv: sbi: debug console write tests MIME-Version: 1.0 Message-Id: <20240706-sbi-dbcn-write-tests-v2-1-a5dc6a749f4a@berkeley.edu> X-B4-Tracking: v=1; b=H4sIAIHZiWYC/4WNTQ6CMBBGr0Jm7Rha+asr72FYWDrIRAOkU6uEc HcrF3D5XvK9bwUhzyRwzlbwFFl4GhPoQwbdcBvvhOwSg851kdd5hWIZne1GfHsOhIEkCBZaN6Z XJ6PIQZrOnnr+7Nlrm3hgCZNf9peofvZPMCpUaOuyoFJVxvTNxZJ/0JOWI7kXtNu2fQEHBFh1u wAAAA== 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-20240706_165550_526520_3D74021B X-CRM114-Status: GOOD ( 11.20 ) X-Spam-Score: -0.2 (/) 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: --- Signed-off-by: Cade Richard --- Changes in v2: - Added prefix pop to exit dbcn tests - Link to v1: --- lib/riscv/asm/sbi.h | 7 +++++++ riscv/sbi.c | 60 ++++++++++++++++++++++++++++++++++++++++ [...] Content analysis details: (-0.2 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:132 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches 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 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 --- Signed-off-by: Cade Richard --- Changes in v2: - Added prefix pop to exit dbcn tests - Link to v1: https://lore.kernel.org/r/20240706-sbi-dbcn-write-tests-v1-1-b754e51699f8@berkeley.edu --- lib/riscv/asm/sbi.h | 7 +++++++ riscv/sbi.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) --- base-commit: 40e1fd76ffc80b1d43214e31a023aaf087ece987 change-id: 20240706-sbi-dbcn-write-tests-42289f1391ed Best regards, diff --git a/lib/riscv/asm/sbi.h b/lib/riscv/asm/sbi.h index d82a384d..c5fa84ae 100644 --- a/lib/riscv/asm/sbi.h +++ b/lib/riscv/asm/sbi.h @@ -18,6 +18,7 @@ enum sbi_ext_id { SBI_EXT_BASE = 0x10, SBI_EXT_HSM = 0x48534d, SBI_EXT_SRST = 0x53525354, + SBI_EXT_DBCN = 0x4442434E, }; enum sbi_ext_base_fid { @@ -37,6 +38,12 @@ enum sbi_ext_hsm_fid { SBI_EXT_HSM_HART_SUSPEND, }; +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 762e9711..18646842 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -7,6 +7,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) { @@ -19,6 +23,11 @@ static struct sbiret __base_sbi_ecall(int fid, unsigned long arg0) return sbi_ecall(SBI_EXT_BASE, fid, arg0, 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)) { @@ -112,6 +121,56 @@ static void check_base(void) report_prefix_pop(); } +static void check_dbcn(void) +{ + + struct sbiret ret; + unsigned long num_bytes, base_addr_lo, base_addr_hi; + + 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"); + + num_bytes = strlen(DBCN_WRITE_TEST_STRING); + base_addr_hi = 0x0; + base_addr_lo = virt_to_phys((void *) &DBCN_WRITE_TEST_STRING); + + 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; + } while (num_bytes != 0 && ret.error == SBI_SUCCESS) ; + report(SBI_SUCCESS == ret.error, "write success"); + report(ret.value == num_bytes, "correct number of bytes written"); + + // Bytes are read from memory and written to the console + if (env_or_skip("INVALID_READ_ADDR")) { + base_addr_lo = strtol(getenv("INVALID_READ_ADDR"), NULL, 0); + ret = __dbcn_sbi_ecall(SBI_EXT_DBCN_CONSOLE_WRITE, num_bytes, 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(); + report_prefix_pop(); +} + int main(int argc, char **argv) { @@ -122,6 +181,7 @@ int main(int argc, char **argv) report_prefix_push("sbi"); check_base(); + check_dbcn(); return report_summary(); }