public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Boqun Feng <boqun.feng@gmail.com>
To: Alice Ryhl <aliceryhl@google.com>
Cc: "Peter Zijlstra" <peterz@infradead.org>,
	"Ingo Molnar" <mingo@redhat.com>, "Will Deacon" <will@kernel.org>,
	"Waiman Long" <longman@redhat.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rust: sync: document that Guard is not a stable lock guard
Date: Fri, 6 Dec 2024 10:28:18 -0800	[thread overview]
Message-ID: <Z1NCQiGRopuS-Uc8@tardis.local> (raw)
In-Reply-To: <CAH5fLgi8N6bdke1o_uTvYsYfwH1KhsY4wTGmFpc43Mi_U6+KWg@mail.gmail.com>

On Fri, Dec 06, 2024 at 10:56:23AM +0100, Alice Ryhl wrote:
> On Thu, Dec 5, 2024 at 7:18 PM Boqun Feng <boqun.feng@gmail.com> wrote:
> >
> > On Thu, Dec 05, 2024 at 12:35:51PM +0000, Alice Ryhl wrote:
> > > Most locks in the linux kernel are stable, which means that holding the
> > > lock is sufficient to keep the value from being freed. For example, this
> > > means that if you acquire a lock on a refcounted value during rcu, then
> > > you do not need to acquire a refcount to keep it alive past
> > > rcu_read_unlock().
> > >
> > > However, the Rust `Guard` type is written in a way where it cannot be
> > > used with this pattern. One reason for this is the existence of the
> > > `do_unlocked` method that is used with `Condvar`. The method allows you
> > > to unlock the lock, run some code, and then reacquire the lock. This
> > > operation is not okay if the lock itself is what keeps the value alive,
> > > as it could be freed right after the unlock call.
> > >
> >
> > Hmm... but `Guard` holds a reference to the corresponding `Lock`. How
> > could this happen? Do you have an example?
> 
> Well it can't. The reference is yet another reason that Guard can't be
> used for stable locking.
> 
> This doc change arises out of me needing a stable lock for something.
> 

Maybe it's better to put together this patch and the stable locking you
are working on? It's better for reviewing in that way.

I can see what a "stable lock' means, but want to make sure we change
the doc to reflect the exact requirement of a stable lock.

Regards,
Boqun

> Alice

  reply	other threads:[~2024-12-06 18:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-05 12:35 [PATCH] rust: sync: document that Guard is not a stable lock guard Alice Ryhl
2024-12-05 18:17 ` Boqun Feng
2024-12-06  9:56   ` Alice Ryhl
2024-12-06 18:28     ` Boqun Feng [this message]
2024-12-09  7:36       ` Alice Ryhl

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=Z1NCQiGRopuS-Uc8@tardis.local \
    --to=boqun.feng@gmail.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    --cc=will@kernel.org \
    /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