BACKPORT: userfaultfd: protect mmap_changing with rw_sem in userfaulfd_ctx
Increments and loads to mmap_changing are always in mmap_lock critical section. This ensures that if userspace requests event notification for non-cooperative operations (e.g. mremap), userfaultfd operations don't occur concurrently. This can be achieved by using a separate read-write semaphore in userfaultfd_ctx such that increments are done in write-mode and loads in read-mode, thereby eliminating the dependency on mmap_lock for this purpose. This is a preparatory step before we replace mmap_lock usage with per-vma locks in fill/move ioctls. Link: https://lkml.kernel.org/r/20240215182756.3448972-3-lokeshgidra@google.com Signed-off-by:Lokesh Gidra <lokeshgidra@google.com> Reviewed-by:
Mike Rapoport (IBM) <rppt@kernel.org> Reviewed-by:
Liam R. Howlett <Liam.Howlett@oracle.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Axel Rasmussen <axelrasmussen@google.com> Cc: Brian Geffon <bgeffon@google.com> Cc: David Hildenbrand <david@redhat.com> Cc: Jann Horn <jannh@google.com> Cc: Kalesh Singh <kaleshsingh@google.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Nicolas Geoffray <ngeoffray@google.com> Cc: Peter Xu <peterx@redhat.com> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Tim Murray <timmurray@google.com> Signed-off-by:
Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit 5e4c24a5) Conflicts: fs/userfaultfd.c include/linux/userfaultfd_k.h mm/userfaultfd.c 1. Functions passing control from fs/userfaultfd.c to mm/userfaultfd.c were renamed after 6.1. a. Replace mfill_atomic_copy() with mcopy_atomic() b. Replace mfill_atomic_zeropage() with mfill_zeropage() c. Replace mfill_atomic_continue() with mcopy_continue() d. Replace mfill_atomic() with __mcopy_atomic() e. Replace mfill_atomic_hugetlb() with __mcopy_atomic_hugetlb() 2. uffd flags were unified into a single parameter after 6.1. Replace 'flags' with 'mcopy_mode' and 'mode'. 3. Fetch dst_mm from dst_vma in __mcopy_atomic_hugetlb(). Bug: 320478828 Bug: 339845931 Signed-off-by:
Lokesh Gidra <lokeshgidra@google.com> (cherry picked from https://android-review.googlesource.com/q/commit:a5b6040d5cb800d56a2d2c5d106e1213838eed4e) Merged-In: I77615c36a0c891801c9eb9de3609df4e7f125c39 Change-Id: I77615c36a0c891801c9eb9de3609df4e7f125c39
Loading
Please sign in to comment