Root Cause Analysis
1. Functions, Structs, and Variables Involved
- Variable / Field:
current->pagefault_disabled (struct task_struct::pagefault_disabled, declared in include/linux/sched.h).
- Accessors:
- Task Context Callers:
strncpy_from_kernel_nofault() in mm/maccess.c:95, 101 (invoked via bpf_probe_read_kernel_str()).
- Interrupt / NMI Context Callers:
perf_callchain_user() in arch/x86/events/core.c:3468, 3492 (and perf_callchain_user32() in lines 3412, 3429), invoked via get_perf_callchain() during an APIC timer interrupt (hrtimer_interrupt -> perf_swevent_hrtimer).
2. Technical Mechanism and Trigger Condition
In Linux, task_struct::pagefault_disabled is an integer counter tracking nesting depth to indicate whether page faults may sleep or must immediately divert to the exception fixup table.
-
Unmarked Read-Modify-Write in include/linux/uaccess.h:
static __always_inline void pagefault_disabled_inc(void)
{
current->pagefault_disabled++;
}
static __always_inline void pagefault_disabled_dec(void)
{
current->pagefault_disabled--;
}
These modifications are plain, unmarked operations on current->pagefault_disabled without atomic primitives, READ_ONCE()/WRITE_ONCE(), or local atomic types (local_t).
-
Absence of IRQ Disabling in Task Context:
Functions such as strncpy_from_kernel_nofault() (and various usercopy/atomic routines) call pagefault_disable() with local interrupts enabled.
-
Re-entrant Modification by Interrupt Handlers:
While task context on CPU 1 is executing pagefault_disable() or pagefault_enable(), a hardware or timer interrupt (such as an APIC timer interrupt triggering perf_swevent_hrtimer) can fire on the same CPU. When the event overflows and samples user callchains, get_perf_callchain() calls architecture-specific perf_callchain_user() (arch/x86/events/core.c). To safely traverse user frame pointers without faulting, perf_callchain_user() also calls pagefault_disable() and pagefault_enable(), modifying current->pagefault_disabled of the interrupted task.
-
KCSAN Data-Race Detection:
With CONFIG_KCSAN_INTERRUPT_WATCHER=y, KCSAN monitors accesses between interrupt handlers and interrupted task code on the same CPU. When kcsan_setup_watchpoint() stalls during the task context's access to current->pagefault_disabled, the timer interrupt executes concurrently on that same CPU and performs another unmarked read-write on the same memory address (0xffff88810283bfd4), triggering the KCSAN data-race report.
3. Invariants and Resolution
Under the Linux Kernel Memory Model (LKMM), shared variables accessed concurrently across execution contexts (including task vs. interrupt contexts) must use marked accesses or synchronization. Although the interrupt handler executes in strict LIFO order and balances increments and decrements, plain C ++/-- accesses violate LKMM assumptions regarding asynchronous re-entrancy. Fixing the warning typically involves using READ_ONCE()/WRITE_ONCE() pairs or transitioning task_struct::pagefault_disabled to an interrupt-safe type such as local_t.