sparc: mark __arch_xchg() as __always_inline

Message ID 20230628094938.2318171-1-arnd@kernel.org
State New
Headers
Series sparc: mark __arch_xchg() as __always_inline |

Commit Message

Arnd Bergmann June 28, 2023, 9:49 a.m. UTC
  From: Arnd Bergmann <arnd@arndb.de>

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.

Reported-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/all/c525adc9-6623-4660-8718-e0c9311563b8@roeck-us.net/
Fixes: d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/sparc/include/asm/cmpxchg_32.h | 2 +-
 arch/sparc/include/asm/cmpxchg_64.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
  

Comments

Mark Rutland June 28, 2023, 11:45 a.m. UTC | #1
On Wed, Jun 28, 2023 at 11:49:18AM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> 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.
> 
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> Link: https://lore.kernel.org/all/c525adc9-6623-4660-8718-e0c9311563b8@roeck-us.net/
> Fixes: d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Aha; you saved me writing a patch! :)

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

Acked-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> ---
>  arch/sparc/include/asm/cmpxchg_32.h | 2 +-
>  arch/sparc/include/asm/cmpxchg_64.h | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/sparc/include/asm/cmpxchg_32.h b/arch/sparc/include/asm/cmpxchg_32.h
> index 7a1339533d1d7..d0af82c240b73 100644
> --- a/arch/sparc/include/asm/cmpxchg_32.h
> +++ b/arch/sparc/include/asm/cmpxchg_32.h
> @@ -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:
> diff --git a/arch/sparc/include/asm/cmpxchg_64.h b/arch/sparc/include/asm/cmpxchg_64.h
> index 66cd61dde9ec1..3de25262c4118 100644
> --- a/arch/sparc/include/asm/cmpxchg_64.h
> +++ b/arch/sparc/include/asm/cmpxchg_64.h
> @@ -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
>
  
Guenter Roeck June 28, 2023, 12:35 p.m. UTC | #2
On 6/28/23 02:49, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> 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.
> 
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> Link: https://lore.kernel.org/all/c525adc9-6623-4660-8718-e0c9311563b8@roeck-us.net/
> Fixes: d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Nice catch.

Acked-by: Guenter Roeck <linux@roeck-us.net>

> ---
>   arch/sparc/include/asm/cmpxchg_32.h | 2 +-
>   arch/sparc/include/asm/cmpxchg_64.h | 2 +-
>   2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/sparc/include/asm/cmpxchg_32.h b/arch/sparc/include/asm/cmpxchg_32.h
> index 7a1339533d1d7..d0af82c240b73 100644
> --- a/arch/sparc/include/asm/cmpxchg_32.h
> +++ b/arch/sparc/include/asm/cmpxchg_32.h
> @@ -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:
> diff --git a/arch/sparc/include/asm/cmpxchg_64.h b/arch/sparc/include/asm/cmpxchg_64.h
> index 66cd61dde9ec1..3de25262c4118 100644
> --- a/arch/sparc/include/asm/cmpxchg_64.h
> +++ b/arch/sparc/include/asm/cmpxchg_64.h
> @@ -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) {
  
Sam Ravnborg June 28, 2023, 3:51 p.m. UTC | #3
On Wed, Jun 28, 2023 at 11:49:18AM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> 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.
> 
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> Link: https://lore.kernel.org/all/c525adc9-6623-4660-8718-e0c9311563b8@roeck-us.net/
> Fixes: d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>

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

	Sam
  
Andi Shyti June 28, 2023, 4:23 p.m. UTC | #4
Hi Arnd,

> 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.
> 
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> Link: https://lore.kernel.org/all/c525adc9-6623-4660-8718-e0c9311563b8@roeck-us.net/
> Fixes: d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Acked-by: Andi Shyti <andi.shyti@linux.intel.com> 

Thanks,
Andi
  
Linux regression tracking (Thorsten Leemhuis) July 13, 2023, 1:47 p.m. UTC | #5
On 28.06.23 17:51, Sam Ravnborg wrote:
> On Wed, Jun 28, 2023 at 11:49:18AM +0200, Arnd Bergmann wrote:
>> From: Arnd Bergmann <arnd@arndb.de>
>>
>> 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.
>>
>> Reported-by: Guenter Roeck <linux@roeck-us.net>
>> Link: https://lore.kernel.org/all/c525adc9-6623-4660-8718-e0c9311563b8@roeck-us.net/
>> Fixes: d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")
>> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
> 
> 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.
  
Palmer Dabbelt July 13, 2023, 2 p.m. UTC | #6
On Wed, 28 Jun 2023 04:45:43 PDT (-0700), Mark Rutland wrote:
> On Wed, Jun 28, 2023 at 11:49:18AM +0200, Arnd Bergmann wrote:
>> From: Arnd Bergmann <arnd@arndb.de>
>>
>> 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.
>>
>> Reported-by: Guenter Roeck <linux@roeck-us.net>
>> Link: https://lore.kernel.org/all/c525adc9-6623-4660-8718-e0c9311563b8@roeck-us.net/
>> Fixes: d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")
>> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>
> Aha; you saved me writing a patch! :)
>
> We should probably do likewise for all the other bits like __cmpxchg(), but
> either way:
>
> Acked-by: Mark Rutland <mark.rutland@arm.com>

Acked-by: Palmer Dabbelt <palmer@rivosinc.com>

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

> Mark.
>
>> ---
>>  arch/sparc/include/asm/cmpxchg_32.h | 2 +-
>>  arch/sparc/include/asm/cmpxchg_64.h | 2 +-
>>  2 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/sparc/include/asm/cmpxchg_32.h b/arch/sparc/include/asm/cmpxchg_32.h
>> index 7a1339533d1d7..d0af82c240b73 100644
>> --- a/arch/sparc/include/asm/cmpxchg_32.h
>> +++ b/arch/sparc/include/asm/cmpxchg_32.h
>> @@ -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:
>> diff --git a/arch/sparc/include/asm/cmpxchg_64.h b/arch/sparc/include/asm/cmpxchg_64.h
>> index 66cd61dde9ec1..3de25262c4118 100644
>> --- a/arch/sparc/include/asm/cmpxchg_64.h
>> +++ b/arch/sparc/include/asm/cmpxchg_64.h
>> @@ -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
>>
  
Kees Cook July 13, 2023, 4:55 p.m. UTC | #7
On Thu, Jul 13, 2023 at 07:00:37AM -0700, Palmer Dabbelt wrote:
> On Wed, 28 Jun 2023 04:45:43 PDT (-0700), Mark Rutland wrote:
> > On Wed, Jun 28, 2023 at 11:49:18AM +0200, Arnd Bergmann wrote:
> > > From: Arnd Bergmann <arnd@arndb.de>
> > > 
> > > 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.
> > > 
> > > Reported-by: Guenter Roeck <linux@roeck-us.net>
> > > Link: https://lore.kernel.org/all/c525adc9-6623-4660-8718-e0c9311563b8@roeck-us.net/
> > > Fixes: d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")
> > > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > 
> > Aha; you saved me writing a patch! :)
> > 
> > We should probably do likewise for all the other bits like __cmpxchg(), but
> > either way:
> > 
> > Acked-by: Mark Rutland <mark.rutland@arm.com>
> 
> Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
> 
> 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.
  
Kees Cook July 13, 2023, 5:55 p.m. UTC | #8
On Wed, 28 Jun 2023 11:49:18 +0200, Arnd Bergmann wrote:
> 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,
  

Patch

diff --git a/arch/sparc/include/asm/cmpxchg_32.h b/arch/sparc/include/asm/cmpxchg_32.h
index 7a1339533d1d7..d0af82c240b73 100644
--- a/arch/sparc/include/asm/cmpxchg_32.h
+++ b/arch/sparc/include/asm/cmpxchg_32.h
@@ -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:
diff --git a/arch/sparc/include/asm/cmpxchg_64.h b/arch/sparc/include/asm/cmpxchg_64.h
index 66cd61dde9ec1..3de25262c4118 100644
--- a/arch/sparc/include/asm/cmpxchg_64.h
+++ b/arch/sparc/include/asm/cmpxchg_64.h
@@ -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) {