Skip to contentSkip to conversation

mm-shmem-fix-race-in-shmem_undo_range-w-thp.patch removed from -mm tree

merged mm-hotfixes-stable Andrew Morton 1 participant 1 message Dec 13, 2023 Stable branch

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: mm/shmem: fix race in shmem_undo_range w/THP
has been removed from the -mm tree. Its filename was
mm-shmem-fix-race-in-shmem_undo_range-w-thp.patch

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

------------------------------------------------------
From: David Stevens <[email protected]>
Subject: mm/shmem: fix race in shmem_undo_range w/THP
Date: Tue, 18 Apr 2023 17:40:31 +0900

Split folios during the second loop of shmem_undo_range. It's not sufficient to only split folios when dealing with partial pages, since it's possible for a THP to be faulted in after that point. Calling truncate_inode_folio in that situation can result in throwing away data outside of the range being targeted.

[[email protected]: tidy up comment layout]
Fixes b9a8a4195c7d ("truncate,shmem: Handle truncates that split large folios")
Cc Matthew Wilcox (Oracle) <[email protected]>
Cc Suleiman Souhlal <[email protected]>

---

 mm/shmem.c |   19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
mm/shmem.c renamed from mm/shmem.c~mm-shmem-fix-race-in-shmem_undo_range-w-thp +18 -1
@@ -1080,7 +1080,24 @@ whole_folios:
 				}
 				VM_BUG_ON_FOLIO(folio_test_writeback(folio),
 						folio);
-				truncate_inode_folio(mapping, folio);
+
+				if (!folio_test_large(folio)) {
+					truncate_inode_folio(mapping, folio);
+				} else if (truncate_inode_partial_folio(folio, lstart, lend)) {
+					/*
+					 * If we split a page, reset the loop so
+					 * that we pick up the new sub pages.
+					 * Otherwise the THP was entirely
+					 * dropped or the target range was
+					 * zeroed, so just continue the loop as
+					 * is.
+					 */
+					if (!folio_test_large(folio)) {
+						folio_unlock(folio);
+						index = start;
+						break;
+					}
+				}
 			}
 			folio_unlock(folio);
 		}

_

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