Root Cause
This is a KCSAN-reported data race in the XArray mark-tracking code between a locked mark update (xa_set_mark()) and a lockless RCU marked search (xa_find() -> xas_find_marked() -> xas_find_chunk()), triggered concurrently through devlink registration and netlink lookup/dump paths.
Involved Structures, Functions, and Files
Trigger Mechanism
- Task 3329 (CPU 1) creates a
netdevsim device via sysfs (new_device_store -> nsim_drv_probe -> devl_register at net/devlink/core.c:413). The devlink instance was previously inserted into the devlinks XArray in __devlink_alloc() (net/devlink/core.c:468), and devl_register() sets DEVLINK_REGISTERED (XA_MARK_1) via xa_set_mark(&devlinks, devlink->index, DEVLINK_REGISTERED).
- Task 3324 (CPU 0) concurrently executes a netlink dump (
devlink_nl_port_get_dumpit -> devlink_nl_dumpit -> devlink_get_from_attrs_lock -> devlinks_xa_find_get -> __devlinks_xa_find_get at net/devlink/core.c:375), which calls xa_find(&devlinks, indexp, end, DEVLINK_REGISTERED) under rcu_read_lock().
- While Task 3329 executes
__test_and_set_bit() on node->marks[DEVLINK_REGISTERED][0] under xa_lock(&devlinks), Task 3324 reads the same 8-byte node->marks[DEVLINK_REGISTERED][0] word in xas_find_chunk() without xa_lock.
Violated Invariant / Concurrency Rule
Although all writers to xa_node->marks are mutually serialized by xa_lock (and xa_node freeing is RCU-deferred via xa_node_free() -> call_rcu()), lockless RCU readers access node->marks concurrently with xa_lock-protected writers. xas_find_chunk() uses an unmarked plain read (*addr) instead of a marked/atomic read (READ_ONCE()), and node_set_mark() (along with node_clear_mark()) uses non-atomic bitops (__test_and_set_bit() / __test_and_clear_bit()) rather than marked writes or data_race() annotations compatible with KCSAN. Without READ_ONCE() on the reader and atomic/marked updates (or WRITE_ONCE() / set_bit() / data_race()) on the writer, C-level data-race rules are violated, causing KCSAN to flag the concurrent access (and theoretically permitting compiler load/store tearing or reloading across *addr on the reader path).