userfaultfd/shmem: support minor fault registration for shmem
[linux-block.git] / mm / shmem.c
index 9b66a2b2680c02bec921fd50d41f40e69354db29..0d186b91a2f989b579bb25768ad40b0bcf822bfb 100644 (file)
@@ -1797,7 +1797,7 @@ unlock:
  * vm. If we swap it in we mark it dirty since we also free the swap
  * entry since a page cannot live in both the swap and page cache.
  *
- * vmf and fault_type are only supplied by shmem_fault:
+ * vma, vmf, and fault_type are only supplied by shmem_fault:
  * otherwise they are NULL.
  */
 static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
@@ -1832,6 +1832,16 @@ repeat:
 
        page = pagecache_get_page(mapping, index,
                                        FGP_ENTRY | FGP_HEAD | FGP_LOCK, 0);
+
+       if (page && vma && userfaultfd_minor(vma)) {
+               if (!xa_is_value(page)) {
+                       unlock_page(page);
+                       put_page(page);
+               }
+               *fault_type = handle_userfault(vmf, VM_UFFD_MINOR);
+               return 0;
+       }
+
        if (xa_is_value(page)) {
                error = shmem_swapin_page(inode, index, &page,
                                          sgp, gfp, vma, fault_type);