lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAPRMd3nhDKApttF_wBU01es76NG=qAyZMAer_gjbbtTSH_FmSA@mail.gmail.com>
Date: Fri, 25 Jul 2025 18:32:20 +0530
From: Shankari Anand <shankari.ak0208@...il.com>
To: linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>, Dave Ertman <david.m.ertman@...el.com>, 
	Ira Weiny <ira.weiny@...el.com>, Leon Romanovsky <leon@...nel.org>, 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>, 
	Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>, 
	Danilo Krummrich <dakr@...nel.org>, "Rafael J . Wysocki" <rafael@...nel.org>, 
	Abdiel Janulgue <abdiel.janulgue@...il.com>, Daniel Almeida <daniel.almeida@...labora.com>, 
	Robin Murphy <robin.murphy@....com>, Viresh Kumar <vireshk@...nel.org>, Nishanth Menon <nm@...com>, 
	Stephen Boyd <sboyd@...nel.org>, Bjorn Helgaas <bhelgaas@...gle.com>, 
	Krzysztof Wilczyński <kwilczynski@...nel.org>
Subject: Re: [PATCH 7/7] rust: kernel: update ARef and AlwaysRefCounted
 imports from sync::aref

Hello,

Can this be picked up for review? Should I be splitting each core
kernel file into a separate patch?

On Thu, Jul 17, 2025 at 1:05 PM Shankari Anand
<shankari.ak0208@...il.com> wrote:
>
> Update call sites in the core kernel files to import `ARef`
> and `AlwaysRefCounted` from `sync::aref` instead of `types`.
>
> This aligns with the ongoing effort to move `ARef` and
> `AlwaysRefCounted` to sync.
>
> Suggested-by: Benno Lossin <lossin@...nel.org>
> Link: https://github.com/Rust-for-Linux/linux/issues/1173
> Signed-off-by: Shankari Anand <shankari.ak0208@...il.com>
> ---
> Its part of a subsystem-wise split series, as suggested in:
> https://lore.kernel.org/rust-for-linux/CANiq72=NSRMV_6UxXVgkebmWmbgN4i=sfRszr-G+x3W5A4DYOg@mail.gmail.com/T/#u
> This split series is intended to ease review and subsystem-level maintenance.
>
> The original moving patch is here:
> https://lore.kernel.org/rust-for-linux/DBCLH4WXYTJL.FDZ9B39OO3TY@kernel.org/T/#mb67fbddcd894665d6ec6b0854e37930dedab468b
>
> Gradually the re-export from types.rs will be eliminated in the
> future cycle.
> ---
>  rust/kernel/auxiliary.rs     |  2 +-
>  rust/kernel/cred.rs          |  6 +-----
>  rust/kernel/device.rs        | 10 +++-------
>  rust/kernel/devres.rs        |  3 +--
>  rust/kernel/dma.rs           |  2 +-
>  rust/kernel/opp.rs           | 13 +++++++------
>  rust/kernel/pci.rs           |  5 +++--
>  rust/kernel/pid_namespace.rs |  5 +----
>  rust/kernel/platform.rs      |  2 +-
>  rust/kernel/task.rs          |  7 ++++---
>  10 files changed, 23 insertions(+), 32 deletions(-)
>
> diff --git a/rust/kernel/auxiliary.rs b/rust/kernel/auxiliary.rs
> index d2cfe1eeefb6..776c63387832 100644
> --- a/rust/kernel/auxiliary.rs
> +++ b/rust/kernel/auxiliary.rs
> @@ -250,7 +250,7 @@ extern "C" fn release(dev: *mut bindings::device) {
>  kernel::impl_device_context_into_aref!(Device);
>
>  // SAFETY: Instances of `Device` are always reference-counted.
> -unsafe impl crate::types::AlwaysRefCounted for Device {
> +unsafe impl crate::sync::aref::AlwaysRefCounted for Device {
>      fn inc_ref(&self) {
>          // SAFETY: The existence of a shared reference guarantees that the refcount is non-zero.
>          unsafe { bindings::get_device(self.as_ref().as_raw()) };
> diff --git a/rust/kernel/cred.rs b/rust/kernel/cred.rs
> index 2599f01e8b28..4a2229542fb7 100644
> --- a/rust/kernel/cred.rs
> +++ b/rust/kernel/cred.rs
> @@ -8,11 +8,7 @@
>  //!
>  //! Reference: <https://www.kernel.org/doc/html/latest/security/credentials.html>
>
> -use crate::{
> -    bindings,
> -    task::Kuid,
> -    types::{AlwaysRefCounted, Opaque},
> -};
> +use crate::{bindings, sync::aref::AlwaysRefCounted, task::Kuid, types::Opaque};
>
>  /// Wraps the kernel's `struct cred`.
>  ///
> diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
> index 5c946af3a4d5..8b965b82163c 100644
> --- a/rust/kernel/device.rs
> +++ b/rust/kernel/device.rs
> @@ -4,11 +4,7 @@
>  //!
>  //! C header: [`include/linux/device.h`](srctree/include/linux/device.h)
>
> -use crate::{
> -    bindings,
> -    str::CStr,
> -    types::{ARef, Opaque},
> -};
> +use crate::{bindings, str::CStr, sync::aref::ARef, types::Opaque};
>  use core::{fmt, marker::PhantomData, ptr};
>
>  #[cfg(CONFIG_PRINTK)]
> @@ -216,7 +212,7 @@ pub fn property_present(&self, name: &CStr) -> bool {
>  kernel::impl_device_context_into_aref!(Device);
>
>  // SAFETY: Instances of `Device` are always reference-counted.
> -unsafe impl crate::types::AlwaysRefCounted for Device {
> +unsafe impl crate::sync::aref::AlwaysRefCounted for Device {
>      fn inc_ref(&self) {
>          // SAFETY: The existence of a shared reference guarantees that the refcount is non-zero.
>          unsafe { bindings::get_device(self.as_raw()) };
> @@ -322,7 +318,7 @@ macro_rules! impl_device_context_deref {
>  #[macro_export]
>  macro_rules! __impl_device_context_into_aref {
>      ($src:ty, $device:tt) => {
> -        impl ::core::convert::From<&$device<$src>> for $crate::types::ARef<$device> {
> +        impl ::core::convert::From<&$device<$src>> for $crate::sync::aref::ARef<$device> {
>              fn from(dev: &$device<$src>) -> Self {
>                  (&**dev).into()
>              }
> diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs
> index d0e6c6e162c2..7a1e2f2721b8 100644
> --- a/rust/kernel/devres.rs
> +++ b/rust/kernel/devres.rs
> @@ -13,8 +13,7 @@
>      ffi::c_void,
>      prelude::*,
>      revocable::{Revocable, RevocableGuard},
> -    sync::{rcu, Arc, Completion},
> -    types::ARef,
> +    sync::{aref::ARef, rcu, Arc, Completion},
>  };
>
>  #[pin_data]
> diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs
> index 1f7bae643416..6339e1e22e08 100644
> --- a/rust/kernel/dma.rs
> +++ b/rust/kernel/dma.rs
> @@ -9,8 +9,8 @@
>      device::{Bound, Device},
>      error::code::*,
>      error::Result,
> +    sync::aref::ARef,
>      transmute::{AsBytes, FromBytes},
> -    types::ARef,
>  };
>
>  /// Possible attributes associated with a DMA mapping.
> diff --git a/rust/kernel/opp.rs b/rust/kernel/opp.rs
> index 0e94cb2703ec..de1fea9964f3 100644
> --- a/rust/kernel/opp.rs
> +++ b/rust/kernel/opp.rs
> @@ -16,7 +16,8 @@
>      ffi::c_ulong,
>      prelude::*,
>      str::CString,
> -    types::{ARef, AlwaysRefCounted, Opaque},
> +    sync::aref::{ARef, AlwaysRefCounted},
> +    types::Opaque,
>  };
>
>  #[cfg(CONFIG_CPU_FREQ)]
> @@ -162,7 +163,7 @@ fn from(power: MicroWatt) -> Self {
>  /// use kernel::device::Device;
>  /// use kernel::error::Result;
>  /// use kernel::opp::{Data, MicroVolt, Token};
> -/// use kernel::types::ARef;
> +/// use kernel::sync::aref::ARef;
>  ///
>  /// fn create_opp(dev: &ARef<Device>, freq: Hertz, volt: MicroVolt, level: u32) -> Result<Token> {
>  ///     let data = Data::new(freq, volt, level, false);
> @@ -211,7 +212,7 @@ fn drop(&mut self) {
>  /// use kernel::device::Device;
>  /// use kernel::error::Result;
>  /// use kernel::opp::{Data, MicroVolt, Token};
> -/// use kernel::types::ARef;
> +/// use kernel::sync::aref::ARef;
>  ///
>  /// fn create_opp(dev: &ARef<Device>, freq: Hertz, volt: MicroVolt, level: u32) -> Result<Token> {
>  ///     let data = Data::new(freq, volt, level, false);
> @@ -262,7 +263,7 @@ fn freq(&self) -> Hertz {
>  /// use kernel::clk::Hertz;
>  /// use kernel::error::Result;
>  /// use kernel::opp::{OPP, SearchType, Table};
> -/// use kernel::types::ARef;
> +/// use kernel::sync::aref::ARef;
>  ///
>  /// fn find_opp(table: &Table, freq: Hertz) -> Result<ARef<OPP>> {
>  ///     let opp = table.opp_from_freq(freq, Some(true), None, SearchType::Exact)?;
> @@ -335,7 +336,7 @@ fn drop(&mut self) {
>  /// use kernel::error::Result;
>  /// use kernel::opp::{Config, ConfigOps, ConfigToken};
>  /// use kernel::str::CString;
> -/// use kernel::types::ARef;
> +/// use kernel::sync::aref::ARef;
>  /// use kernel::macros::vtable;
>  ///
>  /// #[derive(Default)]
> @@ -581,7 +582,7 @@ extern "C" fn config_regulators(
>  /// use kernel::device::Device;
>  /// use kernel::error::Result;
>  /// use kernel::opp::Table;
> -/// use kernel::types::ARef;
> +/// use kernel::sync::aref::ARef;
>  ///
>  /// fn get_table(dev: &ARef<Device>, mask: &mut Cpumask, freq: Hertz) -> Result<Table> {
>  ///     let mut opp_table = Table::from_of_cpumask(dev, mask)?;
> diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
> index 5ce07999168e..7c17c937de59 100644
> --- a/rust/kernel/pci.rs
> +++ b/rust/kernel/pci.rs
> @@ -14,7 +14,8 @@
>      io::Io,
>      io::IoRaw,
>      str::CStr,
> -    types::{ARef, ForeignOwnable, Opaque},
> +    sync::aref::ARef,
> +    types::{ForeignOwnable, Opaque},
>      ThisModule,
>  };
>  use core::{
> @@ -438,7 +439,7 @@ pub fn set_master(&self) {
>  kernel::impl_device_context_into_aref!(Device);
>
>  // SAFETY: Instances of `Device` are always reference-counted.
> -unsafe impl crate::types::AlwaysRefCounted for Device {
> +unsafe impl crate::sync::aref::AlwaysRefCounted for Device {
>      fn inc_ref(&self) {
>          // SAFETY: The existence of a shared reference guarantees that the refcount is non-zero.
>          unsafe { bindings::pci_dev_get(self.as_raw()) };
> diff --git a/rust/kernel/pid_namespace.rs b/rust/kernel/pid_namespace.rs
> index 0e93808e4639..979a9718f153 100644
> --- a/rust/kernel/pid_namespace.rs
> +++ b/rust/kernel/pid_namespace.rs
> @@ -7,10 +7,7 @@
>  //! C header: [`include/linux/pid_namespace.h`](srctree/include/linux/pid_namespace.h) and
>  //! [`include/linux/pid.h`](srctree/include/linux/pid.h)
>
> -use crate::{
> -    bindings,
> -    types::{AlwaysRefCounted, Opaque},
> -};
> +use crate::{bindings, sync::aref::AlwaysRefCounted, types::Opaque};
>  use core::ptr;
>
>  /// Wraps the kernel's `struct pid_namespace`. Thread safe.
> diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs
> index e894790c510c..1c136341b670 100644
> --- a/rust/kernel/platform.rs
> +++ b/rust/kernel/platform.rs
> @@ -198,7 +198,7 @@ fn as_raw(&self) -> *mut bindings::platform_device {
>  kernel::impl_device_context_into_aref!(Device);
>
>  // SAFETY: Instances of `Device` are always reference-counted.
> -unsafe impl crate::types::AlwaysRefCounted for Device {
> +unsafe impl crate::sync::aref::AlwaysRefCounted for Device {
>      fn inc_ref(&self) {
>          // SAFETY: The existence of a shared reference guarantees that the refcount is non-zero.
>          unsafe { bindings::get_device(self.as_ref().as_raw()) };
> diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs
> index 927413d85484..b46488f6d1a8 100644
> --- a/rust/kernel/task.rs
> +++ b/rust/kernel/task.rs
> @@ -9,7 +9,8 @@
>      ffi::{c_int, c_long, c_uint},
>      mm::MmWithUser,
>      pid_namespace::PidNamespace,
> -    types::{ARef, NotThreadSafe, Opaque},
> +    sync::aref::ARef,
> +    types::{NotThreadSafe, Opaque},
>  };
>  use core::{
>      cmp::{Eq, PartialEq},
> @@ -76,7 +77,7 @@ macro_rules! current {
>  /// incremented when creating `State` and decremented when it is dropped:
>  ///
>  /// ```
> -/// use kernel::{task::Task, types::ARef};
> +/// use kernel::{task::Task, sync::aref::ARef};
>  ///
>  /// struct State {
>  ///     creator: ARef<Task>,
> @@ -340,7 +341,7 @@ pub fn active_pid_ns(&self) -> Option<&PidNamespace> {
>  }
>
>  // SAFETY: The type invariants guarantee that `Task` is always refcounted.
> -unsafe impl crate::types::AlwaysRefCounted for Task {
> +unsafe impl crate::sync::aref::AlwaysRefCounted for Task {
>      fn inc_ref(&self) {
>          // SAFETY: The existence of a shared reference means that the refcount is nonzero.
>          unsafe { bindings::get_task_struct(self.as_ptr()) };
>
> base-commit: 8ecb65b7b68ea48350833ba59c1257718e859768
> --
> 2.34.1
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ