From: Alice Ryhl <aliceryhl@google.com>
To: jongan.kim@lge.com
Cc: a.hindborg@kernel.org, arve@android.com,
bjorn3_gh@protonmail.com, boqun.feng@gmail.com,
brauner@kernel.org, cmllamas@google.com, dakr@kernel.org,
daniel.almeida@collabora.com, gary@garyguo.net,
gregkh@linuxfoundation.org, tamird@gmail.com, tkjos@android.com,
tmgross@umich.edu, viresh.kumar@linaro.org,
vitaly.wool@konsulko.se, yury.norov@gmail.com, ojeda@kernel.org,
lossin@kernel.org, heesu0025.kim@lge.com, ht.hong@lge.com,
jungsu.hwang@lge.com, kernel-team@android.com,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
sanghun.lee@lge.com, seulgi.lee@lge.com, sunghoon.kim@lge.com
Subject: Re: [PATCH v4 2/3] rust: pid: add Pid abstraction and init_ns helper
Date: Wed, 11 Feb 2026 10:42:30 +0000 [thread overview]
Message-ID: <aYxdFgSM7lu8iz21@google.com> (raw)
In-Reply-To: <20260206085336.32819-3-jongan.kim@lge.com>
On Fri, Feb 06, 2026 at 05:53:35PM +0900, jongan.kim@lge.com wrote:
> From: HeeSu Kim <heesu0025.kim@lge.com>
>
> Add a new Pid abstraction in rust/kernel/pid.rs that wraps the
> kernel's struct pid and provides safe Rust interfaces for:
> - find_vpid: Find a pid by number under RCU protection
> - pid_task: Get the task associated with a pid under RCU protection
>
> Also add init_ns() associated function to PidNamespace to get
> a reference to the init PID namespace.
>
> These abstractions use lifetime-bounded references tied to RCU guards
> to ensure memory safety when accessing RCU-protected data structures.
>
> Suggested-by: Alice Ryhl <aliceryhl@google.com>
> Link: https://lore.kernel.org/lkml/aXs3OjlGzQVABAwR@google.com/
> Suggested-by: Gary Guo <gary@garyguo.net>
> Link: https://lore.kernel.org/lkml/DG15B78C8IK4.ITL5HKRZ1QKP@garyguo.net/
> Signed-off-by: HeeSu Kim <heesu0025.kim@lge.com>
> Reviewed-by: Gary Guo <gary@garyguo.net>
> +#ifndef __rust_helper
> +#define __rust_helper
> +#endif
This should not be included. __rust_helper is always defined.
> + pub fn find_vpid<'a>(nr: i32, _rcu_guard: &'a rcu::Guard) -> Option<&'a Self> {
This should use the typedef of pid_t (in task.rs) instead of i32.
> diff --git a/rust/kernel/pid_namespace.rs b/rust/kernel/pid_namespace.rs
> index 979a9718f153..fc815945d614 100644
> --- a/rust/kernel/pid_namespace.rs
> +++ b/rust/kernel/pid_namespace.rs
> @@ -38,6 +38,15 @@ pub unsafe fn from_ptr<'a>(ptr: *const bindings::pid_namespace) -> &'a Self {
> // `PidNamespace` type being transparent makes the cast ok.
> unsafe { &*ptr.cast() }
> }
> +
> + /// Returns a reference to the init PID namespace.
> + ///
> + /// This is the root PID namespace that exists throughout the lifetime of the kernel.
> + #[inline]
> + pub fn init_ns() -> &'static Self {
> + // SAFETY: `init_pid_ns` is a global static that is valid for the lifetime of the kernel.
> + unsafe { Self::from_ptr(&raw const bindings::init_pid_ns) }
> + }
This is no longer used anywhere.
> }
>
> // SAFETY: Instances of `PidNamespace` are always reference-counted.
> @@ -63,3 +72,11 @@ unsafe impl Send for PidNamespace {}
> // SAFETY: It's OK to access `PidNamespace` through shared references from other threads because
> // we're either accessing properties that don't change or that are properly synchronised by C code.
> unsafe impl Sync for PidNamespace {}
> +
> +impl PartialEq for PidNamespace {
> + fn eq(&self, other: &Self) -> bool {
> + self.as_ptr() == other.as_ptr()
> + }
> +}
> +impl Eq for PidNamespace {}
This is not used anywhere either.
Alice
next prev parent reply other threads:[~2026-02-11 10:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-06 8:53 [PATCH v4 0/3] binder: handle PID namespace conversion for freeze operation jongan.kim
2026-02-06 8:53 ` [PATCH v4 1/3] binder: fix PID namespace collision " jongan.kim
2026-02-11 10:17 ` jongan.kim
2026-02-11 10:17 ` jongan.kim
2026-02-11 11:13 ` Greg KH
2026-02-12 1:05 ` jongan.kim
2026-02-06 8:53 ` [PATCH v4 2/3] rust: pid: add Pid abstraction and init_ns helper jongan.kim
2026-02-11 10:42 ` Alice Ryhl [this message]
2026-02-13 5:15 ` jongan.kim
2026-02-06 8:53 ` [PATCH v4 3/3] rust_binder: fix PID namespace collision for freeze operation jongan.kim
2026-02-06 16:20 ` Gary Guo
2026-02-09 5:21 ` heesu0025.kim
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=aYxdFgSM7lu8iz21@google.com \
--to=aliceryhl@google.com \
--cc=a.hindborg@kernel.org \
--cc=arve@android.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=brauner@kernel.org \
--cc=cmllamas@google.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=heesu0025.kim@lge.com \
--cc=ht.hong@lge.com \
--cc=jongan.kim@lge.com \
--cc=jungsu.hwang@lge.com \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sanghun.lee@lge.com \
--cc=seulgi.lee@lge.com \
--cc=sunghoon.kim@lge.com \
--cc=tamird@gmail.com \
--cc=tkjos@android.com \
--cc=tmgross@umich.edu \
--cc=viresh.kumar@linaro.org \
--cc=vitaly.wool@konsulko.se \
--cc=yury.norov@gmail.com \
/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