mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
To: Zi Yan <ziy@nvidia.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	Brendan Jackman <jackmanb@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Jiaqi Yan <jiaqiyan@google.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH hotfix] mm/compaction: handle free_pages_prepare() properly in compaction_free()
Date: Mon, 22 Jun 2026 17:47:00 +0200	[thread overview]
Message-ID: <b8962738-98a4-41c2-a85a-f668fe8c211b@kernel.org> (raw)
In-Reply-To: <20260622-handle_free_pages_prepare_in_compaction_free-v1-1-fcf3b14abcf7@nvidia.com>

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,


  reply	other threads:[~2026-06-22 15:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-22 15:30 Zi Yan
2026-06-22 15:47 ` Vlastimil Babka (SUSE) [this message]
2026-06-22 20:23 ` Johannes Weiner
2026-06-23  1:54 ` Baolin Wang
2026-06-23  7:26 ` Lance Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b8962738-98a4-41c2-a85a-f668fe8c211b@kernel.org \
    --to=vbabka@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=hannes@cmpxchg.org \
    --cc=jackmanb@google.com \
    --cc=jiaqiyan@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=stable@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox