Message ID | 20221219153525.632521981@infradead.org |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2463130wrn; Mon, 19 Dec 2022 07:46:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf5AfP7BfsIwsjOC442si3nWR4hFAwOLcWRnmPZX/8YcmF7HPv7fwnUcBgF6tiQR7ca6n6fX X-Received: by 2002:a17:902:f602:b0:187:4920:3a3c with SMTP id n2-20020a170902f60200b0018749203a3cmr45503151plg.33.1671464815681; Mon, 19 Dec 2022 07:46:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671464815; cv=none; d=google.com; s=arc-20160816; b=lX8AEYw9JpR3Rr96vXjI2d6gF5bS1E30foZfSp23Gunt7YrZthRrWZrIgnudwSwH0+ lqs1pQLwWcTM9CprENpdO+51owQ3ebmyt1ijL1TUmUx9u1WPgcyhZc74QQ4hrXkS17R4 S4z/AV/SKy4BVeCvOVJ061znakxs+mssb2L7qcKsetBjT4Vd1OuwDmU7HMG7oOJus3/Z HcoiUCQtzGk8mKyIg6JFYXbIwY2wowvMHdJHejyg1XVvn5I1s4BVV5e1CjH6ADa9oH5p YjHMrJddpX4PJrSaHQhCneybuzZ32C3xDiSS55cehcNStmmcWWkdp39RQfdDoqYZcDkQ gDGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:user-agent:message-id :dkim-signature; bh=fH7vUY5IU4m1cKDzFBDt+eq6lohLTkHTMZiIE4ke4VY=; b=j4AahmLW8WdwAA8hsNFR2aq68CLfgX3kDvtZ/z7al24p7sRP1L1zaksx3ONR2sldZm elPnys8SdqgxbcnnXaVuKWlcuhPXCZNhJq8Ogwg1cVkCSWVvSIaaRzoYivG5F3dzBdGL lSNaeJ+FCOH5mXx30xjtxIyyAWSuqC5ARLqRSPpiV1O+chK2jIMTsWZ+E01JDA3hUxUd ZCmiUNgy0fTngxO6/sfqtDgj5kKGYVB/pfvVYP7bH9QpVSPxr62hASnTyVfUEk8bcoT3 tMseNbnJnq6nESii9GywPtOKazQ4K62XKoJ3NvH+gzfC/ok7gUjpMaT5JJQ0r2u5j36V CS2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=hmTPYkhC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u4-20020a170902b28400b00186ab03eebfsi10673667plr.418.2022.12.19.07.46.42; Mon, 19 Dec 2022 07:46:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=hmTPYkhC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232725AbiLSPqE (ORCPT <rfc822;abdi.embedded@gmail.com> + 99 others); Mon, 19 Dec 2022 10:46:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232611AbiLSPpa (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 19 Dec 2022 10:45:30 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17D5313D61; Mon, 19 Dec 2022 07:44:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Subject:Cc:To:From:Date:Message-ID: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To:References; bh=fH7vUY5IU4m1cKDzFBDt+eq6lohLTkHTMZiIE4ke4VY=; b=hmTPYkhC/7+cqNJUN5N9enIC/k RI5NBONX3QLG7mKq+yLzWmmPG8HTz/NW05/q2t+NIC08Ns9r4JZ2UscvuMGis6p5aIV98rt+d5PYB nAJujak0DMGsy0jBuXm6mns7IRswwY028uKylH5d6HEyxKa0v7TWHR4V7NhweEQZexadjXP2cENfB PN0CBN/Z4zLKueR3qNhwICGa49xaayJGmuojh1b1Ti3KDYK/3ICqowGwv0pFcI9xUFdbcrZ+0iIxu Ge/5HFB3a3AtlZL/G1E9c/b18BhPteeNkIwbOO3E2lBnqhM7d/CMFvm6DhrYuPEd5j261z2I8GL8m +sBcpybw==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1p7IIS-000qwa-OK; Mon, 19 Dec 2022 15:43:20 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 9B358300193; Mon, 19 Dec 2022 16:43:06 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 6037520A1AB9F; Mon, 19 Dec 2022 16:43:06 +0100 (CET) Message-ID: <20221219153525.632521981@infradead.org> User-Agent: quilt/0.66 Date: Mon, 19 Dec 2022 16:35:25 +0100 From: Peter Zijlstra <peterz@infradead.org> To: torvalds@linux-foundation.org Cc: corbet@lwn.net, will@kernel.org, peterz@infradead.org, boqun.feng@gmail.com, mark.rutland@arm.com, catalin.marinas@arm.com, dennis@kernel.org, tj@kernel.org, cl@linux.com, hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, borntraeger@linux.ibm.com, svens@linux.ibm.com, Herbert Xu <herbert@gondor.apana.org.au>, davem@davemloft.net, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, joro@8bytes.org, suravee.suthikulpanit@amd.com, robin.murphy@arm.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, Arnd Bergmann <arnd@arndb.de>, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, Andrew Morton <akpm@linux-foundation.org>, vbabka@suse.cz, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-s390@vger.kernel.org, linux-crypto@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org Subject: [RFC][PATCH 00/12] Introduce cmpxchg128() -- aka. the demise of cmpxchg_double() X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752657890816300700?= X-GMAIL-MSGID: =?utf-8?q?1752657890816300700?= |
Series |
Introduce cmpxchg128() -- aka. the demise of cmpxchg_double()
|
|
Message
Peter Zijlstra
Dec. 19, 2022, 3:35 p.m. UTC
Hi, Since Linus hated on cmpxchg_double(), a few patches to get rid of it, as proposed here: https://lkml.kernel.org/r/Y2U3WdU61FvYlpUh@hirez.programming.kicks-ass.net based on tip/master because Linus' tree is moving a wee bit fast at the moment. 0day robot is all green for building, very limited testing on arm64/s390 for obvious raisins -- I tried to get the asm right, but please, double check.
Comments
Hi Peter, On Mon, Dec 19, 2022 at 04:35:25PM +0100, Peter Zijlstra wrote: > Hi, > > Since Linus hated on cmpxchg_double(), a few patches to get rid of it, as proposed here: > > https://lkml.kernel.org/r/Y2U3WdU61FvYlpUh@hirez.programming.kicks-ass.net > > based on tip/master because Linus' tree is moving a wee bit fast at the moment. > > 0day robot is all green for building, very limited testing on arm64/s390 > for obvious raisins -- I tried to get the asm right, but please, double > check. > I added some test cases for cmpxcgh128 APIs, and found two issues. I will reply separately in the patches. The test cases themselves are at the end, let me know if you want to me to send a proper patch. Regards, Boqun ------------------------------------------------------------>8 Subject: [PATCH] atomic: Add test cases for cmpxchg128 family Besides for 32bit and 64bit cmpxchg, we only test via atomic_cmpxchg_* APIs, add tests via cmpxchg* APIs while we are at it. Signed-off-by: Boqun Feng <boqun.feng@gmail.com> --- lib/atomic64_test.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/atomic64_test.c b/lib/atomic64_test.c index d9d170238165..7f79d0704ba8 100644 --- a/lib/atomic64_test.c +++ b/lib/atomic64_test.c @@ -76,12 +76,19 @@ do { \ BUG_ON(atomic##bit##_read(&v) != expect); \ } while (0) +#define TEST_ARGS_PLAIN(_, op, init, ret, expect, args...) \ +do { \ + __WRITE_ONCE(n, init); \ + BUG_ON(op(&n, ##args) != ret); \ + BUG_ON(__READ_ONCE(n) != expect); \ +} while (0) + #define XCHG_FAMILY_TEST(bit, init, new) \ do { \ FAMILY_TEST(TEST_ARGS, bit, xchg, init, init, new, new); \ } while (0) -#define CMPXCHG_FAMILY_TEST(bit, init, new, wrong) \ +#define ATOMIC_CMPXCHG_FAMILY_TEST(bit, init, new, wrong) \ do { \ FAMILY_TEST(TEST_ARGS, bit, cmpxchg, \ init, init, new, init, new); \ @@ -89,6 +96,14 @@ do { \ init, init, init, wrong, new); \ } while (0) +#define CMPXCHG_FAMILY_TEST(bit, init, new, wrong) \ +do { \ + FAMILY_TEST(TEST_ARGS_PLAIN, _, cmpxchg##bit, \ + init, init, new, init, new); \ + FAMILY_TEST(TEST_ARGS_PLAIN, _, cmpxchg##bit, \ + init, init, init, wrong, new); \ +} while (0) + #define INC_RETURN_FAMILY_TEST(bit, i) \ do { \ FAMILY_TEST(TEST_ARGS, bit, inc_return, \ @@ -109,6 +124,7 @@ static __init void test_atomic(void) int one = 1; atomic_t v; + int n; int r; TEST(, add, +=, onestwos); @@ -139,6 +155,7 @@ static __init void test_atomic(void) DEC_RETURN_FAMILY_TEST(, v0); XCHG_FAMILY_TEST(, v0, v1); + ATOMIC_CMPXCHG_FAMILY_TEST(, v0, v1, onestwos); CMPXCHG_FAMILY_TEST(, v0, v1, onestwos); } @@ -155,6 +172,7 @@ static __init void test_atomic64(void) int r_int; atomic64_t v = ATOMIC64_INIT(v0); + long long n = 0; long long r = v0; BUG_ON(v.counter != r); @@ -201,6 +219,7 @@ static __init void test_atomic64(void) DEC_RETURN_FAMILY_TEST(64, v0); XCHG_FAMILY_TEST(64, v0, v1); + ATOMIC_CMPXCHG_FAMILY_TEST(64, v0, v1, v2); CMPXCHG_FAMILY_TEST(64, v0, v1, v2); INIT(v0); @@ -245,10 +264,30 @@ static __init void test_atomic64(void) BUG_ON(!r_int); } +#ifdef system_has_cmpxchg128 +static __init void test_atomic128(void) +{ + long long v0 = 0xaaa31337c001d00dLL; + long long v1 = 0xdeadbeefdeafcafeLL; + long long v2 = 0xfaceabadf00df001LL; + long long v3 = 0x8000000000000000LL; + + s128 init = ((s128)v0 << 64) + v1; + s128 new = ((s128)v1 << 64) + v0; + s128 wrong = ((s128)v2 << 64) + v3; + s128 n = 1; + + CMPXCHG_FAMILY_TEST(128, init, new, wrong); +} +#else +static __init void test_atomic128(void) {} +#endif + static __init int test_atomics_init(void) { test_atomic(); test_atomic64(); + test_atomic128(); #ifdef CONFIG_X86 pr_info("passed for %s platform %s CX8 and %s SSE\n",