Commit Graph

9 Commits

Author SHA1 Message Date
Alice Ryhl
8e67cb756f UPSTREAM: mm: rust: add VmaNew for f_ops->mmap()
This type will be used when setting up a new vma in an f_ops->mmap() hook.
Using a separate type from VmaRef allows us to have a separate set of
operations that you are only able to use during the mmap() hook.  For
example, the VM_MIXEDMAP flag must not be changed after the initial setup
that happens during the f_ops->mmap() hook.

To avoid setting invalid flag values, the methods for clearing VM_MAYWRITE
and similar involve a check of VM_WRITE, and return an error if VM_WRITE
is set.  Trying to use `try_clear_maywrite` without checking the return
value results in a compilation error because the `Result` type is marked

For now, there's only a method for VM_MIXEDMAP and not VM_PFNMAP.  When we
add a VM_PFNMAP method, we will need some way to prevent you from setting
both VM_MIXEDMAP and VM_PFNMAP on the same vma.

Link: https://lkml.kernel.org/r/20250408-vma-v16-6-d8b446e885d9@google.com
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Reviewed-by: Jann Horn <jannh@google.com>
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Cc: Alex Gaynor <alex.gaynor@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Balbir Singh <balbirs@nvidia.com>
Cc: Benno Lossin <benno.lossin@proton.me>
Cc: Björn Roy Baron <bjorn3_gh@protonmail.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Gary Guo <gary@garyguo.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Trevor Gross <tmgross@umich.edu>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Bug: 429146594
(cherry picked from commit dcb81aeab406e417bc0b4cf68de6eb07a1d2e6ce)
Change-Id: I195a63f4ae613192ccf9be5f4805263fb5b42170
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:08:22 +00:00
Alice Ryhl
0b5465bb31 UPSTREAM: mm: rust: add vm_insert_page
The vm_insert_page method is only usable on vmas with the VM_MIXEDMAP
flag, so we introduce a new type to keep track of such vmas.

The approach used in this patch assumes that we will not need to encode
many flag combinations in the type.  I don't think we need to encode more
than VM_MIXEDMAP and VM_PFNMAP as things are now.  However, if that
becomes necessary, using generic parameters in a single type would scale
better as the number of flags increases.

Link: https://lkml.kernel.org/r/20250408-vma-v16-3-d8b446e885d9@google.com
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Cc: Alex Gaynor <alex.gaynor@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Balbir Singh <balbirs@nvidia.com>
Cc: Benno Lossin <benno.lossin@proton.me>
Cc: Björn Roy Baron <bjorn3_gh@protonmail.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jann Horn <jannh@google.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Trevor Gross <tmgross@umich.edu>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Bug: 429146594
(cherry picked from commit bf3d331bb80749542cf299f94c471f611fb113b1)
Change-Id: I6f8b796cfa216af7b2d5ca29c3ad7c770e3ce9ee
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:08:22 +00:00
Alice Ryhl
d7f52612c5 UPSTREAM: mm: rust: add vm_area_struct methods that require read access
This adds a type called VmaRef which is used when referencing a vma that
you have read access to.  Here, read access means that you hold either the
mmap read lock or the vma read lock (or stronger).

Additionally, a vma_lookup method is added to the mmap read guard, which
enables you to obtain a &VmaRef in safe Rust code.

This patch only provides a way to lock the mmap read lock, but a follow-up
patch also provides a way to just lock the vma read lock.

Link: https://lkml.kernel.org/r/20250408-vma-v16-2-d8b446e885d9@google.com
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Reviewed-by: Jann Horn <jannh@google.com>
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Cc: Alex Gaynor <alex.gaynor@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Balbir Singh <balbirs@nvidia.com>
Cc: Benno Lossin <benno.lossin@proton.me>
Cc: Björn Roy Baron <bjorn3_gh@protonmail.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Trevor Gross <tmgross@umich.edu>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Bug: 429146594
(cherry picked from commit 040f404b731207935ed644b14bcc2bb8b8488d00)
Change-Id: I87c6ccb0f6fe99e492040babed1cc0ca6f482374
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:08:22 +00:00
Alice Ryhl
a012c15566 Revert "FROMLIST: mm: rust: add vm_area_struct methods that require read access"
This reverts commit 84aa9d6318.

Bug: 429146594
Change-Id: Iff6a420abd6dcdbb0589cc3714b84c2013930545
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:08:03 +00:00
Alice Ryhl
3be00a9bf8 Revert "FROMLIST: mm: rust: add vm_insert_page"
This reverts commit 5fd689f0d4.

Bug: 429146594
Change-Id: I6b5db9de36f2e44aaf4f1ac85dd2292e3d99d2bf
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:08:01 +00:00
Alice Ryhl
9248564a81 Revert "FROMLIST: mm: rust: add VmAreaNew for f_ops->mmap()"
This reverts commit 7d1983ce89.

Bug: 429146594
Change-Id: I4d01e34d4ae0f24ca5ddbb64bac219c6f9b48fc3
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:07:52 +00:00
Alice Ryhl
7d1983ce89 FROMLIST: mm: rust: add VmAreaNew for f_ops->mmap()
This type will be used when setting up a new vma in an f_ops->mmap()
hook. Using a separate type from VmAreaRef allows us to have a separate
set of operations that you are only able to use during the mmap() hook.
For example, the VM_MIXEDMAP flag must not be changed after the initial
setup that happens during the f_ops->mmap() hook.

To avoid setting invalid flag values, the methods for clearing
VM_MAYWRITE and similar involve a check of VM_WRITE, and return an error
if VM_WRITE is set. Trying to use `try_clear_maywrite` without checking
the return value results in a compilation error because the `Result`
type is marked #[must_use].

For now, there's only a method for VM_MIXEDMAP and not VM_PFNMAP. When
we add a VM_PFNMAP method, we will need some way to prevent you from
setting both VM_MIXEDMAP and VM_PFNMAP on the same vma.

Acked-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> (for mm bits)
Reviewed-by: Jann Horn <jannh@google.com>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>

Bug: 370906207
Link: https://lore.kernel.org/all/20250115-vma-v12-6-375099ae017a@google.com/
Change-Id: I3a0829a32ed7e05961eadf15c6266be9d54c2d92
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-02-13 09:25:42 +00:00
Alice Ryhl
5fd689f0d4 FROMLIST: mm: rust: add vm_insert_page
The vm_insert_page method is only usable on vmas with the VM_MIXEDMAP
flag, so we introduce a new type to keep track of such vmas.

The approach used in this patch assumes that we will not need to encode
many flag combinations in the type. I don't think we need to encode more
than VM_MIXEDMAP and VM_PFNMAP as things are now. However, if that
becomes necessary, using generic parameters in a single type would scale
better as the number of flags increases.

Acked-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> (for mm bits)
Signed-off-by: Alice Ryhl <aliceryhl@google.com>

Bug: 370906207
Link: https://lore.kernel.org/all/20250115-vma-v12-3-375099ae017a@google.com/
Change-Id: Iae049c9981dce3e3539c6d4437c065cd1b8c3251
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-02-13 09:25:41 +00:00
Alice Ryhl
84aa9d6318 FROMLIST: mm: rust: add vm_area_struct methods that require read access
This adds a type called VmAreaRef which is used when referencing a vma
that you have read access to. Here, read access means that you hold
either the mmap read lock or the vma read lock (or stronger).

Additionally, a vma_lookup method is added to the mmap read guard, which
enables you to obtain a &VmAreaRef in safe Rust code.

This patch only provides a way to lock the mmap read lock, but a
follow-up patch also provides a way to just lock the vma read lock.

Acked-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> (for mm bits)
Reviewed-by: Jann Horn <jannh@google.com>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>

Bug: 370906207
Link: https://lore.kernel.org/all/20250115-vma-v12-2-375099ae017a@google.com/
Change-Id: I6e1fc0d60c1a578edac41680855a60401d05cafd
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-02-13 09:25:41 +00:00