forked from Mirrors/opensbi
platform/lib: Allow the OS to map the regions that are protected by PMP
This is achieved by removing the 'no-map' property from the 'reserved-memory' node when PMP is present, otherwise we keep it as it offers a small protection if the OS does not map this region at all. A new callback in platform_override is introduced and allows to fixup the device-tree. It is used here to override this new default behaviour on SiFive Fu540 platforms that has an erratum that prevents S-mode software to access a PMP protected region using 1GB page table mapping. If PMP is present, telling the OS not to map the reserved regions does not add much protection since it only avoids access to regions that are already protected by PMP. But by not allowing the OS to map those regions, it creates holes in the OS system memory map and prevents the use of hugepages which would generate, among other benefits, less TLB miss. Signed-off-by: Alexandre Ghiti <alex@ghiti.fr> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
This commit is contained in:

committed by
Anup Patel

parent
e2c3f01af4
commit
6966ad0abe
@@ -21,6 +21,7 @@ struct platform_override {
|
||||
void (*early_exit)(const struct fdt_match *match);
|
||||
void (*final_exit)(const struct fdt_match *match);
|
||||
int (*system_reset)(u32 reset_type, const struct fdt_match *match);
|
||||
int (*fdt_fixup)(void *fdt, const struct fdt_match *match);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -153,6 +153,12 @@ static int generic_final_init(bool cold_boot)
|
||||
fdt_cpu_fixup(fdt);
|
||||
fdt_fixups(fdt);
|
||||
|
||||
if (generic_plat && generic_plat->fdt_fixup) {
|
||||
rc = generic_plat->fdt_fixup(fdt, generic_plat_match);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <platform_override.h>
|
||||
#include <sbi_utils/fdt/fdt_helper.h>
|
||||
#include <sbi_utils/fdt/fdt_fixup.h>
|
||||
|
||||
static u64 sifive_fu540_tlbr_flush_limit(const struct fdt_match *match)
|
||||
{
|
||||
@@ -19,6 +20,18 @@ 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" },
|
||||
@@ -30,4 +43,5 @@ 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,
|
||||
};
|
||||
|
@@ -63,6 +63,13 @@ static void fu540_modify_dt(void *fdt)
|
||||
fdt_cpu_fixup(fdt);
|
||||
|
||||
fdt_fixups(fdt);
|
||||
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
static int fu540_final_init(bool cold_boot)
|
||||
|
Reference in New Issue
Block a user