oe-kbuild-all.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [linux-next:master 4753/5832] error[E0432]: unresolved import `crate::mm`
@ 2025-05-07 13:08 kernel test robot
  2025-05-08  8:35 ` [PATCH] mm: rust: make CONFIG_MMU ifdefs more narrow Alice Ryhl
  0 siblings, 1 reply; 3+ messages in thread
From: kernel test robot @ 2025-05-07 13:08 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: oe-kbuild-all, Andrew Morton, Linux Memory Management List,
	Boqun Feng, Andreas Hindborg, Gary Guo

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   08710e696081d58163c8078e0e096be6d35c5fad
commit: 03be7043bbae0380e3e314cde042e4bb5c63b48c [4753/5832] task: rust: rework how current is accessed
config: riscv-randconfig-r071-20250427 (https://download.01.org/0day-ci/archive/20250507/202505072116.eSYC8igT-lkp@intel.com/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project f819f46284f2a79790038e1f6649172789734ae8)
rustc: rustc 1.78.0 (9b00956e5 2024-04-29)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250507/202505072116.eSYC8igT-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202505072116.eSYC8igT-lkp@intel.com/

All errors (new ones prefixed by >>):

>> error[E0432]: unresolved import `crate::mm`
   --> rust/kernel/task.rs:10:5
   |
   10 |     mm::MmWithUser,
   |     ^^ could not find `mm` in the crate root

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] mm: rust: make CONFIG_MMU ifdefs more narrow
  2025-05-07 13:08 [linux-next:master 4753/5832] error[E0432]: unresolved import `crate::mm` kernel test robot
@ 2025-05-08  8:35 ` Alice Ryhl
  2025-05-12 16:10   ` Boqun Feng
  0 siblings, 1 reply; 3+ messages in thread
From: Alice Ryhl @ 2025-05-08  8:35 UTC (permalink / raw)
  To: lkp, akpm
  Cc: a.hindborg, aliceryhl, boqun.feng, gary, linux-mm, rust-for-linux,
	oe-kbuild-all

Currently the entire kernel::mm module is ifdef'd out when CONFIG_MMU=n.
However, there are some downstream users of the module in
rust/kernel/task.rs and rust/kernel/miscdevice.rs. Thus, update the cfgs
so that only MmWithUserAsync is removed with CONFIG_MMU=n.

The code is moved into a new file, since the #[cfg()] annotation
otherwise has to be duplicated several times.

Closes: https://lore.kernel.org/all/202505071753.kldNHYVQ-lkp@intel.com/
Closes: https://lore.kernel.org/all/202505072116.eSYC8igT-lkp@intel.com/
Fixes: 3ca414d725d6 ("mm: rust: add abstraction for struct mm_struct")
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
 rust/kernel/mm.rs             | 56 +++--------------------------
 rust/kernel/mm/mmput_async.rs | 68 +++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 52 deletions(-)
 create mode 100644 rust/kernel/mm/mmput_async.rs

diff --git a/rust/kernel/mm.rs b/rust/kernel/mm.rs
index 615907a0f3b4..43f525c0d16c 100644
--- a/rust/kernel/mm.rs
+++ b/rust/kernel/mm.rs
@@ -10,7 +10,6 @@
 //! control what happens when userspace reads or writes to that region of memory.
 //!
 //! C header: [`include/linux/mm.h`](srctree/include/linux/mm.h)
-#![cfg(CONFIG_MMU)]
 
 use crate::{
     bindings,
@@ -21,6 +20,10 @@
 pub mod virt;
 use virt::VmaRef;
 
+#[cfg(CONFIG_MMU)]
+pub use mmput_async::MmWithUserAsync;
+mod mmput_async;
+
 /// A wrapper for the kernel's `struct mm_struct`.
 ///
 /// This represents the address space of a userspace process, so each process has one `Mm`
@@ -111,50 +114,6 @@ fn deref(&self) -> &Mm {
     }
 }
 
-/// A wrapper for the kernel's `struct mm_struct`.
-///
-/// This type is identical to `MmWithUser` except that it uses `mmput_async` when dropping a
-/// refcount. This means that the destructor of `ARef<MmWithUserAsync>` is safe to call in atomic
-/// context.
-///
-/// # Invariants
-///
-/// Values of this type are always refcounted using `mmget`. The value of `mm_users` is non-zero.
-#[repr(transparent)]
-pub struct MmWithUserAsync {
-    mm: MmWithUser,
-}
-
-// SAFETY: It is safe to call `mmput_async` on another thread than where `mmget` was called.
-unsafe impl Send for MmWithUserAsync {}
-// SAFETY: All methods on `MmWithUserAsync` can be called in parallel from several threads.
-unsafe impl Sync for MmWithUserAsync {}
-
-// SAFETY: By the type invariants, this type is always refcounted.
-unsafe impl AlwaysRefCounted for MmWithUserAsync {
-    #[inline]
-    fn inc_ref(&self) {
-        // SAFETY: The pointer is valid since self is a reference.
-        unsafe { bindings::mmget(self.as_raw()) };
-    }
-
-    #[inline]
-    unsafe fn dec_ref(obj: NonNull<Self>) {
-        // SAFETY: The caller is giving up their refcount.
-        unsafe { bindings::mmput_async(obj.cast().as_ptr()) };
-    }
-}
-
-// Make all `MmWithUser` methods available on `MmWithUserAsync`.
-impl Deref for MmWithUserAsync {
-    type Target = MmWithUser;
-
-    #[inline]
-    fn deref(&self) -> &MmWithUser {
-        &self.mm
-    }
-}
-
 // These methods are safe to call even if `mm_users` is zero.
 impl Mm {
     /// Returns a raw pointer to the inner `mm_struct`.
@@ -206,13 +165,6 @@ pub unsafe fn from_raw<'a>(ptr: *const bindings::mm_struct) -> &'a MmWithUser {
         unsafe { &*ptr.cast() }
     }
 
-    /// Use `mmput_async` when dropping this refcount.
-    #[inline]
-    pub fn into_mmput_async(me: ARef<MmWithUser>) -> ARef<MmWithUserAsync> {
-        // SAFETY: The layouts and invariants are compatible.
-        unsafe { ARef::from_raw(ARef::into_raw(me).cast()) }
-    }
-
     /// Attempt to access a vma using the vma read lock.
     ///
     /// This is an optimistic trylock operation, so it may fail if there is contention. In that
diff --git a/rust/kernel/mm/mmput_async.rs b/rust/kernel/mm/mmput_async.rs
new file mode 100644
index 000000000000..9289e05f7a67
--- /dev/null
+++ b/rust/kernel/mm/mmput_async.rs
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0
+
+// Copyright (C) 2024 Google LLC.
+
+//! Version of `MmWithUser` using `mmput_async`.
+//!
+//! This is a separate file from `mm.rs` due to the dependency on `CONFIG_MMU=y`.
+#![cfg(CONFIG_MMU)]
+
+use crate::{
+    bindings,
+    mm::MmWithUser,
+    types::{ARef, AlwaysRefCounted},
+};
+use core::{ops::Deref, ptr::NonNull};
+
+/// A wrapper for the kernel's `struct mm_struct`.
+///
+/// This type is identical to `MmWithUser` except that it uses `mmput_async` when dropping a
+/// refcount. This means that the destructor of `ARef<MmWithUserAsync>` is safe to call in atomic
+/// context.
+///
+/// # Invariants
+///
+/// Values of this type are always refcounted using `mmget`. The value of `mm_users` is non-zero.
+#[repr(transparent)]
+pub struct MmWithUserAsync {
+    mm: MmWithUser,
+}
+
+// SAFETY: It is safe to call `mmput_async` on another thread than where `mmget` was called.
+unsafe impl Send for MmWithUserAsync {}
+// SAFETY: All methods on `MmWithUserAsync` can be called in parallel from several threads.
+unsafe impl Sync for MmWithUserAsync {}
+
+// SAFETY: By the type invariants, this type is always refcounted.
+unsafe impl AlwaysRefCounted for MmWithUserAsync {
+    #[inline]
+    fn inc_ref(&self) {
+        // SAFETY: The pointer is valid since self is a reference.
+        unsafe { bindings::mmget(self.as_raw()) };
+    }
+
+    #[inline]
+    unsafe fn dec_ref(obj: NonNull<Self>) {
+        // SAFETY: The caller is giving up their refcount.
+        unsafe { bindings::mmput_async(obj.cast().as_ptr()) };
+    }
+}
+
+// Make all `MmWithUser` methods available on `MmWithUserAsync`.
+impl Deref for MmWithUserAsync {
+    type Target = MmWithUser;
+
+    #[inline]
+    fn deref(&self) -> &MmWithUser {
+        &self.mm
+    }
+}
+
+impl MmWithUser {
+    /// Use `mmput_async` when dropping this refcount.
+    #[inline]
+    pub fn into_mmput_async(me: ARef<MmWithUser>) -> ARef<MmWithUserAsync> {
+        // SAFETY: The layouts and invariants are compatible.
+        unsafe { ARef::from_raw(ARef::into_raw(me).cast()) }
+    }
+}

base-commit: 03be7043bbae0380e3e314cde042e4bb5c63b48c
-- 
2.49.0.987.g0cc8ee98dc-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: rust: make CONFIG_MMU ifdefs more narrow
  2025-05-08  8:35 ` [PATCH] mm: rust: make CONFIG_MMU ifdefs more narrow Alice Ryhl
@ 2025-05-12 16:10   ` Boqun Feng
  0 siblings, 0 replies; 3+ messages in thread
From: Boqun Feng @ 2025-05-12 16:10 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: lkp, akpm, a.hindborg, gary, linux-mm, rust-for-linux,
	oe-kbuild-all

On Thu, May 08, 2025 at 08:35:40AM +0000, Alice Ryhl wrote:
> Currently the entire kernel::mm module is ifdef'd out when CONFIG_MMU=n.
> However, there are some downstream users of the module in
> rust/kernel/task.rs and rust/kernel/miscdevice.rs. Thus, update the cfgs
> so that only MmWithUserAsync is removed with CONFIG_MMU=n.
> 
> The code is moved into a new file, since the #[cfg()] annotation
> otherwise has to be duplicated several times.
> 
> Closes: https://lore.kernel.org/all/202505071753.kldNHYVQ-lkp@intel.com/
> Closes: https://lore.kernel.org/all/202505072116.eSYC8igT-lkp@intel.com/
> Fixes: 3ca414d725d6 ("mm: rust: add abstraction for struct mm_struct")
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>

One nit below, but overall it looks good to me, with or without it, feel
free to add:

Reviewed-by: Boqun Feng <boqun.feng@gmail.com>

> ---
>  rust/kernel/mm.rs             | 56 +++--------------------------
>  rust/kernel/mm/mmput_async.rs | 68 +++++++++++++++++++++++++++++++++++
>  2 files changed, 72 insertions(+), 52 deletions(-)
>  create mode 100644 rust/kernel/mm/mmput_async.rs
> 
> diff --git a/rust/kernel/mm.rs b/rust/kernel/mm.rs
> index 615907a0f3b4..43f525c0d16c 100644
> --- a/rust/kernel/mm.rs
> +++ b/rust/kernel/mm.rs
> @@ -10,7 +10,6 @@
>  //! control what happens when userspace reads or writes to that region of memory.
>  //!
>  //! C header: [`include/linux/mm.h`](srctree/include/linux/mm.h)
> -#![cfg(CONFIG_MMU)]
>  
>  use crate::{
>      bindings,
> @@ -21,6 +20,10 @@
>  pub mod virt;
>  use virt::VmaRef;
>  
> +#[cfg(CONFIG_MMU)]
> +pub use mmput_async::MmWithUserAsync;
> +mod mmput_async;
> +
>  /// A wrapper for the kernel's `struct mm_struct`.
>  ///
>  /// This represents the address space of a userspace process, so each process has one `Mm`
> @@ -111,50 +114,6 @@ fn deref(&self) -> &Mm {
>      }
>  }
>  
> -/// A wrapper for the kernel's `struct mm_struct`.
> -///
> -/// This type is identical to `MmWithUser` except that it uses `mmput_async` when dropping a
> -/// refcount. This means that the destructor of `ARef<MmWithUserAsync>` is safe to call in atomic
> -/// context.
> -///
> -/// # Invariants
> -///
> -/// Values of this type are always refcounted using `mmget`. The value of `mm_users` is non-zero.
> -#[repr(transparent)]
> -pub struct MmWithUserAsync {
> -    mm: MmWithUser,
> -}
> -
> -// SAFETY: It is safe to call `mmput_async` on another thread than where `mmget` was called.
> -unsafe impl Send for MmWithUserAsync {}
> -// SAFETY: All methods on `MmWithUserAsync` can be called in parallel from several threads.
> -unsafe impl Sync for MmWithUserAsync {}
> -
> -// SAFETY: By the type invariants, this type is always refcounted.
> -unsafe impl AlwaysRefCounted for MmWithUserAsync {
> -    #[inline]
> -    fn inc_ref(&self) {
> -        // SAFETY: The pointer is valid since self is a reference.
> -        unsafe { bindings::mmget(self.as_raw()) };
> -    }
> -
> -    #[inline]
> -    unsafe fn dec_ref(obj: NonNull<Self>) {
> -        // SAFETY: The caller is giving up their refcount.
> -        unsafe { bindings::mmput_async(obj.cast().as_ptr()) };
> -    }
> -}
> -
> -// Make all `MmWithUser` methods available on `MmWithUserAsync`.
> -impl Deref for MmWithUserAsync {
> -    type Target = MmWithUser;
> -
> -    #[inline]
> -    fn deref(&self) -> &MmWithUser {
> -        &self.mm
> -    }
> -}
> -
>  // These methods are safe to call even if `mm_users` is zero.
>  impl Mm {
>      /// Returns a raw pointer to the inner `mm_struct`.
> @@ -206,13 +165,6 @@ pub unsafe fn from_raw<'a>(ptr: *const bindings::mm_struct) -> &'a MmWithUser {
>          unsafe { &*ptr.cast() }
>      }
>  
> -    /// Use `mmput_async` when dropping this refcount.
> -    #[inline]
> -    pub fn into_mmput_async(me: ARef<MmWithUser>) -> ARef<MmWithUserAsync> {
> -        // SAFETY: The layouts and invariants are compatible.
> -        unsafe { ARef::from_raw(ARef::into_raw(me).cast()) }
> -    }
> -
>      /// Attempt to access a vma using the vma read lock.
>      ///
>      /// This is an optimistic trylock operation, so it may fail if there is contention. In that
> diff --git a/rust/kernel/mm/mmput_async.rs b/rust/kernel/mm/mmput_async.rs
> new file mode 100644
> index 000000000000..9289e05f7a67
> --- /dev/null
> +++ b/rust/kernel/mm/mmput_async.rs
> @@ -0,0 +1,68 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +// Copyright (C) 2024 Google LLC.
> +
> +//! Version of `MmWithUser` using `mmput_async`.
> +//!
> +//! This is a separate file from `mm.rs` due to the dependency on `CONFIG_MMU=y`.
> +#![cfg(CONFIG_MMU)]
> +
> +use crate::{
> +    bindings,
> +    mm::MmWithUser,

It's better to use 

	use super::MmWithUser;

here, I think.

Regards,
Boqun


> +    types::{ARef, AlwaysRefCounted},
> +};
> +use core::{ops::Deref, ptr::NonNull};
> +
> +/// A wrapper for the kernel's `struct mm_struct`.
> +///
> +/// This type is identical to `MmWithUser` except that it uses `mmput_async` when dropping a
> +/// refcount. This means that the destructor of `ARef<MmWithUserAsync>` is safe to call in atomic
> +/// context.
> +///
> +/// # Invariants
> +///
> +/// Values of this type are always refcounted using `mmget`. The value of `mm_users` is non-zero.
> +#[repr(transparent)]
> +pub struct MmWithUserAsync {
> +    mm: MmWithUser,
> +}
> +
> +// SAFETY: It is safe to call `mmput_async` on another thread than where `mmget` was called.
> +unsafe impl Send for MmWithUserAsync {}
> +// SAFETY: All methods on `MmWithUserAsync` can be called in parallel from several threads.
> +unsafe impl Sync for MmWithUserAsync {}
> +
> +// SAFETY: By the type invariants, this type is always refcounted.
> +unsafe impl AlwaysRefCounted for MmWithUserAsync {
> +    #[inline]
> +    fn inc_ref(&self) {
> +        // SAFETY: The pointer is valid since self is a reference.
> +        unsafe { bindings::mmget(self.as_raw()) };
> +    }
> +
> +    #[inline]
> +    unsafe fn dec_ref(obj: NonNull<Self>) {
> +        // SAFETY: The caller is giving up their refcount.
> +        unsafe { bindings::mmput_async(obj.cast().as_ptr()) };
> +    }
> +}
> +
> +// Make all `MmWithUser` methods available on `MmWithUserAsync`.
> +impl Deref for MmWithUserAsync {
> +    type Target = MmWithUser;
> +
> +    #[inline]
> +    fn deref(&self) -> &MmWithUser {
> +        &self.mm
> +    }
> +}
> +
> +impl MmWithUser {
> +    /// Use `mmput_async` when dropping this refcount.
> +    #[inline]
> +    pub fn into_mmput_async(me: ARef<MmWithUser>) -> ARef<MmWithUserAsync> {
> +        // SAFETY: The layouts and invariants are compatible.
> +        unsafe { ARef::from_raw(ARef::into_raw(me).cast()) }
> +    }
> +}
> 
> base-commit: 03be7043bbae0380e3e314cde042e4bb5c63b48c
> -- 
> 2.49.0.987.g0cc8ee98dc-goog
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-05-12 16:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-07 13:08 [linux-next:master 4753/5832] error[E0432]: unresolved import `crate::mm` kernel test robot
2025-05-08  8:35 ` [PATCH] mm: rust: make CONFIG_MMU ifdefs more narrow Alice Ryhl
2025-05-12 16:10   ` Boqun Feng

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).