Skip to contentSkip to conversation

xtensa: Increase size of gcc stack frame check

PATCH In review Guenter Roeck 3 participants 9 messages Sep 12, 2021 – Sep 14, 2021 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xtensa: Increase size of gcc stack frame check

xtensa frame size is larger than the frame size for almost all other architectures. This results in more than 50 "the frame size of <n> is larger than 1024 bytes" errors when trying to build xtensa:allmodconfig.

Increase frame size for xtensa to 1536 bytes to avoid compile errors due to frame size limits.

Cc Chris Zankel <[email protected]>
Cc Max Filippov <[email protected]>
---
 lib/Kconfig.debug | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/Kconfig.debug +1 -1
index ed4a31e34098..afad11e57d6b 100644
@@ -346,7 +346,7 @@ config FRAME_WARN
 	int "Warn for stack frames larger than"
 	range 0 8192
 	default 2048 if GCC_PLUGIN_LATENT_ENTROPY
-	default 1536 if (!64BIT && PARISC)
+	default 1536 if (!64BIT && (PARISC || XTENSA))
 	default 1024 if (!64BIT && !PARISC)
 	default 2048 if 64BIT
 	help
Signature · 1 line
2.33.0
#1 lore raw
Quoted 20 lines · Guenter Roeck

xtensa frame size is larger than the frame size for almost all other architectures. This results in more than 50 "the frame size of <n> is larger than 1024 bytes" errors when trying to build xtensa:allmodconfig.

Increase frame size for xtensa to 1536 bytes to avoid compile errors due to frame size limits.

Cc Chris Zankel <[email protected]>
Cc Max Filippov <[email protected]>
---
 lib/Kconfig.debug | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/Kconfig.debug +0 -0
index ed4a31e34098..afad11e57d6b 100644

lib/Kconfig.debug config FRAME_WARN · line 350

Quoted 6 lines
lib/Kconfig.debug +1 -1
@@ -346,7 +346,7 @@ config FRAME_WARN
        int "Warn for stack frames larger than"
        range 0 8192
        default 2048 if GCC_PLUGIN_LATENT_ENTROPY
-       default 1536 if (!64BIT && PARISC)
+       default 1536 if (!64BIT && (PARISC || XTENSA))
        default 1024 if (!64BIT && !PARISC)

Shouldn't that line also be changed to
default 1024 if (!64BIT && !(PARISC || XTENSA))
?

Quoted 5 lines
lib/Kconfig.debug +0 -1
        default 2048 if 64BIT
        help
--

2.33.0

Signature · 2 lines
Thanks.
-- Max
#2 lore raw
Quoted 16 lines · Max Filippov
Quoted 15 lines · Guenter Roeck

xtensa frame size is larger than the frame size for almost all other architectures. This results in more than 50 "the frame size of <n> is larger than 1024 bytes" errors when trying to build xtensa:allmodconfig.

Increase frame size for xtensa to 1536 bytes to avoid compile errors due to frame size limits.

Cc Chris Zankel <[email protected]>
Cc Max Filippov <[email protected]>
---
  lib/Kconfig.debug | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

lib/Kconfig.debug config FRAME_WARN · line 350

Quoted 11 lines
lib/Kconfig.debug +1 -1
index ed4a31e34098..afad11e57d6b 100644
@@ -346,7 +346,7 @@ config FRAME_WARN
         int "Warn for stack frames larger than"
         range 0 8192
         default 2048 if GCC_PLUGIN_LATENT_ENTROPY
-       default 1536 if (!64BIT && PARISC)
+       default 1536 if (!64BIT && (PARISC || XTENSA))
         default 1024 if (!64BIT && !PARISC)

Shouldn't that line also be changed to
default 1024 if (!64BIT && !(PARISC || XTENSA))
?

I could do that, but I tested it and it looks like the evaluation is top-down, so it didn't seem necessary or useful. For example, the default value is 2048 for 32-bit systems (such as arm, riscv32, or i386) if GCC_PLUGIN_LATENT_ENTROPY is enabled, even though the line with the default of 1024 matches as well.

Thanks,
Guenter

Reviewed-by
#3 lore raw
Quoted 34 lines · Guenter Roeck
Quoted 16 lines · Max Filippov
Quoted 15 lines · Guenter Roeck

xtensa frame size is larger than the frame size for almost all other architectures. This results in more than 50 "the frame size of <n> is larger than 1024 bytes" errors when trying to build xtensa:allmodconfig.

Increase frame size for xtensa to 1536 bytes to avoid compile errors due to frame size limits.

Cc Chris Zankel <[email protected]>
Cc Max Filippov <[email protected]>
---
  lib/Kconfig.debug | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

lib/Kconfig.debug config FRAME_WARN · line 350

Quoted 11 lines
lib/Kconfig.debug +1 -1
index ed4a31e34098..afad11e57d6b 100644
@@ -346,7 +346,7 @@ config FRAME_WARN
         int "Warn for stack frames larger than"
         range 0 8192
         default 2048 if GCC_PLUGIN_LATENT_ENTROPY
-       default 1536 if (!64BIT && PARISC)
+       default 1536 if (!64BIT && (PARISC || XTENSA))
         default 1024 if (!64BIT && !PARISC)

Shouldn't that line also be changed to
default 1024 if (!64BIT && !(PARISC || XTENSA))
?

Quoted 5 lines

I could do that, but I tested it and it looks like the evaluation is top-down, so it didn't seem necessary or useful. For example, the default value is 2048 for 32-bit systems (such as arm, riscv32, or i386) if GCC_PLUGIN_LATENT_ENTROPY is enabled, even though the line with the default of 1024 matches as well.

Signature · 2 lines
Thanks.
-- Max
#4 lore raw
In reply to Guenter Roeck

From: Guenter Roeck

Quoted 8 lines

Sent: 12 September 2021 03:53

xtensa frame size is larger than the frame size for almost all other architectures. This results in more than 50 "the frame size of <n> is larger than 1024 bytes" errors when trying to build xtensa:allmodconfig.

Increase frame size for xtensa to 1536 bytes to avoid compile errors due to frame size limits.

Have you done anything to check what happens at run-time? I'd guess that the deepest stack use is inside printk() in some obscure error path.

In reality all these 1k+ stack frames need killing rather than the limit for the compiler warning increased.

While it may be sensible for a system call entry function so allocate a reasonable size buffer on stack (as poll() and sendmsg() probably do) allocating big buffers way down the call stack could easily cause stack overflow. Even a 1k stack frame is huge.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

#5 lore raw
Quoted 14 lines · David Laight

From: Guenter Roeck

Quoted 8 lines

Sent: 12 September 2021 03:53

xtensa frame size is larger than the frame size for almost all other architectures. This results in more than 50 "the frame size of <n> is larger than 1024 bytes" errors when trying to build xtensa:allmodconfig.

Increase frame size for xtensa to 1536 bytes to avoid compile errors due to frame size limits.

Have you done anything to check what happens at run-time? I'd guess that the deepest stack use is inside printk() in some obscure error path.

Quoted 9 lines

In reality all these 1k+ stack frames need killing rather than the limit for the compiler warning increased.

While it may be sensible for a system call entry function so allocate a reasonable size buffer on stack (as poll() and sendmsg() probably do) allocating big buffers way down the call stack could easily cause stack overflow. Even a 1k stack frame is huge.

The functions I checked typically have pretty large local data (like, more than 700-800 bytes). The errors are only observed with xtensa:allmodconfig test builds. While it may be arguable if those functions really need that much data on the stack, it is unreasonable to assume that all those errors (again, more than 50) are ever going to get fixed, especially since the errors are only seen with xtensa and not with any other architecture (including parisc; setting a stack limit of 1024 works just fine with that architecture, at least with gcc 11.x). So the realistic options are:

1) accept this or a similar patch
2) stop build testing xtensa:allmodconfig
3) Manually disable CONFIG_WERROR when test building xtensa:allmodconfig

As it looks like, I'll probably implement option 3) in my test builds. I planned to start doing that around v5.15-rc4/rc5, but I may do it earlier if it is becoming obvious that the now-errors won't get fixed.

Guenter

#6 lore raw
Quoted 7 lines · Guenter Roeck

The functions I checked typically have pretty large local data (like, more than 700-800 bytes). The errors are only observed with xtensa:allmodconfig test builds. While it may be arguable if those functions really need that much data on the stack, it is unreasonable to assume that all those errors (again, more than 50) are ever going to get fixed, especially since the errors are only seen with xtensa and not with any other architecture

That's not what I observe. If I build allmodconfig on v5.15-rc1 for arm with gcc-8.3 I get 69 of them.

Quoted 2 lines

(including parisc; setting a stack limit of 1024 works just fine with that architecture, at least with gcc 11.x). So the realistic

This comparison is a bit biased because allmodconfig on xtensa enables KASAN which is not supported by the parisc. Disabling KASAN roughly halves the size of stack frames for a few instances that I've checked.

Signature · 2 lines
Thanks.
-- Max
#7 lore raw
Quoted 9 lines · Max Filippov
Quoted 7 lines · Guenter Roeck

The functions I checked typically have pretty large local data (like, more than 700-800 bytes). The errors are only observed with xtensa:allmodconfig test builds. While it may be arguable if those functions really need that much data on the stack, it is unreasonable to assume that all those errors (again, more than 50) are ever going to get fixed, especially since the errors are only seen with xtensa and not with any other architecture

Quoted 3 lines

That's not what I observe. If I build allmodconfig on v5.15-rc1 for arm with gcc-8.3 I get 69 of them.

Interesting. I had used gcc 11.2. Anyway, arm:allmodconfig sets the limit to 2048 for me, for both gcc 8.3 and 11.2, due to GCC_PLUGIN_LATENT_ENTROPY=y. But you are right, if I disable GCC_PLUGIN_LATENT_ENTROPY and set the frame size to 1024, I get lots of frame size errors on arm as well.

Quoted 8 lines
Quoted 2 lines

(including parisc; setting a stack limit of 1024 works just fine with that architecture, at least with gcc 11.x). So the realistic

This comparison is a bit biased because allmodconfig on xtensa enables KASAN which is not supported by the parisc. Disabling KASAN roughly halves the size of stack frames for a few instances that I've checked.

It wasn't meant to be biased or unbiased, just a (surprising) observation. Maybe there is some configuration in parisc that is not enabled with allmodconfig which increases the frame size.

I still don't think that those stack limit warnings (now errors) will ever get fixed. Which is the point I was trying to make, and your observation that the stack frames are really that large because of KASAN just makes that argument stronger.

Other than that, it is not my call to make that to do with this patch. If you think that it is inappropriate, by all means reject it.

Thanks,
Guenter

#8 lore raw
Quoted 8 lines · Guenter Roeck

I still don't think that those stack limit warnings (now errors) will ever get fixed. Which is the point I was trying to make, and your observation that the stack frames are really that large because of KASAN just makes that argument stronger.

Other than that, it is not my call to make that to do with this patch. If you think that it is inappropriate, by all means reject it.

I like it, also for the reason that with KASAN enabled kernel stack size on xtensa is 4 times bigger.

Signature · 2 lines
Thanks.
-- Max