Skip to contentSkip to conversation

arm64: fix clang warning about TRAMP_VALIAS

PATCH Applied Arnd Bergmann 5 participants 6 messages Mar 16, 2022 – Mar 22, 2022 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: fix clang warning about TRAMP_VALIAS

From: Arnd Bergmann <[email protected]>

The newly introduced TRAMP_VALIAS definition causes a build warning with clang-14:

arch/arm64/include/asm/vectors.h:66:31: error: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Werror,-Wnull-pointer-arithmetic]

                return (char *)TRAMP_VALIAS + SZ_2K * slot;

Change the addition to something clang does not complain about.

Fixes bd09128d16fa ("arm64: Add percpu vectors for EL1")
---
 arch/arm64/include/asm/vectors.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

I see this warning on 5.17-rc8, but did not test it on linux-next, which may already have a fix.

arch/arm64/include/asm/vectors.h +2 -2
index f64613a96d53..bc9a2145f419 100644
@@ -56,14 +56,14 @@ enum arm64_bp_harden_el1_vectors {
 DECLARE_PER_CPU_READ_MOSTLY(const char *, this_cpu_vector);
 
 #ifndef CONFIG_UNMAP_KERNEL_AT_EL0
-#define TRAMP_VALIAS	0
+#define TRAMP_VALIAS	0ul
 #endif
 
 static inline const char *
 arm64_get_bp_hardening_vector(enum arm64_bp_harden_el1_vectors slot)
 {
 	if (arm64_kernel_unmapped_at_el0())
-		return (char *)TRAMP_VALIAS + SZ_2K * slot;
+		return (char *)(TRAMP_VALIAS + SZ_2K * slot);
 
 	WARN_ON_ONCE(slot == EL1_VECTOR_KPTI);
 
Signature · 1 line
2.29.2
Acked-by on v1 1/1
#1 lore raw

Hi Arnd,

Quoted 7 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The newly introduced TRAMP_VALIAS definition causes a build warning with clang-14:

arch/arm64/include/asm/vectors.h:66:31: error: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Werror,-Wnull-pointer-arithmetic]

                 return (char *)TRAMP_VALIAS + SZ_2K * slot;

It is? Good to know!
(clang 11 doesn't seem to be so fussy)

Just for some more background:
TRAMP_VALIAS existed before, but it wasn't defined if KPTI is disabled at compile time, you can't do that without CONFIG_EXPERT.
I thought these dummy definitions would be cleaner than #ifdef'ing the code.

Quoted 1 line

Change the addition to something clang does not complain about.

Thanks!

James

Quoted 25 lines

I see this warning on 5.17-rc8, but did not test it on linux-next, which may already have a fix.

arch/arm64/include/asm/vectors.h +2 -2
index f64613a96d53..bc9a2145f419 100644
@@ -56,14 +56,14 @@ enum arm64_bp_harden_el1_vectors {
  DECLARE_PER_CPU_READ_MOSTLY(const char *, this_cpu_vector);
 
  #ifndef CONFIG_UNMAP_KERNEL_AT_EL0
-#define TRAMP_VALIAS	0
+#define TRAMP_VALIAS	0ul
  #endif
 
  static inline const char *
  arm64_get_bp_hardening_vector(enum arm64_bp_harden_el1_vectors slot)
  {
  	if (arm64_kernel_unmapped_at_el0())
-		return (char *)TRAMP_VALIAS + SZ_2K * slot;
+		return (char *)(TRAMP_VALIAS + SZ_2K * slot);
 
  	WARN_ON_ONCE(slot == EL1_VECTOR_KPTI);
 
maintainer Applied
#2 lore raw
In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The newly introduced TRAMP_VALIAS definition causes a build warning with clang-14:

arch/arm64/include/asm/vectors.h:66:31: error: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Werror,-Wnull-pointer-arithmetic]

                return (char *)TRAMP_VALIAS + SZ_2K * slot;

[...]

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

[1/1] arm64: fix clang warning about TRAMP_VALIAS

      https://git.kernel.org/arm64/c/7f34b43e07cb
Signature · 1 line
Catalin
#3 lore raw
In reply to Arnd Bergmann
Quoted 6 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The newly introduced TRAMP_VALIAS definition causes a build warning with clang-14:

arch/arm64/include/asm/vectors.h:66:31: error: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Werror,-Wnull-pointer-arithmetic]

Tangentially, all the other GNU extensions we depend on throughout Linux are also GNU extensions. Do we know what's special about this one?

Robin.

Quoted 34 lines
                 return (char *)TRAMP_VALIAS + SZ_2K * slot;

Change the addition to something clang does not complain about.

Fixes bd09128d16fa ("arm64: Add percpu vectors for EL1")
---
  arch/arm64/include/asm/vectors.h | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

I see this warning on 5.17-rc8, but did not test it on linux-next, which may already have a fix.

arch/arm64/include/asm/vectors.h +2 -2
index f64613a96d53..bc9a2145f419 100644
@@ -56,14 +56,14 @@ enum arm64_bp_harden_el1_vectors {
  DECLARE_PER_CPU_READ_MOSTLY(const char *, this_cpu_vector);
 
  #ifndef CONFIG_UNMAP_KERNEL_AT_EL0
-#define TRAMP_VALIAS	0
+#define TRAMP_VALIAS	0ul
  #endif
 
  static inline const char *
  arm64_get_bp_hardening_vector(enum arm64_bp_harden_el1_vectors slot)
  {
  	if (arm64_kernel_unmapped_at_el0())
-		return (char *)TRAMP_VALIAS + SZ_2K * slot;
+		return (char *)(TRAMP_VALIAS + SZ_2K * slot);
 
  	WARN_ON_ONCE(slot == EL1_VECTOR_KPTI);
 
#4 lore raw
Quoted 11 lines · Robin Murphy
Quoted 6 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The newly introduced TRAMP_VALIAS definition causes a build warning with clang-14:

arch/arm64/include/asm/vectors.h:66:31: error: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Werror,-Wnull-pointer-arithmetic]

Tangentially, all the other GNU extensions we depend on throughout Linux are also GNU extensions. Do we know what's special about this one?

My first thought is that -Wnull-pointer-arithmetic should be in the -Wgnu flag group, such that -Wno-gnu (as set by Kbuild) implies -Wno-null-pointer-arithmetic.

One issue seems to be that -Wnull-pointer-arithmetic seems to control at least 2 different checks in clang.

https://godbolt.org/z/hdYYejj3d

So it's likely these two checks should have 2 distinct flags, such that the warning we're observing can be grouped under -Wgnu.

Filed: https://github.com/llvm/llvm-project/issues/54444

Quoted 37 lines

Robin.

Quoted 34 lines
                 return (char *)TRAMP_VALIAS + SZ_2K * slot;

Change the addition to something clang does not complain about.

Fixes bd09128d16fa ("arm64: Add percpu vectors for EL1")
---
  arch/arm64/include/asm/vectors.h | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

I see this warning on 5.17-rc8, but did not test it on linux-next, which may already have a fix.

arch/arm64/include/asm/vectors.h +2 -2
index f64613a96d53..bc9a2145f419 100644
@@ -56,14 +56,14 @@ enum arm64_bp_harden_el1_vectors {
  DECLARE_PER_CPU_READ_MOSTLY(const char *, this_cpu_vector);
 
  #ifndef CONFIG_UNMAP_KERNEL_AT_EL0
-#define TRAMP_VALIAS 0
+#define TRAMP_VALIAS 0ul
  #endif
 
  static inline const char *
  arm64_get_bp_hardening_vector(enum arm64_bp_harden_el1_vectors slot)
  {
      if (arm64_kernel_unmapped_at_el0())
-             return (char *)TRAMP_VALIAS + SZ_2K * slot;
+             return (char *)(TRAMP_VALIAS + SZ_2K * slot);
 
      WARN_ON_ONCE(slot == EL1_VECTOR_KPTI);
 
Signature · 2 lines
Thanks,
~Nick Desaulniers
#5 lore raw
Quoted 21 lines · Nick Desaulniers
Quoted 11 lines · Robin Murphy
Quoted 6 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The newly introduced TRAMP_VALIAS definition causes a build warning with clang-14:

arch/arm64/include/asm/vectors.h:66:31: error: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Werror,-Wnull-pointer-arithmetic]

Tangentially, all the other GNU extensions we depend on throughout Linux are also GNU extensions. Do we know what's special about this one?

My first thought is that -Wnull-pointer-arithmetic should be in the

(quoted diff) +0 -2
-Wgnu flag group, such that -Wno-gnu (as set by Kbuild) implies
-Wno-null-pointer-arithmetic.

One issue seems to be that -Wnull-pointer-arithmetic seems to control at least 2 different checks in clang.

Quoted 6 lines

https://godbolt.org/z/hdYYejj3d

So it's likely these two checks should have 2 distinct flags, such that the warning we're observing can be grouped under -Wgnu.

Filed: https://github.com/llvm/llvm-project/issues/54444

Fix should be landing shortly:
https://reviews.llvm.org/D122224

Signature · 2 lines
Thanks,
~Nick Desaulniers