Skip to content

Commit 3270bfd

Browse files
AlexGhitipalmer-dabbelt
authored andcommitted
riscv: Allow to dynamically define VA_BITS
With 4-level page table folding at runtime, we don't know at compile time the size of the virtual address space so we must set VA_BITS dynamically so that sparsemem reserves the right amount of memory for struct pages. Signed-off-by: Alexandre Ghiti <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 840125a commit 3270bfd

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

arch/riscv/Kconfig

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,6 @@ config MMU
146146
Select if you want MMU-based virtualised addressing space
147147
support by paged memory management. If unsure, say 'Y'.
148148

149-
config VA_BITS
150-
int
151-
default 32 if 32BIT
152-
default 39 if 64BIT
153-
154-
config PA_BITS
155-
int
156-
default 34 if 32BIT
157-
default 56 if 64BIT
158-
159149
config PAGE_OFFSET
160150
hex
161151
default 0xC0000000 if 32BIT

arch/riscv/include/asm/kasan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828
#define KASAN_SHADOW_SCALE_SHIFT 3
2929

30-
#define KASAN_SHADOW_SIZE (UL(1) << ((CONFIG_VA_BITS - 1) - KASAN_SHADOW_SCALE_SHIFT))
30+
#define KASAN_SHADOW_SIZE (UL(1) << ((VA_BITS - 1) - KASAN_SHADOW_SCALE_SHIFT))
3131
#define KASAN_SHADOW_START (KASAN_SHADOW_END - KASAN_SHADOW_SIZE)
3232
#define KASAN_SHADOW_END MODULES_LOWEST_VADDR
3333
#define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL)

arch/riscv/include/asm/pgtable.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,14 @@
6161
* struct pages to map half the virtual address space. Then
6262
* position vmemmap directly below the VMALLOC region.
6363
*/
64+
#ifdef CONFIG_64BIT
65+
#define VA_BITS 39
66+
#else
67+
#define VA_BITS 32
68+
#endif
69+
6470
#define VMEMMAP_SHIFT \
65-
(CONFIG_VA_BITS - PAGE_SHIFT - 1 + STRUCT_PAGE_MAX_SHIFT)
71+
(VA_BITS - PAGE_SHIFT - 1 + STRUCT_PAGE_MAX_SHIFT)
6672
#define VMEMMAP_SIZE BIT(VMEMMAP_SHIFT)
6773
#define VMEMMAP_END (VMALLOC_START - 1)
6874
#define VMEMMAP_START (VMALLOC_START - VMEMMAP_SIZE)
@@ -661,7 +667,7 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma,
661667
* and give the kernel the other (upper) half.
662668
*/
663669
#ifdef CONFIG_64BIT
664-
#define KERN_VIRT_START (-(BIT(CONFIG_VA_BITS)) + TASK_SIZE)
670+
#define KERN_VIRT_START (-(BIT(VA_BITS)) + TASK_SIZE)
665671
#else
666672
#define KERN_VIRT_START FIXADDR_START
667673
#endif

arch/riscv/include/asm/sparsemem.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
#define _ASM_RISCV_SPARSEMEM_H
55

66
#ifdef CONFIG_SPARSEMEM
7-
#define MAX_PHYSMEM_BITS CONFIG_PA_BITS
7+
#ifdef CONFIG_64BIT
8+
#define MAX_PHYSMEM_BITS 56
9+
#else
10+
#define MAX_PHYSMEM_BITS 34
11+
#endif /* CONFIG_64BIT */
812
#define SECTION_SIZE_BITS 27
913
#endif /* CONFIG_SPARSEMEM */
1014

0 commit comments

Comments
 (0)