Skip to content

Commit d7e76ce

Browse files
Merge patch series "riscv: Increase mmap_rnd_bits_max on Sv48/57"
Sami Tolvanen <[email protected]> says: We noticed that 64-bit RISC-V kernels limit mmap_rnd_bits to 24 even if the hardware supports a larger virtual address space size [1]. These two patches allow mmap_rnd_bits_max to be changed during init, and bumps up the maximum randomness if we end up setting up 4/5-level paging at boot. * b4-shazam-merge: riscv: mm: Update mmap_rnd_bits_max mm: Change mmap_rnd_bits_max to __ro_after_init Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
2 parents e2d6b54 + 7df1ff5 commit d7e76ce

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

arch/riscv/mm/init.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,11 @@ static int __init print_no5lvl(char *p)
767767
}
768768
early_param("no5lvl", print_no5lvl);
769769

770+
static void __init set_mmap_rnd_bits_max(void)
771+
{
772+
mmap_rnd_bits_max = MMAP_VA_BITS - PAGE_SHIFT - 3;
773+
}
774+
770775
/*
771776
* There is a simple way to determine if 4-level is supported by the
772777
* underlying hardware: establish 1:1 mapping in 4-level page table mode
@@ -1081,6 +1086,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
10811086

10821087
#if defined(CONFIG_64BIT) && !defined(CONFIG_XIP_KERNEL)
10831088
set_satp_mode(dtb_pa);
1089+
set_mmap_rnd_bits_max();
10841090
#endif
10851091

10861092
/*

include/linux/mm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ extern int sysctl_legacy_va_layout;
8686

8787
#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
8888
extern const int mmap_rnd_bits_min;
89-
extern const int mmap_rnd_bits_max;
89+
extern int mmap_rnd_bits_max __ro_after_init;
9090
extern int mmap_rnd_bits __read_mostly;
9191
#endif
9292
#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS

mm/mmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565
#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
6666
const int mmap_rnd_bits_min = CONFIG_ARCH_MMAP_RND_BITS_MIN;
67-
const int mmap_rnd_bits_max = CONFIG_ARCH_MMAP_RND_BITS_MAX;
67+
int mmap_rnd_bits_max __ro_after_init = CONFIG_ARCH_MMAP_RND_BITS_MAX;
6868
int mmap_rnd_bits __read_mostly = CONFIG_ARCH_MMAP_RND_BITS;
6969
#endif
7070
#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS

0 commit comments

Comments
 (0)