[PATCH 2/8] lib: sbi_domain: allow specifying inaccessible region

Yu-Chien Peter Lin
2025-08-14T14:16:59Z

According to the RISC‑V Privileged Specification, SmePMP
regions that grant no access in any privilege mode are
valid. Allow such regions to be specified.

Signed-off-by: Yu-Chien Peter Lin <peter.lin@sifive.com>
---
lib/sbi/sbi_domain.c | 13 ++++++++++++-
lib/sbi/sbi_hart.c | 4 ----
2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c
index 1fa56b6a..e8adf66f 100644
--- a/lib/sbi/sbi_domain.c
+++ b/lib/sbi/sbi_domain.c
@@ -126,7 +126,18 @@ unsigned int sbi_domain_get_smepmp_flags(struct sbi_domain_memregion *reg)
{
unsigned int pmp_flags = 0;

- if (SBI_DOMAIN_MEMREGION_IS_SHARED(reg->flags)) {
+ if ((reg->flags & SBI_DOMAIN_MEMREGION_ACCESS_MASK) == 0) {
+ /*
+ * Inaccessible region for any modes
+ *
+ * Note that SmePMP configuration allows two settings
+ * for such region:
+ * - pmpcfg.LRWX = 0000 (Inaccessible region)
+ * - pmpcfg.LRWX = 1000 (Locked inaccessible region)
+ * Here we use the first one.
+ */
+ return 0;
+ } else if (SBI_DOMAIN_MEMREGION_IS_SHARED(reg->flags)) {
/* Read only for both M and SU modes */
if (SBI_DOMAIN_MEMREGION_IS_SUR_MR(reg->flags))
pmp_flags = (PMP_L | PMP_R | PMP_W | PMP_X);
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index c5c3ecb4..eab27f48 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -358,8 +358,6 @@ static int sbi_hart_smepmp_configure(struct sbi_scratch *scratch,
}

pmp_flags = sbi_domain_get_smepmp_flags(reg);
- if (!pmp_flags)
- return 0;

sbi_hart_smepmp_set(scratch, dom, reg, pmp_idx++, pmp_flags,
pmp_log2gran, pmp_addr_max);
@@ -384,8 +382,6 @@ static int sbi_hart_smepmp_configure(struct sbi_scratch *scratch,
}

pmp_flags = sbi_domain_get_smepmp_flags(reg);
- if (!pmp_flags)
- return 0;

sbi_hart_smepmp_set(scratch, dom, reg, pmp_idx++, pmp_flags,
pmp_log2gran, pmp_addr_max);