[RFC PATCH 09/23] lib: sbi: hart_pmp: verify and propagate regular PMP configure errors

Yu-Chien Peter Lin peter.lin at sifive.com
Mon Nov 30 02:11:33 PST 2026


Use verified PMP operations in sbi_hart_oldpmp_configure() when
programming domain regions and disabling unused entries. Return the
first programming or verification error so callers can reject a
partially programmed domain map.

Regions that fail the granularity or address-range check are still
logged and skipped without an error, as before.

Signed-off-by: Yu-Chien Peter Lin <peter.lin at sifive.com>
---
 lib/sbi/sbi_hart_pmp.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/lib/sbi/sbi_hart_pmp.c b/lib/sbi/sbi_hart_pmp.c
index 30524a97..27894bae 100644
--- a/lib/sbi/sbi_hart_pmp.c
+++ b/lib/sbi/sbi_hart_pmp.c
@@ -466,6 +466,7 @@ int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch,
 	unsigned int pmp_log2gran;
 	unsigned int pmp_idx, pmp_count;
 	unsigned int pmp_flags;
+	int rc;
 
 	pmp_count = sbi_hart_pmp_count(scratch);
 	pmp_log2gran = sbi_hart_pmp_log2gran(scratch);
@@ -482,7 +483,11 @@ int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch,
 			sbi_platform_pmp_set(sbi_platform_ptr(scratch),
 					     pmp_idx, reg->flags, pmp_flags,
 					     reg->base, reg->order);
-			sbi_hart_pmp_set(pmp_idx++, pmp_flags, reg->base, reg->order);
+			rc = sbi_hart_pmp_set_verified(pmp_idx, pmp_flags,
+						       reg->base, reg->order);
+			if (rc)
+				return rc;
+			pmp_idx++;
 		} else {
 			sbi_printf("Can not configure pmp for domain %s because"
 				   " memory region address 0x%lx or size 0x%lx "
@@ -491,8 +496,12 @@ int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch,
 		}
 	}
 	/* Disable remaining PMP entries */
-	for(; pmp_idx < pmp_count; pmp_idx++)
-		sbi_hart_pmp_disable(pmp_idx);
+	for (; pmp_idx < pmp_count; pmp_idx++) {
+		int rc = sbi_hart_pmp_disable_verified(pmp_idx);
+
+		if (rc)
+			return rc;
+	}
 
 	sbi_hart_pmp_fence();
 	return 0;
-- 
2.43.7




More information about the opensbi mailing list