diff mbox series

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

Message ID 20261005120700.383058-4-brads@mainlining.org
State New
Headers show
Series Add two-byte cmpxchg emulation and wire it into the architectures | expand

Commit Message

Bradley Morgan Oct. 5, 2026, 12:07 p.m. UTC
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.

Signed-off-by: Bradley Morgan <brads@mainlining.org>
---
 arch/xtensa/include/asm/cmpxchg.h | 1 +
 1 file changed, 1 insertion(+)

Comments

kernel test robot Oct. 6, 2026, 9:54 a.m. UTC | #1
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/202610061704.rvbolgPy-lkp@intel.com/config)
compiler: xtensa-linux-gcc (GCC) 16.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261006/202610061704.rvbolgPy-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202610061704.rvbolgPy-lkp@intel.com/

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
Paul E. McKenney Oct. 6, 2026, 3:44 p.m. UTC | #2
On Tue, Oct 06, 2026 at 05:54:53PM +0800, kernel test robot wrote:
> 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/202610061704.rvbolgPy-lkp@intel.com/config)
> compiler: xtensa-linux-gcc (GCC) 16.1.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261006/202610061704.rvbolgPy-lkp@intel.com/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 <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202610061704.rvbolgPy-lkp@intel.com/
> 
> 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

>    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
Bradley Morgan Oct. 6, 2026, 3:46 p.m. UTC | #3
On 6 October 2026 16:44:13 BST, "Paul E. McKenney" <paulmck@kernel.org>
wrote:
>On Tue, Oct 06, 2026 at 05:54:53PM +0800, kernel test robot wrote:
>> 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/202610061704.rvbolgPy-lkp@intel.com/config)
>> compiler: xtensa-linux-gcc (GCC) 16.1.0
>> reproduce (this is a W=1 build):
>(https://download.01.org/0day-ci/archive/20261006/202610061704.rvbolgPy-lkp@intel.com/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 <lkp@intel.com>
>> | Closes:
>https://lore.kernel.org/oe-kbuild-all/202610061704.rvbolgPy-lkp@intel.com/
>> 
>> 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, 

>
>							Thanx, Paul
>
>>    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

--- Thanks!
"I'm not a very positive person" - Linus torvalds
Paul E. McKenney Oct. 6, 2026, 4:10 p.m. UTC | #4
On Tue, Oct 06, 2026 at 04:46:22PM +0100, Bradley Morgan wrote:
> On 6 October 2026 16:44:13 BST, "Paul E. McKenney" <paulmck@kernel.org>
> wrote:
> >On Tue, Oct 06, 2026 at 05:54:53PM +0800, kernel test robot wrote:
> >> 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/202610061704.rvbolgPy-lkp@intel.com/config)
> >> compiler: xtensa-linux-gcc (GCC) 16.1.0
> >> reproduce (this is a W=1 build):
> >(https://download.01.org/0day-ci/archive/20261006/202610061704.rvbolgPy-lkp@intel.com/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 <lkp@intel.com>
> >> | Closes:
> >https://lore.kernel.org/oe-kbuild-all/202610061704.rvbolgPy-lkp@intel.com/
> >> 
> >> 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, 

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

> >>    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
> 
> --- Thanks!
> "I'm not a very positive person" - Linus torvalds
Vineet Gupta Oct. 7, 2026, 8:24 a.m. UTC | #5
On 10/6/26 17:44, Paul E. McKenney wrote:
> 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
Vineet Gupta Oct. 7, 2026, 8:26 a.m. UTC | #6
On 10/6/26 17:46, Bradley Morgan wrote:
> 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
Paul E. McKenney Oct. 7, 2026, 3:56 p.m. UTC | #7
On Wed, Oct 07, 2026 at 10:24:28AM +0200, Vineet Gupta wrote:
> On 10/6/26 17:44, Paul E. McKenney wrote:
> > 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
diff mbox series

Patch

diff --git a/arch/xtensa/include/asm/cmpxchg.h b/arch/xtensa/include/asm/cmpxchg.h
index b6db4838b175..8dea8e357fc0 100644
--- a/arch/xtensa/include/asm/cmpxchg.h
+++ b/arch/xtensa/include/asm/cmpxchg.h
@@ -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;