Linux SNPS ARC Archive on lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH 0/6] Add two-byte cmpxchg emulation and wire it into the architectures
       [not found] <20260911192540.20983-1-brads@mainlining.org>
@ 2026-09-11 20:17 ` Arnd Bergmann
       [not found] ` <20260911192540.20983-6-brads@mainlining.org>
       [not found] ` <20260911192540.20983-2-brads@mainlining.org>
  2 siblings, 0 replies; 10+ messages in thread
From: Arnd Bergmann @ 2026-09-11 20:17 UTC (permalink / raw)
  To: Bradley Morgan, Paul E. McKenney
  Cc: Frederic Weisbecker, neeraj.upadhyay, Boqun Feng, Joel Fernandes,
	rcu, Andrew Morton, Linux-Arch, Vineet Gupta, linux-snps-arc,
	Russell King, linux-arm-kernel, guoren,
	linux-csky@vger.kernel.org, Yoshinori Sato, Rich Felker,
	John Paul Adrian Glaubitz, linux-sh, Chris Zankel, Max Filippov,
	linux-kernel

On Fri, Sep 11, 2026, at 21:25, Bradley Morgan wrote:
> Per Paul's note, Arnd Bergmann's platform removal series was
> checked before analyzing the users. It removes the imx31 and
> omap24xx CPU_ARM1136R0 selectors, but INTEGRATOR_CM1136JFS still
> selects CPU_ARM1136R0 until its scheduled removal in early 2027,
> so the ARMv6 path in patch 3 is still live.

I can still restructure this and pull the INTEGRATOR_CM1136JFS
removal a little earlier. At the moment, this is part of the
patch to remove CPU_ARM1136R0, which I had planned to submit
once the arch/arm/mach-*/ platform removal patches are done:

https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git/commit/?id=a8cfcc5533e33a

I could turn the mach-versatile/Kconfig change into a separate
(trivial) patch and add it to the platform series to avoid
churn here. The armv6 cmpxchg() code would still exist
in 7.4 then, but be unreachable.

       Arnd

_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

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

* Re: [PATCH 1/6] lib: Add two-byte cmpxchg emulation function
       [not found] ` <20260911192540.20983-2-brads@mainlining.org>
@ 2026-09-11 22:10   ` David Laight
  2026-09-11 23:09     ` Paul E. McKenney
  2026-09-23 10:43   ` David Laight
  1 sibling, 1 reply; 10+ messages in thread
From: David Laight @ 2026-09-11 22:10 UTC (permalink / raw)
  To: Bradley Morgan
  Cc: Paul E. McKenney, frederic, neeraj.upadhyay, boqun, joelagnelf,
	rcu, Andrew Morton, Arnd Bergmann, linux-arch, Vineet Gupta,
	linux-snps-arc, Russell King, linux-arm-kernel, Guo Ren,
	linux-csky, Yoshinori Sato, Rich Felker,
	John Paul Adrian Glaubitz, linux-sh, Chris Zankel, Max Filippov,
	linux-kernel

On Fri, 11 Sep 2026 19:25:34 +0000
Bradley Morgan <brads@mainlining.org> wrote:

> cmpxchg_emu_u8() emulates one-byte cmpxchg() in terms of four-byte
> cmpxchg() for the architectures lacking native one-byte atomics.
> The same architectures also lack native two-byte cmpxchg(), where
> such an operation is not supported and either fails to compile via
> BUILD_BUG() or fails to link, because the bad pointer sentinels
> these architectures declare are never defined.
> 
> Add cmpxchg_emu_u16(), the two-byte sibling. It reads the enclosing
> word with READ_ONCE(), splices the two target bytes through a union
> and loops on cmpxchg() of the full word until the compare succeeds.
> Like cmpxchg_emu_u8() it is fully ordered.
> 
> The Kconfig symbol gating this file is renamed from
> ARCH_NEED_CMPXCHG_1_EMU to ARCH_NEED_CMPXCHG_1_2_EMU, as it now
> selects both the one-byte and the two-byte emulation.
> 
> Suggested-by: Paul E. McKenney <paulmck@kernel.org>
> Signed-off-by: Bradley Morgan <brads@mainlining.org>
> ---
>  arch/Kconfig                |  2 +-
>  arch/arc/Kconfig            |  2 +-
>  arch/arm/Kconfig            |  2 +-
>  arch/csky/Kconfig           |  2 +-
>  arch/sh/Kconfig             |  2 +-
>  arch/xtensa/Kconfig         |  2 +-
>  include/linux/cmpxchg-emu.h |  1 +
>  lib/Makefile                |  2 +-
>  lib/cmpxchg-emu.c           | 35 ++++++++++++++++++++++++++++++++---
>  9 files changed, 40 insertions(+), 10 deletions(-)
> 
...
> diff --git a/include/linux/cmpxchg-emu.h b/include/linux/cmpxchg-emu.h
> index 998deec67740..fee8171fa05e 100644
> --- a/include/linux/cmpxchg-emu.h
> +++ b/include/linux/cmpxchg-emu.h
> @@ -11,5 +11,6 @@
>  #define __LINUX_CMPXCHG_EMU_H
>  
>  uintptr_t cmpxchg_emu_u8(volatile u8 *p, uintptr_t old, uintptr_t new);
> +uintptr_t cmpxchg_emu_u16(volatile u16 *p, uintptr_t old, uintptr_t new);

Why uintptr_t? Shouldn't it just be u16?
(Which probably means the code would better if it was just 'unsigned int')

David


_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

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

* Re: [PATCH 1/6] lib: Add two-byte cmpxchg emulation function
  2026-09-11 22:10   ` [PATCH 1/6] lib: Add two-byte cmpxchg emulation function David Laight
@ 2026-09-11 23:09     ` Paul E. McKenney
  2026-09-12  9:30       ` David Laight
  0 siblings, 1 reply; 10+ messages in thread
From: Paul E. McKenney @ 2026-09-11 23:09 UTC (permalink / raw)
  To: David Laight
  Cc: Bradley Morgan, frederic, neeraj.upadhyay, boqun, joelagnelf, rcu,
	Andrew Morton, Arnd Bergmann, linux-arch, Vineet Gupta,
	linux-snps-arc, Russell King, linux-arm-kernel, Guo Ren,
	linux-csky, Yoshinori Sato, Rich Felker,
	John Paul Adrian Glaubitz, linux-sh, Chris Zankel, Max Filippov,
	linux-kernel

On Fri, Sep 11, 2026 at 11:10:17PM +0100, David Laight wrote:
> On Fri, 11 Sep 2026 19:25:34 +0000
> Bradley Morgan <brads@mainlining.org> wrote:
> 
> > cmpxchg_emu_u8() emulates one-byte cmpxchg() in terms of four-byte
> > cmpxchg() for the architectures lacking native one-byte atomics.
> > The same architectures also lack native two-byte cmpxchg(), where
> > such an operation is not supported and either fails to compile via
> > BUILD_BUG() or fails to link, because the bad pointer sentinels
> > these architectures declare are never defined.
> > 
> > Add cmpxchg_emu_u16(), the two-byte sibling. It reads the enclosing
> > word with READ_ONCE(), splices the two target bytes through a union
> > and loops on cmpxchg() of the full word until the compare succeeds.
> > Like cmpxchg_emu_u8() it is fully ordered.
> > 
> > The Kconfig symbol gating this file is renamed from
> > ARCH_NEED_CMPXCHG_1_EMU to ARCH_NEED_CMPXCHG_1_2_EMU, as it now
> > selects both the one-byte and the two-byte emulation.
> > 
> > Suggested-by: Paul E. McKenney <paulmck@kernel.org>
> > Signed-off-by: Bradley Morgan <brads@mainlining.org>
> > ---
> >  arch/Kconfig                |  2 +-
> >  arch/arc/Kconfig            |  2 +-
> >  arch/arm/Kconfig            |  2 +-
> >  arch/csky/Kconfig           |  2 +-
> >  arch/sh/Kconfig             |  2 +-
> >  arch/xtensa/Kconfig         |  2 +-
> >  include/linux/cmpxchg-emu.h |  1 +
> >  lib/Makefile                |  2 +-
> >  lib/cmpxchg-emu.c           | 35 ++++++++++++++++++++++++++++++++---
> >  9 files changed, 40 insertions(+), 10 deletions(-)
> > 
> ...
> > diff --git a/include/linux/cmpxchg-emu.h b/include/linux/cmpxchg-emu.h
> > index 998deec67740..fee8171fa05e 100644
> > --- a/include/linux/cmpxchg-emu.h
> > +++ b/include/linux/cmpxchg-emu.h
> > @@ -11,5 +11,6 @@
> >  #define __LINUX_CMPXCHG_EMU_H
> >  
> >  uintptr_t cmpxchg_emu_u8(volatile u8 *p, uintptr_t old, uintptr_t new);
> > +uintptr_t cmpxchg_emu_u16(volatile u16 *p, uintptr_t old, uintptr_t new);
> 
> Why uintptr_t? Shouldn't it just be u16?
> (Which probably means the code would better if it was just 'unsigned int')

I suspect that Bradley is just following my cmpxchg_emu_u8() example,
which also returns uintptr_t.

I remember that *something* broke when I made this be u8, but I cannot
recall what the problem was.

Bradley, could you please try making it be u16 as David suggests just to
see what happens?  Who knows?  Maybe it was a compiler issue that has
since been fixed.  Or maybe the macros and asms using cmpxchg_emu_u8()
need that uintptr_t for some reason.

							Thanx, Paul

_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

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

* Re: [PATCH 1/6] lib: Add two-byte cmpxchg emulation function
  2026-09-11 23:09     ` Paul E. McKenney
@ 2026-09-12  9:30       ` David Laight
  2026-09-12 18:58         ` Paul E. McKenney
  0 siblings, 1 reply; 10+ messages in thread
From: David Laight @ 2026-09-12  9:30 UTC (permalink / raw)
  To: Paul E. McKenney
  Cc: Bradley Morgan, frederic, neeraj.upadhyay, boqun, joelagnelf, rcu,
	Andrew Morton, Arnd Bergmann, linux-arch, Vineet Gupta,
	linux-snps-arc, Russell King, linux-arm-kernel, Guo Ren,
	linux-csky, Yoshinori Sato, Rich Felker,
	John Paul Adrian Glaubitz, linux-sh, Chris Zankel, Max Filippov,
	linux-kernel

On Fri, 11 Sep 2026 16:09:16 -0700
"Paul E. McKenney" <paulmck@kernel.org> wrote:

> On Fri, Sep 11, 2026 at 11:10:17PM +0100, David Laight wrote:
> > On Fri, 11 Sep 2026 19:25:34 +0000
> > Bradley Morgan <brads@mainlining.org> wrote:
> >   
> > > cmpxchg_emu_u8() emulates one-byte cmpxchg() in terms of four-byte
> > > cmpxchg() for the architectures lacking native one-byte atomics.
> > > The same architectures also lack native two-byte cmpxchg(), where
> > > such an operation is not supported and either fails to compile via
> > > BUILD_BUG() or fails to link, because the bad pointer sentinels
> > > these architectures declare are never defined.
> > > 
> > > Add cmpxchg_emu_u16(), the two-byte sibling. It reads the enclosing
> > > word with READ_ONCE(), splices the two target bytes through a union
> > > and loops on cmpxchg() of the full word until the compare succeeds.
> > > Like cmpxchg_emu_u8() it is fully ordered.
> > > 
> > > The Kconfig symbol gating this file is renamed from
> > > ARCH_NEED_CMPXCHG_1_EMU to ARCH_NEED_CMPXCHG_1_2_EMU, as it now
> > > selects both the one-byte and the two-byte emulation.
> > > 
> > > Suggested-by: Paul E. McKenney <paulmck@kernel.org>
> > > Signed-off-by: Bradley Morgan <brads@mainlining.org>
> > > ---
> > >  arch/Kconfig                |  2 +-
> > >  arch/arc/Kconfig            |  2 +-
> > >  arch/arm/Kconfig            |  2 +-
> > >  arch/csky/Kconfig           |  2 +-
> > >  arch/sh/Kconfig             |  2 +-
> > >  arch/xtensa/Kconfig         |  2 +-
> > >  include/linux/cmpxchg-emu.h |  1 +
> > >  lib/Makefile                |  2 +-
> > >  lib/cmpxchg-emu.c           | 35 ++++++++++++++++++++++++++++++++---
> > >  9 files changed, 40 insertions(+), 10 deletions(-)
> > >   
> > ...  
> > > diff --git a/include/linux/cmpxchg-emu.h b/include/linux/cmpxchg-emu.h
> > > index 998deec67740..fee8171fa05e 100644
> > > --- a/include/linux/cmpxchg-emu.h
> > > +++ b/include/linux/cmpxchg-emu.h
> > > @@ -11,5 +11,6 @@
> > >  #define __LINUX_CMPXCHG_EMU_H
> > >  
> > >  uintptr_t cmpxchg_emu_u8(volatile u8 *p, uintptr_t old, uintptr_t new);
> > > +uintptr_t cmpxchg_emu_u16(volatile u16 *p, uintptr_t old, uintptr_t new);  
> > 
> > Why uintptr_t? Shouldn't it just be u16?
> > (Which probably means the code would better if it was just 'unsigned int')  
> 
> I suspect that Bradley is just following my cmpxchg_emu_u8() example,
> which also returns uintptr_t.
> 
> I remember that *something* broke when I made this be u8, but I cannot
> recall what the problem was.
> 
> Bradley, could you please try making it be u16 as David suggests just to
> see what happens?  Who knows?  Maybe it was a compiler issue that has
> since been fixed.  Or maybe the macros and asms using cmpxchg_emu_u8()
> need that uintptr_t for some reason.

I think the uintptr (unsigned long) cast is needed to stop a compile
error when exchanging pointers.
But that is an issue with the #define not the called functions.

Possibly changing the #define to have:
	unsigned long ul_old = (unsigned long)(old);
Or even, with the type check from:
	unsigned long ul_old = (unsigned long)(0 ? *(ptr) : (old));
(with the same for 'new')
and the removing all the casts where the value are used might be better.

David

> 
> 							Thanx, Paul


_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

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

* Re: [PATCH 1/6] lib: Add two-byte cmpxchg emulation function
  2026-09-12  9:30       ` David Laight
@ 2026-09-12 18:58         ` Paul E. McKenney
  0 siblings, 0 replies; 10+ messages in thread
From: Paul E. McKenney @ 2026-09-12 18:58 UTC (permalink / raw)
  To: David Laight
  Cc: Bradley Morgan, frederic, neeraj.upadhyay, boqun, joelagnelf, rcu,
	Andrew Morton, Arnd Bergmann, linux-arch, Vineet Gupta,
	linux-snps-arc, Russell King, linux-arm-kernel, Guo Ren,
	linux-csky, Yoshinori Sato, Rich Felker,
	John Paul Adrian Glaubitz, linux-sh, Chris Zankel, Max Filippov,
	linux-kernel

On Sat, Sep 12, 2026 at 10:30:47AM +0100, David Laight wrote:
> On Fri, 11 Sep 2026 16:09:16 -0700
> "Paul E. McKenney" <paulmck@kernel.org> wrote:
> 
> > On Fri, Sep 11, 2026 at 11:10:17PM +0100, David Laight wrote:
> > > On Fri, 11 Sep 2026 19:25:34 +0000
> > > Bradley Morgan <brads@mainlining.org> wrote:
> > >   
> > > > cmpxchg_emu_u8() emulates one-byte cmpxchg() in terms of four-byte
> > > > cmpxchg() for the architectures lacking native one-byte atomics.
> > > > The same architectures also lack native two-byte cmpxchg(), where
> > > > such an operation is not supported and either fails to compile via
> > > > BUILD_BUG() or fails to link, because the bad pointer sentinels
> > > > these architectures declare are never defined.
> > > > 
> > > > Add cmpxchg_emu_u16(), the two-byte sibling. It reads the enclosing
> > > > word with READ_ONCE(), splices the two target bytes through a union
> > > > and loops on cmpxchg() of the full word until the compare succeeds.
> > > > Like cmpxchg_emu_u8() it is fully ordered.
> > > > 
> > > > The Kconfig symbol gating this file is renamed from
> > > > ARCH_NEED_CMPXCHG_1_EMU to ARCH_NEED_CMPXCHG_1_2_EMU, as it now
> > > > selects both the one-byte and the two-byte emulation.
> > > > 
> > > > Suggested-by: Paul E. McKenney <paulmck@kernel.org>
> > > > Signed-off-by: Bradley Morgan <brads@mainlining.org>
> > > > ---
> > > >  arch/Kconfig                |  2 +-
> > > >  arch/arc/Kconfig            |  2 +-
> > > >  arch/arm/Kconfig            |  2 +-
> > > >  arch/csky/Kconfig           |  2 +-
> > > >  arch/sh/Kconfig             |  2 +-
> > > >  arch/xtensa/Kconfig         |  2 +-
> > > >  include/linux/cmpxchg-emu.h |  1 +
> > > >  lib/Makefile                |  2 +-
> > > >  lib/cmpxchg-emu.c           | 35 ++++++++++++++++++++++++++++++++---
> > > >  9 files changed, 40 insertions(+), 10 deletions(-)
> > > >   
> > > ...  
> > > > diff --git a/include/linux/cmpxchg-emu.h b/include/linux/cmpxchg-emu.h
> > > > index 998deec67740..fee8171fa05e 100644
> > > > --- a/include/linux/cmpxchg-emu.h
> > > > +++ b/include/linux/cmpxchg-emu.h
> > > > @@ -11,5 +11,6 @@
> > > >  #define __LINUX_CMPXCHG_EMU_H
> > > >  
> > > >  uintptr_t cmpxchg_emu_u8(volatile u8 *p, uintptr_t old, uintptr_t new);
> > > > +uintptr_t cmpxchg_emu_u16(volatile u16 *p, uintptr_t old, uintptr_t new);  
> > > 
> > > Why uintptr_t? Shouldn't it just be u16?
> > > (Which probably means the code would better if it was just 'unsigned int')  
> > 
> > I suspect that Bradley is just following my cmpxchg_emu_u8() example,
> > which also returns uintptr_t.
> > 
> > I remember that *something* broke when I made this be u8, but I cannot
> > recall what the problem was.
> > 
> > Bradley, could you please try making it be u16 as David suggests just to
> > see what happens?  Who knows?  Maybe it was a compiler issue that has
> > since been fixed.  Or maybe the macros and asms using cmpxchg_emu_u8()
> > need that uintptr_t for some reason.
> 
> I think the uintptr (unsigned long) cast is needed to stop a compile
> error when exchanging pointers.
> But that is an issue with the #define not the called functions.
> 
> Possibly changing the #define to have:
> 	unsigned long ul_old = (unsigned long)(old);
> Or even, with the type check from:
> 	unsigned long ul_old = (unsigned long)(0 ? *(ptr) : (old));
> (with the same for 'new')
> and the removing all the casts where the value are used might be better.

It does sound worth a try, especially since we have the uintptr_t version
to fall back on should that fail, or in case it somehow makes things
more complicated.

But we have been living with uintptr_t for some years with the 8-bit
code, so this should be able to be a follow-on patch.

							Thanx, Paul

_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

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

* Re: [PATCH 5/6] sh: Emulate two-byte cmpxchg
       [not found] ` <20260911192540.20983-6-brads@mainlining.org>
@ 2026-09-16 19:16   ` John Paul Adrian Glaubitz
  2026-09-16 21:01     ` Paul E. McKenney
  2026-09-22 23:06     ` Paul E. McKenney
  0 siblings, 2 replies; 10+ messages in thread
From: John Paul Adrian Glaubitz @ 2026-09-16 19:16 UTC (permalink / raw)
  To: Bradley Morgan, Paul E. McKenney
  Cc: frederic, neeraj.upadhyay, boqun, joelagnelf, rcu, Andrew Morton,
	Arnd Bergmann, linux-arch, Vineet Gupta, linux-snps-arc,
	Russell King, linux-arm-kernel, Guo Ren, linux-csky,
	Yoshinori Sato, Rich Felker, linux-sh, Chris Zankel, Max Filippov,
	linux-kernel

Hi Bradley,

On Fri, 2026-09-11 at 19:25 +0000, Bradley Morgan wrote:
> SH has no byte or halfword atomic memory operations, so the
> __cmpxchg() switch routes case 1 through cmpxchg_emu_u8() and
> lets case 2 fall through to __cmpxchg_called_with_bad_pointer(),
> which is declared but never defined, so a two-byte cmpxchg()
> fails at link time. Route case 2 through the new cmpxchg_emu_u16().
> 
> Signed-off-by: Bradley Morgan <brads@mainlining.org>
> ---
>  arch/sh/include/asm/cmpxchg.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/sh/include/asm/cmpxchg.h b/arch/sh/include/asm/cmpxchg.h
> index 1e5dc5ccf7bf..477d3025a441 100644
> --- a/arch/sh/include/asm/cmpxchg.h
> +++ b/arch/sh/include/asm/cmpxchg.h
> @@ -59,6 +59,8 @@ static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
>  	switch (size) {
>  	case 1:
>  		return cmpxchg_emu_u8(ptr, old, new);
> +	case 2:
> +		return cmpxchg_emu_u16(ptr, old, new);
>  	case 4:
>  		return __cmpxchg_u32(ptr, old, new);
>  	}

Odd, I thought this series was merged long time ago. Was there anything holding it back?

Either way:

Acked-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>

Adrian

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

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

* Re: [PATCH 5/6] sh: Emulate two-byte cmpxchg
  2026-09-16 19:16   ` [PATCH 5/6] sh: Emulate two-byte cmpxchg John Paul Adrian Glaubitz
@ 2026-09-16 21:01     ` Paul E. McKenney
  2026-09-22 23:06     ` Paul E. McKenney
  1 sibling, 0 replies; 10+ messages in thread
From: Paul E. McKenney @ 2026-09-16 21:01 UTC (permalink / raw)
  To: John Paul Adrian Glaubitz
  Cc: Bradley Morgan, frederic, neeraj.upadhyay, boqun, joelagnelf, rcu,
	Andrew Morton, Arnd Bergmann, linux-arch, Vineet Gupta,
	linux-snps-arc, Russell King, linux-arm-kernel, Guo Ren,
	linux-csky, Yoshinori Sato, Rich Felker, linux-sh, Chris Zankel,
	Max Filippov, linux-kernel

On Wed, Sep 16, 2026 at 09:16:16PM +0200, John Paul Adrian Glaubitz wrote:
> Hi Bradley,
> 
> On Fri, 2026-09-11 at 19:25 +0000, Bradley Morgan wrote:
> > SH has no byte or halfword atomic memory operations, so the
> > __cmpxchg() switch routes case 1 through cmpxchg_emu_u8() and
> > lets case 2 fall through to __cmpxchg_called_with_bad_pointer(),
> > which is declared but never defined, so a two-byte cmpxchg()
> > fails at link time. Route case 2 through the new cmpxchg_emu_u16().
> > 
> > Signed-off-by: Bradley Morgan <brads@mainlining.org>
> > ---
> >  arch/sh/include/asm/cmpxchg.h | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/arch/sh/include/asm/cmpxchg.h b/arch/sh/include/asm/cmpxchg.h
> > index 1e5dc5ccf7bf..477d3025a441 100644
> > --- a/arch/sh/include/asm/cmpxchg.h
> > +++ b/arch/sh/include/asm/cmpxchg.h
> > @@ -59,6 +59,8 @@ static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
> >  	switch (size) {
> >  	case 1:
> >  		return cmpxchg_emu_u8(ptr, old, new);
> > +	case 2:
> > +		return cmpxchg_emu_u16(ptr, old, new);
> >  	case 4:
> >  		return __cmpxchg_u32(ptr, old, new);
> >  	}
> 
> Odd, I thought this series was merged long time ago. Was there anything holding it back?

You might be thinking of the cmpxchg_emu_u8() series from a few years back.
This is cmpxchg_emu_u16().

							Thanx, Paul

> Either way:
> 
> Acked-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
> 
> Adrian
> 
> -- 
>  .''`.  John Paul Adrian Glaubitz
> : :' :  Debian Developer
> `. `'   Physicist
>   `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

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

* Re: [PATCH 5/6] sh: Emulate two-byte cmpxchg
  2026-09-16 19:16   ` [PATCH 5/6] sh: Emulate two-byte cmpxchg John Paul Adrian Glaubitz
  2026-09-16 21:01     ` Paul E. McKenney
@ 2026-09-22 23:06     ` Paul E. McKenney
  1 sibling, 0 replies; 10+ messages in thread
From: Paul E. McKenney @ 2026-09-22 23:06 UTC (permalink / raw)
  To: John Paul Adrian Glaubitz
  Cc: Bradley Morgan, frederic, neeraj.upadhyay, boqun, joelagnelf, rcu,
	Andrew Morton, Arnd Bergmann, linux-arch, Vineet Gupta,
	linux-snps-arc, Russell King, linux-arm-kernel, Guo Ren,
	linux-csky, Yoshinori Sato, Rich Felker, linux-sh, Chris Zankel,
	Max Filippov, linux-kernel

On Wed, Sep 16, 2026 at 09:16:16PM +0200, John Paul Adrian Glaubitz wrote:
> Hi Bradley,
> 
> On Fri, 2026-09-11 at 19:25 +0000, Bradley Morgan wrote:
> > SH has no byte or halfword atomic memory operations, so the
> > __cmpxchg() switch routes case 1 through cmpxchg_emu_u8() and
> > lets case 2 fall through to __cmpxchg_called_with_bad_pointer(),
> > which is declared but never defined, so a two-byte cmpxchg()
> > fails at link time. Route case 2 through the new cmpxchg_emu_u16().
> > 
> > Signed-off-by: Bradley Morgan <brads@mainlining.org>
> > ---
> >  arch/sh/include/asm/cmpxchg.h | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/arch/sh/include/asm/cmpxchg.h b/arch/sh/include/asm/cmpxchg.h
> > index 1e5dc5ccf7bf..477d3025a441 100644
> > --- a/arch/sh/include/asm/cmpxchg.h
> > +++ b/arch/sh/include/asm/cmpxchg.h
> > @@ -59,6 +59,8 @@ static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
> >  	switch (size) {
> >  	case 1:
> >  		return cmpxchg_emu_u8(ptr, old, new);
> > +	case 2:
> > +		return cmpxchg_emu_u16(ptr, old, new);
> >  	case 4:
> >  		return __cmpxchg_u32(ptr, old, new);
> >  	}
> 
> Odd, I thought this series was merged long time ago. Was there anything holding it back?
> 
> Either way:
> 
> Acked-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>

Thank you, John!

In my reshuffling, I associated the arch/sh/Kconfig change with the
cmpxchg.h changes, as shown below.  The idea is to show all the changes
for a given architecture in one place.  I kept your Acked-by, but please
let me know if this is in any way problematic.

						Thanx, Paul

------------------------------------------------------------------------

commit 662151462e30187c342cffcd250834a32a9eb67a
Author: Bradley Morgan <brads@mainlining.org>
Date:   Tue Sep 22 17:33:52 2026 +0000

    sh: Emulate two-byte cmpxchg
    
    SH has no byte or halfword atomic memory operations, so the __cmpxchg()
    switch routes case 1 through cmpxchg_emu_u8() and lets case 2 fall
    through to __cmpxchg_called_with_bad_pointer(), which is declared but
    never defined, so a two-byte cmpxchg() fails at link time. Route case
    2 through the new cmpxchg_emu_u16(), which takes the old and new
    values as unsigned long, so the (unsigned long) casts move off the
    call and into _old_ and _new_ declarations that type check the old
    and new arguments against *ptr through (unsigned long)(0 ? *ptr : _o_),
    the idiom David Laight suggested, so cmpxchg(&p, 4, 5) no longer
    compiles silently.
    
    Acked-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
    Signed-off-by: Bradley Morgan <brads@mainlining.org>
    Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
    Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
    Cc: Rich Felker <dalias@libc.org>
    Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
    Cc: <linux-sh@vger.kernel.org>

diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index d60f1d5a94c0..09e556fced01 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -14,7 +14,7 @@ config SUPERH
 	select ARCH_HIBERNATION_POSSIBLE if MMU
 	select ARCH_MIGHT_HAVE_PC_PARPORT
 	select ARCH_WANT_IPC_PARSE_VERSION
-	select ARCH_NEED_CMPXCHG_1_EMU
+	select ARCH_NEED_CMPXCHG_1_2_EMU
 	select CPU_NO_EFFICIENT_FFS
 	select DMA_DECLARE_COHERENT
 	select GENERIC_ATOMIC64
diff --git a/arch/sh/include/asm/cmpxchg.h b/arch/sh/include/asm/cmpxchg.h
index 1e5dc5ccf7bf..b87f59107b4e 100644
--- a/arch/sh/include/asm/cmpxchg.h
+++ b/arch/sh/include/asm/cmpxchg.h
@@ -59,6 +59,8 @@ static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
 	switch (size) {
 	case 1:
 		return cmpxchg_emu_u8(ptr, old, new);
+	case 2:
+		return cmpxchg_emu_u16(ptr, old, new);
 	case 4:
 		return __cmpxchg_u32(ptr, old, new);
 	}
@@ -70,8 +72,10 @@ static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
   ({									 \
      __typeof__(*(ptr)) _o_ = (o);					 \
      __typeof__(*(ptr)) _n_ = (n);					 \
-     (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,		 \
-				    (unsigned long)_n_, sizeof(*(ptr))); \
+     unsigned long _old_ = (unsigned long)(0 ? *ptr : _o_);	 \
+     unsigned long _new_ = (unsigned long)(0 ? *ptr : _n_);	 \
+     (__typeof__(*(ptr))) __cmpxchg((ptr), _old_,				 \
+				    _new_, sizeof(*(ptr)));	 \
   })
 
 #include <asm-generic/cmpxchg-local.h>

_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

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

* Re: [PATCH 1/6] lib: Add two-byte cmpxchg emulation function
       [not found] ` <20260911192540.20983-2-brads@mainlining.org>
  2026-09-11 22:10   ` [PATCH 1/6] lib: Add two-byte cmpxchg emulation function David Laight
@ 2026-09-23 10:43   ` David Laight
  2026-09-23 17:00     ` Paul E. McKenney
  1 sibling, 1 reply; 10+ messages in thread
From: David Laight @ 2026-09-23 10:43 UTC (permalink / raw)
  To: Bradley Morgan
  Cc: Paul E. McKenney, frederic, neeraj.upadhyay, boqun, joelagnelf,
	rcu, Andrew Morton, Arnd Bergmann, linux-arch, Vineet Gupta,
	linux-snps-arc, Russell King, linux-arm-kernel, Guo Ren,
	linux-csky, Yoshinori Sato, Rich Felker,
	John Paul Adrian Glaubitz, linux-sh, Chris Zankel, Max Filippov,
	linux-kernel

On Fri, 11 Sep 2026 19:25:34 +0000
Bradley Morgan <brads@mainlining.org> wrote:

> cmpxchg_emu_u8() emulates one-byte cmpxchg() in terms of four-byte
> cmpxchg() for the architectures lacking native one-byte atomics.
> The same architectures also lack native two-byte cmpxchg(), where
> such an operation is not supported and either fails to compile via
> BUILD_BUG() or fails to link, because the bad pointer sentinels
> these architectures declare are never defined.
> 
> Add cmpxchg_emu_u16(), the two-byte sibling. It reads the enclosing
> word with READ_ONCE(), splices the two target bytes through a union
> and loops on cmpxchg() of the full word until the compare succeeds.
> Like cmpxchg_emu_u8() it is fully ordered.
> 
> The Kconfig symbol gating this file is renamed from
> ARCH_NEED_CMPXCHG_1_EMU to ARCH_NEED_CMPXCHG_1_2_EMU, as it now
> selects both the one-byte and the two-byte emulation.
> 
> Suggested-by: Paul E. McKenney <paulmck@kernel.org>
> Signed-off-by: Bradley Morgan <brads@mainlining.org>
> ---
>  arch/Kconfig                |  2 +-
>  arch/arc/Kconfig            |  2 +-
>  arch/arm/Kconfig            |  2 +-
>  arch/csky/Kconfig           |  2 +-
>  arch/sh/Kconfig             |  2 +-
>  arch/xtensa/Kconfig         |  2 +-
>  include/linux/cmpxchg-emu.h |  1 +
>  lib/Makefile                |  2 +-
>  lib/cmpxchg-emu.c           | 35 ++++++++++++++++++++++++++++++++---
>  9 files changed, 40 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/Kconfig b/arch/Kconfig
> index 3bb2e568f5b1..d56064797e09 100644
> --- a/arch/Kconfig
> +++ b/arch/Kconfig
> @@ -1817,7 +1817,7 @@ config CC_HAS_SANE_FUNCTION_ALIGNMENT
>  	# strict alignment always, even with -falign-functions.
>  	def_bool CC_HAS_MIN_FUNCTION_ALIGNMENT || CC_IS_CLANG
>  
> -config ARCH_NEED_CMPXCHG_1_EMU
> +config ARCH_NEED_CMPXCHG_1_2_EMU

Is it actually worth the churn of changing the name?
Maybe just a comment that say it adds both 1 and 2 byte emulation?

David

>  	bool
>  
...

_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

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

* Re: [PATCH 1/6] lib: Add two-byte cmpxchg emulation function
  2026-09-23 10:43   ` David Laight
@ 2026-09-23 17:00     ` Paul E. McKenney
  0 siblings, 0 replies; 10+ messages in thread
From: Paul E. McKenney @ 2026-09-23 17:00 UTC (permalink / raw)
  To: David Laight
  Cc: Bradley Morgan, frederic, neeraj.upadhyay, boqun, joelagnelf, rcu,
	Andrew Morton, Arnd Bergmann, linux-arch, Vineet Gupta,
	linux-snps-arc, Russell King, linux-arm-kernel, Guo Ren,
	linux-csky, Yoshinori Sato, Rich Felker,
	John Paul Adrian Glaubitz, linux-sh, Chris Zankel, Max Filippov,
	linux-kernel

On Wed, Sep 23, 2026 at 11:43:13AM +0100, David Laight wrote:
> On Fri, 11 Sep 2026 19:25:34 +0000
> Bradley Morgan <brads@mainlining.org> wrote:
> 
> > cmpxchg_emu_u8() emulates one-byte cmpxchg() in terms of four-byte
> > cmpxchg() for the architectures lacking native one-byte atomics.
> > The same architectures also lack native two-byte cmpxchg(), where
> > such an operation is not supported and either fails to compile via
> > BUILD_BUG() or fails to link, because the bad pointer sentinels
> > these architectures declare are never defined.
> > 
> > Add cmpxchg_emu_u16(), the two-byte sibling. It reads the enclosing
> > word with READ_ONCE(), splices the two target bytes through a union
> > and loops on cmpxchg() of the full word until the compare succeeds.
> > Like cmpxchg_emu_u8() it is fully ordered.
> > 
> > The Kconfig symbol gating this file is renamed from
> > ARCH_NEED_CMPXCHG_1_EMU to ARCH_NEED_CMPXCHG_1_2_EMU, as it now
> > selects both the one-byte and the two-byte emulation.
> > 
> > Suggested-by: Paul E. McKenney <paulmck@kernel.org>
> > Signed-off-by: Bradley Morgan <brads@mainlining.org>
> > ---
> >  arch/Kconfig                |  2 +-
> >  arch/arc/Kconfig            |  2 +-
> >  arch/arm/Kconfig            |  2 +-
> >  arch/csky/Kconfig           |  2 +-
> >  arch/sh/Kconfig             |  2 +-
> >  arch/xtensa/Kconfig         |  2 +-
> >  include/linux/cmpxchg-emu.h |  1 +
> >  lib/Makefile                |  2 +-
> >  lib/cmpxchg-emu.c           | 35 ++++++++++++++++++++++++++++++++---
> >  9 files changed, 40 insertions(+), 10 deletions(-)
> > 
> > diff --git a/arch/Kconfig b/arch/Kconfig
> > index 3bb2e568f5b1..d56064797e09 100644
> > --- a/arch/Kconfig
> > +++ b/arch/Kconfig
> > @@ -1817,7 +1817,7 @@ config CC_HAS_SANE_FUNCTION_ALIGNMENT
> >  	# strict alignment always, even with -falign-functions.
> >  	def_bool CC_HAS_MIN_FUNCTION_ALIGNMENT || CC_IS_CLANG
> >  
> > -config ARCH_NEED_CMPXCHG_1_EMU
> > +config ARCH_NEED_CMPXCHG_1_2_EMU
> 
> Is it actually worth the churn of changing the name?
> Maybe just a comment that say it adds both 1 and 2 byte emulation?

The churn is only a few lines of code, and the potential confusion from
the name would be forever.  I agree that if we were stuck with the old
name, the comment would help, but why not just rip the bandage off and
be done with it?  ;-)

							Thanx, Paul

_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

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

end of thread, other threads:[~2026-09-23 17:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20260911192540.20983-1-brads@mainlining.org>
2026-09-11 20:17 ` [PATCH 0/6] Add two-byte cmpxchg emulation and wire it into the architectures Arnd Bergmann
     [not found] ` <20260911192540.20983-6-brads@mainlining.org>
2026-09-16 19:16   ` [PATCH 5/6] sh: Emulate two-byte cmpxchg John Paul Adrian Glaubitz
2026-09-16 21:01     ` Paul E. McKenney
2026-09-22 23:06     ` Paul E. McKenney
     [not found] ` <20260911192540.20983-2-brads@mainlining.org>
2026-09-11 22:10   ` [PATCH 1/6] lib: Add two-byte cmpxchg emulation function David Laight
2026-09-11 23:09     ` Paul E. McKenney
2026-09-12  9:30       ` David Laight
2026-09-12 18:58         ` Paul E. McKenney
2026-09-23 10:43   ` David Laight
2026-09-23 17:00     ` Paul E. McKenney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox