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:
Alexandre Ghiti
2023-06-14 10:20:39 +02:00
committed by Anup Patel
parent 932be2cde1
commit 8153b2622b
3 changed files with 10 additions and 66 deletions

View File

@@ -20,18 +20,6 @@ static u64 sifive_fu540_tlbr_flush_limit(const struct fdt_match *match)
return 0;
}
static int sifive_fu540_fdt_fixup(void *fdt, const struct fdt_match *match)
{
/*
* SiFive Freedom U540 has an erratum that prevents S-mode software
* to access a PMP protected region using 1GB page table mapping, so
* always add the no-map attribute on this platform.
*/
fdt_reserved_memory_nomap_fixup(fdt);
return 0;
}
static const struct fdt_match sifive_fu540_match[] = {
{ .compatible = "sifive,fu540" },
{ .compatible = "sifive,fu540g" },
@@ -43,5 +31,4 @@ static const struct fdt_match sifive_fu540_match[] = {
const struct platform_override sifive_fu540 = {
.match_table = sifive_fu540_match,
.tlbr_flush_limit = sifive_fu540_tlbr_flush_limit,
.fdt_fixup = sifive_fu540_fdt_fixup,
};