Re: [PATCH] fork: mark memcpy() in dup_mm() with data_race()

From: Lorenzo Stoakes (ARM)

Date: Tue Nov 17 2026 - 08:02:50 EST


On Tue, Nov 17, 2026 at 11:54:28AM +0100, David Hildenbrand (Arm) wrote:
> On 11/17/26 11:24, Muhammad Haris Awan wrote:
> > Hi David,
> >
> > Reclaim isn't touching the new mm being initialized (which isn't added to
> > mm_list->fifo until lru_gen_add_mm() at the end of copy_process()).
>
> Oh, that makes sense.
>
> >
> > The KCSAN read is on oldmm inside dup_mm()'s memcpy(mm, oldmm, sizeof(*mm)):
> > oldmm is an already-live mm sitting on mm_list->fifo, so when an adjacent
> > exiting mm calls lru_gen_del_mm(), list_del_init() updates
> > oldmm->lru_gen.list.next/.prev under mm_list->lock.
> > > Since oldmm is live, lru_gen_del_mm() has to update those list pointers.
> > The alternatives in dup_mm() would be taking mm_list->lock (plus
> > mmlist_lock) during fork, or avoiding copying oldmm->lru_gen / oldmm->mmlist
> > (awkward because struct mm_struct uses __randomize_layout). Wrapping the

The focus on __randomize_layout is really weird. What, were you assuming you
could avoid it by using offsetof() or something? That'd be an awful solution
anyway?

> > memcpy() in data_race() avoids locking on fork and matches dup_vma() in
> > mm/vma_init.c.

(BTW this reads like it's an AI-generated reply... sigh.)

_My_ LLM says that lock thing wouldn't work without really fiddly changes as it
relies on memcg and you'd have to double-check a concurrent change didn't take
place and etc.

All to silence a once-in-4-year KCSAN report...

>
> Yeah, the only concern I have is that this is the big hammer for any members,
> not just the ones where we expect races.
>
> We hold the mmap lock in write mode, so one would assume that nothing can rally
> modify it. Well, besides these list exceptions.
>
> Let's see what others have to say, but I guess this is fine then, although a bit
> suboptimal.

Replied, but this for me is far from fine, since it means that we basically no
longer have any KCSAN protection against most of what fork does.

Since it's 1 report in 4 years, I think we can just live without it. And I don't
really trust the submitter to not try to slop some broken alternative solution.

>
> --
> Cheers,
>
> David

--
Cheers, Lorenzo