The commit is pushed to "branch-rh9-5.14.0-362.18.1.vz9.40.x-ovz" and will
appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-362.18.1.vz9.40.1
------>
commit 3961da0b9522818e9f8b017ee42d65d3b3c033e6
Author: David Stevens <[email protected]>
Date: Tue Apr 18 17:40:31 2023 +0900
ms/mm/shmem: fix race in shmem_undo_range w/THP
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]
Link: https://lkml.kernel.org/r/[email protected]
mFixes: b9a8a4195c7d ("truncate,shmem: Handle truncates that split large
folios")
Signed-off-by: David Stevens <[email protected]>
Cc: Matthew Wilcox (Oracle) <[email protected]>
Cc: Suleiman Souhlal <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
https://virtuozzo.atlassian.net/browse/PSBM-154569
(cherry picked from commit 55ac8bbe358bdd2f3c044c12f249fd22d48fe015)
Signed-off-by: Konstantin Khorenko <[email protected]>
Feature: fix ms/mm
---
mm/shmem.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/mm/shmem.c b/mm/shmem.c
index fbfecb73e740..a9b36d089340 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1051,7 +1051,24 @@ static void shmem_undo_range(struct inode *inode, loff_t
lstart, loff_t lend,
}
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;
+ }
+ }
}
index = folio->index + folio_nr_pages(folio) - 1;
folio_unlock(folio);
_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel