From: Harry Yoo <harry@kernel.org>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: 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>,
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>,
linux-mm@kvack.org, linux-rt-devel@lists.linux.dev,
linux-riscv@lists.infradead.org, stable@vger.kernel.org,
Kirk Swidowski <swidowski@google.com>
Subject: Re: [PATCH] mm/rmap: avoid reusing batched TLB flush generations
Date: Tue, 24 Nov 2026 21:54:21 +0000 [thread overview]
Message-ID: <awYFSeZKPzqcCvW8@thinkstation> (raw)
In-Reply-To: <1cd2306c-eaec-43cd-9d0d-92f8cb6e691b@kernel.org>
On Tue, Nov 24, 2026 at 10:16:25PM +0100, David Hildenbrand (Arm) wrote:
> On 11/24/26 21:50, Harry Yoo wrote:
> > On Tue, Nov 24, 2026 at 10:39:11AM +0100, David Hildenbrand (Arm) wrote:
> Hi Harry,
>
> thanks for all that effort!
No problem, thanks for looking at the issue ;)
> > Uh, I spent a couple of hours to review and make sure this is correct.
> > I thought this is correct but then my claude flagged a race during fork.
> >
> > dup_mm() copies the counters with memcpy() and it doesn't know the
> > ordering. When flushed and pending fields sit in separate words,
> > dup_mm() could read them in two separate loads, but in the wrong order.
> >
> > It's especially problematic in a very rare (IMO) case where
> > flushed == pending + 1 becomes true in the child (which means the first
> > pending flush in the child might not be flushed properly).
> >
> > fork reclaim another process
> > memcpy reads pending = X
> > pending++ (X + 1)
> > truncate()
> > -> flush_tlb_batched_pending()
> > -> flushed = X + 1
> > memcpy reads flushed = X + 1
> >
> > Maybe reset the counters after copying mm_struct?
>
> Resetting sounds in general like the right thing to do. Ugh, this copying of
> random state is nasty.
Indeed.
> The child never ran, so there isn't anything to flush for it.
>
> So what you say is that the first deferred flush in the child will be missed.
Yes, I exactly meant that.
> I agree that it's extremely unlikely, but we should handle it.
Agreed.
> We currently have:
>
> if (unlikely(pending - flushed > INT_MAX))
>
> So I guess an alternative would be:
>
> if (unlikely(pending - flushed - 1 >= INT_MAX))
>
>
> pending = x + 1
> flushed = x + 1
>
> (x + 1 - (x + 1 ) - 1) = (unsigned)-1 >= INT_MAX
Oh that's subtle :)
> But yeah, let's just initialize it during fork(), thanks!
Sounds good, thanks!
--
Cheers,
Harry / Hyeonggon
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
prev parent reply other threads:[~2026-11-24 21:54 UTC|newest]
Thread overview: 4+ 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 [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=awYFSeZKPzqcCvW8@thinkstation \
--to=harry@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=huang.ying.caritas@gmail.com \
--cc=jannh@google.com \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=linux-riscv@lists.infradead.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=stable@vger.kernel.org \
--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