Skip to contentSkip to conversation

userfaultfd-fix-move_pages_pte-splitting-folio-under-rcu-read-lock.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message Jan 5, 2024

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: userfaultfd: fix move_pages_pte() splitting folio under RCU read lock
has been removed from the -mm tree. Its filename was
userfaultfd-fix-move_pages_pte-splitting-folio-under-rcu-read-lock.patch

This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Suren Baghdasaryan <[email protected]>
Subject: userfaultfd: fix move_pages_pte() splitting folio under RCU read lock
Date: Tue, 2 Jan 2024 15:32:56 -0800

While testing the split PMD path with lockdep enabled I've got an "Invalid wait context" error caused by split_huge_page_to_list() trying to lock anon_vma->rwsem while inside RCU read section. The issues is due to move_pages_pte() calling split_folio() under RCU read lock. Fix this by unmapping the PTEs and exiting RCU read section before splitting the folio and then retrying. The same retry pattern is used when locking the folio or anon_vma in this function. After splitting the large folio we unlock and release it because after the split the old folio might not be the one that contains the src_addr.

Fixes adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")
Cc Al Viro <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Axel Rasmussen <[email protected]>
Cc Brian Geffon <[email protected]>
Cc Christian Brauner <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Jann Horn <[email protected]>
Cc Kalesh Singh <[email protected]>
Cc Liam R. Howlett <[email protected]>
Cc Lokesh Gidra <[email protected]>
Cc Matthew Wilcox (Oracle) <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mike Rapoport (IBM) <[email protected]>
Cc Nicolas Geoffray <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Shuah Khan <[email protected]>
Cc ZhangPeng <[email protected]>

---

 mm/userfaultfd.c |    9 +++++++++
 1 file changed, 9 insertions(+)
mm/userfaultfd.c renamed from mm/userfaultfd.c~userfaultfd-fix-move_pages_pte-splitting-folio-under-rcu-read-lock +9 -0
@@ -1078,9 +1078,18 @@ retry:
 
 		/* at this point we have src_folio locked */
 		if (folio_test_large(src_folio)) {
+			/* split_folio() can block */
+			pte_unmap(&orig_src_pte);
+			pte_unmap(&orig_dst_pte);
+			src_pte = dst_pte = NULL;
 			err = split_folio(src_folio);
 			if (err)
 				goto out;
+			/* have to reacquire the folio after it got split */
+			folio_unlock(src_folio);
+			folio_put(src_folio);
+			src_folio = NULL;
+			goto retry;
 		}
 
 		if (!src_anon_vma) {

_

Patches currently in -mm which might be from [email protected] are