Root Cause Analysis
This KCSAN report is triggered by a concurrent access to the aliased 8-byte word at offset 8 of struct page / struct folio (0xffffea00041fe048, corresponding to struct page at 0xffffea00041fe040):
How the race occurs
-
Folio enters the LRU while read I/O is pending:
When a pagecache folio is added for read or readahead (e.g., filemap_add_folio() in mm/filemap.c:969-986), the folio is locked (__folio_set_locked(folio)) and immediately placed on the LRU via folio_add_lru(folio). ext4_mpage_readpages() (fs/ext4/readpage.c:293) then attaches the locked folio to a bio via bio_add_folio() and submits the read request.
-
Reclaim isolates and manipulates folio->lru without the folio lock (CPU 0):
During MGLRU reclaim (evict_folios() -> isolate_folios() -> scan_folios() -> isolate_folio() in mm/vmscan.c:4869), isolate_folio() only checks folio_try_get() and folio_test_clear_lru(); it does not check or acquire PG_locked, so a folio undergoing read I/O can be isolated onto the local list.
evict_folios() then calls shrink_folio_list(&list, ...) (mm/vmscan.c:1189-1193), which pops the folio and removes it from the local list before calling folio_trylock(folio):
folio = lru_to_folio(folio_list);
list_del(&folio->lru);
if (!folio_trylock(folio))
goto keep;
list_del(&folio->lru) (include/linux/list.h:276) performs an unmarked 8-byte write entry->next = LIST_POISON1 (0xdead000000000100) to folio->lru.next (0xffffea00041fe048), and after folio_trylock() fails, keep: (mm/vmscan.c:1647) calls list_add(&folio->lru, &ret_folios), writing to folio->lru.next again.
-
BIO completion reads page->compound_info locklessly (CPU 1):
In mpage_end_io() -> __read_end_io() (fs/ext4/readpage.c:65), bio_for_each_folio_all(fi, bio) advances from one bio_vec to the next via bio_next_folio() -> bio_first_folio() (include/linux/bio.h:291,309) -> bvec_folio() (include/linux/bvec.h:89) -> page_folio() -> _compound_head() (include/linux/page-flags.h:221):
unsigned long info = READ_ONCE(page->compound_info);
Because folio_end_read() has not yet been called on the folio in the next bio_vec, that folio is still locked (PG_locked set), and _compound_head() performs a marked 8-byte READ_ONCE() on page->compound_info (0xffffea00041fe048) concurrently with shrink_folio_list()'s unmarked write in list_del(&folio->lru).
Invariant analysis
As documented in include/linux/mm_types.h:85-87 and include/linux/page-flags.h:289, page_folio() / _compound_head() is explicitly permitted without holding a reference or lock, provided that any other user of the union word never sets bit 0 (PageTail()). Here:
folio->lru belongs only to the head page of the folio (&folio->page).
- Every value stored in
folio->lru.nextβaligned struct list_head * pointers and LIST_POISON1 ((void *)0x100 + POISON_POINTER_DELTA)βhas bit 0 equal to 0.
- When bit 0 of
info is 0, _compound_head() returns (unsigned long)page regardless of the remaining bits (both when compound_info_has_mask() is true, as under CONFIG_VMEMMAP_OPTIMIZATION=y, where mask = (0) - 1 = -1UL, and when it is false).
- Meanwhile,
shrink_folio_list() fails folio_trylock(folio) because the folio is still locked for read I/O, so the folio cannot be freed, split, or otherwise modified by reclaim.
To silence the KCSAN warning, the list_del(&folio->lru) / list_add(&folio->lru, ...) updates in mm/vmscan.c (or the READ_ONCE(page->compound_info) in _compound_head() in include/linux/page-flags.h with data_race() or WRITE_ONCE on the lru side) would need appropriate KCSAN annotations, or shrink_folio_list() would need to avoid modifying folio->lru until after folio_trylock(folio) succeeds (which would require a list_for_each_entry_safe-style traversal or data_race()).