Add support for suppressing warning backtraces
Subsystems (16)
v4 cover Add support for suppressing warning backtraces
Some unit tests intentionally trigger warning backtraces by passing bad parameters to kernel API functions. Such unit tests typically check the return value from such calls, not the existence of the warning backtrace.
Such intentionally generated warning backtraces are neither desirable nor useful for a number of reasons.
- They can result in overlooked real problems.
- A warning that suddenly starts to show up in unit tests needs to be investigated and has to be marked to be ignored, for example by adjusting filter scripts. Such filters are ad-hoc because there is no real standard format for warnings. On top of that, such filter scripts would require constant maintenance.
One option to address problem would be to add messages such as "expected warning backtraces start / end here" to the kernel log. However, that would again require filter scripts, it might result in missing real problematic warning backtraces triggered while the test is running, and the irrelevant backtrace(s) would still clog the kernel log.
Solve the problem by providing a means to identify and suppress specific warning backtraces while executing test code. Support suppressing multiple backtraces while at the same time limiting changes to generic code to the absolute minimum. Architecture specific changes are kept at minimum by retaining function names only if both CONFIG_DEBUG_BUGVERBOSE and CONFIG_KUNIT are enabled.
The first patch of the series introduces the necessary infrastructure. The second patch introduces support for counting suppressed backtraces. This capability is used in patch three to implement unit tests. Patch four documents the new API.
The next two patches add support for suppressing backtraces in drm_rect and dev_addr_lists unit tests. These patches are intended to serve as examples for the use of the functionality introduced with this series. The remaining patches implement the necessary changes for all architectures with GENERIC_BUG support.
With CONFIG_KUNIT enabled, image size increase with this series applied is approximately 1%. The image size increase (and with it the functionality introduced by this series) can be avoided by disabling CONFIG_KUNIT_SUPPRESS_BACKTRACE.
This series is based on the RFC patch and subsequent discussion at
https://patchwork.kernel.org/project/linux-kselftest/patch/[email protected]/
and offers a more comprehensive solution of the problem discussed there.
Design note:
Function pointers are only added to the __bug_table section if both CONFIG_KUNIT_SUPPRESS_BACKTRACE and CONFIG_DEBUG_BUGVERBOSE are enabled to avoid image size increases if CONFIG_KUNIT is disabled. There would be some benefits to adding those pointers all the time (reduced complexity, ability to display function names in BUG/WARNING messages). That change, if desired, can be made later.
Checkpatch note:
Remaining checkpatch errors and warnings were deliberately ignored. Some are triggered by matching coding style or by comments interpreted as code, others by assembler macros which are disliked by checkpatch. Suggestions for improvements are welcome.
Changes since RFC:
- Introduced CONFIG_KUNIT_SUPPRESS_BACKTRACE
- Minor cleanups and bug fixes
- Added support for all affected architectures
- Added support for counting suppressed warnings
- Added unit tests using those counters
- Added patch to suppress warning backtraces in dev_addr_lists tests
Changes since v1:
- Rebased to v6.9-rc1
- Added Tested-by:, Acked-by:, and Reviewed-by: tags
[I retained those tags since there have been no functional changes]
- Introduced KUNIT_SUPPRESS_BACKTRACE configuration option, enabled by default.
Changes since v2:
- Rebased to v6.9-rc2
- Added comments to drm warning suppression explaining why it is needed.
- Added patch to move conditional code in arch/sh/include/asm/bug.h to avoid kerneldoc warning
- Added architecture maintainers to Cc: for architecture specific patches
- No functional changes
Changes since v3:
- Rebased to v6.14-rc6
- Dropped net: "kunit: Suppress lock warning noise at end of dev_addr_lists tests" since 3db3b62955cd6d73afde05a17d7e8e106695c3b9
- Added __kunit_ and KUNIT_ prefixes.
- Tested on interessed architectures.
----
Guenter Roeck (14):
bug/kunit: Core support for suppressing warning backtraces
kunit: bug: Count suppressed warning backtraces
kunit: Add test cases for backtrace warning suppression
kunit: Add documentation for warning backtrace suppression API
drm: Suppress intentional warning backtraces in scaling unit tests
x86: Add support for suppressing warning backtraces
arm64: Add support for suppressing warning backtraces
loongarch: Add support for suppressing warning backtraces
parisc: Add support for suppressing warning backtraces
s390: Add support for suppressing warning backtraces
sh: Add support for suppressing warning backtraces
sh: Move defines needed for suppressing warning backtraces
riscv: Add support for suppressing warning backtraces
powerpc: Add support for suppressing warning backtraces
Documentation/dev-tools/kunit/usage.rst | 30 ++++++- arch/arm64/include/asm/asm-bug.h | 27 ++++-- arch/arm64/include/asm/bug.h | 8 +- arch/loongarch/include/asm/bug.h | 42 +++++++--- arch/parisc/include/asm/bug.h | 29 +++++-- arch/powerpc/include/asm/bug.h | 37 +++++++-- arch/riscv/include/asm/bug.h | 38 ++++++--- arch/s390/include/asm/bug.h | 17 +++- arch/sh/include/asm/bug.h | 28 ++++++- arch/x86/include/asm/bug.h | 21 +++-- drivers/gpu/drm/tests/drm_rect_test.c | 16 ++++ include/asm-generic/bug.h | 16 +++- include/kunit/bug.h | 56 +++++++++++++ include/kunit/test.h | 1 + include/linux/bug.h | 13 +++ lib/bug.c | 51 +++++++++++- lib/kunit/Kconfig | 9 ++ lib/kunit/Makefile | 7 +- lib/kunit/backtrace-suppression-test.c | 104 ++++++++++++++++++++++++ lib/kunit/bug.c | 42 ++++++++++ 20 files changed, 519 insertions(+), 73 deletions(-) create mode 100644 include/kunit/bug.h create mode 100644 lib/kunit/backtrace-suppression-test.c create mode 100644 lib/kunit/bug.c
Signature · 1 line
2.34.1
PATCH v4 1/14 bug/kunit: Core support for suppressing warning backtraces
From: Guenter Roeck <[email protected]>
Some unit tests intentionally trigger warning backtraces by passing bad parameters to API functions. Such unit tests typically check the return value from those calls, not the existence of the warning backtrace.
Such intentionally generated warning backtraces are neither desirable nor useful for a number of reasons.
- They can result in overlooked real problems.
- A warning that suddenly starts to show up in unit tests needs to be investigated and has to be marked to be ignored, for example by adjusting filter scripts. Such filters are ad-hoc because there is no real standard format for warnings. On top of that, such filter scripts would require constant maintenance.
One option to address problem would be to add messages such as "expected warning backtraces start / end here" to the kernel log. However, that would again require filter scripts, it might result in missing real problematic warning backtraces triggered while the test is running, and the irrelevant backtrace(s) would still clog the kernel log.
Solve the problem by providing a means to identify and suppress specific warning backtraces while executing test code. Since the new functionality results in an image size increase of about 1% if CONFIG_KUNIT is enabled, provide configuration option KUNIT_SUPPRESS_BACKTRACE to be able to disable the new functionality. This option is by default enabled since almost all systems with CONFIG_KUNIT enabled will want to benefit from it.
--- include/asm-generic/bug.h | 16 +++++++++--- include/kunit/bug.h | 51 +++++++++++++++++++++++++++++++++++++++ include/kunit/test.h | 1 + include/linux/bug.h | 13 ++++++++++ lib/bug.c | 51 ++++++++++++++++++++++++++++++++++++--- lib/kunit/Kconfig | 9 +++++++ lib/kunit/Makefile | 6 +++-- lib/kunit/bug.c | 40 ++++++++++++++++++++++++++++++ 8 files changed, 178 insertions(+), 9 deletions(-) create mode 100644 include/kunit/bug.h create mode 100644 lib/kunit/bug.c
include/asm-generic/bug.h +13 -3
@@ -18,6 +18,7 @@#endif #ifndef __ASSEMBLY__ +#include <kunit/bug.h> #include <linux/panic.h> #include <linux/printk.h>
@@ -39,8 +40,14 @@ struct bug_entry {#ifdef CONFIG_DEBUG_BUGVERBOSE #ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS const char *file; +#ifdef HAVE_BUG_FUNCTION +const char *function; +#endif #else signed int file_disp; +#ifdef HAVE_BUG_FUNCTION +signed int function_disp; +#endif #endif unsigned short line;#endif
@@ -96,15 +103,18 @@ extern __printf(1, 2) void __warn_printk(const char *fmt, ...);#define __WARN () __WARN_printf(TAINT_WARN, NULL) #define __WARN_printf(taint, arg...) do { \ instrumentation_begin(); \ - warn_slowpath_fmt(__FILE__, __LINE__, taint, arg); \ + if (!KUNIT_IS_SUPPRESSED_WARNING(__func__)) \ + warn_slowpath_fmt(__FILE__, __LINE__, taint, arg);\ instrumentation_end(); \ } while (0)#else #define __WARN () __WARN_FLAGS(BUGFLAG_TAINT(TAINT_WARN)) #define __WARN_printf(taint, arg...) do { \ instrumentation_begin(); \ - __warn_printk(arg); \ - __WARN_FLAGS(BUGFLAG_NO_CUT_HERE | BUGFLAG_TAINT(taint));\ + if (!KUNIT_IS_SUPPRESSED_WARNING(__func__)) { \ + __warn_printk(arg); \ + __WARN_FLAGS(BUGFLAG_NO_CUT_HERE | BUGFLAG_TAINT(taint));\ + } \ instrumentation_end(); \ } while (0)#define WARN_ON_ONCE (condition) ({ \
include/kunit/bug.h new file +51 -0
51 lines not on this page · raw message
include/kunit/test.h +1 -0
@@ -10,6 +10,7 @@#define _KUNIT_TEST_H#include <kunit/assert.h> +#include <kunit/bug.h> #include <kunit/try-catch.h> #include <linux/args.h>
include/linux/bug.h +13 -0
@@ -36,6 +36,9 @@ static inline int is_warning_bug(const struct bug_entry *bug)return bug->flags &BUGFLAG_WARNING ; } +void bug_get_file_function_line (struct bug_entry *bug,const char **file, +const char **function,unsigned int *line); +void bug_get_file_line (struct bug_entry *bug,const char **file,unsigned int *line);
@@ -62,6 +65,16 @@ static inline enum bug_trap_type report_bug(unsigned long bug_addr, }struct bug_entry ; +static inline void bug_get_file_function_line (struct bug_entry *bug, +const char **file, +const char **function, +unsigned int *line) +{ + *file =NULL ; + *function =NULL ; + *line =0 ; +} +static inline void bug_get_file_line (struct bug_entry *bug,const char **file,unsigned int *line) {
lib/bug.c +47 -4
93 lines not on this page · raw message
lib/kunit/Kconfig +9 -0
@@ -15,6 +15,15 @@ menuconfig KUNIT if KUNIT +config KUNIT_SUPPRESS_BACKTRACE + bool "KUnit - Enable backtrace suppression" + default y + help + Enable backtrace suppression for KUnit. If enabled, backtraces + generated intentionally by KUnit tests are suppressed. Disable + to reduce kernel image size if image size is more important than + suppression of backtraces generated by KUnit tests. + config KUNIT_DEBUGFS bool "KUnit - Enable /sys/kernel/debug/kunit debugfs representation" if !KUNIT_ALL_TESTS default KUNIT_ALL_TESTS
lib/kunit/Makefile +4 -2
@@ -16,8 +16,10 @@ ifeq ($(CONFIG_KUNIT_DEBUGFS),y) kunit-objs += debugfs.o endif -# KUnit 'hooks' are built-in even when KUnit is built as a module. -obj-y += hooks.o +# KUnit 'hooks' and bug handling are built-in even when KUnit is built +# as a module. +obj-y += hooks.o \ + bug.o obj-$(CONFIG_KUNIT_TEST) += kunit-test.o obj-$(CONFIG_KUNIT_TEST) += platform-test.o
lib/kunit/bug.c new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* KUnit helpers for backtrace suppression +* +* Copyright (c) 2024 Guenter Roeck <[email protected]> +*/ + +#include <kunit/bug.h> +#include <linux/export.h> +#include <linux/list.h> +#include <linux/string.h> + +static LIST_HEAD (suppressed_warnings); + +void __kunit_start_suppress_warning (struct __suppressed_warning *warning) +{ +list_add (&warning->node, &suppressed_warnings); +} +EXPORT_SYMBOL_GPL (__kunit_start_suppress_warning); + +void __kunit_end_suppress_warning (struct __suppressed_warning *warning) +{ +list_del (&warning->node); +} +EXPORT_SYMBOL_GPL (__kunit_end_suppress_warning); + +bool __kunit_is_suppressed_warning (const char *function) +{ +struct __suppressed_warning *warning; + +if (!function) +return false; + +list_for_each_entry (warning, &suppressed_warnings, node) { +if (!strcmp (function, warning->function)) +return true; + } +return false; +} +EXPORT_SYMBOL_GPL (__kunit_is_suppressed_warning);
Signature · 1 line
2.34.1
Re: [PATCH v4 01/14] bug/kunit: Core support for suppressing warning backtraces
Quoted 38 lines · Alessandro Carminati
From: Guenter Roeck <[email protected]>
Some unit tests intentionally trigger warning backtraces by passing bad parameters to API functions. Such unit tests typically check the return value from those calls, not the existence of the warning backtrace.
Such intentionally generated warning backtraces are neither desirable nor useful for a number of reasons.
- They can result in overlooked real problems.
- A warning that suddenly starts to show up in unit tests needs to be investigated and has to be marked to be ignored, for example by adjusting filter scripts. Such filters are ad-hoc because there is no real standard format for warnings. On top of that, such filter scripts would require constant maintenance.One option to address problem would be to add messages such as "expected warning backtraces start / end here" to the kernel log. However, that would again require filter scripts, it might result in missing real problematic warning backtraces triggered while the test is running, and the irrelevant backtrace(s) would still clog the kernel log.
Solve the problem by providing a means to identify and suppress specific warning backtraces while executing test code. Since the new functionality results in an image size increase of about 1% if
CONFIG_KUNITis enabled, provide configuration optionKUNIT_SUPPRESS_BACKTRACEto be able to disable the new functionality. This option is by default enabled since almost all systems withCONFIG_KUNITenabled will want to benefit from it.Cc Dan Carpenter <[email protected]>Cc Daniel Diaz <[email protected]>Cc Naresh Kamboju <[email protected]>Cc Kees Cook <[email protected]>Acked-by Dan Carpenter <[email protected]>Reviewed-by Kees Cook <[email protected]>Signed-off-by Guenter Roeck <[email protected]>Signed-off-by Alessandro Carminati <[email protected]>
Quoted 1 line
---
Thanks Guenter & Alessandro: I'm very happy with this.
-- David
PATCH v4 2/14 kunit: bug: Count suppressed warning backtraces
In reply to Alessandro CarminatiFrom: Guenter Roeck <[email protected]>
Count suppressed warning backtraces to enable code which suppresses warning backtraces to check if the expected backtrace(s) have been observed.
Using atomics for the backtrace count resulted in build errors on some architectures due to include file recursion, so use a plain integer for now.
--- include/kunit/bug.h | 7 ++++++- lib/kunit/bug.c | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-)
include/kunit/bug.h +6 -1
@@ -20,6 +20,7 @@struct __suppressed_warning {struct list_head node;const char *function; +int counter; };void __kunit_start_suppress_warning (struct __suppressed_warning *warning);
@@ -28,7 +29,7 @@ bool __kunit_is_suppressed_warning(const char *function);#define DEFINE_SUPPRESSED_WARNING (func) \ struct __suppressed_warning __kunit_suppress_##func = \ - { .function = __stringify(func) } + { .function = __stringify(func), .counter = 0 }#define KUNIT_START_SUPPRESSED_WARNING (func) \ __kunit_start_suppress_warning(&__kunit_suppress_##func)
@@ -39,12 +40,16 @@ bool __kunit_is_suppressed_warning(const char *function);#define KUNIT_IS_SUPPRESSED_WARNING (func) \ __kunit_is_suppressed_warning(func) +#define SUPPRESSED_WARNING_COUNT (func) \ + (__kunit_suppress_##func.counter) +#else /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ #define DEFINE_SUPPRESSED_WARNING (func)#define KUNIT_START_SUPPRESSED_WARNING (func)#define KUNIT_END_SUPPRESSED_WARNING (func)#define KUNIT_IS_SUPPRESSED_WARNING (func) (false) +#define SUPPRESSED_WARNING_COUNT (func) (0)#endif /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ #endif /* __ASSEMBLY__ */
lib/kunit/bug.c +3 -1
@@ -32,8 +32,10 @@ bool __kunit_is_suppressed_warning(const char *function)return false;list_for_each_entry (warning, &suppressed_warnings, node) { -if (!strcmp (function, warning->function)) +if (!strcmp (function, warning->function)) { + warning->counter++;return true; + } }return false; }
Signature · 1 line
2.34.1
Re: [PATCH v4 02/14] kunit: bug: Count suppressed warning backtraces
Quoted 11 lines · Alessandro Carminati
From: Guenter Roeck <[email protected]>
Count suppressed warning backtraces to enable code which suppresses warning backtraces to check if the expected backtrace(s) have been observed.
Using atomics for the backtrace count resulted in build errors on some architectures due to include file recursion, so use a plain integer for now.
Quoted 7 lines
Acked-by Dan Carpenter <[email protected]>Reviewed-by Kees Cook <[email protected]>Signed-off-by Guenter Roeck <[email protected]>Reviewed-by David Gow <[email protected]>Signed-off-by Alessandro Carminati <[email protected]>---
Looks good. I'd definitely prefer the atomics to work one day, but I doubt we're likely to have backtraces from multiple threads happening in a KUnit test, so it's definitely not urgent.
Cheers,
-- David
Quoted 61 lines
include/kunit/bug.h | 7 ++++++- lib/kunit/bug.c | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-)include/kunit/bug.h +6
-1@@ -20,6 +20,7 @@struct __suppressed_warning {struct list_head node;const char *function; +int counter; };void __kunit_start_suppress_warning (struct __suppressed_warning *warning);@@ -28,7 +29,7 @@ bool __kunit_is_suppressed_warning(const char *function);#define DEFINE_SUPPRESSED_WARNING (func) \ struct __suppressed_warning __kunit_suppress_##func = \ - { .function = __stringify(func) } + { .function = __stringify(func), .counter = 0 }#define KUNIT_START_SUPPRESSED_WARNING (func) \ __kunit_start_suppress_warning(&__kunit_suppress_##func)@@ -39,12 +40,16 @@ bool __kunit_is_suppressed_warning(const char *function);#define KUNIT_IS_SUPPRESSED_WARNING (func) \ __kunit_is_suppressed_warning(func) +#define SUPPRESSED_WARNING_COUNT (func) \ + (__kunit_suppress_##func.counter) +#else /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ #define DEFINE_SUPPRESSED_WARNING (func)#define KUNIT_START_SUPPRESSED_WARNING (func)#define KUNIT_END_SUPPRESSED_WARNING (func)#define KUNIT_IS_SUPPRESSED_WARNING (func) (false) +#define SUPPRESSED_WARNING_COUNT (func) (0)#endif /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ #endif /* __ASSEMBLY__ */ lib/kunit/bug.c +3
-2@@ -32,8 +32,10 @@ bool __kunit_is_suppressed_warning(const char *function)return false;list_for_each_entry (warning, &suppressed_warnings, node) { -if (!strcmp (function, warning->function)) +if (!strcmp (function, warning->function)) { + warning->counter++;return true; + } }return false; } --2.34.1
PATCH v4 3/14 kunit: Add test cases for backtrace warning suppression
In reply to Alessandro CarminatiFrom: Guenter Roeck <[email protected]>
Add unit tests to verify that warning backtrace suppression works.
If backtrace suppression does _not_ work, the unit tests will likely trigger unsuppressed backtraces, which should actually help to get the affected architectures / platforms fixed.
--- lib/kunit/Makefile | 7 +- lib/kunit/backtrace-suppression-test.c | 104 +++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 lib/kunit/backtrace-suppression-test.c
lib/kunit/Makefile +5 -2
@@ -18,11 +18,14 @@ endif # KUnit 'hooks' and bug handling are built-in even when KUnit is built # as a module. -obj-y += hooks.o \ - bug.o +obj-y += hooks.o +obj-$(CONFIG_KUNIT_SUPPRESS_BACKTRACE) += bug.o obj-$(CONFIG_KUNIT_TEST) += kunit-test.o obj-$(CONFIG_KUNIT_TEST) += platform-test.o +ifeq ($(CONFIG_KUNIT_SUPPRESS_BACKTRACE),y) +obj-$(CONFIG_KUNIT_TEST) += backtrace-suppression-test.o +endif # string-stream-test compiles built-in only. ifeq ($(CONFIG_KUNIT_TEST),y)
lib/kunit/backtrace-suppression-test.c new file +104 -0
104 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v4 03/14] kunit: Add test cases for backtrace warning suppression
Quoted 9 lines · Alessandro Carminati
From: Guenter Roeck <[email protected]>
Add unit tests to verify that warning backtrace suppression works.
If backtrace suppression does _not_ work, the unit tests will likely trigger unsuppressed backtraces, which should actually help to get the affected architectures / platforms fixed.
Quoted 6 lines
Acked-by Dan Carpenter <[email protected]>Reviewed-by Kees Cook <[email protected]>Signed-off-by Guenter Roeck <[email protected]>Signed-off-by Alessandro Carminati <[email protected]>---
Always nice to have tests. :-)
Cheers,
-- David
PATCH v4 4/14 kunit: Add documentation for warning backtrace suppression API
In reply to Alessandro CarminatiFrom: Guenter Roeck <[email protected]>
Document API functions for suppressing warning backtraces.
--- Documentation/dev-tools/kunit/usage.rst | 30 ++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
Documentation/dev-tools/kunit/usage.rst +29 -1
@@ -157,6 +157,34 @@ Alternatively, one can take full control over the error message by using if (some_setup_function()) KUNIT_FAIL(test, "Failed to setup thing for testing"); +Suppressing warning backtraces +------------------------------ + +Some unit tests trigger warning backtraces either intentionally or as side +effect. Such backtraces are normally undesirable since they distract from +the actual test and may result in the impression that there is a problem. + +Such backtraces can be suppressed. To suppress a backtrace in some_function(), +use the following code. + +.. code-block:: c + + static void some_test(struct kunit *test) + { + DEFINE_SUPPRESSED_WARNING(some_function); + + KUNIT_START_SUPPRESSED_WARNING(some_function); + trigger_backtrace(); + KUNIT_END_SUPPRESSED_WARNING(some_function); + } + +SUPPRESSED_WARNING_COUNT() returns the number of suppressed backtraces. If the +suppressed backtrace was triggered on purpose, this can be used to check if +the backtrace was actually triggered. + +.. code-block:: c + + KUNIT_EXPECT_EQ(test, SUPPRESSED_WARNING_COUNT(some_function), 1); Test Suites ~~~~~~~~~~~
@@ -857,4 +885,4 @@ For example: dev_managed_string = devm_kstrdup(fake_device, "Hello, World!"); // Everything is cleaned up automatically when the test ends. - } + }
Signature · 1 line
2.34.1
PATCH v4 5/14 drm: Suppress intentional warning backtraces in scaling unit tests
In reply to Alessandro CarminatiFrom: Guenter Roeck <[email protected]>
The drm_test_rect_calc_hscale and drm_test_rect_calc_vscale unit tests intentionally trigger warning backtraces by providing bad parameters to the tested functions. What is tested is the return value, not the existence of a warning backtrace. Suppress the backtraces to avoid clogging the kernel log and distraction from real problems.
--- drivers/gpu/drm/tests/drm_rect_test.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/gpu/drm/tests/drm_rect_test.c +16 -0
@@ -406,22 +406,38 @@ KUNIT_ARRAY_PARAM(drm_rect_scale, drm_rect_scale_cases, drm_rect_scale_case_descstatic void drm_test_rect_calc_hscale (struct kunit *test) { +DEFINE_SUPPRESSED_WARNING (drm_calc_scale);const struct drm_rect_scale_case *params = test->param_value;int scaling_factor; +/* +* drm_rect_calc_hscale() generates a warning backtrace whenever bad +* parameters are passed to it. This affects all unit tests with an +* error code in expected_scaling_factor. +*/ +KUNIT_START_SUPPRESSED_WARNING (drm_calc_scale); scaling_factor =drm_rect_calc_hscale (¶ms->src, ¶ms->dst, params->min_range, params->max_range); +KUNIT_END_SUPPRESSED_WARNING (drm_calc_scale);KUNIT_EXPECT_EQ (test, scaling_factor, params->expected_scaling_factor); }static void drm_test_rect_calc_vscale (struct kunit *test) { +DEFINE_SUPPRESSED_WARNING (drm_calc_scale);const struct drm_rect_scale_case *params = test->param_value;int scaling_factor; +/* +* drm_rect_calc_vscale() generates a warning backtrace whenever bad +* parameters are passed to it. This affects all unit tests with an +* error code in expected_scaling_factor. +*/ +KUNIT_START_SUPPRESSED_WARNING (drm_calc_scale); scaling_factor =drm_rect_calc_vscale (¶ms->src, ¶ms->dst, params->min_range, params->max_range); +KUNIT_END_SUPPRESSED_WARNING (drm_calc_scale);KUNIT_EXPECT_EQ (test, scaling_factor, params->expected_scaling_factor); }
Signature · 1 line
2.34.1
PATCH v4 6/14 x86: Add support for suppressing warning backtraces
In reply to Alessandro CarminatiFrom: Guenter Roeck <[email protected]>
Add name of functions triggering warning backtraces to the __bug_table object section to enable support for suppressing WARNING backtraces.
To limit image size impact, the pointer to the function name is only added to the __bug_table section if both CONFIG_KUNIT_SUPPRESS_BACKTRACE and CONFIG_DEBUG_BUGVERBOSE are enabled. Otherwise, the __func__ assembly parameter is replaced with a (dummy) NULL parameter to avoid an image size increase due to unused __func__ entries (this is necessary because __func__ is not a define but a virtual variable).
--- arch/x86/include/asm/bug.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
arch/x86/include/asm/bug.h +16 -5
@@ -35,18 +35,28 @@#ifdef CONFIG_DEBUG_BUGVERBOSE +#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE +# define HAVE_BUG_FUNCTION +# define __BUG_FUNC_PTR __BUG_REL(%c1) +# define __BUG_FUNC __func__ +#else +# define __BUG_FUNC_PTR +# define __BUG_FUNC NULL +#endif /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ +#define _BUG_FLAGS (ins, flags, extra) \ do { \ asm_inline volatile("1:\t" ins "\n" \ ".pushsection __bug_table,\"aw\"\n" \ "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \ "\t" __BUG_REL(%c0) "\t# bug_entry::file\n" \ - "\t.word %c1" "\t# bug_entry::line\n" \ - "\t.word %c2" "\t# bug_entry::flags\n" \ - "\t.org 2b+%c3\n" \ + "\t" __BUG_FUNC_PTR "\t# bug_entry::function\n" \ + "\t.word %c2" "\t# bug_entry::line\n" \ + "\t.word %c3" "\t# bug_entry::flags\n" \ + "\t.org 2b+%c4\n" \ ".popsection\n" \ extra \ - : : "i" (__FILE__), "i" (__LINE__), \ + : : "i" (__FILE__), "i" (__BUG_FUNC), "i" (__LINE__),\ "i" (flags), \ "i" (sizeof(struct bug_entry))); \ } while (0)
@@ -92,7 +102,8 @@ do { \do { \__auto_type __flags =BUGFLAG_WARNING |(flags); \instrumentation_begin (); \ -_BUG_FLAGS (ASM_UD2 , __flags,ANNOTATE_REACHABLE (1b )); \ +if (!KUNIT_IS_SUPPRESSED_WARNING (__func__)) \ +_BUG_FLAGS (ASM_UD2 , __flags,ANNOTATE_REACHABLE (1b )); \instrumentation_end (); \ }while (0 )
Signature · 1 line
2.34.1
Re: [PATCH v4 06/14] x86: Add support for suppressing warning backtraces
Quoted 21 lines · Alessandro Carminati
From: Guenter Roeck <[email protected]>
Add name of functions triggering warning backtraces to the
__bug_tableobject section to enable support for suppressing WARNING backtraces.To limit image size impact, the pointer to the function name is only added to the
__bug_tablesection if bothCONFIG_KUNIT_SUPPRESS_BACKTRACEandCONFIG_DEBUG_BUGVERBOSEare enabled. Otherwise, the__func__assembly parameter is replaced with a (dummy) NULL parameter to avoid an image size increase due to unused__func__entries (this is necessary because__func__is not a define but a virtual variable).Acked-by Dan Carpenter <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Borislav Petkov <[email protected]>Cc Dave Hansen <[email protected]>Signed-off-by Guenter Roeck <[email protected]>Signed-off-by Alessandro Carminati <[email protected]>
Quoted 1 line
---
Cheers,
-- David
Quoted 53 lines
arch/x86/include/asm/bug.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)arch/x86/include/asm/bug.h +16
-6@@ -35,18 +35,28 @@#ifdef CONFIG_DEBUG_BUGVERBOSE +#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE +# define HAVE_BUG_FUNCTION +# define __BUG_FUNC_PTR __BUG_REL(%c1) +# define __BUG_FUNC __func__ +#else +# define __BUG_FUNC_PTR +# define __BUG_FUNC NULL +#endif /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ +#define _BUG_FLAGS (ins, flags, extra) \ do { \ asm_inline volatile("1:\t" ins "\n" \ ".pushsection __bug_table,\"aw\"\n" \ "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \ "\t" __BUG_REL(%c0) "\t# bug_entry::file\n" \ - "\t.word %c1" "\t# bug_entry::line\n" \ - "\t.word %c2" "\t# bug_entry::flags\n" \ - "\t.org 2b+%c3\n" \ + "\t" __BUG_FUNC_PTR "\t# bug_entry::function\n" \ + "\t.word %c2" "\t# bug_entry::line\n" \ + "\t.word %c3" "\t# bug_entry::flags\n" \ + "\t.org 2b+%c4\n" \ ".popsection\n" \ extra \ - : : "i" (__FILE__), "i" (__LINE__), \ + : : "i" (__FILE__), "i" (__BUG_FUNC), "i" (__LINE__),\ "i" (flags), \ "i" (sizeof(struct bug_entry))); \ } while (0)@@ -92,7 +102,8 @@ do { \do { \__auto_type __flags =BUGFLAG_WARNING |(flags); \instrumentation_begin (); \ -_BUG_FLAGS (ASM_UD2 , __flags,ANNOTATE_REACHABLE (1b )); \ +if (!KUNIT_IS_SUPPRESSED_WARNING (__func__)) \ +_BUG_FLAGS (ASM_UD2 , __flags,ANNOTATE_REACHABLE (1b )); \instrumentation_end (); \ }while (0 ) --2.34.1
Peter Zijlstra
NAKRe: [PATCH v4 06/14] x86: Add support for suppressing warning backtraces
In reply to Alessandro CarminatiQuoted 62 lines · Alessandro Carminati
From: Guenter Roeck <[email protected]>
Add name of functions triggering warning backtraces to the
__bug_tableobject section to enable support for suppressing WARNING backtraces.To limit image size impact, the pointer to the function name is only added to the
__bug_tablesection if bothCONFIG_KUNIT_SUPPRESS_BACKTRACEandCONFIG_DEBUG_BUGVERBOSEare enabled. Otherwise, the__func__assembly parameter is replaced with a (dummy) NULL parameter to avoid an image size increase due to unused__func__entries (this is necessary because__func__is not a define but a virtual variable).Acked-by Dan Carpenter <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Borislav Petkov <[email protected]>Cc Dave Hansen <[email protected]>Signed-off-by Guenter Roeck <[email protected]>Signed-off-by Alessandro Carminati <[email protected]>--- arch/x86/include/asm/bug.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)arch/x86/include/asm/bug.h +14
-4@@ -35,18 +35,28 @@#ifdef CONFIG_DEBUG_BUGVERBOSE +#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE +# define HAVE_BUG_FUNCTION +# define __BUG_FUNC_PTR __BUG_REL(%c1) +# define __BUG_FUNC __func__ +#else +# define __BUG_FUNC_PTR +# define __BUG_FUNC NULL +#endif /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ +#define _BUG_FLAGS (ins, flags, extra) \ do { \ asm_inline volatile("1:\t" ins "\n" \ ".pushsection __bug_table,\"aw\"\n" \ "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \ "\t" __BUG_REL(%c0) "\t# bug_entry::file\n" \ - "\t.word %c1" "\t# bug_entry::line\n" \ - "\t.word %c2" "\t# bug_entry::flags\n" \ - "\t.org 2b+%c3\n" \ + "\t" __BUG_FUNC_PTR "\t# bug_entry::function\n" \ + "\t.word %c2" "\t# bug_entry::line\n" \ + "\t.word %c3" "\t# bug_entry::flags\n" \ + "\t.org 2b+%c4\n" \ ".popsection\n" \ extra \ - : : "i" (__FILE__), "i" (__LINE__), \ + : : "i" (__FILE__), "i" (__BUG_FUNC), "i" (__LINE__),\ "i" (flags), \ "i" (sizeof(struct bug_entry))); \ } while (0)
arch/x86/include/asm/bug.h do { \ · line 108
Quoted 8 lines
arch/x86/include/asm/bug.h +2
-1@@ -92,7 +102,8 @@ do { \do { \__auto_type __flags =BUGFLAG_WARNING |(flags); \instrumentation_begin (); \ -_BUG_FLAGS (ASM_UD2 , __flags,ANNOTATE_REACHABLE (1b )); \ +if (!KUNIT_IS_SUPPRESSED_WARNING (__func__)) \ +_BUG_FLAGS (ASM_UD2 , __flags,ANNOTATE_REACHABLE (1b )); \instrumentation_end (); \ }while (0 )
NAK, this grows the BUG site for now appreciable reason.
Re: [PATCH v4 06/14] x86: Add support for suppressing warning backtraces
Quoted 65 lines · Peter Zijlstra
Quoted 64 lines · Alessandro Carminati
From: Guenter Roeck <[email protected]>
Add name of functions triggering warning backtraces to the
__bug_tableobject section to enable support for suppressing WARNING backtraces.To limit image size impact, the pointer to the function name is only added to the
__bug_tablesection if bothCONFIG_KUNIT_SUPPRESS_BACKTRACEandCONFIG_DEBUG_BUGVERBOSEare enabled. Otherwise, the__func__assembly parameter is replaced with a (dummy) NULL parameter to avoid an image size increase due to unused__func__entries (this is necessary because__func__is not a define but a virtual variable).Acked-by Dan Carpenter <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Borislav Petkov <[email protected]>Cc Dave Hansen <[email protected]>Signed-off-by Guenter Roeck <[email protected]>Signed-off-by Alessandro Carminati <[email protected]>--- arch/x86/include/asm/bug.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)arch/x86/include/asm/bug.h +14
-4@@ -35,18 +35,28 @@#ifdef CONFIG_DEBUG_BUGVERBOSE +#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE +# define HAVE_BUG_FUNCTION +# define __BUG_FUNC_PTR __BUG_REL(%c1) +# define __BUG_FUNC __func__ +#else +# define __BUG_FUNC_PTR +# define __BUG_FUNC NULL +#endif /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ +#define _BUG_FLAGS (ins, flags, extra) \ do { \ asm_inline volatile("1:\t" ins "\n" \ ".pushsection __bug_table,\"aw\"\n" \ "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \ "\t" __BUG_REL(%c0) "\t# bug_entry::file\n" \ - "\t.word %c1" "\t# bug_entry::line\n" \ - "\t.word %c2" "\t# bug_entry::flags\n" \ - "\t.org 2b+%c3\n" \ + "\t" __BUG_FUNC_PTR "\t# bug_entry::function\n" \ + "\t.word %c2" "\t# bug_entry::line\n" \ + "\t.word %c3" "\t# bug_entry::flags\n" \ + "\t.org 2b+%c4\n" \ ".popsection\n" \ extra \ - : : "i" (__FILE__), "i" (__LINE__), \ + : : "i" (__FILE__), "i" (__BUG_FUNC), "i" (__LINE__),\ "i" (flags), \ "i" (sizeof(struct bug_entry))); \ } while (0)@@ -92,7 +102,8 @@ do { \ do { \ __auto_type __flags = BUGFLAG_WARNING|(flags); \
Quoted 8 lines
arch/x86/include/asm/bug.h do { \ · line 108
Quoted 6 lines
arch/x86/include/asm/bug.h +2
-1instrumentation_begin (); \ -_BUG_FLAGS (ASM_UD2 , __flags,ANNOTATE_REACHABLE (1b )); \ +if (!KUNIT_IS_SUPPRESSED_WARNING (__func__)) \ +_BUG_FLAGS (ASM_UD2 , __flags,ANNOTATE_REACHABLE (1b )); \instrumentation_end (); \ }while (0 )NAK, this grows the BUG site for now appreciable reason.
Only if CONFIG_KUNIT_SUPPRESS_BACKTRACE is enabled. Why does that warrant a NACK ?
Guenter
Re: [PATCH v4 06/14] x86: Add support for suppressing warning backtraces
Quoted 10 lines · Guenter Roeck
Quoted 6 lines · Peter Zijlstra
arch/x86/include/asm/bug.h do { \ · line 108
Quoted 4 lines
arch/x86/include/asm/bug.h +2
-0+if (!KUNIT_IS_SUPPRESSED_WARNING (__func__)) \ +_BUG_FLAGS (ASM_UD2 , __flags,ANNOTATE_REACHABLE (1b )); \instrumentation_end (); \ }while (0 )NAK, this grows the BUG site for now appreciable reason.
Only if
CONFIG_KUNIT_SUPPRESS_BACKTRACEis enabled. Why does that warrant a NACK ?
I agree with Peter, this bloats the code around thousands of UD2 sites.
It would be much better to do the checking after the exception. In fact it looks like you're already doing that in report_bug()?
if (warning && KUNIT_IS_SUPPRESSED_WARNING(function)) return BUG_TRAP_TYPE_WARN;
Why check it twice?
Signature · 1 line
Josh
Re: [PATCH v4 06/14] x86: Add support for suppressing warning backtraces
In reply to Guenter RoeckQuoted 12 lines · Guenter Roeck
Quoted 11 lines
arch/x86/include/asm/bug.h do { \ · line 108
Quoted 9 lines
arch/x86/include/asm/bug.h +2
-1@@ -92,7 +102,8 @@ do { \do { \__auto_type __flags =BUGFLAG_WARNING |(flags); \instrumentation_begin (); \ -_BUG_FLAGS (ASM_UD2 , __flags,ANNOTATE_REACHABLE (1b )); \ +if (!KUNIT_IS_SUPPRESSED_WARNING (__func__)) \ +_BUG_FLAGS (ASM_UD2 , __flags,ANNOTATE_REACHABLE (1b )); \instrumentation_end (); \ }while (0 )NAK, this grows the BUG site for now appreciable reason.
Quoted 1 line
Only if
CONFIG_KUNIT_SUPPRESS_BACKTRACEis enabled. Why does that warrant a NACK ?
And isn't that something distros will want enabled? All I'm seeing is bloating every single UD2 site, and no real justification. As Josh said, this should be done on the other side of the trap if at all.
Re: [PATCH v4 06/14] x86: Add support for suppressing warning backtraces
In reply to Guenter RoeckQuoted 12 lines · Guenter Roeck
Quoted 12 lines
Quoted 12 lines
#define _BUG_FLAGS(ins, flags, extra) \ do { \ asm_inline volatile("1:\t" ins "\n" \ ".pushsection __bug_table,\"aw\"\n" \ "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \ "\t" __BUG_REL(%c0) "\t# bug_entry::file\n" \arch/x86/include/asm/bug.h +3
-3-"\t.word %c1" "\t# bug_entry::line\n" \ -"\t.word %c2" "\t# bug_entry::flags\n" \ -"\t.org 2b+%c3\n" \ +"\t" __BUG_FUNC_PTR"\t# bug_entry::function\n" \ +"\t.word %c2" "\t# bug_entry::line\n" \ +"\t.word %c3" "\t# bug_entry::flags\n" \
Quoted 8 lines
Quoted 8 lines
arch/x86/include/asm/bug.h line 62
Quoted 8 lines
arch/x86/include/asm/bug.h +2
-1+ "\t.org 2b+%c4\n" \ ".popsection\n" \ extra \ - : : "i" (__FILE__), "i" (__LINE__), \ + : : "i" (__FILE__), "i" (__BUG_FUNC), "i" (__LINE__),\"i" (flags), \ "i" (sizeof(struct bug_entry))); \ }while (0 )
Also this, why do you need this extra function in the bug entry? Isn't that trivial from the trap site itself? symbol information should be able to get you the function from the trap ip.
None of this makes any sense.
PATCH v4 7/14 arm64: Add support for suppressing warning backtraces
In reply to Alessandro CarminatiFrom: Guenter Roeck <[email protected]>
Add name of functions triggering warning backtraces to the __bug_table object section to enable support for suppressing WARNING backtraces.
To limit image size impact, the pointer to the function name is only added to the __bug_table section if both CONFIG_KUNIT_SUPPRESS_BACKTRACE and CONFIG_DEBUG_BUGVERBOSE are enabled. Otherwise, the __func__ assembly parameter is replaced with a (dummy) NULL parameter to avoid an image size increase due to unused __func__ entries (this is necessary because __func__ is not a define but a virtual variable).
--- arch/arm64/include/asm/asm-bug.h | 27 ++++++++++++++++++--------- arch/arm64/include/asm/bug.h | 8 +++++++- 2 files changed, 25 insertions(+), 10 deletions(-)
arch/arm64/include/asm/asm-bug.h +18 -9
@@ -8,37 +8,46 @@#include <asm/brk-imm.h> #ifdef CONFIG_DEBUG_BUGVERBOSE -#define _BUGVERBOSE_LOCATION (file, line) __BUGVERBOSE_LOCATION(file, line) -#define __BUGVERBOSE_LOCATION (file, line) \ + +#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE +# define HAVE_BUG_FUNCTION +# define __BUG_FUNC_PTR (func) .long func - .; +#else +# define __BUG_FUNC_PTR (func) +#endif + +#define _BUGVERBOSE_LOCATION (file, func, line) __BUGVERBOSE_LOCATION(file, func, line) +#define __BUGVERBOSE_LOCATION (file, func, line) \ .pushsection .rodata.str,"aMS",@progbits,1; \ 14472: .string file; \ .popsection; \ \ .long 14472b - .; \ + __BUG_FUNC_PTR(func) \ .short line;#else -#define _BUGVERBOSE_LOCATION (file, line) +#define _BUGVERBOSE_LOCATION (file, func, line)#endif #ifdef CONFIG_GENERIC_BUG -#define __BUG_ENTRY (flags) \ +#define __BUG_ENTRY (flags, func) \ .pushsection __bug_table,"aw"; \ .align 2; \ 14470: .long 14471f - .; \ -_BUGVERBOSE_LOCATION(__FILE__, __LINE__) \ +_BUGVERBOSE_LOCATION(__FILE__, func, __LINE__) \ .short flags; \ .align 2; \ .popsection; \ 14471:#else -#define __BUG_ENTRY (flags) +#define __BUG_ENTRY (flags, func)#endif -#define ASM_BUG_FLAGS (flags) \ - __BUG_ENTRY(flags) \ +#define ASM_BUG_FLAGS (flags, func) \ + __BUG_ENTRY(flags, func) \ brk BUG_BRK_IMM -#define ASM_BUG () ASM_BUG_FLAGS(0) +#define ASM_BUG () ASM_BUG_FLAGS(0, .)#endif /* __ASM_ASM_BUG_H */
arch/arm64/include/asm/bug.h +7 -1
@@ -11,8 +11,14 @@#include <asm/asm-bug.h> +#ifdef HAVE_BUG_FUNCTION +# define __BUG_FUNC __func__ +#else +# define __BUG_FUNC NULL +#endif +#define __BUG_FLAGS (flags) \ - asm volatile (__stringify(ASM_BUG_FLAGS(flags))); + asm volatile (__stringify(ASM_BUG_FLAGS(flags, %c0)) : : "i" (__BUG_FUNC));#define BUG () do { \ __BUG_FLAGS(0); \
Signature · 1 line
2.34.1
Will Deacon
maintainerRe: [PATCH v4 07/14] arm64: Add support for suppressing warning backtraces
Quoted 7 lines · Alessandro Carminati
arch/arm64/include/asm/bug.h +0
-0@@ -11,8 +11,14 @@#include <asm/asm-bug.h>
arch/arm64/include/asm/bug.h line 21
Quoted 10 lines
arch/arm64/include/asm/bug.h +7
-1+#ifdef HAVE_BUG_FUNCTION +# define __BUG_FUNC __func__ +#else +# define __BUG_FUNC NULL +#endif +#define __BUG_FLAGS (flags) \ - asm volatile (__stringify(ASM_BUG_FLAGS(flags))); + asm volatile (__stringify(ASM_BUG_FLAGS(flags, %c0)) : : "i" (__BUG_FUNC));
Why is 'i' the right asm constraint to use here? It seems a bit odd to use that for a pointer.
Will
Re: [PATCH v4 07/14] arm64: Add support for suppressing warning backtraces
Hello Will,
Quoted 10 lines · Will Deacon
Quoted 8 lines · Alessandro Carminati
arch/arm64/include/asm/bug.h +0
-0@@ -11,8 +11,14 @@#include <asm/asm-bug.h>
Quoted 12 lines
arch/arm64/include/asm/bug.h line 21
Quoted 9 lines
arch/arm64/include/asm/bug.h +7
-1+#ifdef HAVE_BUG_FUNCTION +# define __BUG_FUNC __func__ +#else +# define __BUG_FUNC NULL +#endif +#define __BUG_FLAGS (flags) \ - asm volatile (__stringify(ASM_BUG_FLAGS(flags))); + asm volatile (__stringify(ASM_BUG_FLAGS(flags, %c0)) : : "i" (__BUG_FUNC));Why is 'i' the right asm constraint to use here? It seems a bit odd to use that for a pointer.
I received this code as legacy from a previous version.
In my review, I considered the case when HAVE_BUG_FUNCTION is defined:
Here, __BUG_FUNC is defined as __func__, which is the name of the current function as a string literal.
Using the constraint "i" seems appropriate to me in this case.
However, when HAVE_BUG_FUNCTION is not defined:__BUG_FUNC is defined as NULL. Initially, I considered it literal 0, but after investigating your concern, I found:
```
$ echo -E "#include <stdio.h>\n#include <stddef.h>\nint main()
{\nreturn 0;\n}" | aarch64-linux-gnu-gcc -E -dM - | grep NULL
#define NULL ((void *)0)
```I realized that NULL is actually a pointer that is not a link time symbol, and using the "i" constraint with NULL may result in undefined behavior.
Would the following alternative definition for __BUG_FUNC be more convincing?
```
#ifdef HAVE_BUG_FUNCTION
#define __BUG_FUNC __func__
#else
#define __BUG_FUNC (uintptr_t)0
#endif
```Let me know your thoughts.
Quoted 3 lines
Will
--
---
172
Will Deacon
maintainerRe: [PATCH v4 07/14] arm64: Add support for suppressing warning backtraces
Quoted 46 lines · Alessandro Carminati
Quoted 10 lines · Will Deacon
Quoted 8 lines · Alessandro Carminati
arch/arm64/include/asm/bug.h +0
-0@@ -11,8 +11,14 @@#include <asm/asm-bug.h> Quoted 12 lines
arch/arm64/include/asm/bug.h line 21
Quoted 9 lines
arch/arm64/include/asm/bug.h +7
-1+#ifdef HAVE_BUG_FUNCTION +# define __BUG_FUNC __func__ +#else +# define __BUG_FUNC NULL +#endif +#define __BUG_FLAGS (flags) \ - asm volatile (__stringify(ASM_BUG_FLAGS(flags))); + asm volatile (__stringify(ASM_BUG_FLAGS(flags, %c0)) : : "i" (__BUG_FUNC));Why is 'i' the right asm constraint to use here? It seems a bit odd to use that for a pointer.
I received this code as legacy from a previous version.
In my review, I considered the case whenHAVE_BUG_FUNCTIONis defined:
Here,__BUG_FUNCis defined as__func__, which is the name of the current function as a string literal.
Using the constraint "i" seems appropriate to me in this case.However, when
HAVE_BUG_FUNCTIONis not defined:__BUG_FUNCis defined as NULL. Initially, I considered it literal 0, but after investigating your concern, I found:``` $ echo -E "#include <stdio.h>\n#include <stddef.h>\nint main() {\nreturn 0;\n}" | aarch64-linux-gnu-gcc -E -dM - | grep NULL #define NULL ((void *)0) ```I realized that NULL is actually a pointer that is not a link time symbol, and using the "i" constraint with NULL may result in undefined behavior.
Would the following alternative definition for
__BUG_FUNCbe more convincing?
Quoted 8 lines
``` #ifdef HAVE_BUG_FUNCTION #define __BUG_FUNC __func__ #else #define __BUG_FUNC (uintptr_t)0 #endif ```Let me know your thoughts.
Thanks for the analysis; I hadn't noticed this specific issue, it just smelled a bit fishy. Anyway, the diff above looks better, thanks.
Will
Re: [PATCH v4 07/14] arm64: Add support for suppressing warning backtraces
Quoted 56 lines · Will Deacon
Quoted 46 lines · Alessandro Carminati
Quoted 10 lines · Will Deacon
Quoted 8 lines · Alessandro Carminati
arch/arm64/include/asm/bug.h +0
-0@@ -11,8 +11,14 @@#include <asm/asm-bug.h> Quoted 12 lines
arch/arm64/include/asm/bug.h line 21
Quoted 9 lines
arch/arm64/include/asm/bug.h +7
-1+#ifdef HAVE_BUG_FUNCTION +# define __BUG_FUNC __func__ +#else +# define __BUG_FUNC NULL +#endif +#define __BUG_FLAGS (flags) \ - asm volatile (__stringify(ASM_BUG_FLAGS(flags))); + asm volatile (__stringify(ASM_BUG_FLAGS(flags, %c0)) : : "i" (__BUG_FUNC));Why is 'i' the right asm constraint to use here? It seems a bit odd to use that for a pointer.
I received this code as legacy from a previous version.
In my review, I considered the case whenHAVE_BUG_FUNCTIONis defined:
Here,__BUG_FUNCis defined as__func__, which is the name of the current function as a string literal.
Using the constraint "i" seems appropriate to me in this case.However, when
HAVE_BUG_FUNCTIONis not defined:__BUG_FUNCis defined as NULL. Initially, I considered it literal 0, but after investigating your concern, I found:``` $ echo -E "#include <stdio.h>\n#include <stddef.h>\nint main() {\nreturn 0;\n}" | aarch64-linux-gnu-gcc -E -dM - | grep NULL #define NULL ((void *)0) ```I realized that NULL is actually a pointer that is not a link time symbol, and using the "i" constraint with NULL may result in undefined behavior.
Would the following alternative definition for
__BUG_FUNCbe more convincing?Quoted 8 lines
``` #ifdef HAVE_BUG_FUNCTION #define __BUG_FUNC __func__ #else #define __BUG_FUNC (uintptr_t)0 #endif ```Let me know your thoughts.
Quoted 3 lines
Thanks for the analysis; I hadn't noticed this specific issue, it just smelled a bit fishy. Anyway, the diff above looks better, thanks.
It has been a long time, but I seem to recall that I ran into trouble when trying to use a different constraint.
Guenter
Re: [PATCH v4 07/14] arm64: Add support for suppressing warning backtraces
In reply to Will DeaconLe 18/03/2025 à 16:59, Will Deacon a écrit :
Quoted 56 lines · Alessandro Carminati
Quoted 46 lines · Will Deacon
Quoted 10 lines · Alessandro Carminati
Quoted 8 lines
arch/arm64/include/asm/bug.h +0
-0@@ -11,8 +11,14 @@#include <asm/asm-bug.h> Quoted 12 lines
arch/arm64/include/asm/bug.h line 21
Quoted 9 lines
arch/arm64/include/asm/bug.h +7
-1+#ifdef HAVE_BUG_FUNCTION +# define __BUG_FUNC __func__ +#else +# define __BUG_FUNC NULL +#endif +#define __BUG_FLAGS (flags) \ - asm volatile (__stringify(ASM_BUG_FLAGS(flags))); + asm volatile (__stringify(ASM_BUG_FLAGS(flags, %c0)) : : "i" (__BUG_FUNC));Why is 'i' the right asm constraint to use here? It seems a bit odd to use that for a pointer.
I received this code as legacy from a previous version.
In my review, I considered the case whenHAVE_BUG_FUNCTIONis defined:
Here,__BUG_FUNCis defined as__func__, which is the name of the current function as a string literal.
Using the constraint "i" seems appropriate to me in this case.However, when
HAVE_BUG_FUNCTIONis not defined:__BUG_FUNCis defined as NULL. Initially, I considered it literal 0, but after investigating your concern, I found:``` $ echo -E "#include <stdio.h>\n#include <stddef.h>\nint main() {\nreturn 0;\n}" | aarch64-linux-gnu-gcc -E -dM - | grep NULL #define NULL ((void *)0) ```I realized that NULL is actually a pointer that is not a link time symbol, and using the "i" constraint with NULL may result in undefined behavior.
Would the following alternative definition for
__BUG_FUNCbe more convincing?Quoted 8 lines
``` #ifdef HAVE_BUG_FUNCTION #define __BUG_FUNC __func__ #else #define __BUG_FUNC (uintptr_t)0 #endif ```Let me know your thoughts.
Quoted 2 lines
Thanks for the analysis; I hadn't noticed this specific issue, it just smelled a bit fishy. Anyway, the diff above looks better, thanks.
That propably deserves a comment.
Doesn't sparse and/or checkpatch complain about 0 being used in lieu of NULL ?
By the way I had similar problem in the past with GCC not seeing NULL as a __builtin_constant_p(), refer commit 1d8f739b07bd ("powerpc/kuap: Fix set direction in allow/prevent_user_access()")
Christophe
Re: [PATCH v4 07/14] arm64: Add support for suppressing warning backtraces
Quoted 3 lines · Christophe Leroy
Doesn't sparse and/or checkpatch complain about 0 being used in lieu of NULL ?
Sparse does have a "Using plain integer as NULL pointer" warning, yes.
I can't apply this patchset and I haven't been following the conversation closely (plus I'm pretty stupid as well) so I'm not sure if it will trigger here...
regards,
dan carpenter
Re: [PATCH v4 07/14] arm64: Add support for suppressing warning backtraces
In reply to Christophe LeroyQuoted 59 lines · Christophe Leroy
Le 18/03/2025 à 16:59, Will Deacon a écrit :
Quoted 56 lines · Alessandro Carminati
Quoted 54 lines · Will Deacon
Quoted 10 lines · Alessandro Carminati
Quoted 8 lines
arch/arm64/include/asm/bug.h +0
-0@@ -11,8 +11,14 @@ #include <asm/asm-bug.h>Quoted 12 lines
arch/arm64/include/asm/bug.h line 21
Quoted 9 lines
arch/arm64/include/asm/bug.h +7
-1+#ifdef HAVE_BUG_FUNCTION +# define __BUG_FUNC __func__ +#else +# define __BUG_FUNC NULL +#endif + #define __BUG_FLAGS(flags) \ - asm volatile (__stringify(ASM_BUG_FLAGS(flags))); + asm volatile (__stringify(ASM_BUG_FLAGS(flags, %c0)) : : "i" (__BUG_FUNC));Why is 'i' the right asm constraint to use here? It seems a bit odd to use that for a pointer.
I received this code as legacy from a previous version.
In my review, I considered the case whenHAVE_BUG_FUNCTIONis defined:
Here,__BUG_FUNCis defined as__func__, which is the name of the current function as a string literal.
Using the constraint "i" seems appropriate to me in this case.However, when
HAVE_BUG_FUNCTIONis not defined:__BUG_FUNCis defined as NULL. Initially, I considered it literal 0, but after investigating your concern, I found:``` $ echo -E "#include <stdio.h>\n#include <stddef.h>\nint main() {\nreturn 0;\n}" | aarch64-linux-gnu-gcc -E -dM - | grep NULL #define NULL ((void *)0) ```I realized that NULL is actually a pointer that is not a link time symbol, and using the "i" constraint with NULL may result in undefined behavior.
Would the following alternative definition for
__BUG_FUNCbe more convincing?``` #ifdef HAVE_BUG_FUNCTION #define __BUG_FUNC __func__ #else #define __BUG_FUNC (uintptr_t)0 #endif ```Let me know your thoughts.
Quoted 7 lines
Quoted 2 lines
Thanks for the analysis; I hadn't noticed this specific issue, it just smelled a bit fishy. Anyway, the diff above looks better, thanks.
That propably deserves a comment.
Doesn't sparse and/or checkpatch complain about 0 being used in lieu of NULL ?
__BUG_FUNC is only used as parameter to asm code, not as pointer.
From the diff:
- : : "i" (__FILE__), "i" (__LINE__), \
+ : : "i" (__FILE__), "i" (__BUG_FUNC), "i" (__LINE__),\
The use is quite similar to __FILE__ and __LINE__. It might even be possible and appropriate to just define __BUG_FUNC as 0 if HAVE_BUG_FUNCTION is not defined.
Guenter
PATCH v4 8/14 loongarch: Add support for suppressing warning backtraces
In reply to Alessandro CarminatiFrom: Guenter Roeck <[email protected]>
Add name of functions triggering warning backtraces to the __bug_table object section to enable support for suppressing WARNING backtraces.
To limit image size impact, the pointer to the function name is only added to the __bug_table section if both CONFIG_KUNIT_SUPPRESS_BACKTRACE and CONFIG_DEBUG_BUGVERBOSE are enabled. Otherwise, the __func__ assembly parameter is replaced with a (dummy) NULL parameter to avoid an image size increase due to unused __func__ entries (this is necessary because __func__ is not a define but a virtual variable).
--- arch/loongarch/include/asm/bug.h | 42 ++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 13 deletions(-)
arch/loongarch/include/asm/bug.h +29 -13
@@ -3,49 +3,65 @@#define __ASM_BUG_H#include <asm/break.h> +#include <kunit/bug.h> #include <linux/stringify.h> #include <linux/objtool.h> #ifndef CONFIG_DEBUG_BUGVERBOSE -#define _BUGVERBOSE_LOCATION (file, line) +#define _BUGVERBOSE_LOCATION (file, func, line)#else -#define __BUGVERBOSE_LOCATION (file, line) \ +#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE +# define HAVE_BUG_FUNCTION +# define __BUG_FUNC_PTR (func) .long func - .; +#else +# define __BUG_FUNC_PTR (func) +#endif /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ + +#define __BUGVERBOSE_LOCATION (file, func, line) \ .pushsection .rodata.str, "aMS", @progbits, 1; \ 10002: .string file; \ .popsection; \ \ .long 10002b - .; \ + __BUG_FUNC_PTR(func) \ .short line; -#define _BUGVERBOSE_LOCATION (file, line) __BUGVERBOSE_LOCATION(file, line) +#define _BUGVERBOSE_LOCATION (file, func, line) __BUGVERBOSE_LOCATION(file, func, line)#endif #ifndef CONFIG_GENERIC_BUG -#define __BUG_ENTRY (flags) +#define __BUG_ENTRY (flags, func)#else -#define __BUG_ENTRY (flags) \ +#define __BUG_ENTRY (flags, func) \ .pushsection __bug_table, "aw"; \ .align 2; \ 10000: .long 10001f - .; \ - _BUGVERBOSE_LOCATION(__FILE__, __LINE__) \ + _BUGVERBOSE_LOCATION(__FILE__, func, __LINE__) \ .short flags; \ .popsection; \ 10001:#endif -#define ASM_BUG_FLAGS (flags) \ - __BUG_ENTRY(flags) \ +#define ASM_BUG_FLAGS (flags, func) \ + __BUG_ENTRY(flags, func) \ break BRK_BUG; -#define ASM_BUG () ASM_BUG_FLAGS(0) +#define ASM_BUG () ASM_BUG_FLAGS(0, .) + +#ifdef HAVE_BUG_FUNCTION +# define __BUG_FUNC __func__ +#else +# define __BUG_FUNC NULL +#endif -#define __BUG_FLAGS (flags, extra) \ - asm_inline volatile (__stringify(ASM_BUG_FLAGS(flags)) \ - extra); +#define __BUG_FLAGS (flags, extra) \ + asm_inline volatile (__stringify(ASM_BUG_FLAGS(flags, %0)) \ + extra : : "i" (__BUG_FUNC) );#define __WARN_FLAGS (flags) \ do { \ instrumentation_begin(); \ - __BUG_FLAGS(BUGFLAG_WARNING|(flags), ANNOTATE_REACHABLE(10001b));\ + if (!KUNIT_IS_SUPPRESSED_WARNING(__func__)) \ + __BUG_FLAGS(BUGFLAG_WARNING|(flags), ANNOTATE_REACHABLE(10001b));\ instrumentation_end(); \ } while (0)
Signature · 1 line
2.34.1
PATCH v4 9/14 parisc: Add support for suppressing warning backtraces
In reply to Alessandro CarminatiFrom: Guenter Roeck <[email protected]>
Add name of functions triggering warning backtraces to the __bug_table object section to enable support for suppressing WARNING backtraces.
To limit image size impact, the pointer to the function name is only added to the __bug_table section if both CONFIG_KUNIT_SUPPRESS_BACKTRACE and CONFIG_DEBUG_BUGVERBOSE are enabled. Otherwise, the __func__ assembly parameter is replaced with a (dummy) NULL parameter to avoid an image size increase due to unused __func__ entries (this is necessary because __func__ is not a define but a virtual variable).
While at it, declare assembler parameters as constants where possible. Refine .blockz instructions to calculate the necessary padding instead of using fixed values.
--- arch/parisc/include/asm/bug.h | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-)
arch/parisc/include/asm/bug.h +21 -8
@@ -23,8 +23,17 @@# define __BUG_REL (val) ".word " __stringify(val)#endif -#ifdef CONFIG_DEBUG_BUGVERBOSE + +#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE +# define HAVE_BUG_FUNCTION +# define __BUG_FUNC_PTR __BUG_REL(%c1) +# define __BUG_FUNC __func__ +#else +# define __BUG_FUNC_PTR +# define __BUG_FUNC NULL +#endif /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ +#define BUG () \ do { \ asm volatile("\n" \
@@ -33,10 +42,12 @@"\t.align 4\n" \ "2:\t" __BUG_REL(1b) "\n" \ "\t" __BUG_REL(%c0) "\n" \ -"\t.short %1, %2\n" \ -"\t.blockz %3-2*4-2*2\n" \ +"\t" __BUG_FUNC_PTR"\n" \ +"\t.short %c2, %c3\n" \ +"\t.blockz %c4-(.-2b)\n" \"\t.popsection" \ - : : "i" (__FILE__), "i" (__LINE__), \ + : : "i" (__FILE__), "i" (__BUG_FUNC), \ +"i" (__LINE__), \ "i" (0), "i" (sizeof(struct bug_entry)) ); \unreachable (); \ }while (0 )
@@ -58,10 +69,12 @@"\t.align 4\n" \ "2:\t" __BUG_REL(1b) "\n" \ "\t" __BUG_REL(%c0) "\n" \ -"\t.short %1, %2\n" \ -"\t.blockz %3-2*4-2*2\n" \ +"\t" __BUG_FUNC_PTR"\n" \ +"\t.short %c2, %3\n" \ +"\t.blockz %c4-(.-2b)\n" \"\t.popsection" \ - : : "i" (__FILE__), "i" (__LINE__), \ + : : "i" (__FILE__), "i" (__BUG_FUNC), \ +"i" (__LINE__), \"i" (BUGFLAG_WARNING |(flags)), \ "i" (sizeof(struct bug_entry)) ); \ }while (0 )
@@ -74,7 +87,7 @@"\t.align 4\n" \ "2:\t" __BUG_REL(1b) "\n" \"\t.short %0\n" \ -"\t.blockz %1-4-2\n" \ +"\t.blockz %c1-(.-2b)\n" \"\t.popsection" \ : : "i" (BUGFLAG_WARNING|(flags)), \ "i" (sizeof(struct bug_entry)) ); \
Signature · 1 line
2.34.1
PATCH v4 10/14 s390: Add support for suppressing warning backtraces
In reply to Alessandro CarminatiFrom: Guenter Roeck <[email protected]>
Add name of functions triggering warning backtraces to the __bug_table object section to enable support for suppressing WARNING backtraces.
To limit image size impact, the pointer to the function name is only added to the __bug_table section if both CONFIG_KUNIT_SUPPRESS_BACKTRACE and CONFIG_DEBUG_BUGVERBOSE are enabled. Otherwise, the __func__ assembly parameter is replaced with a (dummy) NULL parameter to avoid an image size increase due to unused __func__ entries (this is necessary because __func__ is not a define but a virtual variable).
--- arch/s390/include/asm/bug.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
arch/s390/include/asm/bug.h +14 -3
@@ -8,6 +8,15 @@#ifdef CONFIG_DEBUG_BUGVERBOSE +#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE +# define HAVE_BUG_FUNCTION +# define __BUG_FUNC_PTR " .long %0-.\n" +# define __BUG_FUNC __func__ +#else +# define __BUG_FUNC_PTR +# define __BUG_FUNC NULL +#endif /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ +#define __EMIT_BUG (x) do { \ asm_inline volatile( \ "0: mc 0,0\n" \
@@ -17,10 +26,12 @@".section __bug_table,\"aw\"\n" \"2: .long 0b-.\n" \" .long 1b-.\n" \ -" .short %0,%1\n" \ -" .org 2b+%2\n" \ + __BUG_FUNC_PTR \ +" .short %1,%2\n" \ +" .org 2b+%3\n" \".previous\n" \ - : : "i" (__LINE__), \ + : : "i" (__BUG_FUNC), \ +"i" (__LINE__), \"i" (x), \ "i" (sizeof(struct bug_entry))); \ }while (0 )
Signature · 1 line
2.34.1
Re: [PATCH v4 10/14] s390: Add support for suppressing warning backtraces
Quoted 28 lines · Alessandro Carminati
From: Guenter Roeck <[email protected]>
Add name of functions triggering warning backtraces to the
__bug_tableobject section to enable support for suppressing WARNING backtraces.To limit image size impact, the pointer to the function name is only added to the
__bug_tablesection if bothCONFIG_KUNIT_SUPPRESS_BACKTRACEandCONFIG_DEBUG_BUGVERBOSEare enabled. Otherwise, the__func__assembly parameter is replaced with a (dummy) NULL parameter to avoid an image size increase due to unused__func__entries (this is necessary because__func__is not a define but a virtual variable).Acked-by Dan Carpenter <[email protected]>Cc Heiko Carstens <[email protected]>Cc Vasily Gorbik <[email protected]>Cc Alexander Gordeev <[email protected]>Signed-off-by Guenter Roeck <[email protected]>Signed-off-by Alessandro Carminati <[email protected]>--- arch/s390/include/asm/bug.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)arch/s390/include/asm/bug.h +0
-0
arch/s390/include/asm/bug.h line 14
Quoted 7 lines
arch/s390/include/asm/bug.h +4
-0@@ -8,6 +8,15 @@#ifdef CONFIG_DEBUG_BUGVERBOSE +#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE +# define HAVE_BUG_FUNCTION +# define __BUG_FUNC_PTR " .long %0-.\n" +# define __BUG_FUNC __func__
gcc 7.5.0 on s390 barfs; it doesn't like the use of "__func__" with "%0-."
drivers/gpu/drm/bridge/analogix/analogix-i2c-dptx.c: In function 'anx_dp_aux_transfer':././include/linux/compiler_types.h:492:20: warning: asm operand 0 probably doesn't match constraints
I was unable to find an alternate constraint that the compiler would accept.
I don't know if the same problem is seen with older compilers on other architectures, or if the problem is relevant in the first place.
gcc 10.3.0 and later do not have this problem. I also tried s390 builds with gcc 9.4 and 9.5 but they both crash for unrelated reasons.
If this is a concern, the best idea I have is to make KUNIT_SUPPRESS_BACKTRACE depend on, say,
depends on CC_IS_CLANG || (CC_IS_GCC && GCC_VERSION >= 100300)
A more complex solution might be to define an architecture flag such as HAVE_SUPPRESS_BACKTRACE, make that conditional on the gcc version for s390 only, and make KUNIT_SUPPRESS_BACKTRACE depend on it.
Guenter
Arnd Bergmann
maintainerRe: [PATCH v4 10/14] s390: Add support for suppressing warning backtraces
Quoted 6 lines · Guenter Roeck
On 3/13/25 04:43, Alessandro Carminati wrote:
gcc 10.3.0 and later do not have this problem. I also tried s390 builds with gcc 9.4
and 9.5 but they both crash for unrelated reasons.
Quoted 7 lines
If this is a concern, the best idea I have is to make
KUNIT_SUPPRESS_BACKTRACEdepend on, say,depends on CC_IS_CLANG || (CC_IS_GCC && GCC_VERSION >= 100300)A more complex solution might be to define an architecture flag such as
HAVE_SUPPRESS_BACKTRACE, make that conditional on the gcc version for s390 only, and makeKUNIT_SUPPRESS_BACKTRACEdepend on it.
That is probably fine, there are very few users on s390 that build their own kernels, and they likely all have modern compilers anyway.
I should still send a patch to raise the minimum compiler version to gcc-8.1, but unfortunately that is not enough here.
Arnd
Re: [PATCH v4 10/14] s390: Add support for suppressing warning backtraces
In reply to Guenter RoeckHello Guenter,
Sorry for being late to the party.
Quoted 51 lines · Guenter Roeck
Quoted 28 lines · Alessandro Carminati
From: Guenter Roeck <[email protected]>
Add name of functions triggering warning backtraces to the
__bug_tableobject section to enable support for suppressing WARNING backtraces.To limit image size impact, the pointer to the function name is only added to the
__bug_tablesection if bothCONFIG_KUNIT_SUPPRESS_BACKTRACEandCONFIG_DEBUG_BUGVERBOSEare enabled. Otherwise, the__func__assembly parameter is replaced with a (dummy) NULL parameter to avoid an image size increase due to unused__func__entries (this is necessary because__func__is not a define but a virtual variable).Acked-by Dan Carpenter <[email protected]>Cc Heiko Carstens <[email protected]>Cc Vasily Gorbik <[email protected]>Cc Alexander Gordeev <[email protected]>Signed-off-by Guenter Roeck <[email protected]>Signed-off-by Alessandro Carminati <[email protected]>--- arch/s390/include/asm/bug.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)arch/s390/include/asm/bug.h +0
-0arch/s390/include/asm/bug.h line 14
Quoted 7 lines
arch/s390/include/asm/bug.h +4
-0@@ -8,6 +8,15 @@#ifdef CONFIG_DEBUG_BUGVERBOSE +#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE +# define HAVE_BUG_FUNCTION +# define __BUG_FUNC_PTR " .long %0-.\n" +# define __BUG_FUNC __func__gcc 7.5.0 on s390 barfs; it doesn't like the use of "
__func__" with "%0-."
drivers/gpu/drm/bridge/analogix/analogix-i2c-dptx.c: In function 'anx_dp_aux_transfer':././include/linux/compiler_types.h:492:20: warning: asm operand 0 probably doesn't match constraintsI was unable to find an alternate constraint that the compiler would accept.
I don't know if the same problem is seen with older compilers on other architectures, or if the problem is relevant in the first place.
gcc 10.3.0 and later do not have this problem. I also tried s390 builds with gcc 9.4 and 9.5 but they both crash for unrelated reasons.
Quoted 7 lines
If this is a concern, the best idea I have is to make
KUNIT_SUPPRESS_BACKTRACEdepend on, say,depends on CC_IS_CLANG || (CC_IS_GCC && GCC_VERSION >= 100300)A more complex solution might be to define an architecture flag such as
HAVE_SUPPRESS_BACKTRACE, make that conditional on the gcc version for s390 only, and makeKUNIT_SUPPRESS_BACKTRACEdepend on it.
I've spent some time trying to better define the problem. Although it may seem trivial, the old compiler simply doesn't work—I believe the issue is a bit more complex.
So, let me share some code and then comment on it.
$ cat bug-s390.c
#include "bug_entry.h"
#define asm_inline asm __inline
# define __BUG_FUNC_PTR " .long %0-.\n"
# define __BUG_FUNC __func__
#define __EMIT_BUG(x) do { \
asm_inline volatile( \
"0: mc 0,0\n" \
".section .rodata.str,\"aMS\",@progbits,1\n" \
"1: .asciz \""__FILE__"\"\n" \
".previous\n" \
".section __bug_table,\"aw\"\n" \
"2: .long 0b-.\n" \
" .long 1b-.\n" \
__BUG_FUNC_PTR \
" .short %1,%2\n" \
" .org 2b+%3\n" \
".previous\n" \
: : "i" (__BUG_FUNC), \
"i" (__LINE__), \
"i" (x), \
"i" (sizeof(struct bug_entry))); \
} while (0)#define BUG() do { \__EMIT_BUG(0); \
} while (0)
void f1(){BUG();
}
void f2(){BUG();
}
int main() {
BUG();
f1();
f2();
return 0;
}
$ # This is a stripped version of the s390x code for bug
$ ~/x-tools/s390x-ibm-linux-gnu_14/bin/s390x-ibm-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=/home/alessandro/x-tools/s390x-ibm-linux-gnu_14/bin/s390x-ibm-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/home/alessandro/x-tools/s390x-ibm-linux-gnu_14/bin/../libexec/gcc/s390x-ibm-linux-gnu/14.2.0/lto-wrapper
Target: s390x-ibm-linux-gnu
Configured with:
/home/alessandro/src/s390x-toolchain/.build/s390x-ibm-linux-gnu/src/gcc/configure
--build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu
--target=s390x-ibm-linux-gnu
--prefix=/home/alessandro/x-tools/s390x-ibm-linux-gnu
--exec_prefix=/home/alessandro/x-tools/s390x-ibm-linux-gnu
--with-sysroot=/home/alessandro/x-tools/s390x-ibm-linux-gnu/s390x-ibm-linux-gnu/sysroot
--enable-languages=c,c++ --with-pkgversion='crosstool-NG
1.27.0.18_7458341' --enable-__cxa_atexit --disable-libmudflap
--disable-libgomp --disable-libssp --disable-libquadmath
--disable-libquadmath-support --disable-libsanitizer --disable-libmpx
--with-gmp=/home/alessandro/src/s390x-toolchain/.build/s390x-ibm-linux-gnu/buildtools
--with-mpfr=/home/alessandro/src/s390x-toolchain/.build/s390x-ibm-linux-gnu/buildtools
--with-mpc=/home/alessandro/src/s390x-toolchain/.build/s390x-ibm-linux-gnu/buildtools
--with-isl=/home/alessandro/src/s390x-toolchain/.build/s390x-ibm-linux-gnu/buildtools
--enable-lto --enable-threads=posix --enable-target-optspace
--disable-plugin --disable-nls --disable-multilib
--with-local-prefix=/home/alessandro/x-tools/s390x-ibm-linux-gnu/s390x-ibm-linux-gnu/sysroot
--enable-long-long
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.0 (crosstool-NG 1.27.0.18_7458341)
$ ~/x-tools/s390x-ibm-linux-gnu_14/bin/s390x-ibm-linux-gnu-gcc -S -m64
bug-s390.c
$ ~/x-tools/s390x-ibm-linux-gnu_14/bin/s390x-ibm-linux-gnu-gcc -S -m64
-fPIC bug-s390.c
$ ~/x-tools/s390x-ibm-linux-gnu/bin/s390x-ibm-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=/home/alessandro/x-tools/s390x-ibm-linux-gnu/bin/s390x-ibm-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/home/alessandro/x-tools/s390x-ibm-linux-gnu/libexec/gcc/s390x-ibm-linux-gnu/7.5.0/lto-wrapper
Target: s390x-ibm-linux-gnu
Configured with:
/home/alessandro/src/cross-s390/.build/s390x-ibm-linux-gnu/src/gcc/configure
--build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu
--target=s390x-ibm-linux-gnu
--prefix=/home/alessandro/x-tools/s390x-ibm-linux-gnu
--exec_prefix=/home/alessandro/x-tools/s390x-ibm-linux-gnu
--with-sysroot=/home/alessandro/x-tools/s390x-ibm-linux-gnu/s390x-ibm-linux-gnu/sysroot
--enable-languages=c --with-pkgversion='crosstool-NG
1.27.0.18_7458341' --enable-__cxa_atexit --disable-tm-clone-registry
--disable-libmudflap --disable-libgomp --disable-libssp
--disable-libquadmath --disable-libquadmath-support
--disable-libsanitizer --disable-libmpx --disable-libstdcxx-verbose
--with-gmp=/home/alessandro/src/cross-s390/.build/s390x-ibm-linux-gnu/buildtools
--with-mpfr=/home/alessandro/src/cross-s390/.build/s390x-ibm-linux-gnu/buildtools
--with-mpc=/home/alessandro/src/cross-s390/.build/s390x-ibm-linux-gnu/buildtools
--with-isl=/home/alessandro/src/cross-s390/.build/s390x-ibm-linux-gnu/buildtools
--enable-lto --without-zstd --enable-threads=posix
--enable-target-optspace --disable-plugin --disable-nls
--disable-multilib
--with-local-prefix=/home/alessandro/x-tools/s390x-ibm-linux-gnu/s390x-ibm-linux-gnu/sysroot
--enable-long-long
Thread model: posix
gcc version 7.5.0 (crosstool-NG 1.27.0.18_7458341)
$ ~/x-tools/s390x-ibm-linux-gnu/bin/s390x-ibm-linux-gnu-gcc -S -m64 bug-s390.c
$ ~/x-tools/s390x-ibm-linux-gnu/bin/s390x-ibm-linux-gnu-gcc -S -m64
-fPIC bug-s390.c
bug-s390.c: In function 'f1':
bug-s390.c:2:20: warning: asm operand 0 probably doesn't match constraints
#define asm_inline asm __inline
^
bug-s390.c:6:2: note: in expansion of macro 'asm_inline'
asm_inline volatile( \
^~~~~~~~~~
bug-s390.c:25:2: note: in expansion of macro '__EMIT_BUG'
__EMIT_BUG(0); \
^~~~~~~~~~
bug-s390.c:29:2: note: in expansion of macro 'BUG'
BUG();
^~~
bug-s390.c:2:20: error: impossible constraint in 'asm'
#define asm_inline asm __inline
^
bug-s390.c:6:2: note: in expansion of macro 'asm_inline'
asm_inline volatile( \
^~~~~~~~~~
bug-s390.c:25:2: note: in expansion of macro '__EMIT_BUG'
__EMIT_BUG(0); \
^~~~~~~~~~
bug-s390.c:29:2: note: in expansion of macro 'BUG'
BUG();
^~~
bug-s390.c: In function 'f2':
bug-s390.c:2:20: warning: asm operand 0 probably doesn't match constraints
#define asm_inline asm __inline
^
bug-s390.c:6:2: note: in expansion of macro 'asm_inline'
asm_inline volatile( \
^~~~~~~~~~
bug-s390.c:25:2: note: in expansion of macro '__EMIT_BUG'
__EMIT_BUG(0); \
^~~~~~~~~~
bug-s390.c:32:2: note: in expansion of macro 'BUG'
BUG();
^~~
bug-s390.c: In function 'main':
bug-s390.c:2:20: warning: asm operand 0 probably doesn't match constraints
#define asm_inline asm __inline
^
bug-s390.c:6:2: note: in expansion of macro 'asm_inline'
asm_inline volatile( \
^~~~~~~~~~
bug-s390.c:25:2: note: in expansion of macro '__EMIT_BUG'
__EMIT_BUG(0); \
^~~~~~~~~~
bug-s390.c:35:2: note: in expansion of macro 'BUG'
BUG();
^~~
$ cat linux-6.14-rc7/arch/s390/Makefile| grep "fPIC"
KBUILD_AFLAGS_MODULE += -fPIC
KBUILD_CFLAGS_MODULE += -fPIC
KBUILD_CFLAGS += -fPICAs you can see, the problem is not that the compiler itself doesn't work, but rather that -fPIC introduces some complications. __func__ is a compile-time constant, but this holds true only for traditionally linked code.
When compiling position-independent code, this assumption no longer applies.
GCC makes significant efforts to handle this, and for several architectures, it manages to solve the problem.
However, this is not universally the case.
Additionally, -fPIC is not widely used in kernel code... I have only seen it used for VDSO, the x86 boot piggyback decompressor, PowerPC boot, and the s390x architecture.
That said, GCC has been mitigating this issue, allowing us to treat a non-compile-time constant as if it were one.
A proof of this is that, at least since GCC 11, the s390x version of GCC is able to build this code.
Before that... certainly in GCC 7.5 it couldn't.
A simple fix would be to restrict usage to GCC versions greater than 11 for s390.
The real concern is that we have a latent issue that could be triggered by changes in build settings, as "feature" support varies across GCC versions and architectures.
For example, while x86_64 at version 14 seems to work both with and without -fPIC, this is not the case for AArch64, where enabling -fPIC causes failures even in version 14.
I'm currently working on a long-term fix for this.
Quoted 3 lines
Guenter
Signature · 2 lines
--- Alessandro
Heiko Carstens
maintainerRe: [PATCH v4 10/14] s390: Add support for suppressing warning backtraces
Quoted 6 lines · Alessandro Carminati
Quoted 6 lines
arch/s390/include/asm/bug.h line 14
Quoted 4 lines
arch/s390/include/asm/bug.h +4
-0+#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE +# define HAVE_BUG_FUNCTION +# define __BUG_FUNC_PTR " .long %0-.\n" +# define __BUG_FUNC __func__gcc 7.5.0 on s390 barfs; it doesn't like the use of "
__func__" with "%0-."
...
Quoted 7 lines
GCC makes significant efforts to handle this, and for several architectures, it manages to solve the problem.
However, this is not universally the case.
Additionally, -fPIC is not widely used in kernel code... I have only seen it used for VDSO, the x86 boot piggyback decompressor, PowerPC boot, and the s390x architecture.
Quoted 8 lines
That said, GCC has been mitigating this issue, allowing us to treat a non-compile-time constant as if it were one.
A proof of this is that, at least since GCC 11, the s390x version of GCC is able to build this code.
Before that... certainly in GCC 7.5 it couldn't.A simple fix would be to restrict usage to GCC versions greater than 11 for s390.
But please add that dependency only for this new feature for the time being. Right now I would not like to see that s390 is the only architecture (besides parisc) which requires a much higher minimum gcc level than every other architecture. Unless there are specific reasons.
PATCH v4 11/14 sh: Add support for suppressing warning backtraces
In reply to Alessandro CarminatiFrom: Guenter Roeck <[email protected]>
Add name of functions triggering warning backtraces to the __bug_table object section to enable support for suppressing WARNING backtraces.
To limit image size impact, the pointer to the function name is only added to the __bug_table section if both CONFIG_KUNIT_SUPPRESS_BACKTRACE and CONFIG_DEBUG_BUGVERBOSE are enabled. Otherwise, the __func__ assembly parameter is replaced with a (dummy) NULL parameter to avoid an image size increase due to unused __func__ entries (this is necessary because __func__ is not a define but a virtual variable).
--- arch/sh/include/asm/bug.h | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
arch/sh/include/asm/bug.h +22 -4
@@ -24,21 +24,36 @@* The offending file and line are encoded in the __bug_table section. */ #ifdef CONFIG_DEBUG_BUGVERBOSE + +#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE +# define HAVE_BUG_FUNCTION +# define __BUG_FUNC_PTR "\t.long %O2\n" +#else +# define __BUG_FUNC_PTR +#endif /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ +#define _EMIT_BUG_ENTRY \ "\t.pushsection __bug_table,\"aw\"\n" \ "2:\t.long 1b, %O1\n" \ - "\t.short %O2, %O3\n" \ - "\t.org 2b+%O4\n" \ + __BUG_FUNC_PTR \ + "\t.short %O3, %O4\n" \ + "\t.org 2b+%O5\n" \ "\t.popsection\n"#else #define _EMIT_BUG_ENTRY \ "\t.pushsection __bug_table,\"aw\"\n" \ "2:\t.long 1b\n" \ - "\t.short %O3\n" \ - "\t.org 2b+%O4\n" \ + "\t.short %O4\n" \ + "\t.org 2b+%O5\n" \ "\t.popsection\n"#endif +#ifdef HAVE_BUG_FUNCTION +# define __BUG_FUNC __func__ +#else +# define __BUG_FUNC NULL +#endif +#define BUG () \ do { \ __asm__ __volatile__ ( \
@@ -47,6 +62,7 @@ do { \ : \ : "n" (TRAPA_BUG_OPCODE), \"i" (__FILE__), \ +"i" (__BUG_FUNC), \"i" (__LINE__),"i" (0 ), \ "i" (sizeof(struct bug_entry))); \unreachable (); \
@@ -60,6 +76,7 @@ do { \ : \ : "n" (TRAPA_BUG_OPCODE), \"i" (__FILE__), \ +"i" (__BUG_FUNC), \"i" (__LINE__), \"i" (BUGFLAG_WARNING |(flags)), \ "i" (sizeof(struct bug_entry))); \
@@ -85,6 +102,7 @@ do { \ : \ : "n" (TRAPA_BUG_OPCODE), \"i" (__FILE__), \ +"i" (__BUG_FUNC), \"i" (__LINE__), \"i" (BUGFLAG_UNWINDER ), \ "i" (sizeof(struct bug_entry))); \
Signature · 1 line
2.34.1
PATCH v4 12/14 sh: Move defines needed for suppressing warning backtraces
In reply to Alessandro CarminatiFrom: Guenter Roeck <[email protected]>
Declaring the defines needed for suppressing warning inside '#ifdef CONFIG_DEBUG_BUGVERBOSE' results in a kerneldoc warning.
.../bug.h:29: warning: expecting prototype for _EMIT_BUG_ENTRY().
Prototype was for HAVE_BUG_FUNCTION() instead
Move the defines above the kerneldoc entry for _EMIT_BUG_ENTRY to make kerneldoc happy.
--- arch/sh/include/asm/bug.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
arch/sh/include/asm/bug.h +9 -7
@@ -11,6 +11,15 @@#define HAVE_ARCH_BUG #define HAVE_ARCH_WARN_ON +#ifdef CONFIG_DEBUG_BUGVERBOSE +#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE +# define HAVE_BUG_FUNCTION +# define __BUG_FUNC_PTR "\t.long %O2\n" +#else +# define __BUG_FUNC_PTR +#endif /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ +#endif /* CONFIG_DEBUG_BUGVERBOSE */ +/** * _EMIT_BUG_ENTRY * %1 - __FILE__
@@ -25,13 +34,6 @@*/ #ifdef CONFIG_DEBUG_BUGVERBOSE -#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE -# define HAVE_BUG_FUNCTION -# define __BUG_FUNC_PTR "\t.long %O2\n" -#else -# define __BUG_FUNC_PTR -#endif /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ -#define _EMIT_BUG_ENTRY \ "\t.pushsection __bug_table,\"aw\"\n" \ "2:\t.long 1b, %O1\n" \
Signature · 1 line
2.34.1
PATCH v4 13/14 riscv: Add support for suppressing warning backtraces
In reply to Alessandro CarminatiFrom: Guenter Roeck <[email protected]>
Add name of functions triggering warning backtraces to the __bug_table object section to enable support for suppressing WARNING backtraces.
To limit image size impact, the pointer to the function name is only added to the __bug_table section if both CONFIG_KUNIT_SUPPRESS_BACKTRACE and CONFIG_DEBUG_BUGVERBOSE are enabled. Otherwise, the __func__ assembly parameter is replaced with a (dummy) NULL parameter to avoid an image size increase due to unused __func__ entries (this is necessary because __func__ is not a define but a virtual variable).
To simplify the implementation, unify the __BUG_ENTRY_ADDR and __BUG_ENTRY_FILE macros into a single macro named __BUG_REL() which takes the address, file, or function reference as parameter.
--- arch/riscv/include/asm/bug.h | 38 ++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-)
arch/riscv/include/asm/bug.h +26 -12
@@ -30,26 +30,39 @@typedef u32 bug_insn_t ;#ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS -#define __BUG_ENTRY_ADDR RISCV_INT " 1b - ." -#define __BUG_ENTRY_FILE RISCV_INT " %0 - ." +#define __BUG_REL (val) RISCV_INT " " __stringify(val) " - ."#else -#define __BUG_ENTRY_ADDR RISCV_PTR " 1b" -#define __BUG_ENTRY_FILE RISCV_PTR " %0" +#define __BUG_REL (val) RISCV_PTR " " __stringify(val)#endif #ifdef CONFIG_DEBUG_BUGVERBOSE + +#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE +# define HAVE_BUG_FUNCTION +# define __BUG_FUNC_PTR __BUG_REL(%1) +#else +# define __BUG_FUNC_PTR +#endif /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ +#define __BUG_ENTRY \ - __BUG_ENTRY_ADDR "\n\t" \ - __BUG_ENTRY_FILE "\n\t" \ - RISCV_SHORT " %1\n\t" \ - RISCV_SHORT " %2" + __BUG_REL(1b) "\n\t" \ + __BUG_REL(%0) "\n\t" \ + __BUG_FUNC_PTR "\n\t" \ + RISCV_SHORT " %2\n\t" \ + RISCV_SHORT " %3"#else #define __BUG_ENTRY \ - __BUG_ENTRY_ADDR "\n\t" \ - RISCV_SHORT " %2" + __BUG_REL(1b) "\n\t" \ + RISCV_SHORT " %3"#endif #ifdef CONFIG_GENERIC_BUG +#ifdef HAVE_BUG_FUNCTION +# define __BUG_FUNC __func__ +#else +# define __BUG_FUNC NULL +#endif +#define __BUG_FLAGS (flags) \ do { \ __asm__ __volatile__ ( \
@@ -58,10 +71,11 @@ do { \".pushsection __bug_table,\"aw\"\n\t" \"2:\n\t" \ __BUG_ENTRY"\n\t" \ -".org 2b + %3\n\t" \ +".org 2b + %4\n\t" \".popsection" \ : \ - : "i" (__FILE__), "i" (__LINE__), \ + : "i" (__FILE__), "i" (__BUG_FUNC), \ +"i" (__LINE__), \"i" (flags), \ "i" (sizeof(struct bug_entry))); \ }while (0 )
Signature · 1 line
2.34.1
PATCH v4 14/14 powerpc: Add support for suppressing warning backtraces
In reply to Alessandro CarminatiFrom: Guenter Roeck <[email protected]>
Add name of functions triggering warning backtraces to the __bug_table object section to enable support for suppressing WARNING backtraces.
To limit image size impact, the pointer to the function name is only added to the __bug_table section if both CONFIG_KUNIT_SUPPRESS_BACKTRACE and CONFIG_DEBUG_BUGVERBOSE are enabled. Otherwise, the __func__ assembly parameter is replaced with a (dummy) NULL parameter to avoid an image size increase due to unused __func__ entries (this is necessary because __func__ is not a define but a virtual variable).
--- arch/powerpc/include/asm/bug.h | 37 +++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-)
arch/powerpc/include/asm/bug.h +28 -9
@@ -14,6 +14,9 @@ .section __bug_table,"aw" 5001: .4byte \addr - . .4byte 5002f - . +#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE + .4byte 0 +#endif .short \line, \flags .org 5001b+BUG_ENTRY_SIZE .previous
@@ -32,30 +35,46 @@#endif /* verbose */ #else /* !__ASSEMBLY__ */ -/* _EMIT_BUG_ENTRY expects args %0,%1,%2,%3 to be FILE, LINE, flags and -sizeof(struct bug_entry), respectively */ +/* _EMIT_BUG_ENTRY expects args %0,%1,%2,%3,%4 to be FILE, __func__, LINE, flags +and sizeof(struct bug_entry), respectively */ #ifdef CONFIG_DEBUG_BUGVERBOSE + +#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE +# define HAVE_BUG_FUNCTION +# define __BUG_FUNC_PTR " .4byte %1 - .\n" +#else +# define __BUG_FUNC_PTR +#endif /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ +#define _EMIT_BUG_ENTRY \ ".section __bug_table,\"aw\"\n" \ "2: .4byte 1b - .\n" \ " .4byte %0 - .\n" \ - " .short %1, %2\n" \ - ".org 2b+%3\n" \ + __BUG_FUNC_PTR \ + " .short %2, %3\n" \ + ".org 2b+%4\n" \ ".previous\n"#else #define _EMIT_BUG_ENTRY \ ".section __bug_table,\"aw\"\n" \ "2: .4byte 1b - .\n" \ - " .short %2\n" \ - ".org 2b+%3\n" \ + " .short %3\n" \ + ".org 2b+%4\n" \ ".previous\n"#endif +#ifdef HAVE_BUG_FUNCTION +# define __BUG_FUNC __func__ +#else +# define __BUG_FUNC NULL +#endif +#define BUG_ENTRY (insn, flags, ...) \ __asm__ __volatile__( \ "1: " insn "\n" \ _EMIT_BUG_ENTRY \ - : : "i" (__FILE__), "i" (__LINE__), \ + : : "i" (__FILE__), "i" (__BUG_FUNC), \ + "i" (__LINE__), \ "i" (flags), \ "i" (sizeof(struct bug_entry)), \ ##__VA_ARGS__)
@@ -80,7 +99,7 @@if (x) \BUG (); \ }else { \ -BUG_ENTRY (PPC_TLNEI " %4, 0" ,0 ,"r" ((__force long )(x))); \ +BUG_ENTRY (PPC_TLNEI " %5, 0" ,0 ,"r" ((__force long )(x))); \ } \ }while (0 )
@@ -90,7 +109,7 @@if (__ret_warn_on) \__WARN (); \ }else { \ -BUG_ENTRY (PPC_TLNEI " %4, 0" , \ +BUG_ENTRY (PPC_TLNEI " %5, 0" , \BUGFLAG_WARNING |BUGFLAG_TAINT (TAINT_WARN ), \"r" (__ret_warn_on)); \ } \
Signature · 1 line
2.34.1
Quoted 3 lines · Alessandro Carminati
Some unit tests intentionally trigger warning backtraces by passing bad parameters to kernel API functions. Such unit tests typically check the return value from such calls, not the existence of the warning backtrace.
Thanks for picking this series back up! I honestly thought this had already landed. :)
Quoted 4 lines
With
CONFIG_KUNITenabled, image size increase with this series applied is approximately 1%. The image size increase (and with it the functionality introduced by this series) can be avoided by disablingCONFIG_KUNIT_SUPPRESS_BACKTRACE.
Yeah, as with my prior review, I'm a fan of this. It makes a bunch of my very noisy tests much easier to deal with.
-Kees
Signature · 1 line
Kees Cook
Maxime Ripard
maintainerHi,
Quoted 8 lines · Kees Cook
Quoted 3 lines · Alessandro Carminati
Some unit tests intentionally trigger warning backtraces by passing bad parameters to kernel API functions. Such unit tests typically check the return value from such calls, not the existence of the warning backtrace.
Thanks for picking this series back up! I honestly thought this had already landed. :)
Quoted 7 lines
Quoted 4 lines
With
CONFIG_KUNITenabled, image size increase with this series applied is approximately 1%. The image size increase (and with it the functionality introduced by this series) can be avoided by disablingCONFIG_KUNIT_SUPPRESS_BACKTRACE.Yeah, as with my prior review, I'm a fan of this. It makes a bunch of my very noisy tests much easier to deal with.
And for the record, we're also affected by this in DRM and would very much like to get it merged in one shape or another.
Maxime
Quoted 7 lines · Maxime Ripard
Quoted 3 lines
Yeah, as with my prior review, I'm a fan of this. It makes a bunch of my very noisy tests much easier to deal with.
And for the record, we're also affected by this in DRM and would very much like to get it merged in one shape or another.
I was unable to get maintainers of major architectures interested enough to provide feedback, and did not see a path forward. Maybe Alessandro has more success than me.
Guenter
Andrew Morton
maintainerQuoted 5 lines · On Thu, 13 Mar 2025 11:31:12 -0700 Guenter Roeck <[email protected]> wrote:
Quoted 4 lines · Maxime Ripard
Quoted 3 lines
Yeah, as with my prior review, I'm a fan of this. It makes a bunch of my very noisy tests much easier to deal with.
Quoted 7 lines
Quoted 3 lines
And for the record, we're also affected by this in DRM and would very much like to get it merged in one shape or another.
I was unable to get maintainers of major architectures interested enough to provide feedback, and did not see a path forward. Maybe Alessandro has more success than me.
I'll put them into mm.git, to advance things a bit.
If someone wants to merge via a different tree, please speak up.
Hopefully the various arch maintainers will review at least their parts of the series.
Shuah Khan
maintainerQuoted 11 lines · Andrew Morton
Quoted 9 lines · On Thu, 13 Mar 2025 11:31:12 -0700 Guenter Roeck <[email protected]> wrote:
Quoted 7 lines · Maxime Ripard
Quoted 3 lines
Yeah, as with my prior review, I'm a fan of this. It makes a bunch of my very noisy tests much easier to deal with.
And for the record, we're also affected by this in DRM and would very much like to get it merged in one shape or another.
Quoted 5 lines
Quoted 3 lines
I was unable to get maintainers of major architectures interested enough to provide feedback, and did not see a path forward. Maybe Alessandro has more success than me.
I'll put them into mm.git, to advance things a bit.
I haven't heard from kunit maintainers yet. This thread got lost in inbox due to travel.
David/Brendan/Rae, Okay to take this series?
Andrew, Okay to take this through your tree - this needs merging.
thanks,
-- Shuah
Andrew Morton
maintainerQuoted 18 lines · On Fri, 28 Mar 2025 16:14:55 -0600 Shuah Khan <[email protected]> wrote:
Quoted 11 lines · Andrew Morton
Quoted 9 lines · On Thu, 13 Mar 2025 11:31:12 -0700 Guenter Roeck <[email protected]> wrote:
Quoted 7 lines · Maxime Ripard
Quoted 3 lines
Yeah, as with my prior review, I'm a fan of this. It makes a bunch of my very noisy tests much easier to deal with.
And for the record, we're also affected by this in DRM and would very much like to get it merged in one shape or another.
Quoted 5 lines
Quoted 3 lines
I was unable to get maintainers of major architectures interested enough to provide feedback, and did not see a path forward. Maybe Alessandro has more success than me.
I'll put them into mm.git, to advance things a bit.
Quoted 7 lines
I haven't heard from kunit maintainers yet. This thread got lost in inbox due to travel.
David/Brendan/Rae, Okay to take this series?
Andrew, Okay to take this through your tree - this needs merging.
The review for 07/14 made me expect an update - perhaps tweak the asm constraints and add a comment. This can be addressed later, as long as we don't forget.
However
https://lkml.kernel.org/r/[email protected]
needs to be addressed before a merge. The series in mm.git breaks the s390 build.
Quoted 16 lines · Maxime Ripard
Hi,
Quoted 13 lines · Kees Cook
Quoted 3 lines · Alessandro Carminati
Some unit tests intentionally trigger warning backtraces by passing bad parameters to kernel API functions. Such unit tests typically check the return value from such calls, not the existence of the warning backtrace.
Thanks for picking this series back up! I honestly thought this had already landed. :)
Quoted 4 lines
With
CONFIG_KUNITenabled, image size increase with this series applied is approximately 1%. The image size increase (and with it the functionality introduced by this series) can be avoided by disablingCONFIG_KUNIT_SUPPRESS_BACKTRACE.
Quoted 5 lines
Quoted 2 lines
Yeah, as with my prior review, I'm a fan of this. It makes a bunch of my very noisy tests much easier to deal with.
And for the record, we're also affected by this in DRM and would very much like to get it merged in one shape or another.
Here is another case:
https://lore.kernel.org/all/[email protected]/
It would be very useful to have this feature merged. Without it, we may need to remove useful tests.
Maxime Ripard
maintainerQuoted 20 lines · Mickaël Salaün
Quoted 19 lines · Maxime Ripard
Hi,
Quoted 15 lines · Kees Cook
Quoted 3 lines · Alessandro Carminati
Some unit tests intentionally trigger warning backtraces by passing bad parameters to kernel API functions. Such unit tests typically check the return value from such calls, not the existence of the warning backtrace.
Thanks for picking this series back up! I honestly thought this had already landed. :)
Quoted 4 lines
With
CONFIG_KUNITenabled, image size increase with this series applied is approximately 1%. The image size increase (and with it the functionality introduced by this series) can be avoided by disablingCONFIG_KUNIT_SUPPRESS_BACKTRACE.Yeah, as with my prior review, I'm a fan of this. It makes a bunch of my very noisy tests much easier to deal with.
Quoted 8 lines
Quoted 2 lines
And for the record, we're also affected by this in DRM and would very much like to get it merged in one shape or another.
Here is another case:
https://lore.kernel.org/all/[email protected]/It would be very useful to have this feature merged. Without it, we may need to remove useful tests.
AFAIK, it's been merged in next a couple of weeks ago, so it should be in 6.15.
Maxime
Quoted 83 lines · Alessandro Carminati
Some unit tests intentionally trigger warning backtraces by passing bad parameters to kernel API functions. Such unit tests typically check the return value from such calls, not the existence of the warning backtrace.
Such intentionally generated warning backtraces are neither desirable nor useful for a number of reasons.
- They can result in overlooked real problems.
- A warning that suddenly starts to show up in unit tests needs to be investigated and has to be marked to be ignored, for example by adjusting filter scripts. Such filters are ad-hoc because there is no real standard format for warnings. On top of that, such filter scripts would require constant maintenance.One option to address problem would be to add messages such as "expected warning backtraces start / end here" to the kernel log. However, that would again require filter scripts, it might result in missing real problematic warning backtraces triggered while the test is running, and the irrelevant backtrace(s) would still clog the kernel log.
Solve the problem by providing a means to identify and suppress specific warning backtraces while executing test code. Support suppressing multiple backtraces while at the same time limiting changes to generic code to the absolute minimum. Architecture specific changes are kept at minimum by retaining function names only if both
CONFIG_DEBUG_BUGVERBOSEandCONFIG_KUNITare enabled.The first patch of the series introduces the necessary infrastructure. The second patch introduces support for counting suppressed backtraces. This capability is used in patch three to implement unit tests. Patch four documents the new API.
The next two patches add support for suppressing backtraces indrm_rectanddev_addr_listsunit tests. These patches are intended to serve as examples for the use of the functionality introduced with this series. The remaining patches implement the necessary changes for all architectures withGENERIC_BUGsupport.With
CONFIG_KUNITenabled, image size increase with this series applied is approximately 1%. The image size increase (and with it the functionality introduced by this series) can be avoided by disablingCONFIG_KUNIT_SUPPRESS_BACKTRACE.This series is based on the RFC patch and subsequent discussion at
https://patchwork.kernel.org/project/linux-kselftest/patch/[email protected]/
and offers a more comprehensive solution of the problem discussed there.Design note:
Function pointers are only added to the__bug_tablesection if bothCONFIG_KUNIT_SUPPRESS_BACKTRACEandCONFIG_DEBUG_BUGVERBOSEare enabled to avoid image size increases ifCONFIG_KUNITis disabled. There would be some benefits to adding those pointers all the time (reduced complexity, ability to display function names in BUG/WARNING messages). That change, if desired, can be made later.Checkpatch note:
Remaining checkpatch errors and warnings were deliberately ignored. Some are triggered by matching coding style or by comments interpreted as code, others by assembler macros which are disliked by checkpatch. Suggestions for improvements are welcome.Changes since RFC:
- IntroducedCONFIG_KUNIT_SUPPRESS_BACKTRACE
- Minor cleanups and bug fixes
- Added support for all affected architectures
- Added support for counting suppressed warnings
- Added unit tests using those counters
- Added patch to suppress warning backtraces indev_addr_liststestsChanges since v1:
- Rebased to v6.9-rc1
- Added Tested-by:, Acked-by:, and Reviewed-by: tags
[I retained those tags since there have been no functional changes]
- IntroducedKUNIT_SUPPRESS_BACKTRACEconfiguration option, enabled by default.Changes since v2:
- Rebased to v6.9-rc2
- Added comments to drm warning suppression explaining why it is needed.
- Added patch to move conditional code inarch/sh/include/asm/bug.hto avoid kerneldoc warning
- Added architecture maintainers to Cc: for architecture specific patches
- No functional changes
Quoted 8 lines
Changes since v3:
- Rebased to v6.14-rc6
- Dropped net: "kunit: Suppress lock warning noise at end ofdev_addr_liststests" since3db3b62955cd6d73afde05a17d7e8e106695c3b9
- Added__kunit_andKUNIT_prefixes.
- Tested on interessed architectures.----
Sorry: I also thought this had already landed.
I'm definitely in favour of us taking this, though agree that we definitely can't afford to break the s390x build.
I've (re-)reviewed the early patches as well, and am generally acking the series (though some of the architecture-specific patches are definitely beyond my expertise to review fully).
Cheers,
-- David
Quoted 44 lines
Guenter Roeck (14):
bug/kunit: Core support for suppressing warning backtraces
kunit: bug: Count suppressed warning backtraces
kunit: Add test cases for backtrace warning suppression
kunit: Add documentation for warning backtrace suppression API
drm: Suppress intentional warning backtraces in scaling unit tests
x86: Add support for suppressing warning backtraces
arm64: Add support for suppressing warning backtraces
loongarch: Add support for suppressing warning backtraces
parisc: Add support for suppressing warning backtraces
s390: Add support for suppressing warning backtraces
sh: Add support for suppressing warning backtraces
sh: Move defines needed for suppressing warning backtraces
riscv: Add support for suppressing warning backtraces
powerpc: Add support for suppressing warning backtracesDocumentation/dev-tools/kunit/usage.rst | 30 ++++++- arch/arm64/include/asm/asm-bug.h | 27 ++++-- arch/arm64/include/asm/bug.h | 8 +- arch/loongarch/include/asm/bug.h | 42 +++++++--- arch/parisc/include/asm/bug.h | 29 +++++-- arch/powerpc/include/asm/bug.h | 37 +++++++-- arch/riscv/include/asm/bug.h | 38 ++++++--- arch/s390/include/asm/bug.h | 17 +++- arch/sh/include/asm/bug.h | 28 ++++++- arch/x86/include/asm/bug.h | 21 +++-- drivers/gpu/drm/tests/drm_rect_test.c | 16 ++++ include/asm-generic/bug.h | 16 +++- include/kunit/bug.h | 56 +++++++++++++ include/kunit/test.h | 1 + include/linux/bug.h | 13 +++ lib/bug.c | 51 +++++++++++- lib/kunit/Kconfig | 9 ++ lib/kunit/Makefile | 7 +- lib/kunit/backtrace-suppression-test.c | 104 ++++++++++++++++++++++++ lib/kunit/bug.c | 42 ++++++++++ 20 files changed, 519 insertions(+), 73 deletions(-) create mode 100644 include/kunit/bug.h create mode 100644 lib/kunit/backtrace-suppression-test.c create mode 100644 lib/kunit/bug.c--
2.34.1
Andrew Morton
maintainerQuoted 3 lines · On Thu, 13 Mar 2025 11:43:15 +0000 Alessandro Carminati <[email protected]>…
Some unit tests intentionally trigger warning backtraces by passing bad parameters to kernel API functions. Such unit tests typically check the return value from such calls, not the existence of the warning backtrace.
I've had this series in mm.git's mm-new branch for a while. I didn't send it up for 6.15-rc1 due to what I believe to be unresolved review issues.
I'll drop this v4 series. Please resend if/when suitable.
Some notes I have taken are:
https://lkml.kernel.org/r/[email protected]
https://lkml.kernel.org/r/[email protected]
#arm64-add-support-for-suppressing-warning-backtraces.patch: check review
Some fixes I had merged which presumably should be carried forward are
https://lore.kernel.org/all/[email protected]/T/
https://lkml.kernel.org/r/[email protected]
Thanks.