syzbot
KCSAN: data-race in evict_folios / mpage_end_io
Status:
moderation: reported on 2026/11/19 00:05
Subsystems:
ext4
Labels:
prio:low
race:benign
[Documentation on labels]
Reported-by: syzbot+31d0fd3e2418cf8d7d40@syzkaller.appspotmail.com
First crash: 1d21h, last: 4h40m
✨ AI-generated root cause summary:
A KCSAN data race occurs between proactive memory reclaim (evict_folios) and read I/O completion (mpage_end_io). In struct page / struct folio, folio->lru.next and page->compound_info share a union slot at byte offset 8. While an in-flight read bio completes in softirq context, mpage_end_io() traverses folios via bio_for_each_folio_all() -> page_folio() -> _compound_head(), which executes a marked READ_ONCE(page->compound_info) without holding locks. Concurrently, evict_folios() performs an unmarked plain store to folio->lru.next via list_move() -> __list_add(), triggering KCSAN due to an unmarked write racing with a marked read.
▶
▼
✨ Full AI root cause analysis
Root Cause Analysis
1. Functions, Structs, and Fields Involved
struct page / struct folio (include/linux/mm_types.h):
- In
struct page (lines 89–131) and struct folio (lines 407–423), the 8-byte word at offset 8 (0xffffea000420f208) is an overlapping union member.
- On head pages and base (order-0) pages, this word holds
folio->lru.next (struct list_head lru).
- On tail pages of compound pages, this word holds
page->compound_info. By kernel convention (include/linux/mm_types.h:85-87), bit 0 encodes PageTail() (1 for tail pages, 0 for head/order-0 pages). All non-tail union users must guarantee bit 0 remains 0.
_compound_head() / page_folio() (include/linux/page-flags.h:219-248, 283-298):
page_folio() is explicitly documented to require neither references nor locks ("Context: No reference, nor lock is required on @page.").
- It invokes
_compound_head(), which executes READ_ONCE(page->compound_info) on the page to test whether bit 0 is set (info & 1).
evict_folios() / __list_add() (mm/vmscan.c:5115-5117, include/linux/list.h:165-176):
- Proactive reclaim manipulates the folio's LRU linkage (
folio->lru).
- In
__list_add(), new->next = next; (line 173) updates folio->lru.next via a plain C store without WRITE_ONCE().
mpage_end_io() / __read_end_io() (fs/ext4/readpage.c:61-70, 103-114):
- The bio end-of-I/O handler iterates over folios in the completed read request using
bio_for_each_folio_all(fi, bio) (include/linux/bio.h:281-319).
- It resolves each
bio_vec page to its enclosing folio via bvec_folio() -> page_folio() -> _compound_head().
2. Triggering Mechanism and Race Condition
-
Readahead Folio Allocation and Submission:
- During file readahead / fault handling (
filemap_fault() -> filemap_add_folio()), a newly allocated page cache folio is locked (__folio_set_locked()) and immediately added to the LRU list via folio_add_lru().
- The filesystem submits a read request (
ext4_mpage_readpages()) creating a REQ_OP_READ bio with completion callback mpage_end_io(). The folio remains locked while I/O is in flight.
-
Proactive Memory Reclaim on CPU 0:
- Concurrently, proactive reclaim (
evict_folios()) isolates folios from the LRU and passes them to shrink_folio_list().
- In
shrink_folio_list(), folio_trylock(folio) fails because the folio is held locked for read I/O, so the folio is returned on the local reclaim list.
- Back in
evict_folios() (lines 5115–5117), the loop tests !skip_retry && !folio_test_active(folio) && !folio_mapped(folio) && !folio_test_dirty(folio) && !folio_test_writeback(folio).
- Because the folio is clean and inactive,
list_move(&folio->lru, &clean) is called.
list_move() calls list_add(), which calls __list_add(), executing new->next = next; (include/linux/list.h:173). This writes to folio->lru.next at offset 8 as an unmarked plain store.
-
Read Completion Softirq on CPU 1:
- As the block device completes the read I/O, the interrupt triggers softirq execution (
blk_done_softirq() -> bio_endio() -> mpage_end_io() -> __read_end_io()).
__read_end_io() calls bio_for_each_folio_all() -> bio_first_folio() -> bvec_folio() -> page_folio(bv->bv_page) -> _compound_head().
_compound_head() reads READ_ONCE(page->compound_info) from the exact same offset 8 on the head page.
-
KCSAN Splat:
- Under LKMM, an unmarked plain write (
new->next = next) racing concurrently with a marked read (READ_ONCE(page->compound_info)) constitutes a data race, which KCSAN detects and flags.
Sample crash report:
* Struck through repros no longer work on HEAD.