Commit aa6a52b2 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Catalin Marinas

arm64: head: move memstart_offset_seed handling to C code

Now that we can set BSS variables from the early code running from the
ID map, we can set memstart_offset_seed directly from the C code that
derives the value instead of passing it back and forth between C and asm
code.
Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20240214122845.2033971-60-ardb+git@google.comSigned-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
parent 8d47b8e5
...@@ -82,7 +82,6 @@ ...@@ -82,7 +82,6 @@
* x21 primary_entry() .. start_kernel() FDT pointer passed at boot in x0 * x21 primary_entry() .. start_kernel() FDT pointer passed at boot in x0
* x22 create_idmap() .. start_kernel() ID map VA of the DT blob * x22 create_idmap() .. start_kernel() ID map VA of the DT blob
* x23 __primary_switch() physical misalignment/KASLR offset * x23 __primary_switch() physical misalignment/KASLR offset
* x24 __primary_switch() linear map KASLR seed
* x25 primary_entry() .. start_kernel() supported VA size * x25 primary_entry() .. start_kernel() supported VA size
* x28 create_idmap() callee preserved temp register * x28 create_idmap() callee preserved temp register
*/ */
...@@ -483,11 +482,6 @@ SYM_FUNC_START_LOCAL(__primary_switched) ...@@ -483,11 +482,6 @@ SYM_FUNC_START_LOCAL(__primary_switched)
str x25, [x8] // ... observes the correct value str x25, [x8] // ... observes the correct value
dc civac, x8 // Make visible to booting secondaries dc civac, x8 // Make visible to booting secondaries
#endif #endif
#ifdef CONFIG_RANDOMIZE_BASE
adrp x5, memstart_offset_seed // Save KASLR linear map seed
strh w24, [x5, :lo12:memstart_offset_seed]
#endif
#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
bl kasan_early_init bl kasan_early_init
#endif #endif
...@@ -779,7 +773,6 @@ SYM_FUNC_START_LOCAL(__primary_switch) ...@@ -779,7 +773,6 @@ SYM_FUNC_START_LOCAL(__primary_switch)
#ifdef CONFIG_RANDOMIZE_BASE #ifdef CONFIG_RANDOMIZE_BASE
mov x0, x22 mov x0, x22
bl __pi_kaslr_early_init bl __pi_kaslr_early_init
and x24, x0, #SZ_2M - 1 // capture memstart offset seed
bic x0, x0, #SZ_2M - 1 bic x0, x0, #SZ_2M - 1
orr x23, x23, x0 // record kernel offset orr x23, x23, x0 // record kernel offset
#endif #endif
......
...@@ -46,6 +46,7 @@ PROVIDE(__pi_id_aa64smfr0_override = id_aa64smfr0_override); ...@@ -46,6 +46,7 @@ PROVIDE(__pi_id_aa64smfr0_override = id_aa64smfr0_override);
PROVIDE(__pi_id_aa64zfr0_override = id_aa64zfr0_override); PROVIDE(__pi_id_aa64zfr0_override = id_aa64zfr0_override);
PROVIDE(__pi_arm64_sw_feature_override = arm64_sw_feature_override); PROVIDE(__pi_arm64_sw_feature_override = arm64_sw_feature_override);
PROVIDE(__pi__ctype = _ctype); PROVIDE(__pi__ctype = _ctype);
PROVIDE(__pi_memstart_offset_seed = memstart_offset_seed);
#ifdef CONFIG_KVM #ifdef CONFIG_KVM
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include <asm/memory.h> #include <asm/memory.h>
#include <asm/pgtable.h> #include <asm/pgtable.h>
extern u16 memstart_offset_seed;
static u64 __init get_kaslr_seed(void *fdt) static u64 __init get_kaslr_seed(void *fdt)
{ {
static char const chosen_str[] __initconst = "chosen"; static char const chosen_str[] __initconst = "chosen";
...@@ -51,6 +53,8 @@ asmlinkage u64 __init kaslr_early_init(void *fdt) ...@@ -51,6 +53,8 @@ asmlinkage u64 __init kaslr_early_init(void *fdt)
return 0; return 0;
} }
memstart_offset_seed = seed & U16_MAX;
/* /*
* OK, so we are proceeding with KASLR enabled. Calculate a suitable * OK, so we are proceeding with KASLR enabled. Calculate a suitable
* kernel image offset from the seed. Let's place the kernel in the * kernel image offset from the seed. Let's place the kernel in the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment