Skip to content

Commit 1191b62

Browse files
mrutland-armwilldeacon
authored andcommitted
arm64: fix KASAN_INLINE
Since commit: a004393 ("arm64: idreg-override: use early FDT mapping in ID map") Kernels built with KASAN_INLINE=y die early in boot before producing any console output. This is because the accesses made to the FDT (e.g. in generic string processing functions) are instrumented with KASAN, and with KASAN_INLINE=y any access to an address in TTBR0 results in a bogus shadow VA, resulting in a data abort. This patch fixes this by reverting commits: 7559d9f ("arm64: setup: drop early FDT pointer helpers") bd0c3fa21878b6d0 ("arm64: idreg-override: use early FDT mapping in ID map") ... and using the TTBR1 fixmap mapping of the FDT. Note that due to a later commit: b65e411 ("arm64: Save state of HCR_EL2.E2H before switch to EL1") ... which altered the prototype of init_feature_override() (and invocation from head.S), commit bd0c3fa21878b6d0 does not revert cleanly, and I've fixed that up manually. Fixes: a004393 ("arm64: idreg-override: use early FDT mapping in ID map") Cc: Ard Biesheuvel <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Marc Zyngier <[email protected]> Cc: Will Deacon <[email protected]> Acked-by: Catalin Marinas <[email protected]> Signed-off-by: Mark Rutland <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 18c9aa4 commit 1191b62

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

arch/arm64/include/asm/setup.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
#include <uapi/asm/setup.h>
77

8+
void *get_early_fdt_ptr(void);
9+
void early_fdt_map(u64 dt_phys);
10+
811
/*
912
* These two variables are used in the head.S file.
1013
*/

arch/arm64/kernel/head.S

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,9 @@ SYM_FUNC_START_LOCAL(__primary_switched)
456456
#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
457457
bl kasan_early_init
458458
#endif
459-
mov x0, x22 // pass FDT address in x0
460-
mov x1, x20 // pass the full boot status
459+
mov x0, x21 // pass FDT address in x0
460+
bl early_fdt_map // Try mapping the FDT early
461+
mov x0, x20 // pass the full boot status
461462
bl init_feature_override // Parse cpu feature overrides
462463
mov x0, x20
463464
bl finalise_el2 // Prefer VHE if possible

arch/arm64/kernel/idreg-override.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,16 @@ static __init void __parse_cmdline(const char *cmdline, bool parse_aliases)
262262
} while (1);
263263
}
264264

265-
static __init const u8 *get_bootargs_cmdline(const void *fdt)
265+
static __init const u8 *get_bootargs_cmdline(void)
266266
{
267267
const u8 *prop;
268+
void *fdt;
268269
int node;
269270

271+
fdt = get_early_fdt_ptr();
272+
if (!fdt)
273+
return NULL;
274+
270275
node = fdt_path_offset(fdt, "/chosen");
271276
if (node < 0)
272277
return NULL;
@@ -278,9 +283,9 @@ static __init const u8 *get_bootargs_cmdline(const void *fdt)
278283
return strlen(prop) ? prop : NULL;
279284
}
280285

281-
static __init void parse_cmdline(const void *fdt)
286+
static __init void parse_cmdline(void)
282287
{
283-
const u8 *prop = get_bootargs_cmdline(fdt);
288+
const u8 *prop = get_bootargs_cmdline();
284289

285290
if (IS_ENABLED(CONFIG_CMDLINE_FORCE) || !prop)
286291
__parse_cmdline(CONFIG_CMDLINE, true);
@@ -290,9 +295,9 @@ static __init void parse_cmdline(const void *fdt)
290295
}
291296

292297
/* Keep checkers quiet */
293-
void init_feature_override(const void *fdt, u64 boot_status);
298+
void init_feature_override(u64 boot_status);
294299

295-
asmlinkage void __init init_feature_override(const void *fdt, u64 boot_status)
300+
asmlinkage void __init init_feature_override(u64 boot_status)
296301
{
297302
int i;
298303

@@ -305,7 +310,7 @@ asmlinkage void __init init_feature_override(const void *fdt, u64 boot_status)
305310

306311
__boot_status = boot_status;
307312

308-
parse_cmdline(fdt);
313+
parse_cmdline();
309314

310315
for (i = 0; i < ARRAY_SIZE(regs); i++) {
311316
if (regs[i]->override)

arch/arm64/kernel/setup.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,21 @@ static void __init smp_build_mpidr_hash(void)
163163
pr_warn("Large number of MPIDR hash buckets detected\n");
164164
}
165165

166+
static void *early_fdt_ptr __initdata;
167+
168+
void __init *get_early_fdt_ptr(void)
169+
{
170+
return early_fdt_ptr;
171+
}
172+
173+
asmlinkage void __init early_fdt_map(u64 dt_phys)
174+
{
175+
int fdt_size;
176+
177+
early_fixmap_init();
178+
early_fdt_ptr = fixmap_remap_fdt(dt_phys, &fdt_size, PAGE_KERNEL);
179+
}
180+
166181
static void __init setup_machine_fdt(phys_addr_t dt_phys)
167182
{
168183
int size;

0 commit comments

Comments
 (0)