Skip to content

Commit 42de3ad

Browse files
xzpeterakpm00
authored andcommitted
mm/shmem: support vm_uffd_ops API
Add support for the new vm_uffd_ops API for shmem. Note that this only introduces the support, the API is not yet used by core mm. Due to the tailored uffd_copy() API, shmem is extremely easy to support it by reusing the existing mfill function. It only needs a separate uffd_get_folio() definition but that's oneliner. Link: https://lkml.kernel.org/r/20250627154655.2085903-3-peterx@redhat.com Signed-off-by: Peter Xu <peterx@redhat.com> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Cc: Hugh Dickins <hughd@google.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Axel Rasmussen <axelrasmussen@google.com> Cc: David Hildenbrand <david@redhat.com> Cc: James Houghton <jthoughton@google.com> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Muchun Song <muchun.song@linux.dev> Cc: Oscar Salvador <osalvador@suse.de> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 3089067 commit 42de3ad

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

mm/shmem.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3161,6 +3161,13 @@ static inline struct inode *shmem_get_inode(struct mnt_idmap *idmap,
31613161
#endif /* CONFIG_TMPFS_QUOTA */
31623162

31633163
#ifdef CONFIG_USERFAULTFD
3164+
3165+
static int shmem_uffd_get_folio(struct inode *inode, pgoff_t pgoff,
3166+
struct folio **folio)
3167+
{
3168+
return shmem_get_folio(inode, pgoff, 0, folio, SGP_NOALLOC);
3169+
}
3170+
31643171
int shmem_mfill_atomic_pte(pmd_t *dst_pmd,
31653172
struct vm_area_struct *dst_vma,
31663173
unsigned long dst_addr,
@@ -5204,6 +5211,19 @@ static int shmem_error_remove_folio(struct address_space *mapping,
52045211
return 0;
52055212
}
52065213

5214+
#ifdef CONFIG_USERFAULTFD
5215+
static const vm_uffd_ops shmem_uffd_ops = {
5216+
.uffd_features = __VM_UFFD_FLAGS,
5217+
.uffd_ioctls = BIT(_UFFDIO_COPY) |
5218+
BIT(_UFFDIO_ZEROPAGE) |
5219+
BIT(_UFFDIO_WRITEPROTECT) |
5220+
BIT(_UFFDIO_CONTINUE) |
5221+
BIT(_UFFDIO_POISON),
5222+
.uffd_get_folio = shmem_uffd_get_folio,
5223+
.uffd_copy = shmem_mfill_atomic_pte,
5224+
};
5225+
#endif
5226+
52075227
static const struct address_space_operations shmem_aops = {
52085228
.dirty_folio = noop_dirty_folio,
52095229
#ifdef CONFIG_TMPFS
@@ -5306,6 +5326,9 @@ static const struct vm_operations_struct shmem_vm_ops = {
53065326
.set_policy = shmem_set_policy,
53075327
.get_policy = shmem_get_policy,
53085328
#endif
5329+
#ifdef CONFIG_USERFAULTFD
5330+
.userfaultfd_ops = &shmem_uffd_ops,
5331+
#endif
53095332
};
53105333

53115334
static const struct vm_operations_struct shmem_anon_vm_ops = {
@@ -5315,6 +5338,9 @@ static const struct vm_operations_struct shmem_anon_vm_ops = {
53155338
.set_policy = shmem_set_policy,
53165339
.get_policy = shmem_get_policy,
53175340
#endif
5341+
#ifdef CONFIG_USERFAULTFD
5342+
.userfaultfd_ops = &shmem_uffd_ops,
5343+
#endif
53185344
};
53195345

53205346
int shmem_init_fs_context(struct fs_context *fc)

0 commit comments

Comments
 (0)