Re: [PATCH] fork: mark memcpy() in dup_mm() with data_race()
From: Muhammad Haris Awan
Date: Tue Nov 17 2026 - 05:25:15 EST
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()).
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.
Thanks,
Muhammad Haris Awan