summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYu-Chien Peter Lin <[email protected]>2025-10-08 16:44:38 +0800
committerAnup Patel <[email protected]>2025-11-02 16:03:35 +0530
commit667eed22661a5c5a7b73654ea3ea81737a6a1188 (patch)
treef0a972e2831b4f8e3d9913a9dbc25ac998fd8fac /lib
parent32c1d38dcf1a184b100bba2e26047939c32ec625 (diff)
lib: sbi_domain: allow specifying inaccessible region
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 <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
Diffstat (limited to 'lib')
-rw-r--r--lib/sbi/sbi_domain.c12
-rw-r--r--lib/sbi/sbi_hart.c4
2 files changed, 11 insertions, 5 deletions
diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c
index 1fa56b6a..89250d4c 100644
--- a/lib/sbi/sbi_domain.c
+++ b/lib/sbi/sbi_domain.c
@@ -126,7 +126,17 @@ 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) {
+ /*
+ * Region is inaccessible in all privilege modes.
+ *
+ * SmePMP allows two encodings for an inaccessible region:
+ * - pmpcfg.LRWX = 0000 (Inaccessible region)
+ * - pmpcfg.LRWX = 1000 (Locked inaccessible region)
+ * We use the first encoding here.
+ */
+ 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 81b9e479..7edd2a05 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);