Technical Root Cause Analysis
The KCSAN report captures a same-CPU data race on task_struct::migration_disabled (unsigned short, 2 bytes at 0xffff8881037ca6f8) between task context and an interrupt/softirq handler running on CPU 1:
-
Task context read (include/linux/sched.h:2457):
While closing a TCP socket (tcp_close() -> __sk_free() -> sk_destruct() -> __sk_destruct()), bpf_sk_storage_free() (net/core/bpf_sk_storage.c:47) brackets its execution with rcu_read_lock_dont_migrate() and rcu_read_unlock_migrate() (include/linux/rcupdate.h:986,994). With CONFIG_PREEMPT_RCU=y, these call migrate_disable() and migrate_enable(), which inline __migrate_disable() and __migrate_enable() (include/linux/sched.h:2444-2497).
Inside __migrate_enable() (at line 2457), task 3294 performs a plain read of p->migration_disabled (if (p->migration_disabled > 1)), where p == current and p->migration_disabled == 1.
-
Interrupt/softirq write (include/linux/sched.h:2490):
Because CONFIG_KCSAN_INTERRUPT_WATCHER=y (enabled via CONFIG_KCSAN_STRICT=y), kcsan_setup_watchpoint() in kernel/kcsan/core.c:589 does not disable interrupts while stalling in delay_access(). An APIC timer interrupt fires on CPU 1 and runs softirqs via __irq_exit_rcu() -> invoke_softirq() -> __do_softirq() -> rcu_core() -> rcu_do_batch().
An RCU callback (sctp_endpoint_destroy_rcu() -> sock_put() -> sk_free() -> __sk_destruct()) calls bpf_sk_storage_free(), which enters rcu_read_lock_dont_migrate() -> migrate_disable() -> __migrate_disable().
Because interrupts/softirqs execute with current still pointing to the interrupted task (p), __migrate_disable() observes p->migration_disabled == 1 (nonzero) and executes the plain read-modify-write p->migration_disabled++ at include/linux/sched.h:2490, triggering the KCSAN report.
-
Why the underlying logic is benign (aside from KCSAN instrumentation):
- On the interrupted CPU,
current is the same task_struct across the interrupt, and every interrupt/softirq path pairs migrate_disable() with migrate_enable() before returning (restoring p->migration_disabled and the per-CPU rq->nr_pinned counter via this_rq_pinned() to their exact pre-interrupt values).
- While
p->migration_disabled > 0, the task cannot be migrated off CPU 1, and any nested interrupt seeing p->migration_disabled >= 1 only increments and decrements p->migration_disabled without reaching ___migrate_enable() or modifying this_rq_pinned().
- Even if an interrupt occurs when
p->migration_disabled == 0 (e.g., between this_rq_pinned()++ and p->migration_disabled = 1 in __migrate_disable(), or after p->migration_disabled = 0 and before this_rq_pinned()-- in __migrate_enable()), the interrupt executes a balanced 0 -> 1 -> 0 transition on both p->migration_disabled and this_rq_pinned().
- The KCSAN warning arises because
__migrate_enable() and __migrate_disable() in include/linux/sched.h use plain C accesses on p->migration_disabled rather than READ_ONCE()/WRITE_ONCE() or data_race() annotations under CONFIG_KCSAN_INTERRUPT_WATCHER=y.