From: sashiko-bot@kernel.org
To: "David Hildenbrand (Arm)" <david@kernel.org>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Mike Rapoport" <rppt@kernel.org>,
"Suren Baghdasaryan" <surenb@google.com>,
"Michal Hocko" <mhocko@suse.com>,
"Rik van Riel" <riel@surriel.com>, "Harry Yoo" <harry@kernel.org>,
"Jann Horn" <jannh@google.com>,
"Lance Yang" <lance.yang@linux.dev>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
"Clark Williams" <clrkwllms@kernel.org>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Paul Walmsley" <pjw@kernel.org>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Albert Ou" <aou@eecs.berkeley.edu>,
"Alexandre Ghiti" <alex@ghiti.fr>,
"Ying Huang" <huang.ying.caritas@gmail.com>
Cc: linux-mm@kvack.org, linux-rt-devel@lists.linux.dev,
"Kirk Swidowski" <swidowski@google.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/rmap: avoid reusing batched TLB flush generations
Date: Wed, 25 Nov 2026 09:39:29 +0000 [thread overview]
Message-ID: <sashiko-outbox-233019@kernel.org> (raw)
In-Reply-To: <20261124-rmap-v1-1-e3dc48a4b527@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm/rmap: uninitialized tlb_flush_batch counters in mm_init()
on fork()
--
commit 087cd5390dc5a69ffce740207a46d0df64ca3039
Author: David Hildenbrand (Arm) <david@kernel.org>
mm/rmap: avoid reusing batched TLB flush generations
This commit replaces the packed mm->tlb_flush_batched counter with separate
32-bit mm->tlb_flush_batch_pending and mm->tlb_flush_batch_flushed counters
to prevent generation reuse races during batched TLB flushes.
> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> index 1ed35d258d2e3..9f51a0ec67451 100644
> --- a/include/linux/mm_types.h
> +++ b/include/linux/mm_types.h
> @@ -1407,7 +1407,8 @@ struct mm_struct {
> atomic_t tlb_flush_pending;
> #ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
> /* See flush_tlb_batched_pending() */
> - atomic_t tlb_flush_batched;
> + atomic_t tlb_flush_batch_pending;
> + atomic_t tlb_flush_batch_flushed;
> #endif
> struct uprobes_state uprobes_state;
> #ifdef CONFIG_PREEMPT_RT
[Severity: Medium]
Should init_tlb_flush_pending() also zero tlb_flush_batch_pending and
tlb_flush_batch_flushed when initializing a new mm?
During fork(), dup_mm() copies oldmm with memcpy() and then calls
mm_init() -> init_tlb_flush_pending(), which only resets
mm->tlb_flush_pending. Because tlb_flush_batch_pending sits before
tlb_flush_batch_flushed in struct mm_struct, memcpy() copies pending before
flushed, the opposite of the flushed-before-pending order required by
flush_tlb_batched_pending():
CPU0 (fork) CPU1 (reclaim on oldmm) CPU2 (flusher on oldmm)
dup_mm()
memcpy(mm, oldmm, ...)
reads pending = P
try_to_unmap_one()
set_tlb_ubc_flush_pending()
pending = P + 1
flush_tlb_batched_pending()
flush_tlb_mm(oldmm)
flushed = P + 1
reads flushed = P + 1
The child mm starts with tlb_flush_batch_pending == P and
tlb_flush_batch_flushed == P + 1. On the first batched unmap in the child,
set_tlb_ubc_flush_pending() increments pending to P + 1 (where
pending - flushed == 0), leaving pending == flushed while a batched flush
is still pending. A racing flush_tlb_batched_pending() in the child then
sees pending == flushed and skips flush_tlb_mm(), leaving stale writable
TLB entries behind.
Even without a concurrent update during memcpy(), inheriting unequal
counters from oldmm causes an unnecessary flush_tlb_mm() in the child and a
data race on oldmm during memcpy().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-rmap-v1-1-e3dc48a4b527@kernel.org?part=1
prev parent reply other threads:[~2026-11-25 9:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 9:39 [PATCH] mm/rmap: avoid reusing batched TLB flush generations David Hildenbrand (Arm)
2026-11-24 20:50 ` Harry Yoo
2026-11-24 21:16 ` David Hildenbrand (Arm)
2026-11-24 21:54 ` Harry Yoo
2026-11-25 8:51 ` Huang, Ying
2026-11-25 9:19 ` David Hildenbrand (Arm)
2026-11-25 9:39 ` sashiko-bot [this message]
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=sashiko-outbox-233019@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=bigeasy@linutronix.de \
--cc=clrkwllms@kernel.org \
--cc=david@kernel.org \
--cc=harry@kernel.org \
--cc=huang.ying.caritas@gmail.com \
--cc=jannh@google.com \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=riel@surriel.com \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=surenb@google.com \
--cc=swidowski@google.com \
--cc=vbabka@kernel.org \
/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