Skip to content

Commit cfb10de

Browse files
Alexandre Ghitipalmer-dabbelt
authored andcommitted
riscv: Fix kernel stack size when KASAN is enabled
We use Kconfig to select the kernel stack size, doubling the default size if KASAN is enabled. But that actually only works if KASAN is selected from the beginning, meaning that if KASAN config is added later (for example using menuconfig), CONFIG_THREAD_SIZE_ORDER won't be updated, keeping the default size, which is not enough for KASAN as reported in [1]. So fix this by moving the logic to compute the right kernel stack into a header. Fixes: a7555f6 ("riscv: stack: Add config of thread stack size") Reported-by: [email protected] Closes: https://lore.kernel.org/all/[email protected]/ [1] Cc: [email protected] Signed-off-by: Alexandre Ghiti <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent c625154 commit cfb10de

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

arch/riscv/Kconfig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,7 @@ config IRQ_STACKS
777777
config THREAD_SIZE_ORDER
778778
int "Kernel stack size (in power-of-two numbers of page size)" if VMAP_STACK && EXPERT
779779
range 0 4
780-
default 1 if 32BIT && !KASAN
781-
default 3 if 64BIT && KASAN
780+
default 1 if 32BIT
782781
default 2
783782
help
784783
Specify the Pages of thread stack size (from 4KB to 64KB), which also

arch/riscv/include/asm/thread_info.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
#include <linux/sizes.h>
1414

1515
/* thread information allocation */
16-
#define THREAD_SIZE_ORDER CONFIG_THREAD_SIZE_ORDER
16+
#ifdef CONFIG_KASAN
17+
#define KASAN_STACK_ORDER 1
18+
#else
19+
#define KASAN_STACK_ORDER 0
20+
#endif
21+
#define THREAD_SIZE_ORDER (CONFIG_THREAD_SIZE_ORDER + KASAN_STACK_ORDER)
1722
#define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
1823

1924
/*

0 commit comments

Comments
 (0)