From patchwork Tue Sep 22 07:33:50 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bradley Morgan X-Patchwork-Id: 2309587 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=hYJtMNEL; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mainlining.org header.i=@mainlining.org header.a=rsa-sha256 header.s=202507r header.b=I+lrooYe; dkim=fail reason="signature verification failed" header.d=mainlining.org header.i=@mainlining.org header.a=ed25519-sha256 header.s=202507e header.b=4B5H3lLT; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hq6hq6wQ6z1y1m for ; Wed, 23 Sep 2026 03:36:27 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zACE6s5069Ya5bLVb/X1tcGxkjE2S94VX7hrFpyTmN8=; b=hYJtMNELJti22H bH7OswW3Ue/6EAAa2fniGKlQpMKeKrwGZyTPrm4MhAcv1HBGMVp0rbjfsS6PlAEPBpJDGhOZ6itjR 1g4Mw2XwMfsIIZZKN/jIS5w0gI+B9PcrZy66ZGNU3Cwyg7U6ouWOPuKxqMi29usi+4gvAJYo0imHq c0TLNFJY7d7C9Tn1OeoJIg82Nv78GXBkmKanVfz1De1TTY3SU/Uc8kLIXbGWPEb1aLqfRCt5UPc/5 438j4D1kdFSlATs1e0Fzzg9unMZGmUHdI1KTkIbMPr2JgvYMtbjWqI9B8qAO4K3yXFYtioVLsOsjG D9818eC1ZOv7KzCfjRDQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x94Pq-00000006Dve-1stz; Tue, 22 Sep 2026 17:36:26 +0000 Received: from mail.mainlining.org ([5.75.144.95]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x94Pn-00000006Du0-0o8F for linux-snps-arc@lists.infradead.org; Tue, 22 Sep 2026 17:36:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; s=202507r; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1790098433; bh=DV+S+YBKPI4yE6gLNe9ePuD 8ye5fzLkcyxtpk3kLyU4=; b=I+lrooYevbZ0Tg8wkwIQhM91+vocihHYqHNTDYx4RtT7Jzn+Ql hZHU1EvQtFSJbjslt+jQcMA3pkiqZgtY1lSg5wC1NgqOSdPcteG5NkGT9Jd3DrZAWhbGSes+sps PpMPMWm0S+UfEmdhb3RpLeq+uinPXUfDP/WMraaWx2FMerxCAdHZr14XhPcI+1972Hbsp1yC0dn 41bYsWbwKKEf0w/lV7UhJ3vKXO8kwuTkTbNKZ71MjjadOEGuVP2F+90xjGHT1R94MDb381fGTSm 3Rkt7Vc0362w8w7LcJVsymGaD8ezU+0pQ36VJrJCZGuuOmw+K0NKtHLnh2tijmHS0tg==; DKIM-Signature: v=1; a=ed25519-sha256; s=202507e; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1790098433; bh=DV+S+YBKPI4yE6gLNe9ePuD 8ye5fzLkcyxtpk3kLyU4=; b=4B5H3lLTqQQDDZX/g8Fy3eGlTbWYmcr09GJ/Ki1qMnDbpF9pch CydZm/GlGh6JsTty1EOWo0x5k7DfHD9O2bAA==; From: Bradley Morgan To: Andrew Morton , Vineet Gupta , Guo Ren , Yoshinori Sato , Rich Felker , Chris Zankel , Max Filippov Cc: Arnd Bergmann , "Paul E . McKenney" , David Laight , John Paul Adrian Glaubitz , linux-snps-arc@lists.infradead.org, linux-csky@vger.kernel.org, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, Bradley Morgan Subject: [PATCH 1/5] lib: Add two-byte cmpxchg emulation function Date: Tue, 22 Sep 2026 17:33:50 +0000 Message-ID: <20260922173354.14404-2-brads@mainlining.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260922173354.14404-1-brads@mainlining.org> References: <20260922173354.14404-1-brads@mainlining.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260922_103623_386017_FE376165 X-CRM114-Status: GOOD ( 17.76 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: cmpxchg_emu_u8() emulates one-byte cmpxchg() in terms of four-byte cmpxchg() for the architectures lacking native one-byte atomics. The same architectures also lack native two-byte cmpxchg(), where su [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 DMARC_PASS DMARC pass policy X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org cmpxchg_emu_u8() emulates one-byte cmpxchg() in terms of four-byte cmpxchg() for the architectures lacking native one-byte atomics. The same architectures also lack native two-byte cmpxchg(), where such an operation is not supported and either fails to compile via BUILD_BUG() or fails to link, because the bad pointer sentinels these architectures declare are never defined. Add cmpxchg_emu_u16(), the two-byte sibling. It reads the enclosing word with READ_ONCE(), splices the two target bytes through a union and loops on cmpxchg() of the full word until the compare succeeds. Like cmpxchg_emu_u8() it is fully ordered. Unlike cmpxchg_emu_u8() it casts the old and new values to u16 internally and returns unsigned long, taking the old and new values as unsigned long, per the suggestion from David Laight. The switch statements in the architecture macros instantiate every size case, so a cmpxchg() on a pointer type checks the two-byte case as well, and a u16 parameter or return would make the macro casts and return conversions warn there. With unsigned long parameters and return the call sites need no narrowing casts, pointer exchanges compile warning free, and the function still compares and returns exactly the 16 bits the caller asked for, which matches the hardware cmpxchg r16 behaviour where a 16-bit compare only looks at the low 16 bits of the register. cmpxchg_emu_u8() keeps returning the old value unmasked, so a caller that passes a wider old than 8 bits still gets it back as passed, matching the behaviour the one-byte emulator always had. The Kconfig symbol gating this file is renamed from ARCH_NEED_CMPXCHG_1_EMU to ARCH_NEED_CMPXCHG_1_2_EMU, as it now selects both the one-byte and the two-byte emulation. Suggested-by: Paul E. McKenney Suggested-by: David Laight Signed-off-by: Bradley Morgan --- arch/Kconfig | 2 +- arch/arc/Kconfig | 2 +- arch/csky/Kconfig | 2 +- arch/sh/Kconfig | 2 +- arch/xtensa/Kconfig | 2 +- include/linux/cmpxchg-emu.h | 4 +++- lib/Makefile | 2 +- lib/cmpxchg-emu.c | 38 +++++++++++++++++++++++++++++++++---- 8 files changed, 43 insertions(+), 11 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 3bb2e568f5b1..d56064797e09 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1817,7 +1817,7 @@ config CC_HAS_SANE_FUNCTION_ALIGNMENT # strict alignment always, even with -falign-functions. def_bool CC_HAS_MIN_FUNCTION_ALIGNMENT || CC_IS_CLANG -config ARCH_NEED_CMPXCHG_1_EMU +config ARCH_NEED_CMPXCHG_1_2_EMU bool config ARCH_WANTS_PRE_LINK_VMLINUX diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig index 80e61175bf52..0e91d254eccb 100644 --- a/arch/arc/Kconfig +++ b/arch/arc/Kconfig @@ -14,7 +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_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/csky/Kconfig b/arch/csky/Kconfig index 4331313a42ff..5f26e8615d7d 100644 --- a/arch/csky/Kconfig +++ b/arch/csky/Kconfig @@ -37,7 +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_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/sh/Kconfig b/arch/sh/Kconfig index d60f1d5a94c0..09e556fced01 100644 --- a/arch/sh/Kconfig +++ b/arch/sh/Kconfig @@ -14,7 +14,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 ARCH_NEED_CMPXCHG_1_2_EMU select CPU_NO_EFFICIENT_FFS select DMA_DECLARE_COHERENT select GENERIC_ATOMIC64 diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig index f2f9cd9cde50..62019fd444d4 100644 --- a/arch/xtensa/Kconfig +++ b/arch/xtensa/Kconfig @@ -14,7 +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_NEED_CMPXCHG_1_2_EMU select ARCH_USE_MEMTEST select ARCH_USE_QUEUED_RWLOCKS select ARCH_USE_QUEUED_SPINLOCKS diff --git a/include/linux/cmpxchg-emu.h b/include/linux/cmpxchg-emu.h index 998deec67740..2db70f1e3925 100644 --- a/include/linux/cmpxchg-emu.h +++ b/include/linux/cmpxchg-emu.h @@ -4,12 +4,14 @@ * lacking direct support for these sizes. These are implemented in terms * of 4-byte cmpxchg operations. * - * Copyright (C) 2024 Paul E. McKenney. + * Copyright (C) 2024 Paul E. McKenney + * Copyright (C) 2026 Bradley Morgan */ #ifndef __LINUX_CMPXCHG_EMU_H #define __LINUX_CMPXCHG_EMU_H uintptr_t cmpxchg_emu_u8(volatile u8 *p, uintptr_t old, uintptr_t new); +unsigned long cmpxchg_emu_u16(volatile u16 *p, unsigned long old, unsigned long new); #endif /* __LINUX_CMPXCHG_EMU_H */ diff --git a/lib/Makefile b/lib/Makefile index 43421c39d21b..d0e69312176a 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -202,7 +202,7 @@ obj-$(CONFIG_CODE_TAGGING) += codetag.o lib-$(CONFIG_GENERIC_BUG) += bug.o obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o -obj-$(CONFIG_ARCH_NEED_CMPXCHG_1_EMU) += cmpxchg-emu.o +obj-$(CONFIG_ARCH_NEED_CMPXCHG_1_2_EMU) += cmpxchg-emu.o obj-$(CONFIG_DYNAMIC_DEBUG_CORE) += dynamic_debug.o #ensure exported functions have prototypes diff --git a/lib/cmpxchg-emu.c b/lib/cmpxchg-emu.c index 27f6f97cb60d..25c69224a759 100644 --- a/lib/cmpxchg-emu.c +++ b/lib/cmpxchg-emu.c @@ -1,10 +1,11 @@ // 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. + * 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. + * Copyright (C) 2024 Paul E. McKenney + * Copyright (C) 2026 Bradley Morgan */ #include @@ -43,3 +44,32 @@ uintptr_t cmpxchg_emu_u8(volatile u8 *p, uintptr_t old, uintptr_t new) 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. */ +unsigned long cmpxchg_emu_u16(volatile u16 *p, unsigned long old, unsigned long new) +{ + u32 *p32 = (u32 *)(((uintptr_t)p) & ~0x3); + int i = (((uintptr_t)p) & 0x2) / 2; + union u16_32 old32; + union u16_32 new32; + u32 ret; + + WARN_ON_ONCE(((uintptr_t)p) & 0x1); + ret = READ_ONCE(*p32); + do { + old32.w = ret; + if (old32.h[i] != (u16)old) + return (unsigned long)old32.h[i]; + new32.w = old32.w; + new32.h[i] = (u16)new; + instrument_atomic_read_write(p, 2); + ret = data_race(cmpxchg(p32, old32.w, new32.w)); // Overridden above. + } while (ret != old32.w); + return (u16)old; +} +EXPORT_SYMBOL_GPL(cmpxchg_emu_u16); From patchwork Tue Sep 22 07:33:51 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bradley Morgan X-Patchwork-Id: 2309586 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Ba8fLifx; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mainlining.org header.i=@mainlining.org header.a=rsa-sha256 header.s=202507r header.b=RgdRjyED; dkim=fail reason="signature verification failed" header.d=mainlining.org header.i=@mainlining.org header.a=ed25519-sha256 header.s=202507e header.b=54xM5N6K; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hq6hn6Zlnz1y1m for ; Wed, 23 Sep 2026 03:36:25 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CwOpSN2gNulSZfSgV67THJIy7CCkFMoCcVWjoOdR1fI=; b=Ba8fLifx3cvyz6 SBtROl0eyOkBYSo6K028zCC47PAfEmr8g+jvGaiaB/FVYp0DQrHjUJur0ikgYHHAoYr4XEzZHCrl6 6O4jahBMUMjFGB3y8UwMFde29MVBwiVEofh45++oId3DyriSZUmxyARx/OET1Sss/eFKAUT30qyT0 IL3Hpgejy6wC3zvPOgzY0q2jrL8dgaRFrMycNzTPb8WhyT8a4bfGEVBtG9QsDLPpq+cl0PpsKohdB rBNWkFPaAiVt4Z4BBl+m+abn84qsd1Btqi2ajLwRWEZneBSInuMfo4Rjs7mNKtmtEjEFW6jBriehE Z2Fcd6wSe+Lascxe4NlA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x94Po-00000006Duw-1hQm; Tue, 22 Sep 2026 17:36:24 +0000 Received: from mail.mainlining.org ([5.75.144.95]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x94Pm-00000006DtL-0Sb8 for linux-snps-arc@lists.infradead.org; Tue, 22 Sep 2026 17:36:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; s=202507r; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1790098434; bh=e1GcMnqFLCYDoymp6RLJVeb pmtQeo9UYDw7sYBJUhCo=; b=RgdRjyEDbXNkMPQ8KeUZHOgR41025YtvXpBr9YubcWfvfFrTkH WsjQGi5iKF0/Q7SxfbLq32+CVgwtchQ06SJ5gzIcpi3WGrBxvO4s7NUL6vMe+4bJHUqRhxoD10/ 67IJY2fFgPoeyXd+/kWcUxSXjv/IgzHlouVSWVrT1b3BW0UFuKz9A1hVjASVqQVX0V/Qvbd0fH8 vHRo8tBFCz/m8QLnTFlKT9PwzfrH5lMW1uOW2QIl5C5/zUZBuVD/2HZxGFpv6GNPma2OJu/CpKj 7q8LI2RexEJBTUq92MqDBL7Vr+uaH85fX/bcVlapDaVsVUx7mXpsTMIIheGpxXR1AhQ==; DKIM-Signature: v=1; a=ed25519-sha256; s=202507e; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1790098434; bh=e1GcMnqFLCYDoymp6RLJVeb pmtQeo9UYDw7sYBJUhCo=; b=54xM5N6KOQWLgmVo6u80leBEDQVMX+gYb8ekcXt6NwZL2Szwo1 LHYwY7CewossBjldsNDBthMIOpoIFgYd7dDg==; From: Bradley Morgan To: Andrew Morton , Vineet Gupta , Guo Ren , Yoshinori Sato , Rich Felker , Chris Zankel , Max Filippov Cc: Arnd Bergmann , "Paul E . McKenney" , David Laight , John Paul Adrian Glaubitz , linux-snps-arc@lists.infradead.org, linux-csky@vger.kernel.org, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, Bradley Morgan Subject: [PATCH 2/5] ARC: Emulate two-byte cmpxchg Date: Tue, 22 Sep 2026 17:33:51 +0000 Message-ID: <20260922173354.14404-3-brads@mainlining.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260922173354.14404-1-brads@mainlining.org> References: <20260922173354.14404-1-brads@mainlining.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260922_103622_306590_72D53680 X-CRM114-Status: GOOD ( 11.39 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: ARC has no two-byte atomic compare and swap, so the arch_cmpxchg_relaxed() macro switch lets case 2 fall through to BUILD_BUG() via default. Route case 2 through the new cmpxchg_emu_u16(), which takes [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 DMARC_PASS DMARC pass policy X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org ARC has no two-byte atomic compare and swap, so the arch_cmpxchg_relaxed() macro switch lets case 2 fall through to BUILD_BUG() via default. Route case 2 through the new cmpxchg_emu_u16(), which takes the old and new values as unsigned long and narrows them itself, so the (uintptr_t) casts on _o_ and _n_ are no longer needed and the case 2 call passes them straight. The switch also now tests sizeof(*(_p_)) instead of sizeof((_p_)), which switched on the pointer and made the size 1 and size 2 cases dead code, routing every sub-word cmpxchg() through the 32-bit llock/scond pair and comparing whole words against sub-word values, so the compare almost never succeeded. The old and new values are now declared as unsigned long through (unsigned long)(0 ? *(_p_) : (old)), the idiom David Laight suggested, which type checks the arguments against the pointee, so cmpxchg(&p, 4, 5) no longer compiles silently. Signed-off-by: Bradley Morgan --- arch/arc/include/asm/cmpxchg.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/arch/arc/include/asm/cmpxchg.h b/arch/arc/include/asm/cmpxchg.h index 76f43db0890f..4596edfefa95 100644 --- a/arch/arc/include/asm/cmpxchg.h +++ b/arch/arc/include/asm/cmpxchg.h @@ -42,16 +42,19 @@ #define arch_cmpxchg_relaxed(ptr, old, new) \ ({ \ __typeof__(ptr) _p_ = (ptr); \ - __typeof__(*(ptr)) _o_ = (old); \ - __typeof__(*(ptr)) _n_ = (new); \ + unsigned long _old_ = (unsigned long)(0 ? *(_p_) : (old)); \ + unsigned long _new_ = (unsigned long)(0 ? *(_p_) : (new)); \ __typeof__(*(ptr)) _prev_; \ \ - switch(sizeof((_p_))) { \ + switch (sizeof(*(_p_))) { \ case 1: \ - _prev_ = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *__force)_p_, (uintptr_t)_o_, (uintptr_t)_n_); \ + _prev_ = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *__force)_p_, _old_, _new_); \ + break; \ + case 2: \ + _prev_ = (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *__force)_p_, _old_, _new_); \ break; \ case 4: \ - _prev_ = __cmpxchg(_p_, _o_, _n_); \ + _prev_ = (__typeof__(*(ptr)))__cmpxchg(_p_, _old_, _new_); \ break; \ default: \ BUILD_BUG(); \ @@ -64,8 +67,8 @@ #define arch_cmpxchg(ptr, old, new) \ ({ \ volatile __typeof__(ptr) _p_ = (ptr); \ - __typeof__(*(ptr)) _o_ = (old); \ - __typeof__(*(ptr)) _n_ = (new); \ + unsigned long _old_ = (unsigned long)(0 ? *(_p_) : (old)); \ + unsigned long _new_ = (unsigned long)(0 ? *(_p_) : (new)); \ __typeof__(*(ptr)) _prev_; \ unsigned long __flags; \ \ @@ -102,7 +105,7 @@ __typeof__(ptr) _p_ = (ptr); \ __typeof__(*(ptr)) _val_ = (val); \ \ - switch(sizeof(*(_p_))) { \ + switch (sizeof(*(_p_))) { \ case 4: \ _val_ = __arch_xchg(_p_, _val_); \ break; \ From patchwork Tue Sep 22 07:33:52 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bradley Morgan X-Patchwork-Id: 2309589 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=MTarutHC; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mainlining.org header.i=@mainlining.org header.a=rsa-sha256 header.s=202507r header.b=bZ38dyWM; dkim=fail reason="signature verification failed" header.d=mainlining.org header.i=@mainlining.org header.a=ed25519-sha256 header.s=202507e header.b=jnZiJ1Qj; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hq6hw0WrVz1y1m for ; Wed, 23 Sep 2026 03:36:32 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qyA8y1X/jw4Lf+OkE2z5XXcJcUYbjLIXey1Kmgo/ZSo=; b=MTarutHC23HDTh lhvGxuQrmv952EyJf8/Vt/s3FTUWlCcpbeYSdfhuOS8vAMxl4GOufMe3/Lp5e3yf0snsczgsntbJz lTHOWf4frkkLuc1/9KfQprJIOApau/ujBLovU9Mo51ZSHow4kdniovptaUo5tn4bwRXm5sm5PFPCF V0ypwaPiiQOaE41trWrPY+2Tu9x9mEuZC2efHYPcVkSjJkwWtvL0DEcO9Bbj3ji3yNfn5phYiQVOj AcysoofmEjmTRaxjbr5oLJBh/4MW5cLeu13R1NwUK2r3x66ESCJq6j5D7jPMACiBfAJF0+rm08Hl2 KTrvU9tVCDEHK8C1yOMg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x94Pu-00000006DxP-2Dft; Tue, 22 Sep 2026 17:36:30 +0000 Received: from mail.mainlining.org ([5.75.144.95]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x94Pr-00000006Dvg-35bD for linux-snps-arc@lists.infradead.org; Tue, 22 Sep 2026 17:36:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; s=202507r; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1790098434; bh=ghYvDCJ6wWgl/DWKvRlZLjc r4JmsCO6Diem7VtlYvoo=; b=bZ38dyWMgd/G/6OMhHggQwAi2Id4aT8IYufucK56A4wyGw4Iuj z2W5xwZGeASaGF/HHJf8ssq8z4PoylGq2B1t7R6ut/d8M3Ij2LG7BjwOviGy/uB0NVYDwscv1JD 7kPkG1IQ6VVkHrlLt2lYDSGuvhjweGzQg3VXOPDtMA2RsQ6UWzausKwtTWqfJRhvMcA8RRPQNtO HTqLo1bFm7LJUzrUzxCrKuZJYb59yJZr/yDqMsOFU2kNCNhtPy0g0jAdHqhHquweKOujEeL+pJ4 vuncC6fMYzfNZrwUChfQxtVt+ggSqaj/oGkEp0xUGYy7/Zp9Vf17BnKlLL2u3mAWDOQ==; DKIM-Signature: v=1; a=ed25519-sha256; s=202507e; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1790098434; bh=ghYvDCJ6wWgl/DWKvRlZLjc r4JmsCO6Diem7VtlYvoo=; b=jnZiJ1QjwuyC2NRhs59khGUE4Z66oJnKO75veJ4E/0hcaljPvm ulv9bbDDiHprbgM5vKUmZm0jYzB24CcBNCDg==; From: Bradley Morgan To: Andrew Morton , Vineet Gupta , Guo Ren , Yoshinori Sato , Rich Felker , Chris Zankel , Max Filippov Cc: Arnd Bergmann , "Paul E . McKenney" , David Laight , John Paul Adrian Glaubitz , linux-snps-arc@lists.infradead.org, linux-csky@vger.kernel.org, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, Bradley Morgan Subject: [PATCH 3/5] sh: Emulate two-byte cmpxchg Date: Tue, 22 Sep 2026 17:33:52 +0000 Message-ID: <20260922173354.14404-4-brads@mainlining.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260922173354.14404-1-brads@mainlining.org> References: <20260922173354.14404-1-brads@mainlining.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260922_103627_927299_E9FDC714 X-CRM114-Status: GOOD ( 10.91 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: SH has no byte or halfword atomic memory operations, so the __cmpxchg() switch routes case 1 through cmpxchg_emu_u8() and lets case 2 fall through to __cmpxchg_called_with_bad_pointer(), which is decl [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 DMARC_PASS DMARC pass policy X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org SH has no byte or halfword atomic memory operations, so the __cmpxchg() switch routes case 1 through cmpxchg_emu_u8() and lets case 2 fall through to __cmpxchg_called_with_bad_pointer(), which is declared but never defined, so a two-byte cmpxchg() fails at link time. Route case 2 through the new cmpxchg_emu_u16(), which takes the old and new values as unsigned long, so the (unsigned long) casts move off the call and into _old_ and _new_ declarations that type check the old and new arguments against *ptr through (unsigned long)(0 ? *ptr : _o_), the idiom David Laight suggested, so cmpxchg(&p, 4, 5) no longer compiles silently. Acked-by: John Paul Adrian Glaubitz Signed-off-by: Bradley Morgan --- arch/sh/include/asm/cmpxchg.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/sh/include/asm/cmpxchg.h b/arch/sh/include/asm/cmpxchg.h index 1e5dc5ccf7bf..b87f59107b4e 100644 --- a/arch/sh/include/asm/cmpxchg.h +++ b/arch/sh/include/asm/cmpxchg.h @@ -59,6 +59,8 @@ static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old, switch (size) { case 1: return cmpxchg_emu_u8(ptr, old, new); + case 2: + return cmpxchg_emu_u16(ptr, old, new); case 4: return __cmpxchg_u32(ptr, old, new); } @@ -70,8 +72,10 @@ static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old, ({ \ __typeof__(*(ptr)) _o_ = (o); \ __typeof__(*(ptr)) _n_ = (n); \ - (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \ - (unsigned long)_n_, sizeof(*(ptr))); \ + unsigned long _old_ = (unsigned long)(0 ? *ptr : _o_); \ + unsigned long _new_ = (unsigned long)(0 ? *ptr : _n_); \ + (__typeof__(*(ptr))) __cmpxchg((ptr), _old_, \ + _new_, sizeof(*(ptr))); \ }) #include From patchwork Tue Sep 22 07:33:53 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bradley Morgan X-Patchwork-Id: 2309585 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=URXbDLz9; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mainlining.org header.i=@mainlining.org header.a=rsa-sha256 header.s=202507r header.b=A5/0/GOU; dkim=fail reason="signature verification failed" header.d=mainlining.org header.i=@mainlining.org header.a=ed25519-sha256 header.s=202507e header.b=NTp5knoE; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hq6hg6LGbz1y1m for ; Wed, 23 Sep 2026 03:36:19 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ly1mBS7p7gwebv64g3zDRoCjZueNwupCxIHcKEBGQhc=; b=URXbDLz9iKcH7m /jPfqZoaO1fAWt4BsD2EjOKMW65KVobc03XkBYARwKeJvEugdXkMGa2/XJu4ZtRB8WMLIqHPGLcD1 dneBGcOr5Ss72L6Rl5qTdz1Ukfj8alTAGQtLlm0NNGBMViykDhLOhz9sVBvV8pEMgbOqOHbzh0ade dZe90MLQL0fA9VN8JVv9uUUF37QGrcHFoA5PmjhXD9VXihccaLkeq6hr4UuY4bf5RJsAMMba9a/R9 HUf/zrPEYUgebjBOVOWlGvMgzrZWKY/LmubUWKcXu8lPND/KNKkBKy4V/1Ga7DmIpl+Y7k04Zq+Wg CyfP6WRW3n62r/Aa6B3g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x94Pi-00000006Dsl-1CSZ; Tue, 22 Sep 2026 17:36:18 +0000 Received: from mail.mainlining.org ([5.75.144.95]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x94Pg-00000006DsL-0KoJ for linux-snps-arc@lists.infradead.org; Tue, 22 Sep 2026 17:36:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; s=202507r; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1790098435; bh=wl+BtXFs/QJChJ/sOKgC86/ HKj3R5tfPpUhFH8oo0uc=; b=A5/0/GOUc+WvYs825/8ouOL1uBIBkqo06ZEzHpL/pV7+uEtN+b Q06RZe/uHEgOY77Uzlh5dL9QmnGwW+2nv5v1qBCVhyXNv4T8Uqdv2Yfcc8ENtyEoImQM/c7WOV8 YCs2e5QkHGlXhMJ+H5KckshFL2DoJqgx/era/7X5JIkCE0YBZeMvl+Q038j/sHyXO00VCzyFPGm kc2VoX6bR2Tw+Kt1LeLRBtpqbrdpVvVDQOuAsb8j2YgHfW4NrjXkxLnF+rgsXf3dHDeuCOwIYmb gNlbihmQLhGtzbM0wf1poT0eIdtdfFePxhoQW+obXpIAfDOsR7EGFDT9B2A5+J/SlVg==; DKIM-Signature: v=1; a=ed25519-sha256; s=202507e; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1790098435; bh=wl+BtXFs/QJChJ/sOKgC86/ HKj3R5tfPpUhFH8oo0uc=; b=NTp5knoEnFR7JN5OFPhBFH1QY9WSnU+vHpvP8lpWk2ed+OsGcb 0/J3nRC2j+Rb5PnC8PsP8xBvuryNvrIOpqBQ==; From: Bradley Morgan To: Andrew Morton , Vineet Gupta , Guo Ren , Yoshinori Sato , Rich Felker , Chris Zankel , Max Filippov Cc: Arnd Bergmann , "Paul E . McKenney" , David Laight , John Paul Adrian Glaubitz , linux-snps-arc@lists.infradead.org, linux-csky@vger.kernel.org, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, Bradley Morgan Subject: [PATCH 4/5] csky: Emulate two-byte cmpxchg Date: Tue, 22 Sep 2026 17:33:53 +0000 Message-ID: <20260922173354.14404-5-brads@mainlining.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260922173354.14404-1-brads@mainlining.org> References: <20260922173354.14404-1-brads@mainlining.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260922_103616_269817_2AA305F7 X-CRM114-Status: UNSURE ( 9.89 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: C-SKY has no two-byte atomic compare and swap, so the __cmpxchg() macros let case 2 fall through to BUILD_BUG() via default. Route case 2 through the new cmpxchg_emu_u16(), which takes the old and new [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 DMARC_PASS DMARC pass policy X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org C-SKY has no two-byte atomic compare and swap, so the __cmpxchg() macros let case 2 fall through to BUILD_BUG() via default. Route case 2 through the new cmpxchg_emu_u16(), which takes the old and new values as unsigned long, so the (uintptr_t) casts on __old and __new are no longer needed and the case 2 call passes them straight. The old and new values are declared as unsigned long through (unsigned long)(0 ? *(ptr) : (old)), the idiom David Laight suggested, which type checks the arguments against the pointee, so cmpxchg(&p, 4, 5) no longer compiles silently. Signed-off-by: Bradley Morgan --- arch/csky/include/asm/cmpxchg.h | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/arch/csky/include/asm/cmpxchg.h b/arch/csky/include/asm/cmpxchg.h index db6dda47184e..29dc56e4b7f1 100644 --- a/arch/csky/include/asm/cmpxchg.h +++ b/arch/csky/include/asm/cmpxchg.h @@ -57,13 +57,16 @@ #define __cmpxchg_relaxed(ptr, old, new, size) \ ({ \ __typeof__(ptr) __ptr = (ptr); \ - __typeof__(new) __new = (new); \ - __typeof__(new) __tmp; \ - __typeof__(old) __old = (old); \ + unsigned long __old = (unsigned long)(0 ? *(ptr) : (old)); \ + unsigned long __new = (unsigned long)(0 ? *(ptr) : (new)); \ + unsigned long __tmp; \ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 1: \ - __ret = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uintptr_t)__old, (uintptr_t)__new); \ + __ret = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, __old, __new); \ + break; \ + case 2: \ + __ret = (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *)__ptr, __old, __new); \ break; \ case 4: \ asm volatile ( \ @@ -90,13 +93,16 @@ #define __cmpxchg_acquire(ptr, old, new, size) \ ({ \ __typeof__(ptr) __ptr = (ptr); \ - __typeof__(new) __new = (new); \ - __typeof__(new) __tmp; \ - __typeof__(old) __old = (old); \ + unsigned long __old = (unsigned long)(0 ? *(ptr) : (old)); \ + unsigned long __new = (unsigned long)(0 ? *(ptr) : (new)); \ + unsigned long __tmp; \ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 1: \ - __ret = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uintptr_t)__old, (uintptr_t)__new); \ + __ret = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, __old, __new); \ + break; \ + case 2: \ + __ret = (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *)__ptr, __old, __new); \ break; \ case 4: \ asm volatile ( \ @@ -124,13 +130,16 @@ #define __cmpxchg(ptr, old, new, size) \ ({ \ __typeof__(ptr) __ptr = (ptr); \ - __typeof__(new) __new = (new); \ - __typeof__(new) __tmp; \ - __typeof__(old) __old = (old); \ + unsigned long __old = (unsigned long)(0 ? *(ptr) : (old)); \ + unsigned long __new = (unsigned long)(0 ? *(ptr) : (new)); \ + unsigned long __tmp; \ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 1: \ - __ret = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uintptr_t)__old, (uintptr_t)__new); \ + __ret = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, __old, __new); \ + break; \ + case 2: \ + __ret = (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *)__ptr, __old, __new); \ break; \ case 4: \ asm volatile ( \ From patchwork Tue Sep 22 07:33:54 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bradley Morgan X-Patchwork-Id: 2309588 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=jAbEqVQ+; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mainlining.org header.i=@mainlining.org header.a=rsa-sha256 header.s=202507r header.b=hxyhNKhp; dkim=fail reason="signature verification failed" header.d=mainlining.org header.i=@mainlining.org header.a=ed25519-sha256 header.s=202507e header.b=mIt3IqqS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hq6hs0KQBz1y1m for ; Wed, 23 Sep 2026 03:36:29 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=boUPUsy7ZECMGqiQ355v+ofcH2XXYmrH2JdY4f+tCk4=; b=jAbEqVQ++92BVY rM0mxen+HVv//klT+0qC3lG0o7860pRntICfEWsK9ivWgVq8lIM2Cz2Of5xInCc7UHwO6lh8LU4nu 0uo+g30r9pSnasscWRxHwP0P0qTiCzr/fYQiCgAQFajpqjyjuYbe8NUZ7Z7COjNIbGeAwCQtPCewi mwcSzllIgSuZ/5xQU44qKidWf94eH7vSRtOyhisLbCONP/rqqbN0M2ego5Du+8RyEFY3KY5RZy3of f9Z8NpXeKgzSYiBEkW7iyjpZVbLkkHG0ntUZKS0y54rnvvjbQjShV73PoFT7O3OrvORoivZjytvrV Jo+7pAnjPFpCEbZbHNsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x94Pr-00000006Dw0-22FM; Tue, 22 Sep 2026 17:36:27 +0000 Received: from mail.mainlining.org ([5.75.144.95]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x94Po-00000006DuK-0nDY for linux-snps-arc@lists.infradead.org; Tue, 22 Sep 2026 17:36:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; s=202507r; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1790098435; bh=4wVfAlEcovYJiLRAiW1UExN eq/b3xEK1OUjxcP/7QYQ=; b=hxyhNKhpHnG4LHB+IQytsfxPMEf6YigYhmBGZ6P1fc8JdTpofF 6/G3CK5eZbESW1khN3Oxuk3tTVRtyjIbZxXm7V/HRQMWqDGh17DVaXZRIj+dplFovWqMFx6Qd/N HYEuhDiGM8wwpRWslxqJozCj/owYlqjVph49yfKRkBOvKGP/olaRr80OLt3TX6jlUFhNPfXQASk UQuRL00HYhzZ/jl7YWoEfFoMh0jYwokqxLaO14TRt4zS0R4tL5JIgaJwdbMzvfPphucuTBMnKFP jjNQE9iV8ZIxOPszyZmfCQkHSxGLynC1RjC3MsaMYSL/3LD5RIP4ZC1boH5HOoZSaVw==; DKIM-Signature: v=1; a=ed25519-sha256; s=202507e; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1790098435; bh=4wVfAlEcovYJiLRAiW1UExN eq/b3xEK1OUjxcP/7QYQ=; b=mIt3IqqSgxeINDfPOkt7tdWMzH4kExoyXkiMgmIYJl8N/S4dZ9 2BgUIRlcxsvR2j6OPj3KfJzB0NPulRzvSkDg==; From: Bradley Morgan To: Andrew Morton , Vineet Gupta , Guo Ren , Yoshinori Sato , Rich Felker , Chris Zankel , Max Filippov Cc: Arnd Bergmann , "Paul E . McKenney" , David Laight , John Paul Adrian Glaubitz , linux-snps-arc@lists.infradead.org, linux-csky@vger.kernel.org, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, Bradley Morgan Subject: [PATCH 5/5] xtensa: Emulate two-byte cmpxchg Date: Tue, 22 Sep 2026 17:33:54 +0000 Message-ID: <20260922173354.14404-6-brads@mainlining.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260922173354.14404-1-brads@mainlining.org> References: <20260922173354.14404-1-brads@mainlining.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260922_103624_378749_03DEAC40 X-CRM114-Status: GOOD ( 10.07 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Xtensa has no two-byte atomic compare and swap, so the __cmpxchg() switch lets case 2 fall through to __cmpxchg_called_with_bad_pointer(), which is declared but never defined, so a two-byte cmpxchg() [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 DMARC_PASS DMARC pass policy X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Xtensa has no two-byte atomic compare and swap, so the __cmpxchg() switch lets case 2 fall through to __cmpxchg_called_with_bad_pointer(), which is declared but never defined, so a two-byte cmpxchg() fails at link time. Route case 2 through the new cmpxchg_emu_u16(), which takes the old and new values as unsigned long, so the (unsigned long) casts on _o_ and _n_ move off the call and into _old_ and _new_ declarations that type check the old and new arguments against *ptr through (unsigned long)(0 ? *ptr : (o)), the idiom David Laight suggested, so cmpxchg(&p, 4, 5) no longer compiles silently. Signed-off-by: Bradley Morgan --- arch/xtensa/include/asm/cmpxchg.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/xtensa/include/asm/cmpxchg.h b/arch/xtensa/include/asm/cmpxchg.h index b6db4838b175..f6bed4221b43 100644 --- a/arch/xtensa/include/asm/cmpxchg.h +++ b/arch/xtensa/include/asm/cmpxchg.h @@ -76,6 +76,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size) { switch (size) { case 1: return cmpxchg_emu_u8(ptr, old, new); + case 2: return cmpxchg_emu_u16(ptr, old, new); case 4: return __cmpxchg_u32(ptr, old, new); default: __cmpxchg_called_with_bad_pointer(); return old; @@ -83,10 +84,10 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size) } #define arch_cmpxchg(ptr,o,n) \ - ({ __typeof__(*(ptr)) _o_ = (o); \ - __typeof__(*(ptr)) _n_ = (n); \ - (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \ - (unsigned long)_n_, sizeof (*(ptr))); \ + ({ unsigned long _old_ = (unsigned long)(0 ? *(ptr) : (o)); \ + unsigned long _new_ = (unsigned long)(0 ? *(ptr) : (n)); \ + (__typeof__(*(ptr))) __cmpxchg((ptr), _old_, \ + _new_, sizeof (*(ptr))); \ }) #include