[RFC PATCH 08/23] lib: sbi: hart_pmp: verify and propagate Smepmp configure errors

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


Use verified PMP operations in sbi_hart_smepmp_configure() when
disabling the temporary entry, programming domain regions, and
disabling unused entries. Make sbi_hart_smepmp_set() return programming
errors and propagate them through configure().

This lets callers reject hardware programming failures. Existing range
filtering still logs and skips unsupported regions without an error;
mseccfg.RLB and mseccfg.MML writes remain unchecked.

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

diff --git a/lib/sbi/sbi_hart_pmp.c b/lib/sbi/sbi_hart_pmp.c
index 0e737820..30524a97 100644
--- a/lib/sbi/sbi_hart_pmp.c
+++ b/lib/sbi/sbi_hart_pmp.c
@@ -271,13 +271,13 @@ void sbi_hart_pmp_fence(void)
 	}
 }
 
-static void sbi_hart_smepmp_set(struct sbi_scratch *scratch,
-				struct sbi_domain *dom,
-				struct sbi_domain_memregion *reg,
-				unsigned int pmp_idx,
-				unsigned int pmp_flags,
-				unsigned int pmp_log2gran,
-				unsigned long pmp_addr_max)
+static int sbi_hart_smepmp_set(struct sbi_scratch *scratch,
+			       struct sbi_domain *dom,
+			       struct sbi_domain_memregion *reg,
+			       unsigned int pmp_idx,
+			       unsigned int pmp_flags,
+			       unsigned int pmp_log2gran,
+			       unsigned long pmp_addr_max)
 {
 	unsigned long pmp_addr = reg->base >> PMP_SHIFT;
 
@@ -285,13 +285,16 @@ static void sbi_hart_smepmp_set(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);
+		return sbi_hart_pmp_set_verified(pmp_idx, pmp_flags, reg->base,
+						 reg->order);
 	} else {
 		sbi_printf("Can not configure pmp for domain %s because"
 			   " memory region address 0x%lx or size 0x%lx "
 			   "is not in range.\n", dom->name, reg->base,
 			   reg->order);
 	}
+
+	return SBI_OK;
 }
 
 static bool is_valid_pmp_idx(unsigned int pmp_count, unsigned int pmp_idx)
@@ -311,6 +314,7 @@ int sbi_hart_smepmp_configure(struct sbi_scratch *scratch,
 	unsigned int pmp_idx, pmp_count;
 	unsigned long pmp_addr_max;
 	unsigned int pmp_flags;
+	int rc;
 
 	pmp_count = sbi_hart_pmp_count(scratch);
 	pmp_log2gran = sbi_hart_pmp_log2gran(scratch);
@@ -326,7 +330,9 @@ int sbi_hart_smepmp_configure(struct sbi_scratch *scratch,
 		return SBI_EFAIL;
 
 	/* Disable the reserved entry */
-	sbi_hart_pmp_disable(start);
+	rc = sbi_hart_pmp_disable_verified(start);
+	if (rc)
+		return rc;
 
 	/* Program M-only regions when MML is not set. */
 	pmp_idx = start + 1;
@@ -358,9 +364,11 @@ int sbi_hart_smepmp_configure(struct sbi_scratch *scratch,
 		}
 
 		pmp_flags = sbi_domain_get_smepmp_flags(reg);
-
-		sbi_hart_smepmp_set(scratch, dom, reg, pmp_idx++, pmp_flags,
-				    pmp_log2gran, pmp_addr_max);
+		rc = sbi_hart_smepmp_set(scratch, dom, reg, pmp_idx, pmp_flags,
+					 pmp_log2gran, pmp_addr_max);
+		if (rc)
+			return rc;
+		pmp_idx++;
 	}
 
 	fw_smepmp_ids_inited = true;
@@ -381,13 +389,19 @@ int sbi_hart_smepmp_configure(struct sbi_scratch *scratch,
 		}
 
 		pmp_flags = sbi_domain_get_smepmp_flags(reg);
-
-		sbi_hart_smepmp_set(scratch, dom, reg, pmp_idx++, pmp_flags,
-				    pmp_log2gran, pmp_addr_max);
+		rc = sbi_hart_smepmp_set(scratch, dom, reg, pmp_idx, pmp_flags,
+					 pmp_log2gran, pmp_addr_max);
+		if (rc)
+			return rc;
+		pmp_idx++;
 	}
 	/* 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;
+	}
 
 	/*
 	 * All entries are programmed.
-- 
2.43.7




More information about the opensbi mailing list