From patchwork Sat Apr 29 07:18:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 88858 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1447063vqo; Sat, 29 Apr 2023 00:44:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5JpTaZEMHdrDOV7ie4YuWgBaNZiXtw3zIn4CSxRpmxuwYXfWFc912EOFURxoV3t2YJpNS2 X-Received: by 2002:a17:90b:3443:b0:246:8b47:3d5b with SMTP id lj3-20020a17090b344300b002468b473d5bmr7842152pjb.18.1682754281058; Sat, 29 Apr 2023 00:44:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682754281; cv=none; d=google.com; s=arc-20160816; b=RZmDKpvNdwNqtnZMAUOqtlmXsvRztryEEXtFq6NBtwIhGwPtVKNz2+Extj2gctA+9m MWL8OA9ps5CCaVXLIs6zmP0Q0STbKCKSkuPGhrlYUr31v1RI0tO+nu9/DOMNpLr35Nbp 6Zstn1plhvpWGHwhXu8I297hcAWgTUIbC2n2KEzKVG5iFLsQQb5h9A2ggdWPGaMCd4pL 8J82yenx3l5XgUAEsMrtoKm/CpMDDuXrEX3rPY6tCzoGrNbpy0G+3L8MbDMbppxTlNuD kBihl0wIEVMGedPmjd31evFNEOE241Xan4WCSQn+cQtW21/fPr/Xs+fQyCf765x2UAXW SsWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=b63iX115ZNoUPKmlmdbrVigldjpSVHVka8Pvjgqli88=; b=MOzTgMy0UO2YpFqa8ZAb/lz3GOm3PohVLFW9f1+lPY3hDapfd7/FsfRJ15pShxQFiW qWz3bwrPTs9paEftKANm2R3nxp+dlZ81SB6E5wgPTJEfMFnnYVYmjng7Qk3iItsoBgpQ lCjH6oGLxJg9iD/Pa/uavybG3toHp3ruKtWGsVZkcqeacctc77/6XlUTHAhAznqyeHi1 jN36fZ9onbbLN+uqHR7FJNrcvy6YlgZhrTORdcFUtdeoqqKpgL3x71xlGS7xEVSZa25F uAu0syYE3RdJ2TSvERuXUCCJkhAykJXkbwVkddqOcJao4d0jLkSDr2ShFCLKEmnTdnMN y8IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yoxQKwQy; dkim=neutral (no key) header.i=@linutronix.de header.b=pSLHBVom; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c14-20020a655a8e000000b0051b72db6281si23138237pgt.456.2023.04.29.00.44.29; Sat, 29 Apr 2023 00:44:41 -0700 (PDT) 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=@linutronix.de header.s=2020 header.b=yoxQKwQy; dkim=neutral (no key) header.i=@linutronix.de header.b=pSLHBVom; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231196AbjD2HSZ (ORCPT + 99 others); Sat, 29 Apr 2023 03:18:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230351AbjD2HSL (ORCPT ); Sat, 29 Apr 2023 03:18:11 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9A7F1BFD; Sat, 29 Apr 2023 00:18:09 -0700 (PDT) Date: Sat, 29 Apr 2023 07:18:08 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1682752688; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b63iX115ZNoUPKmlmdbrVigldjpSVHVka8Pvjgqli88=; b=yoxQKwQysW1LJc9ftbNi8Dr/IFGIiBX6RoSmGFp5uEB+DE/caG/XOFLmR0YnDJ9ONfgCdH 2BSYQQ/9ITRXWrdhhiQE0WCVITXVK4WlttefEDi3LSRblHCNp7bsw3WqE6J9LQgQXudXxb p5eiCuqvyHC7gPZvbOUg2fxxxHxxtKy6VEP/Foqe3MVwQaQvau6BT2bpp5Xr6KkvC0OHDk hBKAAVSaZiNZb0IixrqNSLsnGG1kGtrpnHWRkEggqaGyq18ISk//N1pn9l46xzqIxdVy4X Y50JIgcsIeogI6xOrkbIcpb/Gvksc4aZTWGUifhKQnovt/0WyekXwGXulat+Qw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1682752688; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b63iX115ZNoUPKmlmdbrVigldjpSVHVka8Pvjgqli88=; b=pSLHBVomShEy9AiQMG/1bGPz4EfLTXXKnBGcwfrEQM/2p/U8+TczZqbEU0VAW1iuMAfFiE RAEQ1xYHi5LPIQDw== From: "tip-bot2 for Uros Bizjak" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] locking/generic: Wire up local{,64}_try_cmpxchg() Cc: Uros Bizjak , "Peter Zijlstra (Intel)" , Ingo Molnar , Mark Rutland , Linus Torvalds , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230405141710.3551-3-ubizjak@gmail.com> References: <20230405141710.3551-3-ubizjak@gmail.com> MIME-Version: 1.0 Message-ID: <168275268808.404.3641773961517010776.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails 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_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764493337742094625?= X-GMAIL-MSGID: =?utf-8?q?1764495753144819810?= The following commit has been merged into the locking/core branch of tip: Commit-ID: 8fc4fddaf9a184eea7da21290236a1764e608a01 Gitweb: https://git.kernel.org/tip/8fc4fddaf9a184eea7da21290236a1764e608a01 Author: Uros Bizjak AuthorDate: Wed, 05 Apr 2023 16:17:07 +02:00 Committer: Ingo Molnar CommitterDate: Sat, 29 Apr 2023 09:09:09 +02:00 locking/generic: Wire up local{,64}_try_cmpxchg() Implement generic support for local{,64}_try_cmpxchg(). Redirect to the atomic_ family of functions when the target does not provide its own local.h definitions. For 64-bit targets, implement local64_try_cmpxchg and local64_cmpxchg using typed C wrappers that call local_ family of functions and provide additional checking of their input arguments. Signed-off-by: Uros Bizjak Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Acked-by: Mark Rutland Link: https://lore.kernel.org/r/20230405141710.3551-3-ubizjak@gmail.com Cc: Linus Torvalds --- include/asm-generic/local.h | 1 + include/asm-generic/local64.h | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h index fca7f1d..7f97018 100644 --- a/include/asm-generic/local.h +++ b/include/asm-generic/local.h @@ -42,6 +42,7 @@ typedef struct #define local_inc_return(l) atomic_long_inc_return(&(l)->a) #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n)) +#define local_try_cmpxchg(l, po, n) atomic_long_try_cmpxchg((&(l)->a), (po), (n)) #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n)) #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u)) #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a) diff --git a/include/asm-generic/local64.h b/include/asm-generic/local64.h index 765be0b..14963a7 100644 --- a/include/asm-generic/local64.h +++ b/include/asm-generic/local64.h @@ -42,7 +42,16 @@ typedef struct { #define local64_sub_return(i, l) local_sub_return((i), (&(l)->a)) #define local64_inc_return(l) local_inc_return(&(l)->a) -#define local64_cmpxchg(l, o, n) local_cmpxchg((&(l)->a), (o), (n)) +static inline s64 local64_cmpxchg(local64_t *l, s64 old, s64 new) +{ + return local_cmpxchg(&l->a, old, new); +} + +static inline bool local64_try_cmpxchg(local64_t *l, s64 *old, s64 new) +{ + return local_try_cmpxchg(&l->a, (long *)old, new); +} + #define local64_xchg(l, n) local_xchg((&(l)->a), (n)) #define local64_add_unless(l, _a, u) local_add_unless((&(l)->a), (_a), (u)) #define local64_inc_not_zero(l) local_inc_not_zero(&(l)->a) @@ -81,6 +90,7 @@ typedef struct { #define local64_inc_return(l) atomic64_inc_return(&(l)->a) #define local64_cmpxchg(l, o, n) atomic64_cmpxchg((&(l)->a), (o), (n)) +#define local64_try_cmpxchg(l, po, n) atomic64_try_cmpxchg((&(l)->a), (po), (n)) #define local64_xchg(l, n) atomic64_xchg((&(l)->a), (n)) #define local64_add_unless(l, _a, u) atomic64_add_unless((&(l)->a), (_a), (u)) #define local64_inc_not_zero(l) atomic64_inc_not_zero(&(l)->a)