From nobody Thu Feb 12 03:02:25 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D658C77B7E for ; Sat, 29 Apr 2023 07:18:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231285AbjD2HSW (ORCPT ); Sat, 29 Apr 2023 03:18:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230367AbjD2HSL (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 7307A1986; Sat, 29 Apr 2023 00:18:10 -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=1682752689; 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=tRhCCejpzm0RXldiHqnjEzlzmWOKb5783p3jHTZDtac=; b=BsoLsvi78TEW8WDDQ509gajzd36l1cw5CQP4YLSvMNLvZfCI8TOAuW/dCCFazg8Q9xw4BW hCpGx4QpN5qRPgYj7/nI+IWkf7eKJWtSBlcgT3bqNvjX/EtxCLFKqLyud1426IpxYT8TYc HfD6c/ceeuIxAUXQgiq+QJUF8AXcWEqkjgQmvq672dn6JK0WRuykNWZOHsVzLUqRdLihpP Ef8AUvEfLQx4Cu3rawZ3SKq/wrwBFxbZL2X0pxcr1gA9PSJREwTQoHHWkibv51ahogiBHN brOaCbyjd+AhJr4Wqo1T+14Pc8QbPPrjI51Aq6eOWjw/JfcgxRLp1Mv/zpnt+g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1682752689; 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=tRhCCejpzm0RXldiHqnjEzlzmWOKb5783p3jHTZDtac=; b=kmSq7Ti/ijZvM160oP/39O6q84ESu7nRvuvGfGxHg+6deYHap0exWN3YETPqgr/lK8uJd6 qWRvWcTEYdQX76CA== 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/atomic: Add generic try_cmpxchg{,64}_local() support 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-2-ubizjak@gmail.com> References: <20230405141710.3551-2-ubizjak@gmail.com> MIME-Version: 1.0 Message-ID: <168275268860.404.10947070268957072577.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the locking/core branch of tip: Commit-ID: e6ce9d741163af0b846637ce6550ae8a671b1588 Gitweb: https://git.kernel.org/tip/e6ce9d741163af0b846637ce6550ae8a6= 71b1588 Author: Uros Bizjak AuthorDate: Wed, 05 Apr 2023 16:17:06 +02:00 Committer: Ingo Molnar CommitterDate: Sat, 29 Apr 2023 09:09:02 +02:00 locking/atomic: Add generic try_cmpxchg{,64}_local() support Add generic support for try_cmpxchg{,64}_local() and their falbacks. These provides the generic try_cmpxchg_local family of functions from the arch_ prefixed version, also adding explicit instrumentation. 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-2-ubizjak@gmail.com Cc: Linus Torvalds --- include/linux/atomic/atomic-arch-fallback.h | 24 +++++++++++++++++++- include/linux/atomic/atomic-instrumented.h | 20 ++++++++++++++++- scripts/atomic/gen-atomic-fallback.sh | 4 +++- scripts/atomic/gen-atomic-instrumented.sh | 2 +- 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/include/linux/atomic/atomic-arch-fallback.h b/include/linux/at= omic/atomic-arch-fallback.h index 4226379..a6e4437 100644 --- a/include/linux/atomic/atomic-arch-fallback.h +++ b/include/linux/atomic/atomic-arch-fallback.h @@ -217,6 +217,28 @@ =20 #endif /* arch_try_cmpxchg64_relaxed */ =20 +#ifndef arch_try_cmpxchg_local +#define arch_try_cmpxchg_local(_ptr, _oldp, _new) \ +({ \ + typeof(*(_ptr)) *___op =3D (_oldp), ___o =3D *___op, ___r; \ + ___r =3D arch_cmpxchg_local((_ptr), ___o, (_new)); \ + if (unlikely(___r !=3D ___o)) \ + *___op =3D ___r; \ + likely(___r =3D=3D ___o); \ +}) +#endif /* arch_try_cmpxchg_local */ + +#ifndef arch_try_cmpxchg64_local +#define arch_try_cmpxchg64_local(_ptr, _oldp, _new) \ +({ \ + typeof(*(_ptr)) *___op =3D (_oldp), ___o =3D *___op, ___r; \ + ___r =3D arch_cmpxchg64_local((_ptr), ___o, (_new)); \ + if (unlikely(___r !=3D ___o)) \ + *___op =3D ___r; \ + likely(___r =3D=3D ___o); \ +}) +#endif /* arch_try_cmpxchg64_local */ + #ifndef arch_atomic_read_acquire static __always_inline int arch_atomic_read_acquire(const atomic_t *v) @@ -2646,4 +2668,4 @@ arch_atomic64_dec_if_positive(atomic64_t *v) #endif =20 #endif /* _LINUX_ATOMIC_FALLBACK_H */ -// 00071fffa021cec66f6290d706d69c91df87bade +// ad2e2b4d168dbc60a73922616047a9bfa446af36 diff --git a/include/linux/atomic/atomic-instrumented.h b/include/linux/ato= mic/atomic-instrumented.h index 0496816..245ba66 100644 --- a/include/linux/atomic/atomic-instrumented.h +++ b/include/linux/atomic/atomic-instrumented.h @@ -2132,6 +2132,24 @@ atomic_long_dec_if_positive(atomic_long_t *v) arch_sync_cmpxchg(__ai_ptr, __VA_ARGS__); \ }) =20 +#define try_cmpxchg_local(ptr, oldp, ...) \ +({ \ + typeof(ptr) __ai_ptr =3D (ptr); \ + typeof(oldp) __ai_oldp =3D (oldp); \ + instrument_atomic_write(__ai_ptr, sizeof(*__ai_ptr)); \ + instrument_atomic_write(__ai_oldp, sizeof(*__ai_oldp)); \ + arch_try_cmpxchg_local(__ai_ptr, __ai_oldp, __VA_ARGS__); \ +}) + +#define try_cmpxchg64_local(ptr, oldp, ...) \ +({ \ + typeof(ptr) __ai_ptr =3D (ptr); \ + typeof(oldp) __ai_oldp =3D (oldp); \ + instrument_atomic_write(__ai_ptr, sizeof(*__ai_ptr)); \ + instrument_atomic_write(__ai_oldp, sizeof(*__ai_oldp)); \ + arch_try_cmpxchg64_local(__ai_ptr, __ai_oldp, __VA_ARGS__); \ +}) + #define cmpxchg_double(ptr, ...) \ ({ \ typeof(ptr) __ai_ptr =3D (ptr); \ @@ -2149,4 +2167,4 @@ atomic_long_dec_if_positive(atomic_long_t *v) }) =20 #endif /* _LINUX_ATOMIC_INSTRUMENTED_H */ -// 1b485de9cbaa4900de59e14ee2084357eaeb1c3a +// 97fe4d79aa058d2164df824632cbc4f716d2a407 diff --git a/scripts/atomic/gen-atomic-fallback.sh b/scripts/atomic/gen-ato= mic-fallback.sh index 3a07695..6e853f0 100755 --- a/scripts/atomic/gen-atomic-fallback.sh +++ b/scripts/atomic/gen-atomic-fallback.sh @@ -225,6 +225,10 @@ for cmpxchg in "cmpxchg" "cmpxchg64"; do gen_try_cmpxchg_fallbacks "${cmpxchg}" done =20 +for cmpxchg in "cmpxchg_local" "cmpxchg64_local"; do + gen_try_cmpxchg_fallback "${cmpxchg}" "" +done + grep '^[a-z]' "$1" | while read name meta args; do gen_proto "${meta}" "${name}" "atomic" "int" ${args} done diff --git a/scripts/atomic/gen-atomic-instrumented.sh b/scripts/atomic/gen= -atomic-instrumented.sh index 77c0652..c8165e9 100755 --- a/scripts/atomic/gen-atomic-instrumented.sh +++ b/scripts/atomic/gen-atomic-instrumented.sh @@ -173,7 +173,7 @@ for xchg in "xchg" "cmpxchg" "cmpxchg64" "try_cmpxchg" = "try_cmpxchg64"; do done done =20 -for xchg in "cmpxchg_local" "cmpxchg64_local" "sync_cmpxchg"; do +for xchg in "cmpxchg_local" "cmpxchg64_local" "sync_cmpxchg" "try_cmpxchg_= local" "try_cmpxchg64_local" ; do gen_xchg "${xchg}" "" "" printf "\n" done