[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aEqsgD2ap2VMpTR9@pollux>
Date: Thu, 12 Jun 2025 12:31:28 +0200
From: Danilo Krummrich <dakr@...nel.org>
To: Benno Lossin <lossin@...nel.org>
Cc: gregkh@...uxfoundation.org, rafael@...nel.org, ojeda@...nel.org,
alex.gaynor@...il.com, boqun.feng@...il.com, gary@...yguo.net,
bjorn3_gh@...tonmail.com, benno.lossin@...ton.me,
a.hindborg@...nel.org, aliceryhl@...gle.com, tmgross@...ch.edu,
chrisi.schrefl@...il.com, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 3/3] rust: devres: fix race in Devres::drop()
On Thu, Jun 12, 2025 at 10:13:29AM +0200, Benno Lossin wrote:
> On Tue Jun 3, 2025 at 10:48 PM CEST, Danilo Krummrich wrote:
> > impl<T> Drop for Devres<T> {
> > fn drop(&mut self) {
> > - DevresInner::remove_action(&self.0);
> > + // SAFETY: When `drop` runs, it is guaranteed that nobody is accessing the revocable data
> > + // anymore, hence it is safe not to wait for the grace period to finish.
> > + if unsafe { self.revoke_nosync() } {
> > + // We revoked `self.0.data` before the devres action did, hence try to remove it.
> > + if !DevresInner::remove_action(&self.0) {
>
> Shouldn't this not be inverted? (ie 's/!//')
>
> Otherwise this will return `true`, get negated and we don't run the code
> below and the `inner.data.revoke()` in `devres_callback` will return
> `false` which will get negated and thus it will never return.
DevresInner::remove_action() returns false it means that the devres action has
already been taken from the list and will be run eventually, hence we have to
complete the completion.
If DevresInner::remove_action() returns true, it means that we removed the
action from the list and the callback will never be exectuted, hence nothing to
do.
> > + // We could not remove the devres action, which means that it now runs concurrently,
> > + // hence signal that `self.0.data` has been revoked successfully.
> > + self.0.revoke.complete_all();
> > + }
> > + }
> > }
> > }
>
Powered by blists - more mailing lists