]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm/userfaultfd: Use ctx in uffd_info for uffd_ctx_lock_and_validate_dst()
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Wed, 29 Oct 2025 00:58:31 +0000 (20:58 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Thu, 30 Oct 2025 16:51:22 +0000 (12:51 -0400)
And move other uffd_ops checks external to the locking call.

Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
mm/userfaultfd.c

index e3cda2dad3e135a79f55d03ceb830ebbb0666516..5d32ee22b478ccafb9115ba9fc6beee9fd6f6ee7 100644 (file)
@@ -561,16 +561,15 @@ uffd_failed_do_unlock(struct userfaultfd_ctx *ctx, struct vm_area_struct *dst,
  * Global checks live here, specific checks are in the callback.
  */
 static inline ssize_t
-uffd_ctx_lock_and_validate_dst(struct userfaultfd_ctx *ctx,
-               struct uffd_info *info)
+uffd_ctx_lock_and_validate_dst(struct uffd_info *info)
 {
        /*
         * If memory mappings are changing because of non-cooperative
         * operation (e.g. mremap) running in parallel, bail out and
         * request the user to retry later
         */
-       down_read(&ctx->map_changing_lock);
-       if (atomic_read(&ctx->mmap_changing))
+       down_read(&info->ctx->map_changing_lock);
+       if (atomic_read(&info->ctx->mmap_changing))
                return -EAGAIN;
 
        /*
@@ -587,9 +586,7 @@ uffd_ctx_lock_and_validate_dst(struct userfaultfd_ctx *ctx,
        if (info->wp && !(info->dst_vma->vm_flags & VM_UFFD_WP))
                return -EINVAL;
 
-       WARN_ON_ONCE(!info->uffd_ops->is_dst_valid);
-       return info->uffd_ops->is_dst_valid(info->dst_vma, info->dst_addr,
-                                           info->len);
+       return 0;
 }
 
 ssize_t
@@ -656,18 +653,21 @@ retry:
        if (err)
                goto out;
 
+
+       err = uffd_ctx_lock_and_validate_dst(&info);
+       if (err)
+               goto out_unlock;
+
        dst_vma = info.dst_vma;
        info.uffd_ops = vma_get_uffd_ops(dst_vma);
-       if (WARN_ON_ONCE(!info.uffd_ops->increment)) {
-               info.increment = PAGE_SIZE;
-       } else {
-               info.increment = info.uffd_ops->increment(dst_vma);
-       }
+       WARN_ON_ONCE(!info.uffd_ops->increment);
+       WARN_ON_ONCE(!info.uffd_ops->is_dst_valid);
 
-       err = uffd_ctx_lock_and_validate_dst(ctx, &info);
+       info.increment = info.uffd_ops->increment(info.dst_vma);
+       err = info.uffd_ops->is_dst_valid(info.dst_vma, info.dst_addr,
+                                           info.len);
        if (err)
                goto out_unlock;
-
        /*
         * For shmem mappings, khugepaged is allowed to remove page
         * tables under us; pte_offset_map_lock() will deal with that.