syzbot
KCSAN: data-race in io_issue_sqe / io_submit_sqes
Status:
moderation: reported on 2026/11/17 10:12
Subsystems:
io-uring
Labels:
race:benign
prio:low
[Documentation on labels]
Reported-by: syzbot+fbbda44f5390494292c2@syzkaller.appspotmail.com
First crash: 7h24m, last: 7h24m
✨ AI-generated root cause summary:
A KCSAN data race occurs between task submission and asynchronous io-wq request completion on the 32-bit field ctx->int_flags. In io_init_req() (called from io_submit_sqes() by the submission task or SQPOLL thread under ctx->uring_lock), handling IOSQE_CQE_SKIP_SUCCESS executes an unmarked plain C read-modify-write ctx->int_flags |= IO_RING_F_DRAIN_DISABLED. Simultaneously, an io-wq worker thread completing an asynchronous request in io_req_complete_post() without holding ctx->uring_lock reads ctx->int_flags & IO_RING_F_LOCKLESS_CQ using an unmarked plain C read. Because immutable setup flags (such as IO_RING_F_LOCKLESS_CQ) share the same 32-bit word with dynamic runtime flags (such as IO_RING_F_DRAIN_DISABLED), the concurrent unprotected write and read trigger a data race report in KCSAN.
▶
▼
✨ Full AI root cause analysis
Root Cause Analysis
1. Functions, Structs, and Fields Involved
- Struct and Field:
struct io_ring_ctx::int_flags (include/linux/io_uring_types.h:341), an unsigned int located at byte offset 4 of struct io_ring_ctx (in the hot, read-mostly cacheline directly after flags).
- Flags Involved:
IO_RING_F_DRAIN_DISABLED (BIT(10)): Set at runtime when an SQE with IOSQE_CQE_SKIP_SUCCESS is processed.
IO_RING_F_LOCKLESS_CQ (BIT(7)): Set during ring initialization in io_uring_create() and remains invariant for the lifetime of struct io_ring_ctx.
- Writers:
io_submit_sqes() -> io_submit_sqe() -> io_init_req() (io_uring/io_uring.c:1939), executed by either the submitting user task or the SQPOLL kernel thread (io_sq_thread() / __io_sq_thread(), io_uring/sqpoll.c:252) holding ctx->uring_lock.
- Readers:
io_req_complete_post() (io_uring/io_uring.c:1019), called on asynchronous work completion by an io-wq worker thread (io_wq_worker -> io_worker_handle_work -> io_wq_submit_work -> io_issue_sqe -> io_req_complete_post) without holding ctx->uring_lock.
2. Technical Mechanism and Trigger Conditions
-
Packing Immutable and Dynamic Flags in ctx->int_flags:
In commit f1a424e21c15, individual bitfields in struct io_ring_ctx were converted into flags packed within a single 32-bit field (ctx->int_flags). This field stores both:
- Static/invariant setup flags: Set once at ring creation in
io_uring_create() (such as IO_RING_F_LOCKLESS_CQ, IO_RING_F_TASK_COMPLETE, IO_RING_F_SYSCALL_IOPOLL, and IO_RING_F_COMPAT).
- Dynamic runtime flags: Updated during ring operations (such as
IO_RING_F_DRAIN_DISABLED, IO_RING_F_DRAIN_ACTIVE, IO_RING_F_DRAIN_NEXT, IO_RING_F_POLL_ACTIVATED, etc.).
-
Concurrent Write (CPU 0):
When the SQPOLL thread (io_sq_thread) or user task submits SQEs via io_submit_sqes(), it holds ctx->uring_lock. If an SQE has IOSQE_CQE_SKIP_SUCCESS, io_init_req() executes:
if (sqe_flags & IOSQE_CQE_SKIP_SUCCESS)
ctx->int_flags |= IO_RING_F_DRAIN_DISABLED;
This is an unmarked plain C read-modify-write operation on the 32-bit integer ctx->int_flags.
-
Concurrent Read (CPU 1):
Simultaneously, requests offloaded to io-wq run asynchronously without holding ctx->uring_lock. When an io-wq worker completes a request via io_req_complete_post(), it checks whether the ring uses a lockless CQ model to decide whether completions must be deferred via task_work or can take ctx->completion_lock:
if ((ctx->int_flags & IO_RING_F_LOCKLESS_CQ) ||
(req->flags & (REQ_F_REISSUE | REQ_F_IO_DRAIN))) {
defer_complete:
req->io_task_work.func = io_req_task_complete;
io_req_task_work_add(req);
return;
}
This is an unmarked plain C read of ctx->int_flags.
-
KCSAN Detection:
Because one thread performs a plain C write to ctx->int_flags while another thread concurrently performs a plain C read of ctx->int_flags without mutual exclusion or memory access annotations (such as READ_ONCE() / WRITE_ONCE() or data_race()), KCSAN flags the concurrent access as a data race.
Sample crash report:
* Struck through repros no longer work on HEAD.