Skip to contentSkip to conversation

riscv: Refactor SBI FWFT lock tests

PATCH Superseded Akshay Behl 2 participants 2 messages Mar 18, 2025 – Mar 19, 2025

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 riscv: Refactor SBI FWFT lock tests

This patch adds a generic function for lock tests for all the sbi fwft features. It expects the feature is already locked before being called and tests the locked feature.

---
v2:
- Made changes to handel non boolean feature tests.

 riscv/sbi-fwft.c | 49 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 33 insertions(+), 16 deletions(-)
riscv/sbi-fwft.c +33 -16
index 581cbf6b..7d9735d7 100644
@@ -74,6 +74,34 @@ static void fwft_check_reset(uint32_t feature, unsigned long reset)
 	sbiret_report(&ret, SBI_SUCCESS, reset, "resets to %lu", reset);
 }
 
+/* Must be called after locking the feature using SBI_FWFT_SET_FLAG_LOCK */
+static void fwft_feature_lock_test_values(uint32_t feature, size_t nr_values,
+										unsigned long test_values[], unsigned long locked_value)
+{
+	struct sbiret ret;
+
+	for (int i = 0; i < nr_values; ++i) {
+		ret = fwft_set(feature, test_values[i], 0);
+		sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED,
+			"Set locked feature to %lu without lock", test_values[i]);
+
+		ret = fwft_set(feature, test_values[i], SBI_FWFT_SET_FLAG_LOCK);
+		sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED,
+			"Set locked feature to %lu with lock", test_values[i]);
+	}
+
+	ret = fwft_get(feature);
+	sbiret_report(&ret, SBI_SUCCESS, locked_value,
+		"Get locked feature value %lu", locked_value);
+}
+
+static void fwft_feature_lock_test(uint32_t feature, unsigned long locked_value)
+{
+	unsigned long values[] = {0, 1};
+
+	fwft_feature_lock_test_values(feature, 2 , values, locked_value);
+}
+
 static void fwft_check_base(void)
 {
 	report_prefix_push("base");
@@ -181,11 +209,9 @@ static void fwft_check_misaligned_exc_deleg(void)
 	/* Lock the feature */
 	ret = fwft_misaligned_exc_set(0, SBI_FWFT_SET_FLAG_LOCK);
 	sbiret_report_error(&ret, SBI_SUCCESS, "Set misaligned deleg feature value 0 and lock");
-	ret = fwft_misaligned_exc_set(1, 0);
-	sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED,
-			    "Set locked misaligned deleg feature to new value");
-	ret = fwft_misaligned_exc_get();
-	sbiret_report(&ret, SBI_SUCCESS, 0, "Get misaligned deleg locked value 0");
+
+	/* Test feature lock */
+	fwft_feature_lock_test(SBI_FWFT_MISALIGNED_EXC_DELEG, 0);
 
 	report_prefix_pop();
 }
@@ -326,17 +352,8 @@ adue_inval_tests:
 	else
 		enabled = !enabled;
 
-	ret = fwft_set(SBI_FWFT_PTE_AD_HW_UPDATING, !enabled, 0);
-	sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED, "set locked to %d without lock", !enabled);
-
-	ret = fwft_set(SBI_FWFT_PTE_AD_HW_UPDATING, !enabled, 1);
-	sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED, "set locked to %d with lock", !enabled);
-
-	ret = fwft_set(SBI_FWFT_PTE_AD_HW_UPDATING, enabled, 0);
-	sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED, "set locked to %d without lock", enabled);
-
-	ret = fwft_set(SBI_FWFT_PTE_AD_HW_UPDATING, enabled, 1);
-	sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED, "set locked to %d with lock", enabled);
+	/* Test the feature lock */
+	fwft_feature_lock_test(SBI_FWFT_PTE_AD_HW_UPDATING, enabled);
 
 adue_done:
 	install_exception_handler(EXC_LOAD_PAGE_FAULT, NULL);
Signature · 1 line
2.34.1
#1 lore raw
Quoted 16 lines · Akshay Behl

This patch adds a generic function for lock tests for all the sbi fwft features. It expects the feature is already locked before being called and tests the locked feature.

---
v2:
- Made changes to handel non boolean feature tests.

 riscv/sbi-fwft.c | 49 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 33 insertions(+), 16 deletions(-)
riscv/sbi-fwft.c +0 -0
index 581cbf6b..7d9735d7 100644

riscv/sbi-fwft.c static void fwft_check_reset(uint32_t feature, unsigned long reset) · line 79

Quoted 6 lines
riscv/sbi-fwft.c +3 -0
@@ -74,6 +74,34 @@ static void fwft_check_reset(uint32_t feature, unsigned long reset)
 	sbiret_report(&ret, SBI_SUCCESS, reset, "resets to %lu", reset);
 }
 
+/* Must be called after locking the feature using SBI_FWFT_SET_FLAG_LOCK */
+static void fwft_feature_lock_test_values(uint32_t feature, size_t nr_values,
+										unsigned long test_values[], unsigned long locked_value)

What happened to the indentation here? Please proofread your patches.

riscv/sbi-fwft.c static void fwft_check_reset(uint32_t feature, unsigned long reset) · line 81

Quoted 2 lines
riscv/sbi-fwft.c +2 -0
+{
+	struct sbiret ret;

We could push a "locked" prefix here and then...

riscv/sbi-fwft.c static void fwft_check_reset(uint32_t feature, unsigned long reset) · line 86

Quoted 5 lines
riscv/sbi-fwft.c +5 -0
+
+	for (int i = 0; i < nr_values; ++i) {
+		ret = fwft_set(feature, test_values[i], 0);
+		sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED,
+			"Set locked feature to %lu without lock", test_values[i]);

^ flag

riscv/sbi-fwft.c static void fwft_check_reset(uint32_t feature, unsigned long reset) · line 90

Quoted 4 lines
riscv/sbi-fwft.c +4 -0
+
+		ret = fwft_set(feature, test_values[i], SBI_FWFT_SET_FLAG_LOCK);
+		sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED,
+			"Set locked feature to %lu with lock", test_values[i]);

^ flag

riscv/sbi-fwft.c static void fwft_check_reset(uint32_t feature, unsigned long reset) · line 95

Quoted 5 lines
riscv/sbi-fwft.c +5 -0
+	}
+
+	ret = fwft_get(feature);
+	sbiret_report(&ret, SBI_SUCCESS, locked_value,
+		"Get locked feature value %lu", locked_value);

...drop 'locked feature' from all the reports above.

Then pop the prefix here.

riscv/sbi-fwft.c static void fwft_check_reset(uint32_t feature, unsigned long reset) · line 102

Quoted 7 lines
riscv/sbi-fwft.c +7 -0
+}
+
+static void fwft_feature_lock_test(uint32_t feature, unsigned long locked_value)
+{
+	unsigned long values[] = {0, 1};
+
+	fwft_feature_lock_test_values(feature, 2 , values, locked_value);

^ extra space

Quoted 6 lines
riscv/sbi-fwft.c +2 -0
+}
+
 static void fwft_check_base(void)
 {
 	report_prefix_push("base");

riscv/sbi-fwft.c static void fwft_check_misaligned_exc_deleg(void) · line 213

Quoted 10 lines
riscv/sbi-fwft.c +2 -5
@@ -181,11 +209,9 @@ static void fwft_check_misaligned_exc_deleg(void)
 	/* Lock the feature */
 	ret = fwft_misaligned_exc_set(0, SBI_FWFT_SET_FLAG_LOCK);
 	sbiret_report_error(&ret, SBI_SUCCESS, "Set misaligned deleg feature value 0 and lock");
-	ret = fwft_misaligned_exc_set(1, 0);
-	sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED,
-			    "Set locked misaligned deleg feature to new value");
-	ret = fwft_misaligned_exc_get();
-	sbiret_report(&ret, SBI_SUCCESS, 0, "Get misaligned deleg locked value 0");
+
+	/* Test feature lock */

Can drop this comment since the function name says the same thing.

Quoted 10 lines
riscv/sbi-fwft.c +1 -2
+	fwft_feature_lock_test(SBI_FWFT_MISALIGNED_EXC_DELEG, 0);
 
 	report_prefix_pop();
 }
@@ -326,17 +352,8 @@ adue_inval_tests:
 	else
 		enabled = !enabled;
 
-	ret = fwft_set(SBI_FWFT_PTE_AD_HW_UPDATING, !enabled, 0);
-	sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED, "set locked to %d without lock", !enabled);

riscv/sbi-fwft.c adue_inval_tests: · line 355

Quoted 10 lines
riscv/sbi-fwft.c +1 -9
-
-	ret = fwft_set(SBI_FWFT_PTE_AD_HW_UPDATING, !enabled, 1);
-	sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED, "set locked to %d with lock", !enabled);
-
-	ret = fwft_set(SBI_FWFT_PTE_AD_HW_UPDATING, enabled, 0);
-	sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED, "set locked to %d without lock", enabled);
-
-	ret = fwft_set(SBI_FWFT_PTE_AD_HW_UPDATING, enabled, 1);
-	sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED, "set locked to %d with lock", enabled);
+	/* Test the feature lock */

same comment

Quoted 7 lines
riscv/sbi-fwft.c +1 -0
+	fwft_feature_lock_test(SBI_FWFT_PTE_AD_HW_UPDATING, enabled);
 
 adue_done:
 	install_exception_handler(EXC_LOAD_PAGE_FAULT, NULL);
Signature · 1 line
2.34.1

Thanks,
drew