From nobody Thu Feb 12 03:02:25 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 117F954BDB; Mon, 1 Apr 2024 21:39:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712007592; cv=none; b=VslnTrjctxZp0YWXgO84JHSU0fLe8LMbH1Kre6TqxvmEiKjmIgKGaxq7ZAwLWixGeCnWNljmoVODuD3zDHXcPy5OOfS6VaiTBkofza4Hg33HnT54CKrGfQ29g3OMC1U5kHdSicsl1KoHdgl8TDkairoGFmGCBTqLz9jZB3QnJ9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712007592; c=relaxed/simple; bh=c9GjA7u0Ah+LPIGy6CuP6SHZiXz0K6ltKvEILVHzc/8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=L6mlEtggAk1+16GdaEOb5xBqfciAUURVGz0htUBM27BLw12t6sB6gQ6zV4dzIKhiXosPutfHNZFH1GBIsh2lebNHkK4hmBOUKogsDt8reMDJZYEKiKMzq74615kdStaSZfsRdbDexxucEpMKQa1WO8Zd4qnb92P8GL11MDKPE6E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FPx7qALc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FPx7qALc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 884C3C433C7; Mon, 1 Apr 2024 21:39:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712007591; bh=c9GjA7u0Ah+LPIGy6CuP6SHZiXz0K6ltKvEILVHzc/8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FPx7qALcCOxvTnvEAcA3+dk6h1GB5Tnoxoecgz0uRzekeKZe766+kQZ2Z8Ca5IW1x kmJOvZP/anIHmtsEQ7xEPET9CdARoFdDFRxI4MfannlBA1Mt3PJCJbKb8cslrK8vTa DeGdwO6TTWr9EQ6MnutEVztHHC1GI8ZK6V5V5M/ms+1lTDmr2ucS7XXrP+OqS5zv+J NHr55wA3dE2xFD7IiWXjroW6WIXLX7KgpMlJJrU9SOrKHwxFQrA7oAjXhEnJsuKii9 j7/N+SNoeVo8X9T4rvkPXezLa7VsDu31wG5ddhr1D8qF7uzzbhVUC7FE4BjnMfYuK0 bO4ILXDXEnRFw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 3EF4FCE0738; Mon, 1 Apr 2024 14:39:51 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: kernel-team@meta.com, "Paul E. McKenney" , Marco Elver , Andrew Morton , Thomas Gleixner , "Peter Zijlstra (Intel)" , Douglas Anderson , Petr Mladek , linux-arch@vger.kernel.org Subject: [PATCH RFC cmpxchg 1/8] lib: Add one-byte and two-byte cmpxchg() emulation functions Date: Mon, 1 Apr 2024 14:39:43 -0700 Message-Id: <20240401213950.3910531-1-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <31c82dcc-e203-48a9-aadd-f2fcd57d94c1@paulmck-laptop> References: <31c82dcc-e203-48a9-aadd-f2fcd57d94c1@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Architectures are required to provide four-byte cmpxchg() and 64-bit architectures are additionally required to provide eight-byte cmpxchg(). However, there are cases where one-byte and two-byte cmpxchg() would be extremely useful. Therefore, provide cmpxchg_emu_u8() and cmpxchg_emu_u16() that emulate one-byte and two-byte cmpxchg() in terms of four-byte cmpxchg(). Note that these emulations are fully ordered, and can (for example) cause one-byte cmpxchg_relaxed() to incur the overhead of full ordering. If this causes problems for a given architecture, that architecture is free to provide its own lighter-weight primitives. [ paulmck: Apply Marco Elver feedback. ] [ paulmck: Apply kernel test robot feedback. ] Link: https://lore.kernel.org/all/0733eb10-5e7a-4450-9b8a-527b97c842ff@paul= mck-laptop/ Signed-off-by: Paul E. McKenney Cc: Marco Elver Cc: Andrew Morton Cc: Thomas Gleixner Cc: "Peter Zijlstra (Intel)" Cc: Douglas Anderson Cc: Petr Mladek Cc: Acked-by: Marco Elver --- arch/Kconfig | 3 ++ include/linux/cmpxchg-emu.h | 16 ++++++++ lib/Makefile | 1 + lib/cmpxchg-emu.c | 74 +++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 include/linux/cmpxchg-emu.h create mode 100644 lib/cmpxchg-emu.c diff --git a/arch/Kconfig b/arch/Kconfig index ae4a4f37bbf08..01093c60952a5 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1609,4 +1609,7 @@ config CC_HAS_SANE_FUNCTION_ALIGNMENT # strict alignment always, even with -falign-functions. def_bool CC_HAS_MIN_FUNCTION_ALIGNMENT || CC_IS_CLANG =20 +config ARCH_NEED_CMPXCHG_1_2_EMU + bool + endmenu diff --git a/include/linux/cmpxchg-emu.h b/include/linux/cmpxchg-emu.h new file mode 100644 index 0000000000000..fee8171fa05eb --- /dev/null +++ b/include/linux/cmpxchg-emu.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Emulated 1-byte and 2-byte cmpxchg operations for architectures + * lacking direct support for these sizes. These are implemented in terms + * of 4-byte cmpxchg operations. + * + * Copyright (C) 2024 Paul E. McKenney. + */ + +#ifndef __LINUX_CMPXCHG_EMU_H +#define __LINUX_CMPXCHG_EMU_H + +uintptr_t cmpxchg_emu_u8(volatile u8 *p, uintptr_t old, uintptr_t new); +uintptr_t cmpxchg_emu_u16(volatile u16 *p, uintptr_t old, uintptr_t new); + +#endif /* __LINUX_CMPXCHG_EMU_H */ diff --git a/lib/Makefile b/lib/Makefile index ffc6b2341b45a..1d93b61a7ecbe 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -236,6 +236,7 @@ obj-$(CONFIG_FUNCTION_ERROR_INJECTION) +=3D error-injec= t.o lib-$(CONFIG_GENERIC_BUG) +=3D bug.o =20 obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) +=3D syscall.o +obj-$(CONFIG_ARCH_NEED_CMPXCHG_1_2_EMU) +=3D cmpxchg-emu.o =20 obj-$(CONFIG_DYNAMIC_DEBUG_CORE) +=3D dynamic_debug.o #ensure exported functions have prototypes diff --git a/lib/cmpxchg-emu.c b/lib/cmpxchg-emu.c new file mode 100644 index 0000000000000..a88c4f3c88430 --- /dev/null +++ b/lib/cmpxchg-emu.c @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Emulated 1-byte and 2-byte cmpxchg operations for architectures + * lacking direct support for these sizes. These are implemented in terms + * of 4-byte cmpxchg operations. + * + * Copyright (C) 2024 Paul E. McKenney. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +union u8_32 { + u8 b[4]; + u32 w; +}; + +/* Emulate one-byte cmpxchg() in terms of 4-byte cmpxchg. */ +uintptr_t cmpxchg_emu_u8(volatile u8 *p, uintptr_t old, uintptr_t new) +{ + u32 *p32 =3D (u32 *)(((uintptr_t)p) & ~0x3); + int i =3D ((uintptr_t)p) & 0x3; + union u8_32 old32; + union u8_32 new32; + u32 ret; + + ret =3D READ_ONCE(*p32); + do { + old32.w =3D ret; + if (old32.b[i] !=3D old) + return old32.b[i]; + new32.w =3D old32.w; + new32.b[i] =3D new; + instrument_atomic_read_write(p, 1); + ret =3D data_race(cmpxchg(p32, old32.w, new32.w)); + } while (ret !=3D old32.w); + return old; +} +EXPORT_SYMBOL_GPL(cmpxchg_emu_u8); + +union u16_32 { + u16 h[2]; + u32 w; +}; + +/* Emulate two-byte cmpxchg() in terms of 4-byte cmpxchg. */ +uintptr_t cmpxchg_emu_u16(volatile u16 *p, uintptr_t old, uintptr_t new) +{ + u32 *p32 =3D (u32 *)(((uintptr_t)p) & ~0x3); + int i =3D (((uintptr_t)p) & 0x2) / 2; + union u16_32 old32; + union u16_32 new32; + u32 ret; + + WARN_ON_ONCE(((uintptr_t)p) & 0x1); + ret =3D READ_ONCE(*p32); + do { + old32.w =3D ret; + if (old32.h[i] !=3D old) + return old32.h[i]; + new32.w =3D old32.w; + new32.h[i] =3D new; + instrument_atomic_read_write(p, 2); + ret =3D data_race(cmpxchg(p32, old32.w, new32.w)); + } while (ret !=3D old32.w); + return old; +} +EXPORT_SYMBOL_GPL(cmpxchg_emu_u16); --=20 2.40.1 From nobody Thu Feb 12 03:02:25 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7458955E6A for ; Mon, 1 Apr 2024 21:39:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712007595; cv=none; b=CYGKy9BbbdI0tSqkf/n29zFahdKOvfT3CMZ2YrHSFOa6A91PxmLeB2XcbsNsLgQjpcbfFCF9l/nksU8XQgvSWHen41KKd7GFsRRYAyO+MmKFryv9Q2vfgxNKI/jL5ApfwRBI6/UwIc5G1eIKF/GXrTCdBpzrC8IHPehXgspV5Rk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712007595; c=relaxed/simple; bh=aFyRkJsj1cSeFgIbVoEnc7fhPQM9ciACtkQV40joVhY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=N+IdY+B4H31X3gQ5SNBP7ihqX2gZDB9bqnW2dgaQIznI2dJP11nlQjhB1WITRN2e2cgRUixFgSbbApIVPbuFAmfLyx0HXPU1LCgGgGMGmcFIhSihA7jaB/c7gZfEkyCvkZ3HNWHOLNtDnOXsKYcTnwS+eBnvk2aiHd0JJmC3Ikk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=smYGcuS9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="smYGcuS9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DD85C43390; Mon, 1 Apr 2024 21:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712007595; bh=aFyRkJsj1cSeFgIbVoEnc7fhPQM9ciACtkQV40joVhY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=smYGcuS9pi8XHbtH4nZHtbho9hbNdPpGE1mOA7kUMwobaW0uM++mcAGgm+P/usgkq a788LGBT+7a195WexMII81p/90C/oN2aYkzjedHdB6BKlYem2KnhOrqa6m3k687ahY jlRCnVOfIcFFuUeMc4xjXBit6+AAauyZ9sPi5wypxV0yj6iJajuQfgOsPILUyTX2uL +DXlCVlWCdRdkTosHxT0n/N46f/HIuk2s0OxtbI538hMAKP2rk9ZAqc+5GrAjK7uAC oNB/79nOUn9igu7YnO8HsrGWyHLPwPOYbl1BT7bXJY0+iS5LovRLDUE2V3FatZuQ4G C4FjgEZ9Yaanw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id BD290CE0738; Mon, 1 Apr 2024 14:39:54 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: kernel-team@meta.com, "Paul E. McKenney" , "David S. Miller" , Andreas Larsson , Palmer Dabbelt , Arnd Bergmann , Marco Elver Subject: [PATCH RFC cmpxchg 2/8] sparc: Emulate one-byte and two-byte cmpxchg Date: Mon, 1 Apr 2024 14:39:44 -0700 Message-Id: <20240401213950.3910531-2-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <31c82dcc-e203-48a9-aadd-f2fcd57d94c1@paulmck-laptop> References: <31c82dcc-e203-48a9-aadd-f2fcd57d94c1@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the new cmpxchg_emu_u8() and cmpxchg_emu_u16() to emulate one-byte and two-byte cmpxchg() on 32-bit sparc. Signed-off-by: Paul E. McKenney Cc: "David S. Miller" Cc: Andreas Larsson Cc: Palmer Dabbelt Cc: Arnd Bergmann Cc: Marco Elver --- arch/sparc/Kconfig | 1 + arch/sparc/include/asm/cmpxchg_32.h | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig index 11bf9d312318c..e6d1bbc4fedd0 100644 --- a/arch/sparc/Kconfig +++ b/arch/sparc/Kconfig @@ -55,6 +55,7 @@ config SPARC32 select ARCH_32BIT_OFF_T select ARCH_HAS_CPU_FINALIZE_INIT if !SMP select ARCH_HAS_SYNC_DMA_FOR_CPU + select ARCH_NEED_CMPXCHG_1_2_EMU select CLZ_TAB select DMA_DIRECT_REMAP select GENERIC_ATOMIC64 diff --git a/arch/sparc/include/asm/cmpxchg_32.h b/arch/sparc/include/asm/c= mpxchg_32.h index d0af82c240b73..8eb483b5887a1 100644 --- a/arch/sparc/include/asm/cmpxchg_32.h +++ b/arch/sparc/include/asm/cmpxchg_32.h @@ -41,11 +41,17 @@ void __cmpxchg_called_with_bad_pointer(void); /* we only need to support cmpxchg of a u32 on sparc */ unsigned long __cmpxchg_u32(volatile u32 *m, u32 old, u32 new_); =20 +#include + /* don't worry...optimizer will get rid of most of this */ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new_, int s= ize) { switch (size) { + case 1: + return cmpxchg_emu_u8((volatile u8 *)ptr, old, new_); + case 2: + return cmpxchg_emu_u16((volatile u16 *)ptr, old, new_); case 4: return __cmpxchg_u32((u32 *)ptr, (u32)old, (u32)new_); default: --=20 2.40.1 From nobody Thu Feb 12 03:02:25 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7455A55E4F for ; Mon, 1 Apr 2024 21:39:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712007595; cv=none; b=JPIDxQbB9wF1YoQsfnsCY2vAZIVk3laPvUYllXZaXAPfZiCYCJWaRMFC5XSsnWxh+UVPnDoiIggvQDlx2QsfWKiPWznA/86pt2qgA3TypEP8GCOQButLQFmjg2TqIctW8jDkNVmSFMD7QEvIuWzWLqcKNZF9rmjEXzHUHRpN0yI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712007595; c=relaxed/simple; bh=V+BpmS0L5AY0NVsYdTSBQxe6rtRi97k3MCIt6y0ESdA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FLSLU5iWZRGga4pBtPVpYME9Synqan9D2iL4G1GNolx7JvzujSbsBQl/6gMZd9EO+erbImA0dbj9RJtlGPebT6UXB+2ctcNyAVcYBhQAeSIaIgcVhZwF4vK8iqkZONIIaXAezLCVo4rrKFcjsHUZ7HWdwoyP+xv1ganvyjOkAO8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=t6SR+duR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="t6SR+duR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1EE32C43394; Mon, 1 Apr 2024 21:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712007595; bh=V+BpmS0L5AY0NVsYdTSBQxe6rtRi97k3MCIt6y0ESdA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t6SR+duRyz91MSUJd6aDkPfhqtTUYz+BtdhwHcEwrjvBL3wMl3HTDfuq2dc5KxMs9 VbR0s4/x47BOzkstNFYga3IECVzsunTnepncGio7T7V5OQvbxe3y0O6Xu0PCcrGim4 xpM/LUutYwScLWvyOogZlV1s33uThDYjSz0nTsA76EG3QmRAVJXpVPhpWLkriWfrxf 9AE7YODRHtPCaVjNm2kjP3rWTjKCd9gdyAJbYSqMO+FybJLaCoxTshEq0U260FZFmJ uJ2D9qIfonNIAfSanKTkTyz8TSsf+ihOmImDZyIkJ7rWxapRNK22bfPuP1v1Bd5lyI NYNdUxyKkdA/w== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C0299CE074C; Mon, 1 Apr 2024 14:39:54 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: kernel-team@meta.com, "Paul E. McKenney" , Vineet Gupta , Andi Shyti , Andrzej Hajda , Arnd Bergmann , Palmer Dabbelt , linux-snps-arc@lists.infradead.org Subject: [PATCH RFC cmpxchg 3/8] ARC: Emulate one-byte and two-byte cmpxchg Date: Mon, 1 Apr 2024 14:39:45 -0700 Message-Id: <20240401213950.3910531-3-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <31c82dcc-e203-48a9-aadd-f2fcd57d94c1@paulmck-laptop> References: <31c82dcc-e203-48a9-aadd-f2fcd57d94c1@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the new cmpxchg_emu_u8() and cmpxchg_emu_u16() to emulate one-byte and two-byte cmpxchg() on arc. Signed-off-by: Paul E. McKenney Cc: Vineet Gupta Cc: Andi Shyti Cc: Andrzej Hajda Cc: Arnd Bergmann Cc: Palmer Dabbelt Cc: --- arch/arc/Kconfig | 1 + arch/arc/include/asm/cmpxchg.h | 38 ++++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig index 99d2845f3feb9..0b40039f38eb2 100644 --- a/arch/arc/Kconfig +++ b/arch/arc/Kconfig @@ -14,6 +14,7 @@ config ARC select ARCH_HAS_SETUP_DMA_OPS select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE + select ARCH_NEED_CMPXCHG_1_2_EMU select ARCH_SUPPORTS_ATOMIC_RMW if ARC_HAS_LLSC select ARCH_32BIT_OFF_T select BUILDTIME_TABLE_SORT diff --git a/arch/arc/include/asm/cmpxchg.h b/arch/arc/include/asm/cmpxchg.h index e138fde067dea..1e3e23adaca13 100644 --- a/arch/arc/include/asm/cmpxchg.h +++ b/arch/arc/include/asm/cmpxchg.h @@ -46,6 +46,12 @@ __typeof__(*(ptr)) _prev_; \ \ switch(sizeof((_p_))) { \ + case 1: \ + _prev_ =3D cmpxchg_emu_u8((volatile u8 *)_p_, _o_, _n_); \ + break; \ + case 2: \ + _prev_ =3D cmpxchg_emu_u16((volatile u16 *)_p_, _o_, _n_); \ + break; \ case 4: \ _prev_ =3D __cmpxchg(_p_, _o_, _n_); \ break; \ @@ -65,16 +71,30 @@ __typeof__(*(ptr)) _prev_; \ unsigned long __flags; \ \ - BUILD_BUG_ON(sizeof(_p_) !=3D 4); \ + switch(sizeof((_p_))) { \ + case 1: \ + __flags =3D cmpxchg_emu_u8((volatile u8 *)_p_, _o_, _n_); \ + _prev_ =3D (__typeof__(*(ptr)))__flags; \ + break; \ + case 2: \ + __flags =3D cmpxchg_emu_u16((volatile u16 *)_p_, _o_, _n_); \ + _prev_ =3D (__typeof__(*(ptr)))__flags; \ + break; \ + case 4: \ + /* \ + * spin lock/unlock provide the needed smp_mb() \ + * before/after \ + */ \ + atomic_ops_lock(__flags); \ + _prev_ =3D *_p_; \ + if (_prev_ =3D=3D _o_) \ + *_p_ =3D _n_; \ + atomic_ops_unlock(__flags); \ + break; \ + default: \ + BUILD_BUG(); \ + } \ \ - /* \ - * spin lock/unlock provide the needed smp_mb() before/after \ - */ \ - atomic_ops_lock(__flags); \ - _prev_ =3D *_p_; \ - if (_prev_ =3D=3D _o_) \ - *_p_ =3D _n_; \ - atomic_ops_unlock(__flags); \ _prev_; \ }) =20 --=20 2.40.1 From nobody Thu Feb 12 03:02:25 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 745B955E72; Mon, 1 Apr 2024 21:39:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712007595; cv=none; b=ungtlxZyvHacu++csu1pdGWk/Z8WfbJG4isW1LYDkBGvYgbVN3WYL4SSnVJhn2YqpnVRocpBwCnTixmvVKKY6+xh9BOSgC1HJV9Y1vah8cW7x4O1wtktkKzdan3BFeXevtKyVjiViBAWpOSEoOfktSa6+W6URgl0K4ucSNIlVBs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712007595; c=relaxed/simple; bh=ZGz86/tSVAGS9mMQah03h/TzE5FSFLZz3YJL1al/ZP0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WhgMA4EWJvtTfFi7h3ayCFykUPbIMaVASAuuNdU9/+kqmM2IxZJ2aQN77yDq369S14HA2EU3IBcU2m81z5ZIFj9xUZ6U1+HAAYqlmYF6/xisRjztYIJag5FN2YJ8FI5WiKR9xSf3hwy/yPI/NfR4QvlJkENrEbEbLTf5hiDYWE4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ALYUYhl+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ALYUYhl+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2699BC433C7; Mon, 1 Apr 2024 21:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712007595; bh=ZGz86/tSVAGS9mMQah03h/TzE5FSFLZz3YJL1al/ZP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ALYUYhl+t4DM33sILtMlLhGEKvST/UP5cm8J0LAwDf9/Bkm6xQWIE8iwoktinrOLb iOY4BQXBBAc7rw68xS39P9s0VZqb1gn6Sbt/cle5KzcIslH938LBjGiI5gudH6VeqN OozUjpH+jmiWYx3FRtKGYZhB46AAIsK+K29ePAFrWWpX9ACBCXRHUfDnXbxL60+1re b6S0LI3KQDxmRqJFxFvQiFZvUcUEcRiHAGK8OcUeQSJ85joaso9fT5ZfBMhgI9mz84 R5kXXKaBktQmgMebBiD6EXkWq7rsNfl5TpPg6wqVywJLZA13bEwkRhwX0xKNm8P9mV Cej7pK0/yQ74g== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C2BACCE0B64; Mon, 1 Apr 2024 14:39:54 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: kernel-team@meta.com, "Paul E. McKenney" , Guo Ren , linux-csky@vger.kernel.org Subject: [PATCH RFC cmpxchg 4/8] csky: Emulate one-byte and two-byte cmpxchg Date: Mon, 1 Apr 2024 14:39:46 -0700 Message-Id: <20240401213950.3910531-4-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <31c82dcc-e203-48a9-aadd-f2fcd57d94c1@paulmck-laptop> References: <31c82dcc-e203-48a9-aadd-f2fcd57d94c1@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the new cmpxchg_emu_u8() and cmpxchg_emu_u16() to emulate one-byte and two-byte cmpxchg() on csky. Signed-off-by: Paul E. McKenney Cc: Guo Ren Cc: --- arch/csky/Kconfig | 1 + arch/csky/include/asm/cmpxchg.h | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/arch/csky/Kconfig b/arch/csky/Kconfig index d3ac36751ad1f..860d4e02d6295 100644 --- a/arch/csky/Kconfig +++ b/arch/csky/Kconfig @@ -37,6 +37,7 @@ config CSKY select ARCH_INLINE_SPIN_UNLOCK_BH if !PREEMPTION select ARCH_INLINE_SPIN_UNLOCK_IRQ if !PREEMPTION select ARCH_INLINE_SPIN_UNLOCK_IRQRESTORE if !PREEMPTION + select ARCH_NEED_CMPXCHG_1_2_EMU select ARCH_WANT_FRAME_POINTERS if !CPU_CK610 && $(cc-option,-mbacktrace) select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT select COMMON_CLK diff --git a/arch/csky/include/asm/cmpxchg.h b/arch/csky/include/asm/cmpxch= g.h index 916043b845f14..848a8691c5a2a 100644 --- a/arch/csky/include/asm/cmpxchg.h +++ b/arch/csky/include/asm/cmpxchg.h @@ -61,6 +61,12 @@ __typeof__(old) __old =3D (old); \ __typeof__(*(ptr)) __ret; \ switch (size) { \ + case 1: \ + __ret =3D cmpxchg_emu_u8((volatile u8 *)__ptr, __old, __new); \ + break; \ + case 2: \ + __ret =3D cmpxchg_emu_u16((volatile u16 *)__ptr, __old, __new); \ + break; \ case 4: \ asm volatile ( \ "1: ldex.w %0, (%3) \n" \ @@ -91,6 +97,12 @@ __typeof__(old) __old =3D (old); \ __typeof__(*(ptr)) __ret; \ switch (size) { \ + case 1: \ + __ret =3D cmpxchg_emu_u8((volatile u8 *)__ptr, __old, __new); \ + break; \ + case 2: \ + __ret =3D cmpxchg_emu_u16((volatile u16 *)__ptr, __old, __new); \ + break; \ case 4: \ asm volatile ( \ "1: ldex.w %0, (%3) \n" \ @@ -122,6 +134,12 @@ __typeof__(old) __old =3D (old); \ __typeof__(*(ptr)) __ret; \ switch (size) { \ + case 1: \ + __ret =3D cmpxchg_emu_u8((volatile u8 *)__ptr, __old, __new); \ + break; \ + case 2: \ + __ret =3D cmpxchg_emu_u16((volatile u16 *)__ptr, __old, __new); \ + break; \ case 4: \ asm volatile ( \ RELEASE_FENCE \ --=20 2.40.1 From nobody Thu Feb 12 03:02:25 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 536FD55C3B; Mon, 1 Apr 2024 21:39:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712007595; cv=none; b=D+WE98tjQrWbqWlfnP7aVw/g7cv7BY6x6ouiyKMSUTgMA0tezb1xAVAtZaIC2mblKd2YEMbBjFZEkqMwIWdpZT01UoTpuMkau6ff9mvr4MhHppyYEEXlMZ2rDoXkZkNUqnL13rLluT3IMVQkStRONM0LCXR5HyDRh39Q3cD+Nw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712007595; c=relaxed/simple; bh=tz6SD2Mww8E4+R0q2v0WTL1Y7yCpZZWUXYJiKBI2ETk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=m3HKvSzQV0ZdZZ7r57AjbdcOp3OTf+CcFcEuNg1GQoANi1hqGcYBBQuyPBTJwJFDjJDI0RQN9jCTrfxVNIF1HELi7uG3JWQUhqDhaoX1QeE+Py/lhDfgZCD6fw/HgTF920LktXH90qsV+66FND2N7B9AQWF8PMVTSs+rFTeMqnQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WMIuRxBF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WMIuRxBF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33564C433B2; Mon, 1 Apr 2024 21:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712007595; bh=tz6SD2Mww8E4+R0q2v0WTL1Y7yCpZZWUXYJiKBI2ETk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WMIuRxBFlQY2FUMDKIZBJYahDw6AsGLigwwGSJoFHI3fcSx1OXczvoC8b+Cbkx09r 5nr6nq0QPHlGh6eBkUbqT7dHd4Gb80oz0O7UYpF8mIOT0LNdJF3jsFll8yzEGDzwLT X2bh3/ECmqLUWCHpXsM7bNsnmqH8Le4Z2dHITr7Mo6C+Q38O/Uj7Jw0nkDOodAFq7S 3JOW9fzL8+U8BEqjPb1dGmGZop+e620ZB75mpuI/4A4LT9Xh3aGnxkjj8iLzHdFfXm tw9aB5Ob5VUIcBGkhOPBvo9fwrWulYN4suPZYqRMbz/wGRYyIsEWcyv5xFoeti3D46 WaR+F3MG11fiQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C573DCE0D0C; Mon, 1 Apr 2024 14:39:54 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: kernel-team@meta.com, "Paul E. McKenney" , Andi Shyti , Palmer Dabbelt , Masami Hiramatsu , linux-sh@vger.kernel.org Subject: [PATCH RFC cmpxchg 5/8] sh: Emulate one-byte and two-byte cmpxchg Date: Mon, 1 Apr 2024 14:39:47 -0700 Message-Id: <20240401213950.3910531-5-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <31c82dcc-e203-48a9-aadd-f2fcd57d94c1@paulmck-laptop> References: <31c82dcc-e203-48a9-aadd-f2fcd57d94c1@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the new cmpxchg_emu_u8() and cmpxchg_emu_u16() to emulate one-byte and two-byte cmpxchg() on sh. Signed-off-by: Paul E. McKenney Cc: Andi Shyti Cc: Palmer Dabbelt Cc: Masami Hiramatsu Cc: --- arch/sh/Kconfig | 1 + arch/sh/include/asm/cmpxchg.h | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig index 2ad3e29f0ebec..43a121c6ca0f3 100644 --- a/arch/sh/Kconfig +++ b/arch/sh/Kconfig @@ -16,6 +16,7 @@ config SUPERH select ARCH_HIBERNATION_POSSIBLE if MMU select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_WANT_IPC_PARSE_VERSION + select ARCH_NEED_CMPXCHG_1_2_EMU select CPU_NO_EFFICIENT_FFS select DMA_DECLARE_COHERENT select GENERIC_ATOMIC64 diff --git a/arch/sh/include/asm/cmpxchg.h b/arch/sh/include/asm/cmpxchg.h index 5d617b3ef78f7..18233cc14419e 100644 --- a/arch/sh/include/asm/cmpxchg.h +++ b/arch/sh/include/asm/cmpxchg.h @@ -56,6 +56,10 @@ static inline unsigned long __cmpxchg(volatile void * pt= r, unsigned long old, unsigned long new, int size) { switch (size) { + case 1: + return cmpxchg_emu_u8((volatile u8 *)ptr, old, new); + case 2: + return cmpxchg_emu_u16((volatile u16 *)ptr, old, new); case 4: return __cmpxchg_u32(ptr, old, new); } --=20 2.40.1 From nobody Thu Feb 12 03:02:25 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A644356457 for ; Mon, 1 Apr 2024 21:39:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712007595; cv=none; b=VG9Mj19CZHQVEKEMGi21DPhg31ROfCrsVmsM0kGXL6M4WUhjDdmAE24Cbk0fw2J0WzYCOzWAExO7P6+6+iEW04hAnY0SkbWtNGJHVZxDLfK5JyHIzmN1v+7S+tpTGAEe6fc77ui4FOSw5i/1sCfHTgV9rT7+zfP8iVv5HhbxRlI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712007595; c=relaxed/simple; bh=u5tsJRw/9iU5lxcxjKgSAWhkCKXYpp5m/rW4WPetzII=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=S1PRZ+hhJzI8gj8vN+TdnBIyZW6JcysNxbPVD3YEdc0nrjHeC0fy9iLkVqhnrnbl4RvCxEeXCmMUS2tts4i1ytzgAZFLPNtZjXlkgMVR0TY6gVC5zHjAaWEl3dkRvabYUFPSaNWg/uoKgqhx7YT50zVSkCCpUXxnX5lasqR4AHQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GUqSi9ov; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GUqSi9ov" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41EBDC4166A; Mon, 1 Apr 2024 21:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712007595; bh=u5tsJRw/9iU5lxcxjKgSAWhkCKXYpp5m/rW4WPetzII=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GUqSi9ovGCLT3X5cFF43lGOqAMk5rGSvqS7ktl/RUY0aGffLc3YH44JviREseSD23 MPUwQkrG3/WBCGGpeHIB2j4jTtAIocYhUgvzAPBPwYUnY6wM0q32zbtYbpCeL+bKQH Uy0HNXjb1U9ojXsSG8kZinow512/aaek7StZ85+vZA7l3bRJMRg201jHMrzWDZOL2o wndVDOpebwh7SUcxByrv09p1oO4JNAdwUDE0pamN+OZf9EI4W8oBrw8S+16toQ+GKF VZkZbMu+vhZ0xwWeOQVFYgZRwDY/6xbMjautEgB1jKi8aEx2brYU7oBMXRh9+USI+e 7sAlh1U47z2+A== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C7F9ACE0EE1; Mon, 1 Apr 2024 14:39:54 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: kernel-team@meta.com, "Paul E. McKenney" , Andi Shyti , Geert Uytterhoeven , Arnd Bergmann , "Peter Zijlstra (Intel)" Subject: [PATCH RFC cmpxchg 6/8] xtensa: Emulate one-byte and two-byte cmpxchg Date: Mon, 1 Apr 2024 14:39:48 -0700 Message-Id: <20240401213950.3910531-6-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <31c82dcc-e203-48a9-aadd-f2fcd57d94c1@paulmck-laptop> References: <31c82dcc-e203-48a9-aadd-f2fcd57d94c1@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the new cmpxchg_emu_u8() and cmpxchg_emu_u16() to emulate one-byte and two-byte cmpxchg() on xtensa. [ paulmck: Apply kernel test robot feedback. ] Signed-off-by: Paul E. McKenney Cc: Andi Shyti Cc: Geert Uytterhoeven Cc: Arnd Bergmann Cc: "Peter Zijlstra (Intel)" --- arch/xtensa/Kconfig | 1 + arch/xtensa/include/asm/cmpxchg.h | 3 +++ 2 files changed, 4 insertions(+) diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig index f200a4ec044e6..8131f0d75bb58 100644 --- a/arch/xtensa/Kconfig +++ b/arch/xtensa/Kconfig @@ -14,6 +14,7 @@ config XTENSA select ARCH_HAS_DMA_SET_UNCACHED if MMU select ARCH_HAS_STRNCPY_FROM_USER if !KASAN select ARCH_HAS_STRNLEN_USER + select ARCH_NEED_CMPXCHG_1_2_EMU select ARCH_USE_MEMTEST select ARCH_USE_QUEUED_RWLOCKS select ARCH_USE_QUEUED_SPINLOCKS diff --git a/arch/xtensa/include/asm/cmpxchg.h b/arch/xtensa/include/asm/cm= pxchg.h index 675a11ea8de76..a0f9a2070209b 100644 --- a/arch/xtensa/include/asm/cmpxchg.h +++ b/arch/xtensa/include/asm/cmpxchg.h @@ -15,6 +15,7 @@ =20 #include #include +#include =20 /* * cmpxchg @@ -74,6 +75,8 @@ static __inline__ unsigned long __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int si= ze) { switch (size) { + case 1: return cmpxchg_emu_u8((volatile u8 *)ptr, old, new); + case 2: return cmpxchg_emu_u16((volatile u16 *)ptr, old, new); case 4: return __cmpxchg_u32(ptr, old, new); default: __cmpxchg_called_with_bad_pointer(); return old; --=20 2.40.1 From nobody Thu Feb 12 03:02:25 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A102856451; Mon, 1 Apr 2024 21:39:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712007595; cv=none; b=OHksULmATpQ38ZWlpGbMs7O80ptkUvSsFc4v7GAgibcIEfsPzjZnOpUvcSaUX6uahYEa5kGNxz1B3vwp5spbiRMliBzYwu5P4pSu2nFIytJkIe1n69tkxelRVlTUPV1CxG7fu3dZJvzwgI78qB9BbxnGsVjYB2oFzUHehWTleIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712007595; c=relaxed/simple; bh=Pey06aLnsLIkF3gQwCE3xye5sHMsA4TvrP5HMpqUzF4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qy/lNoxwRBLHRqyrTxYWqyVcJR5U7JFZ1Wbc06L7W17h3K43bAgKCWk8W0+jnVcINkFya7xhl7XJ+hFHEpDF/oDmJZGp1Jl8lUTRk7bxgHeVP36hOEXsjJP4WR4hiJIycuLEJlOyZZ7i6m0KVeF86nUZoPZmmoUClJyf4LMkROQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GbSx1Kih; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GbSx1Kih" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71E1AC4166D; Mon, 1 Apr 2024 21:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712007595; bh=Pey06aLnsLIkF3gQwCE3xye5sHMsA4TvrP5HMpqUzF4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GbSx1KihmT9WtPJs586246mVIRQzi+qsjmxTVRaon1gmEjk0lPItmESlYh5QhC9aV Ib69kzvUKgqxWrUKS37wueAgS72+c0IG3W6VRsD8Rw0BBODDuRjhPDbhQfqZbLi5Zl JATJgrTA8tSNHW38sYwH+8Mld9eGwOElgjCvThaJFDHnxG/j+eDJuOEkTfleTqLZ4k y1QSM8JcNE9ztVxnVdm0kUWrjFqLQ0SeDzpR/S9IOhhl12uCVcUqxSkoZLGewk7ILg MLN7wp98ifSjdXgOA2VjujrSZZglP3VEzV9iw6fcTrBjlc8P17TmdKtn40qCad4c9s tbsftMN3dOLtA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id CA97BCE0FF3; Mon, 1 Apr 2024 14:39:54 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: kernel-team@meta.com, "Paul E. McKenney" , "James E.J. Bottomley" , Helge Deller , Palmer Dabbelt , Geert Uytterhoeven , Arnd Bergmann , "Peter Zijlstra (Intel)" , Andrzej Hajda , linux-parisc@vger.kernel.org Subject: [PATCH RFC cmpxchg 7/8] parisc: Emulate two-byte cmpxchg Date: Mon, 1 Apr 2024 14:39:49 -0700 Message-Id: <20240401213950.3910531-7-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <31c82dcc-e203-48a9-aadd-f2fcd57d94c1@paulmck-laptop> References: <31c82dcc-e203-48a9-aadd-f2fcd57d94c1@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the new cmpxchg_emu_u16() to emulate two-byte cmpxchg() on parisc. Signed-off-by: Paul E. McKenney Cc: "James E.J. Bottomley" Cc: Helge Deller Cc: Palmer Dabbelt Cc: Geert Uytterhoeven Cc: Arnd Bergmann Cc: "Peter Zijlstra (Intel)" Cc: Andrzej Hajda Cc: --- arch/parisc/Kconfig | 1 + arch/parisc/include/asm/cmpxchg.h | 1 + 2 files changed, 2 insertions(+) diff --git a/arch/parisc/Kconfig b/arch/parisc/Kconfig index daafeb20f9937..06f221a3f3459 100644 --- a/arch/parisc/Kconfig +++ b/arch/parisc/Kconfig @@ -15,6 +15,7 @@ config PARISC select ARCH_HAS_STRICT_MODULE_RWX select ARCH_HAS_UBSAN select ARCH_HAS_PTE_SPECIAL + select ARCH_NEED_CMPXCHG_1_2_EMU select ARCH_NO_SG_CHAIN select ARCH_SUPPORTS_HUGETLBFS if PA20 select ARCH_SUPPORTS_MEMORY_FAILURE diff --git a/arch/parisc/include/asm/cmpxchg.h b/arch/parisc/include/asm/cm= pxchg.h index c1d776bb16b4e..f909c000b6577 100644 --- a/arch/parisc/include/asm/cmpxchg.h +++ b/arch/parisc/include/asm/cmpxchg.h @@ -72,6 +72,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned= long new_, int size) #endif case 4: return __cmpxchg_u32((unsigned int *)ptr, (unsigned int)old, (unsigned int)new_); + case 2: return cmpxchg_emu_u16((volatile u16 *)ptr, old, new); case 1: return __cmpxchg_u8((u8 *)ptr, old & 0xff, new_ & 0xff); } __cmpxchg_called_with_bad_pointer(); --=20 2.40.1 From nobody Thu Feb 12 03:02:25 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC95C56759 for ; Mon, 1 Apr 2024 21:39:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712007595; cv=none; b=if5QF8zSOzXRHgCLYYOsmmHhtBM4Ruzar0AnEML9S6x1WJcFyJ0fvHU7IS6bvOOOzal6x0//0hvM25pFoJosK5iWzX+VtomlxJvwtK4CsMcnkEnJhTaovr4vjoBkOxQYvUP4EmqKiItSq1BtDeG7Swyclu488IVVWWyLx+lKqHg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712007595; c=relaxed/simple; bh=cHdjMWF2pKpjp1cSSio1TIEvF/d3v3dy9dZ8dApGZaI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q74puIz1yoDLZIm+/4kZreKTOXI65uTCj1lAzsh4XKQzcuZPuquLc8I9FV1ITiswytoC/uPv3uyavbkMfZQwkcvZyQ7RCVD6be+H+PSnlqbKp94Ba7W4i2Qn/NN1Wp3uTwizWMUdbtVU9pqwGi5L7CSQpoEOfTsAwGLfW4ySHIo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FRjGv/+g; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FRjGv/+g" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7BC9DC41674; Mon, 1 Apr 2024 21:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712007595; bh=cHdjMWF2pKpjp1cSSio1TIEvF/d3v3dy9dZ8dApGZaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FRjGv/+gDSEbG4K6K0NV7MmU0QufJtVBYBfxeKyOQa0h0evV+yct5bBRhoMQSPCMP XDRZmN2Q2pb7o9OYst/ZZnhP3K5xDW7pk44v4JOxwr4VbVkbO5sBbK541XzK7IWXMk pXBVXdoF4cxiWsNPVZwjs4XFjDhVLYvN1G/Gc5NVJrK/HRrlrxizsJ33IyuBJBraTt jOv64zBDQ/UT9nD2WhwhbL4C5Nz0/bvECe1F1YsTvCotZG8uG6rZQo0/ghkTS7kgdr 6fHuxnq+I1XegKXRmh+QS/do3AO8kEqEYwmIvblcphWI1Hu4Tcnvt3vJyEL+HwUjQs ZF6d+P70ZxP2Q== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id CD0D4CE16EF; Mon, 1 Apr 2024 14:39:54 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: kernel-team@meta.com, "Paul E. McKenney" , Andi Shyti , Andrzej Hajda , linux-riscv@lists.infradead.org Subject: [PATCH RFC cmpxchg 8/8] riscv: Emulate one-byte and two-byte cmpxchg Date: Mon, 1 Apr 2024 14:39:50 -0700 Message-Id: <20240401213950.3910531-8-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <31c82dcc-e203-48a9-aadd-f2fcd57d94c1@paulmck-laptop> References: <31c82dcc-e203-48a9-aadd-f2fcd57d94c1@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the new cmpxchg_emu_u8() and cmpxchg_emu_u16() to emulate one-byte and two-byte cmpxchg() on riscv. [ paulmck: Apply kernel test robot feedback. ] Signed-off-by: Paul E. McKenney Cc: Andi Shyti Cc: Andrzej Hajda Cc: Acked-by: Palmer Dabbelt --- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/cmpxchg.h | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index be09c8836d56b..4eaf40d0a52ec 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -44,6 +44,7 @@ config RISCV select ARCH_HAS_UBSAN select ARCH_HAS_VDSO_DATA select ARCH_KEEP_MEMBLOCK if ACPI + select ARCH_NEED_CMPXCHG_1_2_EMU select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT select ARCH_STACKWALK diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpx= chg.h index 2fee65cc84432..a5b377481785c 100644 --- a/arch/riscv/include/asm/cmpxchg.h +++ b/arch/riscv/include/asm/cmpxchg.h @@ -9,6 +9,7 @@ #include =20 #include +#include =20 #define __xchg_relaxed(ptr, new, size) \ ({ \ @@ -170,6 +171,12 @@ __typeof__(*(ptr)) __ret; \ register unsigned int __rc; \ switch (size) { \ + case 1: \ + __ret =3D cmpxchg_emu_u8((volatile u8 *)__ptr, __old, __new); \ + break; \ + case 2: \ + break; \ + __ret =3D cmpxchg_emu_u16((volatile u16 *)__ptr, __old, __new); \ case 4: \ __asm__ __volatile__ ( \ "0: lr.w %0, %2\n" \ @@ -214,6 +221,12 @@ __typeof__(*(ptr)) __ret; \ register unsigned int __rc; \ switch (size) { \ + case 1: \ + __ret =3D cmpxchg_emu_u8((volatile u8 *)__ptr, __old, __new); \ + break; \ + case 2: \ + break; \ + __ret =3D cmpxchg_emu_u16((volatile u16 *)__ptr, __old, __new); \ case 4: \ __asm__ __volatile__ ( \ "0: lr.w %0, %2\n" \ @@ -260,6 +273,12 @@ __typeof__(*(ptr)) __ret; \ register unsigned int __rc; \ switch (size) { \ + case 1: \ + __ret =3D cmpxchg_emu_u8((volatile u8 *)__ptr, __old, __new); \ + break; \ + case 2: \ + break; \ + __ret =3D cmpxchg_emu_u16((volatile u16 *)__ptr, __old, __new); \ case 4: \ __asm__ __volatile__ ( \ RISCV_RELEASE_BARRIER \ @@ -306,6 +325,12 @@ __typeof__(*(ptr)) __ret; \ register unsigned int __rc; \ switch (size) { \ + case 1: \ + __ret =3D cmpxchg_emu_u8((volatile u8 *)__ptr, __old, __new); \ + break; \ + case 2: \ + break; \ + __ret =3D cmpxchg_emu_u16((volatile u16 *)__ptr, __old, __new); \ case 4: \ __asm__ __volatile__ ( \ "0: lr.w %0, %2\n" \ --=20 2.40.1