* Re: [PATCH v2] lib/bitmap: workaround const_eval test build failure
2023-07-17 22:04 [PATCH v2] lib/bitmap: workaround const_eval test build failure Yury Norov
@ 2023-07-17 22:17 ` Nick Desaulniers
2023-07-18 13:44 ` Alexander Lobakin
2023-07-18 21:09 ` Yury Norov
2 siblings, 0 replies; 4+ messages in thread
From: Nick Desaulniers @ 2023-07-17 22:17 UTC (permalink / raw)
To: Yury Norov
Cc: linux-kernel, llvm, Andy Shevchenko, Alexander Lobakin,
Maxim Kuvyrkov, Rasmus Villemoes, Nathan Chancellor, Tom Rix,
oe-kbuild-all, kernel test robot
On Mon, Jul 17, 2023 at 3:04 PM Yury Norov <yury.norov@gmail.com> wrote:
>
> When building with Clang, and when KASAN and GCOV_PROFILE_ALL are both
> enabled, the test fails to build [1]:
>
> >> lib/test_bitmap.c:920:2: error: call to '__compiletime_assert_239' declared with 'error' attribute: BUILD_BUG_ON failed: !__builtin_constant_p(res)
> BUILD_BUG_ON(!__builtin_constant_p(res));
> ^
> include/linux/build_bug.h:50:2: note: expanded from macro 'BUILD_BUG_ON'
> BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
> ^
> include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
> #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
> ^
> include/linux/compiler_types.h:352:2: note: expanded from macro 'compiletime_assert'
> _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
> ^
> include/linux/compiler_types.h:340:2: note: expanded from macro '_compiletime_assert'
> __compiletime_assert(condition, msg, prefix, suffix)
> ^
> include/linux/compiler_types.h:333:4: note: expanded from macro '__compiletime_assert'
> prefix ## suffix(); \
> ^
> <scratch space>:185:1: note: expanded from here
> __compiletime_assert_239
>
> Originally it was attributed to s390, which now looks seemingly wrong. The
> issue is not related to bitmap code itself, but it breaks build for a given
> configuration.
>
> Disabling the const_eval test under that config may potentially hide other
> bugs. Instead, workaround it by disabling GCOV for the test_bitmap unless
> the compiler will get fixed.
>
> [1] https://github.com/ClangBuiltLinux/linux/issues/1874
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202307171254.yFcH97ej-lkp@intel.com/
> Fixes: dc34d5036692 ("lib: test_bitmap: add compile-time optimization/evaluations assertions")
> Co-developed-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Yury Norov <yury.norov@gmail.com>
Thanks for the patch. I hope to see if this is fixable in the
compiler soon, so that we can replace this with a compiler version
check should this be fixable (and then fixed) in the compiler. For
now, we will track this in the above github link.
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
> lib/Makefile | 6 ++++++
> lib/test_bitmap.c | 8 ++++----
> 2 files changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/lib/Makefile b/lib/Makefile
> index 42d307ade225..1ffae65bb7ee 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -82,7 +82,13 @@ obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o
> obj-$(CONFIG_TEST_DYNAMIC_DEBUG) += test_dynamic_debug.o
> obj-$(CONFIG_TEST_PRINTF) += test_printf.o
> obj-$(CONFIG_TEST_SCANF) += test_scanf.o
> +
> obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o
> +ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_KASAN),yy)
> +# FIXME: Clang breaks test_bitmap_const_eval when KASAN and GCOV are enabled
> +GCOV_PROFILE_test_bitmap.o := n
> +endif
> +
> obj-$(CONFIG_TEST_UUID) += test_uuid.o
> obj-$(CONFIG_TEST_XARRAY) += test_xarray.o
> obj-$(CONFIG_TEST_MAPLE_TREE) += test_maple_tree.o
> diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
> index 187f5b2db4cf..4a678de9c350 100644
> --- a/lib/test_bitmap.c
> +++ b/lib/test_bitmap.c
> @@ -1161,6 +1161,10 @@ static void __init test_bitmap_print_buf(void)
> }
> }
>
> +/*
> + * FIXME: Clang breaks compile-time evaluations when KASAN and GCOV are enabled.
> + * To workaround it, GCOV is force-disabled in Makefile for this configuration.
> + */
> static void __init test_bitmap_const_eval(void)
> {
> DECLARE_BITMAP(bitmap, BITS_PER_LONG);
> @@ -1186,11 +1190,7 @@ static void __init test_bitmap_const_eval(void)
> * the compiler is fixed.
> */
> bitmap_clear(bitmap, 0, BITS_PER_LONG);
> -#if defined(__s390__) && defined(__clang__)
> - if (!const_test_bit(7, bitmap))
> -#else
> if (!test_bit(7, bitmap))
> -#endif
> bitmap_set(bitmap, 5, 2);
>
> /* Equals to `unsigned long bitopvar = BIT(20)` */
> --
> 2.39.2
>
>
--
Thanks,
~Nick Desaulniers
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2] lib/bitmap: workaround const_eval test build failure
2023-07-17 22:04 [PATCH v2] lib/bitmap: workaround const_eval test build failure Yury Norov
2023-07-17 22:17 ` Nick Desaulniers
@ 2023-07-18 13:44 ` Alexander Lobakin
2023-07-18 21:09 ` Yury Norov
2 siblings, 0 replies; 4+ messages in thread
From: Alexander Lobakin @ 2023-07-18 13:44 UTC (permalink / raw)
To: Yury Norov
Cc: Nick Desaulniers, Andy Shevchenko, Alexander Lobakin,
Maxim Kuvyrkov, Rasmus Villemoes, Nathan Chancellor, Tom Rix,
oe-kbuild-all, kernel test robot, llvm, linux-kernel
From: Yury Norov <yury.norov@gmail.com>
Date: Mon, 17 Jul 2023 15:04:35 -0700
> When building with Clang, and when KASAN and GCOV_PROFILE_ALL are both
> enabled, the test fails to build [1]:
>
>>> lib/test_bitmap.c:920:2: error: call to '__compiletime_assert_239' declared with 'error' attribute: BUILD_BUG_ON failed: !__builtin_constant_p(res)
> BUILD_BUG_ON(!__builtin_constant_p(res));
> ^
> include/linux/build_bug.h:50:2: note: expanded from macro 'BUILD_BUG_ON'
> BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
> ^
> include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
> #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
> ^
> include/linux/compiler_types.h:352:2: note: expanded from macro 'compiletime_assert'
> _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
> ^
> include/linux/compiler_types.h:340:2: note: expanded from macro '_compiletime_assert'
> __compiletime_assert(condition, msg, prefix, suffix)
> ^
> include/linux/compiler_types.h:333:4: note: expanded from macro '__compiletime_assert'
> prefix ## suffix(); \
> ^
> <scratch space>:185:1: note: expanded from here
> __compiletime_assert_239
>
> Originally it was attributed to s390, which now looks seemingly wrong. The
> issue is not related to bitmap code itself, but it breaks build for a given
> configuration.
>
> Disabling the const_eval test under that config may potentially hide other
> bugs. Instead, workaround it by disabling GCOV for the test_bitmap unless
> the compiler will get fixed.
>
> [1] https://github.com/ClangBuiltLinux/linux/issues/1874
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202307171254.yFcH97ej-lkp@intel.com/
> Fixes: dc34d5036692 ("lib: test_bitmap: add compile-time optimization/evaluations assertions")
> Co-developed-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Yury Norov <yury.norov@gmail.com>
> ---
> lib/Makefile | 6 ++++++
> lib/test_bitmap.c | 8 ++++----
> 2 files changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/lib/Makefile b/lib/Makefile
> index 42d307ade225..1ffae65bb7ee 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -82,7 +82,13 @@ obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o
> obj-$(CONFIG_TEST_DYNAMIC_DEBUG) += test_dynamic_debug.o
> obj-$(CONFIG_TEST_PRINTF) += test_printf.o
> obj-$(CONFIG_TEST_SCANF) += test_scanf.o
> +
> obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o
> +ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_KASAN),yy)
> +# FIXME: Clang breaks test_bitmap_const_eval when KASAN and GCOV are enabled
> +GCOV_PROFILE_test_bitmap.o := n
> +endif
Oh, quite elegant!
> +
> obj-$(CONFIG_TEST_UUID) += test_uuid.o
> obj-$(CONFIG_TEST_XARRAY) += test_xarray.o
> obj-$(CONFIG_TEST_MAPLE_TREE) += test_maple_tree.o
> diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
> index 187f5b2db4cf..4a678de9c350 100644
> --- a/lib/test_bitmap.c
> +++ b/lib/test_bitmap.c
> @@ -1161,6 +1161,10 @@ static void __init test_bitmap_print_buf(void)
> }
> }
>
> +/*
> + * FIXME: Clang breaks compile-time evaluations when KASAN and GCOV are enabled.
> + * To workaround it, GCOV is force-disabled in Makefile for this configuration.
> + */
> static void __init test_bitmap_const_eval(void)
> {
> DECLARE_BITMAP(bitmap, BITS_PER_LONG);
> @@ -1186,11 +1190,7 @@ static void __init test_bitmap_const_eval(void)
> * the compiler is fixed.
> */
> bitmap_clear(bitmap, 0, BITS_PER_LONG);
> -#if defined(__s390__) && defined(__clang__)
> - if (!const_test_bit(7, bitmap))
> -#else
> if (!test_bit(7, bitmap))
> -#endif
...and even allows to remove that ugly piece.
> bitmap_set(bitmap, 5, 2);
>
> /* Equals to `unsigned long bitopvar = BIT(20)` */
I like this version the most.
Reviewed-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Thanks,
Olek
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2] lib/bitmap: workaround const_eval test build failure
2023-07-17 22:04 [PATCH v2] lib/bitmap: workaround const_eval test build failure Yury Norov
2023-07-17 22:17 ` Nick Desaulniers
2023-07-18 13:44 ` Alexander Lobakin
@ 2023-07-18 21:09 ` Yury Norov
2 siblings, 0 replies; 4+ messages in thread
From: Yury Norov @ 2023-07-18 21:09 UTC (permalink / raw)
To: linux-kernel, llvm, Nick Desaulniers
Cc: Andy Shevchenko, Alexander Lobakin, Maxim Kuvyrkov,
Rasmus Villemoes, Nathan Chancellor, Tom Rix, oe-kbuild-all,
kernel test robot
On Mon, Jul 17, 2023 at 03:04:35PM -0700, Yury Norov wrote:
> When building with Clang, and when KASAN and GCOV_PROFILE_ALL are both
> enabled, the test fails to build [1]:
>
> >> lib/test_bitmap.c:920:2: error: call to '__compiletime_assert_239' declared with 'error' attribute: BUILD_BUG_ON failed: !__builtin_constant_p(res)
> BUILD_BUG_ON(!__builtin_constant_p(res));
> ^
> include/linux/build_bug.h:50:2: note: expanded from macro 'BUILD_BUG_ON'
> BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
> ^
> include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
> #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
> ^
> include/linux/compiler_types.h:352:2: note: expanded from macro 'compiletime_assert'
> _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
> ^
> include/linux/compiler_types.h:340:2: note: expanded from macro '_compiletime_assert'
> __compiletime_assert(condition, msg, prefix, suffix)
> ^
> include/linux/compiler_types.h:333:4: note: expanded from macro '__compiletime_assert'
> prefix ## suffix(); \
> ^
> <scratch space>:185:1: note: expanded from here
> __compiletime_assert_239
>
> Originally it was attributed to s390, which now looks seemingly wrong. The
> issue is not related to bitmap code itself, but it breaks build for a given
> configuration.
>
> Disabling the const_eval test under that config may potentially hide other
> bugs. Instead, workaround it by disabling GCOV for the test_bitmap unless
> the compiler will get fixed.
>
> [1] https://github.com/ClangBuiltLinux/linux/issues/1874
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202307171254.yFcH97ej-lkp@intel.com/
> Fixes: dc34d5036692 ("lib: test_bitmap: add compile-time optimization/evaluations assertions")
> Co-developed-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Yury Norov <yury.norov@gmail.com>
So, I pushed it in bitmap-for-next. If nothing wrong will appear in
~week, I'll send a pull request, so expect merging it in this cycle.
Thank you for the work!
Thanks,
Yury
^ permalink raw reply [flat|nested] 4+ messages in thread