From nobody Wed Dec 17 23:10:08 2025 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 9C4F31304A1; Wed, 1 May 2024 23:01:32 +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=1714604492; cv=none; b=QCVsMqMYgzZoAy1XLqX423AfXKl0TJ3NGl4HbS7siBsoOez1F7e7UmIIy3Ndezvldp3l0GxNLnGN6TKQDISdiLXgjAdsC9L7hTnqun+eyIr9mNyFqPh25B6mFZMCvdXvFQtAhMKpRHgLJOGYg9r0IipRRjf8wN8fsUIJBor2loc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714604492; c=relaxed/simple; bh=JT6TJe0r0m31NAees1xlMQgr2WRm/aZdIYw3Usfm6aw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=W3pVfZ4nHShvTCj8PCrkxEbYdZcViEuaQWMzu69kVeFTJi1QI9pN7kFw3ZTVkOmzX2hL/GFq7klglSZzJ3cmvDFuiYCVZ3aw3H72K1RpDf8Q+VAuxp9SOqFsAIplG6dZyucEmTaMEMzLnLW6B4RXFw1JkVAPVQi+BfUzmVVZvXI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vJCwT8uw; 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="vJCwT8uw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 259E6C072AA; Wed, 1 May 2024 23:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714604492; bh=JT6TJe0r0m31NAees1xlMQgr2WRm/aZdIYw3Usfm6aw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vJCwT8uwqAS1XjmZUiYIgd500wozQllVLdC9W43l4kcQae9gLVbKtFxFBKwXdPGdn 0BcRIa+RY0Pcg4CA0XaiwjTsrx9+4gQlEMq8jR7zEIpL/f/4KTXISZyXfyZNbjJGni D3q82CcGF7LEmHqJFEfvjTaweIDFXQhU7k7TnZtBNnFpGOeA9EcdVfX3KVGXzBYTL7 DMQuAZV67wslIYmRc6fuTAfPlsfInAjnVtOzRzGtXDRJ1fjmDhgs8DFl+KbaNMTegF 51DiPZvNyOuglY4d+1eo5rhMC1sEEjeTwMRstdwz0C0t2c9+yHIbNKlVcXgPe/goB/ rvvDVSt3w1MJg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id BD5CECE1073; Wed, 1 May 2024 16:01:31 -0700 (PDT) From: "Paul E. McKenney" To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Cc: elver@google.com, akpm@linux-foundation.org, tglx@linutronix.de, peterz@infradead.org, dianders@chromium.org, pmladek@suse.com, arnd@arndb.de, torvalds@linux-foundation.org, kernel-team@meta.com, Al Viro , "Paul E . McKenney" Subject: [PATCH v2 cmpxchg 01/13] sparc32: make __cmpxchg_u32() return u32 Date: Wed, 1 May 2024 16:01:18 -0700 Message-Id: <20240501230130.1111603-1-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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" From: Al Viro Conversion between u32 and unsigned long is tautological there, and the only use of return value is to return it from __cmpxchg() (which return unsigned long). Get rid of explicit casts in __cmpxchg_u32() call, while we are at it - normal conversions for arguments will do just fine. Signed-off-by: Al Viro Signed-off-by: Paul E. McKenney --- arch/sparc/include/asm/cmpxchg_32.h | 4 ++-- arch/sparc/lib/atomic32.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/sparc/include/asm/cmpxchg_32.h b/arch/sparc/include/asm/c= mpxchg_32.h index d0af82c240b73..2a05cb236480c 100644 --- a/arch/sparc/include/asm/cmpxchg_32.h +++ b/arch/sparc/include/asm/cmpxchg_32.h @@ -39,7 +39,7 @@ static __always_inline unsigned long __arch_xchg(unsigned= long x, __volatile__ v /* bug catcher for when unsupported size is used - won't link */ 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_); +u32 __cmpxchg_u32(volatile u32 *m, u32 old, u32 new_); =20 /* don't worry...optimizer will get rid of most of this */ static inline unsigned long @@ -47,7 +47,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned= long new_, int size) { switch (size) { case 4: - return __cmpxchg_u32((u32 *)ptr, (u32)old, (u32)new_); + return __cmpxchg_u32(ptr, old, new_); default: __cmpxchg_called_with_bad_pointer(); break; diff --git a/arch/sparc/lib/atomic32.c b/arch/sparc/lib/atomic32.c index cf80d1ae352be..d90d756123d81 100644 --- a/arch/sparc/lib/atomic32.c +++ b/arch/sparc/lib/atomic32.c @@ -159,7 +159,7 @@ unsigned long sp32___change_bit(unsigned long *addr, un= signed long mask) } EXPORT_SYMBOL(sp32___change_bit); =20 -unsigned long __cmpxchg_u32(volatile u32 *ptr, u32 old, u32 new) +u32 __cmpxchg_u32(volatile u32 *ptr, u32 old, u32 new) { unsigned long flags; u32 prev; @@ -169,7 +169,7 @@ unsigned long __cmpxchg_u32(volatile u32 *ptr, u32 old,= u32 new) *ptr =3D new; spin_unlock_irqrestore(ATOMIC_HASH(ptr), flags); =20 - return (unsigned long)prev; + return prev; } EXPORT_SYMBOL(__cmpxchg_u32); =20 --=20 2.40.1 From nobody Wed Dec 17 23:10:08 2025 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 9C4B64F897; Wed, 1 May 2024 23:01:32 +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=1714604492; cv=none; b=Sz+/7jJNIe/mHXDX1hbUnbCC4xqvlhvy7MScKO3k9DUNOdj7Z54NNjs9TMW0/N9hNgCxIw4QOLrrOwj0qq8/45RfpJTPFqV3n/V4Lgnp5UOyZHCnfGQ33pl6ILzOY+k0hkJUJ/M18vzwJESwjq3U3J60IEyzc0XTZ2+XYnNAZlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714604492; c=relaxed/simple; bh=Gwo0L9nG/Bxq+TZGLagGgn6iVboBxYsc87SIRn3872E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CA+N7shms4YPvVWXzZnrdaos/25MmElkKbjXoH+oo2891OiU72d/cC9tw/c8SLwY71Ky+BrUjwHTr8DTXEdGtGlZYVsbUUO4ToMtFqjepWHdkV1WJRb+ihR9YD6VPIY2xxZI/Csg8XAKkCguSkOLsKptVCsRlxdBGJ27OW0x1tc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EEEi0dJQ; 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="EEEi0dJQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B386C4AF14; Wed, 1 May 2024 23:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714604492; bh=Gwo0L9nG/Bxq+TZGLagGgn6iVboBxYsc87SIRn3872E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EEEi0dJQ9tPwkKw0Q/Yl3BJm0bph7/6npi8fKcU/c3JgibF0hgeVfxG7Vqd6YKurD 0bXE+xtjpvYV93H2i0LUpdMmVfAHGYYA+43Gp9ZrvrDroIyx1twkf5WiT3kOubyFVg hpqoJkTno1QSUFG2KXAtVNyWR4pYS4aKHaQ724SH/BC6iQFsx+12V7RRHynhaNo8Zs u7QXH7WmU/YXC3xtwWKvWVJgjqqw0BEAj9sSiIMtjoV2/IkIvhcnV3cW9T2Nqh7Bu9 MfYc+CV+7QXlwCHUxIn3gFQYuJTzaJj16v/2DF++DBcc0OEBcM8fdlGuv8bmgVmkC/ SUKm0WYK4A9GQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id BEF95CE0808; Wed, 1 May 2024 16:01:31 -0700 (PDT) From: "Paul E. McKenney" To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Cc: elver@google.com, akpm@linux-foundation.org, tglx@linutronix.de, peterz@infradead.org, dianders@chromium.org, pmladek@suse.com, arnd@arndb.de, torvalds@linux-foundation.org, kernel-team@meta.com, Al Viro , "Paul E . McKenney" Subject: [PATCH v2 cmpxchg 02/13] sparc32: make the first argument of __cmpxchg_u64() volatile u64 * Date: Wed, 1 May 2024 16:01:19 -0700 Message-Id: <20240501230130.1111603-2-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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" From: Al Viro ... to match all cmpxchg variants. Signed-off-by: Al Viro Signed-off-by: Paul E. McKenney --- arch/sparc/include/asm/cmpxchg_32.h | 2 +- arch/sparc/lib/atomic32.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/sparc/include/asm/cmpxchg_32.h b/arch/sparc/include/asm/c= mpxchg_32.h index 2a05cb236480c..05d5f86a56dc2 100644 --- a/arch/sparc/include/asm/cmpxchg_32.h +++ b/arch/sparc/include/asm/cmpxchg_32.h @@ -63,7 +63,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned= long new_, int size) (unsigned long)_n_, sizeof(*(ptr))); \ }) =20 -u64 __cmpxchg_u64(u64 *ptr, u64 old, u64 new); +u64 __cmpxchg_u64(volatile u64 *ptr, u64 old, u64 new); #define arch_cmpxchg64(ptr, old, new) __cmpxchg_u64(ptr, old, new) =20 #include diff --git a/arch/sparc/lib/atomic32.c b/arch/sparc/lib/atomic32.c index d90d756123d81..e15affbbb5238 100644 --- a/arch/sparc/lib/atomic32.c +++ b/arch/sparc/lib/atomic32.c @@ -173,7 +173,7 @@ u32 __cmpxchg_u32(volatile u32 *ptr, u32 old, u32 new) } EXPORT_SYMBOL(__cmpxchg_u32); =20 -u64 __cmpxchg_u64(u64 *ptr, u64 old, u64 new) +u64 __cmpxchg_u64(volatile u64 *ptr, u64 old, u64 new) { unsigned long flags; u64 prev; --=20 2.40.1 From nobody Wed Dec 17 23:10:08 2025 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 9C47A1C68D; Wed, 1 May 2024 23:01:32 +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=1714604492; cv=none; b=pc6AKr5xzLygtfBPiaSHDtYTJ+vxvXLWEvseu3/naOBMnTj3J9tK/FAfQ8BEeXhO+/GrVGf0tD0/I69eAUitOJr6ceisxBW0w1IyEo0Qv4vZeaFOl8DprJAB0KeL5aSkuYQQ+FAdtPgEx48jxh53/zyFc1nFaBnP+PpMlsSHVq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714604492; c=relaxed/simple; bh=c2cXyTpfqV8tv5AG0/sE+MGJrrEmGRkliM6KcM6nVj0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=O0HyerSL3EeXHSl8kfNLJjg18Um8xeDJkCHhiYZPfFUFpm2YZXJnopqqS1S5JvNWR/uNaXBumJhBNJGy9zT8BxVryLjFU5dVvnba29+aDFFefMjgqqi4tUt+Mkuu5OeButp/v2kMEyGJdqNWLv+CKy6PuIkHPe3pjCtY//MzDBA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NGvXB9Ll; 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="NGvXB9Ll" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2FAC4C113CC; Wed, 1 May 2024 23:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714604492; bh=c2cXyTpfqV8tv5AG0/sE+MGJrrEmGRkliM6KcM6nVj0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NGvXB9LlhqVYz9frifnxysqDrtE+jmWBR03s0B56jvhEG3Ymd7tVXjgkZAMxW6ivR +Zp68VPpFb0ljMEp0FbMzXL6pG632LywY7u5Olj0HqJaj05HqTQp3/d6F0SBzKGlDw tQqA8K4zfsUWBBJgGTXAjKQELAJq1Xrbxt66WKVOEe1G+vjbJfDh4Syqqv52/kuoT1 NhwUdtDaubhxyvyTFwoqK//sjsCB8EOz3PidkwlCzfhPgihJL/k4c65DvuQX9fpmO9 NG5Rfet6CiTDz4x0KKXHVtMw5FDKU2vVxDtjfQX3+Cl3XGLcDv6CMLbCtNRGgmmOdw RI3p9EBhOq2Og== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C23BFCE1415; Wed, 1 May 2024 16:01:31 -0700 (PDT) From: "Paul E. McKenney" To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Cc: elver@google.com, akpm@linux-foundation.org, tglx@linutronix.de, peterz@infradead.org, dianders@chromium.org, pmladek@suse.com, arnd@arndb.de, torvalds@linux-foundation.org, kernel-team@meta.com, Al Viro , "Paul E . McKenney" Subject: [PATCH v2 cmpxchg 03/13] sparc32: unify __cmpxchg_u{32,64} Date: Wed, 1 May 2024 16:01:20 -0700 Message-Id: <20240501230130.1111603-3-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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" From: Al Viro Add a macro that expands to one of those when given u32 or u64 as an argument - atomic32.c has a lot of similar stuff already. Signed-off-by: Al Viro Signed-off-by: Paul E. McKenney --- arch/sparc/lib/atomic32.c | 41 +++++++++++++++------------------------ 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/arch/sparc/lib/atomic32.c b/arch/sparc/lib/atomic32.c index e15affbbb5238..0d215a772428e 100644 --- a/arch/sparc/lib/atomic32.c +++ b/arch/sparc/lib/atomic32.c @@ -159,32 +159,23 @@ unsigned long sp32___change_bit(unsigned long *addr, = unsigned long mask) } EXPORT_SYMBOL(sp32___change_bit); =20 -u32 __cmpxchg_u32(volatile u32 *ptr, u32 old, u32 new) -{ - unsigned long flags; - u32 prev; - - spin_lock_irqsave(ATOMIC_HASH(ptr), flags); - if ((prev =3D *ptr) =3D=3D old) - *ptr =3D new; - spin_unlock_irqrestore(ATOMIC_HASH(ptr), flags); - - return prev; -} +#define CMPXCHG(T) \ + T __cmpxchg_##T(volatile T *ptr, T old, T new) \ + { \ + unsigned long flags; \ + T prev; \ + \ + spin_lock_irqsave(ATOMIC_HASH(ptr), flags); \ + if ((prev =3D *ptr) =3D=3D old) \ + *ptr =3D new; \ + spin_unlock_irqrestore(ATOMIC_HASH(ptr), flags);\ + \ + return prev; \ + } + +CMPXCHG(u32) +CMPXCHG(u64) EXPORT_SYMBOL(__cmpxchg_u32); - -u64 __cmpxchg_u64(volatile u64 *ptr, u64 old, u64 new) -{ - unsigned long flags; - u64 prev; - - spin_lock_irqsave(ATOMIC_HASH(ptr), flags); - if ((prev =3D *ptr) =3D=3D old) - *ptr =3D new; - spin_unlock_irqrestore(ATOMIC_HASH(ptr), flags); - - return prev; -} EXPORT_SYMBOL(__cmpxchg_u64); =20 unsigned long __xchg_u32(volatile u32 *ptr, u32 new) --=20 2.40.1 From nobody Wed Dec 17 23:10:08 2025 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 A65131311AF; Wed, 1 May 2024 23:01:32 +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=1714604492; cv=none; b=AGaaf7GVNsylR8V7G6XGHc8aH/bPlic6uGeFoeUDUmgKUd69vbAqV1bMkwHdxe4K4tUz9PK49Msu9INwXSTKB0HGuexi/2qaSn9fX99a2GOonMQJzpHOkHPBb2oLAh8AZeWMaLmZwta+VmNXVGVoOAGvtWmBNCLNYKjdbeqXccA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714604492; c=relaxed/simple; bh=1eMVNwHdcY4Pw0fbrq6XWtA7kyaxHrAZ9QJnM9orhXk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=abVhbpS4X9HeCwsF1U9Tje6cjyv+YM3JzFOqMzpPrrFnh+EWJX9+lnuZr+VTpv07VyDsbA5u8DLoHhbOAaAiu9KsnRXPADsLP2gyHbfTi7kCOvOpDPbXVp3X+pzPUcddFzumYrM2By83Lg30XqsUgTjoQB4s71Yw34u9m3Z9J98= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KOCq4831; 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="KOCq4831" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43539C4AF1A; Wed, 1 May 2024 23:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714604492; bh=1eMVNwHdcY4Pw0fbrq6XWtA7kyaxHrAZ9QJnM9orhXk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KOCq48315zRPrdn1r25G/IMDaQzgd0easvBHNTxqNBDfhGlmbsJ9UxFy5y1b3HL9U HvSZVQHcLlFVA0CzChIcKrwP+ITv6sRLIYTBgpWdXAb4ONejc4fWbOaKmpz7cXDAJt 2fXdLNZwu4Px9MQYRwkuBPiJcqynJWHcn3GUR+Cyf5t572bfAGGIPxAAvZTjJwVSZp B45IgUsdi79yniaLQ1loLvUftAUiCPAcuTPQ7gnUy2JpdJY1K20SP8p/3dGyFxfRjl aVgwo0tuKQ3Dnm8h64piBeE/ODHpIslauoHwyROCMo+dpOfz2htLaoijr9/ijtRdW9 9pl0BvHvvFnuA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C5295CE1A05; Wed, 1 May 2024 16:01:31 -0700 (PDT) From: "Paul E. McKenney" To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Cc: elver@google.com, akpm@linux-foundation.org, tglx@linutronix.de, peterz@infradead.org, dianders@chromium.org, pmladek@suse.com, arnd@arndb.de, torvalds@linux-foundation.org, kernel-team@meta.com, Al Viro , "Paul E . McKenney" Subject: [PATCH v2 cmpxchg 04/13] sparc32: add __cmpxchg_u{8,16}() and teach __cmpxchg() to handle those sizes Date: Wed, 1 May 2024 16:01:21 -0700 Message-Id: <20240501230130.1111603-4-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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" From: Al Viro trivial now Signed-off-by: Al Viro Signed-off-by: Paul E. McKenney --- arch/sparc/include/asm/cmpxchg_32.h | 16 +++++++--------- arch/sparc/lib/atomic32.c | 4 ++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/arch/sparc/include/asm/cmpxchg_32.h b/arch/sparc/include/asm/c= mpxchg_32.h index 05d5f86a56dc2..8c1a3ca34eeb7 100644 --- a/arch/sparc/include/asm/cmpxchg_32.h +++ b/arch/sparc/include/asm/cmpxchg_32.h @@ -38,21 +38,19 @@ static __always_inline unsigned long __arch_xchg(unsign= ed long x, __volatile__ v =20 /* bug catcher for when unsupported size is used - won't link */ void __cmpxchg_called_with_bad_pointer(void); -/* we only need to support cmpxchg of a u32 on sparc */ +u8 __cmpxchg_u8(volatile u8 *m, u8 old, u8 new_); +u16 __cmpxchg_u16(volatile u16 *m, u16 old, u16 new_); u32 __cmpxchg_u32(volatile u32 *m, u32 old, u32 new_); =20 /* 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 4: - return __cmpxchg_u32(ptr, old, new_); - default: - __cmpxchg_called_with_bad_pointer(); - break; - } - return old; + return + size =3D=3D 1 ? __cmpxchg_u8(ptr, old, new_) : + size =3D=3D 2 ? __cmpxchg_u16(ptr, old, new_) : + size =3D=3D 4 ? __cmpxchg_u32(ptr, old, new_) : + (__cmpxchg_called_with_bad_pointer(), old); } =20 #define arch_cmpxchg(ptr, o, n) \ diff --git a/arch/sparc/lib/atomic32.c b/arch/sparc/lib/atomic32.c index 0d215a772428e..8ae880ebf07aa 100644 --- a/arch/sparc/lib/atomic32.c +++ b/arch/sparc/lib/atomic32.c @@ -173,8 +173,12 @@ EXPORT_SYMBOL(sp32___change_bit); return prev; \ } =20 +CMPXCHG(u8) +CMPXCHG(u16) CMPXCHG(u32) CMPXCHG(u64) +EXPORT_SYMBOL(__cmpxchg_u8); +EXPORT_SYMBOL(__cmpxchg_u16); EXPORT_SYMBOL(__cmpxchg_u32); EXPORT_SYMBOL(__cmpxchg_u64); =20 --=20 2.40.1 From nobody Wed Dec 17 23:10:08 2025 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 A64D6130A4E; Wed, 1 May 2024 23:01:32 +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=1714604492; cv=none; b=A4NyvUik1z4l7h9KzJ2ECQq8s52dnBpWL0dkGtZHNVJICEPT+M3luBwWAChfipJ8MY/ZyY70F6kuS8jDmNG03pJwBeLY0vOFhZrWJmYXrthW+WRPaerJ37+IYCHKXfFwkzDh7Ckz3/tgBp9wCMIc3SoZmNDcpvmMLzamFcNVjNA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714604492; c=relaxed/simple; bh=xV0bjRNG69Gk9MLDp+p1hE+J2KXV1jWcp0coMhIa834=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iTSML5Z1UZUFFTO92/A6R7xtNJVVqiuuZujUkLVMfgv/GaocqjnhoJOkLKir+sllxxfWFtArw0VCmQ3ksHB8+z2YIXEydus2lKGBYgeW3miir/muOLWK5mrPmHUOfbBUZD6oRlgpZVTLJrvZ25dHAi12BAP2TSliVAUKyN6roMs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=diW2GytF; 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="diW2GytF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46977C4AF1C; Wed, 1 May 2024 23:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714604492; bh=xV0bjRNG69Gk9MLDp+p1hE+J2KXV1jWcp0coMhIa834=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=diW2GytFZI+FRAYk8CY838KC8736HkjCtvPMdrmixVTpOL/dv8LXFdB9+JaU0cG6D ZnxeKzIdFLyN1sTmGKzEIO8Opojc5lXgbenCFMdwrk7cF+iYp2dJaZ5mXFbhHE02jQ bzOapP/WI0B/5Rom61Ek45fK49+10lVoB8nlDglyQ9wJrs+FhlSGmGCkXlS2WquTl1 GMvjAGhokT09rZnHSim9bIrbSTUXmFRvaBzNJY3BxBDLuaLJ1fvthdx1emgzYVQZT3 ybfzp9EV8B50LfFa1uIkiFxhJboh6tRJCmJR+2z+yKc4dRuMgmCSEBcKwOU9ABVVM0 zS/wIOJagt2ew== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C7F38CE220F; Wed, 1 May 2024 16:01:31 -0700 (PDT) From: "Paul E. McKenney" To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Cc: elver@google.com, akpm@linux-foundation.org, tglx@linutronix.de, peterz@infradead.org, dianders@chromium.org, pmladek@suse.com, arnd@arndb.de, torvalds@linux-foundation.org, kernel-team@meta.com, Al Viro , "Paul E . McKenney" Subject: [PATCH v2 cmpxchg 05/13] parisc: __cmpxchg_u32(): lift conversion into the callers Date: Wed, 1 May 2024 16:01:22 -0700 Message-Id: <20240501230130.1111603-5-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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" From: Al Viro __cmpxchg_u32() return value is unsigned int explicitly cast to unsigned long. Both callers are returns from functions that return unsigned long; might as well have __cmpxchg_u32() return that unsigned int (aka u32) and let the callers convert implicitly. Signed-off-by: Al Viro Signed-off-by: Paul E. McKenney --- arch/parisc/include/asm/cmpxchg.h | 3 +-- arch/parisc/lib/bitops.c | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/arch/parisc/include/asm/cmpxchg.h b/arch/parisc/include/asm/cm= pxchg.h index c1d776bb16b4e..0924ebc576d28 100644 --- a/arch/parisc/include/asm/cmpxchg.h +++ b/arch/parisc/include/asm/cmpxchg.h @@ -57,8 +57,7 @@ __arch_xchg(unsigned long x, volatile void *ptr, int size) extern void __cmpxchg_called_with_bad_pointer(void); =20 /* __cmpxchg_u32/u64 defined in arch/parisc/lib/bitops.c */ -extern unsigned long __cmpxchg_u32(volatile unsigned int *m, unsigned int = old, - unsigned int new_); +extern u32 __cmpxchg_u32(volatile u32 *m, u32 old, u32 new_); extern u64 __cmpxchg_u64(volatile u64 *ptr, u64 old, u64 new_); extern u8 __cmpxchg_u8(volatile u8 *ptr, u8 old, u8 new_); =20 diff --git a/arch/parisc/lib/bitops.c b/arch/parisc/lib/bitops.c index 36a3141990746..ae2231d921985 100644 --- a/arch/parisc/lib/bitops.c +++ b/arch/parisc/lib/bitops.c @@ -68,16 +68,16 @@ u64 notrace __cmpxchg_u64(volatile u64 *ptr, u64 old, u= 64 new) return prev; } =20 -unsigned long notrace __cmpxchg_u32(volatile unsigned int *ptr, unsigned i= nt old, unsigned int new) +u32 notrace __cmpxchg_u32(volatile u32 *ptr, u32 old, u32 new) { unsigned long flags; - unsigned int prev; + u32 prev; =20 _atomic_spin_lock_irqsave(ptr, flags); if ((prev =3D *ptr) =3D=3D old) *ptr =3D new; _atomic_spin_unlock_irqrestore(ptr, flags); - return (unsigned long)prev; + return prev; } =20 u8 notrace __cmpxchg_u8(volatile u8 *ptr, u8 old, u8 new) --=20 2.40.1 From nobody Wed Dec 17 23:10:08 2025 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 F0B7C168AED; Wed, 1 May 2024 23:01:32 +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=1714604493; cv=none; b=qtuTBG1iu0v7bKQqNSVLx5w7OJiTRAmapONZJphNeRgCVEXojjPXT2YoF36VcYv/eVUpngE0lCS63J3SjWWP+w/GciMrmFjxCPjzpSR5rUet+qyxmuL8DNnKaieVHnB2rQouYZuqA5ASLcenOqqxZmCZjzqYuXxGikehQxMsv90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714604493; c=relaxed/simple; bh=ehpYlEI/7ddbuIzdM9fBMt5Xa6+QYchqcgxnWBcCufs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=habGulP+3HxPtGnzer1nYPSbHyqF+UCLATlvpcnUg8NjPOLnrP8GOaT6vNhrNQA2n8ypk1nbmDEvB0zApF1X++QHJxlBaaE4CaoIEYsMqNYhJjQkC3c/yEHRdknAZqji8AKF8JAQmnIvyVteRaIztLplR/HjeOYDQCntZcrmaaU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=t2KtLMkK; 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="t2KtLMkK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 821FCC4AF4D; Wed, 1 May 2024 23:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714604492; bh=ehpYlEI/7ddbuIzdM9fBMt5Xa6+QYchqcgxnWBcCufs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t2KtLMkKSwpi3V6yfk2x80G1xvO37BHZJpU4pzwPsYJATGnBPLIK8Xwd4b90+VtgV Ucs1mN317R0+ZCd9f/u4jUetGp/Yd2epdeLdPWml5VZBzdcanpn9WOMqyd7Ebs32OS QnKGSGZm+NesLnXvtgTox7Ls2fuqw/J8MvyqvRv8QCYsGRb80qxt87r3S1pGY594sI VSNYFavCYTAPhQ/MFhQMy3PwpM+J57RJJT1W+UitNzQoASnfCkNyLGqbtnbgI7ETT0 +e9hG6sgvzTQxx4AZtKrMZPBpMwqI11zbGEDcA6VGKqoOnMzCXk0wbp1ZxPW+vFn50 R2KepK/5DKD8g== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id CA9A5CE226C; Wed, 1 May 2024 16:01:31 -0700 (PDT) From: "Paul E. McKenney" To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Cc: elver@google.com, akpm@linux-foundation.org, tglx@linutronix.de, peterz@infradead.org, dianders@chromium.org, pmladek@suse.com, arnd@arndb.de, torvalds@linux-foundation.org, kernel-team@meta.com, Al Viro , "Paul E . McKenney" Subject: [PATCH v2 cmpxchg 06/13] parisc: unify implementations of __cmpxchg_u{8,32,64} Date: Wed, 1 May 2024 16:01:23 -0700 Message-Id: <20240501230130.1111603-6-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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" From: Al Viro identical except for type name involved Signed-off-by: Al Viro Signed-off-by: Paul E. McKenney --- arch/parisc/lib/bitops.c | 51 +++++++++++++--------------------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/arch/parisc/lib/bitops.c b/arch/parisc/lib/bitops.c index ae2231d921985..cae30a3eb6d9b 100644 --- a/arch/parisc/lib/bitops.c +++ b/arch/parisc/lib/bitops.c @@ -56,38 +56,19 @@ unsigned long notrace __xchg8(char x, volatile char *pt= r) } =20 =20 -u64 notrace __cmpxchg_u64(volatile u64 *ptr, u64 old, u64 new) -{ - unsigned long flags; - u64 prev; - - _atomic_spin_lock_irqsave(ptr, flags); - if ((prev =3D *ptr) =3D=3D old) - *ptr =3D new; - _atomic_spin_unlock_irqrestore(ptr, flags); - return prev; -} - -u32 notrace __cmpxchg_u32(volatile u32 *ptr, u32 old, u32 new) -{ - unsigned long flags; - u32 prev; - - _atomic_spin_lock_irqsave(ptr, flags); - if ((prev =3D *ptr) =3D=3D old) - *ptr =3D new; - _atomic_spin_unlock_irqrestore(ptr, flags); - return prev; -} - -u8 notrace __cmpxchg_u8(volatile u8 *ptr, u8 old, u8 new) -{ - unsigned long flags; - u8 prev; - - _atomic_spin_lock_irqsave(ptr, flags); - if ((prev =3D *ptr) =3D=3D old) - *ptr =3D new; - _atomic_spin_unlock_irqrestore(ptr, flags); - return prev; -} +#define CMPXCHG(T) \ + T notrace __cmpxchg_##T(volatile T *ptr, T old, T new) \ + { \ + unsigned long flags; \ + T prev; \ + \ + _atomic_spin_lock_irqsave(ptr, flags); \ + if ((prev =3D *ptr) =3D=3D old) \ + *ptr =3D new; \ + _atomic_spin_unlock_irqrestore(ptr, flags); \ + return prev; \ + } + +CMPXCHG(u64) +CMPXCHG(u32) +CMPXCHG(u8) --=20 2.40.1 From nobody Wed Dec 17 23:10:08 2025 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 D3B7B165FA1; Wed, 1 May 2024 23:01:32 +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=1714604492; cv=none; b=qU321hEjwfEcGqji0EitW17s7e0jeomLOii0U6jZi7NstBQi7FvqrhOLlPUkXf6NiFm3SRuNmcXL1qTdWXrtLzY1HWuH5Pfrh6K4P2aNEF1YLoK4K2Da84q5ZNKUMi1zUbgEYHlF7mnSFOmZVRk0mGvS3Tm3KOJnAKQYIIxMl/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714604492; c=relaxed/simple; bh=JQmLzMtBpKC/TtfERldphRZSepAv95vPmjK1jOVEaZM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cF+WwFog0DyOHgI+37QShHAc+jRU0f0hrEWt2W8kyGqDbAIp6wdutFyAH66dBP6lVNCEPE5Xz+2vdtWBXOCBYU2AYATyBpsQDmHxa7WGEFwclMrzboLgp+XTq9bcx10djb90fiKxIvndAg2+ZkPFvpsGwQK7YVFRVDUiWsmczN8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VYYe3iYV; 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="VYYe3iYV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85E8EC4AF52; Wed, 1 May 2024 23:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714604492; bh=JQmLzMtBpKC/TtfERldphRZSepAv95vPmjK1jOVEaZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VYYe3iYVikXiszNpOW5eYSVRF46eyKWebtQFsIdPs+aDuaYa3Tqel/IK7B/bnfftv v1QLnxqFy86Rpq/Y16R+rMtmri6GptIEQrdQKTkEoN+qRnAx4Cz4iuGkL8hdGhOBiu pXV0PFLT6tk9sTVd/+TiWSpe8hw5ih6YI3GyO7YYzmZg1hmw8MTM7jbdAoxdEW6hz3 1ScdcghDxJ53rOfUBJt+lIiyS0p88R0+qvsWqJNRLTDZJWCLojqJ6AC1RaNecXH/s9 y6YVSpQKzqMvjBR4JfZ0JRanZuqufemkYcQaFvgLPqOEbfpARsxdOmwHSEo/36VIJz nzt1zgifH3t7A== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id CD788CE2277; Wed, 1 May 2024 16:01:31 -0700 (PDT) From: "Paul E. McKenney" To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Cc: elver@google.com, akpm@linux-foundation.org, tglx@linutronix.de, peterz@infradead.org, dianders@chromium.org, pmladek@suse.com, arnd@arndb.de, torvalds@linux-foundation.org, kernel-team@meta.com, Al Viro , "Paul E . McKenney" Subject: [PATCH v2 cmpxchg 07/13] parisc: add missing export of __cmpxchg_u8() Date: Wed, 1 May 2024 16:01:24 -0700 Message-Id: <20240501230130.1111603-7-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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" From: Al Viro __cmpxchg_u8() had been added (initially) for the sake of drivers/phy/ti/phy-tusb1210.c; the thing is, that drivers is modular, so we need an export Fixes: b344d6a83d01 "parisc: add support for cmpxchg on u8 pointers" Signed-off-by: Al Viro Signed-off-by: Paul E. McKenney --- arch/parisc/kernel/parisc_ksyms.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/parisc/kernel/parisc_ksyms.c b/arch/parisc/kernel/parisc_= ksyms.c index 6f0c92e8149d8..dcf61cbd31470 100644 --- a/arch/parisc/kernel/parisc_ksyms.c +++ b/arch/parisc/kernel/parisc_ksyms.c @@ -22,6 +22,7 @@ EXPORT_SYMBOL(memset); #include EXPORT_SYMBOL(__xchg8); EXPORT_SYMBOL(__xchg32); +EXPORT_SYMBOL(__cmpxchg_u8); EXPORT_SYMBOL(__cmpxchg_u32); EXPORT_SYMBOL(__cmpxchg_u64); #ifdef CONFIG_SMP --=20 2.40.1 From nobody Wed Dec 17 23:10:08 2025 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 D26951649A8; Wed, 1 May 2024 23:01:32 +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=1714604492; cv=none; b=qxJTEJhG7GFP9V0OfxhxPUaC2tdzf1dIyKwyvmGeGGLsrXxgPxa7l1euDku7YNyumttmvOttcCswS5F+YfS7Hkd44WhZOgHzbH2GSa+G39R0kr31t/wVfjJtA4Qs1arA+ufOpnfxYGzgwe5hv870iZkQO93N1Bx9dOZ1G7z7vWk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714604492; c=relaxed/simple; bh=1iPZOptm0sNwEG3zVn5V4DRrsb9XL24MUs8zOVTokRw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WFm4rzQfmQG6AewAEbk1OHpbdxjTMaah3B1MJA54jmR97T25CnZLxcp8B9EWd6azZOBInFc0ttI0kTGBW6oh/Gzh1pudqcuzGGlh4A3fGxd+7hsfwBHsIb2kY/e0PnhRSRBm/L7fMq21Z21kRTkGEGPNgW3a+WMsMm1SBrFKoBg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=n3zDz6zP; 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="n3zDz6zP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85D4DC4AF50; Wed, 1 May 2024 23:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714604492; bh=1iPZOptm0sNwEG3zVn5V4DRrsb9XL24MUs8zOVTokRw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n3zDz6zPl0EBBQxLNdvQIX+Eby1w+zwffsIfLg6U+ij5N/QmU1XQwiXK8mzdUoCPR hXkYKuVJ877tCotbA3/oUlbW+zQcSkLnLU9tB2pVqDkfMKuG/XpEk8j4+UswKbWXkz Gh7m+q6FrzsmMeIHvB92ic0vQLlY19MMyFrUbthn4kHdFyKmUkuRZiKysTmvy4E6ex MEuLgxJ+FWey566gz16YatvbKvrpCW7XB+vl3xqEltWtUC9ZLHjLASvEpg0D9aYwLl WpKcCSOaSqtrfjWs/VtmOiZXEkDaeV5yW9tXEVLlWvGiS4oepBkg4BPr6IbtEwrqKX iRVW7BMQR2lBg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id D06A6CE2279; Wed, 1 May 2024 16:01:31 -0700 (PDT) From: "Paul E. McKenney" To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Cc: elver@google.com, akpm@linux-foundation.org, tglx@linutronix.de, peterz@infradead.org, dianders@chromium.org, pmladek@suse.com, arnd@arndb.de, torvalds@linux-foundation.org, kernel-team@meta.com, Al Viro , "Paul E . McKenney" Subject: [PATCH v2 cmpxchg 08/13] parisc: add u16 support to cmpxchg() Date: Wed, 1 May 2024 16:01:25 -0700 Message-Id: <20240501230130.1111603-8-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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" From: Al Viro Add (and export) __cmpxchg_u16(), teach __cmpxchg() to use it. And get rid of manual truncation down to u8, etc. in there - the only reason for those is to avoid bogus warnings about constant truncation from sparse, and those are easy to avoid by turning that switch into conditional expression. Signed-off-by: Al Viro Signed-off-by: Paul E. McKenney --- arch/parisc/include/asm/cmpxchg.h | 19 +++++++++---------- arch/parisc/kernel/parisc_ksyms.c | 1 + arch/parisc/lib/bitops.c | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/arch/parisc/include/asm/cmpxchg.h b/arch/parisc/include/asm/cm= pxchg.h index 0924ebc576d28..bf0a0f1189eb2 100644 --- a/arch/parisc/include/asm/cmpxchg.h +++ b/arch/parisc/include/asm/cmpxchg.h @@ -56,25 +56,24 @@ __arch_xchg(unsigned long x, volatile void *ptr, int si= ze) /* bug catcher for when unsupported size is used - won't link */ extern void __cmpxchg_called_with_bad_pointer(void); =20 -/* __cmpxchg_u32/u64 defined in arch/parisc/lib/bitops.c */ +/* __cmpxchg_u... defined in arch/parisc/lib/bitops.c */ +extern u8 __cmpxchg_u8(volatile u8 *ptr, u8 old, u8 new_); +extern u16 __cmpxchg_u16(volatile u16 *ptr, u16 old, u16 new_); extern u32 __cmpxchg_u32(volatile u32 *m, u32 old, u32 new_); extern u64 __cmpxchg_u64(volatile u64 *ptr, u64 old, u64 new_); -extern u8 __cmpxchg_u8(volatile u8 *ptr, u8 old, u8 new_); =20 /* 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) { + return #ifdef CONFIG_64BIT - case 8: return __cmpxchg_u64((u64 *)ptr, old, new_); + size =3D=3D 8 ? __cmpxchg_u64(ptr, old, new_) : #endif - case 4: return __cmpxchg_u32((unsigned int *)ptr, - (unsigned int)old, (unsigned int)new_); - case 1: return __cmpxchg_u8((u8 *)ptr, old & 0xff, new_ & 0xff); - } - __cmpxchg_called_with_bad_pointer(); - return old; + size =3D=3D 4 ? __cmpxchg_u32(ptr, old, new_) : + size =3D=3D 2 ? __cmpxchg_u16(ptr, old, new_) : + size =3D=3D 1 ? __cmpxchg_u8(ptr, old, new_) : + (__cmpxchg_called_with_bad_pointer(), old); } =20 #define arch_cmpxchg(ptr, o, n) \ diff --git a/arch/parisc/kernel/parisc_ksyms.c b/arch/parisc/kernel/parisc_= ksyms.c index dcf61cbd31470..c1587aa35beb6 100644 --- a/arch/parisc/kernel/parisc_ksyms.c +++ b/arch/parisc/kernel/parisc_ksyms.c @@ -23,6 +23,7 @@ EXPORT_SYMBOL(memset); EXPORT_SYMBOL(__xchg8); EXPORT_SYMBOL(__xchg32); EXPORT_SYMBOL(__cmpxchg_u8); +EXPORT_SYMBOL(__cmpxchg_u16); EXPORT_SYMBOL(__cmpxchg_u32); EXPORT_SYMBOL(__cmpxchg_u64); #ifdef CONFIG_SMP diff --git a/arch/parisc/lib/bitops.c b/arch/parisc/lib/bitops.c index cae30a3eb6d9b..9df8100506427 100644 --- a/arch/parisc/lib/bitops.c +++ b/arch/parisc/lib/bitops.c @@ -71,4 +71,5 @@ unsigned long notrace __xchg8(char x, volatile char *ptr) =20 CMPXCHG(u64) CMPXCHG(u32) +CMPXCHG(u16) CMPXCHG(u8) --=20 2.40.1 From nobody Wed Dec 17 23:10:08 2025 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 EC33E168AE6; Wed, 1 May 2024 23:01:32 +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=1714604493; cv=none; b=PcdmXomb7tV+QV9oJxlSO1wdcxFr0OqIOM0Ns1zaVUrRfZ5HEeJQEy0uae5K8nCIgZr8Y0Y95zD1SN1FR7ixMsuYz1sTqBzmn7uIufYIRDcorTp9PogcwpqlcdnbF5GxNtdsNRe7qkhjcIFOLBI8DAi2Dzgm0gC9nZVDe3SnRQ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714604493; c=relaxed/simple; bh=Zs6ak+wPmG4tPQkLrLcc6JxAJjrKyJZjKo6tat/+S/g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ubU8WkWbUWzO2Lw01U4Y122Alo4yFplFsIR8mVpiijMhKlEbDTdAoUNHSMdF7F+nY2tFSIBA4xNli4O2oAcxS0y9zg8jIaHVHX+o3o6vrZndsl5Leigcw2x1MLP7BF3wpRXaeKbiPR7J4T9TLXM8vcPj3C1G4lyDbHgHUbNToXY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XH9vIivI; 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="XH9vIivI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95074C4AF51; Wed, 1 May 2024 23:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714604492; bh=Zs6ak+wPmG4tPQkLrLcc6JxAJjrKyJZjKo6tat/+S/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XH9vIivIX47KRQExC5xnU+LZC/uG5D0FeEfAoXkVPwo/PTEd9yqIYpCPKiZcS7ifl 3ERfMzuFeuTI57s+bH5QGzcUtcsD0t7XyR0NyJeMNKEesobUphmk37JASgd+wTWv9h jeCYJ+rXWPe8/H/pmlpj8BziFD6iXQYJ34DCpQAvMFw8tl4VZnG/kWqSOGfqulujH4 VrvpnKeTVU8fHuwPcCU/cFmzzdvGWyfOUKt+GjhBXzpXhXHgpVtwfnork9aIxwRNhk wfYkihPp4voUhbeAJqC5JMczxccduyhU+c+6FuCRt/x2j5E/AR8jAI+ntK/qSgNUx5 oXHnotmaZeiMQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id D3895CE2281; Wed, 1 May 2024 16:01:31 -0700 (PDT) From: "Paul E. McKenney" To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Cc: elver@google.com, akpm@linux-foundation.org, tglx@linutronix.de, peterz@infradead.org, dianders@chromium.org, pmladek@suse.com, arnd@arndb.de, torvalds@linux-foundation.org, kernel-team@meta.com, "Paul E. McKenney" Subject: [PATCH v2 cmpxchg 09/13] lib: Add one-byte emulation function Date: Wed, 1 May 2024 16:01:26 -0700 Message-Id: <20240501230130.1111603-9-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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 cmpxchg() would be extremely useful. Therefore, provide cmpxchg_emu_u8() that emulates one-byte cmpxchg() in terms of four-byte cmpxchg(). Note that this emulations is 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. ] [ paulmck: Drop two-byte support per Arnd Bergmann feedback. ] Link: https://lore.kernel.org/all/0733eb10-5e7a-4450-9b8a-527b97c842ff@paul= mck-laptop/ Signed-off-by: Paul E. McKenney Acked-by: Marco Elver Cc: Andrew Morton Cc: Thomas Gleixner Cc: "Peter Zijlstra (Intel)" Cc: Douglas Anderson Cc: Petr Mladek Cc: Arnd Bergmann Cc: --- arch/Kconfig | 3 +++ include/linux/cmpxchg-emu.h | 15 +++++++++++++ lib/Makefile | 1 + lib/cmpxchg-emu.c | 45 +++++++++++++++++++++++++++++++++++++ 4 files changed, 64 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 9f066785bb71d..284663392eef8 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_EMU + bool + endmenu diff --git a/include/linux/cmpxchg-emu.h b/include/linux/cmpxchg-emu.h new file mode 100644 index 0000000000000..998deec67740a --- /dev/null +++ b/include/linux/cmpxchg-emu.h @@ -0,0 +1,15 @@ +/* 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); + +#endif /* __LINUX_CMPXCHG_EMU_H */ diff --git a/lib/Makefile b/lib/Makefile index ffc6b2341b45a..cc3d52fdb477d 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_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..27f6f97cb60dd --- /dev/null +++ b/lib/cmpxchg-emu.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Emulated 1-byte cmpxchg operation for architectures lacking direct + * support for this size. This is 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)); // Overridden above. + } while (ret !=3D old32.w); + return old; +} +EXPORT_SYMBOL_GPL(cmpxchg_emu_u8); --=20 2.40.1 From nobody Wed Dec 17 23:10:08 2025 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 EF83B168AEC; Wed, 1 May 2024 23:01:32 +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=1714604493; cv=none; b=gnJKW8sH2PySUD66dtHR7W+4aLXqcv47WqQeDEq4zk6Ksl3w+oM8UNcvKReg4/ptIg5q1RTOa0RFp67eFp1OoRfe658qNJnO9ngcLtjJEhE0aWCRFXuddTNZk4OR/EXBm4a4lH88YGEo4oNaXbyjjof7MyDEb9x2gcOrS6Z2igI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714604493; c=relaxed/simple; bh=225e9ZrZUo35qiu06QPAPMUsNmM/XjwmxVyvd0jYw/w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZPwVoTZZcN9p4DHJKy3xU4iexufohRc6lJhvfRF7lhYT+ZsLYStNAWj8x/xQCoFLebMuR/7aPuxU+j5BEcQXvWzPUexPk3xb39qKfYMEgrkZuqQrPnoni0hOcrM18ER6QPoBAVIj/W/UHOwYVZcRW41dDnz54/jc2mC1g1X5HJo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aW6xdmzw; 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="aW6xdmzw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F534C4AF54; Wed, 1 May 2024 23:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714604492; bh=225e9ZrZUo35qiu06QPAPMUsNmM/XjwmxVyvd0jYw/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aW6xdmzw+K9cnrAtCo3noevENO5U0fkbybYY/UG7BhPW577IP7aufNJRTbTtMF6kP IpGrc+z2gPPwy1MUtxwFVwzfkh8KNfCqU7g+D5yXJ9hf+vhd7f5gi3ZZ70p5V09Nfl fYZK5UCMfbNRfu5Cab6uaz8D3g8Wf7MO9DUD54N8SIiQhYiW0WM+/Y1uLJaK2/7m05 3pLr8wBSv6mV6PI5iK5ONHxInz09CrEOPRKXPS2Mo7gTAQJLBF6nojWdDau/HIPndq zpGvOVyprRXvXtQzxqXwGnkNDVJi5GHGvaKWXEfRFw2H0Z+RovEE28ZANSFKQEmozc SH+3pQ9XMv+rA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id D6CB7CE28A3; Wed, 1 May 2024 16:01:31 -0700 (PDT) From: "Paul E. McKenney" To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Cc: elver@google.com, akpm@linux-foundation.org, tglx@linutronix.de, peterz@infradead.org, dianders@chromium.org, pmladek@suse.com, arnd@arndb.de, torvalds@linux-foundation.org, kernel-team@meta.com, "Paul E. McKenney" , Vineet Gupta , Andi Shyti , Andrzej Hajda , Palmer Dabbelt , linux-snps-arc@lists.infradead.org Subject: [PATCH v2 cmpxchg 10/13] ARC: Emulate one-byte cmpxchg Date: Wed, 1 May 2024 16:01:27 -0700 Message-Id: <20240501230130.1111603-10-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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() to emulate one-byte cmpxchg() on arc. [ paulmck: Drop two-byte support per Arnd Bergmann feedback. ] [ paulmck: Apply feedback from Naresh Kamboju. ] [ paulmck: Apply kernel test robot feedback. ] 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 | 33 ++++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig index 99d2845f3feb9..5bf6137f0fd47 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_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..2102ce076f28b 100644 --- a/arch/arc/include/asm/cmpxchg.h +++ b/arch/arc/include/asm/cmpxchg.h @@ -8,6 +8,7 @@ =20 #include #include +#include =20 #include #include @@ -46,6 +47,9 @@ __typeof__(*(ptr)) _prev_; \ \ switch(sizeof((_p_))) { \ + case 1: \ + _prev_ =3D (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)_p_, (uintp= tr_t)_o_, (uintptr_t)_n_); \ + break; \ case 4: \ _prev_ =3D __cmpxchg(_p_, _o_, _n_); \ break; \ @@ -65,16 +69,27 @@ __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_, (uintptr_t)_o_, (uintptr_= t)_n_); \ + _prev_ =3D (__typeof__(*(ptr)))__flags; \ + break; \ + 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 Wed Dec 17 23:10:08 2025 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 F208D168AEE; Wed, 1 May 2024 23:01:32 +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=1714604493; cv=none; b=F3EJAG2MJqDhE68IcXYIYxH8IFQbOMLg6rCGfn/bZATs+rksJqRBoqg971iyLmXq1FtJnuzjmPwP8CQEWgG4UQpW3XRhqqMc74wda7+HP6kg8Cg+7zIrsw5QyJ9QkBxvpUnxe8ztWnI6ihc2e1CABi+Hwuj3/XrEFxc8AfAfpLI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714604493; c=relaxed/simple; bh=WKYKHYI+0R9pnBOWkWIHPz6LwRVJ8kFwJ9YA0/qhV2w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=V3q8zQEmnvfAaflKN4vRdalhuRr4zHYSrvI6X6G97j4Fwx6aUlIudmfKcUMMqYqUCmAiGcERsGg/Q3eRIhMOU+kYczVmmuvgkWdHSk8x8a/1x+nBBgqf0xVceEFDorWjrXfoEcMUQJatz2H+vrjFFNCzPxJ59RNrqCF8uEvJCbc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dkWvtQ6I; 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="dkWvtQ6I" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98781C4AF53; Wed, 1 May 2024 23:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714604492; bh=WKYKHYI+0R9pnBOWkWIHPz6LwRVJ8kFwJ9YA0/qhV2w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dkWvtQ6ImaDQCpaRW/GM9Kxzl0aMNvM9bdSFLU8tjP3IWqGR94n9mzXRMHpo/vVOg mRUw4scDFHfgYIlsKRdUSg6sInyTZ5IaA9+LDGZUtQev4+wh4bkZ7zPARSE3KsOIwh fN0WTi/qhrENELvVALKC3tNx1KI/JlCvBW268k8W+O5v1UbuLrOoySYEpEExLn0+iP 4a6kepf53caGhWEzeqvAaAH+azO6u6lF45KeQ/BcJzJsbKnkdTGoaW2uaS0oDpGrBb J6AJFvndPWBPuOFmc2GFTGW4wZks5AWHN+kPL9lsT8tPCs5aWon5m62Qh6k8zrv5T7 nAMNrZzVCuA2w== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id D9D84CE28A8; Wed, 1 May 2024 16:01:31 -0700 (PDT) From: "Paul E. McKenney" To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Cc: elver@google.com, akpm@linux-foundation.org, tglx@linutronix.de, peterz@infradead.org, dianders@chromium.org, pmladek@suse.com, arnd@arndb.de, torvalds@linux-foundation.org, kernel-team@meta.com, "Paul E. McKenney" , Yujie Liu , Guo Ren , linux-csky@vger.kernel.org Subject: [PATCH v2 cmpxchg 11/13] csky: Emulate one-byte cmpxchg Date: Wed, 1 May 2024 16:01:28 -0700 Message-Id: <20240501230130.1111603-11-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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() to emulate one-byte cmpxchg() on csky. [ paulmck: Apply kernel test robot feedback. ] [ paulmck: Drop two-byte support per Arnd Bergmann feedback. ] Co-developed-by: Yujie Liu Signed-off-by: Yujie Liu Signed-off-by: Paul E. McKenney Tested-by: Yujie Liu Cc: Guo Ren Cc: Arnd Bergmann Cc: Reviewed-by: Guo Ren --- arch/csky/Kconfig | 1 + arch/csky/include/asm/cmpxchg.h | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/arch/csky/Kconfig b/arch/csky/Kconfig index d3ac36751ad1f..5479707eb5d10 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_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..db6dda47184e4 100644 --- a/arch/csky/include/asm/cmpxchg.h +++ b/arch/csky/include/asm/cmpxchg.h @@ -6,6 +6,7 @@ #ifdef CONFIG_SMP #include #include +#include =20 #define __xchg_relaxed(new, ptr, size) \ ({ \ @@ -61,6 +62,9 @@ __typeof__(old) __old =3D (old); \ __typeof__(*(ptr)) __ret; \ switch (size) { \ + case 1: \ + __ret =3D (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uint= ptr_t)__old, (uintptr_t)__new); \ + break; \ case 4: \ asm volatile ( \ "1: ldex.w %0, (%3) \n" \ @@ -91,6 +95,9 @@ __typeof__(old) __old =3D (old); \ __typeof__(*(ptr)) __ret; \ switch (size) { \ + case 1: \ + __ret =3D (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uint= ptr_t)__old, (uintptr_t)__new); \ + break; \ case 4: \ asm volatile ( \ "1: ldex.w %0, (%3) \n" \ @@ -122,6 +129,9 @@ __typeof__(old) __old =3D (old); \ __typeof__(*(ptr)) __ret; \ switch (size) { \ + case 1: \ + __ret =3D (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uint= ptr_t)__old, (uintptr_t)__new); \ + break; \ case 4: \ asm volatile ( \ RELEASE_FENCE \ --=20 2.40.1 From nobody Wed Dec 17 23:10:08 2025 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 31477168B10; Wed, 1 May 2024 23:01:32 +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=1714604493; cv=none; b=ESw3IBFe0L6VyFb+JpevCuAggcCs0RowuYtH2bLoo/Tbipfam5b5ZUoUYAOYVR5QOj4jOr7+wyf3X9fFNQf8JrcRTbvL+4i26d7O4w0ujjkhWsUqRk+MBe7YG5AV23pcaXWqNDvg/YnX+H62I4RtZPQ0RO7rarH4Qu0ASJ5exXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714604493; c=relaxed/simple; bh=PpSTQpZbHQunQSUzzPQvUIJ+CP30HDC9CfjkaUYmrk4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eaGLkvhzKPB+P9gI7SM71TMpys8ER/wPvXiUQZcdV72AcUXmv65EBqdyQpakM2DT+Qm6CzN/mMZG1Sn+W1xZaS3cTrOpiR3vY5Caw29AROX2Vog+cp1hwi3j+Kr9rOvRuvogfgB4WbGU0VZLjgefB6vPUJnSUFUps79tJXLBcnY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=udk4pKYq; 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="udk4pKYq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC62FC4AF63; Wed, 1 May 2024 23:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714604492; bh=PpSTQpZbHQunQSUzzPQvUIJ+CP30HDC9CfjkaUYmrk4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=udk4pKYqRq0ueXXLHSRjrkKMd/zpUR+9miHTot+JmCll3YBJkGiBLy86jszq+qFzF GeiObNB8nitkHY1DOg59JDhvvnvfgvAlFcK0cjZqjpZ/ssuPrnPX606CQdDWYZA9vm ONxY1yJYUndEIBYXfeTXWQQYDUw79U1RTnQDHrE3HBeEN5D2Yh4dVy5ZnfXIHoTenM tVSKIczrGG7Zg4rkoYiLRrVdBAN2aYxyZiKsbOGqpPEQMk5hRz6G23DnMoepDRx0me ZhR/DNTlAzRfa6sR+giejx0/bFLv/kZQfz865i0CFh/ldfTHdBFcL3zRfpLmXyCB1T XVsxhkv6E0z/g== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id DCFFECE2A4B; Wed, 1 May 2024 16:01:31 -0700 (PDT) From: "Paul E. McKenney" To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Cc: elver@google.com, akpm@linux-foundation.org, tglx@linutronix.de, peterz@infradead.org, dianders@chromium.org, pmladek@suse.com, arnd@arndb.de, torvalds@linux-foundation.org, kernel-team@meta.com, "Paul E. McKenney" , Andi Shyti , Palmer Dabbelt , Masami Hiramatsu , linux-sh@vger.kernel.org Subject: [PATCH v2 cmpxchg 12/13] sh: Emulate one-byte cmpxchg Date: Wed, 1 May 2024 16:01:29 -0700 Message-Id: <20240501230130.1111603-12-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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() to emulate one-byte cmpxchg() on sh. [ paulmck: Drop two-byte support per Arnd Bergmann feedback. ] [ paulmck: Apply feedback from Naresh Kamboju. ] [ Apply Geert Uytterhoeven feedback. ] Signed-off-by: Paul E. McKenney Cc: Andi Shyti Cc: Palmer Dabbelt Cc: Masami Hiramatsu Cc: Arnd Bergmann Cc: --- arch/sh/Kconfig | 1 + arch/sh/include/asm/cmpxchg.h | 3 +++ 2 files changed, 4 insertions(+) diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig index 2ad3e29f0ebec..f47e9ccf4efd2 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_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..1e5dc5ccf7bf5 100644 --- a/arch/sh/include/asm/cmpxchg.h +++ b/arch/sh/include/asm/cmpxchg.h @@ -9,6 +9,7 @@ =20 #include #include +#include =20 #if defined(CONFIG_GUSA_RB) #include @@ -56,6 +57,8 @@ static inline unsigned long __cmpxchg(volatile void * ptr= , unsigned long old, unsigned long new, int size) { switch (size) { + case 1: + return cmpxchg_emu_u8(ptr, old, new); case 4: return __cmpxchg_u32(ptr, old, new); } --=20 2.40.1 From nobody Wed Dec 17 23:10:08 2025 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 EDDB8168AEB; Wed, 1 May 2024 23:01:32 +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=1714604493; cv=none; b=EaGS9UOhlOXApKgn9+2oZ5R6iLGkOeV8JBVPT9clDrAW0ZuK4ngA7DYJwJKj430voTNuZxTwmT5lesqoD/ewqYZmHiiPPBwKicEQtvRJpTkQNhwSlUIHQUbMnmOeOZSesKYKLCUNe//fSl4I+MIG2Sp7gymprkG8fjkz376LnIc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714604493; c=relaxed/simple; bh=SsfSYlvMJfbrFJhxWSLRoEWcjcncMnxVxwE9E1US2+0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dPwjrva52oRs2FawzjvVgOWpg9aS6+I4qv6z2ywuEAI/mfD3DUdDrpI5K7m3rMwbbA9KBstIWhZ0FbhvBpar1zijsUZ+Yq1XX5VL3QpeFBj0GKKlJpm6lQY/LXdt8O5TAJFcM3CazauKcCFoAwTr4yudS5HEtwsiUCWvYVzIW6o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=V9pm7RI3; 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="V9pm7RI3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A4A2C4AF5F; Wed, 1 May 2024 23:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714604492; bh=SsfSYlvMJfbrFJhxWSLRoEWcjcncMnxVxwE9E1US2+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V9pm7RI313isYajaxU6MI4BtAEKwQYVKZpihtD6pDfAyLsbTlYMwrzDphvrx4uDqL ouVZ62brQPFvjq/vyub/X6/1rRTblnD+A6lCjJcZ4kz8J9NrxHN/gvSaAxgrbRoUWK EIGtR/OWw60jIByxODo+T7frJzRzgSvIdO09H+YlvB2j1sJMe3v0dtRq0TsISor+M2 uOIU9jypAZqS9REjSY1iqVzoN41WLmWw9hRRW7frIbOFc3c3lmaA3Pzj48K8Wrqijs QyaI7ki+x45dqAgw19g5nDy/dSBbC/IM1trFtyCXIfb5dBoWuSnPhwGh29Xrmg/F/L saURCZYoT6Cpg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id E0ACDCE2A4C; Wed, 1 May 2024 16:01:31 -0700 (PDT) From: "Paul E. McKenney" To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Cc: elver@google.com, akpm@linux-foundation.org, tglx@linutronix.de, peterz@infradead.org, dianders@chromium.org, pmladek@suse.com, arnd@arndb.de, torvalds@linux-foundation.org, kernel-team@meta.com, "Paul E. McKenney" , Yujie Liu , Andi Shyti , Geert Uytterhoeven Subject: [PATCH v2 cmpxchg 13/13] xtensa: Emulate one-byte cmpxchg Date: Wed, 1 May 2024 16:01:30 -0700 Message-Id: <20240501230130.1111603-13-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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() to emulate one-byte cmpxchg() on xtensa. [ paulmck: Apply kernel test robot feedback. ] [ paulmck: Drop two-byte support per Arnd Bergmann feedback. ] [ Apply Geert Uytterhoeven feedback. ] Signed-off-by: Paul E. McKenney Tested-by: Yujie Liu Cc: Andi Shyti Cc: Geert Uytterhoeven Cc: Arnd Bergmann Cc: "Peter Zijlstra (Intel)" --- arch/xtensa/Kconfig | 1 + arch/xtensa/include/asm/cmpxchg.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig index f200a4ec044e6..d3db28f2f8110 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_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..95e33a913962d 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,7 @@ 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(ptr, old, new); case 4: return __cmpxchg_u32(ptr, old, new); default: __cmpxchg_called_with_bad_pointer(); return old; --=20 2.40.1