2023-06-28 10:20:51

by Arnd Bergmann

[permalink] [raw]
Subject: [PATCH] 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.

Reported-by: Guenter Roeck <[email protected]>
Link: https://lore.kernel.org/all/[email protected]/
Fixes: d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")
Signed-off-by: Arnd Bergmann <[email protected]>
---
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



2023-06-28 12:17:24

by Mark Rutland

[permalink] [raw]
Subject: Re: [PATCH] sparc: mark __arch_xchg() as __always_inline

On Wed, Jun 28, 2023 at 11:49:18AM +0200, Arnd Bergmann wrote:
> 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.
>
> Reported-by: Guenter Roeck <[email protected]>
> Link: https://lore.kernel.org/all/[email protected]/
> Fixes: d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")
> Signed-off-by: Arnd Bergmann <[email protected]>

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 <[email protected]>

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
>

2023-06-28 12:47:35

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH] sparc: mark __arch_xchg() as __always_inline

On 6/28/23 02:49, Arnd Bergmann wrote:
> 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.
>
> Reported-by: Guenter Roeck <[email protected]>
> Link: https://lore.kernel.org/all/[email protected]/
> Fixes: d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")
> Signed-off-by: Arnd Bergmann <[email protected]>

Nice catch.

Acked-by: Guenter Roeck <[email protected]>

> ---
> 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) {


2023-06-28 15:57:36

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [PATCH] sparc: mark __arch_xchg() as __always_inline

On Wed, Jun 28, 2023 at 11:49:18AM +0200, Arnd Bergmann wrote:
> 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.
>
> Reported-by: Guenter Roeck <[email protected]>
> Link: https://lore.kernel.org/all/[email protected]/
> Fixes: d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")
> Signed-off-by: Arnd Bergmann <[email protected]>
Reviewed-by: Sam Ravnborg <[email protected]>

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

Sam

2023-06-28 16:50:31

by Andi Shyti

[permalink] [raw]
Subject: Re: [PATCH] sparc: mark __arch_xchg() as __always_inline

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 <[email protected]>
> Link: https://lore.kernel.org/all/[email protected]/
> Fixes: d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")
> Signed-off-by: Arnd Bergmann <[email protected]>

Acked-by: Andi Shyti <[email protected]>

Thanks,
Andi

Subject: Re: [PATCH] sparc: mark __arch_xchg() as __always_inline

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 <[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.
>>
>> Reported-by: Guenter Roeck <[email protected]>
>> Link: https://lore.kernel.org/all/[email protected]/
>> Fixes: d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")
>> Signed-off-by: Arnd Bergmann <[email protected]>
> Reviewed-by: Sam Ravnborg <[email protected]>
>
> 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.

2023-07-13 14:13:07

by Palmer Dabbelt

[permalink] [raw]
Subject: Re: [PATCH] sparc: mark __arch_xchg() as __always_inline

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 <[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.
>>
>> Reported-by: Guenter Roeck <[email protected]>
>> Link: https://lore.kernel.org/all/[email protected]/
>> Fixes: d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")
>> Signed-off-by: Arnd Bergmann <[email protected]>
>
> 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 <[email protected]>

Acked-by: Palmer Dabbelt <[email protected]>

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
>>

2023-07-13 17:27:46

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH] sparc: mark __arch_xchg() as __always_inline

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 <[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.
> > >
> > > Reported-by: Guenter Roeck <[email protected]>
> > > Link: https://lore.kernel.org/all/[email protected]/
> > > Fixes: d12157efc8e08 ("locking/atomic: make atomic*_{cmp,}xchg optional")
> > > Signed-off-by: Arnd Bergmann <[email protected]>
> >
> > 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 <[email protected]>
>
> Acked-by: Palmer Dabbelt <[email protected]>
>
> 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

2023-07-13 18:40:15

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH] sparc: mark __arch_xchg() as __always_inline


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,
--
Kees Cook