Skip to content

Commit 1074dd4

Browse files
avpatelpalmer-dabbelt
authored andcommitted
RISC-V: Use non-PGD mappings for early DTB access
Currently, we use PGD mappings for early DTB mapping in early_pgd but this breaks Linux kernel on SiFive Unleashed because on SiFive Unleashed PMP checks don't work correctly for PGD mappings. To fix early DTB mappings on SiFive Unleashed, we use non-PGD mappings (i.e. PMD) for early DTB access. Fixes: 8f3a2b4 ("RISC-V: Move DT mapping outof fixmap") Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Tested-by: Atish Patra <atish.patra@wdc.com> Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
1 parent 635e3f3 commit 1074dd4

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

arch/riscv/mm/init.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ pmd_t fixmap_pmd[PTRS_PER_PMD] __page_aligned_bss;
293293
#define NUM_EARLY_PMDS (1UL + MAX_EARLY_MAPPING_SIZE / PGDIR_SIZE)
294294
#endif
295295
pmd_t early_pmd[PTRS_PER_PMD * NUM_EARLY_PMDS] __initdata __aligned(PAGE_SIZE);
296+
pmd_t early_dtb_pmd[PTRS_PER_PMD] __initdata __aligned(PAGE_SIZE);
296297

297298
static pmd_t *__init get_pmd_virt_early(phys_addr_t pa)
298299
{
@@ -490,13 +491,26 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
490491
load_pa + (va - PAGE_OFFSET),
491492
map_size, PAGE_KERNEL_EXEC);
492493

494+
#ifndef __PAGETABLE_PMD_FOLDED
495+
/* Setup early PMD for DTB */
496+
create_pgd_mapping(early_pg_dir, DTB_EARLY_BASE_VA,
497+
(uintptr_t)early_dtb_pmd, PGDIR_SIZE, PAGE_TABLE);
498+
/* Create two consecutive PMD mappings for FDT early scan */
499+
pa = dtb_pa & ~(PMD_SIZE - 1);
500+
create_pmd_mapping(early_dtb_pmd, DTB_EARLY_BASE_VA,
501+
pa, PMD_SIZE, PAGE_KERNEL);
502+
create_pmd_mapping(early_dtb_pmd, DTB_EARLY_BASE_VA + PMD_SIZE,
503+
pa + PMD_SIZE, PMD_SIZE, PAGE_KERNEL);
504+
dtb_early_va = (void *)DTB_EARLY_BASE_VA + (dtb_pa & (PMD_SIZE - 1));
505+
#else
493506
/* Create two consecutive PGD mappings for FDT early scan */
494507
pa = dtb_pa & ~(PGDIR_SIZE - 1);
495508
create_pgd_mapping(early_pg_dir, DTB_EARLY_BASE_VA,
496509
pa, PGDIR_SIZE, PAGE_KERNEL);
497510
create_pgd_mapping(early_pg_dir, DTB_EARLY_BASE_VA + PGDIR_SIZE,
498511
pa + PGDIR_SIZE, PGDIR_SIZE, PAGE_KERNEL);
499512
dtb_early_va = (void *)DTB_EARLY_BASE_VA + (dtb_pa & (PGDIR_SIZE - 1));
513+
#endif
500514
dtb_early_pa = dtb_pa;
501515

502516
/*

0 commit comments

Comments
 (0)