syzbot
KCSAN: data-race in shrink_folio_list / swap_cache_get_folio
Status:
moderation: reported on 2026/11/17 15:28
Subsystems:
mm
Labels:
prio:low
[Documentation on labels]
Reported-by: syzbot+9729e31b04cba39101c0@syzkaller.appspotmail.com
First crash: 11h41m, last: 11h41m
✨ AI-generated root cause summary:
A data race occurs between lockless swap cache lookup in swap_cache_get_folio() and folio LRU list manipulation in shrink_folio_list(). In struct page and struct folio, folio->lru.next is unioned with page->compound_info at offset 8 bytes (FOLIO_MATCH(compound_info, lru)). When a folio in the swap cache fails or bypasses reclaim, shrink_folio_list() unlocks it and calls list_add(&folio->lru, &ret_folios), which performs an unmarked store to folio->lru.next. Concurrently, swap_cache_get_folio() invokes swp_tb_to_folio() -> pfn_folio() -> _compound_head(), which performs a READ_ONCE(page->compound_info) on the same union word without holding a lock or folio reference.
▶
▼
✨ Full AI root cause analysis
Root Cause Technical Analysis
1. Functions, Structs, and Fields Involved
swap_cache_get_folio() (mm/swap_state.c:101-105): Performs a lockless lookup of a swap entry in the swap cache/table (swap_table_get()) and attempts to obtain a folio reference via folio_try_get().
swp_tb_to_folio() (mm/swap_table.h:178-182): Converts a swap table entry (swp_tb) into a struct folio * by invoking pfn_folio().
_compound_head() (include/linux/page-flags.h:219-248): Called by pfn_folio() -> page_folio() on pfn_to_page(pfn). Performs READ_ONCE(page->compound_info) to determine whether the page is a tail page and locate its head folio.
shrink_folio_list() (mm/vmscan.c:1645-1647): Reclaim logic that unlocks folios that are not reclaimed and adds them to ret_folios using list_add(&folio->lru, &ret_folios).
__list_add() (include/linux/list.h:165-176): Writes new->next = next, which corresponds to folio->lru.next.
struct page and struct folio (include/linux/mm_types.h:89-131, 404-450, 517):
At offset +8 bytes within the struct descriptor, page->compound_info (used for identifying compound tail pages via bit 0) aliases folio->lru.next via an anonymous union (FOLIO_MATCH(compound_info, lru)).
2. Detailed Mechanism and Trigger
-
Unmapped or Kept Folios in Reclaim:
A swap-backed folio resides in the swap cache. During page reclaim, shrink_folio_list() isolates the folio from its LRU list. If the folio cannot be reclaimed (for example, if unmapping failed, if it is pinned, or if it is dirty/locked), control jumps to keep_locked:, where folio_unlock(folio) is executed. At keep:, while still holding the isolation reference, shrink_folio_list() executes:
list_add(&folio->lru, &ret_folios);
Inside __list_add(), this performs an unmarked store (new->next = next) to folio->lru.next at offset 8 bytes of the folio.
-
Concurrent Lockless Swap Cache Lookup:
Concurrently, another task experiences a swap page fault for this folio (do_swap_page()) and calls swap_cache_get_folio(entry):
swp_tb = swap_table_get(ci, ci_off);
if (!swp_tb_is_folio(swp_tb))
return NULL;
folio = swp_tb_to_folio(swp_tb);
if (!folio_try_get(folio))
continue;
swap_cache_get_folio() does not hold the cluster lock or any folio locks during the initial probe. When it calls swp_tb_to_folio(swp_tb), it invokes pfn_folio(), which calls page_folio(pfn_to_page(pfn)). This leads into _compound_head(), which executes:
unsigned long info = READ_ONCE(page->compound_info);
Since page->compound_info and folio->lru.next occupy the exact same memory word (offset 8), this READ_ONCE() reads from the exact same address (0xffffea00047ae9c8 in the report) that is concurrently modified by list_add().
-
Concurrency Rule Violation:
Because one side performs a concurrent unmarked write (new->next = next) while the other side performs a marked read (READ_ONCE(page->compound_info)) without synchronization (locks or RCU grace periods protecting list membership), KCSAN detects a data race under the Linux Kernel Memory Model (LKMM).
-
Safety Analysis in Practice:
Both lru.next pointers and head page addresses are naturally aligned kernel virtual pointers, meaning bit 0 is strictly 0. As documented in include/linux/mm_types.h:85-87, non-tail users of this union word must keep bit 0 clear to prevent collision with PageTail(). Both before and after the list_add() store, (info & 1) evaluates to 0, causing _compound_head() to return the correct head page (struct folio *)page. After folio_try_get(), swap_cache_get_folio() re-checks swap_table_get() to ensure the folio was not removed and replaced, making this race benign in practice on modern 64-bit architectures.
Sample crash report:
* Struck through repros no longer work on HEAD.