mm/huge_memory: fix huge_zero_pfn race
Status from this message: [merged mm-hotfixes-stable] mm-huge_memory-separate-out-config_persistent_huge_zero_folio-logic.patch removed from -mm tree
Get series with b4
b4 am [email protected] change-id 20260728-fix-refcounted-huge-zero-21cb07b4fa3eVersions newest first
- v2 Latest2 patches 4 repliesApplied 2/2
- v12 patches 11 repliesSuperseded
Changes in v2 from the cover letter
- Reordered the series so the fix now comes first with the CONFIG_PERSISTENT_HUGE_ZERO_FOLIO separation following it as a pure cleanup as per David.
- Fixed up wording as per David.
- Cleaned up Cc's since dependency of fix on cleanup no longer exists.
Patches in v2 All 2 applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | mm/huge_memory: fix huge_zero_pfn racemm/ | +29 | 1 reply | Applied |
| 2/2 | mm/huge_memory: separate out CONFIG_PERSISTENT_HUGE_ZERO_FOLIO logicmm/ | +94 | 2 replies | Applied |
Reviews trailers per patch
1 of 2 patches has a Reviewed-by or Acked-by.
| Patch | David Hildenbrand (Arm) |
|---|---|
| 1/2 | A-b |
| 2/2 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH mm-hotfixes v2 0/2] mm/huge_memory: fix huge_zero_pfn race
There is a subtle race in the reference-counted huge_zero_folio implementation.
The fast path atomic logic fails to account for the fact that the shrinker (which drops the final huge_zero_refcount pin) can overwrite huge_zero_pfn with the ~0UL sentinel value in shrink_huge_zero_folio_scan() after a racing get_huge_zero_folio() installed a valid value there.
This results in huge_zero_folio being correctly set but huge_zero_pfn being set incorrectly and thus is_huge_zero_pfn() and consequently is_huge_zero_pmd() will misidentify the huge zero folio as being an ordinary THP folio.
This can result in the huge zero folio being split and otherwise treated incorrectly.
The solution to this is very subtle as there is an atomic fast path, and thus ordering in weakly ordered architectures has to be treated very carefully.
The first commit fixes the issue by introducing a spinlock around huge_zero_[pfn, folio, refcount] write, with careful consideration paid to load/store ordering in the fast path. It is placed first and kept as small as possible so that it can be backported on its own.
The second commit is a pure cleanup which reworks the CONFIG_PERSISTENT_HUGE_ZERO_FOLIO logic to better separate the persistent logic from the dynamically allocated one.
Andrew - I know you don't like a mix of fix/cleanup, but thought it'd be easier to keep the 2 together as there's a dependency.
---
v2:
- Reordered the series so the fix now comes first with the CONFIG_PERSISTENT_HUGE_ZERO_FOLIO separation following it as a pure cleanup as per David.
- Fixed up wording as per David.
- Cleaned up Cc's since dependency of fix on cleanup no longer exists.
v1:
https://patch.msgid.link/[email protected]
To: Andrew Morton <[email protected]>
To: David Hildenbrand <[email protected]>
To: Zi Yan <[email protected]>
To: Baolin Wang <[email protected]>
To: "Liam R. Howlett" <[email protected]>
To: Nico Pache <[email protected]>
To: Ryan Roberts <[email protected]>
To: Dev Jain <[email protected]>
To: Barry Song <[email protected]>
To: Lance Yang <[email protected]>
To: Usama Arif <[email protected]>
To: Pankaj Raghav <[email protected]>
To: Hannes Reinecke <[email protected]>
To: Hugh Dickins <[email protected]>
To: Yang Shi <[email protected]>
To: Kiryl Shutsemau <[email protected]>
---
Lorenzo Stoakes (ARM) (2):
mm/huge_memory: fix huge_zero_pfn race
mm/huge_memory: separate out CONFIG_PERSISTENT_HUGE_ZERO_FOLIO logic
mm/huge_memory.c | 189 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 116 insertions(+), 73 deletions(-)
---
base-commit: 5db85e34ec49beee590676d55f13e8e2b14c742f
change-id: 20260728-fix-refcounted-huge-zero-21cb07b4fa3e
Cheers,
Signature · 1 line
Lorenzo Stoakes (ARM) <[email protected]>