diff mbox series

[4/5] csky: Emulate two-byte cmpxchg

Message ID 20261007203636.1982188-4-paulmck@kernel.org
State New
Headers show
Series Provide two-byte cmpxchg() emulation | expand

Commit Message

Paul E. McKenney Oct. 7, 2026, 8:36 p.m. UTC
From: Bradley Morgan <brads@mainlining.org>

C-SKY has no two-byte atomic compare and swap, so the __cmpxchg()
macros let case 2 fall through to BUILD_BUG() via default, and a
two-byte cmpxchg() fails the build.

Route case 2 through the new cmpxchg_emu_u16(), which narrows the
old and new values itself, so all three orderings, relaxed, acquire
and full, keep the (uintptr_t) casts the case 1 path already uses.

Signed-off-by: Bradley Morgan <brads@mainlining.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
 arch/csky/include/asm/cmpxchg.h | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Guo Ren Oct. 8, 2026, 5:54 a.m. UTC | #1
On Thu, Oct 8, 2026 at 4:36 AM Paul E. McKenney <paulmck@kernel.org> wrote:
>
> From: Bradley Morgan <brads@mainlining.org>
>
> C-SKY has no two-byte atomic compare and swap, so the __cmpxchg()
> macros let case 2 fall through to BUILD_BUG() via default, and a
> two-byte cmpxchg() fails the build.
>
> Route case 2 through the new cmpxchg_emu_u16(), which narrows the
> old and new values itself, so all three orderings, relaxed, acquire
> and full, keep the (uintptr_t) casts the case 1 path already uses.
>
> Signed-off-by: Bradley Morgan <brads@mainlining.org>
> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> ---
>  arch/csky/include/asm/cmpxchg.h | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/arch/csky/include/asm/cmpxchg.h b/arch/csky/include/asm/cmpxchg.h
> index db6dda47184e4..6f3ca79e54acf 100644
> --- a/arch/csky/include/asm/cmpxchg.h
> +++ b/arch/csky/include/asm/cmpxchg.h
> @@ -64,6 +64,9 @@
>         switch (size) {                                         \
>         case 1:                                                 \
>                 __ret = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uintptr_t)__old, (uintptr_t)__new); \
> +               break;                                                  \
> +       case 2:                                                 \
> +               __ret = (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *)__ptr, (unsigned long)__old, (unsigned long)__new); \
>                 break;                                          \
>         case 4:                                                 \
>                 asm volatile (                                  \
> @@ -97,6 +100,9 @@
>         switch (size) {                                         \
>         case 1:                                                 \
>                 __ret = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uintptr_t)__old, (uintptr_t)__new); \
> +               break;                                                  \
> +       case 2:                                                 \
> +               __ret = (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *)__ptr, (unsigned long)__old, (unsigned long)__new); \
>                 break;                                          \
>         case 4:                                                 \
>                 asm volatile (                                  \
> @@ -131,6 +137,9 @@
>         switch (size) {                                         \
>         case 1:                                                 \
>                 __ret = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uintptr_t)__old, (uintptr_t)__new); \
> +               break;                                                  \
> +       case 2:                                                 \
> +               __ret = (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *)__ptr, (unsigned long)__old, (unsigned long)__new); \
LGTM!

Acked-by: GUO Ren <guoren@kernel.org>

>                 break;                                          \
>         case 4:                                                 \
>                 asm volatile (                                  \
> --
> 2.40.1
>
Paul E. McKenney Oct. 8, 2026, 3:38 p.m. UTC | #2
On Thu, Oct 08, 2026 at 01:54:57PM +0800, Guo Ren wrote:
> On Thu, Oct 8, 2026 at 4:36 AM Paul E. McKenney <paulmck@kernel.org> wrote:
> >
> > From: Bradley Morgan <brads@mainlining.org>
> >
> > C-SKY has no two-byte atomic compare and swap, so the __cmpxchg()
> > macros let case 2 fall through to BUILD_BUG() via default, and a
> > two-byte cmpxchg() fails the build.
> >
> > Route case 2 through the new cmpxchg_emu_u16(), which narrows the
> > old and new values itself, so all three orderings, relaxed, acquire
> > and full, keep the (uintptr_t) casts the case 1 path already uses.
> >
> > Signed-off-by: Bradley Morgan <brads@mainlining.org>
> > Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> > ---
> >  arch/csky/include/asm/cmpxchg.h | 9 +++++++++
> >  1 file changed, 9 insertions(+)
> >
> > diff --git a/arch/csky/include/asm/cmpxchg.h b/arch/csky/include/asm/cmpxchg.h
> > index db6dda47184e4..6f3ca79e54acf 100644
> > --- a/arch/csky/include/asm/cmpxchg.h
> > +++ b/arch/csky/include/asm/cmpxchg.h
> > @@ -64,6 +64,9 @@
> >         switch (size) {                                         \
> >         case 1:                                                 \
> >                 __ret = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uintptr_t)__old, (uintptr_t)__new); \
> > +               break;                                                  \
> > +       case 2:                                                 \
> > +               __ret = (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *)__ptr, (unsigned long)__old, (unsigned long)__new); \
> >                 break;                                          \
> >         case 4:                                                 \
> >                 asm volatile (                                  \
> > @@ -97,6 +100,9 @@
> >         switch (size) {                                         \
> >         case 1:                                                 \
> >                 __ret = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uintptr_t)__old, (uintptr_t)__new); \
> > +               break;                                                  \
> > +       case 2:                                                 \
> > +               __ret = (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *)__ptr, (unsigned long)__old, (unsigned long)__new); \
> >                 break;                                          \
> >         case 4:                                                 \
> >                 asm volatile (                                  \
> > @@ -131,6 +137,9 @@
> >         switch (size) {                                         \
> >         case 1:                                                 \
> >                 __ret = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uintptr_t)__old, (uintptr_t)__new); \
> > +               break;                                                  \
> > +       case 2:                                                 \
> > +               __ret = (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *)__ptr, (unsigned long)__old, (unsigned long)__new); \
> LGTM!
> 
> Acked-by: GUO Ren <guoren@kernel.org>

Thank you!  I will apply this on my next rebase.

							Thanx, Paul

> >                 break;                                          \
> >         case 4:                                                 \
> >                 asm volatile (                                  \
> > --
> > 2.40.1
> >
> 
> 
> -- 
> Best Regards
>  Guo Ren
diff mbox series

Patch

diff --git a/arch/csky/include/asm/cmpxchg.h b/arch/csky/include/asm/cmpxchg.h
index db6dda47184e4..6f3ca79e54acf 100644
--- a/arch/csky/include/asm/cmpxchg.h
+++ b/arch/csky/include/asm/cmpxchg.h
@@ -64,6 +64,9 @@ 
 	switch (size) {						\
 	case 1:							\
 		__ret = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uintptr_t)__old, (uintptr_t)__new); \
+		break;							\
+	case 2:							\
+		__ret = (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *)__ptr, (unsigned long)__old, (unsigned long)__new); \
 		break;						\
 	case 4:							\
 		asm volatile (					\
@@ -97,6 +100,9 @@ 
 	switch (size) {						\
 	case 1:							\
 		__ret = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uintptr_t)__old, (uintptr_t)__new); \
+		break;							\
+	case 2:							\
+		__ret = (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *)__ptr, (unsigned long)__old, (unsigned long)__new); \
 		break;						\
 	case 4:							\
 		asm volatile (					\
@@ -131,6 +137,9 @@ 
 	switch (size) {						\
 	case 1:							\
 		__ret = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uintptr_t)__old, (uintptr_t)__new); \
+		break;							\
+	case 2:							\
+		__ret = (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *)__ptr, (unsigned long)__old, (unsigned long)__new); \
 		break;						\
 	case 4:							\
 		asm volatile (					\