From: Yu-Chien Peter Lin <peter.lin@sifive.com>
To: opensbi@lists.infradead.org
Cc: zong.li@sifive.com, greentime.hu@sifive.com,
alvinga@andestech.com, Yu-Chien Peter Lin <peter.lin@sifive.com>
Subject: [PATCH 7/8] lib: sbi_domain: ensure consistent firmware PMP entries
Date: Thu, 14 Aug 2025 19:05:21 +0800 [thread overview]
Message-ID: <20250814110522.18809-8-peter.lin@sifive.com> (raw)
In-Reply-To: <20250814110522.18809-1-peter.lin@sifive.com>
Currently, during a domain context switch, all PMP entries — including
those granting RW/RX permissions to firmware data and code are cleared
which will lead to access faults.
To configure firmware PMP entries deterministically across switches,
sort regions so that firmware regions come before others.
Signed-off-by: Yu-Chien Peter Lin <peter.lin@sifive.com>
---
include/sbi/sbi_domain.h | 3 +++
lib/sbi/sbi_domain.c | 14 ++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/include/sbi/sbi_domain.h b/include/sbi/sbi_domain.h
index d71354c7..31237401 100644
--- a/include/sbi/sbi_domain.h
+++ b/include/sbi/sbi_domain.h
@@ -121,6 +121,9 @@ struct sbi_domain_memregion {
((__flags & SBI_DOMAIN_MEMREGION_SU_ACCESS_MASK) && \
!(__flags & SBI_DOMAIN_MEMREGION_M_ACCESS_MASK))
+#define SBI_DOMAIN_MEMREGION_IS_FIRMWARE(__flags) \
+ ((__flags & SBI_DOMAIN_MEMREGION_FW) ? true : false) \
+
/** Bit to control if permissions are enforced on all modes */
#define SBI_DOMAIN_MEMREGION_ENF_PERMISSIONS (1UL << 6)
diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c
index ccfcc7f0..9e284f49 100644
--- a/lib/sbi/sbi_domain.c
+++ b/lib/sbi/sbi_domain.c
@@ -295,6 +295,20 @@ static bool is_region_compatible(const struct sbi_domain_memregion *regA,
static bool is_region_before(const struct sbi_domain_memregion *regA,
const struct sbi_domain_memregion *regB)
{
+ /*
+ * Firmware regions are placed before non‑firmware
+ * regions. This ensures firmware code/data remain
+ * accessible when SmePMP is enabled. Optional for
+ * regular PMP, but safe to follow consistently.
+ */
+ if (SBI_DOMAIN_MEMREGION_IS_FIRMWARE(regA->flags) &&
+ !SBI_DOMAIN_MEMREGION_IS_FIRMWARE(regB->flags))
+ return true;
+ if (!SBI_DOMAIN_MEMREGION_IS_FIRMWARE(regA->flags) &&
+ SBI_DOMAIN_MEMREGION_IS_FIRMWARE(regB->flags))
+ return false;
+
+
if (regA->order < regB->order)
return true;
--
2.39.3
--
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
next prev parent reply other threads:[~2025-08-14 15:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-14 11:05 [PATCH 0/8] SmePMP bugfixes and improvement Yu-Chien Peter Lin
2025-08-14 11:05 ` [PATCH 1/8] lib: sbi_hart: move sbi_hart_get_smepmp_flags() to sbi_domain Yu-Chien Peter Lin
2025-08-14 11:05 ` [PATCH 2/8] lib: sbi_domain: allow specifying inaccessible region Yu-Chien Peter Lin
2025-08-14 11:05 ` [PATCH 3/8] lib: sbi_domain: print unsupported SmePMP permissions Yu-Chien Peter Lin
2025-08-14 11:05 ` [PATCH 4/8] lib: sbi_hart: add error message for insufficient PMP entries Yu-Chien Peter Lin
2025-08-14 11:05 ` [PATCH 5/8] lib: sbi_domain_context: skip the reserved entry during domain context switch Yu-Chien Peter Lin
2025-08-15 5:54 ` Alvin Che-Chia Chang(張哲嘉)
2025-08-14 11:05 ` [PATCH 6/8] lib: sbi_domain: add SBI_DOMAIN_MEMREGION_FW memregion flag Yu-Chien Peter Lin
2025-08-14 15:39 ` Alvin Che-Chia Chang(張哲嘉)
2025-08-21 8:32 ` Xiang W
2025-08-14 11:05 ` Yu-Chien Peter Lin [this message]
2025-08-14 11:05 ` [PATCH 8/8] lib: sbi_domain_context: preserve firmware PMP entries during domain context switch Yu-Chien Peter Lin
2025-10-06 5:21 ` [PATCH 0/8] SmePMP bugfixes and improvement Anup Patel
2025-10-08 1:30 ` Peter Lin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250814110522.18809-8-peter.lin@sifive.com \
--to=peter.lin@sifive.com \
--cc=alvinga@andestech.com \
--cc=greentime.hu@sifive.com \
--cc=opensbi@lists.infradead.org \
--cc=zong.li@sifive.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox