Skip to content

Commit 63d5fee

Browse files
xzpeterakpm00
authored andcommitted
mm/hugetlb: support vm_uffd_ops API
Add support for the new vm_uffd_ops API for hugetlb. Note that this only introduces the support, the API is not yet used by core mm. Due to legacy reasons, it's still not trivial to move hugetlb completely to the API (like shmem). But it will still use uffd_features and uffd_ioctls properly on the API because that's pretty general. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Peter Xu <[email protected]> Cc: Muchun Song <[email protected]> Cc: Oscar Salvador <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Axel Rasmussen <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: James Houghton <[email protected]> Cc: Liam Howlett <[email protected]> Cc: Lorenzo Stoakes <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Suren Baghdasaryan <[email protected]> Cc: Vlastimil Babka <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent f17f03f commit 63d5fee

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

mm/hugetlb.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5457,6 +5457,22 @@ static vm_fault_t hugetlb_vm_op_fault(struct vm_fault *vmf)
54575457
return 0;
54585458
}
54595459

5460+
#ifdef CONFIG_USERFAULTFD
5461+
static const vm_uffd_ops hugetlb_uffd_ops = {
5462+
.uffd_features = __VM_UFFD_FLAGS,
5463+
/* _UFFDIO_ZEROPAGE not supported */
5464+
.uffd_ioctls = BIT(_UFFDIO_COPY) |
5465+
BIT(_UFFDIO_WRITEPROTECT) |
5466+
BIT(_UFFDIO_CONTINUE) |
5467+
BIT(_UFFDIO_POISON),
5468+
/*
5469+
* Hugetlbfs still has its own hard-coded handler in userfaultfd,
5470+
* due to limitations similar to vm_operations_struct.fault().
5471+
* TODO: generalize it to use the API functions.
5472+
*/
5473+
};
5474+
#endif
5475+
54605476
/*
54615477
* When a new function is introduced to vm_operations_struct and added
54625478
* to hugetlb_vm_ops, please consider adding the function to shm_vm_ops.
@@ -5470,6 +5486,9 @@ const struct vm_operations_struct hugetlb_vm_ops = {
54705486
.close = hugetlb_vm_op_close,
54715487
.may_split = hugetlb_vm_op_split,
54725488
.pagesize = hugetlb_vm_op_pagesize,
5489+
#ifdef CONFIG_USERFAULTFD
5490+
.userfaultfd_ops = &hugetlb_uffd_ops,
5491+
#endif
54735492
};
54745493

54755494
static pte_t make_huge_pte(struct vm_area_struct *vma, struct folio *folio,

0 commit comments

Comments
 (0)