From patchwork Sat Apr 29 07:03:05 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: 88844 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1432686vqo; Sat, 29 Apr 2023 00:06:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6HEOcFfzsQY1aX8ij7X4qT9e9zabe+AzYjPwpC9ZlmDhpPuIsmI2PPi8poubY+sz3r7N3h X-Received: by 2002:a05:6a00:2d9b:b0:633:8cc7:bbd5 with SMTP id fb27-20020a056a002d9b00b006338cc7bbd5mr9405617pfb.11.1682751977543; Sat, 29 Apr 2023 00:06:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682751977; cv=none; d=google.com; s=arc-20160816; b=RFoCqXD5R6izyVmRffzx7Xx8bN/CVUNc9UnDBr48BYCAz9dw0c1ncjLK/Mtl6XftCp YP7kxV7J1g7B5FZrr8s31Nt1Bajjp7/FHqJfxpunV4XSxEFiAASEieFM5+SfnKU84vFf U5ZdadrwYOWhJJrG8rM/1ajry3JzBopsIsLaSai+/zdfs6XjnD3atKQNxkoQJcNUwFUK nPNAGMa+FzcH3ATgj95ubHAhZvwXqwvvKQq32B0GI+d8Nw5nXQI2zhB5WUQZMTzPYlnO rFCexKSfh4vA0LBdBfI/QyL0zyw2Sk5KUyaCGgxF0vbDO2tTmMmltmz2IUNUt1X5Ayx3 543w== 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=5PAHzEtWjSQfsur1ramAAYhxI8qZrfxDsahv84miBHY=; b=Uz3hYu/G+HFaZIUSsRl+LWWvPm/HDbZSmtXmXNjTYLHzzmDdlJQwWlPitLGgqCS4AB 0jrk1rTbxvFzo/N5eIfAWZ8WnkyZ1GMomA05MnzoV1z5q98flx3K1ZD4Vxic07e/0622 qm825Tqqzo5/62kJKueOTMo/P9ax5/cyHQiIn2aPibc7jDyP0Uku3MHkerqFUu1VX3np 3Via8w4rYOxEHo6J0/IibYzFXQ57JGfSkWemQc6FB52nKt+IlLmGGWfT/P+Y8uv7YjpV TpAQr8N7xKEIVYpWTiGHK7C72xZtgLQjzVzuhnfmHKA+X0n4np7OlCSPQ2GNUR/adIZ8 Iukw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="D/lb0GUq"; dkim=neutral (no key) header.i=@linutronix.de header.b=KY181dBr; 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 f12-20020aa7968c000000b0063b7c4435c2si23049718pfk.52.2023.04.29.00.06.02; Sat, 29 Apr 2023 00:06:17 -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="D/lb0GUq"; dkim=neutral (no key) header.i=@linutronix.de header.b=KY181dBr; 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 S231193AbjD2HDU (ORCPT + 99 others); Sat, 29 Apr 2023 03:03:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229509AbjD2HDK (ORCPT ); Sat, 29 Apr 2023 03:03:10 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 645622D49; Sat, 29 Apr 2023 00:03:07 -0700 (PDT) Date: Sat, 29 Apr 2023 07:03:05 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1682751785; 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=5PAHzEtWjSQfsur1ramAAYhxI8qZrfxDsahv84miBHY=; b=D/lb0GUqK9eM7tU+AOt1niQjOcQjGOMXqFTlUy6HBbsZDTfX7GifzBRn/gBYmIvLOWAoyl MZwm7ypYoXpqv8jgAKLVs50dOfOrkh1gFaup7rtTVtQ6aqycZiBlJSFeiixKkFexHOYJlt G9lgDuTrmUXdUs/X5iGxB5YMKI2IBCU3T7KhWAqf4TKUy9V97aHnjRl8jbtp62y2hom0Iq AjBkJsxzfYzlbMfkBdwBwwH4fUX9Qy7Y2Kml9z+B9A2DmNF5UWrLjLONsG6DUKadXtIPAD snSV+yrcGb6DIHY1p+IWSi9Kw4vl+4sWGzYJFLD8JGKDMUyqdg3GGm5yJrfuQQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1682751785; 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=5PAHzEtWjSQfsur1ramAAYhxI8qZrfxDsahv84miBHY=; b=KY181dBrekTYtWpLXRcvy4bVK/TJU56QtzpJODCFzQ7isA8IKt1cA0Ag7UfcT2wqN+tfRK TYV+yfU25ntMyJBQ== 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: <168275178521.404.7881369194752823490.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?1764493337742094625?= The following commit has been merged into the locking/core branch of tip: Commit-ID: 8184667fd00ee1081aa37b3300947d1bfc294210 Gitweb: https://git.kernel.org/tip/8184667fd00ee1081aa37b3300947d1bfc294210 Author: Uros Bizjak AuthorDate: Wed, 05 Apr 2023 16:17:07 +02:00 Committer: Ingo Molnar CommitterDate: Sat, 29 Apr 2023 08:52:16 +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)