linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64: avoid BUILD_BUG_ON() in alternative-macros
@ 2022-09-20 14:00 Mark Rutland
  2022-09-20 14:53 ` Ard Biesheuvel
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mark Rutland @ 2022-09-20 14:00 UTC (permalink / raw)
  To: linux-arm-kernel, Catalin Marinas
  Cc: ardb, james.morse, joey.gouly, mark.rutland, maz, nathan, will

Nathan reports that the build fails when using clang and LTO:

|  In file included from kernel/bounds.c:10:
|  In file included from ./include/linux/page-flags.h:10:
|  In file included from ./include/linux/bug.h:5:
|  In file included from ./arch/arm64/include/asm/bug.h:26:
|  In file included from ./include/asm-generic/bug.h:5:
|  In file included from ./include/linux/compiler.h:248:
|  In file included from ./arch/arm64/include/asm/rwonce.h:11:
|  ./arch/arm64/include/asm/alternative-macros.h:224:2: error: call to undeclared function 'BUILD_BUG_ON'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
|          BUILD_BUG_ON(feature >= ARM64_NCAPS);
|          ^
|  ./arch/arm64/include/asm/alternative-macros.h:241:2: error: call to undeclared function 'BUILD_BUG_ON'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
|          BUILD_BUG_ON(feature >= ARM64_NCAPS);
|          ^
|  2 errors generated.

... the problem being that when LTO is enabled, <asm/rwonce.h> includes
<asm/alternative-macros.h>, and causes a circular include dependency
through <linux/bug.h>. This manifests as BUILD_BUG_ON() not being
defined when used within <asm/alternative-macros.h>.

This patch avoids the problem and simplifies the include dependencies by
using compiletime_assert() instead of BUILD_BUG_ON().

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Fixes: 21fb26bfb01ffe0d ("arm64: alternatives: add alternative_has_feature_*()")
Reported-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Link: http://lore.kernel.org/r/YyigTrxhE3IRPzjs@dev-arch.thelio-3990X
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Joey Gouly <joey.gouly@arm.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Will Deacon <will@kernel.org>
---
 arch/arm64/include/asm/alternative-macros.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/include/asm/alternative-macros.h b/arch/arm64/include/asm/alternative-macros.h
index 4a2a98d6d2227..966767debaa3a 100644
--- a/arch/arm64/include/asm/alternative-macros.h
+++ b/arch/arm64/include/asm/alternative-macros.h
@@ -215,13 +215,13 @@ alternative_endif
 
 #ifndef __ASSEMBLY__
 
-#include <linux/bug.h>
 #include <linux/types.h>
 
 static __always_inline bool
 alternative_has_feature_likely(unsigned long feature)
 {
-	BUILD_BUG_ON(feature >= ARM64_NCAPS);
+	compiletime_assert(feature < ARM64_NCAPS,
+			   "feature must be < ARM64_NCAPS");
 
 	asm_volatile_goto(
 	ALTERNATIVE_CB("b	%l[l_no]", %[feature], alt_cb_patch_nops)
@@ -238,7 +238,8 @@ alternative_has_feature_likely(unsigned long feature)
 static __always_inline bool
 alternative_has_feature_unlikely(unsigned long feature)
 {
-	BUILD_BUG_ON(feature >= ARM64_NCAPS);
+	compiletime_assert(feature < ARM64_NCAPS,
+			   "feature must be < ARM64_NCAPS");
 
 	asm_volatile_goto(
 	ALTERNATIVE("nop", "b	%l[l_yes]", %[feature])
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] arm64: avoid BUILD_BUG_ON() in alternative-macros
  2022-09-20 14:00 [PATCH] arm64: avoid BUILD_BUG_ON() in alternative-macros Mark Rutland
@ 2022-09-20 14:53 ` Ard Biesheuvel
  2022-09-20 15:48 ` Marc Zyngier
  2022-09-21 12:04 ` Catalin Marinas
  2 siblings, 0 replies; 4+ messages in thread
From: Ard Biesheuvel @ 2022-09-20 14:53 UTC (permalink / raw)
  To: Mark Rutland
  Cc: linux-arm-kernel, Catalin Marinas, james.morse, joey.gouly, maz,
	nathan, will

On Tue, 20 Sept 2022 at 16:00, Mark Rutland <mark.rutland@arm.com> wrote:
>
> Nathan reports that the build fails when using clang and LTO:
>
> |  In file included from kernel/bounds.c:10:
> |  In file included from ./include/linux/page-flags.h:10:
> |  In file included from ./include/linux/bug.h:5:
> |  In file included from ./arch/arm64/include/asm/bug.h:26:
> |  In file included from ./include/asm-generic/bug.h:5:
> |  In file included from ./include/linux/compiler.h:248:
> |  In file included from ./arch/arm64/include/asm/rwonce.h:11:
> |  ./arch/arm64/include/asm/alternative-macros.h:224:2: error: call to undeclared function 'BUILD_BUG_ON'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
> |          BUILD_BUG_ON(feature >= ARM64_NCAPS);
> |          ^
> |  ./arch/arm64/include/asm/alternative-macros.h:241:2: error: call to undeclared function 'BUILD_BUG_ON'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
> |          BUILD_BUG_ON(feature >= ARM64_NCAPS);
> |          ^
> |  2 errors generated.
>
> ... the problem being that when LTO is enabled, <asm/rwonce.h> includes
> <asm/alternative-macros.h>, and causes a circular include dependency
> through <linux/bug.h>. This manifests as BUILD_BUG_ON() not being
> defined when used within <asm/alternative-macros.h>.
>
> This patch avoids the problem and simplifies the include dependencies by
> using compiletime_assert() instead of BUILD_BUG_ON().
>
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Fixes: 21fb26bfb01ffe0d ("arm64: alternatives: add alternative_has_feature_*()")
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Tested-by: Nathan Chancellor <nathan@kernel.org>
> Link: http://lore.kernel.org/r/YyigTrxhE3IRPzjs@dev-arch.thelio-3990X
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: James Morse <james.morse@arm.com>
> Cc: Joey Gouly <joey.gouly@arm.com>
> Cc: Marc Zyngier <maz@kernel.org>
> Cc: Will Deacon <will@kernel.org>

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>

> ---
>  arch/arm64/include/asm/alternative-macros.h | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm64/include/asm/alternative-macros.h b/arch/arm64/include/asm/alternative-macros.h
> index 4a2a98d6d2227..966767debaa3a 100644
> --- a/arch/arm64/include/asm/alternative-macros.h
> +++ b/arch/arm64/include/asm/alternative-macros.h
> @@ -215,13 +215,13 @@ alternative_endif
>
>  #ifndef __ASSEMBLY__
>
> -#include <linux/bug.h>
>  #include <linux/types.h>
>
>  static __always_inline bool
>  alternative_has_feature_likely(unsigned long feature)
>  {
> -       BUILD_BUG_ON(feature >= ARM64_NCAPS);
> +       compiletime_assert(feature < ARM64_NCAPS,
> +                          "feature must be < ARM64_NCAPS");
>
>         asm_volatile_goto(
>         ALTERNATIVE_CB("b       %l[l_no]", %[feature], alt_cb_patch_nops)
> @@ -238,7 +238,8 @@ alternative_has_feature_likely(unsigned long feature)
>  static __always_inline bool
>  alternative_has_feature_unlikely(unsigned long feature)
>  {
> -       BUILD_BUG_ON(feature >= ARM64_NCAPS);
> +       compiletime_assert(feature < ARM64_NCAPS,
> +                          "feature must be < ARM64_NCAPS");
>
>         asm_volatile_goto(
>         ALTERNATIVE("nop", "b   %l[l_yes]", %[feature])
> --
> 2.30.2
>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] arm64: avoid BUILD_BUG_ON() in alternative-macros
  2022-09-20 14:00 [PATCH] arm64: avoid BUILD_BUG_ON() in alternative-macros Mark Rutland
  2022-09-20 14:53 ` Ard Biesheuvel
@ 2022-09-20 15:48 ` Marc Zyngier
  2022-09-21 12:04 ` Catalin Marinas
  2 siblings, 0 replies; 4+ messages in thread
From: Marc Zyngier @ 2022-09-20 15:48 UTC (permalink / raw)
  To: Mark Rutland
  Cc: linux-arm-kernel, Catalin Marinas, ardb, james.morse, joey.gouly,
	nathan, will

On Tue, 20 Sep 2022 15:00:44 +0100,
Mark Rutland <mark.rutland@arm.com> wrote:
> 
> Nathan reports that the build fails when using clang and LTO:
> 
> |  In file included from kernel/bounds.c:10:
> |  In file included from ./include/linux/page-flags.h:10:
> |  In file included from ./include/linux/bug.h:5:
> |  In file included from ./arch/arm64/include/asm/bug.h:26:
> |  In file included from ./include/asm-generic/bug.h:5:
> |  In file included from ./include/linux/compiler.h:248:
> |  In file included from ./arch/arm64/include/asm/rwonce.h:11:
> |  ./arch/arm64/include/asm/alternative-macros.h:224:2: error: call to undeclared function 'BUILD_BUG_ON'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
> |          BUILD_BUG_ON(feature >= ARM64_NCAPS);
> |          ^
> |  ./arch/arm64/include/asm/alternative-macros.h:241:2: error: call to undeclared function 'BUILD_BUG_ON'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
> |          BUILD_BUG_ON(feature >= ARM64_NCAPS);
> |          ^
> |  2 errors generated.
> 
> ... the problem being that when LTO is enabled, <asm/rwonce.h> includes
> <asm/alternative-macros.h>, and causes a circular include dependency
> through <linux/bug.h>. This manifests as BUILD_BUG_ON() not being
> defined when used within <asm/alternative-macros.h>.
> 
> This patch avoids the problem and simplifies the include dependencies by
> using compiletime_assert() instead of BUILD_BUG_ON().
> 
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Fixes: 21fb26bfb01ffe0d ("arm64: alternatives: add alternative_has_feature_*()")
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Tested-by: Nathan Chancellor <nathan@kernel.org>
> Link: http://lore.kernel.org/r/YyigTrxhE3IRPzjs@dev-arch.thelio-3990X
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: James Morse <james.morse@arm.com>
> Cc: Joey Gouly <joey.gouly@arm.com>
> Cc: Marc Zyngier <maz@kernel.org>
> Cc: Will Deacon <will@kernel.org>
> ---
>  arch/arm64/include/asm/alternative-macros.h | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)

Acked-by: Marc Zyngier <maz@kernel.org>

	M.

-- 
Without deviation from the norm, progress is not possible.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] arm64: avoid BUILD_BUG_ON() in alternative-macros
  2022-09-20 14:00 [PATCH] arm64: avoid BUILD_BUG_ON() in alternative-macros Mark Rutland
  2022-09-20 14:53 ` Ard Biesheuvel
  2022-09-20 15:48 ` Marc Zyngier
@ 2022-09-21 12:04 ` Catalin Marinas
  2 siblings, 0 replies; 4+ messages in thread
From: Catalin Marinas @ 2022-09-21 12:04 UTC (permalink / raw)
  To: Mark Rutland, linux-arm-kernel
  Cc: Will Deacon, maz, joey.gouly, ardb, james.morse, nathan

On Tue, 20 Sep 2022 15:00:44 +0100, Mark Rutland wrote:
> Nathan reports that the build fails when using clang and LTO:
> 
> |  In file included from kernel/bounds.c:10:
> |  In file included from ./include/linux/page-flags.h:10:
> |  In file included from ./include/linux/bug.h:5:
> |  In file included from ./arch/arm64/include/asm/bug.h:26:
> |  In file included from ./include/asm-generic/bug.h:5:
> |  In file included from ./include/linux/compiler.h:248:
> |  In file included from ./arch/arm64/include/asm/rwonce.h:11:
> |  ./arch/arm64/include/asm/alternative-macros.h:224:2: error: call to undeclared function 'BUILD_BUG_ON'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
> |          BUILD_BUG_ON(feature >= ARM64_NCAPS);
> |          ^
> |  ./arch/arm64/include/asm/alternative-macros.h:241:2: error: call to undeclared function 'BUILD_BUG_ON'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
> |          BUILD_BUG_ON(feature >= ARM64_NCAPS);
> |          ^
> |  2 errors generated.
> 
> [...]

Applied to arm64 (for-next/alternatives), thanks!

[1/1] arm64: avoid BUILD_BUG_ON() in alternative-macros
      https://git.kernel.org/arm64/c/0072dc1b53c3

-- 
Catalin


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2022-09-21 12:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-20 14:00 [PATCH] arm64: avoid BUILD_BUG_ON() in alternative-macros Mark Rutland
2022-09-20 14:53 ` Ard Biesheuvel
2022-09-20 15:48 ` Marc Zyngier
2022-09-21 12:04 ` Catalin Marinas

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