platform/lib: Set no-map attribute on all PMP regions
authorAlexandre Ghiti <alexghiti@rivosinc.com>
Wed, 14 Jun 2023 08:20:39 +0000 (10:20 +0200)
committerAnup Patel <anup@brainfault.org>
Thu, 15 Jun 2023 12:57:17 +0000 (18:27 +0530)
commit8153b2622b08802cc542f30a1fcba407a5667ab9
tree8f9934cf456d14a691e2c242b3d968500c8f9059
parent932be2cde1b0f38c676bddaf801fa1030f9e9065
platform/lib: Set no-map attribute on all PMP regions

This reverts commit 6966ad0abe70 ("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>
include/sbi_utils/fdt/fdt_fixup.h
lib/utils/fdt/fdt_fixup.c
platform/generic/sifive/fu540.c