Skip to contentSkip to conversation

RISC-V: redefine PTRS_PER_PGD/PTRS_PER_PMD/PTRS_PER_PTE

PATCH In review damon 3 participants 4 messages Apr 24, 2019 – Jul 24, 2019 RISC-V

lore
Share & tools
lore

damon

author
#0 lore raw

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 | 1 +
 arch/riscv/include/asm/pgtable-64.h | 3 ++-
 arch/riscv/include/asm/pgtable.h    | 8 ++++++--
 3 files changed, 9 insertions(+), 3 deletions(-)
arch/riscv/include/asm/pgtable-32.h +1 -0
index d61974b7..c9c8ca8 100644
@@ -17,6 +17,7 @@
 #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 PGDIR_SIZE      (_AC(1, UL) << PGDIR_SHIFT)
arch/riscv/include/asm/pgtable-64.h +2 -1
index 7aa0ea9..a56d4d0 100644
@@ -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 +6 -2
index 1141364..9148043 100644
@@ -33,9 +33,13 @@
 #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))
+#ifdef __PAGETABLE_PMD_FOLDED
+#define PTRS_PER_PTE   (1 << (PGDIR_SHIFT - PAGE_SHIFT))
+#else
+#define PTRS_PER_PTE   (1 << (PMD_SHIFT - PAGE_SHIFT))
+#endif
 
 /* 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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 64 lines · damon

Use the number of addresses to define the relevant macros.

---
 arch/riscv/include/asm/pgtable-32.h | 1 +
 arch/riscv/include/asm/pgtable-64.h | 3 ++-
 arch/riscv/include/asm/pgtable.h    | 8 ++++++--
 3 files changed, 9 insertions(+), 3 deletions(-)
arch/riscv/include/asm/pgtable-32.h +1 -0
index d61974b7..c9c8ca8 100644
@@ -17,6 +17,7 @@
 #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 PGDIR_SIZE      (_AC(1, UL) << PGDIR_SHIFT)
arch/riscv/include/asm/pgtable-64.h +2 -1
index 7aa0ea9..a56d4d0 100644
@@ -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 +6 -3
index 1141364..9148043 100644
@@ -33,9 +33,13 @@
 #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))
+#ifdef __PAGETABLE_PMD_FOLDED
+#define PTRS_PER_PTE   (1 << (PGDIR_SHIFT - PAGE_SHIFT))
+#else
+#define PTRS_PER_PTE   (1 << (PMD_SHIFT - PAGE_SHIFT))
+#endif
 
 /* Number of PGD entries that a user-mode program can use */
 #define USER_PTRS_PER_PGD   (TASK_SIZE / PGDIR_SIZE)
--
Quoted 2 lines

1.9.1

LGTM.

Regards,
Anup

#2 lore raw
In reply to damon
Quoted 3 lines · damon

Use the number of addresses to define the relevant macros.

This patch looks reasonable to me. But what's missing from the description is the motivation. Is this a prerequisite for another patch that you're planning to post? Or because you think this is clearer than the original? Or something else? etc.

- Paul

author
#3 lore raw

I think the previous description is unclear, and it is difficult for readers to understand the meaning of these macros, because I never understand. So I submitted this patch with reference to the definition of arm. I think this way can make the reader easier to understand, and I also think that this definition is more reasonable.

2019-06-29 2:52 GMT+08:00, Paul Walmsley <[email protected]>:

Quoted 14 lines · damon
Quoted 4 lines

Use the number of addresses to define the relevant macros.

This patch looks reasonable to me. But what's missing from the description is the motivation. Is this a prerequisite for another patch that you're planning to post? Or because you think this is clearer than the original? Or something else? etc.

- Paul