From 0250db4dad85248c08a53df4056634dac5ed7169 Mon Sep 17 00:00:00 2001 From: Yu-Chien Peter Lin Date: Wed, 8 Oct 2025 16:44:44 +0800 Subject: [PATCH] lib: sbi_domain_context: preserve firmware PMP entries during domain context switch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When SmePMP is enabled, clearing firmware PMP entries during a domain context switch can temporarily revoke access to OpenSBI’s own code and data, leading to faults. Keep firmware PMP entries enabled across switches so firmware regions remain accessible and executable. Signed-off-by: Yu-Chien Peter Lin Reviewed-by: Anup Patel Link: https://lore.kernel.org/r/20251008084444.3525615-9-peter.lin@sifive.com Signed-off-by: Anup Patel --- lib/sbi/sbi_domain_context.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c index 5490df28..74ad25e8 100644 --- a/lib/sbi/sbi_domain_context.c +++ b/lib/sbi/sbi_domain_context.c @@ -122,6 +122,10 @@ static int switch_to_next_domain_context(struct hart_context *ctx, /* Reconfigure PMP settings for the new domain */ for (int i = 0; i < pmp_count; i++) { + /* Don't revoke firmware access permissions */ + if (sbi_hart_smepmp_is_fw_region(i)) + continue; + sbi_platform_pmp_disable(sbi_platform_thishart_ptr(), i); pmp_disable(i); }