From nobody Fri Jan 2 17:27:53 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 92D9FCD6119 for ; Mon, 9 Oct 2023 17:49:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378009AbjJIRtV (ORCPT ); Mon, 9 Oct 2023 13:49:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377937AbjJIRtO (ORCPT ); Mon, 9 Oct 2023 13:49:14 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21450A3; Mon, 9 Oct 2023 10:49:11 -0700 (PDT) Date: Mon, 09 Oct 2023 17:49:08 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696873749; 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; bh=AWNPjlwwdK1lk4c+xJcA60ZLb6nJMrrz1GEMuSFR7G8=; b=ZHscMiMQnF93wFaJzBe56PlLgnZrp9ihOJzU+UIDK3HXiAAfWx4nOVRuSTsRguGjoKBXDE 9Qmk2wtk6IL9zrH5e5qWJ6frQQ+QUeNFPZkg1mE6veGesYWEwIbGmlQhITZdXz9hn6qhN4 4xrTZWKcb2c3g8LSPbMAwk7QOm7sZmj1jvKypKDxUxsZ+IvrVgUhfSHt0sgJd0JkDqwcoT Wnh6RvewZ3pUAGyuaOPBVb5tDcZZZaIZOSyxEg9Fq74NfSQ49t6lqnS0BfOH18RaTRetvs S3NHt9DXItG63sCQ57KmYAPjpoHbXBXS6VeAJND1N9F5r27JQB3ei1pYlvfcVQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696873749; 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; bh=AWNPjlwwdK1lk4c+xJcA60ZLb6nJMrrz1GEMuSFR7G8=; b=7tTIJ6OTk7Ky84tUX3lp1hT/76pM7LGerab4LXyQvaPTaTC37UroLbpzIUrVt4XVYTOaWq 2cVdMo0p5JnWtBDQ== 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 support for sync_try_cmpxchg() and its fallback Cc: Uros Bizjak , Ingo Molnar , Will Deacon , Peter Zijlstra , Boqun Feng , Mark Rutland , Linus Torvalds , linux-kernel@vger.kernel.org, x86@kernel.org MIME-Version: 1.0 Message-ID: <169687374861.3135.9482250979449813044.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: e01cc1e8c2ad73cebb980878ede5584e0f2688f7 Gitweb: https://git.kernel.org/tip/e01cc1e8c2ad73cebb980878ede5584e0= f2688f7 Author: Uros Bizjak AuthorDate: Mon, 25 Sep 2023 16:50:23 +02:00 Committer: Ingo Molnar CommitterDate: Mon, 09 Oct 2023 18:14:15 +02:00 locking/atomic: Add generic support for sync_try_cmpxchg() and its fallback Provide the generic sync_try_cmpxchg() function from the raw_ prefixed version, also adding explicit instrumentation. The patch amends existing scripts to generate sync_try_cmpxchg() locking primitive and its raw_sync_try_cmpxchg() fallback, while leaving existing macros from the try_cmpxchg() family unchanged. The target can define its own arch_sync_try_cmpxchg() to override the generic version of raw_sync_try_cmpxchg(). This allows the target to generate more optimal assembly than the generic version. Additionally, the patch renames two scripts to better reflect whet they really do. Signed-off-by: Uros Bizjak Signed-off-by: Ingo Molnar Cc: Will Deacon Cc: Peter Zijlstra Cc: Boqun Feng Cc: Mark Rutland Cc: Linus Torvalds Cc: linux-kernel@vger.kernel.org --- include/linux/atomic/atomic-arch-fallback.h | 15 ++++++++- include/linux/atomic/atomic-instrumented.h | 10 +++++- scripts/atomic/gen-atomic-fallback.sh | 33 ++++++++++---------- scripts/atomic/gen-atomic-instrumented.sh | 3 +- 4 files changed, 43 insertions(+), 18 deletions(-) diff --git a/include/linux/atomic/atomic-arch-fallback.h b/include/linux/at= omic/atomic-arch-fallback.h index b83ef19..5e95faa 100644 --- a/include/linux/atomic/atomic-arch-fallback.h +++ b/include/linux/atomic/atomic-arch-fallback.h @@ -428,6 +428,19 @@ extern void raw_cmpxchg128_relaxed_not_implemented(voi= d); =20 #define raw_sync_cmpxchg arch_sync_cmpxchg =20 +#ifdef arch_sync_try_cmpxchg +#define raw_sync_try_cmpxchg arch_sync_try_cmpxchg +#else +#define raw_sync_try_cmpxchg(_ptr, _oldp, _new) \ +({ \ + typeof(*(_ptr)) *___op =3D (_oldp), ___o =3D *___op, ___r; \ + ___r =3D raw_sync_cmpxchg((_ptr), ___o, (_new)); \ + if (unlikely(___r !=3D ___o)) \ + *___op =3D ___r; \ + likely(___r =3D=3D ___o); \ +}) +#endif + /** * raw_atomic_read() - atomic load with relaxed ordering * @v: pointer to atomic_t @@ -4649,4 +4662,4 @@ raw_atomic64_dec_if_positive(atomic64_t *v) } =20 #endif /* _LINUX_ATOMIC_FALLBACK_H */ -// 2fdd6702823fa842f9cea57a002e6e4476ae780c +// eec048affea735b8464f58e6d96992101f8f85f1 diff --git a/include/linux/atomic/atomic-instrumented.h b/include/linux/ato= mic/atomic-instrumented.h index d401b40..54d7bbe 100644 --- a/include/linux/atomic/atomic-instrumented.h +++ b/include/linux/atomic/atomic-instrumented.h @@ -4998,6 +4998,14 @@ atomic_long_dec_if_positive(atomic_long_t *v) raw_try_cmpxchg128_local(__ai_ptr, __ai_oldp, __VA_ARGS__); \ }) =20 +#define sync_try_cmpxchg(ptr, ...) \ +({ \ + typeof(ptr) __ai_ptr =3D (ptr); \ + kcsan_mb(); \ + instrument_atomic_read_write(__ai_ptr, sizeof(*__ai_ptr)); \ + raw_sync_try_cmpxchg(__ai_ptr, __VA_ARGS__); \ +}) + =20 #endif /* _LINUX_ATOMIC_INSTRUMENTED_H */ -// 1568f875fef72097413caab8339120c065a39aa4 +// 2cc4bc990fef44d3836ec108f11b610f3f438184 diff --git a/scripts/atomic/gen-atomic-fallback.sh b/scripts/atomic/gen-ato= mic-fallback.sh index a45154c..f80d69c 100755 --- a/scripts/atomic/gen-atomic-fallback.sh +++ b/scripts/atomic/gen-atomic-fallback.sh @@ -223,14 +223,15 @@ gen_xchg_fallbacks() =20 gen_try_cmpxchg_fallback() { + local prefix=3D"$1"; shift local cmpxchg=3D"$1"; shift; - local order=3D"$1"; shift; + local suffix=3D"$1"; shift; =20 cat <