mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-11-22 19:01:33 +00:00
lib: sbi_domain: ensure consistent firmware PMP entries
During domain context switches, all PMP entries are reconfigured which can clear firmware access permissions, causing M-mode access faults under SmePMP. Sort domain regions to place firmware regions first, ensuring consistent firmware PMP entries so they won't be revoked during domain context switches. Signed-off-by: Yu-Chien Peter Lin <peter.lin@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20251008084444.3525615-7-peter.lin@sifive.com Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
committed by
Anup Patel
parent
b34caeef81
commit
631efeeb49
@@ -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)
|
||||
|
||||
|
||||
@@ -292,6 +292,19 @@ 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)
|
||||
{
|
||||
/*
|
||||
* Enforce firmware region ordering for memory access
|
||||
* under SmePMP.
|
||||
* Place firmware regions first to ensure consistent
|
||||
* PMP entries during domain context switches.
|
||||
*/
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user