Skip to content

Commit

Permalink
riscv64: use wider default range for kernel text and modules
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoles committed Mar 30, 2024
1 parent e26d4da commit 3e60aad
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/kasld.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,11 @@
/* -----------------------------------------------------------------------------
* RISC-V 64-bit (riscv64)
* -----------------------------------------------------------------------------
* https://docs.kernel.org/riscv/vm-layout.html
* KASLR support added in commit f57805555834494e8cad729d01d86ba326d64959 in
* v6.6-rc1~10^2~5 on 2023-11-08.
* https://github.com/torvalds/linux/commit/f57805555834494e8cad729d01d86ba326d64959
* https://www.kernel.org/doc/html/next/riscv/vm-layout.html
* https://www.kernel.org/doc/html/next/riscv/boot.html
*/
#elif (defined(__riscv) || defined(__riscv__)) && __riscv_xlen == 64

Expand All @@ -386,16 +390,23 @@
// https://elixir.bootlin.com/linux/v6.1.1/source/arch/riscv/mm/init.c#L976
#define phys_to_virt(x) ((unsigned long)(x) + (PAGE_OFFSET - 0x80000000ul))

#define KERNEL_VAS_START 0xff00000000000000ul
// VAS start with SV57 (5-level page tables): 0xff1bffff_fea00000
// VAS start with SV48 (4-level page tables): 0xffff8d7f_fea00000
// VAS start with SV39 (3-level page tables): 0xffffffc6_fea00000
#define KERNEL_VAS_START 0xff10000000000000ul
#define KERNEL_VAS_END 0xfffffffffffffffful

#define KERNEL_BASE_MIN 0xffffffff80000000ul
// common:
// 0xffffffe0_00000000
// 0xffffffff_80000000
#define KERNEL_BASE_MIN 0xffffffe000000000ul
#define KERNEL_BASE_MAX 0xffffffffff000000ul

// Modules are located below kernel: KERNEL_LINK_ADDR - 2GB (0x80000000)
// https://elixir.bootlin.com/linux/v6.1.1/source/arch/riscv/include/asm/pgtable.h#L52
// 0xffffffd0_00000000 is also common
#define MODULES_START KERNEL_VAS_START - 0x80000000ul
#define MODULES_END KERNEL_BASE_MIN
#define MODULES_END 0xfffffffffffffffful

// https://elixir.bootlin.com/linux/v6.2-rc2/source/arch/riscv/include/asm/efi.h#L41
#define KERNEL_ALIGN 2 * MB
Expand All @@ -407,6 +418,8 @@
/* -----------------------------------------------------------------------------
* RISC-V 32-bit (riscv32)
* -----------------------------------------------------------------------------
* Linux for RISCV 32-bit does not support KASLR
* https://elixir.bootlin.com/linux/v6.8.2/source/arch/riscv/Kconfig#L819
*/
#elif (defined(__riscv) || defined(__riscv__)) && __riscv_xlen == 32

Expand Down

0 comments on commit 3e60aad

Please sign in to comment.