From: Matthew Wilcox <willy@infradead.org>
To: Jiayuan Chen <jiayuan.chen@linux.dev>
Cc: stable@vger.kernel.org, linux-mm@kvack.org,
jiayuan.chen@shopee.com, yingfu.zhou@shopee.com,
Andrew Morton <akpm@linux-foundation.org>,
Huang Ying <ying.huang@intel.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 5.15.y 6.1.y 6.6.y 1/1] mm/vmscan: flush deferred TLB before freeing large folios
Date: Wed, 8 Jul 2026 12:58:53 +0100 [thread overview]
Message-ID: <ak47fZui1es8Lobz@casper.infradead.org> (raw)
In-Reply-To: <20260708041237.289026-2-jiayuan.chen@linux.dev>
On Wed, Jul 08, 2026 at 12:12:36PM +0800, Jiayuan Chen wrote:
> In reclaim, shrink_folio_list() unmaps PTEs with a deferred, batched TLB
> flush. The batch is only flushed by try_to_unmap_flush() near the end of
> the function, just before the order-0 folios collected in @free_folios are
> handed back to the allocator.
>
> Large folios don't go through @free_folios -- they're freed inline at the
> free_it label via destroy_large_folio(), which runs before that flush. So
> a large folio's pages can be returned to the buddy allocator and reused
> while another CPU still holds a stale TLB entry for them, and that CPU then
> reads or executes through the stale translation into the reused page. For
> file-backed large folios (e.g. executable text) this shows up as random
> SIGSEGV/SIGILL in user space, with fault addresses that don't match the
> code being run.
>
> Flush the deferred batch before freeing a large folio inline, the same way
> the order-0 path already waits for the flush.
>
> Upstream this is fixed as a side effect of commit bc2ff4cbc329 ("mm: free
> folios in a batch in shrink_folio_list()"), which is a larger change; this
> is the minimal fix for -stable.
I agree that it would be wrong to backport bc2ff4cbc329 and all its
dependencies. And free_unref_page_list() only handles order-0 folios,
so we can't do this:
- if (unlikely(folio_test_large(folio)))
- destroy_large_folio(folio);
- else
- list_add(&folio->lru, &free_folios);
+ list_add(&folio->lru, &free_folios);
continue;
I think this is the right fix.
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Reported-by: Yingfu Zhou <yingfu.zhou@shopee.com>
> Fixes: bd4c82c22c36 ("mm, THP, swap: delay splitting THP after swapped out")
> Cc: Jiayuan Chen <jiayuan.chen@linux.dev>
> Signed-off-by: Jiayuan Chen <jiayuan.chen@shopee.com>
> ---
> destroy_compound_page was recently renamed to destroy_large_folio.
> So it would be conflict when this patch was applied to 5.15/6.1
> ---
> mm/vmscan.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index aba757e5c597..8eb498351d9b 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -2123,10 +2123,12 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,
> * Is there need to periodically free_folio_list? It would
> * appear not as the counts should be low
> */
> - if (unlikely(folio_test_large(folio)))
> + if (unlikely(folio_test_large(folio))) {
> + try_to_unmap_flush();
> destroy_large_folio(folio);
> - else
> + } else {
> list_add(&folio->lru, &free_folios);
> + }
> continue;
>
> activate_locked_split:
> --
> 2.43.0
>
next prev parent reply other threads:[~2026-07-08 11:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 4:12 [PATCH 5.15.y 6.1.y 6.6.y 0/1] mm/vmscan: flush deferred TLB before freeing large folios in reclaim Jiayuan Chen
2026-07-08 4:12 ` [PATCH 5.15.y 6.1.y 6.6.y 1/1] mm/vmscan: flush deferred TLB before freeing large folios Jiayuan Chen
2026-07-08 11:58 ` Matthew Wilcox [this message]
2026-07-08 16:18 ` Sasha Levin
2026-07-09 0:56 ` Jiayuan Chen
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=ak47fZui1es8Lobz@casper.infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=jiayuan.chen@linux.dev \
--cc=jiayuan.chen@shopee.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=stable@vger.kernel.org \
--cc=ying.huang@intel.com \
--cc=yingfu.zhou@shopee.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