Skip to contentSkip to conversation

sparc: mark __arch_xchg() as __always_inline

PATCH Applied Arnd Bergmann 8 participants 9 messages Jun 28, 2023 – Jul 13, 2023 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sparc: mark __arch_xchg() as __always_inline

From: Arnd Bergmann <[email protected]>

An otherwise correct change to the atomic operations uncovered an existing bug in the sparc __arch_xchg() function, which is calls __xchg_called_with_bad_pointer() when its arguments are unknown at compile time:

ERROR: modpost: "__xchg_called_with_bad_pointer" [lib/atomic64_test.ko] undefined!

This now happens because gcc determines that it's better to not inline the function. Avoid this by just marking the function as __always_inline to force the compiler to do the right thing here.

Fixes d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")
---
 arch/sparc/include/asm/cmpxchg_32.h | 2 +-
 arch/sparc/include/asm/cmpxchg_64.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/sparc/include/asm/cmpxchg_32.h +1 -1
index 7a1339533d1d7..d0af82c240b73 100644
@@ -15,7 +15,7 @@
 unsigned long __xchg_u32(volatile u32 *m, u32 new);
 void __xchg_called_with_bad_pointer(void);
 
-static inline unsigned long __arch_xchg(unsigned long x, __volatile__ void * ptr, int size)
+static __always_inline unsigned long __arch_xchg(unsigned long x, __volatile__ void * ptr, int size)
 {
 	switch (size) {
 	case 4:
arch/sparc/include/asm/cmpxchg_64.h +1 -1
index 66cd61dde9ec1..3de25262c4118 100644
@@ -87,7 +87,7 @@ xchg16(__volatile__ unsigned short *m, unsigned short val)
 	return (load32 & mask) >> bit_shift;
 }
 
-static inline unsigned long
+static __always_inline unsigned long
 __arch_xchg(unsigned long x, __volatile__ void * ptr, int size)
 {
 	switch (size) {
Signature · 1 line
2.39.2
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

An otherwise correct change to the atomic operations uncovered an existing bug in the sparc __arch_xchg() function, which is calls __xchg_called_with_bad_pointer() when its arguments are unknown at compile time:

ERROR: modpost: "__xchg_called_with_bad_pointer" [lib/atomic64_test.ko] undefined!

Quoted 8 lines

This now happens because gcc determines that it's better to not inline the function. Avoid this by just marking the function as __always_inline to force the compiler to do the right thing here.

Fixes d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")

Aha; you saved me writing a patch! :)

We should probably do likewise for all the other bits like __cmpxchg(), but either way:

Mark.

Quoted 34 lines
---
 arch/sparc/include/asm/cmpxchg_32.h | 2 +-
 arch/sparc/include/asm/cmpxchg_64.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/sparc/include/asm/cmpxchg_32.h +1 -1
index 7a1339533d1d7..d0af82c240b73 100644
@@ -15,7 +15,7 @@
 unsigned long __xchg_u32(volatile u32 *m, u32 new);
 void __xchg_called_with_bad_pointer(void);
 
-static inline unsigned long __arch_xchg(unsigned long x, __volatile__ void * ptr, int size)
+static __always_inline unsigned long __arch_xchg(unsigned long x, __volatile__ void * ptr, int size)
 {
 	switch (size) {
 	case 4:
arch/sparc/include/asm/cmpxchg_64.h +1 -1
index 66cd61dde9ec1..3de25262c4118 100644
@@ -87,7 +87,7 @@ xchg16(__volatile__ unsigned short *m, unsigned short val)
 	return (load32 & mask) >> bit_shift;
 }
 
-static inline unsigned long
+static __always_inline unsigned long
 __arch_xchg(unsigned long x, __volatile__ void * ptr, int size)
 {
 	switch (size) {
Signature · 1 line
2.39.2
Acked-by on v1 1/1
#4 lore raw
In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

An otherwise correct change to the atomic operations uncovered an existing bug in the sparc __arch_xchg() function, which is calls __xchg_called_with_bad_pointer() when its arguments are unknown at compile time:

ERROR: modpost: "__xchg_called_with_bad_pointer" [lib/atomic64_test.ko] undefined!

Quoted 8 lines

This now happens because gcc determines that it's better to not inline the function. Avoid this by just marking the function as __always_inline to force the compiler to do the right thing here.

Fixes d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")

Nice catch.

Quoted 31 lines
---
  arch/sparc/include/asm/cmpxchg_32.h | 2 +-
  arch/sparc/include/asm/cmpxchg_64.h | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
arch/sparc/include/asm/cmpxchg_32.h +1 -1
index 7a1339533d1d7..d0af82c240b73 100644
@@ -15,7 +15,7 @@
  unsigned long __xchg_u32(volatile u32 *m, u32 new);
  void __xchg_called_with_bad_pointer(void);
 
-static inline unsigned long __arch_xchg(unsigned long x, __volatile__ void * ptr, int size)
+static __always_inline unsigned long __arch_xchg(unsigned long x, __volatile__ void * ptr, int size)
  {
  	switch (size) {
  	case 4:
arch/sparc/include/asm/cmpxchg_64.h +1 -1
index 66cd61dde9ec1..3de25262c4118 100644
@@ -87,7 +87,7 @@ xchg16(__volatile__ unsigned short *m, unsigned short val)
  	return (load32 & mask) >> bit_shift;
  }
 
-static inline unsigned long
+static __always_inline unsigned long
  __arch_xchg(unsigned long x, __volatile__ void * ptr, int size)
  {
  	switch (size) {
Reviewed-by on v1 1/1
#5 lore raw
In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

An otherwise correct change to the atomic operations uncovered an existing bug in the sparc __arch_xchg() function, which is calls __xchg_called_with_bad_pointer() when its arguments are unknown at compile time:

ERROR: modpost: "__xchg_called_with_bad_pointer" [lib/atomic64_test.ko] undefined!

Quoted 8 lines

This now happens because gcc determines that it's better to not inline the function. Avoid this by just marking the function as __always_inline to force the compiler to do the right thing here.

Fixes d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")

I assume you will find a way to apply the patch.

Sam

Acked-by on v1 1/1
#7 lore raw
In reply to Arnd Bergmann

Hi Arnd,

Quoted 7 lines

An otherwise correct change to the atomic operations uncovered an existing bug in the sparc __arch_xchg() function, which is calls __xchg_called_with_bad_pointer() when its arguments are unknown at compile time:

ERROR: modpost: "__xchg_called_with_bad_pointer" [lib/atomic64_test.ko] undefined!

Quoted 8 lines

This now happens because gcc determines that it's better to not inline the function. Avoid this by just marking the function as __always_inline to force the compiler to do the right thing here.

Fixes d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")

Thanks,
Andi

#6 lore raw
In reply to Sam Ravnborg
Quoted 14 lines · Sam Ravnborg
Quoted 13 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

An otherwise correct change to the atomic operations uncovered an existing bug in the sparc __arch_xchg() function, which is calls __xchg_called_with_bad_pointer() when its arguments are unknown at compile time:

ERROR: modpost: "__xchg_called_with_bad_pointer" [lib/atomic64_test.ko] undefined!

This now happens because gcc determines that it's better to not inline the function. Avoid this by just marking the function as __always_inline to force the compiler to do the right thing here.

Quoted 7 lines
Quoted 4 lines
Fixes d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")

I assume you will find a way to apply the patch.

Hmmm, looks to me like this patch is sitting here for two weeks now without having made any progress. From a quick search on lore it also looks like Dave is not very active currently. Hence:

Arnd, is that maybe something that is worth sending straight to Linus?

Ciao, Thorsten (wearing his 'the Linux kernel's regression tracker' hat) --
Everything you wanna know about Linux kernel regression tracking:
https://linux-regtracking.leemhuis.info/about/#tldr
If I did something stupid, please tell me, as explained on that page.

#2 lore raw
In reply to Mark Rutland
Quoted 19 lines · Mark Rutland
Quoted 9 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

An otherwise correct change to the atomic operations uncovered an existing bug in the sparc __arch_xchg() function, which is calls __xchg_called_with_bad_pointer() when its arguments are unknown at compile time:

ERROR: modpost: "__xchg_called_with_bad_pointer" [lib/atomic64_test.ko] undefined!

Quoted 8 lines

This now happens because gcc determines that it's better to not inline the function. Avoid this by just marking the function as __always_inline to force the compiler to do the right thing here.

Fixes d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")
Quoted 6 lines

Aha; you saved me writing a patch! :)

We should probably do likewise for all the other bits like __cmpxchg(), but either way:

Though I'm not sure that means a whole lot over here ;)

Quoted 36 lines

Mark.

Quoted 34 lines
---
 arch/sparc/include/asm/cmpxchg_32.h | 2 +-
 arch/sparc/include/asm/cmpxchg_64.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/sparc/include/asm/cmpxchg_32.h +1 -1
index 7a1339533d1d7..d0af82c240b73 100644
@@ -15,7 +15,7 @@
 unsigned long __xchg_u32(volatile u32 *m, u32 new);
 void __xchg_called_with_bad_pointer(void);
 
-static inline unsigned long __arch_xchg(unsigned long x, __volatile__ void * ptr, int size)
+static __always_inline unsigned long __arch_xchg(unsigned long x, __volatile__ void * ptr, int size)
 {
 	switch (size) {
 	case 4:
arch/sparc/include/asm/cmpxchg_64.h +1 -2
index 66cd61dde9ec1..3de25262c4118 100644
@@ -87,7 +87,7 @@ xchg16(__volatile__ unsigned short *m, unsigned short val)
 	return (load32 & mask) >> bit_shift;
 }
 
-static inline unsigned long
+static __always_inline unsigned long
 __arch_xchg(unsigned long x, __volatile__ void * ptr, int size)
 {
 	switch (size) {
--

2.39.2

#3 lore raw
Quoted 22 lines · Palmer Dabbelt
Quoted 21 lines · Mark Rutland
Quoted 9 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

An otherwise correct change to the atomic operations uncovered an existing bug in the sparc __arch_xchg() function, which is calls __xchg_called_with_bad_pointer() when its arguments are unknown at compile time:

ERROR: modpost: "__xchg_called_with_bad_pointer" [lib/atomic64_test.ko] undefined!

Quoted 8 lines

This now happens because gcc determines that it's better to not inline the function. Avoid this by just marking the function as __always_inline to force the compiler to do the right thing here.

Fixes d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")

Aha; you saved me writing a patch! :)

Quoted 8 lines
Quoted 4 lines

We should probably do likewise for all the other bits like __cmpxchg(), but either way:

Though I'm not sure that means a whole lot over here ;)

I've carried some other sparc stuff before. I can send this to Linus with other fixes.

Signature · 1 line
Kees Cook
Applied
#8 lore raw
In reply to Arnd Bergmann
Quoted 8 lines · Arnd Bergmann

An otherwise correct change to the atomic operations uncovered an existing bug in the sparc __arch_xchg() function, which is calls __xchg_called_with_bad_pointer() when its arguments are unknown at compile time:

ERROR: modpost: "__xchg_called_with_bad_pointer" [lib/atomic64_test.ko] undefined!

[...]

Applied, thanks!

[1/1] sparc: mark __arch_xchg() as __always_inline

      https://git.kernel.org/kees/c/ec7633de404e

Best regards,

Signature · 1 line
Kees Cook