[RFC PATCH 10/23] lib: sbi: hart_pmp: verify temporary Smepmp map and unmap operations
Yu-Chien Peter Lin
peter.lin at sifive.com
Mon Nov 30 02:11:34 PST 2026
Use sbi_hart_pmp_set_verified() in sbi_hart_smepmp_temp_map_range() and
sbi_hart_pmp_disable_verified() in sbi_hart_smepmp_temp_unmap_range().
Return programming and verification errors from both operations so a
successful return confirms that the requested entry update took effect.
Signed-off-by: Yu-Chien Peter Lin <peter.lin at sifive.com>
---
lib/sbi/sbi_hart_pmp.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/lib/sbi/sbi_hart_pmp.c b/lib/sbi/sbi_hart_pmp.c
index 27894bae..1e88be73 100644
--- a/lib/sbi/sbi_hart_pmp.c
+++ b/lib/sbi/sbi_hart_pmp.c
@@ -419,6 +419,7 @@ int sbi_hart_smepmp_temp_map_range(struct sbi_scratch *scratch,
/* shared R/W access for M and S/U mode */
unsigned int pmp_flags = (PMP_W | PMP_X);
unsigned long order, base = 0;
+ int rc;
if (!is_valid_pmp_idx(sbi_hart_pmp_count(scratch), start))
return SBI_EFAIL;
@@ -442,20 +443,31 @@ int sbi_hart_smepmp_temp_map_range(struct sbi_scratch *scratch,
sbi_platform_pmp_set(sbi_platform_ptr(scratch), start,
SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW, pmp_flags,
base, order);
- sbi_hart_pmp_set(start, pmp_flags, base, order);
+ rc = sbi_hart_pmp_set_verified(start, pmp_flags, base, order);
+ if (rc) {
+ /* Do not leave a stale or wrong shared entry behind */
+ sbi_hart_pmp_disable(start);
+ sbi_platform_pmp_disable(sbi_platform_ptr(scratch), start);
+ }
- return SBI_OK;
+ return rc;
}
int sbi_hart_smepmp_temp_unmap_range(struct sbi_scratch *scratch,
unsigned long addr, unsigned long size,
unsigned int start)
{
+ int rc;
+
if (!is_valid_pmp_idx(sbi_hart_pmp_count(scratch), start))
return SBI_EFAIL;
+ rc = sbi_hart_pmp_disable_verified(start);
+ if (rc)
+ return rc;
+
sbi_platform_pmp_disable(sbi_platform_ptr(scratch), start);
- return sbi_hart_pmp_disable(start);
+ return SBI_OK;
}
int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch,
--
2.43.7
More information about the opensbi
mailing list