mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-25 07:41:42 +01:00
platform/lib: Set no-map attribute on all PMP regions
This reverts commit 6966ad0abe
("platform/lib: Allow the OS to map the
regions that are protected by PMP").
It was thought at the time of this commit that allowing the kernel to map
PMP protected regions was safe but it is actually not: for example, the
hibernation process will try to access any linear mapping page and then
will fault on such mapped PMP regions [1]. Another issue is that the
device tree specification [2] states that a !no-map region must be
declared as EfiBootServicesData/Code in the EFI memory map which would make
the PMP protected regions reclaimable by the kernel. And to circumvent
this, RISC-V edk2 diverges from the DT specification to declare those
regions as EfiReserved.
The no-map attribute was removed to allow the kernel to use hugepages
larger than 2MB to map the linear mapping to improve the performance but
actually a recent talk from Mike Rapoport [3] stated that the
performance benefit was marginal.
For all those reasons, let's mark all the PMP protected regions as "no-map".
[1] https://lore.kernel.org/linux-riscv/CAAYs2=gQvkhTeioMmqRDVGjdtNF_vhB+vm_1dHJxPNi75YDQ_Q@mail.gmail.com/
[2] "3.5.4 /reserved-memory and UEFI" https://github.com/devicetree-org/devicetree-specification/releases/download/v0.4-rc1/devicetree-specification-v0.4-rc1.pdf
[3] https://lwn.net/Articles/931406/
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Reviewed-by: Atish Patra <atishp@rivosinc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
This commit is contained in:

committed by
Anup Patel

parent
932be2cde1
commit
8153b2622b
@@ -210,7 +210,7 @@ void fdt_plic_fixup(void *fdt)
|
||||
|
||||
static int fdt_resv_memory_update_node(void *fdt, unsigned long addr,
|
||||
unsigned long size, int index,
|
||||
int parent, bool no_map)
|
||||
int parent)
|
||||
{
|
||||
int na = fdt_address_cells(fdt, 0);
|
||||
int ns = fdt_size_cells(fdt, 0);
|
||||
@@ -239,16 +239,14 @@ static int fdt_resv_memory_update_node(void *fdt, unsigned long addr,
|
||||
if (subnode < 0)
|
||||
return subnode;
|
||||
|
||||
if (no_map) {
|
||||
/*
|
||||
* Tell operating system not to create a virtual
|
||||
* mapping of the region as part of its standard
|
||||
* mapping of system memory.
|
||||
*/
|
||||
err = fdt_setprop_empty(fdt, subnode, "no-map");
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
/*
|
||||
* Tell operating system not to create a virtual
|
||||
* mapping of the region as part of its standard
|
||||
* mapping of system memory.
|
||||
*/
|
||||
err = fdt_setprop_empty(fdt, subnode, "no-map");
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
/* encode the <reg> property value */
|
||||
val = reg;
|
||||
@@ -286,7 +284,6 @@ int fdt_reserved_memory_fixup(void *fdt)
|
||||
{
|
||||
struct sbi_domain_memregion *reg;
|
||||
struct sbi_domain *dom = sbi_domain_thishart_ptr();
|
||||
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
||||
unsigned long filtered_base[PMP_COUNT] = { 0 };
|
||||
unsigned char filtered_order[PMP_COUNT] = { 0 };
|
||||
unsigned long addr, size;
|
||||
@@ -382,33 +379,7 @@ int fdt_reserved_memory_fixup(void *fdt)
|
||||
for (j = 0; j < i; j++) {
|
||||
addr = filtered_base[j];
|
||||
size = 1UL << filtered_order[j];
|
||||
fdt_resv_memory_update_node(fdt, addr, size, j, parent,
|
||||
(sbi_hart_pmp_count(scratch))
|
||||
? false : true);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fdt_reserved_memory_nomap_fixup(void *fdt)
|
||||
{
|
||||
int parent, subnode;
|
||||
int err;
|
||||
|
||||
/* Locate the reserved memory node */
|
||||
parent = fdt_path_offset(fdt, "/reserved-memory");
|
||||
if (parent < 0)
|
||||
return parent;
|
||||
|
||||
fdt_for_each_subnode(subnode, fdt, parent) {
|
||||
/*
|
||||
* Tell operating system not to create a virtual
|
||||
* mapping of the region as part of its standard
|
||||
* mapping of system memory.
|
||||
*/
|
||||
err = fdt_setprop_empty(fdt, subnode, "no-map");
|
||||
if (err < 0)
|
||||
return err;
|
||||
fdt_resv_memory_update_node(fdt, addr, size, j, parent);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user