RDMA/umem: remove FOLL_FORCE usage
authorDavid Hildenbrand <david@redhat.com>
Wed, 16 Nov 2022 10:26:49 +0000 (11:26 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 30 Nov 2022 23:58:58 +0000 (15:58 -0800)
GUP now supports reliable R/O long-term pinning in COW mappings, such
that we break COW early. MAP_SHARED VMAs only use the shared zeropage so
far in one corner case (DAXFS file with holes), which can be ignored
because GUP does not support long-term pinning in fsdax (see
check_vma_flags()).

Consequently, FOLL_FORCE | FOLL_WRITE | FOLL_LONGTERM is no longer required
for reliable R/O long-term pinning: FOLL_LONGTERM is sufficient. So stop
using FOLL_FORCE, which is really only for ptrace access.

Link: https://lkml.kernel.org/r/20221116102659.70287-11-david@redhat.com
Tested-by: Leon Romanovsky <leonro@nvidia.com> [over mlx4 and mlx5]
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Cc: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
drivers/infiniband/core/umem.c

index 86d4797..755a9c5 100644 (file)
@@ -156,7 +156,7 @@ struct ib_umem *ib_umem_get(struct ib_device *device, unsigned long addr,
        struct mm_struct *mm;
        unsigned long npages;
        int pinned, ret;
-       unsigned int gup_flags = FOLL_WRITE;
+       unsigned int gup_flags = FOLL_LONGTERM;
 
        /*
         * If the combination of the addr and size requested for this memory
@@ -210,8 +210,8 @@ struct ib_umem *ib_umem_get(struct ib_device *device, unsigned long addr,
 
        cur_base = addr & PAGE_MASK;
 
-       if (!umem->writable)
-               gup_flags |= FOLL_FORCE;
+       if (umem->writable)
+               gup_flags |= FOLL_WRITE;
 
        while (npages) {
                cond_resched();
@@ -219,7 +219,7 @@ struct ib_umem *ib_umem_get(struct ib_device *device, unsigned long addr,
                                          min_t(unsigned long, npages,
                                                PAGE_SIZE /
                                                sizeof(struct page *)),
-                                         gup_flags | FOLL_LONGTERM, page_list);
+                                         gup_flags, page_list);
                if (pinned < 0) {
                        ret = pinned;
                        goto umem_release;