[PATCH 2/7] mm: rust: add VMA page offset helper

From: Deborah Brouwer

Date: Thu May 07 2026 - 19:35:59 EST


From: Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx>

Add VmaRef::pgoff() to expose vm_area_struct::vm_pgoff through the Rust
VMA abstractions.

vm_pgoff stores the mmap file offset in PAGE_SIZE units and can be used to
distinguish different mmap regions and dispatch mmap or fault handling
logic based on the requested offset.

This matches the existing start()/end()/flags() helpers and avoids
open-coded raw vm_area_struct access in Rust drivers.

Signed-off-by: Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx>
Signed-off-by: Deborah Brouwer <deborah.brouwer@xxxxxxxxxxxxx>
---
rust/kernel/mm/virt.rs | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/rust/kernel/mm/virt.rs b/rust/kernel/mm/virt.rs
index 63eb730b0b05..cb670e9d5fd9 100644
--- a/rust/kernel/mm/virt.rs
+++ b/rust/kernel/mm/virt.rs
@@ -92,6 +92,16 @@ pub fn end(&self) -> usize {
unsafe { (*self.as_ptr()).__bindgen_anon_1.__bindgen_anon_1.vm_end }
}

+ /// Returns the page offset of the virtual memory area.
+ ///
+ /// This is the offset in pages from the start of the file being mapped.
+ #[inline]
+ pub fn pgoff(&self) -> usize {
+ // SAFETY: By the type invariants, the caller holds at least the mmap read lock, so this
+ // access is not a data race.
+ unsafe { (*self.as_ptr()).vm_pgoff }
+ }
+
/// Zap pages in the given page range.
///
/// This clears page table mappings for the range at the leaf level, leaving all other page

--
2.53.0