From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C475D38239A for ; Fri, 11 Sep 2026 22:10:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789164622; cv=none; b=JW4TM4rM61ogAvsqMWJvIDkQ472SdYN/CpZot8JRS4bBsG4nda4isyY3pCfhQdSdr8XRZMucCHGkoJIhEcfshl8JSX5oVq3YUhDlX7DaBiN6XMs4S+4K/nYhIRn6lS6264skrHp0BrtnhUpV7vOaJhjBVN4PsskjCP5jzl+aFbI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789164622; c=relaxed/simple; bh=wzOAT8P+HfggfOuW+tbV1rDr39BIeDu1f097JVhjors=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WGZtXYVL96nc++Sl99C0vUDxZ5xhxUinetYDI55j0ZPCCYOt0VHH0CZVnskcotsv3D68WZl6R3nUGekG4qpI2LoiGQpzN3uOjGja6RhWMorh1rj7XrF1bkPnkdTdyvYpiTb0DPFYbCE7+aHSMRk/Q7t0vG+JJHdOm6QJBy2V+pQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=V8kPqdVL; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="V8kPqdVL" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4998b5a63e2so15540485e9.1 for ; Fri, 11 Sep 2026 15:10:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789164619; x=1789769419; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=1CitEInQG9IH8hFfkxw+Dy1+TcxOBHzYjUh6RK88Fgs=; b=V8kPqdVLxhbxYq/ndSOhh59EWr8wuK81XRGpgyG1cXj+UuOWKJMFJ2T2a2dgpFrdLa WkuVwWjHua6E0jDuliU9Xfih3FGXadW6+THWVrO6iOtCVXUCSCtYS+LVNXHxOpwM1s/Y /bOxgg+4FBx1y8MXDR1zhT3bH3ZKtN6CF8wJX8J7oMW/zGMtXic0VCWyi99/rWWjnfd/ uuXLEKmMOpD1pjjTO6VRI6T6CUOYwvNYIghCxNP5Ys0xeNLSImT2vW7SH3c25q936lXU qUoUKrw/pjuOxzetQVpQHrvTyuVJAj49eK1mHFx/vB/wgw7+zJMHO9eiGbAO23VErWjb 30HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789164619; x=1789769419; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=1CitEInQG9IH8hFfkxw+Dy1+TcxOBHzYjUh6RK88Fgs=; b=pzaFeTKDT2endVxIDHRAo3VSPQ1YxNEYjHGUkGebezaubt4JWACmZTA+tJHJhwmyrq dpPOnOGWrkeCMN8UZmZWgxtFVsrdWt7vtsh204slimN9x8la3glbMfuJ5cNYrR2ZXKeF wruJv15fGY+HsOJbzdPSi3acS3XpmxfYN1rCnH/3kXq4FwhH6xWke6ebFxh9iofQtVZx 0hVvJY6d5DIsY3d5XEhGjC3RROBQejFM5EdXFE8G8aqmgxcp/JgdNIeSG/i3dSlPsHN9 XkPPnO+DT8sKYMut1oTHTeZKLFvl5fRDJn+PdQs045OaOqc1W3oTVXZoqNaAfHifHfPm yCyA== X-Forwarded-Encrypted: i=1; AKwUvBxiA5RAnVoyrz1HDQQR31j5xtmgRmVfWHEpPo1FlQSQis6+xpH5Vh+X22oQszSwjrAvQM9AkDIWJQ==@vger.kernel.org X-Gm-Message-State: AFuF++loDcGa7DbZLaNLZh2JthURnY7cdEVLObph0Khqc4wFotX6ue/A MsT9XuFVZKrQA7DYy8tQtuRuQFFWwzm8uSbKDzqBjgad1obu3JtfzqEe X-Gm-Gg: AYBFou0p3jM749E5pPRNlGSX3nVjM4N/onl9yIw/jd9CW8wFMGn56TJ61KnBfjQf83A zm5BlxFtGBxM+tgd2Xqa84jQt48QpK81utbJwUPm7nkYmH3ZIln7Yc7w/J+xHa17r4vyTTfsxuA rLbZQ5EIQ97Q7A6kFntYZtIn9Ia0BH9XewhCQOgMeuROPT5VDc7GppaYa/PrK6jV3/2Yr9imx3C OUJV9NWvF7QnSi7uGY4cw3R+q1f2Ffr4j/fLR03uUc0z+l6sjOxwSGwdFw2j51Z0BJdKUzzfkSI rtDkr6USEpUB+yVvkTkyyeBGOBRsQ5PwuIBjp9acsYHtL93xNGpEPHZvIdySjKod60QmRPVNohk vJg5aBKDlC06JdkGSogVJu5kIZ0ER4gfwKUcrklXq1/80hihJrb+ThZ3tqjyoR7IlIvzAsw2sM2 uUxfJyaSsuU0vI9HC5Ok8/HkD4A8Yt4uO0IIALfGEfHI1pqfMj6MC2hFmhWfjxbGb3UgWhbRuns odcZdhd5pLAsANEvqeljDqpy+cMiCS9azJT X-Received: by 2002:a05:600c:8b41:b0:49b:d45:703e with SMTP id 5b1f17b1804b1-49e6198865dmr87033975e9.8.1789164618893; Fri, 11 Sep 2026 15:10:18 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49e61a81943sm69553525e9.1.2026.09.11.15.10.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 15:10:18 -0700 (PDT) Date: Fri, 11 Sep 2026 23:10:17 +0100 From: David Laight To: Bradley Morgan Cc: "Paul E. McKenney" , frederic@kernel.org, neeraj.upadhyay@kernel.org, boqun@kernel.org, joelagnelf@nvidia.com, rcu@vger.kernel.org, "Andrew Morton" , "Arnd Bergmann" , linux-arch@vger.kernel.org, "Vineet Gupta" , linux-snps-arc@lists.infradead.org, "Russell King" , linux-arm-kernel@lists.infradead.org, "Guo Ren" , linux-csky@vger.kernel.org, "Yoshinori Sato" , "Rich Felker" , "John Paul Adrian Glaubitz" , linux-sh@vger.kernel.org, "Chris Zankel" , "Max Filippov" , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/6] lib: Add two-byte cmpxchg emulation function Message-ID: <20260911231017.550f8cd1@pumpkin> In-Reply-To: <20260911192540.20983-2-brads@mainlining.org> References: <20260911192540.20983-1-brads@mainlining.org> <20260911192540.20983-2-brads@mainlining.org> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-sh@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 11 Sep 2026 19:25:34 +0000 Bradley Morgan wrote: > 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. > > 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 > Signed-off-by: Bradley Morgan > --- > arch/Kconfig | 2 +- > arch/arc/Kconfig | 2 +- > arch/arm/Kconfig | 2 +- > arch/csky/Kconfig | 2 +- > arch/sh/Kconfig | 2 +- > arch/xtensa/Kconfig | 2 +- > include/linux/cmpxchg-emu.h | 1 + > lib/Makefile | 2 +- > lib/cmpxchg-emu.c | 35 ++++++++++++++++++++++++++++++++--- > 9 files changed, 40 insertions(+), 10 deletions(-) > ... > diff --git a/include/linux/cmpxchg-emu.h b/include/linux/cmpxchg-emu.h > index 998deec67740..fee8171fa05e 100644 > --- a/include/linux/cmpxchg-emu.h > +++ b/include/linux/cmpxchg-emu.h > @@ -11,5 +11,6 @@ > #define __LINUX_CMPXCHG_EMU_H > > uintptr_t cmpxchg_emu_u8(volatile u8 *p, uintptr_t old, uintptr_t new); > +uintptr_t cmpxchg_emu_u16(volatile u16 *p, uintptr_t old, uintptr_t new); Why uintptr_t? Shouldn't it just be u16? (Which probably means the code would better if it was just 'unsigned int') David From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 99297C88E50 for ; Fri, 11 Sep 2026 22:10:25 +0000 (UTC) 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:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8Umz5vTdmpo6FnUbGdi0zfmgUVvpmUzzFqh/RurR3gs=; b=pBQyC/89ZXINC4 Yfbq+moTfcFrkeuyHj51D0icJlBsS4OQLFPQQhXcHBMn/4/Io2wtf7BKgZ9cZ6bOf7h5Pr3UFVQes 3vkF3wOUrLOFpYzBWPTFWdeHD00zfeW+DwvlEz9OVrDFS3jdlE/9QrgwMNtJDxsj6Sxv4MEIBa48W q5BumSPvU0ZQZNFBiJX9j0goaQu7h8TLYe7BQaHs6uY0zdA39+oEciL+uuvX9L7fsP/Ok35/eBtlU GZ87u5v0NVWNkfVQndjD/Nu83AHh0rxU9zvcM2loL3VuCfsPXmphAXe0H2dIwUa0fnYXA2vxOlzko oy612oaCZWDjZumsnKGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x59Rx-00000000EOa-0xsE; Fri, 11 Sep 2026 22:10:25 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x59Rt-00000000ENY-0lgs for linux-snps-arc@lists.infradead.org; Fri, 11 Sep 2026 22:10:23 +0000 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-49b0d8bc2aaso16423505e9.0 for ; Fri, 11 Sep 2026 15:10:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789164619; x=1789769419; darn=lists.infradead.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=1CitEInQG9IH8hFfkxw+Dy1+TcxOBHzYjUh6RK88Fgs=; b=Vu6dKsPcNI5U9U7anAngoqYq+QRvUlGMvbGoSrQ6Fx6TDM4YpLscW+5Ma9uZTM3Wci m/TLsPX7wv2t11xVLFjQfehrf1CBVrkCWyyRzbvTFjSd+sMHBBb+YZYaPoK44oaCOVH8 9Fi9FKfWDWHyGpYlSqBAaCseBtuM50Tc4CHE4tl2ZZQunwVxZRy6L27ImirAU0XqMcE9 QZBv8X3tK2l1KEy7N285Gw69qnMqSWATCvYfhN6/cevQmqMdXu7jjQ++MzPmlMm6Raq0 keIL4hqZqMxzqQBxTDdTW+6v7Qq3IfZ1fiGVHXy+LteCx01+8u6TLJ5YyPeoN8u95ROe ZJRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789164619; x=1789769419; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=1CitEInQG9IH8hFfkxw+Dy1+TcxOBHzYjUh6RK88Fgs=; b=FsDD736ACbrsaEOzbkdXtm05UeBOKgTzZDK/BK04P2KW7cK7Y2///DEWDxiIZkI+Un j9i7cdp3v71xzMn4daK4u8vBUmCbEAarDjZSz2B9ZJTI6u7l08XakT7tR68YcRVRQVrP AsP4/YqOtMldH+SD1c1iPaJ546G2Zv9tvu06doIclu8ecROr+wUVJIrhM5lEK9gkQ3RS TLf/4daU4/H41gyeJsq3OfsAeeKtqWWgsaHf86HtQe8oi3ji+BAsHzeAFf+tsHHzSgOI QTGcxvbBZM1nvZywFg57fEX7a9pFDyPGi7HRGzjc1ukd05DSdWc4BzGCoOkSFA8YTsCj ezpw== X-Forwarded-Encrypted: i=1; AKwUvBzgTsRUl5mkPojNKco2VAm1tWbr/39P9aWwWTZS5MCLJda9eYi/OoVFOIOdwypGqpbgOY08JIXLIx7FyrHHpw==@lists.infradead.org X-Gm-Message-State: AFuF++ngshhhkHSDAf4QgkfXTATtVRTOlmYJfs9ARVBRwP4uW0Pf2Kkc WKgYEEcFufhXv3h5X+ySfIJN02gC6ZiP6TKi9oADu8bx2LnafNJEPdEc X-Gm-Gg: AYBFou3isQ7yCdFDZeyEVPe3cjjkLxeIJ2gIRi1v1SL0Ducs1Z4QIieehqhxJRL9i5Z rviOdlazBmqX8UN8L5tprBWZPFlptoLrYgVuODYgWAqDsHxmxwShvpj6ZSAVEPaK5+lhqOS5lSC sKllwG71ysrvYrWV2SaewLQ6T7w0fizwUDfMnhq+N+WbS2SMsx6vBWUiDptv28xFDuQY5g6wnHS tsM6HkZsP0vYU/ZA4fz4EZNIPNDhjHoR3i7Z63nsuR2295yV+izM/gmsIplB2Mx+X+GzOYnMjxV 631q/ilZPQXzFK/EMkkzR+N9QYENnXRLyaahD1Lm/eFvyMN8SkJcdIVEsNIIrd24HACemsvYBwW CULh8nrXvzgHjuaFmmxURJF5PAJqNXgXnKFXx6zmw+4x+nDD7tD/SwGTLKlt9Oyh16O7gOip0cg qD1S96fp0htcUJTWuAus3etbIdOe60FL6BE2xXerXHwSdbmr2wjmyEMw4DAU3B418AH4lA/WHHO RSN8flf6ica04l3Az3uvbom3kwaIjJTI4bS X-Received: by 2002:a05:600c:8b41:b0:49b:d45:703e with SMTP id 5b1f17b1804b1-49e6198865dmr87033975e9.8.1789164618893; Fri, 11 Sep 2026 15:10:18 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49e61a81943sm69553525e9.1.2026.09.11.15.10.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 15:10:18 -0700 (PDT) Date: Fri, 11 Sep 2026 23:10:17 +0100 From: David Laight To: Bradley Morgan Cc: "Paul E. McKenney" , frederic@kernel.org, neeraj.upadhyay@kernel.org, boqun@kernel.org, joelagnelf@nvidia.com, rcu@vger.kernel.org, "Andrew Morton" , "Arnd Bergmann" , linux-arch@vger.kernel.org, "Vineet Gupta" , linux-snps-arc@lists.infradead.org, "Russell King" , linux-arm-kernel@lists.infradead.org, "Guo Ren" , linux-csky@vger.kernel.org, "Yoshinori Sato" , "Rich Felker" , "John Paul Adrian Glaubitz" , linux-sh@vger.kernel.org, "Chris Zankel" , "Max Filippov" , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/6] lib: Add two-byte cmpxchg emulation function Message-ID: <20260911231017.550f8cd1@pumpkin> In-Reply-To: <20260911192540.20983-2-brads@mainlining.org> References: <20260911192540.20983-1-brads@mainlining.org> <20260911192540.20983-2-brads@mainlining.org> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260911_151021_250803_4431D3C2 X-CRM114-Status: GOOD ( 17.56 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+linux-snps-arc=archiver.kernel.org@lists.infradead.org On Fri, 11 Sep 2026 19:25:34 +0000 Bradley Morgan wrote: > 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. > > 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 > Signed-off-by: Bradley Morgan > --- > arch/Kconfig | 2 +- > arch/arc/Kconfig | 2 +- > arch/arm/Kconfig | 2 +- > arch/csky/Kconfig | 2 +- > arch/sh/Kconfig | 2 +- > arch/xtensa/Kconfig | 2 +- > include/linux/cmpxchg-emu.h | 1 + > lib/Makefile | 2 +- > lib/cmpxchg-emu.c | 35 ++++++++++++++++++++++++++++++++--- > 9 files changed, 40 insertions(+), 10 deletions(-) > ... > diff --git a/include/linux/cmpxchg-emu.h b/include/linux/cmpxchg-emu.h > index 998deec67740..fee8171fa05e 100644 > --- a/include/linux/cmpxchg-emu.h > +++ b/include/linux/cmpxchg-emu.h > @@ -11,5 +11,6 @@ > #define __LINUX_CMPXCHG_EMU_H > > uintptr_t cmpxchg_emu_u8(volatile u8 *p, uintptr_t old, uintptr_t new); > +uintptr_t cmpxchg_emu_u16(volatile u16 *p, uintptr_t old, uintptr_t new); Why uintptr_t? Shouldn't it just be u16? (Which probably means the code would better if it was just 'unsigned int') David _______________________________________________ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc