diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2025-06-02 16:00:26 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2025-06-02 16:00:26 -0700 |
| commit | fd1f8473503e5bf897bd3e8efe3545c0352954e6 (patch) | |
| tree | bd9f699a23c0093dd55be8cac76d4329837654d0 /rust/kernel/mm.rs | |
| parent | fe4281644c62ce9385d3b9165e27d6c86ae0a845 (diff) | |
| parent | 0b43b8bc8ef88bb45b018b2d4853d38bfc5ce2a7 (diff) | |
Merge tag 'mm-stable-2025-06-01-14-06' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Pull more MM updates from Andrew Morton:
- "zram: support algorithm-specific parameters" from Sergey Senozhatsky
adds infrastructure for passing algorithm-specific parameters into
zram. A single parameter `winbits' is implemented at this time.
- "memcg: nmi-safe kmem charging" from Shakeel Butt makes memcg
charging nmi-safe, which is required by BFP, which can operate in NMI
context.
- "Some random fixes and cleanup to shmem" from Kemeng Shi implements
small fixes and cleanups in the shmem code.
- "Skip mm selftests instead when kernel features are not present" from
Zi Yan fixes some issues in the MM selftest code.
- "mm/damon: build-enable essential DAMON components by default" from
SeongJae Park reworks DAMON Kconfig to make it easier to enable
CONFIG_DAMON.
- "sched/numa: add statistics of numa balance task migration" from Libo
Chen adds more info into sysfs and procfs files to improve visibility
into the NUMA balancer's task migration activity.
- "selftests/mm: cow and gup_longterm cleanups" from Mark Brown
provides various updates to some of the MM selftests to make them
play better with the overall containing framework.
* tag 'mm-stable-2025-06-01-14-06' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (43 commits)
mm/khugepaged: clean up refcount check using folio_expected_ref_count()
selftests/mm: fix test result reporting in gup_longterm
selftests/mm: report unique test names for each cow test
selftests/mm: add helper for logging test start and results
selftests/mm: use standard ksft_finished() in cow and gup_longterm
selftests/damon/_damon_sysfs: skip testcases if CONFIG_DAMON_SYSFS is disabled
sched/numa: add statistics of numa balance task
sched/numa: fix task swap by skipping kernel threads
tools/testing: check correct variable in open_procmap()
tools/testing/vma: add missing function stub
mm/gup: update comment explaining why gup_fast() disables IRQs
selftests/mm: two fixes for the pfnmap test
mm/khugepaged: fix race with folio split/free using temporary reference
mm: add CONFIG_PAGE_BLOCK_ORDER to select page block order
mmu_notifiers: remove leftover stub macros
selftests/mm: deduplicate test names in madv_populate
kcov: rust: add flags for KCOV with Rust
mm: rust: make CONFIG_MMU ifdefs more narrow
mmu_gather: move tlb flush for VM_PFNMAP/VM_MIXEDMAP vmas into free_pgtables()
mm/damon/Kconfig: enable CONFIG_DAMON by default
...
Diffstat (limited to 'rust/kernel/mm.rs')
| -rw-r--r-- | rust/kernel/mm.rs | 56 |
1 files changed, 4 insertions, 52 deletions
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 @@ use core::{ops::Deref, ptr::NonNull}; 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 @@ impl Deref for MmWithUser { } } -/// 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 @@ impl 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 |