From: Boqun Feng <boqun.feng@gmail.com>
To: Alice Ryhl <alice@ryhl.io>
Cc: "Alice Ryhl" <aliceryhl@google.com>,
"Christian Brauner" <brauner@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Jan Kara" <jack@suse.cz>, "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>,
linux-fsdevel@vger.kernel.org, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rust: task: adjust safety comments in Task methods
Date: Tue, 15 Oct 2024 11:45:49 -0700 [thread overview]
Message-ID: <Zw64XYHtjGmbnfTO@boqun-archlinux> (raw)
In-Reply-To: <23a73a6f-160d-4d06-8d45-ec77293ff258@ryhl.io>
On Tue, Oct 15, 2024 at 08:37:36PM +0200, Alice Ryhl wrote:
> On 10/15/24 8:24 PM, Boqun Feng wrote:
> > On Tue, Oct 15, 2024 at 02:02:12PM +0000, Alice Ryhl wrote:
> > > The `Task` struct has several safety comments that aren't so great. For
> > > example, the reason that it's okay to read the `pid` is that the field
> > > is immutable, so there is no data race, which is not what the safety
> > > comment says.
> > >
> > > Thus, improve the safety comments. Also add an `as_ptr` helper. This
> > > makes it easier to read the various accessors on Task, as `self.0` may
> > > be confusing syntax for new Rust users.
> > >
> > > Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> > > ---
> > > This is based on top of vfs.rust.file as the file series adds some new
> > > task methods. Christian, can you take this through that tree?
> > > ---
> > > rust/kernel/task.rs | 43 ++++++++++++++++++++++++-------------------
> > > 1 file changed, 24 insertions(+), 19 deletions(-)
> > >
> > > diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs
> > > index 1a36a9f19368..080599075875 100644
> > > --- a/rust/kernel/task.rs
> > > +++ b/rust/kernel/task.rs
> > > @@ -145,11 +145,17 @@ fn deref(&self) -> &Self::Target {
> > > }
> > > }
> > > + /// Returns a raw pointer to the task.
> > > + #[inline]
> > > + pub fn as_ptr(&self) -> *mut bindings::task_struct {
> >
> > FWIW, I think the name convention is `as_raw()` for a wrapper type of
> > `Opaque<T>` to return `*mut T`, e.g. `kernel::device::Device`.
> >
> > Otherwise this looks good to me.
> Both names are in use. See e.g. Page and File that use as_ptr.
>
`Page` is a different case because it currently is a pointer.
> In fact, I was asked to change the name on File *to* as_ptr.
>
I'm not able to find the discussion on that ask. Appreciate it if you
can share a link.
Anyway, this is not important for now, and might not be in the future.
So:
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Regards,
Boqun
> Alice
next prev parent reply other threads:[~2024-10-15 18:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-15 14:02 [PATCH] rust: task: adjust safety comments in Task methods Alice Ryhl
2024-10-15 14:06 ` Christian Brauner
2024-10-15 17:19 ` Alice Ryhl
2024-10-15 14:07 ` Christian Brauner
2024-10-15 18:24 ` Boqun Feng
2024-10-15 18:37 ` Alice Ryhl
2024-10-15 18:45 ` Boqun Feng [this message]
2024-10-15 18:53 ` 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=Zw64XYHtjGmbnfTO@boqun-archlinux \
--to=boqun.feng@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=alice@ryhl.io \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=brauner@kernel.org \
--cc=gary@garyguo.net \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=viro@zeniv.linux.org.uk \
/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