From patchwork Thu Apr 13 11:38:30 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: 82925 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp965487vqo; Thu, 13 Apr 2023 04:39:21 -0700 (PDT) X-Google-Smtp-Source: AKy350azlVg8GDHGRt12VrDhXpWA/xDYFryO8IV52iuzBO+fSunTV/7wNbtlvqrgSDJCD8tLRErZ X-Received: by 2002:a05:6a00:218f:b0:63b:1853:29a3 with SMTP id h15-20020a056a00218f00b0063b185329a3mr3219842pfi.25.1681385960853; Thu, 13 Apr 2023 04:39:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681385960; cv=none; d=google.com; s=arc-20160816; b=ZnQvUp4r0wA8f+Tc8F8VZcBi1f9vVuqDnts3J87FZ3epOMXGxbVIORKZ40d4CJyIvW JPQVPisBmGkO21Ds8O7/iqC8P9kXz8KduDPC/APkWacn8ByZ3jHgz2Iw+S9fqtm+6EpC fUnGx/3gvWNLzNsNVAqC5erPN5Fr/1AM6GxZr9sZsgyF1eK1WWUJ/CeG9pYt60YnzmIF sx/ZNoQsQSytNUuRakM4LrxYavCgdTl+zuBerP2rAeepzlxpQom31c8us9ikLRtyYtLe Pmd/qdxkBp3OwkXE5NR81+8LQPHzmRdzJ1OLyIyZuVzVpziKWBIzHOgJfqDjswtbDHTM IvWQ== 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=CrJur1YwyQC6UpMSRQKfbtGbDIthO3tAdBH2QlbRHgw=; b=hvkBFAIMw9QKeSMDmpFtq9eY+hvjBcvUf6He+oSBWUYdbkWp7D91jJTf4mk15H7FNQ 5HS5R/Ye27sOe0wFQXD+6sYwa/N3PYzENmiUkIWPBt7qkh7uwmQcBrG8w5LTJ64oPUBI pOdP/Z6GZNMOd/0L1WW6Dcr48s4V1Ii6esek3GXN0Jt3s+Z6IWiAshB2nBtSibEPzMBO tpKw6XNw8F0nV1qfbVS5K4QjBd4Q8k8Sh1YAESeNSM0EYi+p8MjO+gpnJGuxbvNhjzLZ hcUhSVBGuaz3nhxRITQw2DBosoSxeR8IHi8kPDA39WeYi2Wdy/I1eqNI2E6xZMpwnggp lCCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=MkPd6b6O; dkim=neutral (no key) header.i=@linutronix.de; 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 e18-20020a056a0000d200b0063b217d67aesi1565516pfj.167.2023.04.13.04.39.09; Thu, 13 Apr 2023 04:39:20 -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=MkPd6b6O; dkim=neutral (no key) header.i=@linutronix.de; 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 S230084AbjDMLij (ORCPT + 99 others); Thu, 13 Apr 2023 07:38:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229506AbjDMLie (ORCPT ); Thu, 13 Apr 2023 07:38:34 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50AB626B8; Thu, 13 Apr 2023 04:38:33 -0700 (PDT) Date: Thu, 13 Apr 2023 11:38:30 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1681385911; 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=CrJur1YwyQC6UpMSRQKfbtGbDIthO3tAdBH2QlbRHgw=; b=MkPd6b6Ors5JGQF0ule2UsJ2c83QdqqGoAlZ7VwtsRIA+ov/N1B3kcIzSuZQZTYrnR4POM MrlZPldmMV5GN4iGKwG1aJ95jt4p6WuLSJ26ScL/Ye/Tftqce3djxCPnLfawN6L6qInAMX WQ9e91RHPOLEFjivyFasgS/qiIjc7MYFpVEGWswNyYusO6SRmaXaDH2CIWQ+b0EqE2AFTr 0YUFi59qb11R34qDF3szZfQcFjZe9UVzsmsduRYvBG3EPqV7k7PEWkS1oYISyZ+5irVW25 XAVBxBpjksoBbDMGm56OHCMqcYeuFiLRzkHACgXj8G+PpUfo6UgHnAP7i6hjvA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1681385911; 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=CrJur1YwyQC6UpMSRQKfbtGbDIthO3tAdBH2QlbRHgw=; b=6Lc8pazT1Bbb+O4OcIsyxJcmzNj53EODMq8VOG/07xewXcPE2ERaE4lXOh+28qt8pKRlbN L4mCpIYM9OOxoWAw== 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)" , Mark Rutland , 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: <168138591104.404.18396770570686121527.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,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?1762346535249178714?= X-GMAIL-MSGID: =?utf-8?q?1763060965366422225?= The following commit has been merged into the locking/core branch of tip: Commit-ID: 1e9653c8289cf4b3c8690b558cdbe717d99e673a Gitweb: https://git.kernel.org/tip/1e9653c8289cf4b3c8690b558cdbe717d99e673a Author: Uros Bizjak AuthorDate: Wed, 05 Apr 2023 16:17:07 +02:00 Committer: Peter Zijlstra CommitterDate: Wed, 12 Apr 2023 16:46:34 +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) Acked-by: Mark Rutland Link: https://lore.kernel.org/r/20230405141710.3551-3-ubizjak@gmail.com --- 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)