Skip to contentSkip to conversation

Kbuild: change CONFIG_FRAME_WARN for 32-bit

RFC PATCH In review Arnd Bergmann 3 participants 3 messages Jun 17, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Kbuild: change CONFIG_FRAME_WARN for 32-bit

From: Arnd Bergmann <[email protected]>

The introduction of CONFIG_GCC_PLUGIN_LATENT_ENTROPY raised the warning limit for 32-bit architectures to a much higher value in 2016. Initially this had no effect for Arm machines as their kernels tend to be cross-compiled, and the feature detection for the plugin did not work with common cross compilers.

I could not find the original regression report that led to the warning limit getting raised, but I have been unable to reproduce this with gcc-12 and linux-5.18 -- all frame sizes appear to be be below the normal 1024 byte limit on at least arm32 and i386.

However, the KASAN feature introduced later on does raise the frame size of a number of functions above the warning limit, in almost all cases to somewhere below 1280 bytes. The effect is that an arm allmodconfig build produces no warnings because of the check for the latent entropy plugin, but a normal KASAN based build with gcc does produce build warnings or failures when CONFIG_WERROR is set.

The 1280 byte limit is an arbitrary choice here, as it disables almost all warnings but leaves a few outliers that are probably better addressed with code changes. There are a number of functions that are just below the normal 1024 byte limit at the moment, and an extra 256 bytes for those is within the expectation, but more than that is probably an indication of a bad design or a real bug.

Cc Uwe Kleine-König <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Kees Cook <[email protected]>
---
 lib/Kconfig.debug | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/Kconfig.debug +1 -1
index 3da5f9acb966..8a3afd837e99 100644
@@ -387,9 +387,9 @@ endif # DEBUG_INFO
 config FRAME_WARN
 	int "Warn for stack frames larger than"
 	range 0 8192
-	default 2048 if GCC_PLUGIN_LATENT_ENTROPY
 	default 2048 if PARISC
 	default 1536 if (!64BIT && XTENSA)
+	default 1280 if (!64BIT && KASAN_STACK)
 	default 1024 if !64BIT
 	default 2048 if 64BIT
 	help
Signature · 1 line
2.29.2
Acked-by on v1 1/1
#1 lore raw

Hello Arnd,

your To: was empty, I wonder if that was on purpose?!

Quoted 41 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The introduction of CONFIG_GCC_PLUGIN_LATENT_ENTROPY raised the warning limit for 32-bit architectures to a much higher value in 2016. Initially this had no effect for Arm machines as their kernels tend to be cross-compiled, and the feature detection for the plugin did not work with common cross compilers.

I could not find the original regression report that led to the warning limit getting raised, but I have been unable to reproduce this with gcc-12 and linux-5.18 -- all frame sizes appear to be be below the normal 1024 byte limit on at least arm32 and i386.

However, the KASAN feature introduced later on does raise the frame size of a number of functions above the warning limit, in almost all cases to somewhere below 1280 bytes. The effect is that an arm allmodconfig build produces no warnings because of the check for the latent entropy plugin, but a normal KASAN based build with gcc does produce build warnings or failures when CONFIG_WERROR is set.

The 1280 byte limit is an arbitrary choice here, as it disables almost all warnings but leaves a few outliers that are probably better addressed with code changes. There are a number of functions that are just below the normal 1024 byte limit at the moment, and an extra 256 bytes for those is within the expectation, but more than that is probably an indication of a bad design or a real bug.

Cc Uwe Kleine-König <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Kees Cook <[email protected]>
---
 lib/Kconfig.debug | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/Kconfig.debug +0 -0
index 3da5f9acb966..8a3afd837e99 100644

lib/Kconfig.debug endif # DEBUG_INFO · line 395

Quoted 10 lines
lib/Kconfig.debug +1 -1
@@ -387,9 +387,9 @@ endif # DEBUG_INFO
 config FRAME_WARN
 	int "Warn for stack frames larger than"
 	range 0 8192
-	default 2048 if GCC_PLUGIN_LATENT_ENTROPY
 	default 2048 if PARISC
 	default 1536 if (!64BIT && XTENSA)
+	default 1280 if (!64BIT && KASAN_STACK)
 	default 1024 if !64BIT
 	default 2048 if 64BIT
 	help

I wasn't aware this was configurable with a Kconfig symbol.

Thanks for addressing that issue, the reasoning looks good and right. I just now noticed you explained your findings earlier in irc, only found them because I digged my irc logs for my original report to you.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
#2 lore raw
In reply to Arnd Bergmann

Hi Arnd,

Quoted 41 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The introduction of CONFIG_GCC_PLUGIN_LATENT_ENTROPY raised the warning limit for 32-bit architectures to a much higher value in 2016. Initially this had no effect for Arm machines as their kernels tend to be cross-compiled, and the feature detection for the plugin did not work with common cross compilers.

I could not find the original regression report that led to the warning limit getting raised, but I have been unable to reproduce this with gcc-12 and linux-5.18 -- all frame sizes appear to be be below the normal 1024 byte limit on at least arm32 and i386.

However, the KASAN feature introduced later on does raise the frame size of a number of functions above the warning limit, in almost all cases to somewhere below 1280 bytes. The effect is that an arm allmodconfig build produces no warnings because of the check for the latent entropy plugin, but a normal KASAN based build with gcc does produce build warnings or failures when CONFIG_WERROR is set.

The 1280 byte limit is an arbitrary choice here, as it disables almost all warnings but leaves a few outliers that are probably better addressed with code changes. There are a number of functions that are just below the normal 1024 byte limit at the moment, and an extra 256 bytes for those is within the expectation, but more than that is probably an indication of a bad design or a real bug.

Cc Uwe Kleine-König <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Kees Cook <[email protected]>
---
 lib/Kconfig.debug | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/Kconfig.debug +0 -0
index 3da5f9acb966..8a3afd837e99 100644

lib/Kconfig.debug endif # DEBUG_INFO · line 392

Quoted 7 lines
lib/Kconfig.debug +1 -1
@@ -387,9 +387,9 @@ endif # DEBUG_INFO
 config FRAME_WARN
 	int "Warn for stack frames larger than"
 	range 0 8192
-	default 2048 if GCC_PLUGIN_LATENT_ENTROPY
 	default 2048 if PARISC
 	default 1536 if (!64BIT && XTENSA)
+	default 1280 if (!64BIT && KASAN_STACK)

For what it's worth, if this was changed to just KASAN, this would improve the situation for clang and ARCH=arm allmodconfig as well. It leaves just two -Wframe-larger-than warnings in drivers/gpu/drm/amd/display, which can be worked around with a kernel side change:

https://github.com/ClangBuiltLinux/linux/issues/1455#issuecomment-995337569

Cheers,
Nathan