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

From: David Hildenbrand (Arm)

Date: Tue Nov 17 2026 - 05:54:40 EST


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
> memcpy() in data_race() avoids locking on fork and matches dup_vma() in
> mm/vma_init.c.

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.

--
Cheers,

David