* [PATCH hotfix] mm/compaction: handle free_pages_prepare() properly in compaction_free()
@ 2026-06-22 15:30 Zi Yan
2026-06-22 15:47 ` Vlastimil Babka (SUSE)
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Zi Yan @ 2026-06-22 15:30 UTC (permalink / raw)
To: Andrew Morton, Vlastimil Babka, Suren Baghdasaryan, Michal Hocko,
Brendan Jackman, Johannes Weiner, Baolin Wang
Cc: Jiaqi Yan, linux-mm, linux-kernel, Zi Yan, stable
free_pages_prepare() can fail but compaction_free() does not handle the
failure case. Failed pages should not be added back to cc->freepages for
future use, since they can be either PageHWPoison or free_page_is_bad()
and might cause data corruption.
Fixes: 733aea0b3a7bb ("mm/compaction: add support for >0 order folio memory compaction.")
Signed-off-by: Zi Yan <ziy@nvidia.com>
Cc: stable@vger.kernel.org
---
free_pages_prepare() can fail if a page is PageHWPoison or
free_page_is_bad(). compaction_free() needs to handle these cases to
prevent failed pages being reused in cc->freepages.
---
mm/compaction.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/mm/compaction.c b/mm/compaction.c
index b776f35ad0200..f08765ade014c 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -1875,15 +1875,14 @@ static void compaction_free(struct folio *dst, unsigned long data)
int order = folio_order(dst);
struct page *page = &dst->page;
- if (folio_put_testzero(dst)) {
- free_pages_prepare(page, order);
+ if (folio_put_testzero(dst) && free_pages_prepare(page, order)) {
list_add(&dst->lru, &cc->freepages[order]);
cc->nr_freepages += 1 << order;
}
cc->nr_migratepages += 1 << order;
/*
- * someone else has referenced the page, we cannot take it back to our
- * free list.
+ * someone else has referenced the page or free_pages_prepare() fails,
+ * we cannot take it back to our free list.
*/
}
---
base-commit: 13a1e1a618858407fa12c391f664ea750651f6b2
change-id: 20260621-handle_free_pages_prepare_in_compaction_free-7cca3ff08367
Best regards,
--
Zi Yan <ziy@nvidia.com>
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH hotfix] mm/compaction: handle free_pages_prepare() properly in compaction_free()
2026-06-22 15:30 [PATCH hotfix] mm/compaction: handle free_pages_prepare() properly in compaction_free() Zi Yan
@ 2026-06-22 15:47 ` Vlastimil Babka (SUSE)
2026-06-22 20:23 ` Johannes Weiner
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Vlastimil Babka (SUSE) @ 2026-06-22 15:47 UTC (permalink / raw)
To: Zi Yan, Andrew Morton, Suren Baghdasaryan, Michal Hocko,
Brendan Jackman, Johannes Weiner, Baolin Wang
Cc: Jiaqi Yan, linux-mm, linux-kernel, stable
On 6/22/26 17:30, Zi Yan wrote:
> free_pages_prepare() can fail but compaction_free() does not handle the
> failure case. Failed pages should not be added back to cc->freepages for
> future use, since they can be either PageHWPoison or free_page_is_bad()
> and might cause data corruption.
>
> Fixes: 733aea0b3a7bb ("mm/compaction: add support for >0 order folio memory compaction.")
> Signed-off-by: Zi Yan <ziy@nvidia.com>
> Cc: stable@vger.kernel.org
Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
> ---
> free_pages_prepare() can fail if a page is PageHWPoison or
> free_page_is_bad(). compaction_free() needs to handle these cases to
> prevent failed pages being reused in cc->freepages.
> ---
> mm/compaction.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/mm/compaction.c b/mm/compaction.c
> index b776f35ad0200..f08765ade014c 100644
> --- a/mm/compaction.c
> +++ b/mm/compaction.c
> @@ -1875,15 +1875,14 @@ static void compaction_free(struct folio *dst, unsigned long data)
> int order = folio_order(dst);
> struct page *page = &dst->page;
>
> - if (folio_put_testzero(dst)) {
> - free_pages_prepare(page, order);
> + if (folio_put_testzero(dst) && free_pages_prepare(page, order)) {
> list_add(&dst->lru, &cc->freepages[order]);
> cc->nr_freepages += 1 << order;
> }
> cc->nr_migratepages += 1 << order;
> /*
> - * someone else has referenced the page, we cannot take it back to our
> - * free list.
> + * someone else has referenced the page or free_pages_prepare() fails,
> + * we cannot take it back to our free list.
> */
> }
>
>
> ---
> base-commit: 13a1e1a618858407fa12c391f664ea750651f6b2
> change-id: 20260621-handle_free_pages_prepare_in_compaction_free-7cca3ff08367
>
> Best regards,
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH hotfix] mm/compaction: handle free_pages_prepare() properly in compaction_free()
2026-06-22 15:30 [PATCH hotfix] mm/compaction: handle free_pages_prepare() properly in compaction_free() Zi Yan
2026-06-22 15:47 ` Vlastimil Babka (SUSE)
@ 2026-06-22 20:23 ` Johannes Weiner
2026-06-23 1:54 ` Baolin Wang
2026-06-23 7:26 ` Lance Yang
3 siblings, 0 replies; 5+ messages in thread
From: Johannes Weiner @ 2026-06-22 20:23 UTC (permalink / raw)
To: Zi Yan
Cc: Andrew Morton, Vlastimil Babka, Suren Baghdasaryan, Michal Hocko,
Brendan Jackman, Baolin Wang, Jiaqi Yan, linux-mm, linux-kernel,
stable
On Mon, Jun 22, 2026 at 11:30:42AM -0400, Zi Yan wrote:
> free_pages_prepare() can fail but compaction_free() does not handle the
> failure case. Failed pages should not be added back to cc->freepages for
> future use, since they can be either PageHWPoison or free_page_is_bad()
> and might cause data corruption.
>
> Fixes: 733aea0b3a7bb ("mm/compaction: add support for >0 order folio memory compaction.")
> Signed-off-by: Zi Yan <ziy@nvidia.com>
> Cc: stable@vger.kernel.org
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH hotfix] mm/compaction: handle free_pages_prepare() properly in compaction_free()
2026-06-22 15:30 [PATCH hotfix] mm/compaction: handle free_pages_prepare() properly in compaction_free() Zi Yan
2026-06-22 15:47 ` Vlastimil Babka (SUSE)
2026-06-22 20:23 ` Johannes Weiner
@ 2026-06-23 1:54 ` Baolin Wang
2026-06-23 7:26 ` Lance Yang
3 siblings, 0 replies; 5+ messages in thread
From: Baolin Wang @ 2026-06-23 1:54 UTC (permalink / raw)
To: Zi Yan, Andrew Morton, Vlastimil Babka, Suren Baghdasaryan,
Michal Hocko, Brendan Jackman, Johannes Weiner
Cc: Jiaqi Yan, linux-mm, linux-kernel, stable
On 6/22/26 11:30 PM, Zi Yan wrote:
> free_pages_prepare() can fail but compaction_free() does not handle the
> failure case. Failed pages should not be added back to cc->freepages for
> future use, since they can be either PageHWPoison or free_page_is_bad()
> and might cause data corruption.
>
> Fixes: 733aea0b3a7bb ("mm/compaction: add support for >0 order folio memory compaction.")
> Signed-off-by: Zi Yan <ziy@nvidia.com>
> Cc: stable@vger.kernel.org
> ---
> free_pages_prepare() can fail if a page is PageHWPoison or
> free_page_is_bad(). compaction_free() needs to handle these cases to
> prevent failed pages being reused in cc->freepages.
> ---
LGTM. Thanks.
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH hotfix] mm/compaction: handle free_pages_prepare() properly in compaction_free()
2026-06-22 15:30 [PATCH hotfix] mm/compaction: handle free_pages_prepare() properly in compaction_free() Zi Yan
` (2 preceding siblings ...)
2026-06-23 1:54 ` Baolin Wang
@ 2026-06-23 7:26 ` Lance Yang
3 siblings, 0 replies; 5+ messages in thread
From: Lance Yang @ 2026-06-23 7:26 UTC (permalink / raw)
To: ziy
Cc: akpm, vbabka, surenb, mhocko, jackmanb, hannes, baolin.wang,
jiaqiyan, linux-mm, linux-kernel, stable, Lance Yang
On Mon, Jun 22, 2026 at 11:30:42AM -0400, Zi Yan wrote:
>free_pages_prepare() can fail but compaction_free() does not handle the
>failure case. Failed pages should not be added back to cc->freepages for
>future use, since they can be either PageHWPoison or free_page_is_bad()
>and might cause data corruption.
>
>Fixes: 733aea0b3a7bb ("mm/compaction: add support for >0 order folio memory compaction.")
>Signed-off-by: Zi Yan <ziy@nvidia.com>
>Cc: stable@vger.kernel.org
>---
LGTM. Feel free to add:
Reviewed-by: Lance Yang <lance.yang@linux.dev>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-06-23 7:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-22 15:30 [PATCH hotfix] mm/compaction: handle free_pages_prepare() properly in compaction_free() Zi Yan
2026-06-22 15:47 ` Vlastimil Babka (SUSE)
2026-06-22 20:23 ` Johannes Weiner
2026-06-23 1:54 ` Baolin Wang
2026-06-23 7:26 ` Lance Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox