Bug Mechanism and Root Cause Analysis
1. Overlapping Fields in struct page / struct folio
In include/linux/mm_types.h, the memory layout of struct page and struct folio defines a union immediately following the flags field (at offset 8):
struct page {
memdesc_flags_t flags;
union {
struct {
union {
struct list_head lru;
...
};
...
};
...
struct {
unsigned long compound_info; /* Bit zero is set */
};
...
};
...
};
For order-0 and compound head pages (the base page representing the folio), the member folio->lru.next and page->compound_info share the exact same 8-byte word (offset 8 from the start of the struct page, which corresponds to 0xffffea00042ddbc8 in the report).
2. Reclaim Path (Unmarked Write via evict_folios())
When a swap-in fault occurs (swap_cache_read_folio() or swapin_sync() in mm/swap_state.c), a folio is allocated, locked (folio_test_locked() is true), and immediately added to the LRU list via folio_add_lru(folio) before the swap read bio is dispatched.
While the swap read I/O is in flight:
- Memory reclaim (
evict_folios() in mm/vmscan.c) scans and isolates the folio from the LRU onto a local list (&list), where it is no longer protected by lruvec->lru_lock.
- In
shrink_folio_list(), folio_trylock(folio) fails because the folio is held locked by the ongoing swap read I/O. As a result, the folio is not reclaimed and branches to the keep: label, where it is placed into ret_folios and spliced back into &list.
- Back in
evict_folios(), the loop checks:
if (!skip_retry && !folio_test_active(folio) && !folio_mapped(folio) &&
!folio_test_dirty(folio) && !folio_test_writeback(folio)) {
list_move(&folio->lru, &clean);
continue;
}
list_move(&folio->lru, &clean) calls __list_add() (include/linux/list.h:173), which writes new->next = next; using a plain, unmarked C store directly to folio->lru.next (0xffffea00042ddbc8).
3. Swap I/O Completion Path (Marked Read in swap_read_end())
Concurrently, on an interrupt/softirq CPU handling the completion of the swap read bio:
swap_bio_read_end_io() calls swap_read_end(sio, failed) (mm/page_io.c:556).
swap_read_end() processes each bio vector:
struct folio *folio = bvec_folio(&sio->bvecs[p]);
bvec_folio() calls page_folio(bv->bv_page), which invokes _compound_head(page) (include/linux/page-flags.h:221):
unsigned long info = READ_ONCE(page->compound_info);
- This marked read accesses
page->compound_info, which is the exact same location as folio->lru.next.
Because list_move() performs an unmarked write while _compound_head() performs a concurrent READ_ONCE() on the same 8-byte memory location without mutual synchronization (the folio lock protects the page contents and state flags, but folio->lru is manipulated independently while isolated by the LRU scanner), KCSAN detects and flags the data race.