[PATCH 5/8] lib: sbi_domain_context: skip the reserved entry during domain context switch

Yu-Chien Peter Lin
2025-08-14T15:37:20Z

The reserved entry is activated to create shared region between M-mode
and S-mode, it should remain unchanged during domain context switch.

Signed-off-by: Yu-Chien Peter Lin <peter.lin@sifive.com>
---
lib/sbi/sbi_domain_context.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c
index fb04d81d..1812c7c9 100644
--- a/lib/sbi/sbi_domain_context.c
+++ b/lib/sbi/sbi_domain_context.c
@@ -116,6 +116,11 @@ static void switch_to_next_domain_context(struct hart_context *ctx,

/* Reconfigure PMP settings for the new domain */
for (int i = 0; i < pmp_count; i++) {
+ /* Skip the reserved entry when SmePMP is enabled */
+ if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SMEPMP) &&
+ (i == SBI_SMEPMP_RESV_ENTRY)) {
+ continue;
+ }
sbi_platform_pmp_disable(sbi_platform_thishart_ptr(), i);
pmp_disable(i);
}