All of lore.kernel.org
 help / color / mirror / Atom feed
From: Akshay Behl <akshaybehl231@gmail.com>
To: kvm@vger.kernel.org
Cc: andrew.jones@linux.dev, cleger@rivosinc.com, atishp@rivosinc.com,
	Akshay Behl <akshaybehl231@gmail.com>
Subject: [RFC kvm-unit-tests PATCH] riscv: Refactoring sbi fwft tests
Date: Thu, 13 Mar 2025 13:28:45 +0530	[thread overview]
Message-ID: <20250313075845.411130-1-akshaybehl231@gmail.com> (raw)

This patch refactors the current sbi fwft tests
(pte_ad_hw_updating, misaligned_exc_deleg)

Signed-off-by: Akshay Behl <akshaybehl231@gmail.com>
---
 riscv/sbi-fwft.c | 58 +++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 45 insertions(+), 13 deletions(-)

diff --git a/riscv/sbi-fwft.c b/riscv/sbi-fwft.c
index ac2e3486..bf735f62 100644
--- a/riscv/sbi-fwft.c
+++ b/riscv/sbi-fwft.c
@@ -19,6 +19,15 @@
 
 void check_fwft(void);
 
+static bool env_or_skip(const char *env)
+{
+	if (!getenv(env)) {
+		report_skip("missing %s environment variable", env);
+		return false;
+	}
+
+	return true;
+}
 
 static struct sbiret fwft_set_raw(unsigned long feature, unsigned long value, unsigned long flags)
 {
@@ -66,6 +75,13 @@ static void fwft_check_reserved(unsigned long id)
 	sbiret_report_error(&ret, SBI_ERR_DENIED, "set reserved feature 0x%lx", id);
 }
 
+static void fwft_check_reset(uint32_t feature, unsigned long reset)
+{
+	struct sbiret ret = fwft_get(feature);
+
+	sbiret_report(&ret, SBI_SUCCESS, reset, "resets to %lu", reset);
+}
+
 static void fwft_check_base(void)
 {
 	report_prefix_push("base");
@@ -99,18 +115,32 @@ static struct sbiret fwft_misaligned_exc_get(void)
 static void fwft_check_misaligned_exc_deleg(void)
 {
 	struct sbiret ret;
+	unsigned long expected;
 
 	report_prefix_push("misaligned_exc_deleg");
 
 	ret = fwft_misaligned_exc_get();
-	if (ret.error == SBI_ERR_NOT_SUPPORTED) {
-		report_skip("SBI_FWFT_MISALIGNED_EXC_DELEG is not supported");
+	if (ret.error != SBI_SUCCESS) {
+		if (env_or_skip("SBI_HAVE_FWFT_MISALIGNED_EXC_DELEG")) {
+			expected = (unsigned long)strtoul(getenv("SBI_HAVE_FWFT_MISALIGNED_EXC_DELEG"), NULL, 0);
+			if (expected == 1)
+			{
+				report_fail("not supported by platform");
+				return;
+			}
+		}
+		report_skip("not supported by platform");
 		return;
 	}
 
 	if (!sbiret_report_error(&ret, SBI_SUCCESS, "Get misaligned deleg feature"))
 		return;
 
+	if (env_or_skip("MISALIGNED_EXC_DELEG_RESET")) {
+		expected = (unsigned long)strtoul(getenv("MISALIGNED_EXC_DELEG_RESET"), NULL, 0);
+		fwft_check_reset(SBI_FWFT_MISALIGNED_EXC_DELEG, expected);
+	}
+
 	ret = fwft_misaligned_exc_set(2, 0);
 	sbiret_report_error(&ret, SBI_ERR_INVALID_PARAM,
 			    "Set misaligned deleg feature invalid value 2");
@@ -129,16 +159,10 @@ static void fwft_check_misaligned_exc_deleg(void)
 #endif
 
 	/* Set to 0 and check after with get */
-	ret = fwft_misaligned_exc_set(0, 0);
-	sbiret_report_error(&ret, SBI_SUCCESS, "Set misaligned deleg feature value 0");
-	ret = fwft_misaligned_exc_get();
-	sbiret_report(&ret, SBI_SUCCESS, 0, "Get misaligned deleg feature expected value 0");
+	fwft_set_and_check_raw("", SBI_FWFT_MISALIGNED_EXC_DELEG, 0, 0);
 
 	/* Set to 1 and check after with get */
-	ret = fwft_misaligned_exc_set(1, 0);
-	sbiret_report_error(&ret, SBI_SUCCESS, "Set misaligned deleg feature value 1");
-	ret = fwft_misaligned_exc_get();
-	sbiret_report(&ret, SBI_SUCCESS, 1, "Get misaligned deleg feature expected value 1");
+	fwft_set_and_check_raw("", SBI_FWFT_MISALIGNED_EXC_DELEG, 1, 0);
 
 	install_exception_handler(EXC_LOAD_MISALIGNED, misaligned_handler);
 
@@ -257,11 +281,20 @@ static void fwft_check_pte_ad_hw_updating(void)
 {
 	struct sbiret ret;
 	bool enabled;
+	unsigned long expected;
 
 	report_prefix_push("pte_ad_hw_updating");
 
 	ret = fwft_get(SBI_FWFT_PTE_AD_HW_UPDATING);
-	if (ret.error == SBI_ERR_NOT_SUPPORTED) {
+	if (ret.error != SBI_SUCCESS) {
+		if (env_or_skip("SBI_HAVE_FWFT_PTE_AD_HW_UPDATING")) {
+			expected = (unsigned long)strtoul(getenv("SBI_HAVE_FWFT_PTE_AD_HW_UPDATING"), NULL, 0);
+			if (expected == 1)
+			{
+				report_fail("not supported by platform");
+				return;
+			}
+		}
 		report_skip("not supported by platform");
 		return;
 	} else if (!sbiret_report_error(&ret, SBI_SUCCESS, "get")) {
@@ -269,10 +302,9 @@ static void fwft_check_pte_ad_hw_updating(void)
 		return;
 	}
 
-	report(ret.value == 0 || ret.value == 1, "first get value is 0/1");
+	fwft_check_reset(SBI_FWFT_PTE_AD_HW_UPDATING, 1);
 
 	enabled = ret.value;
-	report_kfail(true, !enabled, "resets to 0");
 
 	install_exception_handler(EXC_LOAD_PAGE_FAULT, adue_read_handler);
 	install_exception_handler(EXC_STORE_PAGE_FAULT, adue_write_handler);
-- 
2.34.1


             reply	other threads:[~2025-03-13  7:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-13  7:58 Akshay Behl [this message]
2025-03-13  9:07 ` [RFC kvm-unit-tests PATCH] riscv: Refactoring sbi fwft tests Andrew Jones
2025-03-13 17:12 ` [RFC kvm-unit-tests PATCH v2] " Akshay Behl
2025-03-14 12:57   ` Andrew Jones
2025-03-14 13:06     ` Andrew Jones
2025-03-22 10:48   ` Andrew Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250313075845.411130-1-akshaybehl231@gmail.com \
    --to=akshaybehl231@gmail.com \
    --cc=andrew.jones@linux.dev \
    --cc=atishp@rivosinc.com \
    --cc=cleger@rivosinc.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.