syzbot
KCSAN: data-race in filemap_fault / filemap_read_folio (2)
Status:
moderation: reported on 2026/11/19 00:07
Subsystems:
mm
Labels:
prio:low
race:benign
[Documentation on labels]
Reported-by: syzbot+b7808ed798bd9e9bd311@syzkaller.appspotmail.com
First crash: 1d16h, last: 1d06h
✨ AI-generated root cause summary:
A data race occurs on the 'ra_pages' field of struct file_ra_state (embedded in struct file as f_ra) between shrink_readahead_size_eio() and do_async_mmap_readahead(). When a folio read fails with an I/O error in filemap_read_folio(), shrink_readahead_size_eio() reduces the readahead size with an unsynchronized read-modify-write ('ra->ra_pages /= 4'). Concurrently, another thread faulting on the same shared file mapping in do_async_mmap_readahead() performs an unsynchronized read of 'ra->ra_pages'. Because struct file_ra_state accesses across concurrent page faults lack synchronization or atomic annotations (READ_ONCE/WRITE_ONCE), KCSAN flags the concurrent access as a data race.
▶
▼
✨ Full AI root cause analysis
Technical Analysis and Root Cause
1. Functions, Structs, and Files Involved
- File:
mm/filemap.c
- Functions:
shrink_readahead_size_eio(), filemap_read_folio(), do_async_mmap_readahead(), filemap_fault()
- Data Structures and Fields:
struct file (f_ra), struct file_ra_state (ra_pages)
2. Root Cause and Mechanism
struct file_ra_state is embedded inside each struct file (file->f_ra) to maintain readahead context and heuristics for that open file description. When multiple threads or processes map the same open file and take concurrent page faults, they share this file->f_ra instance without per-file synchronization.
-
Write Path (shrink_readahead_size_eio):
When an I/O error occurs while reading a folio from a backing device (as indicated by the loop device error in the report: Buffer I/O error on dev loop5... attempt to access beyond end of device), filemap_read_folio() determines that the folio could not be made up-to-date and calls:
static void shrink_readahead_size_eio(struct file_ra_state *ra)
{
ra->ra_pages /= 4;
}
This performs an unsynchronized read-modify-write on ra->ra_pages to reduce the readahead window and avoid thrashing on media errors.
-
Read Path (do_async_mmap_readahead):
Concurrently, another thread executing filemap_fault() on a mapping of the same struct file enters do_async_mmap_readahead(), which inspects:
/* If we don't want any read-ahead, don't bother */
if (vmf->vma->vm_flags & VM_RAND_READ || !ra->ra_pages)
return fpin;
and subsequently passes ra->ra_pages to page_cache_async_ra().
-
Concurrency Defect:
Neither shrink_readahead_size_eio() nor do_async_mmap_readahead() takes a lock or uses atomic primitives/marked memory access operations (e.g., READ_ONCE() / WRITE_ONCE(), which are used for other fields in file_ra_state such as mmap_miss). Because one thread performs an unsynchronized write while another performs an unsynchronized read to the exact same 4-byte address ra->ra_pages, KCSAN detects and reports a data race.
Sample crash report:
* Struck through repros no longer work on HEAD.