RISC-V: redefine PTRS_PER_PGD/PTRS_PER_PMD/PTRS_PER_PTE
PATCH 1/1 RISC-V: redefine PTRS_PER_PGD/PTRS_PER_PMD/PTRS_PER_PTE
Use the number of addresses to define the relevant macros.
--- arch/riscv/include/asm/pgtable-32.h | 2 ++ arch/riscv/include/asm/pgtable-64.h | 3 ++- arch/riscv/include/asm/pgtable.h | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-)
arch/riscv/include/asm/pgtable-32.h +2 -0
@@ -17,8 +17,10 @@#include <asm-generic/pgtable-nopmd.h> #include <linux/const.h> +#define MAX_USER_VA_BITS 32/* Size of region mapped by a page global directory */ #define PGDIR_SHIFT 22 +#define PMD_SHIFT PGDIR_SHIFT#define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT)#define PGDIR_MASK (~(PGDIR_SIZE - 1))
arch/riscv/include/asm/pgtable-64.h +2 -1
@@ -16,6 +16,7 @@#include <linux/const.h> +#define MAX_USER_VA_BITS 39#define PGDIR_SHIFT 30/* Size of region mapped by a page global directory */ #define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT)
@@ -34,7 +35,7 @@#define pmd_val (x) ((x).pmd)#define __pmd (x) ((pmd_t) { (x) }) -#define PTRS_PER_PMD (PAGE_SIZE / sizeof(pmd_t)) +#define PTRS_PER_PMD (1 << (PGDIR_SHIFT - PMD_SHIFT))static inline int pud_present (pud_t pud) {
arch/riscv/include/asm/pgtable.h +2 -2
@@ -33,9 +33,9 @@#endif /* CONFIG_64BIT */ /* Number of entries in the page global directory */ -#define PTRS_PER_PGD (PAGE_SIZE / sizeof(pgd_t)) +#define PTRS_PER_PGD (1 << (MAX_USER_VA_BITS - PGDIR_SHIFT))/* Number of entries in the page table */ -#define PTRS_PER_PTE (PAGE_SIZE / sizeof(pte_t)) +#define PTRS_PER_PTE (1 << (PMD_SHIFT - PAGE_SHIFT))/* Number of PGD entries that a user-mode program can use */ #define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE)
Signature · 1 line
1.9.1
Quoted 15 lines · damon
Use the number of addresses to define the relevant macros.
Signed-off-by damon <[email protected]>--- arch/riscv/include/asm/pgtable-32.h | 2 ++ arch/riscv/include/asm/pgtable-64.h | 3 ++- arch/riscv/include/asm/pgtable.h | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-)arch/riscv/include/asm/pgtable-32.h +0
-0
arch/riscv/include/asm/pgtable-32.h line 23
Quoted 7 lines
arch/riscv/include/asm/pgtable-32.h +2
-0@@ -17,8 +17,10 @@#include <asm-generic/pgtable-nopmd.h> #include <linux/const.h> +#define MAX_USER_VA_BITS 32/* Size of region mapped by a page global directory */ #define PGDIR_SHIFT 22 +#define PMD_SHIFT PGDIR_SHIFT
We don't have PMD in RV32. We have only two level page table for RV32 so defining PMD_SHIFT is misleading and in-correct.
I suggest you drop PMD_SHIFT here instead look at below suggestion for defining PTRS_PER_PTE in asm/pgtable.h
Quoted 29 lines
arch/riscv/include/asm/pgtable-32.h +0
-0#define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT)#define PGDIR_MASK (~(PGDIR_SIZE - 1))arch/riscv/include/asm/pgtable-64.h +2
-1@@ -16,6 +16,7 @@#include <linux/const.h> +#define MAX_USER_VA_BITS 39#define PGDIR_SHIFT 30/* Size of region mapped by a page global directory */ #define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT)@@ -34,7 +35,7 @@#define pmd_val (x) ((x).pmd)#define __pmd (x) ((pmd_t) { (x) }) -#define PTRS_PER_PMD (PAGE_SIZE / sizeof(pmd_t)) +#define PTRS_PER_PMD (1 << (PGDIR_SHIFT - PMD_SHIFT))static inline int pud_present (pud_t pud) {arch/riscv/include/asm/pgtable.h +0
-0
arch/riscv/include/asm/pgtable.h line 38
Quoted 8 lines
arch/riscv/include/asm/pgtable.h +2
-2@@ -33,9 +33,9 @@#endif /* CONFIG_64BIT */ /* Number of entries in the page global directory */ -#define PTRS_PER_PGD (PAGE_SIZE / sizeof(pgd_t)) +#define PTRS_PER_PGD (1 << (MAX_USER_VA_BITS - PGDIR_SHIFT))/* Number of entries in the page table */ -#define PTRS_PER_PTE (PAGE_SIZE / sizeof(pte_t)) +#define PTRS_PER_PTE (1 << (PMD_SHIFT - PAGE_SHIFT))
Instead of defining PTRS_PER_PTD using PMD_SHIFT for both RV32 and RV64, do the following:
#ifdef __PAGETABLE_PMD_FOLDED
#define PTRS_PER_PTE (1 << (PGDIR_SHIFT - PAGE_SHIFT))
#else
#define PTRS_PER_PTE (1 << (PMD_SHIFT - PAGE_SHIFT))
#endif
Quoted 6 lines
arch/riscv/include/asm/pgtable.h +0
-1/* Number of PGD entries that a user-mode program can use */ #define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE) --1.9.1
Regards,
Anup