Skip to content

Commit b4abe38

Browse files
chleroympe
authored andcommitted
powerpc/32: prepare shadow area for KASAN
This patch prepares a shadow area for KASAN. The shadow area will be at the top of the kernel virtual memory space above the fixmap area and will occupy one eighth of the total kernel virtual memory space. Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent a67beca commit b4abe38

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-0
lines changed

arch/powerpc/Kconfig.debug

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,3 +366,8 @@ config PPC_FAST_ENDIAN_SWITCH
366366
depends on DEBUG_KERNEL && PPC_BOOK3S_64
367367
help
368368
If you're unsure what this is, say N.
369+
370+
config KASAN_SHADOW_OFFSET
371+
hex
372+
depends on KASAN
373+
default 0xe0000000

arch/powerpc/include/asm/fixmap.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@
2222
#include <asm/kmap_types.h>
2323
#endif
2424

25+
#ifdef CONFIG_KASAN
26+
#include <asm/kasan.h>
27+
#define FIXADDR_TOP (KASAN_SHADOW_START - PAGE_SIZE)
28+
#else
2529
#define FIXADDR_TOP ((unsigned long)(-PAGE_SIZE))
30+
#endif
2631

2732
/*
2833
* Here we define all the compile-time 'special' virtual

arch/powerpc/include/asm/kasan.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,20 @@
1212
#define EXPORT_SYMBOL_KASAN(fn)
1313
#endif
1414

15+
#ifndef __ASSEMBLY__
16+
17+
#include <asm/page.h>
18+
19+
#define KASAN_SHADOW_SCALE_SHIFT 3
20+
21+
#define KASAN_SHADOW_START (KASAN_SHADOW_OFFSET + \
22+
(PAGE_OFFSET >> KASAN_SHADOW_SCALE_SHIFT))
23+
24+
#define KASAN_SHADOW_OFFSET ASM_CONST(CONFIG_KASAN_SHADOW_OFFSET)
25+
26+
#define KASAN_SHADOW_END 0UL
27+
28+
#define KASAN_SHADOW_SIZE (KASAN_SHADOW_END - KASAN_SHADOW_START)
29+
30+
#endif /* __ASSEMBLY */
1531
#endif

arch/powerpc/mm/mem.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ void __init mem_init(void)
310310
mem_init_print_info(NULL);
311311
#ifdef CONFIG_PPC32
312312
pr_info("Kernel virtual memory layout:\n");
313+
#ifdef CONFIG_KASAN
314+
pr_info(" * 0x%08lx..0x%08lx : kasan shadow mem\n",
315+
KASAN_SHADOW_START, KASAN_SHADOW_END);
316+
#endif
313317
pr_info(" * 0x%08lx..0x%08lx : fixmap\n", FIXADDR_START, FIXADDR_TOP);
314318
#ifdef CONFIG_HIGHMEM
315319
pr_info(" * 0x%08lx..0x%08lx : highmem PTEs\n",

arch/powerpc/mm/ptdump/ptdump.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ static struct addr_marker address_markers[] = {
100100
#endif
101101
{ 0, "Fixmap start" },
102102
{ 0, "Fixmap end" },
103+
#endif
104+
#ifdef CONFIG_KASAN
105+
{ 0, "kasan shadow mem start" },
106+
{ 0, "kasan shadow mem end" },
103107
#endif
104108
{ -1, NULL },
105109
};
@@ -323,6 +327,10 @@ static void populate_markers(void)
323327
#endif
324328
address_markers[i++].start_address = FIXADDR_START;
325329
address_markers[i++].start_address = FIXADDR_TOP;
330+
#ifdef CONFIG_KASAN
331+
address_markers[i++].start_address = KASAN_SHADOW_START;
332+
address_markers[i++].start_address = KASAN_SHADOW_END;
333+
#endif
326334
#endif /* CONFIG_PPC64 */
327335
}
328336

0 commit comments

Comments
 (0)