[{"id":3672622,"web_url":"http://patchwork.ozlabs.org/comment/3672622/","msgid":"<20260402095747.6efbd456@pumpkin>","list_archive_url":null,"date":"2026-04-02T08:57:47","subject":"Re: [PATCH] cmpxchg: allow const-qualified old value in cmpxchg()","submitter":{"id":89989,"url":"http://patchwork.ozlabs.org/api/people/89989/","name":"David Laight","email":"david.laight.linux@gmail.com"},"content":"On Thu, 02 Apr 2026 14:56:01 +0800\nHangbin Liu <liuhangbin@gmail.com> wrote:\n\n> The old value passed to cmpxchg() is semantically read-only: it is\n> only loaded into a register as a comparand and is never written back.\n> However, the macro currently assigns it implicitly to a local variable\n> of type __typeof__(*(ptr)), which triggers -Werror=discarded-qualifiers\n> when old is a const-qualified pointer and ptr points to a non-const type.\n> \n> To avoid this, let's add an explicit cast to __typeof__(*(ptr)) for the\n> old local variable in the cmpxchg macros. This explicit cast suppresses\n> the -Wdiscarded-qualifiers diagnostic.\n> \n> The new value is intentionally left without a cast: new will be stored\n> into *ptr, so silently accepting a const-qualified new would allow\n> callers to store a pointer-to-const into a non-const location without\n> any compiler warning.\n> \n> Suggested-by: Jakub Kicinski <kuba@kernel.org>\n> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>\n...\n> \n> diff --git a/arch/alpha/include/asm/cmpxchg.h b/arch/alpha/include/asm/cmpxchg.h\n> index ae1b96479d0c..b4b8dac759c4 100644\n> --- a/arch/alpha/include/asm/cmpxchg.h\n> +++ b/arch/alpha/include/asm/cmpxchg.h\n> @@ -234,7 +234,7 @@ ____cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,\n>  \n>  #define arch_cmpxchg_local(ptr, o, n)\t\t\t\t\t\\\n>  ({\t\t\t\t\t\t\t\t\t\\\n> -\t__typeof__(*(ptr)) _o_ = (o);\t\t\t\t\t\\\n> +\t__typeof__(*(ptr)) _o_ = (__typeof__(*(ptr)))(o);\t\t\\\n>  \t__typeof__(*(ptr)) _n_ = (n);\t\t\t\t\t\\\n>  \t(__typeof__(*(ptr))) ____cmpxchg((ptr), (unsigned long)_o_,\t\\\n>  \t\t\t\t\t  (unsigned long)_n_,\t\t\\\n\nThat looks like it loses the check that 'o' has the same type as '*ptr'.\nMaybe this works?\n\tauto _o_ = 1 ? (o) : *(ptr);\n\n  David","headers":{"Return-Path":"\n <linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=lists.infradead.org header.i=@lists.infradead.org\n header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Hw3nHDOL;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256\n header.s=desiato.20200630 header.b=jfd3rcbb;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=nc+iquM/;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=none (no SPF record) smtp.mailfrom=lists.infradead.org\n (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org;\n envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from bombadil.infradead.org (bombadil.infradead.org\n [IPv6:2607:7c80:54:3::133])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fmbNg3cf1z1yCs\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 02 Apr 2026 19:58:11 +1100 (AEDT)","from localhost ([::1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1w8DsO-0000000HDUK-2SPB;\n\tThu, 02 Apr 2026 08:58:09 +0000","from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05])\n\tby bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1w8DsN-0000000HDU3-1B9K\n\tfor linux-snps-arc@bombadil.infradead.org;\n\tThu, 02 Apr 2026 08:58:07 +0000","from mail-wm1-x329.google.com ([2a00:1450:4864:20::329])\n\tby desiato.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1w8Ds8-000000024V8-0qVg\n\tfor linux-snps-arc@lists.infradead.org;\n\tThu, 02 Apr 2026 08:58:01 +0000","by mail-wm1-x329.google.com with SMTP id\n 5b1f17b1804b1-4853c1ca73aso5763335e9.2\n        for <linux-snps-arc@lists.infradead.org>;\n Thu, 02 Apr 2026 01:57:51 -0700 (PDT)","from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36])\n        by smtp.gmail.com with ESMTPSA id\n 5b1f17b1804b1-4887e735532sm217845265e9.0.2026.04.02.01.57.48\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Thu, 02 Apr 2026 01:57:49 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20210309; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post:\n\tList-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:\n\tMessage-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:\n\tResent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:\n\tList-Owner; bh=+su5OjfTwEN1XYerXI9NVz+K6jafONljd3yQ2126FPg=; b=Hw3nHDOLUxdKGN\n\tNX6Fl0GLkTtyuqeVI9KapeAt91XVJOiF686+++4qKMBOws21k2pUAt1Pe7qZTY85ssvFXngauWJU2\n\tJtDIYBVxh43M0t14IKuoipixfSt7QN7GOf2fnBgnf5E7fuypQckOaKNOxkAkg9ilh776bpa0EhzJU\n\t51U7P39rdHHBFy+tnIY9AgOqcJTHwA3uNeF+8Jm9R8fCVnRUDoQJs2lNrEsh1VsW4+xBF+ci0lYVW\n\tHKaGrVywV8Jyp+Z+Y97jyC3F2luTWoKZCN8bxIDeMb6VAfpDu6FqxPSP756Uzkft+MZSS50A+JW7u\n\tkbdhc2H6MDfg2m84kOjQ==;","v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type\n\t:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To:From:Date:\n\tSender:Reply-To:Content-ID:Content-Description;\n\tbh=LnQTQFMkaspyfTBlP7NJBNzFuL146lWNPT7LvqeL2XU=; b=jfd3rcbb1Layc7/jXfyEGQflnB\n\tACQ1z3fjDNjjwW03THjpdEXzhkg52mN7QQqaZNUjgfduqnSNC/UrkacFqJOtwxez7Ab96IhEohYjf\n\tB0BKH22uXtngd1boXxUwFHH9h3DyV+PasPjdrVfHsc2suIkrGz2QMfPMF7OA/8AuZPZo5/NHfg2aw\n\tUPaZIxfnxmG2iN+MoM/nW/tocV1PKMc6VPY9+PMT08hP606hQVF2RmD7FmmRQCHMo/8oYrHS4ruv9\n\tUXSH9qvNwvR038huDLKh7cHPxfEz87UZqJ0U448T0gxVDUQ1Vxfg/oPGw+LAxr1U4K8udSnyZLeB+\n\tflUYF0zA==;","v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1775120270; x=1775725070;\n darn=lists.infradead.org;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:subject:cc:to:from:date:from:to:cc:subject:date\n         :message-id:reply-to;\n        bh=LnQTQFMkaspyfTBlP7NJBNzFuL146lWNPT7LvqeL2XU=;\n        b=nc+iquM/NgxY2f2+whZGx2BqnoFNpCCgF4Z9oqFCaxoRX7m4RuafI685+rou8v7EO/\n         Eiv7BcmfIjmTGmEQEyrWJsaEK2PDq8eGnR+WV+wOiDc2q4GG6GzeSNYDmSZHJPG7j437\n         /+jMZGAWkAFoxAMmLyiK26oATqRqisfBHmPcsSbyn9TU9DX4Iup3IHX/0eJneIhY88Mo\n         5sOUGvgQFKbizHjqVa/AKPWHKHwXynKOKR7qunxbSoq04XTrTJQuZ5qqKJLUPphHcxxC\n         vDihPiLa8kLX/cNrk7JLwQv1bZPCJzEs/Bicx3NXQaZq2YZv98/ian4PcJ9JKu9Qe2oh\n         TYXQ=="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1775120270; x=1775725070;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from\n         :to:cc:subject:date:message-id:reply-to;\n        bh=LnQTQFMkaspyfTBlP7NJBNzFuL146lWNPT7LvqeL2XU=;\n        b=p32o/k2tzba6eJwAO01t1E4pWb+CQnsQOnRnbVJZvbz9G5FD/oysWlGU9zuDdzwk9h\n         bQL9Jxng57mYU9/nfP2/RhYYj1EspIhuFwQx7NhUWRKf5LKRGRFggsE8RBG1co1Cx643\n         h0lQOSAQNnKAgig8+zEPdHm1SFs9C91YM26HZ1FTfi0d86c1i3nwcz5l4NDP/DyI/cZ8\n         Qg/zvK7Vmta9k9YX75PiSO3Bf5vCXSbN9StC9WayaLTzJg8jR+pTmwo6y8GP0y7UBVBI\n         VNujDSrVJ4Zqfe5r/VHsDOLmsL4/P8PCEtZTI/rxi+QMlaYSINC5vh0XjrAoh45OZNqc\n         49RQ==","X-Forwarded-Encrypted":"i=1;\n AJvYcCW0iqqHM2LMvinXUNkRoYchJ0UmEmKsX1dCc1dIXKm9PApe6Gf8Qe6DjzvTVJF6mKY82fxt1YU7Ckqk1e1n2Q==@lists.infradead.org","X-Gm-Message-State":"AOJu0YwX7gq0u/oIypVd+rHRFsgFVcXlv+vb6dnBJRxb2WY/NveLUgxz\n\tDhJn1vspHsQuzwqKVTvgs115yKX8h2yooViTLgO/AC9cP/SdsPXjvSoY","X-Gm-Gg":"ATEYQzz1bVhjXBOlLr4DKttk+D1jvLsnPqrILywF6TTRL4Vvh/OYV1yTwtbXyRC2KPp\n\t8T0RUS4OrpD1V6DfXJ+klVZWtsNb96cuoZYyW+Kju1u9dTW8aXasCMSkUK9Yijs2cFfvQXsn0pt\n\t4rnsbx3/Paj9BsBEhUlMIDoKRt8dT4JKYsI59DVD9dXeeAWT1cH40GwEuWCD1WbsV0rPzQ8tnza\n\tqR9lRZZ9uc3vP8dQrrFl5GpaOQIVCuGsIl5xMwFAuIGvh6OVbRMpZXGD7siV5+7Pj1kzndc1yZG\n\tfPZPErti5Jdm9fLE8cp4QZFEC2DbRCdUQZt0HNfjfz9lx6WGkNs69Qw8LH8Q5NajzXMEV/GWa/7\n\tUKY55gG2NEtAFfmQIDZQiqo8582ASsmizCl5W22541kQKu2Odwf+HN80kcMP+AP6cfWTtGYn6bs\n\twIfBxWJdKHVn1da7FcBpJjcPLefnLEts1sXttq9X19AldAKqYbXheeBq8yyQjH","X-Received":"by 2002:a05:600c:630f:b0:487:288:1198 with SMTP id\n 5b1f17b1804b1-4888359da58mr102555095e9.22.1775120270131;\n        Thu, 02 Apr 2026 01:57:50 -0700 (PDT)","Date":"Thu, 2 Apr 2026 09:57:47 +0100","From":"David Laight <david.laight.linux@gmail.com>","To":"Hangbin Liu <liuhangbin@gmail.com>","Cc":"Richard Henderson <richard.henderson@linaro.org>, Matt Turner\n <mattst88@gmail.com>, Magnus Lindholm <linmag7@gmail.com>, Vineet Gupta\n <vgupta@kernel.org>, Brian Cain <bcain@kernel.org>, \"James E.J. Bottomley\"\n <James.Bottomley@HansenPartnership.com>, Helge Deller <deller@gmx.de>,\n Madhavan Srinivasan <maddy@linux.ibm.com>, Michael Ellerman\n <mpe@ellerman.id.au>, Nicholas Piggin <npiggin@gmail.com>, \"Christophe\n Leroy (CS GROUP)\" <chleroy@kernel.org>, Paul Walmsley <pjw@kernel.org>,\n Palmer Dabbelt <palmer@dabbelt.com>, Albert Ou <aou@eecs.berkeley.edu>,\n Alexandre Ghiti <alex@ghiti.fr>, Yoshinori Sato\n <ysato@users.sourceforge.jp>, Rich Felker <dalias@libc.org>, John Paul\n Adrian Glaubitz <glaubitz@physik.fu-berlin.de>, \"David S. Miller\"\n <davem@davemloft.net>, Andreas Larsson <andreas@gaisler.com>, Thomas\n Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>, Borislav Petkov\n <bp@alien8.de>, Dave Hansen <dave.hansen@linux.intel.com>, x86@kernel.org,\n \"H. Peter Anvin\" <hpa@zytor.com>, Chris Zankel <chris@zankel.net>, Max\n Filippov <jcmvbkbc@gmail.com>, linux-alpha@vger.kernel.org,\n linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org,\n linux-hexagon@vger.kernel.org, linux-parisc@vger.kernel.org,\n linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org,\n linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, Jakub Kicinski\n <kuba@kernel.org>","Subject":"Re: [PATCH] cmpxchg: allow const-qualified old value in cmpxchg()","Message-ID":"<20260402095747.6efbd456@pumpkin>","In-Reply-To":"<20260402-cmpxchg-v1-1-4561e2c05d2c@gmail.com>","References":"<20260402-cmpxchg-v1-1-4561e2c05d2c@gmail.com>","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.8.0 (BSD) ) MR-646709E3 ","X-CRM114-CacheID":"sfid-20260402_095758_819675_BEDCE7F0 ","X-CRM114-Status":"GOOD (  17.11  )","X-Spam-Score":"-0.2 (/)","X-Spam-Report":"Spam detection software,\n running on the system \"desiato.infradead.org\",\n has NOT identified this incoming email as spam.  The original\n message has been attached to this so you can view it or label\n similar future email.  If you have any questions, see\n the administrator of that system for details.\n Content preview:  On Thu, 02 Apr 2026 14:56:01 +0800 Hangbin Liu wrote: > The\n    old value passed to cmpxchg() is semantically read-only: it is > only\n loaded\n    into a register as a comparand and is never written back. > However, the\n   macro currently assigns it implicitly to a l [...]\n Content analysis details:   (-0.2 points, 5.0 required)\n  pts rule name              description\n ---- ----------------------\n --------------------------------------------------\n -0.0 RCVD_IN_DNSWL_NONE     RBL: Sender listed at https://www.dnswl.org/, no\n                             trust\n                             [2a00:1450:4864:20:0:0:0:329 listed in]\n                             [list.dnswl.org]\n -0.0 SPF_PASS               SPF: sender matches SPF record\n  0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record\n  0.1 DKIM_SIGNED            Message has a DKIM or DK signature,\n not necessarily valid\n -0.1 DKIM_VALID_EF          Message has a valid DKIM or DK signature from\n                             envelope-from domain\n -0.1 DKIM_VALID_AU          Message has a valid DKIM or DK signature from\n author's\n                             domain\n -0.1 DKIM_VALID             Message has at least one valid DKIM or DK\n signature\n  0.0 FREEMAIL_FROM          Sender email is commonly abused enduser mail\n provider\n                             [david.laight.linux(at)gmail.com]","X-BeenThere":"linux-snps-arc@lists.infradead.org","X-Mailman-Version":"2.1.34","Precedence":"list","List-Id":"Linux on Synopsys ARC Processors <linux-snps-arc.lists.infradead.org>","List-Unsubscribe":"<http://lists.infradead.org/mailman/options/linux-snps-arc>,\n <mailto:linux-snps-arc-request@lists.infradead.org?subject=unsubscribe>","List-Archive":"<http://lists.infradead.org/pipermail/linux-snps-arc/>","List-Post":"<mailto:linux-snps-arc@lists.infradead.org>","List-Help":"<mailto:linux-snps-arc-request@lists.infradead.org?subject=help>","List-Subscribe":"<http://lists.infradead.org/mailman/listinfo/linux-snps-arc>,\n <mailto:linux-snps-arc-request@lists.infradead.org?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Sender":"\"linux-snps-arc\" <linux-snps-arc-bounces@lists.infradead.org>","Errors-To":"\n linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"}},{"id":3672658,"web_url":"http://patchwork.ozlabs.org/comment/3672658/","msgid":"<20260402104733.GZ3738786@noisy.programming.kicks-ass.net>","list_archive_url":null,"date":"2026-04-02T10:47:33","subject":"Re: [PATCH] cmpxchg: allow const-qualified old value in cmpxchg()","submitter":{"id":493,"url":"http://patchwork.ozlabs.org/api/people/493/","name":"Peter Zijlstra","email":"peterz@infradead.org"},"content":"On Thu, Apr 02, 2026 at 02:56:01PM +0800, Hangbin Liu wrote:\n> The old value passed to cmpxchg() is semantically read-only: it is\n> only loaded into a register as a comparand and is never written back.\n> However, the macro currently assigns it implicitly to a local variable\n> of type __typeof__(*(ptr)), which triggers -Werror=discarded-qualifiers\n> when old is a const-qualified pointer and ptr points to a non-const type.\n> \n> To avoid this, let's add an explicit cast to __typeof__(*(ptr)) for the\n> old local variable in the cmpxchg macros. This explicit cast suppresses\n> the -Wdiscarded-qualifiers diagnostic.\n> \n> The new value is intentionally left without a cast: new will be stored\n> into *ptr, so silently accepting a const-qualified new would allow\n> callers to store a pointer-to-const into a non-const location without\n> any compiler warning.\n> \n> Suggested-by: Jakub Kicinski <kuba@kernel.org>\n> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>\n> ---\n\nWhere is this a problem? I've never seen this. Also, new code should\nprobably use try_cmpxchg() anyway.","headers":{"Return-Path":"\n <linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=lists.infradead.org header.i=@lists.infradead.org\n header.a=rsa-sha256 header.s=bombadil.20210309 header.b=VoQEilXK;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256\n header.s=desiato.20200630 header.b=fWHvfBdk;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=none (no SPF record) smtp.mailfrom=lists.infradead.org\n (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org;\n envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from bombadil.infradead.org (bombadil.infradead.org\n [IPv6:2607:7c80:54:3::133])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fmdq31lQLz1yGH\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 02 Apr 2026 21:47:43 +1100 (AEDT)","from localhost ([::1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1w8FaP-0000000HQpV-3ury;\n\tThu, 02 Apr 2026 10:47:41 +0000","from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05])\n\tby bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1w8FaN-0000000HQp5-3x64;\n\tThu, 02 Apr 2026 10:47:39 +0000","from\n 2001-1c00-8d85-4b00-266e-96ff-fe07-7dcc.cable.dynamic.v6.ziggo.nl\n ([2001:1c00:8d85:4b00:266e:96ff:fe07:7dcc]\n helo=noisy.programming.kicks-ass.net)\n\tby desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1w8FaH-00000002G2g-3cX8;\n\tThu, 02 Apr 2026 10:47:34 +0000","by noisy.programming.kicks-ass.net (Postfix, from userid 1000)\n\tid 53C6A30301D; Thu, 02 Apr 2026 12:47:33 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20210309; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post:\n\tList-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:\n\tMessage-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:\n\tResent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:\n\tList-Owner; bh=CSUq2pgGXb1RWEt7F883WtMTGaNU0HCmYzBsb6Pnec0=; b=VoQEilXK66rLoU\n\taJ9tdEDnfvYhh2e3VAD2IWJUMtV8hur2N3lp5SGErvHC8lzgKk54swvFhBrMQhQN6PsRLkFhst6oZ\n\tSMgpQOHixghAQ6ZHySoWc3FhQvseFkzFcAJTPric22mLOk+MND5J01mxpOgVsxzCwFg/MJtnwTMLi\n\ttXWWIxNeqbnflUHl3Sm17UIVYwb33MYSkJRtQ+cH7/Z+tgHHg9hVLSz47TDP+6k3o0OLFZ5HtJ+II\n\tIC1d/SgeDallGAGEjDR9l/asjIlQrG5r291Rqi7oWzX5Li3FH6CS0b9wWbQwi7DaK2Sv9m1xnVcDG\n\tDhSFmIdXd+OTqwKPPbQA==;","v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version:\n\tReferences:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To:\n\tContent-Transfer-Encoding:Content-ID:Content-Description;\n\tbh=WuSnxkIyTO13mUz+vZ1/ml/c/eqQ5D0dK9NUy7xy4Pw=; b=fWHvfBdkYBp1lDE/7yjJLeJyG4\n\tTDG024jO+otVJtwiymsQjjwAfzXysI0Ne/Hap+hOUQ6HF3At22XcXejbtpYlWZVb7GLO9iSy8lBz/\n\txXoiPgVJTNjnS6NdQ+JrLTq5kguJS2cahxS6gs3sXaw3b07PcCyOKgqMNnJYuSMZkSWQ1zbwrH1lL\n\toQvCfWFVfYg2y5n87Si+3p5rgef7vqX5HJwvSTsRp8czWpsWUtQti6XMSrgnlzRPw7jmDhnI0sbSY\n\tFLNqQFUUhtoZK6LgqB9dMKy1Plr2pBXtNoo1Rj1bEdri+YGju2kRuh4KtAyO/E8p9i0u4EW5ey6u+\n\tj2zCRXxw==;"],"Date":"Thu, 2 Apr 2026 12:47:33 +0200","From":"Peter Zijlstra <peterz@infradead.org>","To":"Hangbin Liu <liuhangbin@gmail.com>","Cc":"Richard Henderson <richard.henderson@linaro.org>,\n\tMatt Turner <mattst88@gmail.com>,\n\tMagnus Lindholm <linmag7@gmail.com>,\n\tVineet Gupta <vgupta@kernel.org>, Brian Cain <bcain@kernel.org>,\n\t\"James E.J. Bottomley\" <James.Bottomley@hansenpartnership.com>,\n\tHelge Deller <deller@gmx.de>,\n\tMadhavan Srinivasan <maddy@linux.ibm.com>,\n\tMichael Ellerman <mpe@ellerman.id.au>,\n\tNicholas Piggin <npiggin@gmail.com>,\n\t\"Christophe Leroy (CS GROUP)\" <chleroy@kernel.org>,\n\tPaul Walmsley <pjw@kernel.org>, Palmer Dabbelt <palmer@dabbelt.com>,\n\tAlbert Ou <aou@eecs.berkeley.edu>, Alexandre Ghiti <alex@ghiti.fr>,\n\tYoshinori Sato <ysato@users.sourceforge.jp>,\n\tRich Felker <dalias@libc.org>,\n\tJohn Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,\n\t\"David S. Miller\" <davem@davemloft.net>,\n\tAndreas Larsson <andreas@gaisler.com>,\n\tThomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,\n\tBorislav Petkov <bp@alien8.de>,\n\tDave Hansen <dave.hansen@linux.intel.com>, x86@kernel.org,\n\t\"H. Peter Anvin\" <hpa@zytor.com>, Chris Zankel <chris@zankel.net>,\n\tMax Filippov <jcmvbkbc@gmail.com>, linux-alpha@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org,\n\tlinux-hexagon@vger.kernel.org, linux-parisc@vger.kernel.org,\n\tlinuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org,\n\tlinux-sh@vger.kernel.org, sparclinux@vger.kernel.org,\n\tJakub Kicinski <kuba@kernel.org>","Subject":"Re: [PATCH] cmpxchg: allow const-qualified old value in cmpxchg()","Message-ID":"<20260402104733.GZ3738786@noisy.programming.kicks-ass.net>","References":"<20260402-cmpxchg-v1-1-4561e2c05d2c@gmail.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20260402-cmpxchg-v1-1-4561e2c05d2c@gmail.com>","X-BeenThere":"linux-snps-arc@lists.infradead.org","X-Mailman-Version":"2.1.34","Precedence":"list","List-Id":"Linux on Synopsys ARC Processors <linux-snps-arc.lists.infradead.org>","List-Unsubscribe":"<http://lists.infradead.org/mailman/options/linux-snps-arc>,\n <mailto:linux-snps-arc-request@lists.infradead.org?subject=unsubscribe>","List-Archive":"<http://lists.infradead.org/pipermail/linux-snps-arc/>","List-Post":"<mailto:linux-snps-arc@lists.infradead.org>","List-Help":"<mailto:linux-snps-arc-request@lists.infradead.org?subject=help>","List-Subscribe":"<http://lists.infradead.org/mailman/listinfo/linux-snps-arc>,\n <mailto:linux-snps-arc-request@lists.infradead.org?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Sender":"\"linux-snps-arc\" <linux-snps-arc-bounces@lists.infradead.org>","Errors-To":"\n linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"}},{"id":3672712,"web_url":"http://patchwork.ozlabs.org/comment/3672712/","msgid":"<ac5qIUS5azbWAc9q@fedora>","list_archive_url":null,"date":"2026-04-02T13:07:45","subject":"Re: [PATCH] cmpxchg: allow const-qualified old value in cmpxchg()","submitter":{"id":15639,"url":"http://patchwork.ozlabs.org/api/people/15639/","name":"Hangbin Liu","email":"liuhangbin@gmail.com"},"content":"On Thu, Apr 02, 2026 at 09:57:47AM +0100, David Laight wrote:\n> > diff --git a/arch/alpha/include/asm/cmpxchg.h b/arch/alpha/include/asm/cmpxchg.h\n> > index ae1b96479d0c..b4b8dac759c4 100644\n> > --- a/arch/alpha/include/asm/cmpxchg.h\n> > +++ b/arch/alpha/include/asm/cmpxchg.h\n> > @@ -234,7 +234,7 @@ ____cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,\n> >  \n> >  #define arch_cmpxchg_local(ptr, o, n)\t\t\t\t\t\\\n> >  ({\t\t\t\t\t\t\t\t\t\\\n> > -\t__typeof__(*(ptr)) _o_ = (o);\t\t\t\t\t\\\n> > +\t__typeof__(*(ptr)) _o_ = (__typeof__(*(ptr)))(o);\t\t\\\n> >  \t__typeof__(*(ptr)) _n_ = (n);\t\t\t\t\t\\\n> >  \t(__typeof__(*(ptr))) ____cmpxchg((ptr), (unsigned long)_o_,\t\\\n> >  \t\t\t\t\t  (unsigned long)_n_,\t\t\\\n> \n> That looks like it loses the check that 'o' has the same type as '*ptr'.\n> Maybe this works?\n> \tauto _o_ = 1 ? (o) : *(ptr);\n> \nOh, I didn't notice this. Thanks for the comment!\n\nBest Regards\nHangbin","headers":{"Return-Path":"\n <linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=lists.infradead.org header.i=@lists.infradead.org\n header.a=rsa-sha256 header.s=bombadil.20210309 header.b=KnkVas9K;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=KdCQxl3x;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=none (no SPF record) smtp.mailfrom=lists.infradead.org\n (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org;\n envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from bombadil.infradead.org (bombadil.infradead.org\n [IPv6:2607:7c80:54:3::133])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fmhx261jqz1xtJ\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 03 Apr 2026 00:08:06 +1100 (AEDT)","from localhost ([::1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1w8HmF-000000008nK-3mZP;\n\tThu, 02 Apr 2026 13:08:03 +0000","from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033])\n\tby bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1w8HmE-000000008mu-1FsQ\n\tfor linux-snps-arc@lists.infradead.org;\n\tThu, 02 Apr 2026 13:08:03 +0000","by mail-pj1-x1033.google.com with SMTP id\n 98e67ed59e1d1-35d99031e4eso483978a91.1\n        for <linux-snps-arc@lists.infradead.org>;\n Thu, 02 Apr 2026 06:08:01 -0700 (PDT)","from fedora ([209.132.188.88])\n        by smtp.gmail.com with ESMTPSA id\n 98e67ed59e1d1-35dbe41b11fsm7822915a91.0.2026.04.02.06.07.48\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Thu, 02 Apr 2026 06:08:00 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20210309; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post:\n\tList-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:\n\tMessage-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:\n\tResent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:\n\tList-Owner; bh=8eKoUnM1fsPnicTN/5xyKPEfojQCS8dQ+C+6qfxJceo=; b=KnkVas9KG40Fb8\n\t2bF0Va4TVzt1tqLkVVrSAdaHlXzi1bfynZxSmJmY5ocFTeoHzFzWdfJyrnEqSss+B1LrA2enVdAJn\n\t4sN9WQWP6zOkGwyWU6pxPFSuheqNQqBCIdnQfSoxYwtnmUpKb6g7qsZkgZIXon2OItg7X4FnlTdU9\n\tGhN2ndSVUl2iwXOxMlLSl/OJ3APmxMke4/H6i2iGdAXm2UKVNTzhMnYut8OeQnNztf2l1qSQUU3nj\n\tDX3pe8HE/CyjRBpMQIrEpTkdGvLDnXAGwUADmU76cqakhESw0Dn0jTV0FM7EN54M8405s8Jni4Cv7\n\ts+rNI2CjmZFwcJF6ki/w==;","v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1775135281; x=1775740081;\n darn=lists.infradead.org;\n        h=in-reply-to:content-disposition:mime-version:references:message-id\n         :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to;\n        bh=KWxJTOWQkri5jmv5ZKMT+tNuIWsfKgbRVKTEMtbqloY=;\n        b=KdCQxl3xZcTvwf/ge78doEjn+mHpzSrYGXSwfJo3ORUsvwJjXTg7UF94Jq1ZycwQnl\n         tbCQFYLs0jjul5E35FODm8eIe4FQwXW/cHtDp7r1agwWcpRu/SPQXfpXcr4BaUUt4y80\n         MrJo3kLtGHMobWTQiBA9z5n6gyhpMmGbWypdtyMhKxeX+XCK9oFG9wOFqyDCZiIl66b3\n         ate5kJOfg21qhWLWENosvZK2Wh0NzXBeeNHLQQvJjZdqZfgA8HRjqjg7bVKd6st5XUEd\n         HDKPa5+6VWJ965400bzTL4YaYGL52VMA0ss139/EUKryGu9pKB8gWK7xanP/fiJPYWaG\n         SK+Q=="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1775135281; x=1775740081;\n        h=in-reply-to:content-disposition:mime-version:references:message-id\n         :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc\n         :subject:date:message-id:reply-to;\n        bh=KWxJTOWQkri5jmv5ZKMT+tNuIWsfKgbRVKTEMtbqloY=;\n        b=BsU1Rd/iHiYo0y48auR5jhnKR2HfND9Eag9P3wPz8ejet5b0PJhARTYpJK/PnO1jLn\n         oETAVmsrcsKJ1hM9pm771AdB7nCfpVvgSE14Xcv9406wJNW79xFUzTi4TUP0BhetFT0b\n         Z83UJuyLJYMSAv1DpVSA2GW74L9GWNkA844rZH4uZrRjV2sAoujF7K2ignlyK0bPLYwa\n         mEdT5FMPPoFOw6IlG5NZiR3ODIHz9CG251+9dhcCns9oUFFI0ILWN0KdtL3P4/rHq65U\n         OrdAKcXHufJ7crsgJXtkSG0VoHWmWHc2FwmNgjrWmnoAXvYMlZZH++1pFcnruykteUbe\n         ZUaA==","X-Forwarded-Encrypted":"i=1;\n AJvYcCXV4E5p+65U12+QLV/EaxUksnjfUq6UAO33Yq0B26GB/g7K+dzupVCpHvCBbS3nhzFrZ9nHZIG1dODuhozS9A==@lists.infradead.org","X-Gm-Message-State":"AOJu0YwSppxYqh2zgTFtT5GlC5ek28kTw1pmevCtrWE0WSe0fj1tsODU\n\tUHQXcvXE5dejfQRDYBJpiLlKAdjc/uiYtcyfwz0MAkLDxBriWw0zD3Bp","X-Gm-Gg":"AeBDieublxhie25Lhb1v09F0Z6Mn5c3jYnhU5UWhqhQl0g+FEmK/+9rJycbnSe0W9GA\n\tkTZV5MOFpJqeKOAYJrSdWZaVIlTcyz52l4cr43NIA0GdvEt7AFa84uvFYNZqGX1x3ENOD+7GD1k\n\tpVWYg1df0n4RcEXXUTv+2soAxJ2vAVdgoasQ7a6glQ9E+v0eEvUlhFnah27t/4UDzjUNUYT2orf\n\tQZFKN+bKKFytiAhf8JATWkgWtwO2yKaK4ky9Y73kIAz7JVh9LLwjQoD2bznjKNPxwwNxBEBZRYV\n\tB8WHavdiPtdb7yby6yoyuGdMFLygkebjS92f2+VRUPBuAq1pMAtiRO3Hjz2ae2mx/u3GaN35Ykc\n\tSBgdAyBn1ANbz6m0kQlzLulNL86XWCHz3A3mP/rWWHBdtskGnCqflgoHQk86jFbquTGCY3wbbim\n\tN0sialYxsJE3qpI2GDsqt+Y8iHOkk=","X-Received":"by 2002:a17:90b:4d81:b0:35d:a412:3c79 with SMTP id\n 98e67ed59e1d1-35dc7079cb6mr6805318a91.30.1775135280985;\n        Thu, 02 Apr 2026 06:08:00 -0700 (PDT)","Date":"Thu, 2 Apr 2026 13:07:45 +0000","From":"Hangbin Liu <liuhangbin@gmail.com>","To":"David Laight <david.laight.linux@gmail.com>","Cc":"Richard Henderson <richard.henderson@linaro.org>,\n\tMatt Turner <mattst88@gmail.com>,\n\tMagnus Lindholm <linmag7@gmail.com>,\n\tVineet Gupta <vgupta@kernel.org>, Brian Cain <bcain@kernel.org>,\n\t\"James E.J. Bottomley\" <James.Bottomley@hansenpartnership.com>,\n\tHelge Deller <deller@gmx.de>,\n\tMadhavan Srinivasan <maddy@linux.ibm.com>,\n\tMichael Ellerman <mpe@ellerman.id.au>,\n\tNicholas Piggin <npiggin@gmail.com>,\n\t\"Christophe Leroy (CS GROUP)\" <chleroy@kernel.org>,\n\tPaul Walmsley <pjw@kernel.org>, Palmer Dabbelt <palmer@dabbelt.com>,\n\tAlbert Ou <aou@eecs.berkeley.edu>, Alexandre Ghiti <alex@ghiti.fr>,\n\tYoshinori Sato <ysato@users.sourceforge.jp>,\n\tRich Felker <dalias@libc.org>,\n\tJohn Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,\n\t\"David S. Miller\" <davem@davemloft.net>,\n\tAndreas Larsson <andreas@gaisler.com>,\n\tThomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,\n\tBorislav Petkov <bp@alien8.de>,\n\tDave Hansen <dave.hansen@linux.intel.com>, x86@kernel.org,\n\t\"H. Peter Anvin\" <hpa@zytor.com>, Chris Zankel <chris@zankel.net>,\n\tMax Filippov <jcmvbkbc@gmail.com>, linux-alpha@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org,\n\tlinux-hexagon@vger.kernel.org, linux-parisc@vger.kernel.org,\n\tlinuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org,\n\tlinux-sh@vger.kernel.org, sparclinux@vger.kernel.org,\n\tJakub Kicinski <kuba@kernel.org>","Subject":"Re: [PATCH] cmpxchg: allow const-qualified old value in cmpxchg()","Message-ID":"<ac5qIUS5azbWAc9q@fedora>","References":"<20260402-cmpxchg-v1-1-4561e2c05d2c@gmail.com>\n <20260402095747.6efbd456@pumpkin>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20260402095747.6efbd456@pumpkin>","X-CRM114-Version":"20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ","X-CRM114-CacheID":"sfid-20260402_060802_369543_D9F7F78D ","X-CRM114-Status":"GOOD (  13.97  )","X-Spam-Score":"-2.1 (--)","X-Spam-Report":"Spam detection software,\n running on the system \"bombadil.infradead.org\",\n has NOT identified this incoming email as spam.  The original\n message has been attached to this so you can view it or label\n similar future email.  If you have any questions, see\n the administrator of that system for details.\n Content preview:  On Thu, Apr 02, 2026 at 09:57:47AM +0100,\n David Laight wrote:\n    > > diff --git a/arch/alpha/include/asm/cmpxchg.h\n b/arch/alpha/include/asm/cmpxchg.h\n    > > index ae1b96479d0c..b4b8dac759c4 100644 > > --- a [...]\n Content analysis details:   (-2.1 points, 5.0 required)\n  pts rule name              description\n ---- ----------------------\n --------------------------------------------------\n -0.0 SPF_PASS               SPF: sender matches SPF record\n  0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record\n  0.1 DKIM_SIGNED            Message has a DKIM or DK signature,\n not necessarily valid\n -0.1 DKIM_VALID_EF          Message has a valid DKIM or DK signature from\n                             envelope-from domain\n -0.1 DKIM_VALID_AU          Message has a valid DKIM or DK signature from\n author's\n                             domain\n -0.1 DKIM_VALID             Message has at least one valid DKIM or DK\n signature\n -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%\n                             [score: 0.0000]\n  0.0 FREEMAIL_FROM          Sender email is commonly abused enduser mail\n provider\n                             [liuhangbin(at)gmail.com]\n -0.0 RCVD_IN_DNSWL_NONE     RBL: Sender listed at https://www.dnswl.org/, no\n                             trust\n                             [2607:f8b0:4864:20:0:0:0:1033 listed in]\n                             [list.dnswl.org]","X-BeenThere":"linux-snps-arc@lists.infradead.org","X-Mailman-Version":"2.1.34","Precedence":"list","List-Id":"Linux on Synopsys ARC Processors <linux-snps-arc.lists.infradead.org>","List-Unsubscribe":"<http://lists.infradead.org/mailman/options/linux-snps-arc>,\n <mailto:linux-snps-arc-request@lists.infradead.org?subject=unsubscribe>","List-Archive":"<http://lists.infradead.org/pipermail/linux-snps-arc/>","List-Post":"<mailto:linux-snps-arc@lists.infradead.org>","List-Help":"<mailto:linux-snps-arc-request@lists.infradead.org?subject=help>","List-Subscribe":"<http://lists.infradead.org/mailman/listinfo/linux-snps-arc>,\n <mailto:linux-snps-arc-request@lists.infradead.org?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Sender":"\"linux-snps-arc\" <linux-snps-arc-bounces@lists.infradead.org>","Errors-To":"\n linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"}}]