From nobody Wed Dec 17 23:10:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 241C7168AEB; Wed, 1 May 2024 23:21:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714605695; cv=none; b=giEuHvAQYRlLe8WgMBQych5xyyeIF4WeB4MXoSW7phZwl8L7oRDoODKBeXgIkUpu8nzSp7HpNLQSJXd7GnMzKipTxy6dVp/ugI7wwneFii7tEjD3Qifo+J0q3cigX+Bd22u/OgqViA3kOfuTb1K5O/cK6I5UR+/KPm/jUYfKcZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714605695; c=relaxed/simple; bh=ibJ7tBfcSHE8gIrgfKmrh4eEE1rQM1LM/7svDbVFHa0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AAhHyW4kXgGt3Jd/gKKaRbIHNHXeVIY0trZuPOclA8KzXC7/U0izFBYW0L6853oNYEb5d8bVGkGcPkoSfQ8cs8Thegu1KOiQlMF2TkBhYA03b15YHH6zN+KVc22RGZQb9Rt1Rp2vsohqAgz4GpgTEnJeAqiTZIQ5xPvVVWfL8FE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ey/sscED; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ey/sscED" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5CD3C072AA; Wed, 1 May 2024 23:21:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714605694; bh=ibJ7tBfcSHE8gIrgfKmrh4eEE1rQM1LM/7svDbVFHa0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ey/sscEDF9TXLGAIQyztoHiDad6TZo3EhhsYRD4q8JDRioozq1/o2dJh3aNT281YM Far2IKzktYWQpiz89L7i+DRjK/X9rnpeGjqEDMzsQKNif9JBWeDWmkqg2XnnYRQPtQ 1TfLNqGbktjclvRFZNpukKhgWTLxUMsiib3gb8K4wTWzB56t4IsU6MzI8O4gS/13XD c8SdgCkmYXy6npvGuvsLMSmfiljQwt8oAnBk1SmXf+jLWCve/s+XUnyt+tzIhJjZ+I E6yGTk6qIeN+fkhaIYAIz87TLOSOw1HF/+4QXO1yFeY6U6Zir6OqQcflq7K3KHxqmF wvZaESnZdl6uQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 62DB5CE1073; Wed, 1 May 2024 16:21:34 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, kernel-team@meta.com, mingo@kernel.org Cc: stern@rowland.harvard.edu, parri.andrea@gmail.com, will@kernel.org, peterz@infradead.org, boqun.feng@gmail.com, npiggin@gmail.com, dhowells@redhat.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr, akiyks@gmail.com, "Paul E. McKenney" , Daniel Lustig , Joel Fernandes , Mark Rutland , Jonathan Corbet , linux-doc@vger.kernel.org Subject: [PATCH memory-model 1/4] Documentation/litmus-tests: Add locking tests to README Date: Wed, 1 May 2024 16:21:29 -0700 Message-Id: <20240501232132.1785861-1-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <42a43181-a431-44bd-8aff-6b305f8111ba@paulmck-laptop> References: <42a43181-a431-44bd-8aff-6b305f8111ba@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit documents the litmus tests in the "locking" directory. [ paulmck: Apply formatting feedback from Andrea Parri. ] Signed-off-by: Paul E. McKenney Cc: Alan Stern Cc: Will Deacon Cc: Peter Zijlstra Cc: Boqun Feng Cc: Nicholas Piggin Cc: David Howells Cc: Jade Alglave Cc: Luc Maranget Cc: "Paul E. McKenney" Cc: Akira Yokosawa Cc: Daniel Lustig Cc: Joel Fernandes Cc: Mark Rutland Cc: Jonathan Corbet Cc: Cc: Acked-by: Andrea Parri --- Documentation/litmus-tests/README | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Documentation/litmus-tests/README b/Documentation/litmus-tests= /README index 658d37860d397..26ca56df02125 100644 --- a/Documentation/litmus-tests/README +++ b/Documentation/litmus-tests/README @@ -22,6 +22,35 @@ Atomic-RMW-ops-are-atomic-WRT-atomic_set.litmus NOTE: Require herd7 7.56 or later which supports "(void)expr". =20 =20 +locking (/locking directory) +---------------------------- + +DCL-broken.litmus + Demonstrates that double-checked locking needs more than just + the obvious lock acquisitions and releases. + +DCL-fixed.litmus + Demonstrates corrected double-checked locking that uses + smp_store_release() and smp_load_acquire() in addition to the + obvious lock acquisitions and releases. + +RM-broken.litmus + Demonstrates problems with "roach motel" locking, where code is + freely moved into lock-based critical sections. This example also + shows how to use the "filter" clause to discard executions that + would be excluded by other code not modeled in the litmus test. + Note also that this "roach motel" optimization is emulated by + physically moving P1()'s two reads from x under the lock. + + What is a roach motel? This is from an old advertisement for + a cockroach trap, much later featured in one of the "Men in + Black" movies. "The roaches check in. They don't check out." + +RM-fixed.litmus + The counterpart to RM-broken.litmus, showing P0()'s two loads from + x safely outside of the critical section. + + RCU (/rcu directory) -------------------- =20 --=20 2.40.1 From nobody Wed Dec 17 23:10:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24122168AE2; Wed, 1 May 2024 23:21:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714605695; cv=none; b=MXE8Nv7vfxIyegR5ZHusBQY4j0vgoaIDtWcnv+LPkdWgbALWwyMbty/vpTisnZ1j/+qUW0t9XCYYsxR9935tkIJWWixWhqsMOdZIU4GHs6vvWU55UNuxLhf6qvKaRLxSL+Ndo0waVUgWKz2lSXwKzpCPYwpx659GLQh+OPeVHWc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714605695; c=relaxed/simple; bh=PjIIBgLr+DWstHxKJAAho0J12+hAPDhHwNbpvgl5zCA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QjDIyEcmVF6RuQPpkSWzskZu89SdNOa3+lf0kKVEoU/TcEWNR9LX0gs2i55EB1I2e5FErYXdO1KHrZWBEl3CctPGCyZpHLyU7bqbMlXk2OEtirAtDLfTYOvfeyAHn3BRNKKm3/HfVtmIFmctSIhIWhqvvw4E7bEERLN3POh+SSY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SAD4W3nm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SAD4W3nm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BCEB1C113CC; Wed, 1 May 2024 23:21:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714605694; bh=PjIIBgLr+DWstHxKJAAho0J12+hAPDhHwNbpvgl5zCA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SAD4W3nmymLlQ101Ufjj+TJsSyo//tQXuHtAPRSXD79p+3bQip6eWH5pV5fOQCRsr 8OUisyyw6+oraEt33gcn80SGacU/H+CzZUXe5PvHQLtTwBLa4Yb3hF1R2+7oPAAnmT m/KvKpe2FjkeZfNn83zirKlEJFk0wRHcrg/VB4VshlmHD7dmg9Vg9lpWcFRa9nRlJf HsjTuCmgDSWBqQ8UrkHSK5U+gJ7jNvOiLfWz3Ye8hBm4bzGGXRujhNakHeQPOy/vML /2sfqun0/G98sv9wBCVtqcx13pZxtThyjnhROMAPORxWrqeSMEH5d/MLDaXwd8T95m DPHpfej2Inl/A== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 671A6CE12E9; Wed, 1 May 2024 16:21:34 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, kernel-team@meta.com, mingo@kernel.org Cc: stern@rowland.harvard.edu, parri.andrea@gmail.com, will@kernel.org, peterz@infradead.org, boqun.feng@gmail.com, npiggin@gmail.com, dhowells@redhat.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr, akiyks@gmail.com, "Paul E. McKenney" , Frederic Weisbecker , Daniel Lustig , Joel Fernandes , Mark Rutland , Jonathan Corbet , linux-doc@vger.kernel.org Subject: [PATCH memory-model 2/4] Documentation/litmus-tests: Demonstrate unordered failing cmpxchg Date: Wed, 1 May 2024 16:21:30 -0700 Message-Id: <20240501232132.1785861-2-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <42a43181-a431-44bd-8aff-6b305f8111ba@paulmck-laptop> References: <42a43181-a431-44bd-8aff-6b305f8111ba@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit adds four litmus tests showing that a failing cmpxchg() operation is unordered unless followed by an smp_mb__after_atomic() operation. Suggested-by: Frederic Weisbecker Signed-off-by: Paul E. McKenney Cc: Alan Stern Cc: Will Deacon Cc: Peter Zijlstra Cc: Boqun Feng Cc: Nicholas Piggin Cc: David Howells Cc: Jade Alglave Cc: Luc Maranget Cc: "Paul E. McKenney" Cc: Akira Yokosawa Cc: Daniel Lustig Cc: Joel Fernandes Cc: Mark Rutland Cc: Jonathan Corbet Cc: Cc: Acked-by: Andrea Parri --- Documentation/litmus-tests/README | 16 +++++++++ .../atomic/cmpxchg-fail-ordered-1.litmus | 34 +++++++++++++++++++ .../atomic/cmpxchg-fail-ordered-2.litmus | 30 ++++++++++++++++ .../atomic/cmpxchg-fail-unordered-1.litmus | 33 ++++++++++++++++++ .../atomic/cmpxchg-fail-unordered-2.litmus | 30 ++++++++++++++++ 5 files changed, 143 insertions(+) create mode 100644 Documentation/litmus-tests/atomic/cmpxchg-fail-ordered-= 1.litmus create mode 100644 Documentation/litmus-tests/atomic/cmpxchg-fail-ordered-= 2.litmus create mode 100644 Documentation/litmus-tests/atomic/cmpxchg-fail-unordere= d-1.litmus create mode 100644 Documentation/litmus-tests/atomic/cmpxchg-fail-unordere= d-2.litmus diff --git a/Documentation/litmus-tests/README b/Documentation/litmus-tests= /README index 26ca56df02125..6c666f3422ea3 100644 --- a/Documentation/litmus-tests/README +++ b/Documentation/litmus-tests/README @@ -21,6 +21,22 @@ Atomic-RMW-ops-are-atomic-WRT-atomic_set.litmus Test that atomic_set() cannot break the atomicity of atomic RMWs. NOTE: Require herd7 7.56 or later which supports "(void)expr". =20 +cmpxchg-fail-ordered-1.litmus + Demonstrate that a failing cmpxchg() operation acts as a full barrier + when followed by smp_mb__after_atomic(). + +cmpxchg-fail-ordered-2.litmus + Demonstrate that a failing cmpxchg() operation acts as an acquire + operation when followed by smp_mb__after_atomic(). + +cmpxchg-fail-unordered-1.litmus + Demonstrate that a failing cmpxchg() operation does not act as a + full barrier. + +cmpxchg-fail-unordered-2.litmus + Demonstrate that a failing cmpxchg() operation does not act as an + acquire operation. + =20 locking (/locking directory) ---------------------------- diff --git a/Documentation/litmus-tests/atomic/cmpxchg-fail-ordered-1.litmu= s b/Documentation/litmus-tests/atomic/cmpxchg-fail-ordered-1.litmus new file mode 100644 index 0000000000000..3df1d140b189b --- /dev/null +++ b/Documentation/litmus-tests/atomic/cmpxchg-fail-ordered-1.litmus @@ -0,0 +1,34 @@ +C cmpxchg-fail-ordered-1 + +(* + * Result: Never + * + * Demonstrate that a failing cmpxchg() operation will act as a full + * barrier when followed by smp_mb__after_atomic(). + *) + +{} + +P0(int *x, int *y, int *z) +{ + int r0; + int r1; + + WRITE_ONCE(*x, 1); + r1 =3D cmpxchg(z, 1, 0); + smp_mb__after_atomic(); + r0 =3D READ_ONCE(*y); +} + +P1(int *x, int *y, int *z) +{ + int r0; + + WRITE_ONCE(*y, 1); + r1 =3D cmpxchg(z, 1, 0); + smp_mb__after_atomic(); + r0 =3D READ_ONCE(*x); +} + +locations[0:r1;1:r1] +exists (0:r0=3D0 /\ 1:r0=3D0) diff --git a/Documentation/litmus-tests/atomic/cmpxchg-fail-ordered-2.litmu= s b/Documentation/litmus-tests/atomic/cmpxchg-fail-ordered-2.litmus new file mode 100644 index 0000000000000..54146044a16f6 --- /dev/null +++ b/Documentation/litmus-tests/atomic/cmpxchg-fail-ordered-2.litmus @@ -0,0 +1,30 @@ +C cmpxchg-fail-ordered-2 + +(* + * Result: Never + * + * Demonstrate use of smp_mb__after_atomic() to make a failing cmpxchg + * operation have acquire ordering. + *) + +{} + +P0(int *x, int *y) +{ + int r0; + int r1; + + WRITE_ONCE(*x, 1); + r1 =3D cmpxchg(y, 0, 1); +} + +P1(int *x, int *y) +{ + int r0; + + r1 =3D cmpxchg(y, 0, 1); + smp_mb__after_atomic(); + r2 =3D READ_ONCE(*x); +} + +exists (0:r1=3D0 /\ 1:r1=3D1 /\ 1:r2=3D0) diff --git a/Documentation/litmus-tests/atomic/cmpxchg-fail-unordered-1.lit= mus b/Documentation/litmus-tests/atomic/cmpxchg-fail-unordered-1.litmus new file mode 100644 index 0000000000000..a727ce23b1a6e --- /dev/null +++ b/Documentation/litmus-tests/atomic/cmpxchg-fail-unordered-1.litmus @@ -0,0 +1,33 @@ +C cmpxchg-fail-unordered-1 + +(* + * Result: Sometimes + * + * Demonstrate that a failing cmpxchg() operation does not act as a + * full barrier. (In contrast, a successful cmpxchg() does act as a + * full barrier.) + *) + +{} + +P0(int *x, int *y, int *z) +{ + int r0; + int r1; + + WRITE_ONCE(*x, 1); + r1 =3D cmpxchg(z, 1, 0); + r0 =3D READ_ONCE(*y); +} + +P1(int *x, int *y, int *z) +{ + int r0; + + WRITE_ONCE(*y, 1); + r1 =3D cmpxchg(z, 1, 0); + r0 =3D READ_ONCE(*x); +} + +locations[0:r1;1:r1] +exists (0:r0=3D0 /\ 1:r0=3D0) diff --git a/Documentation/litmus-tests/atomic/cmpxchg-fail-unordered-2.lit= mus b/Documentation/litmus-tests/atomic/cmpxchg-fail-unordered-2.litmus new file mode 100644 index 0000000000000..a245bac55b578 --- /dev/null +++ b/Documentation/litmus-tests/atomic/cmpxchg-fail-unordered-2.litmus @@ -0,0 +1,30 @@ +C cmpxchg-fail-unordered-2 + +(* + * Result: Sometimes + * + * Demonstrate that a failing cmpxchg() operation does not act as either + * an acquire release operation. (In contrast, a successful cmpxchg() + * does act as both an acquire and a release operation.) + *) + +{} + +P0(int *x, int *y) +{ + int r0; + int r1; + + WRITE_ONCE(*x, 1); + r1 =3D cmpxchg(y, 0, 1); +} + +P1(int *x, int *y) +{ + int r0; + + r1 =3D cmpxchg(y, 0, 1); + r2 =3D READ_ONCE(*x); +} + +exists (0:r1=3D0 /\ 1:r1=3D1 /\ 1:r2=3D0) --=20 2.40.1 From nobody Wed Dec 17 23:10:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2420E168AEC; Wed, 1 May 2024 23:21:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714605695; cv=none; b=aOEp/5GZ9VZMzAluGnLbh4w6yKo3ji+ktEf/qK7vN5/GPYru6ZEFB/f1YEH8xHjGRJqGBVxYVUhTS96R1CuaoIYfXWFDjIw4c52QFsM7yVeY01BgUg+EmfvakGXl+MKIIgO0Ti/Orj6gj1caN5S8y0+3AzUctNytFkKxFWD2qT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714605695; c=relaxed/simple; bh=tN99QeAtJ9rSCHUuXKIZr5kPNcQaT1UKModjibckfc0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HDyBrj9pKijnCeS6FPM1hXl565JnqZtoKQL2R2lK+opNc10yF2oSSUKDwebPNIVFNoiKSC/4TKK00quOzLq5dyx8lnZOpuC94gjV8DZ7RWvi5z6BxwYuJYWf8yGOM57lVVAswzdj3fAtsCgB/Zgs0S0YV3N1Ne8jP/RjM4insc4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AS96LH93; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AS96LH93" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6B9EC4AF1A; Wed, 1 May 2024 23:21:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714605694; bh=tN99QeAtJ9rSCHUuXKIZr5kPNcQaT1UKModjibckfc0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AS96LH93+Xv7uqyFVwP7Ifz/QqcBdBaP5BGxQ4L0EAKdW6laZio2vPkeRSX6XRuKE xZJvNqkbdAOtJLv6R/FSAflXrHWOP5kQS4UFIE6lCBffZuLWzagw0pvF3rHTIysJ62 hBcLQcvkVn8NWM+SoK5K0vkJATmyO7aVfGwvAKRJrBSxWANKtyE2slV8h30k98amrx +rCjY+9VY+m9Vlc7LOAmKOZqhCK3H5xnkh5SzAE3LRfmaN+xlVItrgESbIVnMLO41l ATk9IXV/NjDDBos5BU++QwnyulVUIwu9SOHINzQBhyP65F6c+UdwggBy02KOwdq3iM G3bcO0UI+DoXg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 6A93DCE1415; Wed, 1 May 2024 16:21:34 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, kernel-team@meta.com, mingo@kernel.org Cc: stern@rowland.harvard.edu, parri.andrea@gmail.com, will@kernel.org, peterz@infradead.org, boqun.feng@gmail.com, npiggin@gmail.com, dhowells@redhat.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr, akiyks@gmail.com, "Paul E. McKenney" , Anna-Maria Behnsen , Daniel Lustig , Joel Fernandes , Mark Rutland , Jonathan Corbet , linux-doc@vger.kernel.org Subject: [PATCH memory-model 3/4] Documentation/atomic_t: Emphasize that failed atomic operations give no ordering Date: Wed, 1 May 2024 16:21:31 -0700 Message-Id: <20240501232132.1785861-3-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <42a43181-a431-44bd-8aff-6b305f8111ba@paulmck-laptop> References: <42a43181-a431-44bd-8aff-6b305f8111ba@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The ORDERING section of Documentation/atomic_t.txt can easily be read as saying that conditional atomic RMW operations that fail are ordered when those operations have the _acquire() or _release() suffixes. This is not the case, therefore update this section to make it clear that failed conditional atomic RMW operations provide no ordering. Reported-by: Anna-Maria Behnsen Signed-off-by: Paul E. McKenney Cc: Alan Stern Cc: Will Deacon Cc: Peter Zijlstra Cc: Boqun Feng Cc: Nicholas Piggin Cc: David Howells Cc: Jade Alglave Cc: Luc Maranget Cc: "Paul E. McKenney" Cc: Akira Yokosawa Cc: Daniel Lustig Cc: Joel Fernandes Cc: Mark Rutland Cc: Jonathan Corbet Cc: Cc: Acked-by: Andrea Parri Acked-by: Mark Rutland --- Documentation/atomic_t.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/atomic_t.txt b/Documentation/atomic_t.txt index d7adc6d543db4..bee3b1bca9a7b 100644 --- a/Documentation/atomic_t.txt +++ b/Documentation/atomic_t.txt @@ -171,14 +171,14 @@ The rule of thumb: - RMW operations that are conditional are unordered on FAILURE, otherwise the above rules apply. =20 -Except of course when an operation has an explicit ordering like: +Except of course when a successful operation has an explicit ordering like: =20 {}_relaxed: unordered {}_acquire: the R of the RMW (or atomic_read) is an ACQUIRE {}_release: the W of the RMW (or atomic_set) is a RELEASE =20 Where 'unordered' is against other memory locations. Address dependencies = are -not defeated. +not defeated. Conditional operations are still unordered on FAILURE. =20 Fully ordered primitives are ordered against everything prior and everythi= ng subsequent. Therefore a fully ordered primitive is like having an smp_mb() --=20 2.40.1 From nobody Wed Dec 17 23:10:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24170168AE4; Wed, 1 May 2024 23:21:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714605695; cv=none; b=FuNbdhJS4tvYv9I+l9bkWjQIVZxwKDreO5ydnpQBwBXF6qk5ngeEZEgHjGjGZ4TpOJWtPP0a3QuL0Gs+X/ZJhY/iTg/LlFilhRdZ4G+vwm0qruwu7/y4bWSslDI472/6EPYsvn8lVyHvrH7SkRgyyWqAu/MKBLx13/0ag0Fca1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714605695; c=relaxed/simple; bh=M3rljuLjY3UhKUT1g/wRug4MwuxiMyvh+qPJzdYy2n4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PYBEZMFBvKj1gsLau7O9NJvYNH+Uyf6RG8Lnsyz4fw7K/FYs+UGXste0eKfysqAVmq9iyv4yiw3nsaJK59PIYPQFPgnujVz10T9RINc9DIFwCMldWs1N0eXrhnGLXmSph+XEoMSriOjt6+oyp4QqosKaQkBFrfdET5Qsd73/0Ck= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XYTtNkxc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XYTtNkxc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C658FC4AF19; Wed, 1 May 2024 23:21:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714605694; bh=M3rljuLjY3UhKUT1g/wRug4MwuxiMyvh+qPJzdYy2n4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XYTtNkxcIF5q4iFu1XBRlQYGdaxLZWZJ8F6KFhl5o9Snvpvdb+dJ1dR6L83txqSRF NtHxoQMzq4v3IsZupeVTZBd3OPEwx0omr5rgnPUyu1TyirQ+97ZyDXl5ADF1XcC1fS e/fiyecpV7QjniY+q1u/MWyPkDqPYnI7AV3qqaMYXzSEa4qXTrYdY4/a0nVUdpcGmu VQS6pHNkdwqfTfs+ivFH+mevHSitULh1foSkbLQl4pevPWgKrr3LIOerYVFgWmxXNO oeFlVmL58qCv9N5RlSJJd7yUGkyaCn9dFC9luH0UWwGL/YVKPwO0DnctLgFPt73acY plqXwLCNADlXQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 6DAF0CE1A05; Wed, 1 May 2024 16:21:34 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, kernel-team@meta.com, mingo@kernel.org Cc: stern@rowland.harvard.edu, parri.andrea@gmail.com, will@kernel.org, peterz@infradead.org, boqun.feng@gmail.com, npiggin@gmail.com, dhowells@redhat.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr, akiyks@gmail.com, "Paul E. McKenney" Subject: [PATCH memory-model 4/4] Documentation/litmus-tests: Make cmpxchg() tests safe for klitmus Date: Wed, 1 May 2024 16:21:32 -0700 Message-Id: <20240501232132.1785861-4-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <42a43181-a431-44bd-8aff-6b305f8111ba@paulmck-laptop> References: <42a43181-a431-44bd-8aff-6b305f8111ba@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The four litmus tests in Documentation/litmus-tests/atomic do not declare all of their local variables. Although this is just fine for LKMM analysis by herd7, it causes build failures when run in-kernel by klitmus. This commit therefore adjusts these tests to declare all local variables. Reported-by: Andrea Parri Signed-off-by: Paul E. McKenney Acked-by: Andrea Parri --- .../litmus-tests/atomic/cmpxchg-fail-ordered-1.litmus | 1 + .../litmus-tests/atomic/cmpxchg-fail-ordered-2.litmus | 4 ++-- .../litmus-tests/atomic/cmpxchg-fail-unordered-1.litmus | 1 + .../litmus-tests/atomic/cmpxchg-fail-unordered-2.litmus | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Documentation/litmus-tests/atomic/cmpxchg-fail-ordered-1.litmu= s b/Documentation/litmus-tests/atomic/cmpxchg-fail-ordered-1.litmus index 3df1d140b189b..c0f93dc07105e 100644 --- a/Documentation/litmus-tests/atomic/cmpxchg-fail-ordered-1.litmus +++ b/Documentation/litmus-tests/atomic/cmpxchg-fail-ordered-1.litmus @@ -23,6 +23,7 @@ P0(int *x, int *y, int *z) P1(int *x, int *y, int *z) { int r0; + int r1; =20 WRITE_ONCE(*y, 1); r1 =3D cmpxchg(z, 1, 0); diff --git a/Documentation/litmus-tests/atomic/cmpxchg-fail-ordered-2.litmu= s b/Documentation/litmus-tests/atomic/cmpxchg-fail-ordered-2.litmus index 54146044a16f6..5c06054f46947 100644 --- a/Documentation/litmus-tests/atomic/cmpxchg-fail-ordered-2.litmus +++ b/Documentation/litmus-tests/atomic/cmpxchg-fail-ordered-2.litmus @@ -11,7 +11,6 @@ C cmpxchg-fail-ordered-2 =20 P0(int *x, int *y) { - int r0; int r1; =20 WRITE_ONCE(*x, 1); @@ -20,7 +19,8 @@ P0(int *x, int *y) =20 P1(int *x, int *y) { - int r0; + int r1; + int r2; =20 r1 =3D cmpxchg(y, 0, 1); smp_mb__after_atomic(); diff --git a/Documentation/litmus-tests/atomic/cmpxchg-fail-unordered-1.lit= mus b/Documentation/litmus-tests/atomic/cmpxchg-fail-unordered-1.litmus index a727ce23b1a6e..39ea1f56a28d2 100644 --- a/Documentation/litmus-tests/atomic/cmpxchg-fail-unordered-1.litmus +++ b/Documentation/litmus-tests/atomic/cmpxchg-fail-unordered-1.litmus @@ -23,6 +23,7 @@ P0(int *x, int *y, int *z) P1(int *x, int *y, int *z) { int r0; + int r1; =20 WRITE_ONCE(*y, 1); r1 =3D cmpxchg(z, 1, 0); diff --git a/Documentation/litmus-tests/atomic/cmpxchg-fail-unordered-2.lit= mus b/Documentation/litmus-tests/atomic/cmpxchg-fail-unordered-2.litmus index a245bac55b578..61aab24a4a643 100644 --- a/Documentation/litmus-tests/atomic/cmpxchg-fail-unordered-2.litmus +++ b/Documentation/litmus-tests/atomic/cmpxchg-fail-unordered-2.litmus @@ -12,7 +12,6 @@ C cmpxchg-fail-unordered-2 =20 P0(int *x, int *y) { - int r0; int r1; =20 WRITE_ONCE(*x, 1); @@ -21,7 +20,8 @@ P0(int *x, int *y) =20 P1(int *x, int *y) { - int r0; + int r1; + int r2; =20 r1 =3D cmpxchg(y, 0, 1); r2 =3D READ_ONCE(*x); --=20 2.40.1