FAILED: patch "[PATCH] mm/truncate: unmap large folio on split failure" failed to apply to 6.12-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x fa04f5b60fda62c98a53a60de3a1e763f11feb41
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025112038-skipping-reemerge-8dc9@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From fa04f5b60fda62c98a53a60de3a1e763f11feb41 Mon Sep 17 00:00:00 2001
From: Kiryl Shutsemau <[email protected]>
Date: Mon, 27 Oct 2025 11:56:36 +0000
Subject: [PATCH] mm/truncate: unmap large folio on split failure
Accesses within VMA, but beyond i_size rounded up to PAGE_SIZE are supposed to generate SIGBUS.
This behavior might not be respected on truncation.
During truncation, the kernel splits a large folio in order to reclaim memory. As a side effect, it unmaps the folio and destroys PMD mappings of the folio. The folio will be refaulted as PTEs and SIGBUS semantics are preserved.
However, if the split fails, PMD mappings are preserved and the user will not receive SIGBUS on any accesses within the PMD.
Unmap the folio on split failure. It will lead to refault as PTEs and preserve SIGBUS semantics.
Make an exception for shmem/tmpfs that for long time intentionally mapped with PMDs across i_size.
mm/truncate.c +29 -6
@@ -177,6 +177,32 @@ int truncate_inode_folio(struct address_space *mapping, struct folio *folio)return 0 ; } +static int try_folio_split_or_unmap (struct folio *folio,struct page *split_at, +unsigned long min_order) +{ +enum ttu_flags ttu_flags = +TTU_SYNC | +TTU_SPLIT_HUGE_PMD | +TTU_IGNORE_MLOCK ; +int ret; + + ret =try_folio_split_to_order (folio, split_at, min_order); + +/* +* If the split fails, unmap the folio, so it will be refaulted +* with PTEs to respect SIGBUS semantics. +* +* Make an exception for shmem/tmpfs that for long time +* intentionally mapped with PMDs across i_size. +*/ +if (ret && !shmem_mapping (folio->mapping)) { +try_to_unmap (folio, ttu_flags); +WARN_ON (folio_mapped (folio)); + } + +return ret; +} +/* * Handle partial folios. The folio may be entirely within the * range if a split has raced with us. If not, we zero the part of the
@@ -226,7 +252,7 @@ bool truncate_inode_partial_folio(struct folio *folio, loff_t start, loff_t end) min_order =mapping_min_folio_order (folio->mapping); split_at =folio_page (folio,PAGE_ALIGN_DOWN (offset) /PAGE_SIZE ); -if (!try_folio_split_to_order (folio, split_at, min_order)) { +if (!try_folio_split_or_unmap (folio, split_at, min_order)) {/* * try to split at offset + length to make sure folios within * the range can be dropped, especially to avoid memory waste
@@ -250,13 +276,10 @@ bool truncate_inode_partial_folio(struct folio *folio, loff_t start, loff_t end)if (!folio_trylock (folio2)) goto out; -/* -* make sure folio2 is large and does not change its mapping. -* Its split result does not matter here. -*/ +/* make sure folio2 is large and does not change its mapping */ if (folio_test_large (folio2) && folio2->mapping == folio->mapping) -try_folio_split_to_order (folio2, split_at2, min_order); +try_folio_split_or_unmap (folio2, split_at2, min_order);folio_unlock (folio2); out:
PATCH 1/1 mm/truncate: unmap large folio on split failure
Accesses within VMA, but beyond i_size rounded up to PAGE_SIZE are supposed to generate SIGBUS.
This behavior might not be respected on truncation.
During truncation, the kernel splits a large folio in order to reclaim memory. As a side effect, it unmaps the folio and destroys PMD mappings of the folio. The folio will be refaulted as PTEs and SIGBUS semantics are preserved.
However, if the split fails, PMD mappings are preserved and the user will not receive SIGBUS on any accesses within the PMD.
Unmap the folio on split failure. It will lead to refault as PTEs and preserve SIGBUS semantics.
Make an exception for shmem/tmpfs that for long time intentionally mapped with PMDs across i_size.
--- mm/truncate.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
mm/truncate.c +26 -1
@@ -179,6 +179,31 @@ int truncate_inode_folio(struct address_space *mapping, struct folio *folio)return 0 ; } +static int try_folio_split_or_unmap (struct folio *folio) +{ +enum ttu_flags ttu_flags = +TTU_SYNC | +TTU_SPLIT_HUGE_PMD | +TTU_IGNORE_MLOCK ; +int ret; + + ret =split_folio (folio); + +/* +* If the split fails, unmap the folio, so it will be refaulted +* with PTEs to respect SIGBUS semantics. +* +* Make an exception for shmem/tmpfs that for long time +* intentionally mapped with PMDs across i_size. +*/ +if (ret && !shmem_mapping (folio->mapping)) { +try_to_unmap (folio, ttu_flags); +WARN_ON (folio_mapped (folio)); + } + +return ret; +} +/* * Handle partial folios. The folio may be entirely within the * range if a split has raced with us. If not, we zero the part of the
@@ -223,7 +248,7 @@ bool truncate_inode_partial_folio(struct folio *folio, loff_t start, loff_t end)folio_invalidate (folio, offset, length);if (!folio_test_large (folio))return true; -if (split_folio (folio) ==0 ) +if (try_folio_split_or_unmap (folio) ==0 )return true;if (folio_test_dirty (folio))return false;
Signature · 1 line
2.51.0