Skip to contentSkip to conversation

kunit: build kunit tests without structleak plugin

PATCH Superseded Brendan Higgins 6 participants 23 messages Sep 17, 2021 – Sep 29, 2021

Subsystems (9)
USB Kbuild Kselftest Library code +5 more subsystems

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover kunit: build kunit tests without structleak plugin

The structleak plugin causes the stack frame size to grow immensely when used with KUnit; this is caused because KUnit allocates lots of moderately sized structs on the stack as part of its assertion macro implementation. For most tests with small to moderately sized tests cases there are never enough KUnit assertions to be an issue at all; even when a single test cases has many KUnit assertions, the compiler should never put all these struct allocations on the stack at the same time since the scope of the structs is so limited; however, the structleak plugin does not seem to respect the compiler doing the right thing and will still warn of excessive stack size in some cases.

These patches are not a permanent solution since new tests can be added with huge test cases, but this serves as a stop gap to stop structleak from being used on KUnit tests which will currently result in excessive stack size.

Of the following patches, I think the thunderbolt patch may be unnecessary since Linus already fixed that test. Additionally, I was not able to reproduce the error on the sdhci-of-aspeed test. Nevertheless, I included these tests cases for completeness. Please see my discussion with Arnd for more context[1].

NOTE: Arnd did the legwork for most of these patches, but did not actually share code for some of them, so I left his Signed-off-by off of those patches as I don't want to misrepresent him. Arnd, please sign off on those patches at your soonest convenience.

[1] https://lore.kernel.org/linux-arm-kernel/CAFd5g44udqkDiYBWh+VeDVJ=ELXeoXwunjv0f9frEN6HJODZng@mail.gmail.com/

Arnd Bergmann (1):
bitfield: build kunit tests without structleak plugin

Brendan Higgins (5):
gcc-plugins/structleak: add makefile var for disabling structleak iio/test-format: build kunit tests without structleak plugin device property: build kunit tests without structleak plugin
thunderbolt: build kunit tests without structleak plugin
mmc: sdhci-of-aspeed: build kunit tests without structleak plugin

 drivers/base/test/Makefile   | 2 +-
 drivers/iio/test/Makefile    | 1 +
 drivers/mmc/host/Makefile    | 1 +
 drivers/thunderbolt/Makefile | 1 +
 lib/Makefile                 | 2 +-
 scripts/Makefile.gcc-plugins | 4 ++++
 6 files changed, 9 insertions(+), 2 deletions(-)

base-commit: 316346243be6df12799c0b64b788e06bad97c30b

Signature · 1 line
2.33.0.464.g1972c5931b-goog
#1 lore raw

PATCH 1/6 gcc-plugins/structleak: add makefile var for disabling structleak

KUnit and structleak don't play nice, so add a makefile variable for enabling structleak when it complains.

---
 scripts/Makefile.gcc-plugins | 4 ++++
 1 file changed, 4 insertions(+)
scripts/Makefile.gcc-plugins +4 -0
index 952e46876329a..4aad284800355 100644
@@ -19,6 +19,10 @@ gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF)		\
 		+= -fplugin-arg-structleak_plugin-byref
 gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL)	\
 		+= -fplugin-arg-structleak_plugin-byref-all
+ifdef CONFIG_GCC_PLUGIN_STRUCTLEAK
+    DISABLE_STRUCTLEAK_PLUGIN += -fplugin-arg-structleak_plugin-disable
+endif
+export DISABLE_STRUCTLEAK_PLUGIN
 gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK)		\
 		+= -DSTRUCTLEAK_PLUGIN
 
Signature · 1 line
2.33.0.464.g1972c5931b-goog
#2 lore raw

Re: [PATCH v1 1/6] gcc-plugins/structleak: add makefile var for disabling structleak

Quoted 4 lines · Brendan Higgins

KUnit and structleak don't play nice, so add a makefile variable for enabling structleak when it complains.

For a C-d-b, also include a S-o-b:

But otherwise, yes, this is good. :)

-Kees

Quoted 23 lines
---
 scripts/Makefile.gcc-plugins | 4 ++++
 1 file changed, 4 insertions(+)
scripts/Makefile.gcc-plugins +4 -0
index 952e46876329a..4aad284800355 100644
@@ -19,6 +19,10 @@ gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF)		\
 		+= -fplugin-arg-structleak_plugin-byref
 gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL)	\
 		+= -fplugin-arg-structleak_plugin-byref-all
+ifdef CONFIG_GCC_PLUGIN_STRUCTLEAK
+    DISABLE_STRUCTLEAK_PLUGIN += -fplugin-arg-structleak_plugin-disable
+endif
+export DISABLE_STRUCTLEAK_PLUGIN
 gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK)		\
 		+= -DSTRUCTLEAK_PLUGIN
 
Signature · 1 line
2.33.0.464.g1972c5931b-goog
Signature · 1 line
Kees Cook
#3 lore raw

Re: [PATCH v1 1/6] gcc-plugins/structleak: add makefile var for disabling structleak

Quoted 5 lines · Kees Cook
Quoted 3 lines · Brendan Higgins

KUnit and structleak don't play nice, so add a makefile variable for enabling structleak when it complains.

Quoted 7 lines
Quoted 1 line

For a C-d-b, also include a S-o-b:

But otherwise, yes, this is good. :)

Yeah, I know that's necessary for the patch to be accepted, but in this case, I don't think your original version of this (it wasn't actually a patch) had a S-o-b on it, so I didn't want to say that you had signed off on something that you didn't.

I have run into this situation before and handled it this way - letting the co-developer sign off on the list. Is this something I should avoid in the future?

In any case, I will resubmit this now that I have your S-o-b.

Thanks!

#4 lore raw

PATCH 2/6 iio/test-format: build kunit tests without structleak plugin

In reply to Brendan Higgins

The structleak plugin causes the stack frame size to grow immensely when used with KUnit:

../drivers/iio/test/iio-test-format.c: In function ‘iio_test_iio_format_value_fixedpoint’:
../drivers/iio/test/iio-test-format.c:98:1: warning: the frame size of 2336 bytes is larger than 2048 bytes [-Wframe-larger-than=]

Turn it off in this file.

---
 drivers/iio/test/Makefile | 1 +
 1 file changed, 1 insertion(+)
drivers/iio/test/Makefile +1 -0
index f1099b4953014..467519a2027e5 100644
@@ -5,3 +5,4 @@
 
 # Keep in alphabetical order
 obj-$(CONFIG_IIO_TEST_FORMAT) += iio-test-format.o
+CFLAGS_iio-test-format.o += $(DISABLE_STRUCTLEAK_PLUGIN)
Signature · 1 line
2.33.0.464.g1972c5931b-goog
Reviewed-by on v1 2/6
#5 lore raw

Re: [PATCH v1 2/6] iio/test-format: build kunit tests without structleak plugin

Quoted 7 lines · Brendan Higgins

The structleak plugin causes the stack frame size to grow immensely when used with KUnit:

../drivers/iio/test/iio-test-format.c: In function ‘iio_test_iio_format_value_fixedpoint’:
../drivers/iio/test/iio-test-format.c:98:1: warning: the frame size of 2336 bytes is larger than 2048 bytes [-Wframe-larger-than=]

Turn it off in this file.

Given that these are all for KUnit tests, is it possible there are going to be other CONFIGs that will interact poorly (e.g. KASAN)? Maybe there needs to be a small level of indirection with something like:

DISABLE_UNDER_KUNIT := $(DISABLE_STRUCTLEAK_PLUGIN) export DISABLE_UNDER_KUNIT

then all of these become:

+CFLAGS_iio-test-format.o += $(DISABLE_UNDER_KUNIT)

Either way, I think these are fine to add.

Quoted 19 lines
---
 drivers/iio/test/Makefile | 1 +
 1 file changed, 1 insertion(+)
drivers/iio/test/Makefile +1 -0
index f1099b4953014..467519a2027e5 100644
@@ -5,3 +5,4 @@
 
 # Keep in alphabetical order
 obj-$(CONFIG_IIO_TEST_FORMAT) += iio-test-format.o
+CFLAGS_iio-test-format.o += $(DISABLE_STRUCTLEAK_PLUGIN)
Signature · 1 line
2.33.0.464.g1972c5931b-goog
Signature · 1 line
Kees Cook
#6 lore raw

Re: [PATCH v1 2/6] iio/test-format: build kunit tests without structleak plugin

Quoted 5 lines · Kees Cook
Quoted 3 lines · Brendan Higgins

The structleak plugin causes the stack frame size to grow immensely when used with KUnit:

Quoted 8 lines
Quoted 4 lines

../drivers/iio/test/iio-test-format.c: In function ‘iio_test_iio_format_value_fixedpoint’:
../drivers/iio/test/iio-test-format.c:98:1: warning: the frame size of 2336 bytes is larger than 2048 bytes [-Wframe-larger-than=]

Turn it off in this file.

Given that these are all for KUnit tests, is it possible there are going to be other CONFIGs that will interact poorly (e.g. KASAN)? Maybe there needs to be a small level of indirection with something like:

I don't think so. KASAN actually uses KUnit to test it, and we have experimented running KASAN alongside other KUnit tests for added protection and results have looked good.

I would be surprised if there are other CONFIGs other than things dealing with stack size that don't like KUnit.

Quoted 8 lines

DISABLE_UNDER_KUNIT := $(DISABLE_STRUCTLEAK_PLUGIN) export DISABLE_UNDER_KUNIT

then all of these become:

+CFLAGS_iio-test-format.o += $(DISABLE_UNDER_KUNIT)

Either way, I think these are fine to add.

I like your suggestion if we find other configs that don't like KUnit, but I don't think we have seen any others so far, so I think I will keep it as it is for now.

Quoted 25 lines
Quoted 17 lines
---
 drivers/iio/test/Makefile | 1 +
 1 file changed, 1 insertion(+)
drivers/iio/test/Makefile +1 -1
index f1099b4953014..467519a2027e5 100644
@@ -5,3 +5,4 @@
 
 # Keep in alphabetical order
 obj-$(CONFIG_IIO_TEST_FORMAT) += iio-test-format.o
+CFLAGS_iio-test-format.o += $(DISABLE_STRUCTLEAK_PLUGIN)
--
Quoted 2 lines

2.33.0.464.g1972c5931b-goog

--
Kees Cook

maintainer Acked-by on v1 2/6
#7 lore raw

Re: [PATCH v1 2/6] iio/test-format: build kunit tests without structleak plugin

In reply to Brendan Higgins
Quoted 10 lines · On Thu, 16 Sep 2021 23:11:00 -0700 Brendan Higgins <[email protected]>…

The structleak plugin causes the stack frame size to grow immensely when used with KUnit:

../drivers/iio/test/iio-test-format.c: In function ‘iio_test_iio_format_value_fixedpoint’:
../drivers/iio/test/iio-test-format.c:98:1: warning: the frame size of 2336 bytes is larger than 2048 bytes [-Wframe-larger-than=]

Turn it off in this file.

Quoted 13 lines
---
 drivers/iio/test/Makefile | 1 +
 1 file changed, 1 insertion(+)
drivers/iio/test/Makefile +1 -0
index f1099b4953014..467519a2027e5 100644
@@ -5,3 +5,4 @@
 
 # Keep in alphabetical order
 obj-$(CONFIG_IIO_TEST_FORMAT) += iio-test-format.o
+CFLAGS_iio-test-format.o += $(DISABLE_STRUCTLEAK_PLUGIN)
#8 lore raw

PATCH 3/6 device property: build kunit tests without structleak plugin

In reply to Brendan Higgins

The structleak plugin causes the stack frame size to grow immensely when used with KUnit:

../drivers/base/test/property-entry-test.c:492:1: warning: the frame size of 2832 bytes is larger than 2048 bytes [-Wframe-larger-than=] ../drivers/base/test/property-entry-test.c:322:1: warning: the frame size of 2080 bytes is larger than 2048 bytes [-Wframe-larger-than=] ../drivers/base/test/property-entry-test.c:250:1: warning: the frame size of 4976 bytes is larger than 2048 bytes [-Wframe-larger-than=] ../drivers/base/test/property-entry-test.c:115:1: warning: the frame size of 3280 bytes is larger than 2048 bytes [-Wframe-larger-than=]

Turn it off in this file.

---
 drivers/base/test/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/test/Makefile +1 -1
index 64b2f3d744d51..7f76fee6f989d 100644
@@ -2,4 +2,4 @@
 obj-$(CONFIG_TEST_ASYNC_DRIVER_PROBE)	+= test_async_driver_probe.o
 
 obj-$(CONFIG_DRIVER_PE_KUNIT_TEST) += property-entry-test.o
-CFLAGS_REMOVE_property-entry-test.o += -fplugin-arg-structleak_plugin-byref -fplugin-arg-structleak_plugin-byref-all
+CFLAGS_property-entry-test.o += $(DISABLE_STRUCTLEAK_PLUGIN)
Signature · 1 line
2.33.0.464.g1972c5931b-goog
Reviewed-by on v1 3/6
#9 lore raw

Re: [PATCH v1 3/6] device property: build kunit tests without structleak plugin

Quoted 8 lines · Brendan Higgins

The structleak plugin causes the stack frame size to grow immensely when used with KUnit:

../drivers/base/test/property-entry-test.c:492:1: warning: the frame size of 2832 bytes is larger than 2048 bytes [-Wframe-larger-than=] ../drivers/base/test/property-entry-test.c:322:1: warning: the frame size of 2080 bytes is larger than 2048 bytes [-Wframe-larger-than=] ../drivers/base/test/property-entry-test.c:250:1: warning: the frame size of 4976 bytes is larger than 2048 bytes [-Wframe-larger-than=] ../drivers/base/test/property-entry-test.c:115:1: warning: the frame size of 3280 bytes is larger than 2048 bytes [-Wframe-larger-than=]

Quoted 4 lines

Turn it off in this file.

Signature · 1 line
Kees Cook
#10 lore raw

PATCH 4/6 thunderbolt: build kunit tests without structleak plugin

In reply to Brendan Higgins

The structleak plugin causes the stack frame size to grow immensely when used with KUnit:

drivers/thunderbolt/test.c:1529:1: error: the frame size of 1176 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]

Turn it off in this file.

Linus already split up tests in this file, so this change *should* be redundant now.

---
 drivers/thunderbolt/Makefile | 1 +
 1 file changed, 1 insertion(+)
drivers/thunderbolt/Makefile +1 -0
index da19d7987d005..78fd365893c13 100644
@@ -7,6 +7,7 @@ thunderbolt-objs += usb4_port.o nvm.o retimer.o quirks.o
 thunderbolt-${CONFIG_ACPI} += acpi.o
 thunderbolt-$(CONFIG_DEBUG_FS) += debugfs.o
 thunderbolt-${CONFIG_USB4_KUNIT_TEST} += test.o
+CFLAGS_test.o += $(DISABLE_STRUCTLEAK_PLUGIN)
 
 thunderbolt_dma_test-${CONFIG_USB4_DMA_TEST} += dma_test.o
 obj-$(CONFIG_USB4_DMA_TEST) += thunderbolt_dma_test.o
Signature · 1 line
2.33.0.464.g1972c5931b-goog
Acked-by on v1 4/6
#11 lore raw

Re: [PATCH v1 4/6] thunderbolt: build kunit tests without structleak plugin

Quoted 5 lines · Brendan Higgins

The structleak plugin causes the stack frame size to grow immensely when used with KUnit:

drivers/thunderbolt/test.c:1529:1: error: the frame size of 1176 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]

Quoted 8 lines

Turn it off in this file.

Linus already split up tests in this file, so this change *should* be redundant now.

Reviewed-by on v1 4/6
#12 lore raw

Re: [PATCH v1 4/6] thunderbolt: build kunit tests without structleak plugin

In reply to Brendan Higgins
Quoted 5 lines · Brendan Higgins

The structleak plugin causes the stack frame size to grow immensely when used with KUnit:

drivers/thunderbolt/test.c:1529:1: error: the frame size of 1176 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]

Quoted 7 lines

Turn it off in this file.

Linus already split up tests in this file, so this change *should* be redundant now.

Signature · 1 line
Kees Cook
#13 lore raw

PATCH 5/6 mmc: sdhci-of-aspeed: build kunit tests without structleak plugin

In reply to Brendan Higgins

The structleak plugin causes the stack frame size to grow immensely when used with KUnit.

Turn it off.

---
 drivers/mmc/host/Makefile | 1 +
 1 file changed, 1 insertion(+)
drivers/mmc/host/Makefile +1 -0
index 14004cc09aaad..2ab083931f8fd 100644
@@ -85,6 +85,7 @@ obj-$(CONFIG_MMC_SDHCI_DOVE)		+= sdhci-dove.o
 obj-$(CONFIG_MMC_SDHCI_TEGRA)		+= sdhci-tegra.o
 obj-$(CONFIG_MMC_SDHCI_OF_ARASAN)	+= sdhci-of-arasan.o
 obj-$(CONFIG_MMC_SDHCI_OF_ASPEED)	+= sdhci-of-aspeed.o
+CFLAGS_sdhci-of-aspeed.o		+= $(DISABLE_STRUCTLEAK_PLUGIN)
 obj-$(CONFIG_MMC_SDHCI_OF_AT91)		+= sdhci-of-at91.o
 obj-$(CONFIG_MMC_SDHCI_OF_ESDHC)	+= sdhci-of-esdhc.o
 obj-$(CONFIG_MMC_SDHCI_OF_HLWD)		+= sdhci-of-hlwd.o
Signature · 1 line
2.33.0.464.g1972c5931b-goog
#14 lore raw

Re: [PATCH v1 5/6] mmc: sdhci-of-aspeed: build kunit tests without structleak plugin

Quoted 16 lines · Brendan Higgins

The structleak plugin causes the stack frame size to grow immensely when used with KUnit.

Turn it off.

---
 drivers/mmc/host/Makefile | 1 +
 1 file changed, 1 insertion(+)
drivers/mmc/host/Makefile +0 -0
index 14004cc09aaad..2ab083931f8fd 100644

drivers/mmc/host/Makefile obj-$(CONFIG_MMC_SDHCI_DOVE) += sdhci-dove.o · line 88

Quoted 4 lines
drivers/mmc/host/Makefile +1 -0
@@ -85,6 +85,7 @@ obj-$(CONFIG_MMC_SDHCI_DOVE)		+= sdhci-dove.o
 obj-$(CONFIG_MMC_SDHCI_TEGRA)		+= sdhci-tegra.o
 obj-$(CONFIG_MMC_SDHCI_OF_ARASAN)	+= sdhci-of-arasan.o
 obj-$(CONFIG_MMC_SDHCI_OF_ASPEED)	+= sdhci-of-aspeed.o
+CFLAGS_sdhci-of-aspeed.o		+= $(DISABLE_STRUCTLEAK_PLUGIN)

This isn't a stand-alone test object, so I'm less excited about disabling STRUCTLEAK here.

Quoted 6 lines
drivers/mmc/host/Makefile +0 -0
 obj-$(CONFIG_MMC_SDHCI_OF_AT91)		+= sdhci-of-at91.o
 obj-$(CONFIG_MMC_SDHCI_OF_ESDHC)	+= sdhci-of-esdhc.o
 obj-$(CONFIG_MMC_SDHCI_OF_HLWD)		+= sdhci-of-hlwd.o
Signature · 1 line
2.33.0.464.g1972c5931b-goog
Signature · 1 line
Kees Cook
#15 lore raw

Re: [PATCH v1 5/6] mmc: sdhci-of-aspeed: build kunit tests without structleak plugin

Quoted 3 lines · Kees Cook

This isn't a stand-alone test object, so I'm less excited about disabling STRUCTLEAK here.

Yeah, please don't do this for things that aren't pure tests. You're now disabling security measures (even if I hate the gcc plugins and hope they will go away).

Linus

#16 lore raw

Re: [PATCH v1 5/6] mmc: sdhci-of-aspeed: build kunit tests without structleak plugin

Quoted 9 lines · Linus Torvalds
Quoted 3 lines · Kees Cook

This isn't a stand-alone test object, so I'm less excited about disabling STRUCTLEAK here.

Yeah, please don't do this for things that aren't pure tests. You're now disabling security measures (even if I hate the gcc plugins and hope they will go away).

Oh, whoops, yeah, I shouldn't do that. I am just going to drop this patch entirely, as I wasn't able to reproduce the stack frame size issue on qemu anyway (as I mentioned on the cover letter).

Thanks for catching this.

Sorry!

#17 lore raw

PATCH 6/6 bitfield: build kunit tests without structleak plugin

In reply to Brendan Higgins

From: Arnd Bergmann <[email protected]>

The structleak plugin causes the stack frame size to grow immensely:

lib/bitfield_kunit.c: In function 'test_bitfields_constants':
lib/bitfield_kunit.c:93:1: error: the frame size of 7440 bytes is larger than 2048 bytes [-Werror=frame-larger-than=]

Turn it off in this file.

---
 lib/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/Makefile +1 -1
index 5efd1b435a37c..c93c4b59af969 100644
@@ -351,7 +351,7 @@ obj-$(CONFIG_OBJAGG) += objagg.o
 obj-$(CONFIG_PLDMFW) += pldmfw/
 
 # KUnit tests
-CFLAGS_bitfield_kunit.o := $(call cc-option,-Wframe-larger-than=10240)
+CFLAGS_bitfield_kunit.o := $(call cc-option,-Wframe-larger-than=10240) $(DISABLE_STRUCTLEAK_PLUGIN)
 obj-$(CONFIG_BITFIELD_KUNIT) += bitfield_kunit.o
 obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o
 obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o
Signature · 1 line
2.33.0.464.g1972c5931b-goog
#18 lore raw

Re: [PATCH v1 6/6] bitfield: build kunit tests without structleak plugin

Quoted 21 lines · Brendan Higgins

From: Arnd Bergmann <[email protected]>

The structleak plugin causes the stack frame size to grow immensely:

lib/bitfield_kunit.c: In function 'test_bitfields_constants':
lib/bitfield_kunit.c:93:1: error: the frame size of 7440 bytes is larger than 2048 bytes [-Werror=frame-larger-than=]

Turn it off in this file.

---
 lib/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/Makefile +0 -0
index 5efd1b435a37c..c93c4b59af969 100644

lib/Makefile obj-$(CONFIG_OBJAGG) += objagg.o · line 354

Quoted 5 lines
lib/Makefile +1 -1
@@ -351,7 +351,7 @@ obj-$(CONFIG_OBJAGG) += objagg.o
 obj-$(CONFIG_PLDMFW) += pldmfw/
 
 # KUnit tests
-CFLAGS_bitfield_kunit.o := $(call cc-option,-Wframe-larger-than=10240)
+CFLAGS_bitfield_kunit.o := $(call cc-option,-Wframe-larger-than=10240) $(DISABLE_STRUCTLEAK_PLUGIN)

I think the $(call cc-option,-Wframe-larger-than=10240) needs to be dropped here. This was not in my original patch and it is definitely broken on all architectures
with 8KB stack size or less if the function needs that much. What is the amount of actual stack usage you observe without this? If we still get a warning, then I think this needs to be fixed in the code.

Arnd

Reviewed-by
#19 lore raw

Re: [PATCH v1 6/6] bitfield: build kunit tests without structleak plugin

Quoted 25 lines · Arnd Bergmann
Quoted 23 lines · Brendan Higgins

From: Arnd Bergmann <[email protected]>

The structleak plugin causes the stack frame size to grow immensely:

lib/bitfield_kunit.c: In function 'test_bitfields_constants':
lib/bitfield_kunit.c:93:1: error: the frame size of 7440 bytes is larger than 2048 bytes [-Werror=frame-larger-than=]

Turn it off in this file.

---
 lib/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/Makefile +0 -0
index 5efd1b435a37c..c93c4b59af969 100644
@@ -351,7 +351,7 @@ obj-$(CONFIG_OBJAGG) += objagg.o
 obj-$(CONFIG_PLDMFW) += pldmfw/
 
Quoted 10 lines

lib/Makefile obj-$(CONFIG_OBJAGG) += objagg.o · line 354

Quoted 3 lines
lib/Makefile +1 -1
 # KUnit tests
-CFLAGS_bitfield_kunit.o := $(call cc-option,-Wframe-larger-than=10240)
+CFLAGS_bitfield_kunit.o := $(call cc-option,-Wframe-larger-than=10240) $(DISABLE_STRUCTLEAK_PLUGIN)

I think the $(call cc-option,-Wframe-larger-than=10240) needs to be dropped here. This was not in my original patch and it is definitely broken on all architectures
with 8KB stack size or less if the function needs that much. What is the amount of actual stack usage you observe without this? If we still get a warning, then I think this needs to be fixed in the code.

With the frame-larger-than dropped:

Signature · 1 line
Kees Cook
#20 lore raw

Re: [PATCH v1 6/6] bitfield: build kunit tests without structleak plugin

In reply to Arnd Bergmann
Quoted 26 lines · Arnd Bergmann
Quoted 23 lines · Brendan Higgins

From: Arnd Bergmann <[email protected]>

The structleak plugin causes the stack frame size to grow immensely:

lib/bitfield_kunit.c: In function 'test_bitfields_constants':
lib/bitfield_kunit.c:93:1: error: the frame size of 7440 bytes is larger than 2048 bytes [-Werror=frame-larger-than=]

Turn it off in this file.

---
 lib/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/Makefile +0 -0
index 5efd1b435a37c..c93c4b59af969 100644
@@ -351,7 +351,7 @@ obj-$(CONFIG_OBJAGG) += objagg.o
 obj-$(CONFIG_PLDMFW) += pldmfw/
 
Quoted 6 lines

lib/Makefile obj-$(CONFIG_OBJAGG) += objagg.o · line 354

Quoted 3 lines
lib/Makefile +1 -1
 # KUnit tests
-CFLAGS_bitfield_kunit.o := $(call cc-option,-Wframe-larger-than=10240)
+CFLAGS_bitfield_kunit.o := $(call cc-option,-Wframe-larger-than=10240) $(DISABLE_STRUCTLEAK_PLUGIN)

I think the $(call cc-option,-Wframe-larger-than=10240) needs to be dropped here. This was not in my original patch and it is definitely broken on

Ah, someone else put that there, so I just left it, but I can drop it.

Quoted 3 lines

all architectures
with 8KB stack size or less if the function needs that much. What is the amount of actual stack usage you observe without this?

Well STRUCTLEAK claims 7440 bytes, but I don't entirely believe that. Regardless, it is definitely less than 8KB.

Quoted 4 lines

If we still get a warning, then
I think this needs to be fixed in the code.

Arnd

Cheers

#21 lore raw
In reply to Brendan Higgins
Quoted 23 lines · Brendan Higgins

The structleak plugin causes the stack frame size to grow immensely when used with KUnit; this is caused because KUnit allocates lots of moderately sized structs on the stack as part of its assertion macro implementation. For most tests with small to moderately sized tests cases there are never enough KUnit assertions to be an issue at all; even when a single test cases has many KUnit assertions, the compiler should never put all these struct allocations on the stack at the same time since the scope of the structs is so limited; however, the structleak plugin does not seem to respect the compiler doing the right thing and will still warn of excessive stack size in some cases.

These patches are not a permanent solution since new tests can be added with huge test cases, but this serves as a stop gap to stop structleak from being used on KUnit tests which will currently result in excessive stack size.

Of the following patches, I think the thunderbolt patch may be unnecessary since Linus already fixed that test. Additionally, I was not able to reproduce the error on the sdhci-of-aspeed test. Nevertheless, I included these tests cases for completeness. Please see my discussion with Arnd for more context[1].

Quoted 4 lines

NOTE: Arnd did the legwork for most of these patches, but did not actually share code for some of them, so I left his Signed-off-by off of those patches as I don't want to misrepresent him. Arnd, please sign off on those patches at your soonest convenience.

Thanks a lot for picking up this work where I dropped the ball.

Patches 1-5 look good to me, and I replied on one remaining issue I see with patch 6. I think you did more work on these that I did, by doing a nice write-up and splitting them into separate patches with useful changelogs, you should keep authorship, and just change my S-o-b to Suggested-by.

If you prefer to keep me as the author, then the correct way would be to commit them with --author= to ensure that the author and first s-o-b match.

Arnd

#22 lore raw
Quoted 39 lines · Arnd Bergmann
Quoted 23 lines · Brendan Higgins

The structleak plugin causes the stack frame size to grow immensely when used with KUnit; this is caused because KUnit allocates lots of moderately sized structs on the stack as part of its assertion macro implementation. For most tests with small to moderately sized tests cases there are never enough KUnit assertions to be an issue at all; even when a single test cases has many KUnit assertions, the compiler should never put all these struct allocations on the stack at the same time since the scope of the structs is so limited; however, the structleak plugin does not seem to respect the compiler doing the right thing and will still warn of excessive stack size in some cases.

These patches are not a permanent solution since new tests can be added with huge test cases, but this serves as a stop gap to stop structleak from being used on KUnit tests which will currently result in excessive stack size.

Of the following patches, I think the thunderbolt patch may be unnecessary since Linus already fixed that test. Additionally, I was not able to reproduce the error on the sdhci-of-aspeed test. Nevertheless, I included these tests cases for completeness. Please see my discussion with Arnd for more context[1].

Quoted 4 lines

NOTE: Arnd did the legwork for most of these patches, but did not actually share code for some of them, so I left his Signed-off-by off of those patches as I don't want to misrepresent him. Arnd, please sign off on those patches at your soonest convenience.

Thanks a lot for picking up this work where I dropped the ball.

Patches 1-5 look good to me, and I replied on one remaining issue I see with patch 6. I think you did more work on these that I did, by doing a nice write-up and splitting them into separate patches with useful changelogs, you should keep authorship, and just change my S-o-b to Suggested-by.

Quoted 3 lines

If you prefer to keep me as the author, then the correct way would be to commit them with --author= to ensure that the author and first s-o-b match.

Sounds good. I will keep the one that has you as the author since I just rebased it, but I will move you to Suggested-by on the others.

Thanks!