rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Benno Lossin" <lossin@kernel.org>
To: "Alice Ryhl" <aliceryhl@google.com>, "Miguel Ojeda" <ojeda@kernel.org>
Cc: "Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Marcelo Moreira" <marcelomoreira1905@gmail.com>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] revocable: rust: document why &T is not used in RevocableGuard
Date: Thu, 12 Jun 2025 14:15:33 +0200	[thread overview]
Message-ID: <DAKJPI52CL6O.5AHQSFJBEZPR@kernel.org> (raw)
In-Reply-To: <20250612-revocable-ptr-comment-v1-1-db36785877f6@google.com>

On Thu Jun 12, 2025 at 1:17 PM CEST, Alice Ryhl wrote:
> When a reference appears in a function argument, the reference is
> assumed to be valid for the entire duration of that function call; this
> is called a stack protector [1]. Because of that, custom pointer types
> whose destructor may invalidate the pointee (i.e. they are more similar
> to Box<T> than &T) cannot internally use a reference, and must instead
> use a raw pointer.
>
> This issue is something that is often missed during unsafe review. For
> examples, see [2] and [3]. To ensure that people don't try to simplify
> RevocableGuard by changing the raw pointer to a reference, add a comment
> to that effect.
>
> Link: https://perso.crans.org/vanille/treebor/protectors.html [1]
> Link: https://users.rust-lang.org/t/unsafe-code-review-semi-owning-weak-rwlock-t-guard/95706 [2]
> Link: https://lore.kernel.org/all/aEqdur4JTFa1V20U@google.com/ [3]
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>

Thanks!

Reviewed-by: Benno Lossin <lossin@kernel.org>

---
Cheers,
Benno

> ---
>  rust/kernel/revocable.rs | 4 ++++
>  1 file changed, 4 insertions(+)

  reply	other threads:[~2025-06-12 12:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-12 11:17 [PATCH] revocable: rust: document why &T is not used in RevocableGuard Alice Ryhl
2025-06-12 12:15 ` Benno Lossin [this message]
2025-06-29 19:31 ` Miguel Ojeda

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=DAKJPI52CL6O.5AHQSFJBEZPR@kernel.org \
    --to=lossin@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelomoreira1905@gmail.com \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /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;
as well as URLs for NNTP newsgroup(s).