Re: [PATCH] locking/atomic: sh: Use generic_cmpxchg_local for arch_cmpxchg_local()
From: "wuqiang.matt" <wuqiang.matt@bytedance.com>
Date: 2023-10-25 01:51:58
Also in:
linux-sh, lkml
On 2023/10/25 07:42, Masami Hiramatsu (Google) wrote:
On Tue, 24 Oct 2023 16:08:12 +0100 Mark Rutland [off-list ref] wrote:quoted
On Tue, Oct 24, 2023 at 11:52:54PM +0900, Masami Hiramatsu (Google) wrote:quoted
From: Masami Hiramatsu (Google) <mhiramat@kernel.org> Use generic_cmpxchg_local() for arch_cmpxchg_local() implementation in SH architecture because it does not implement arch_cmpxchg_local().I do not think this is correct. The implementation in <asm-generic/cmpxchg-local.h> is UP-only (and it only disables interrupts), whereas arch/sh can be built SMP. We should probably add some guards into <asm-generic/cmpxchg-local.h> for that as we have in <asm-generic/cmpxchg.h>.Isn't cmpxchg_local for the data which only needs to ensure to do cmpxchg on local CPU?
asm-generic/cmpxchg.h is only for UP, will throw an error for SMP building: #ifdef CONFIG_SMP #error "Cannot use generic cmpxchg on SMP" #endif SH arch seems it does have SMP systems. The arch/sh/include/asm/cmpxchg.h has the following codes: #if defined(CONFIG_GUSA_RB) #include <asm/cmpxchg-grb.h> #elif defined(CONFIG_CPU_SH4A) #include <asm/cmpxchg-llsc.h> #elif defined(CONFIG_CPU_J2) && defined(CONFIG_SMP) #include <asm/cmpxchg-cas.h> #else #include <asm/cmpxchg-irq.h> #endif
So I think it doesn't care about the other CPUs (IOW, it should not touched by other CPUs), so it only considers UP case. E.g. on x86, arch_cmpxchg_local() is defined as raw "cmpxchg" without lock prefix. #define __cmpxchg_local(ptr, old, new, size) \ __raw_cmpxchg((ptr), (old), (new), (size), "") Thank you,quoted
I think the right thing to do here is to define arch_cmpxchg_local() in terms of arch_cmpxchg(), i.e. at the bottom of arch/sh's <asm/cmpxchg.h> add: #define arch_cmpxchg_local arch_cmpxchg
I agree too. Might not be performance optimized but guarantees correctness.
quoted
Mark.quoted
Reported-by: kernel test robot <redacted> Closes: https://lore.kernel.org/oe-kbuild-all/202310241310.Ir5uukOG-lkp@intel.com/ (local) Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.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 288f6f38d98f..e920e61fb817 100644 --- a/arch/sh/include/asm/cmpxchg.h +++ b/arch/sh/include/asm/cmpxchg.h@@ -71,4 +71,6 @@ static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old, (unsigned long)_n_, sizeof(*(ptr))); \ }) +#include <asm-generic/cmpxchg-local.h> + #endif /* __ASM_SH_CMPXCHG_H */