linux-stable/arch/x86
Lorenzo Stoakes 54d020692b mm/gup: remove unused vmas parameter from get_user_pages()
Patch series "remove the vmas parameter from GUP APIs", v6.

(pin_/get)_user_pages[_remote]() each provide an optional output parameter
for an array of VMA objects associated with each page in the input range.

These provide the means for VMAs to be returned, as long as mm->mmap_lock
is never released during the GUP operation (i.e.  the internal flag
FOLL_UNLOCKABLE is not specified).

In addition, these VMAs can only be accessed with the mmap_lock held and
become invalidated the moment it is released.

The vast majority of invocations do not use this functionality and of
those that do, all but one case retrieve a single VMA to perform checks
upon.

It is not egregious in the single VMA cases to simply replace the
operation with a vma_lookup().  In these cases we duplicate the (fast)
lookup on a slow path already under the mmap_lock, abstracted to a new
get_user_page_vma_remote() inline helper function which also performs
error checking and reference count maintenance.

The special case is io_uring, where io_pin_pages() specifically needs to
assert that the VMAs underlying the range do not result in broken
long-term GUP file-backed mappings.

As GUP now internally asserts that FOLL_LONGTERM mappings are not
file-backed in a broken fashion (i.e.  requiring dirty tracking) - as
implemented in "mm/gup: disallow FOLL_LONGTERM GUP-nonfast writing to
file-backed mappings" - this logic is no longer required and so we can
simply remove it altogether from io_uring.

Eliminating the vmas parameter eliminates an entire class of danging
pointer errors that might have occured should the lock have been
incorrectly released.

In addition, the API is simplified and now clearly expresses what it is
intended for - applying the specified GUP flags and (if pinning) returning
pinned pages.

This change additionally opens the door to further potential improvements
in GUP and the possible marrying of disparate code paths.

I have run this series against gup_test with no issues.

Thanks to Matthew Wilcox for suggesting this refactoring!


This patch (of 6):

No invocation of get_user_pages() use the vmas parameter, so remove it.

The GUP API is confusing and caveated.  Recent changes have done much to
improve that, however there is more we can do.  Exporting vmas is a prime
target as the caller has to be extremely careful to preclude their use
after the mmap_lock has expired or otherwise be left with dangling
pointers.

Removing the vmas parameter focuses the GUP functions upon their primary
purpose - pinning (and outputting) pages as well as performing the actions
implied by the input flags.

This is part of a patch series aiming to remove the vmas parameter
altogether.

Link: https://lkml.kernel.org/r/cover.1684350871.git.lstoakes@gmail.com
Link: https://lkml.kernel.org/r/589e0c64794668ffc799651e8d85e703262b1e9d.1684350871.git.lstoakes@gmail.com
Signed-off-by: Lorenzo Stoakes <lstoakes@gmail.com>
Suggested-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Acked-by: Christian König <christian.koenig@amd.com> (for radeon parts)
Acked-by: Jarkko Sakkinen <jarkko@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Sean Christopherson <seanjc@google.com> (KVM)
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
Cc: Janosch Frank <frankja@linux.ibm.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-06-09 16:25:25 -07:00
..
boot * Do conditional __tdx_hypercall() 'output' processing via an 2023-04-28 09:36:09 -07:00
coco * Do conditional __tdx_hypercall() 'output' processing via an 2023-04-28 09:36:09 -07:00
configs
crypto modules-6.4-rc1 2023-04-27 16:36:55 -07:00
entry cachestat: implement cachestat syscall 2023-06-09 16:25:16 -07:00
events perf/x86/uncore: Correct the number of CHAs on SPR 2023-05-24 22:19:41 +02:00
hyperv Objtool changes for v6.4: 2023-04-28 14:02:54 -07:00
ia32
include KVM: VMX: Fix header file dependency of asm/vmx.h 2023-05-19 13:56:25 -04:00
kernel mm/gup: remove unused vmas parameter from get_user_pages() 2023-06-09 16:25:25 -07:00
kvm KVM: VMX: add MSR_IA32_TSX_CTRL into msrs_to_save 2023-05-21 04:05:51 -04:00
lib x86: re-introduce support for ERMS copies for user space accesses 2023-05-26 12:34:20 -07:00
math-emu
mm x86/mm: Avoid incomplete Global INVLPG flushes 2023-05-17 08:55:02 -07:00
net bpf, x86: Simplify the parsing logic of structure parameters 2023-01-10 15:53:22 -08:00
pci xen: branch for v6.4-rc4 2023-05-27 09:42:56 -07:00
platform Objtool changes for v6.4: 2023-04-28 14:02:54 -07:00
power x86/cpu: Mark {hlt,resume}_play_dead() __noreturn 2023-04-14 17:31:27 +02:00
purgatory purgatory: fix disabling debug info 2023-04-08 19:36:53 +09:00
ras
realmode
tools ELF: fix all "Elf" typos 2023-04-08 13:45:37 -07:00
um um: make stub data pages size tweakable 2023-04-20 23:08:43 +02:00
video
virt/vmx/tdx
xen Objtool changes for v6.4: 2023-04-28 14:02:54 -07:00
.gitignore
Kbuild
Kconfig Add support for new Linear Address Masking CPU feature. This is similar 2023-04-28 09:43:49 -07:00
Kconfig.assembler crypto: x86/aria-avx - fix build failure with old binutils 2023-01-20 18:29:31 +08:00
Kconfig.cpu
Kconfig.debug docs: move x86 documentation into Documentation/arch/ 2023-03-30 12:58:51 -06:00
Makefile x86/build: Make 64-bit defconfig the default 2023-02-15 14:20:17 +01:00
Makefile.um um: Only disable SSE on clang to work around old GCC bugs 2023-04-04 09:57:05 +02:00
Makefile_32.cpu