Skip to contentSkip to conversation

Add two-byte cmpxchg emulation and wire it into the architectures

PATCH Superseded Bradley Morgan 5 participants 17 messages Oct 5 – Oct 7

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v5 cover Add two-byte cmpxchg emulation and wire it into the architectures

This is v5 of the two-byte cmpxchg emulation series, reduced to the three architectures still missing after Paul McKenney queued the lib and sh patches, ARC, csky and xtensa.

The v4 attempt at these folded in a type checking idiom, (unsigned long)(0 ? *ptr : old), meant to make cmpxchg(&p, 4, 5) fail to compile. The kernel test robot and Vineet Gupta showed that idiom breaks real callers, fs/crypto/hooks.c passes a char * and an unsigned char * to cmpxchg_release(), and the conditional expression then has incompatible pointer types, which is a hard error on gcc 14 and newer. So this version only adds the case 2 dispatch, the declarations the architectures already have are kept as is.

The ARC sizeof bug that v4 fixed along the way is in mainline separately through Vineet's f050c3e61d2a ("ARC: arch_cmpxchg_relaxed to use size of pointed type not pointer"), so the ARC patch here is only the case 2 wiring on top of that.

On the why, RCU previously used single-byte cmpxchg(), which is what motivated cmpxchg_emu_u8() in the first place, and Paul has now queued cmpxchg_emu_u16(). Unused new code is frowned upon, so wiring it into the architectures that need it is the missing half, and there are existing workarounds for the missing two-byte cmpxchg() in the tree, _Q_PENDING_BITS for one, that can make use of it.

Per Paul's suggestion each patch is standalone and can go in independently, they only depend on the lib patch already queued. Each one was build tested with the real cross toolchain, ARC with arc-linux-gnu-gcc and csky and xtensa with the gcc 16.2 crosstool builds Vineet pointed at, W=1, with the macro instantiated on u8, u16, u32 and pointer types, confirming the new dispatch is reached and no new warnings appear. The pointer instantiation covers the fs/crypto/hooks.c case that broke v4.

Bradley Morgan (3):
ARC: Emulate two-byte cmpxchg
csky: Emulate two-byte cmpxchg
xtensa: Emulate two-byte cmpxchg

 arch/arc/include/asm/cmpxchg.h    | 3 +++
 arch/csky/include/asm/cmpxchg.h   | 9 +++++++++
 arch/xtensa/include/asm/cmpxchg.h | 1 +
 3 files changed, 13 insertions(+)
Signature · 1 line
2.53.0
#1 lore raw

PATCH v5 1/3 ARC: Emulate two-byte cmpxchg

ARC has no two-byte atomic compare and swap, so the arch_cmpxchg_relaxed() macro switch lets 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 the dispatch keeps the (uintptr_t) casts the case 1 path already uses.

The sizeof(*(_p_)) fix that v4 folded in here landed separately through Vineet's f050c3e61d2a, so this patch is now only the case 2 wiring.

---
 arch/arc/include/asm/cmpxchg.h | 3 +++
 1 file changed, 3 insertions(+)
arch/arc/include/asm/cmpxchg.h +3 -0
index 66b3743c9400..b30b20933f32 100644
@@ -50,6 +50,9 @@
 	case 1:								\
 		_prev_ = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *__force)_p_, (uintptr_t)_o_, (uintptr_t)_n_);	\
 		break;							\
+	case 2:								\
+		_prev_ = (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *__force)_p_, (unsigned long)_o_, (unsigned long)_n_);	\
+		break;							\
 	case 4:								\
 		_prev_ = __cmpxchg(_p_, _o_, _n_);			\
 		break;							\
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH v5 1/3] ARC: Emulate two-byte cmpxchg

kernel test robot noticed the following build errors:

Hi Bradley,

kernel test robot noticed the following build errors:

[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on vgupta-arc/for-curr jcmvbkbc-xtensa/xtensa-for-next linus/master v7.3-rc6 next-20261005] [cannot apply to vgupta-arc/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Bradley-Morgan/ARC-Emulate-two-byte-cmpxchg/20261005-120658
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20261005120700.383058-2-brads%40mainlining.org
patch subject: [PATCH v5 1/3] ARC: Emulate two-byte cmpxchg
config: arc-allyesconfig (https://download.01.org/0day-ci/archive/20261006/[email protected]/config)
compiler: arc-linux-gcc (GCC) 16.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261006/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from arch/arc/include/asm/atomic.h:13,

                    from include/linux/atomic.h:7,
                    from include/asm-generic/bitops/lock.h:5,
                    from arch/arc/include/asm/bitops.h:190,
                    from include/linux/bitops.h:67,
                    from include/linux/log2.h:12,
                    from kernel/bounds.c:14:
   include/linux/atomic/atomic-arch-fallback.h: In function 'raw_atomic_cmpxchg':
>> arch/arc/include/asm/cmpxchg.h:54:46: error: implicit declaration of function 'cmpxchg_emu_u16'; did you mean 'cmpxchg_emu_u8'? [-Wimplicit-function-declaration]
      54 |                 _prev_ = (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *__force)_p_, (unsigned long)_o_, (unsigned long)_n_);       \
         |                                              ^~~~~~~~~~~~~~~
   include/linux/atomic.h:73:16: note: in expansion of macro 'arch_cmpxchg_relaxed'
      73 |         typeof(op##_relaxed(args)) __ret;                               \
         |                ^~
   include/linux/atomic/atomic-arch-fallback.h:58:9: note: in expansion of macro '__atomic_op_fence'
      58 |         __atomic_op_fence(arch_cmpxchg, __VA_ARGS__)
         |         ^~~~~~~~~~~~~~~~~
   include/linux/atomic/atomic-arch-fallback.h:2026:16: note: in expansion of macro 'raw_cmpxchg'
    2026 |         return raw_cmpxchg(&v->counter, old, new);
         |                ^~~~~~~~~~~

make[3]: *** [scripts/Makefile.build:185: kernel/bounds.s] Error 1 make[3]: Target 'prepare' not remade because of errors. make[2]: *** [Makefile:1405: prepare0] Error 2
make[2]: Target 'prepare' not remade because of errors. make[1]: *** [Makefile:248: __sub-make] Error 2 make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.

vim +54 arch/arc/include/asm/cmpxchg.h

    41	
    42	#define arch_cmpxchg_relaxed(ptr, old, new)				\
    43	({									\
    44		__typeof__(ptr) _p_ = (ptr);					\
    45		__typeof__(*(ptr)) _o_ = (old);					\
    46		__typeof__(*(ptr)) _n_ = (new);					\
    47		__typeof__(*(ptr)) _prev_;					\
    48										\
    49		switch (sizeof(*(_p_))) {						\
    50		case 1:								\
    51			_prev_ = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *__force)_p_, (uintptr_t)_o_, (uintptr_t)_n_);	\
    52			break;							\
    53		case 2:								\
  > 54			_prev_ = (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *__force)_p_, (unsigned long)_o_, (unsigned long)_n_);	\
    55			break;							\
    56		case 4:								\
    57			_prev_ = __cmpxchg(_p_, _o_, _n_);			\
    58			break;							\
    59		default:							\
    60			BUILD_BUG();						\
    61		}								\
    62		_prev_;								\
    63	})
    64	

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

#3 lore raw

PATCH v5 2/3 csky: Emulate two-byte cmpxchg

In reply to Bradley Morgan

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.

---
 arch/csky/include/asm/cmpxchg.h | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/csky/include/asm/cmpxchg.h +9 -0
index db6dda47184e..6f3ca79e54ac 100644
@@ -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 (					\
Signature · 1 line
2.53.0
#4 lore raw

PATCH v5 3/3 xtensa: Emulate two-byte cmpxchg

In reply to Bradley Morgan

Xtensa has no two-byte atomic compare and swap, so the __cmpxchg() switch 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 and narrows them itself, so the call needs no extra casts.

---
 arch/xtensa/include/asm/cmpxchg.h | 1 +
 1 file changed, 1 insertion(+)
arch/xtensa/include/asm/cmpxchg.h +1 -0
index b6db4838b175..8dea8e357fc0 100644
@@ -76,6 +76,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
 {
 	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);
 	default: __cmpxchg_called_with_bad_pointer();
 		 return old;
Signature · 6 lines
2.53.0

_______________________________________________
linux-snps-arc mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-snps-arc
#5 lore raw

Re: [PATCH v5 3/3] xtensa: Emulate two-byte cmpxchg

kernel test robot noticed the following build errors:

Hi Bradley,

kernel test robot noticed the following build errors:

[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on vgupta-arc/for-curr jcmvbkbc-xtensa/xtensa-for-next linus/master v7.3-rc6 next-20261005] [cannot apply to vgupta-arc/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Bradley-Morgan/ARC-Emulate-two-byte-cmpxchg/20261005-120658
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20261005120700.383058-4-brads%40mainlining.org
patch subject: [PATCH v5 3/3] xtensa: Emulate two-byte cmpxchg
config: xtensa-allyesconfig (https://download.01.org/0day-ci/archive/20261006/[email protected]/config)
compiler: xtensa-linux-gcc (GCC) 16.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261006/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from arch/xtensa/include/asm/atomic.h:19,

                    from include/linux/atomic.h:7,
                    from include/asm-generic/bitops/atomic.h:5,
                    from arch/xtensa/include/asm/bitops.h:192,
                    from include/linux/bitops.h:67,
                    from include/linux/log2.h:12,
                    from kernel/bounds.c:14:
   arch/xtensa/include/asm/cmpxchg.h: In function '__cmpxchg':
>> arch/xtensa/include/asm/cmpxchg.h:79:25: error: implicit declaration of function 'cmpxchg_emu_u16'; did you mean 'cmpxchg_emu_u8'? [-Wimplicit-function-declaration]
      79 |         case 2:  return cmpxchg_emu_u16(ptr, old, new);
         |                         ^~~~~~~~~~~~~~~
         |                         cmpxchg_emu_u8

make[3]: *** [scripts/Makefile.build:185: kernel/bounds.s] Error 1 make[3]: Target 'prepare' not remade because of errors. make[2]: *** [Makefile:1405: prepare0] Error 2
make[2]: Target 'prepare' not remade because of errors. make[1]: *** [Makefile:248: __sub-make] Error 2 make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.

vim +79 arch/xtensa/include/asm/cmpxchg.h

    73	
    74	static __inline__ unsigned long
    75	__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
    76	{
    77		switch (size) {
    78		case 1:  return cmpxchg_emu_u8(ptr, old, new);
  > 79		case 2:  return cmpxchg_emu_u16(ptr, old, new);
    80		case 4:  return __cmpxchg_u32(ptr, old, new);
    81		default: __cmpxchg_called_with_bad_pointer();
    82			 return old;
    83		}
    84	}
    85	

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

#6 lore raw

Re: [PATCH v5 3/3] xtensa: Emulate two-byte cmpxchg

Quoted 19 lines · kernel test robot

Hi Bradley,

kernel test robot noticed the following build errors:

[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on vgupta-arc/for-curr jcmvbkbc-xtensa/xtensa-for-next linus/master v7.3-rc6 next-20261005] [cannot apply to vgupta-arc/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Bradley-Morgan/ARC-Emulate-two-byte-cmpxchg/20261005-120658
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20261005120700.383058-4-brads%40mainlining.org
patch subject: [PATCH v5 3/3] xtensa: Emulate two-byte cmpxchg
config: xtensa-allyesconfig (https://download.01.org/0day-ci/archive/20261006/[email protected]/config)
compiler: xtensa-linux-gcc (GCC) 16.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261006/[email protected]/reproduce)
Quoted 6 lines

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

These patches need to be applied on top of my -rcu tree's "dev" branch, which supplies cmpxchg_emu_u16().

Nevertheless, thank you for your testing efforts!

Thanx, Paul

Quoted 41 lines

In file included from arch/xtensa/include/asm/atomic.h:19,

                    from include/linux/atomic.h:7,
                    from include/asm-generic/bitops/atomic.h:5,
                    from arch/xtensa/include/asm/bitops.h:192,
                    from include/linux/bitops.h:67,
                    from include/linux/log2.h:12,
                    from kernel/bounds.c:14:

arch/xtensa/include/asm/cmpxchg.h: In function '__cmpxchg':

Quoted 1 line
Quoted 1 line

arch/xtensa/include/asm/cmpxchg.h:79:25: error: implicit declaration of function 'cmpxchg_emu_u16'; did you mean 'cmpxchg_emu_u8'? [-Wimplicit-function-declaration]

      79 |         case 2:  return cmpxchg_emu_u16(ptr, old, new);
         |                         ^~~~~~~~~~~~~~~
         |                         cmpxchg_emu_u8

make[3]: *** [scripts/Makefile.build:185: kernel/bounds.s] Error 1 make[3]: Target 'prepare' not remade because of errors. make[2]: *** [Makefile:1405: prepare0] Error 2
make[2]: Target 'prepare' not remade because of errors. make[1]: *** [Makefile:248: __sub-make] Error 2 make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.

vim +79 arch/xtensa/include/asm/cmpxchg.h

    73	
    74	static __inline__ unsigned long
    75	__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
    76	{
    77		switch (size) {
    78		case 1:  return cmpxchg_emu_u8(ptr, old, new);
Quoted 1 line

79 case 2: return cmpxchg_emu_u16(ptr, old, new);

    80		case 4:  return __cmpxchg_u32(ptr, old, new);
    81		default: __cmpxchg_called_with_bad_pointer();
    82			 return old;
    83		}
    84	}
    85	

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

#7 lore raw

Re: [PATCH v5 3/3] xtensa: Emulate two-byte cmpxchg

Quoted 31 lines · Paul E. McKenney
Quoted 6 lines · kernel test robot

Hi Bradley,

kernel test robot noticed the following build errors:

[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on vgupta-arc/for-curr

jcmvbkbc-xtensa/xtensa-for-next linus/master v7.3-rc6 next-20261005]

Quoted 6 lines

[cannot apply to vgupta-arc/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:

https://github.com/intel-lab-lkp/linux/commits/Bradley-Morgan/ARC-Emulate-two-byte-cmpxchg/20261005-120658

Quoted 1 line

base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git

mm-everything

Quoted 1 line

patch link:

https://lore.kernel.org/r/20261005120700.383058-4-brads%40mainlining.org

Quoted 2 lines

patch subject: [PATCH v5 3/3] xtensa: Emulate two-byte cmpxchg
config: xtensa-allyesconfig

(https://download.01.org/0day-ci/archive/20261006/[email protected]/config)

Quoted 2 lines

compiler: xtensa-linux-gcc (GCC) 16.1.0
reproduce (this is a W=1 build):

(https://download.01.org/0day-ci/archive/20261006/[email protected]/reproduce)

Quoted 2 lines

If you fix the issue in a separate patch/commit (i.e. not just a new

version of

Quoted 3 lines

the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes:

Quoted 8 lines

https://lore.kernel.org/oe-kbuild-all/[email protected]/

Quoted 2 lines

All errors (new ones prefixed by >>):

These patches need to be applied on top of my -rcu tree's "dev" branch, which supplies cmpxchg_emu_u16().

Nevertheless, thank you for your testing efforts!

Do you reckon they are fine to you? The patches?

Arch maintainers may be busy unfortunately :(, I've done testing on all the arches,

Quoted 11 lines

Thanx, Paul

Quoted 8 lines

In file included from arch/xtensa/include/asm/atomic.h:19,

                    from include/linux/atomic.h:7,
                    from include/asm-generic/bitops/atomic.h:5,
                    from arch/xtensa/include/asm/bitops.h:192,
                    from include/linux/bitops.h:67,
                    from include/linux/log2.h:12,
                    from kernel/bounds.c:14:

arch/xtensa/include/asm/cmpxchg.h: In function '__cmpxchg':

Quoted 35 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

arch/xtensa/include/asm/cmpxchg.h:79:25: error: implicit declaration

of function 'cmpxchg_emu_u16'; did you mean 'cmpxchg_emu_u8'? [-Wimplicit-function-declaration]

Quoted 32 lines
      79 |         case 2:  return cmpxchg_emu_u16(ptr, old, new);
         |                         ^~~~~~~~~~~~~~~
         |                         cmpxchg_emu_u8

make[3]: *** [scripts/Makefile.build:185: kernel/bounds.s] Error 1 make[3]: Target 'prepare' not remade because of errors. make[2]: *** [Makefile:1405: prepare0] Error 2
make[2]: Target 'prepare' not remade because of errors. make[1]: *** [Makefile:248: __sub-make] Error 2 make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.

vim +79 arch/xtensa/include/asm/cmpxchg.h

    73	
    74	static __inline__ unsigned long
    75	__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
    76	{
    77		switch (size) {
    78		case 1:  return cmpxchg_emu_u8(ptr, old, new);
Quoted 1 line

79 case 2: return cmpxchg_emu_u16(ptr, old, new);

    80		case 4:  return __cmpxchg_u32(ptr, old, new);
    81		default: __cmpxchg_called_with_bad_pointer();
    82			 return old;
    83		}
    84	}
    85	

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

--- Thanks!
"I'm not a very positive person" - Linus torvalds

_______________________________________________
linux-snps-arc mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

#8 lore raw

Re: [PATCH v5 3/3] xtensa: Emulate two-byte cmpxchg

Quoted 40 lines · Bradley Morgan
Quoted 38 lines · Paul E. McKenney
Quoted 6 lines · kernel test robot

Hi Bradley,

kernel test robot noticed the following build errors:

[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on vgupta-arc/for-curr

jcmvbkbc-xtensa/xtensa-for-next linus/master v7.3-rc6 next-20261005]

Quoted 6 lines

[cannot apply to vgupta-arc/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:

https://github.com/intel-lab-lkp/linux/commits/Bradley-Morgan/ARC-Emulate-two-byte-cmpxchg/20261005-120658

Quoted 1 line

base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git

mm-everything

Quoted 1 line

patch link:

https://lore.kernel.org/r/20261005120700.383058-4-brads%40mainlining.org

Quoted 2 lines

patch subject: [PATCH v5 3/3] xtensa: Emulate two-byte cmpxchg
config: xtensa-allyesconfig

(https://download.01.org/0day-ci/archive/20261006/[email protected]/config)

Quoted 2 lines

compiler: xtensa-linux-gcc (GCC) 16.1.0
reproduce (this is a W=1 build):

(https://download.01.org/0day-ci/archive/20261006/[email protected]/reproduce)

Quoted 2 lines

If you fix the issue in a separate patch/commit (i.e. not just a new

version of

Quoted 3 lines

the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes:

https://lore.kernel.org/oe-kbuild-all/[email protected]/

Quoted 2 lines

All errors (new ones prefixed by >>):

These patches need to be applied on top of my -rcu tree's "dev" branch, which supplies cmpxchg_emu_u16().

Quoted 6 lines
Quoted 1 line

Nevertheless, thank you for your testing efforts!

Do you reckon they are fine to you? The patches?

Arch maintainers may be busy unfortunately :(, I've done testing on all the arches,

I have queued the one that is already acked by the SH maintainer, so we get at least something into the upcoming merge window. I plan to try your patches out later today, Pacific Time, and queue them if they are ready.

If the architecture maintainers ack them in time, I send a pull request for them in the upcoming merge window. If some of the do not yet have acks, I keep those unacked ones for the next merge window. If they are still being ignored at that point, I send the pull request anyway. Maybe Linus takes it, maybe not. If not, I figure things out from that point.

Hey, it is a lot faster than some other communities that I am involved with, where the timeframes are years and even decades rather than mere weeks and months. ;-)

Thanx, Paul

Quoted 46 lines
Quoted 8 lines
Quoted 8 lines

In file included from arch/xtensa/include/asm/atomic.h:19,

                    from include/linux/atomic.h:7,
                    from include/asm-generic/bitops/atomic.h:5,
                    from arch/xtensa/include/asm/bitops.h:192,
                    from include/linux/bitops.h:67,
                    from include/linux/log2.h:12,
                    from kernel/bounds.c:14:

arch/xtensa/include/asm/cmpxchg.h: In function '__cmpxchg':

Quoted 35 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

arch/xtensa/include/asm/cmpxchg.h:79:25: error: implicit declaration

of function 'cmpxchg_emu_u16'; did you mean 'cmpxchg_emu_u8'? [-Wimplicit-function-declaration]

Quoted 32 lines
      79 |         case 2:  return cmpxchg_emu_u16(ptr, old, new);
         |                         ^~~~~~~~~~~~~~~
         |                         cmpxchg_emu_u8

make[3]: *** [scripts/Makefile.build:185: kernel/bounds.s] Error 1 make[3]: Target 'prepare' not remade because of errors. make[2]: *** [Makefile:1405: prepare0] Error 2
make[2]: Target 'prepare' not remade because of errors. make[1]: *** [Makefile:248: __sub-make] Error 2 make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.

vim +79 arch/xtensa/include/asm/cmpxchg.h

    73	
    74	static __inline__ unsigned long
    75	__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
    76	{
    77		switch (size) {
    78		case 1:  return cmpxchg_emu_u8(ptr, old, new);
Quoted 1 line

79 case 2: return cmpxchg_emu_u16(ptr, old, new);

    80		case 4:  return __cmpxchg_u32(ptr, old, new);
    81		default: __cmpxchg_called_with_bad_pointer();
    82			 return old;
    83		}
    84	}
    85	

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

--- Thanks!
"I'm not a very positive person" - Linus torvalds

maintainer
#9 lore raw

Re: [PATCH v5 3/3] xtensa: Emulate two-byte cmpxchg

In reply to Bradley Morgan
Quoted 4 lines · Bradley Morgan

Do you reckon they are fine to you? The patches?

Arch maintainers may be busy unfortunately 🙁, I've done testing on all the arches,

Everyone is traveling due to the conf season - LPC, ELC.

-Vineet

maintainer
#10 lore raw

Re: [PATCH v5 3/3] xtensa: Emulate two-byte cmpxchg

In reply to Paul E. McKenney
Quoted 4 lines · Paul E. McKenney

These patches need to be applied on top of my -rcu tree's "dev" branch, which supplies cmpxchg_emu_u16().

Nevertheless, thank you for your testing efforts!

Sorry I don't have your tree is my git remotes. can u point me to the msg id of the series which was applied so i can fetch it and apply. At this point I can't ACK/Nack the patch since w/o the pre-req it just fails to build locally exactly as the kernel robot found.

Thx,
-Vineet

#11 lore raw

Re: [PATCH v5 3/3] xtensa: Emulate two-byte cmpxchg

Quoted 10 lines · Vineet Gupta
Quoted 4 lines · Paul E. McKenney

These patches need to be applied on top of my -rcu tree's "dev" branch, which supplies cmpxchg_emu_u16().

Nevertheless, thank you for your testing efforts!

Sorry I don't have your tree is my git remotes. can u point me to the msg id of the series which was applied so i can fetch it and apply.
At this point I can't ACK/Nack the patch since w/o the pre-req it just fails to build locally exactly as the kernel robot found.

I will resend the full series later today, Pacific Time. In the meantime, these commits in my -rcu tree [1] on the "dev" branch in "git log" order:

a29bf4d6dc4f3 xtensa: Emulate two-byte cmpxchg 10d67fa61f9f4 csky: Emulate two-byte cmpxchg 1decb1d05ef2e ARC: Emulate two-byte cmpxchg 887685c52e44c sh: Emulate two-byte cmpxchg 109f733202e32 lib: Add two-byte cmpxchg emulation function

Thanx, Paul

[1] git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git

#12 lore raw
In reply to Bradley Morgan
Quoted 13 lines · Bradley Morgan

This is v5 of the two-byte cmpxchg emulation series, reduced to the three architectures still missing after Paul McKenney queued the lib and sh patches, ARC, csky and xtensa.

The v4 attempt at these folded in a type checking idiom, (unsigned long)(0 ? *ptr : old), meant to make cmpxchg(&p, 4, 5) fail to compile. The kernel test robot and Vineet Gupta showed that idiom breaks real callers, fs/crypto/hooks.c passes a char * and an unsigned char * to cmpxchg_release(), and the conditional expression then has incompatible pointer types, which is a hard error on gcc 14 and newer. So this version only adds the case 2 dispatch, the declarations the architectures already have are kept as is.

Quoted 4 lines

The ARC sizeof bug that v4 fixed along the way is in mainline separately through Vineet's f050c3e61d2a ("ARC: arch_cmpxchg_relaxed to use size of pointed type not pointer"), so the ARC patch here is only the case 2 wiring on top of that.

Sashiko took a hitch at it, all the "bugs" are bogus, most are just cuz "u16 is undefined oh no error", but they didn't see Paul's tree, where it is defined.

whatever

Quoted 22 lines

On the why, RCU previously used single-byte cmpxchg(), which is what motivated cmpxchg_emu_u8() in the first place, and Paul has now queued cmpxchg_emu_u16(). Unused new code is frowned upon, so wiring it into the architectures that need it is the missing half, and there are existing workarounds for the missing two-byte cmpxchg() in the tree, _Q_PENDING_BITS for one, that can make use of it.

Per Paul's suggestion each patch is standalone and can go in independently, they only depend on the lib patch already queued. Each one was build tested with the real cross toolchain, ARC with arc-linux-gnu-gcc and csky and xtensa with the gcc 16.2 crosstool builds Vineet pointed at, W=1, with the macro instantiated on u8, u16, u32 and pointer types, confirming the new dispatch is reached and no new warnings appear. The pointer instantiation covers the fs/crypto/hooks.c case that broke v4.

Bradley Morgan (3):
ARC: Emulate two-byte cmpxchg
csky: Emulate two-byte cmpxchg
xtensa: Emulate two-byte cmpxchg

Quoted 6 lines
arch/arc/include/asm/cmpxchg.h    | 3 +++
arch/csky/include/asm/cmpxchg.h   | 9 +++++++++
arch/xtensa/include/asm/cmpxchg.h | 1 +
3 files changed, 13 insertions(+)

--- Thanks!
"I'm not a very positive person" - Linus torvalds

_______________________________________________
linux-snps-arc mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

#13 lore raw
In reply to Bradley Morgan
Quoted 9 lines · On Mon, 5 Oct 2026 12:06:57 +0000 Bradley Morgan <[email protected]> wrote:

This is v5 of the two-byte cmpxchg emulation series, reduced to the three architectures still missing after Paul McKenney queued the lib and sh patches, ARC, csky and xtensa.

The v4 attempt at these folded in a type checking idiom, (unsigned long)(0 ? *ptr : old), meant to make cmpxchg(&p, 4, 5) fail to compile. The kernel test robot and Vineet Gupta showed that idiom breaks real callers, fs/crypto/hooks.c passes a char * and an unsigned char * to cmpxchg_release(),

That ought to be a bug...

David

Quoted 36 lines

and the conditional expression
then has incompatible pointer types, which is a hard error on gcc 14 and newer. So this version only adds the case 2 dispatch, the declarations the architectures already have are kept as is.

The ARC sizeof bug that v4 fixed along the way is in mainline separately through Vineet's f050c3e61d2a ("ARC: arch_cmpxchg_relaxed to use size of pointed type not pointer"), so the ARC patch here is only the case 2 wiring on top of that.

On the why, RCU previously used single-byte cmpxchg(), which is what motivated cmpxchg_emu_u8() in the first place, and Paul has now queued cmpxchg_emu_u16(). Unused new code is frowned upon, so wiring it into the architectures that need it is the missing half, and there are existing workarounds for the missing two-byte cmpxchg() in the tree, _Q_PENDING_BITS for one, that can make use of it.

Per Paul's suggestion each patch is standalone and can go in independently, they only depend on the lib patch already queued. Each one was build tested with the real cross toolchain, ARC with arc-linux-gnu-gcc and csky and xtensa with the gcc 16.2 crosstool builds Vineet pointed at, W=1, with the macro instantiated on u8, u16, u32 and pointer types, confirming the new dispatch is reached and no new warnings appear. The pointer instantiation covers the fs/crypto/hooks.c case that broke v4.

Bradley Morgan (3):
ARC: Emulate two-byte cmpxchg
csky: Emulate two-byte cmpxchg
xtensa: Emulate two-byte cmpxchg

 arch/arc/include/asm/cmpxchg.h    | 3 +++
 arch/csky/include/asm/cmpxchg.h   | 9 +++++++++
 arch/xtensa/include/asm/cmpxchg.h | 1 +
 3 files changed, 13 insertions(+)
#14 lore raw
Quoted 7 lines · David Laight
Quoted 4 lines · On Mon, 5 Oct 2026 12:06:57 +0000 Bradley Morgan <[email protected]> wrote:

This is v5 of the two-byte cmpxchg emulation series, reduced to the three architectures still missing after Paul McKenney queued the lib and sh patches, ARC, csky and xtensa.

Quoted 7 lines
Quoted 5 lines

The v4 attempt at these folded in a type checking idiom, (unsigned long)(0 ? *ptr : old), meant to make cmpxchg(&p, 4, 5) fail to compile. The kernel test robot and Vineet Gupta showed that idiom breaks real callers, fs/crypto/hooks.c passes a char * and an unsigned char * to cmpxchg_release(),

That ought to be a bug...

Perhaps it is? Here is the code:

	cmpxchg_release(&inode->i_link, NULL, pstr.name)

And inode is a struct inode, of which ->i_link is char*. For its part, pstr is a struct fscrypt_str, of which ->name is unsigned char *.

But this is either a 4-byte or 8-byte cmpxchg_release(), depending on CONFIG_64BIT, which is orthogonal to this patch series, which provides 2-byte emulation.

Therefore, I see no reason to hold up these cmpxchg_emu_u16() patches.

But please let me know if I am missing something.

Thanx, Paul

Quoted 39 lines

David

Quoted 36 lines

and the conditional expression
then has incompatible pointer types, which is a hard error on gcc 14 and newer. So this version only adds the case 2 dispatch, the declarations the architectures already have are kept as is.

The ARC sizeof bug that v4 fixed along the way is in mainline separately through Vineet's f050c3e61d2a ("ARC: arch_cmpxchg_relaxed to use size of pointed type not pointer"), so the ARC patch here is only the case 2 wiring on top of that.

On the why, RCU previously used single-byte cmpxchg(), which is what motivated cmpxchg_emu_u8() in the first place, and Paul has now queued cmpxchg_emu_u16(). Unused new code is frowned upon, so wiring it into the architectures that need it is the missing half, and there are existing workarounds for the missing two-byte cmpxchg() in the tree, _Q_PENDING_BITS for one, that can make use of it.

Per Paul's suggestion each patch is standalone and can go in independently, they only depend on the lib patch already queued. Each one was build tested with the real cross toolchain, ARC with arc-linux-gnu-gcc and csky and xtensa with the gcc 16.2 crosstool builds Vineet pointed at, W=1, with the macro instantiated on u8, u16, u32 and pointer types, confirming the new dispatch is reached and no new warnings appear. The pointer instantiation covers the fs/crypto/hooks.c case that broke v4.

Bradley Morgan (3):
ARC: Emulate two-byte cmpxchg
csky: Emulate two-byte cmpxchg
xtensa: Emulate two-byte cmpxchg

 arch/arc/include/asm/cmpxchg.h    | 3 +++
 arch/csky/include/asm/cmpxchg.h   | 9 +++++++++
 arch/xtensa/include/asm/cmpxchg.h | 1 +
 3 files changed, 13 insertions(+)
#15 lore raw
Quoted 20 lines · On Tue, 6 Oct 2026 11:16:42 -0700 "Paul E. McKenney" <[email protected]> wrote:
Quoted 7 lines · David Laight
Quoted 4 lines · On Mon, 5 Oct 2026 12:06:57 +0000 Bradley Morgan <[email protected]> wrote:

This is v5 of the two-byte cmpxchg emulation series, reduced to the three architectures still missing after Paul McKenney queued the lib and sh patches, ARC, csky and xtensa.

Quoted 7 lines
Quoted 5 lines

The v4 attempt at these folded in a type checking idiom, (unsigned long)(0 ? *ptr : old), meant to make cmpxchg(&p, 4, 5) fail to compile. The kernel test robot and Vineet Gupta showed that idiom breaks real callers, fs/crypto/hooks.c passes a char * and an unsigned char * to cmpxchg_release(),

That ought to be a bug...

Perhaps it is? Here is the code:

	cmpxchg_release(&inode->i_link, NULL, pstr.name)
Quoted 8 lines

And inode is a struct inode, of which ->i_link is char*. For its part, pstr is a struct fscrypt_str, of which ->name is unsigned char *.

But this is either a 4-byte or 8-byte cmpxchg_release(), depending on CONFIG_64BIT, which is orthogonal to this patch series, which provides 2-byte emulation.

Therefore, I see no reason to hold up these cmpxchg_emu_u16() patches.

True.

David

Quoted 44 lines

But please let me know if I am missing something.

Thanx, Paul

Quoted 39 lines

David

Quoted 36 lines

and the conditional expression
then has incompatible pointer types, which is a hard error on gcc 14 and newer. So this version only adds the case 2 dispatch, the declarations the architectures already have are kept as is.

The ARC sizeof bug that v4 fixed along the way is in mainline separately through Vineet's f050c3e61d2a ("ARC: arch_cmpxchg_relaxed to use size of pointed type not pointer"), so the ARC patch here is only the case 2 wiring on top of that.

On the why, RCU previously used single-byte cmpxchg(), which is what motivated cmpxchg_emu_u8() in the first place, and Paul has now queued cmpxchg_emu_u16(). Unused new code is frowned upon, so wiring it into the architectures that need it is the missing half, and there are existing workarounds for the missing two-byte cmpxchg() in the tree, _Q_PENDING_BITS for one, that can make use of it.

Per Paul's suggestion each patch is standalone and can go in independently, they only depend on the lib patch already queued. Each one was build tested with the real cross toolchain, ARC with arc-linux-gnu-gcc and csky and xtensa with the gcc 16.2 crosstool builds Vineet pointed at, W=1, with the macro instantiated on u8, u16, u32 and pointer types, confirming the new dispatch is reached and no new warnings appear. The pointer instantiation covers the fs/crypto/hooks.c case that broke v4.

Bradley Morgan (3):
ARC: Emulate two-byte cmpxchg
csky: Emulate two-byte cmpxchg
xtensa: Emulate two-byte cmpxchg

 arch/arc/include/asm/cmpxchg.h    | 3 +++
 arch/csky/include/asm/cmpxchg.h   | 9 +++++++++
 arch/xtensa/include/asm/cmpxchg.h | 1 +
 3 files changed, 13 insertions(+)
#16 lore raw
In reply to Bradley Morgan
Quoted 25 lines · Bradley Morgan

This is v5 of the two-byte cmpxchg emulation series, reduced to the three architectures still missing after Paul McKenney queued the lib and sh patches, ARC, csky and xtensa.

The v4 attempt at these folded in a type checking idiom, (unsigned long)(0 ? *ptr : old), meant to make cmpxchg(&p, 4, 5) fail to compile. The kernel test robot and Vineet Gupta showed that idiom breaks real callers, fs/crypto/hooks.c passes a char * and an unsigned char * to cmpxchg_release(), and the conditional expression then has incompatible pointer types, which is a hard error on gcc 14 and newer. So this version only adds the case 2 dispatch, the declarations the architectures already have are kept as is.

The ARC sizeof bug that v4 fixed along the way is in mainline separately through Vineet's f050c3e61d2a ("ARC: arch_cmpxchg_relaxed to use size of pointed type not pointer"), so the ARC patch here is only the case 2 wiring on top of that.

On the why, RCU previously used single-byte cmpxchg(), which is what motivated cmpxchg_emu_u8() in the first place, and Paul has now queued cmpxchg_emu_u16(). Unused new code is frowned upon, so wiring it into the architectures that need it is the missing half, and there are existing workarounds for the missing two-byte cmpxchg() in the tree, _Q_PENDING_BITS for one, that can make use of it.

Quoted 8 lines

Per Paul's suggestion each patch is standalone and can go in independently, they only depend on the lib patch already queued. Each one was build tested with the real cross toolchain, ARC with arc-linux-gnu-gcc and csky and xtensa with the gcc 16.2 crosstool builds Vineet pointed at, W=1, with the macro instantiated on u8, u16, u32 and pointer types, confirming the new dispatch is reached and no new warnings appear. The pointer instantiation covers the fs/crypto/hooks.c case that broke v4.

Queued for review and testing, thank you!

Thanx, Paul

Quoted 12 lines

Bradley Morgan (3):
ARC: Emulate two-byte cmpxchg
csky: Emulate two-byte cmpxchg
xtensa: Emulate two-byte cmpxchg

 arch/arc/include/asm/cmpxchg.h    | 3 +++
 arch/csky/include/asm/cmpxchg.h   | 9 +++++++++
 arch/xtensa/include/asm/cmpxchg.h | 1 +
 3 files changed, 13 insertions(+)
Signature · 1 line
2.53.0