LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2 0/5] kunit: build kunit tests without structleak plugin
@ 2021-09-29 21:27 Brendan Higgins
  2021-09-29 21:27 ` [PATCH v2 1/5] gcc-plugins/structleak: add makefile var for disabling structleak Brendan Higgins
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Brendan Higgins @ 2021-09-29 21:27 UTC (permalink / raw)
  To: shuah, davidgow, arnd, keescook, rafael, jic23, lars,
	ulf.hansson, andreas.noever, michael.jamet, mika.westerberg,
	YehezkelShB, masahiroy, michal.lkml, ndesaulniers
  Cc: linux-kselftest, kunit-dev, linux-kernel, torvalds, gregkh,
	linux-iio, linux-mmc, linux-usb, linux-hardening, linux-kbuild,
	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.

Please see the discussion thread here[1] for more context.

Changes since last revision:
 - Dropped mmc: sdhci-of-aspeed patch since it was not a pure test and I
   could not reproduce the stack size warning anyway.
 - Removed Wframe-larger-than=10240 warning from the bitfield kunit
   test.
 - All other patches are the same except with updated
   reviewers/contributor commit footers.

[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 (4):
  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

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


base-commit: 02d5e016800d082058b3d3b7c3ede136cdc6ddcb
-- 
2.33.0.685.g46640cef36-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/5] gcc-plugins/structleak: add makefile var for disabling structleak
  2021-09-29 21:27 [PATCH v2 0/5] kunit: build kunit tests without structleak plugin Brendan Higgins
@ 2021-09-29 21:27 ` Brendan Higgins
  2021-09-30  0:12   ` David Gow
  2021-09-29 21:27 ` [PATCH v2 2/5] iio/test-format: build kunit tests without structleak plugin Brendan Higgins
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Brendan Higgins @ 2021-09-29 21:27 UTC (permalink / raw)
  To: shuah, davidgow, arnd, keescook, rafael, jic23, lars,
	ulf.hansson, andreas.noever, michael.jamet, mika.westerberg,
	YehezkelShB, masahiroy, michal.lkml, ndesaulniers
  Cc: linux-kselftest, kunit-dev, linux-kernel, torvalds, gregkh,
	linux-iio, linux-mmc, linux-usb, linux-hardening, linux-kbuild,
	Brendan Higgins

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

Co-developed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
---
Changes since last revision:
 - None
---
 scripts/Makefile.gcc-plugins | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins
index 952e46876329a..4aad284800355 100644
--- a/scripts/Makefile.gcc-plugins
+++ b/scripts/Makefile.gcc-plugins
@@ -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
 
-- 
2.33.0.685.g46640cef36-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 2/5] iio/test-format: build kunit tests without structleak plugin
  2021-09-29 21:27 [PATCH v2 0/5] kunit: build kunit tests without structleak plugin Brendan Higgins
  2021-09-29 21:27 ` [PATCH v2 1/5] gcc-plugins/structleak: add makefile var for disabling structleak Brendan Higgins
@ 2021-09-29 21:27 ` Brendan Higgins
  2021-09-29 21:27 ` [PATCH v2 3/5] device property: " Brendan Higgins
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Brendan Higgins @ 2021-09-29 21:27 UTC (permalink / raw)
  To: shuah, davidgow, arnd, keescook, rafael, jic23, lars,
	ulf.hansson, andreas.noever, michael.jamet, mika.westerberg,
	YehezkelShB, masahiroy, michal.lkml, ndesaulniers
  Cc: linux-kselftest, kunit-dev, linux-kernel, torvalds, gregkh,
	linux-iio, linux-mmc, linux-usb, linux-hardening, linux-kbuild,
	Brendan Higgins, Jonathan Cameron

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.

Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
Suggested-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Kees Cook <keescook@chromium.org>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
Changes since last revision:
 - None
---
 drivers/iio/test/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/iio/test/Makefile b/drivers/iio/test/Makefile
index f1099b4953014..467519a2027e5 100644
--- a/drivers/iio/test/Makefile
+++ b/drivers/iio/test/Makefile
@@ -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)
-- 
2.33.0.685.g46640cef36-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 3/5] device property: build kunit tests without structleak plugin
  2021-09-29 21:27 [PATCH v2 0/5] kunit: build kunit tests without structleak plugin Brendan Higgins
  2021-09-29 21:27 ` [PATCH v2 1/5] gcc-plugins/structleak: add makefile var for disabling structleak Brendan Higgins
  2021-09-29 21:27 ` [PATCH v2 2/5] iio/test-format: build kunit tests without structleak plugin Brendan Higgins
@ 2021-09-29 21:27 ` Brendan Higgins
  2021-09-29 21:27 ` [PATCH v2 4/5] thunderbolt: " Brendan Higgins
  2021-09-29 21:27 ` [PATCH v2 5/5] bitfield: " Brendan Higgins
  4 siblings, 0 replies; 7+ messages in thread
From: Brendan Higgins @ 2021-09-29 21:27 UTC (permalink / raw)
  To: shuah, davidgow, arnd, keescook, rafael, jic23, lars,
	ulf.hansson, andreas.noever, michael.jamet, mika.westerberg,
	YehezkelShB, masahiroy, michal.lkml, ndesaulniers
  Cc: linux-kselftest, kunit-dev, linux-kernel, torvalds, gregkh,
	linux-iio, linux-mmc, linux-usb, linux-hardening, linux-kbuild,
	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.

Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
Suggested-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Kees Cook <keescook@chromium.org>
---
Changes since last revision:
 - None
---
 drivers/base/test/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/test/Makefile b/drivers/base/test/Makefile
index 64b2f3d744d51..7f76fee6f989d 100644
--- a/drivers/base/test/Makefile
+++ b/drivers/base/test/Makefile
@@ -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)
-- 
2.33.0.685.g46640cef36-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 4/5] thunderbolt: build kunit tests without structleak plugin
  2021-09-29 21:27 [PATCH v2 0/5] kunit: build kunit tests without structleak plugin Brendan Higgins
                   ` (2 preceding siblings ...)
  2021-09-29 21:27 ` [PATCH v2 3/5] device property: " Brendan Higgins
@ 2021-09-29 21:27 ` Brendan Higgins
  2021-09-29 21:27 ` [PATCH v2 5/5] bitfield: " Brendan Higgins
  4 siblings, 0 replies; 7+ messages in thread
From: Brendan Higgins @ 2021-09-29 21:27 UTC (permalink / raw)
  To: shuah, davidgow, arnd, keescook, rafael, jic23, lars,
	ulf.hansson, andreas.noever, michael.jamet, mika.westerberg,
	YehezkelShB, masahiroy, michal.lkml, ndesaulniers
  Cc: linux-kselftest, kunit-dev, linux-kernel, torvalds, gregkh,
	linux-iio, linux-mmc, linux-usb, linux-hardening, linux-kbuild,
	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.

Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
Suggested-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
---
Changes since last revision:
 - None
---
 drivers/thunderbolt/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/thunderbolt/Makefile b/drivers/thunderbolt/Makefile
index da19d7987d005..78fd365893c13 100644
--- a/drivers/thunderbolt/Makefile
+++ b/drivers/thunderbolt/Makefile
@@ -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
-- 
2.33.0.685.g46640cef36-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 5/5] bitfield: build kunit tests without structleak plugin
  2021-09-29 21:27 [PATCH v2 0/5] kunit: build kunit tests without structleak plugin Brendan Higgins
                   ` (3 preceding siblings ...)
  2021-09-29 21:27 ` [PATCH v2 4/5] thunderbolt: " Brendan Higgins
@ 2021-09-29 21:27 ` Brendan Higgins
  4 siblings, 0 replies; 7+ messages in thread
From: Brendan Higgins @ 2021-09-29 21:27 UTC (permalink / raw)
  To: shuah, davidgow, arnd, keescook, rafael, jic23, lars,
	ulf.hansson, andreas.noever, michael.jamet, mika.westerberg,
	YehezkelShB, masahiroy, michal.lkml, ndesaulniers
  Cc: linux-kselftest, kunit-dev, linux-kernel, torvalds, gregkh,
	linux-iio, linux-mmc, linux-usb, linux-hardening, linux-kbuild,
	Brendan Higgins

From: Arnd Bergmann <arnd@arndb.de>

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.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
---
Changes since last revision:
 - Dropped -Wframe-larger-than=10240 from CFLAGS.
---
 lib/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/Makefile b/lib/Makefile
index 5efd1b435a37c..a841be5244ac6 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -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 := $(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
-- 
2.33.0.685.g46640cef36-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/5] gcc-plugins/structleak: add makefile var for disabling structleak
  2021-09-29 21:27 ` [PATCH v2 1/5] gcc-plugins/structleak: add makefile var for disabling structleak Brendan Higgins
@ 2021-09-30  0:12   ` David Gow
  0 siblings, 0 replies; 7+ messages in thread
From: David Gow @ 2021-09-30  0:12 UTC (permalink / raw)
  To: Brendan Higgins
  Cc: Shuah Khan, Arnd Bergmann, Kees Cook, rafael, Jonathan Cameron,
	Lars-Peter Clausen, Ulf Hansson, andreas.noever, michael.jamet,
	Mika Westerberg, YehezkelShB, Masahiro Yamada, michal.lkml,
	Nick Desaulniers, open list:KERNEL SELFTEST FRAMEWORK,
	KUnit Development, Linux Kernel Mailing List, Linus Torvalds,
	Greg Kroah-Hartman, linux-iio, linux-mmc, linux-usb,
	linux-hardening, linux-kbuild

On Thu, Sep 30, 2021 at 5:27 AM Brendan Higgins
<brendanhiggins@google.com> wrote:
>
> KUnit and structleak don't play nice, so add a makefile variable for
> enabling structleak when it complains.
>
> Co-developed-by: Kees Cook <keescook@chromium.org>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
> ---
> Changes since last revision:
>  - None
> ---

This seems as sensible a way of working around this as we're going to
get in the short-term.

Reviewed-by: David Gow <davidgow@google.com>

Cheers,
-- David

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-09-30  0:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-29 21:27 [PATCH v2 0/5] kunit: build kunit tests without structleak plugin Brendan Higgins
2021-09-29 21:27 ` [PATCH v2 1/5] gcc-plugins/structleak: add makefile var for disabling structleak Brendan Higgins
2021-09-30  0:12   ` David Gow
2021-09-29 21:27 ` [PATCH v2 2/5] iio/test-format: build kunit tests without structleak plugin Brendan Higgins
2021-09-29 21:27 ` [PATCH v2 3/5] device property: " Brendan Higgins
2021-09-29 21:27 ` [PATCH v2 4/5] thunderbolt: " Brendan Higgins
2021-09-29 21:27 ` [PATCH v2 5/5] bitfield: " Brendan Higgins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).