syzbot
KCSAN: data-race in __pwq_activate_work / queue_delayed_work_on
Status:
moderation: reported on 2026/11/23 06:25
Subsystems:
rds
Labels:
prio:high
race:benign
[Documentation on labels]
Reported-by: syzbot+397ea23d5af42ce48bb1@syzkaller.appspotmail.com
First crash: 4d01h, last: 2h15m
✨ AI-generated root cause summary:
In kernel/workqueue.c, work->data (accessed via work_data_bits(work)) is manipulated locklessly by queue_work_on() and queue_delayed_work_on() via test_and_set_bit(WORK_STRUCT_PENDING_BIT, ...). When a work item is queued on an ordered or congested workqueue where nr_active >= max_active, it is placed onto pwq->inactive_works with both WORK_STRUCT_PENDING and WORK_STRUCT_INACTIVE set in work->data. When an earlier work item completes, the worker thread activates the pending work item in __pwq_activate_work() under pwq->pool->lock using an unmarked plain C read (*wdb & WORK_STRUCT_INACTIVE) and a non-atomic __clear_bit(WORK_STRUCT_INACTIVE_BIT, wdb). A concurrent call to queue_delayed_work_on() (e.g., from rds_tcp_write_space() in softirq) executes test_and_set_bit() locklessly on the same atomic_long_t word, triggering a KCSAN data race.
▶
▼
✨ Full AI root cause analysis
Technical Root Cause Analysis
Involved Components
- Source file:
kernel/workqueue.c (triggered via legitimate use from net/rds/tcp_send.c / net/rds/connection.c)
- Functions:
__pwq_activate_work(), queue_delayed_work_on(), queue_work_on()
- Structures and fields:
struct work_struct::data (atomic_long_t), accessed via work_data_bits(work) (unsigned long *), struct pool_workqueue::inactive_works, and flag bits WORK_STRUCT_PENDING_BIT (bit 0) and WORK_STRUCT_INACTIVE_BIT (bit 1).
Mechanism and Trigger Sequence
-
Lockless PENDING claiming in Workqueue Queueing API:
In kernel/workqueue.c, functions such as queue_work_on() and queue_delayed_work_on() (lines 2765, 2597) are intentionally callable from any context (including interrupt/softirq contexts) without acquiring pool->lock. To determine whether a work item can be queued, they perform an atomic bit operation:
test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))
This operation executes an atomic read-modify-write (LOCK BTS on x86, instrumented as an atomic RMW by KCSAN) directly on work->data.
-
Inactive Work Placement:
In the reported scenario, net/rds allocates an ordered workqueue (alloc_ordered_workqueue("krds_cp_wq#%lu/%d", 0, ...)) where max_active == 1. When a work item such as cp->cp_send_w is queued while another work item is already in flight (pwq->nr_active >= max_active), __queue_work() inserts it into pwq->inactive_works and marks work->data with both WORK_STRUCT_PENDING and WORK_STRUCT_INACTIVE (lines 2549–2550).
-
Activation from inactive_works:
When the running work item finishes, the worker thread executes pwq_dec_nr_in_flight() -> pwq_dec_nr_active() -> node_activate_pending_pwq() -> __pwq_activate_work().
__pwq_activate_work() (lines 1813–1824) runs under pwq->pool->lock and nna->lock:
static void __pwq_activate_work(struct pool_workqueue *pwq,
struct work_struct *work)
{
unsigned long *wdb = work_data_bits(work);
WARN_ON_ONCE(!(*wdb & WORK_STRUCT_INACTIVE));
trace_workqueue_activate_work(work);
if (list_empty(&pwq->pool->worklist))
pwq->pool->last_progress_ts = jiffies;
move_linked_works(work, &pwq->pool->worklist, NULL);
__clear_bit(WORK_STRUCT_INACTIVE_BIT, wdb);
}
-
The Data Race:
While CPU 0 executes __pwq_activate_work() and accesses work->data using an unmarked plain C read (*wdb & WORK_STRUCT_INACTIVE at line 1818, followed by __clear_bit(WORK_STRUCT_INACTIVE_BIT, wdb) at line 1823), an incoming TCP packet triggers softirq execution on CPU 1. In softirq context, rds_tcp_write_space() calls:
queue_delayed_work(cp->cp_wq, &cp->cp_send_w, 0);
which invokes queue_delayed_work_on(). Because queue_delayed_work_on() executes test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)) locklessly outside pool->lock, an atomic read-modify-write access to work->data occurs concurrently with the plain unmarked read in __pwq_activate_work(), causing KCSAN to report a data race.
Sample crash report:
* Struck through repros no longer work on HEAD.