Re: [PATCH] powerpc/Kconfig: Force THREAD_SHIFT to at least 14 with KASAN

From: Christophe Leroy
Date: Tue May 31 2022 - 06:41:12 EST




Le 31/05/2022 à 09:41, Christoph Hellwig a écrit :
> On Tue, May 31, 2022 at 04:16:19PM +1000, Michael Ellerman wrote:
>> I was thinking of doing it in C, similar to the way arm64 handles it.
>>
>> Something like below. It means we always double the stack size when
>> KASAN is enabled. I think it's preferable, as it will always work
>> regardless of whether the user has an old .config (or is bisectting)?
>
> Is there any reason to even offer the Kconfig? It is super cryptic and
> just picking the right value directly in the header would seem much
> more sensible:

Looks like it was added by commit 476134070c03 ("powerpc: Move
THREAD_SHIFT config to Kconfig") in 2017.
https://github.com/torvalds/linux/commit/476134070c037820bd909ff6e43e0d3eae33f376

Seems like powerpc is the only architecture with it configurable via
Kconfig.

I'd be inclined to reverting that commit, and then I'd do something
similar to arm64:

#ifdef CONFIG_KSAN
#define KASAN_THREAD_SHIFT 1
#else
#define KASAN_THREAD_SHIFT 0
#endif

#if defined(CONFIG_PPC_256K_PAGES)
#define MIN_THREAD_SHIFT (15 + KASAN_THREAD_SHIFT)
#elif defined(CONFIG_PPC64)
#define MIN_THREAD_SHIFT (14 + KASAN_THREAD_SHIFT)
#else
#define MIN_THREAD_SHIFT (13 + KASAN_THREAD_SHIFT)
#endif

#if defined(CONFIG_VMAP_STACK) && (MIN_THREAD_SHIFT < PAGE_SHIFT)
#define THREAD_SHIFT PAGE_SHIFT
#else
#define THREAD_SHIFT MIN_THREAD_SHIFT
#endif


And maybe the CONFIG_PPC_256K_PAGES case is already big enough and
doesn't require the + 1 for KASAN.

>
> #if defined(CONFIG_PPC_256K_PAGES)
> #define MIN_THREAD_SHIFT 15
> #elif defined(CONFIG_PPC64)
> #define MIN_THREAD_SHIFT 14
> #else
> #define MIN_THREAD_SHIFT 13
> #endif
>
> #ifdef CONFIG_KASAN
> #define THREAD_SHIFT (MIN_THREAD_SHIFT + 1)
> #else
> #define THREAD_SHIFT MIN_THREAD_SHIFT
> #endif
>
> #if defined(CONFIG_VMAP_STACK) && THREAD_SHIFT < PAGE_SHIFT
> #undef THREAD_SHIFT
> #define THREAD_SHIFT PAGE_SHIFT
> #endif