Skip to content

Commit 71fc362

Browse files
Alexandre Ghitipalmer-dabbelt
authored andcommitted
riscv: Fix P4D_SHIFT definition for 3-level page table mode
RISC-V kernels support 3,4,5-level page tables at runtime by folding upper levels. In case of a 3-level page table, PGDIR is folded into P4D which in turn is folded into PUD: PGDIR_SHIFT value is correctly set to the same value as PUD_SHIFT, but P4D_SHIFT is not, then any use of P4D_SHIFT will access invalid address bits (all set to 1). Fix this by dynamically defining P4D_SHIFT value, like we already do for PGDIR_SHIFT. Fixes: d10efa2 ("riscv: mm: Control p4d's folding by pgtable_l5_enabled") Signed-off-by: Alexandre Ghiti <[email protected]> Reviewed-by: Palmer Dabbelt <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent e923f46 commit 71fc362

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

arch/riscv/include/asm/pgtable-64.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ extern bool pgtable_l5_enabled;
2525
#define PGDIR_MASK (~(PGDIR_SIZE - 1))
2626

2727
/* p4d is folded into pgd in case of 4-level page table */
28-
#define P4D_SHIFT 39
28+
#define P4D_SHIFT_L3 30
29+
#define P4D_SHIFT_L4 39
30+
#define P4D_SHIFT_L5 39
31+
#define P4D_SHIFT (pgtable_l5_enabled ? P4D_SHIFT_L5 : \
32+
(pgtable_l4_enabled ? P4D_SHIFT_L4 : P4D_SHIFT_L3))
2933
#define P4D_SIZE (_AC(1, UL) << P4D_SHIFT)
3034
#define P4D_MASK (~(P4D_SIZE - 1))
3135

0 commit comments

Comments
 (0)