Root Cause Analysis
The KCSAN data race is on struct ring_buffer_per_cpu::commit_page (at offset 0x60 in struct ring_buffer_per_cpu) in kernel/trace/ring_buffer.c, between a task-context commit finishing in ring_buffer_unlock_commit() and a hardirq-context reservation advancing the commit page on the same CPU.
Involved Functions and Fields
- Struct / Field:
struct ring_buffer_per_cpu::commit_page (struct buffer_page *, offset 768 bits / 96 bytes), cpu_buffer->committing, cpu_buffer->current_context, and cpu_buffer->reader_page.
- Reader path (
kernel/trace/ring_buffer.c):
- Writer path (
kernel/trace/ring_buffer.c):
Mechanism
Although ring_buffer_unlock_commit() still has preemption disabled and holds the RB_CTX_NORMAL recursion bit, cpu_buffer->committing has already dropped to 0 in rb_commit() and interrupts are enabled. An interrupt on the same CPU can therefore legitimately become the outermost active committer (committing == 1) and update cpu_buffer->commit_page concurrently with rb_wakeups() reading cpu_buffer->commit_page. Because neither the write in rb_inc_page() (or callers updating commit_page) nor the read in rb_wakeups() uses READ_ONCE()/WRITE_ONCE() (or data_race()), KCSAN reports a data race on the 8-byte commit_page pointer.