From: "Onur Özkan" <work@onurozkan.dev>
To: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: ojeda@kernel.org, "alex.gaynor@gmail.comboqun.feng"@gmail.com,
gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org,
a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu,
dakr@kernel.org, acourbot@nvidia.com, joelagnelf@nvidia.com,
wedsonaf@gmail.com, "Onur Özkan" <work@onurozkan.dev>
Subject: [PATCH] rust: fix outdated safety note in `Revocable::revoke_internal`
Date: Thu, 3 Jul 2025 20:26:05 +0300 [thread overview]
Message-ID: <20250703172605.28891-1-work@onurozkan.dev> (raw)
The code used to use `compare_exchange` in the initial version
but it was changed to `swap` after a reviewer suggestion (see [1]),
and then the safety comment was not updated and became incorrect.
Link: https://lore.kernel.org/all/20241211104742.533392-1-benoit@dugarreau.fr [1]
Signed-off-by: Onur Özkan <work@onurozkan.dev>
---
rust/kernel/revocable.rs | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/rust/kernel/revocable.rs b/rust/kernel/revocable.rs
index 06a3cdfce344..5c0b7afa76fb 100644
--- a/rust/kernel/revocable.rs
+++ b/rust/kernel/revocable.rs
@@ -163,8 +163,10 @@ unsafe fn revoke_internal<const SYNC: bool>(&self) -> bool {
unsafe { bindings::synchronize_rcu() };
}
- // SAFETY: We know `self.data` is valid because only one CPU can succeed the
- // `compare_exchange` above that takes `is_available` from `true` to `false`.
+ // SAFETY: We just used an atomic `swap` to check if the data was still marked
+ // as available. If it returns `true`, that means we are the first (and only)
+ // thread to see it as available and mark it as unavailable. So no other thread
+ // can access or drop the data after this. That makes it safe to drop the data here.
unsafe { drop_in_place(self.data.get()) };
}
--
2.50.0
next reply other threads:[~2025-07-03 17:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-03 17:26 Onur Özkan [this message]
2025-07-03 19:55 ` [PATCH] rust: fix outdated safety note in `Revocable::revoke_internal` Benno Lossin
2025-07-04 5:02 ` Onur
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250703172605.28891-1-work@onurozkan.dev \
--to=work@onurozkan.dev \
--cc="alex.gaynor@gmail.comboqun.feng"@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=joelagnelf@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=wedsonaf@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox