Skip to content

Commit a5bb866

Browse files
rpptakpm00
authored andcommitted
userfaultfd: move vma_can_userfault out of line
vma_can_userfault() has grown pretty big and it's not called on performance critical path. Move it out of line. No functional changes. Link: https://lore.kernel.org/20260402041156.1377214-7-rppt@kernel.org Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Reviewed-by: David Hildenbrand (Red Hat) <david@kernel.org> Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Andrei Vagin <avagin@google.com> Cc: Axel Rasmussen <axelrasmussen@google.com> Cc: Baolin Wang <baolin.wang@linux.alibaba.com> Cc: Harry Yoo <harry.yoo@oracle.com> Cc: Harry Yoo (Oracle) <harry@kernel.org> Cc: Hugh Dickins <hughd@google.com> Cc: James Houghton <jthoughton@google.com> Cc: Lorenzo Stoakes (Oracle) <ljs@kernel.org> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Muchun Song <muchun.song@linux.dev> Cc: Nikita Kalyazin <kalyazin@amazon.com> Cc: Oscar Salvador <osalvador@suse.de> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Peter Xu <peterx@redhat.com> Cc: Sean Christopherson <seanjc@google.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: David Carlier <devnexen@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent f5f035a commit a5bb866

2 files changed

Lines changed: 35 additions & 33 deletions

File tree

include/linux/userfaultfd_k.h

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -211,39 +211,8 @@ static inline bool userfaultfd_armed(struct vm_area_struct *vma)
211211
return vma->vm_flags & __VM_UFFD_FLAGS;
212212
}
213213

214-
static inline bool vma_can_userfault(struct vm_area_struct *vma,
215-
vm_flags_t vm_flags,
216-
bool wp_async)
217-
{
218-
vm_flags &= __VM_UFFD_FLAGS;
219-
220-
if (vma->vm_flags & VM_DROPPABLE)
221-
return false;
222-
223-
if ((vm_flags & VM_UFFD_MINOR) &&
224-
(!is_vm_hugetlb_page(vma) && !vma_is_shmem(vma)))
225-
return false;
226-
227-
/*
228-
* If wp async enabled, and WP is the only mode enabled, allow any
229-
* memory type.
230-
*/
231-
if (wp_async && (vm_flags == VM_UFFD_WP))
232-
return true;
233-
234-
/*
235-
* If user requested uffd-wp but not enabled pte markers for
236-
* uffd-wp, then shmem & hugetlbfs are not supported but only
237-
* anonymous.
238-
*/
239-
if (!uffd_supports_wp_marker() && (vm_flags & VM_UFFD_WP) &&
240-
!vma_is_anonymous(vma))
241-
return false;
242-
243-
/* By default, allow any of anon|shmem|hugetlb */
244-
return vma_is_anonymous(vma) || is_vm_hugetlb_page(vma) ||
245-
vma_is_shmem(vma);
246-
}
214+
bool vma_can_userfault(struct vm_area_struct *vma, vm_flags_t vm_flags,
215+
bool wp_async);
247216

248217
static inline bool vma_has_uffd_without_event_remap(struct vm_area_struct *vma)
249218
{

mm/userfaultfd.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,6 +2018,39 @@ ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start,
20182018
return moved ? moved : err;
20192019
}
20202020

2021+
bool vma_can_userfault(struct vm_area_struct *vma, vm_flags_t vm_flags,
2022+
bool wp_async)
2023+
{
2024+
vm_flags &= __VM_UFFD_FLAGS;
2025+
2026+
if (vma->vm_flags & VM_DROPPABLE)
2027+
return false;
2028+
2029+
if ((vm_flags & VM_UFFD_MINOR) &&
2030+
(!is_vm_hugetlb_page(vma) && !vma_is_shmem(vma)))
2031+
return false;
2032+
2033+
/*
2034+
* If wp async enabled, and WP is the only mode enabled, allow any
2035+
* memory type.
2036+
*/
2037+
if (wp_async && (vm_flags == VM_UFFD_WP))
2038+
return true;
2039+
2040+
/*
2041+
* If user requested uffd-wp but not enabled pte markers for
2042+
* uffd-wp, then shmem & hugetlbfs are not supported but only
2043+
* anonymous.
2044+
*/
2045+
if (!uffd_supports_wp_marker() && (vm_flags & VM_UFFD_WP) &&
2046+
!vma_is_anonymous(vma))
2047+
return false;
2048+
2049+
/* By default, allow any of anon|shmem|hugetlb */
2050+
return vma_is_anonymous(vma) || is_vm_hugetlb_page(vma) ||
2051+
vma_is_shmem(vma);
2052+
}
2053+
20212054
static void userfaultfd_set_vm_flags(struct vm_area_struct *vma,
20222055
vm_flags_t vm_flags)
20232056
{

0 commit comments

Comments
 (0)