Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Mike Rapoport (Microsoft) and committed by
Andrew Morton
a5bb8669 f5f035a7

+35 -33
+2 -33
include/linux/userfaultfd_k.h
··· 211 211 return vma->vm_flags & __VM_UFFD_FLAGS; 212 212 } 213 213 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); 247 216 248 217 static inline bool vma_has_uffd_without_event_remap(struct vm_area_struct *vma) 249 218 {
+33
mm/userfaultfd.c
··· 2018 2018 return moved ? moved : err; 2019 2019 } 2020 2020 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 + 2021 2054 static void userfaultfd_set_vm_flags(struct vm_area_struct *vma, 2022 2055 vm_flags_t vm_flags) 2023 2056 {