[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aTLsUDBbcbl2ivme@google.com>
Date: Fri, 5 Dec 2025 14:29:36 +0000
From: Alice Ryhl <aliceryhl@...gle.com>
To: Oleg Nesterov <oleg@...hat.com>, Christian Brauner <christian@...uner.io>
Cc: Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
"Björn Roy Baron" <bjorn3_gh@...tonmail.com>, Benno Lossin <lossin@...nel.org>,
Andreas Hindborg <a.hindborg@...nel.org>, Trevor Gross <tmgross@...ch.edu>,
Danilo Krummrich <dakr@...nel.org>, Panagiotis Foliadis <pfoliadis@...teo.net>,
Shankari Anand <shankari.ak0208@...il.com>, FUJITA Tomonori <fujita.tomonori@...il.com>,
Alexey Gladkov <legion@...nel.org>, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: rust: wrong SAFETY comments in group_leader() and pid() + questions
On Fri, Dec 05, 2025 at 02:19:27PM +0000, Alice Ryhl wrote:
> Thanks a lot for your email!
>
> +Christian Brauner
>
> On Fri, Dec 05, 2025 at 03:08:23PM +0100, Oleg Nesterov wrote:
> > 2. I am working on the patch(es) which move ->group_leader from task_struct to
> > signal_struct, so the 1st change adds the new trivial helper in preparation:
> >
> > struct task_struct *task_group_leader(struct task_struct *task)
> > {
> > return task->group_leader; // will be updated
> > }
> >
> > Now, how can I change group_leader() to use it? I guess I need to add
> >
> > struct task_struct *rust_helper_task_group_leader(struct task_struct *task)
> > {
> > return task_group_leader(task);
> > }
> >
> > into rust/helpers/task.c, but will something like
> >
> > pub fn group_leader(&self) -> &Task {
> > unsafe { bindings::task_group_leader(self.as_ptr()) }
> > }
> >
> > work? I'm afraid it won't ;)
>
> That looks like it should work. The rust_helper_ function is only
> required if task_group_leader is marked `static inline`. Otherwise
> bindings:: will pick up the function straight from the C header. (As
> long as the relevant header is included in bindings_helper.h)
Ah, actually you need to convert from *mut bindings::task_struct to
&Task. And you need a safety comment. E.g.:
pub fn group_leader(&self) -> &Task {
// SAFETY: The lifetime of the returned task reference is tied to
// the lifetime of `self`, and given that a task has a reference to
// its group leader, we know it must be valid for the lifetime of
// the returned task reference.
unsafe { &*bindings::task_group_leader(self.as_ptr()).cast::<Task>() }
}
Alice
Powered by blists - more mailing lists