Re: [PATCH v3 4/7] mm/gup: introduce the FOLL_SAME_FILE GUP flag

From: David Hildenbrand
Date: Mon Apr 17 2023 - 07:17:48 EST


On 15.04.23 14:09, Lorenzo Stoakes wrote:
This flag causes GUP to assert that all VMAs within the input range possess
the same vma->vm_file. If not, the operation fails.

This is part of a patch series which eliminates the vmas parameter from the
GUP API, implementing the one remaining assertion within the entire kernel
that requires access to the VMAs associated with a GUP range.

Signed-off-by: Lorenzo Stoakes <lstoakes@xxxxxxxxx>

[...]

---
&start, &nr_pages, i,
@@ -1595,7 +1603,7 @@ long faultin_vma_page_range(struct vm_area_struct *vma, unsigned long start,
* We want to report -EINVAL instead of -EFAULT for any permission
* problems or incompatible mappings.
*/
- if (check_vma_flags(vma, gup_flags))
+ if (check_vma_flags(vma, vma->vm_file, gup_flags))
return -EINVAL;

FOLL_SAME_FILE is never set here, just pass NULL instead of vma->vm_file.


As we're not allowing to drop the mmap lock, why can't io_uring simply go over all VMAs once, after pinning succeeded, and make sure that the files match (or even before pinning)?

In most cases, we're dealing with a single VMA only, it's not like the common case is that io_uring pins accross 100s of VMAs.

So I really wonder if the GUP complexity is justified by something. (removing the VMAs is certainly a welcome surprise -- as it doesn't make any sense when used with FOLL_UNLOCKABLE).

--
Thanks,

David / dhildenb