Re: [paulmck-rcu:dev.2024.03.27b 66/69] include/linux/atomic/atomic-arch-fallback.h:2026:9: error: call to undeclared function 'cmpxchg_emu_u8'; ISO C99 and later do not support implicit function declarations

From: Paul E. McKenney
Date: Fri Mar 29 2024 - 16:55:22 EST


On Fri, Mar 29, 2024 at 11:08:05PM +0800, kernel test robot wrote:
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git dev.2024.03.27b
> head: 786fab3085d764055a78edb54023420920344333
> commit: 032d9f7e1213171131a3f45c5c532ea5d11b4b9a [66/69] riscv: Emulate one-byte and two-byte cmpxchg
> config: riscv-defconfig (https://download.01.org/0day-ci/archive/20240329/202403292322.bwguovKc-lkp@xxxxxxxxx/config)
> compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project 79ba323bdd0843275019e16b6e9b35133677c514)
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240329/202403292322.bwguovKc-lkp@xxxxxxxxx/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@xxxxxxxxx>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202403292322.bwguovKc-lkp@xxxxxxxxx/
>
> All errors (new ones prefixed by >>):
>
> In file included from arch/riscv/kernel/asm-offsets.c:10:
> In file included from include/linux/mm.h:7:
> In file included from include/linux/gfp.h:7:
> In file included from include/linux/mmzone.h:8:
> In file included from include/linux/spinlock.h:63:
> In file included from include/linux/lockdep.h:14:
> In file included from include/linux/smp.h:13:
> In file included from include/linux/cpumask.h:14:
> In file included from include/linux/atomic.h:80:
> >> include/linux/atomic/atomic-arch-fallback.h:2026:9: error: call to undeclared function 'cmpxchg_emu_u8'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
> 2026 | return raw_cmpxchg(&v->counter, old, new);
> | ^
> include/linux/atomic/atomic-arch-fallback.h:55:21: note: expanded from macro 'raw_cmpxchg'
> 55 | #define raw_cmpxchg arch_cmpxchg
> | ^
> arch/riscv/include/asm/cmpxchg.h:367:23: note: expanded from macro 'arch_cmpxchg'
> 367 | (__typeof__(*(ptr))) __cmpxchg((ptr), \
> | ^
> arch/riscv/include/asm/cmpxchg.h:328:11: note: expanded from macro '__cmpxchg'
> 328 | __ret = cmpxchg_emu_u8((volatile u8 *)__ptr, __old, __new); \
> | ^

Again, good catch! And again, does the diff at the end of this email
fix things for you?

Thanx, Paul

> In file included from arch/riscv/kernel/asm-offsets.c:10:
> In file included from include/linux/mm.h:7:
> In file included from include/linux/gfp.h:7:
> In file included from include/linux/mmzone.h:8:
> In file included from include/linux/spinlock.h:63:
> In file included from include/linux/lockdep.h:14:
> In file included from include/linux/smp.h:13:
> In file included from include/linux/cpumask.h:14:
> In file included from include/linux/atomic.h:80:
> >> include/linux/atomic/atomic-arch-fallback.h:2026:9: error: call to undeclared function 'cmpxchg_emu_u16'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
> include/linux/atomic/atomic-arch-fallback.h:55:21: note: expanded from macro 'raw_cmpxchg'
> 55 | #define raw_cmpxchg arch_cmpxchg
> | ^
> arch/riscv/include/asm/cmpxchg.h:367:23: note: expanded from macro 'arch_cmpxchg'
> 367 | (__typeof__(*(ptr))) __cmpxchg((ptr), \
> | ^
> arch/riscv/include/asm/cmpxchg.h:332:11: note: expanded from macro '__cmpxchg'
> 332 | __ret = cmpxchg_emu_u16((volatile u16 *)__ptr, __old, __new); \
> | ^
> In file included from arch/riscv/kernel/asm-offsets.c:10:
> In file included from include/linux/mm.h:7:
> In file included from include/linux/gfp.h:7:
> In file included from include/linux/mmzone.h:8:
> In file included from include/linux/spinlock.h:63:
> In file included from include/linux/lockdep.h:14:
> In file included from include/linux/smp.h:13:
> In file included from include/linux/cpumask.h:14:
> In file included from include/linux/atomic.h:80:
> include/linux/atomic/atomic-arch-fallback.h:2055:9: error: call to undeclared function 'cmpxchg_emu_u8'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
> 2055 | return raw_cmpxchg_acquire(&v->counter, old, new);
> | ^
> include/linux/atomic/atomic-arch-fallback.h:65:29: note: expanded from macro 'raw_cmpxchg_acquire'
> 65 | #define raw_cmpxchg_acquire arch_cmpxchg_acquire
> | ^
> arch/riscv/include/asm/cmpxchg.h:263:23: note: expanded from macro 'arch_cmpxchg_acquire'
> 263 | (__typeof__(*(ptr))) __cmpxchg_acquire((ptr), \
> | ^
> arch/riscv/include/asm/cmpxchg.h:224:11: note: expanded from macro '__cmpxchg_acquire'
> 224 | __ret = cmpxchg_emu_u8((volatile u8 *)__ptr, __old, __new); \
> | ^
> In file included from arch/riscv/kernel/asm-offsets.c:10:
> In file included from include/linux/mm.h:7:
> In file included from include/linux/gfp.h:7:
> In file included from include/linux/mmzone.h:8:
> In file included from include/linux/spinlock.h:63:
> In file included from include/linux/lockdep.h:14:
> In file included from include/linux/smp.h:13:
> In file included from include/linux/cpumask.h:14:
> In file included from include/linux/atomic.h:80:
> include/linux/atomic/atomic-arch-fallback.h:2055:9: error: call to undeclared function 'cmpxchg_emu_u16'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
> include/linux/atomic/atomic-arch-fallback.h:65:29: note: expanded from macro 'raw_cmpxchg_acquire'
> 65 | #define raw_cmpxchg_acquire arch_cmpxchg_acquire
> | ^
> arch/riscv/include/asm/cmpxchg.h:263:23: note: expanded from macro 'arch_cmpxchg_acquire'
> 263 | (__typeof__(*(ptr))) __cmpxchg_acquire((ptr), \
> | ^
> arch/riscv/include/asm/cmpxchg.h:228:11: note: expanded from macro '__cmpxchg_acquire'
> 228 | __ret = cmpxchg_emu_u16((volatile u16 *)__ptr, __old, __new); \
> | ^
> In file included from arch/riscv/kernel/asm-offsets.c:10:
> In file included from include/linux/mm.h:7:
> In file included from include/linux/gfp.h:7:
> In file included from include/linux/mmzone.h:8:
> In file included from include/linux/spinlock.h:63:
> In file included from include/linux/lockdep.h:14:
> In file included from include/linux/smp.h:13:
> In file included from include/linux/cpumask.h:14:
> In file included from include/linux/atomic.h:80:
> include/linux/atomic/atomic-arch-fallback.h:2083:9: error: call to undeclared function 'cmpxchg_emu_u8'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
> 2083 | return raw_cmpxchg_release(&v->counter, old, new);
> | ^
> include/linux/atomic/atomic-arch-fallback.h:77:29: note: expanded from macro 'raw_cmpxchg_release'
> 77 | #define raw_cmpxchg_release arch_cmpxchg_release
> | ^
> arch/riscv/include/asm/cmpxchg.h:315:23: note: expanded from macro 'arch_cmpxchg_release'
> 315 | (__typeof__(*(ptr))) __cmpxchg_release((ptr), \
> | ^
> arch/riscv/include/asm/cmpxchg.h:276:11: note: expanded from macro '__cmpxchg_release'
> 276 | __ret = cmpxchg_emu_u8((volatile u8 *)__ptr, __old, __new); \
> | ^
> In file included from arch/riscv/kernel/asm-offsets.c:10:
> In file included from include/linux/mm.h:7:
> In file included from include/linux/gfp.h:7:
> In file included from include/linux/mmzone.h:8:
> In file included from include/linux/spinlock.h:63:
> In file included from include/linux/lockdep.h:14:
> In file included from include/linux/smp.h:13:
> In file included from include/linux/cpumask.h:14:
> In file included from include/linux/atomic.h:80:
> include/linux/atomic/atomic-arch-fallback.h:2083:9: error: call to undeclared function 'cmpxchg_emu_u16'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
> include/linux/atomic/atomic-arch-fallback.h:77:29: note: expanded from macro 'raw_cmpxchg_release'
> 77 | #define raw_cmpxchg_release arch_cmpxchg_release
> | ^
> arch/riscv/include/asm/cmpxchg.h:315:23: note: expanded from macro 'arch_cmpxchg_release'
> 315 | (__typeof__(*(ptr))) __cmpxchg_release((ptr), \
> | ^
> arch/riscv/include/asm/cmpxchg.h:280:11: note: expanded from macro '__cmpxchg_release'
> 280 | __ret = cmpxchg_emu_u16((volatile u16 *)__ptr, __old, __new); \
> | ^
> In file included from arch/riscv/kernel/asm-offsets.c:10:
> In file included from include/linux/mm.h:7:
> In file included from include/linux/gfp.h:7:
> In file included from include/linux/mmzone.h:8:
> In file included from include/linux/spinlock.h:63:
> In file included from include/linux/lockdep.h:14:
> In file included from include/linux/smp.h:13:
> In file included from include/linux/cpumask.h:14:
> In file included from include/linux/atomic.h:80:
> include/linux/atomic/atomic-arch-fallback.h:2108:9: error: call to undeclared function 'cmpxchg_emu_u8'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
> 2108 | return raw_cmpxchg_relaxed(&v->counter, old, new);
>
>
> vim +/cmpxchg_emu_u8 +2026 include/linux/atomic/atomic-arch-fallback.h
>
> 37f8173dd84936 include/linux/atomic-arch-fallback.h Peter Zijlstra 2020-01-24 2000
> ad8110706f3811 include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2001 /**
> ad8110706f3811 include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2002 * raw_atomic_cmpxchg() - atomic compare and exchange with full ordering
> ad8110706f3811 include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2003 * @v: pointer to atomic_t
> ad8110706f3811 include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2004 * @old: int value to compare with
> ad8110706f3811 include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2005 * @new: int value to assign
> ad8110706f3811 include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2006 *
> ad8110706f3811 include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2007 * If (@v == @old), atomically updates @v to @new with full ordering.
> 6dfee110c6cc7a include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2024-02-09 2008 * Otherwise, @v is not modified and relaxed ordering is provided.
> ad8110706f3811 include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2009 *
> ad8110706f3811 include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2010 * Safe to use in noinstr code; prefer atomic_cmpxchg() elsewhere.
> ad8110706f3811 include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2011 *
> ad8110706f3811 include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2012 * Return: The original value of @v.
> ad8110706f3811 include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2013 */
> 37f8173dd84936 include/linux/atomic-arch-fallback.h Peter Zijlstra 2020-01-24 2014 static __always_inline int
> 9257959a6e5b4f include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2015 raw_atomic_cmpxchg(atomic_t *v, int old, int new)
> 37f8173dd84936 include/linux/atomic-arch-fallback.h Peter Zijlstra 2020-01-24 2016 {
> 1d78814d41701c include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2017 #if defined(arch_atomic_cmpxchg)
> 1d78814d41701c include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2018 return arch_atomic_cmpxchg(v, old, new);
> 1d78814d41701c include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2019 #elif defined(arch_atomic_cmpxchg_relaxed)
> 37f8173dd84936 include/linux/atomic-arch-fallback.h Peter Zijlstra 2020-01-24 2020 int ret;
> 37f8173dd84936 include/linux/atomic-arch-fallback.h Peter Zijlstra 2020-01-24 2021 __atomic_pre_full_fence();
> 9257959a6e5b4f include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2022 ret = arch_atomic_cmpxchg_relaxed(v, old, new);
> 37f8173dd84936 include/linux/atomic-arch-fallback.h Peter Zijlstra 2020-01-24 2023 __atomic_post_full_fence();
> 37f8173dd84936 include/linux/atomic-arch-fallback.h Peter Zijlstra 2020-01-24 2024 return ret;
> 9257959a6e5b4f include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2025 #else
> 9257959a6e5b4f include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 @2026 return raw_cmpxchg(&v->counter, old, new);
> d12157efc8e083 include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2027 #endif
> 1d78814d41701c include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2028 }
> d12157efc8e083 include/linux/atomic/atomic-arch-fallback.h Mark Rutland 2023-06-05 2029
>
> :::::: The code at line 2026 was first introduced by commit
> :::::: 9257959a6e5b4fca6fc8e985790bff62c2046f20 locking/atomic: scripts: restructure fallback ifdeffery
>
> :::::: TO: Mark Rutland <mark.rutland@xxxxxxx>
> :::::: CC: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
>
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki

commit da6c6c7a30e5a5015a2995b2119053ca3d12b7a2
Author: Paul E. McKenney <paulmck@xxxxxxxxxx>
Date: Fri Mar 29 11:50:32 2024 -0700

squash! riscv: Emulate one-byte and two-byte cmpxchg

[ paulmck: Apply kernel test robot feedback. ]

Signed-off-by: Paul E. McKenney <paulmck@xxxxxxxxxx>

diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h
index b4cbea69ad2c8..a5b377481785c 100644
--- a/arch/riscv/include/asm/cmpxchg.h
+++ b/arch/riscv/include/asm/cmpxchg.h
@@ -9,6 +9,7 @@
#include <linux/bug.h>

#include <asm/fence.h>
+#include <linux/cmpxchg-emu.h>

#define __xchg_relaxed(ptr, new, size) \
({ \