| 0/0 |
2026/02/23 15:40 |
flow |
assessment-kcsan |
3m
Results: map[Benign:true Confident:true Explanation:The data race occurs between a write to the `drain_disabled` bitfield and a read of the `syscall_iopoll` bitfield within the `struct io_ring_ctx`. These bitfields, along with several others, are grouped together in a single `unsigned int` word in the structure definition (found in `include/linux/io_uring_types.h`).
### Analysis of the Race
1. **Memory Layout**: The bitfields `drain_next`, `op_restricted`, `reg_restricted`, `off_timeout_used`, `drain_active`, `has_evfd`, `task_complete`, `lockless_cq`, `syscall_iopoll`, `poll_activated`, `drain_disabled`, etc., are all part of the same memory location (a 2-byte or 4-byte word). KCSAN identifies a race because a write to one bitfield involves a read-modify-write (RMW) of the entire word, which overlaps with a read of another bitfield in the same word.
2. **Write Access**: The write stack trace shows `io_init_req` setting `ctx->drain_disabled = true`. This happens during request submission. All writes to these bitfields (including `drain_disabled`, `off_timeout_used`, and `poll_activated`) are performed while holding the `ctx->uring_lock`. In the reported case, the SQPOLL thread is performing the submission.
3. **Read Access**: The read stack trace shows `__do_sys_io_uring_enter` reading `ctx->syscall_iopoll`. When `IORING_SETUP_SQPOLL` is enabled, the `io_uring_enter` system call does not take the `uring_lock` before checking this flag.
4. **Nature of the Fields**:
* `syscall_iopoll`: This bit is set during the creation of the `io_uring` context (`io_uring_create`) and is never modified thereafter. It indicates whether the ring is configured for IOPOLL without SQPOLL.
* `drain_disabled`: This bit is only ever set to `true` (in `io_init_req`) and is never cleared. It indicates that the "drain" feature is disabled for this context.
* `poll_activated` and `off_timeout_used`: These are also only ever set to `true` during the lifetime of the context (except for initialization).
### Conclusion
The data race is **benign**. Although the bitfields share a memory location and are accessed without full synchronization, the specific bits being read without a lock (`syscall_iopoll` in this case) are constant. The write to a neighboring bitfield (`drain_disabled`) is a read-modify-write operation that preserves the value of the other bits in the word. Since the bit being read does not change, the reader will always see the correct value regardless of the concurrent write.
This pattern of using bitfields for "read-mostly" or "set-once" flags is common in `io_uring` for performance reasons, and while it triggers KCSAN due to the lack of explicit synchronization on the shared word, it does not result in incorrect logic or memory corruption.]
|
| 1/1 |
2026/02/23 15:40 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/usr/local/google/home/dvyukov/syzkaller/agent/workdir/cache/src/27f21913e25601ec14bf9550912fa548052d7893]
|
| 2/1 |
2026/02/23 15:40 |
action |
kernel-builder |
0m
Results: map[KernelObj:/usr/local/google/home/dvyukov/syzkaller/agent/workdir/cache/build/f610a99703320fc3f40bbab112bbaf5fc74c9413]
|
| 3/1 |
2026/02/23 15:40 |
action |
codesearch-prepare |
0m
Results: map[Index:codesearch-index]
|
| 4/1 |
2026/02/23 15:40 |
agent |
expert |
3m
Model:
Results: map[Benign:true Confident:true]
Instruction:
You are an experienced Linux kernel developer tasked with determining if the given kernel
data race is benign or not. The data race report is from KCSAN tool.
It contains 2 stack traces of the memory accesses that constitute a data race.
A "benign" data races are on a simple int/bool variable or similar field,
and the accesses are not supposed to be protected by any mutual exclusion primitives.
Common examples of such "benign" data races are accesses to various flags fields,
statistics counters, and similar. A "benign" data race does not lead to memory corruption/crash
with a conservative compiler that compiles memory accesses to primitive types
effectively as atomic.
A non-benign (or "harmful" data race) can lead to corruption/crash even with
a conservative compiler that compiles memory accesses to primitive types
effectively as atomic. A common example of a "harmful" data races is race on
a complex container (list/hashmap/etc), where accesses are supposed to be protected
by a mutual exclusion primitive.
Also consider races that happen at the same time with the given one.
If there is no synchronization in between, other memory accesses in the involved threads
race with each other if they access the same memory. For example, if both threads execute:
some_struct->have_elements = true;
list_add(new_node, &some_struct->list_head);
the race on some_struct->have_elements may appear benign, however it also implies there
is a race on some_struct->list_head which is not benign, since the list is not thread-safe.
Take into account that on 32-bit systems 64-bit memory accesses may be split into two accesses,
and thus even with a conservative compiler may not be fully atomic. However, such races may
still be benign depending on how writes are done, and how read data is used.
In the final reply explain why you think the given data race is benign or is harmful.
Use the provided tools to confirm any assumptions, variables/fields being accessed, etc.
In particular, don't make assumptions about the kernel source code,
use codesearch tools to read the actual source code.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The data race report is:
==================================================================
BUG: KCSAN: data-race in __se_sys_io_uring_enter / io_submit_sqes
write to 0xffff8881438eb004 of 2 bytes by task 27617 on cpu 1:
io_init_req io_uring/io_uring.c:1770 [inline]
io_submit_sqe io_uring/io_uring.c:1875 [inline]
io_submit_sqes+0xca3/0x1270 io_uring/io_uring.c:2043
__io_sq_thread io_uring/sqpoll.c:233 [inline]
io_sq_thread+0x7f9/0x1310 io_uring/sqpoll.c:345
ret_from_fork+0x150/0x360 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
read to 0xffff8881438eb004 of 2 bytes by task 27620 on cpu 0:
__do_sys_io_uring_enter io_uring/io_uring.c:2624 [inline]
__se_sys_io_uring_enter+0x2e4/0xf50 io_uring/io_uring.c:2538
__x64_sys_io_uring_enter+0x78/0x90 io_uring/io_uring.c:2538
x64_sys_call+0x1e16/0x3020 arch/x86/include/generated/asm/syscalls_64.h:427
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x12c/0x370 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
value changed: 0x0200 -> 0x0608
Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 27620 Comm: syz.7.7213 Tainted: G W syzkaller #0 PREEMPT(full)
Tainted: [W]=WARN
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 02/12/2026
==================================================================
Reply: The data race occurs between a write to the `drain_disabled` bitfield and a read of the `syscall_iopoll` bitfield within the `struct io_ring_ctx`. These bitfields, along with several others, are grouped together in a single `unsigned int` word in the structure definition (found in `include/linux/io_uring_types.h`).
### Analysis of the Race
1. **Memory Layout**: The bitfields `drain_next`, `op_restricted`, `reg_restricted`, `off_timeout_used`, `drain_active`, `has_evfd`, `task_complete`, `lockless_cq`, `syscall_iopoll`, `poll_activated`, `drain_disabled`, etc., are all part of the same memory location (a 2-byte or 4-byte word). KCSAN identifies a race because a write to one bitfield involves a read-modify-write (RMW) of the entire word, which overlaps with a read of another bitfield in the same word.
2. **Write Access**: The write stack trace shows `io_init_req` setting `ctx->drain_disabled = true`. This happens during request submission. All writes to these bitfields (including `drain_disabled`, `off_timeout_used`, and `poll_activated`) are performed while holding the `ctx->uring_lock`. In the reported case, the SQPOLL thread is performing the submission.
3. **Read Access**: The read stack trace shows `__do_sys_io_uring_enter` reading `ctx->syscall_iopoll`. When `IORING_SETUP_SQPOLL` is enabled, the `io_uring_enter` system call does not take the `uring_lock` before checking this flag.
4. **Nature of the Fields**:
* `syscall_iopoll`: This bit is set during the creation of the `io_uring` context (`io_uring_create`) and is never modified thereafter. It indicates whether the ring is configured for IOPOLL without SQPOLL.
* `drain_disabled`: This bit is only ever set to `true` (in `io_init_req`) and is never cleared. It indicates that the "drain" feature is disabled for this context.
* `poll_activated` and `off_timeout_used`: These are also only ever set to `true` during the lifetime of the context (except for initialization).
### Conclusion
The data race is **benign**. Although the bitfields share a memory location and are accessed without full synchronization, the specific bits being read without a lock (`syscall_iopoll` in this case) are constant. The write to a neighboring bitfield (`drain_disabled`) is a read-modify-write operation that preserves the value of the other bits in the word. Since the bit being read does not change, the reader will always see the correct value regardless of the concurrent write.
This pattern of using bitfields for "read-mostly" or "set-once" flags is common in `io_uring` for performance reasons, and while it triggers KCSAN due to the lack of explicit synchronization on the shared word, it does not result in incorrect logic or memory corruption.
|
| 5/2 |
2026/02/23 15:40 |
llm |
expert |
0m
Model:
Tokens:
input: 3718
output: 22
thoughts: 364
Thoughts: **Analyzing a Data Race in the io_uring Implementation**
Okay, here's what's going on. This report points to a nasty data race within the `io_uring` subsystem, which is not something you want to see. Specifically, it highlights a conflict between `io_submit_sqes` (the write path) and `__se_sys_io_uring_enter` (the read path) targeting a 2-byte field at memory location `0xffff8881438eb004`. The value flips from `0x0200` to `0x0608`. That smells like a classic concurrent access problem.
Now, let's break down those stack traces to understand the flow. The write operation involves `io_init_req` (which is inlined, so it's buried in the calling function), then `io_submit_sqe` (also inlined), which ultimately lands in `io_submit_sqes`. This happens within the `__io_sq_thread`, which is executed in the SQPOLL thread. On the read side, the path starts with `__do_sys_io_uring_enter` (inline), then `__se_sys_io_uring_enter` and finally `__x64_sys_io_uring_enter`. This read operation is originating from a user-space process that's making a system call.
My gut feeling is that `0xffff8881438eb004` is likely a field within some key data structure used by `io_uring`. The challenge now is to determine *which* structure and the exact context of the access.
I'm thinking I need to find the code for `io_init_req` around line 1770 and `__do_sys_io_uring_enter` around line 2624 of `io_uring/io_uring.c`. Of course, line numbers are always a bit fluid depending on kernel version, so I'll probably fire up `codesearch` or similar to pinpoint the functions reliably.
Before I go digging, I should make sure I have the file paths right. Let me quickly list the files within `io_uring/` to make sure I'm in the correct directory.
|
| 6/2 |
2026/02/23 15:40 |
tool |
codesearch-dir-index |
0m
Args:
Results: map[Files:[advise.c advise.h alloc_cache.c alloc_cache.h bpf_filter.c bpf_filter.h cancel.c cancel.h cmd_net.c epoll.c epoll.h eventfd.c eventfd.h fdinfo.c fdinfo.h filetable.c filetable.h fs.c fs.h futex.c futex.h io-wq.c io-wq.h io_uring.c io_uring.h kbuf.c kbuf.h memmap.c memmap.h mock_file.c msg_ring.c msg_ring.h napi.c napi.h net.c net.h nop.c nop.h notif.c notif.h opdef.c opdef.h openclose.c openclose.h poll.c poll.h query.c query.h refs.h register.c register.h rsrc.c rsrc.h rw.c rw.h slist.h splice.c splice.h sqpoll.c sqpoll.h statx.c statx.h sync.c sync.h tctx.c tctx.h timeout.c timeout.h truncate.c truncate.h tw.c tw.h uring_cmd.c uring_cmd.h wait.c wait.h waitid.c waitid.h xattr.c xattr.h zcrx.c zcrx.h] Subdirs:<nil>]
|
| 7/2 |
2026/02/23 15:40 |
llm |
expert |
0m
Model:
Tokens:
input: 5182
output: 43
thoughts: 157
Thoughts: **Analyzing the io_uring Code**
Alright, let's dive in. The report points to `io_uring/io_uring.c`, specifically around line 1770 for `io_init_req` and line 2624 for `__do_sys_io_uring_enter`. I need to understand what's happening at those points.
Hang on... the report explicitly calls out those functions as inline. Hmm, so `io_init_req` is *inline* at `io_uring/io_uring.c:1770`, and `__do_sys_io_uring_enter` is *inline* at `io_uring/io_uring.c:2624`. Okay, I should confirm those definitions in the `io_uring/io_uring.c` source code, keeping in mind the inline nature of the functions could affect things. I need to be aware that the compiler might have optimized these functions away or inlined their contents directly into the calling code. This is something to consider as I work through the code.
|
| 8/2 |
2026/02/23 15:40 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:io_uring/io_uring.c IncludeLines:true Name:io_init_req]
Results: map[SourceCode:1715: static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
1716: const struct io_uring_sqe *sqe, unsigned int *left)
1717: __must_hold(&ctx->uring_lock)
1718: {
1719: const struct io_issue_def *def;
1720: unsigned int sqe_flags;
1721: int personality;
1722: u8 opcode;
1723:
1724: req->ctx = ctx;
1725: req->opcode = opcode = READ_ONCE(sqe->opcode);
1726: /* same numerical values with corresponding REQ_F_*, safe to copy */
1727: sqe_flags = READ_ONCE(sqe->flags);
1728: req->flags = (__force io_req_flags_t) sqe_flags;
1729: req->cqe.user_data = READ_ONCE(sqe->user_data);
1730: req->file = NULL;
1731: req->tctx = current->io_uring;
1732: req->cancel_seq_set = false;
1733: req->async_data = NULL;
1734:
1735: if (unlikely(opcode >= IORING_OP_LAST)) {
1736: req->opcode = 0;
1737: return io_init_fail_req(req, -EINVAL);
1738: }
1739: opcode = array_index_nospec(opcode, IORING_OP_LAST);
1740:
1741: def = &io_issue_defs[opcode];
1742: if (def->is_128 && !(ctx->flags & IORING_SETUP_SQE128)) {
1743: /*
1744: * A 128b op on a non-128b SQ requires mixed SQE support as
1745: * well as 2 contiguous entries.
1746: */
1747: if (!(ctx->flags & IORING_SETUP_SQE_MIXED) || *left < 2 ||
1748: !(ctx->cached_sq_head & (ctx->sq_entries - 1)))
1749: return io_init_fail_req(req, -EINVAL);
1750: /*
1751: * A 128b operation on a mixed SQ uses two entries, so we have
1752: * to increment the head and cached refs, and decrement what's
1753: * left.
1754: */
1755: current->io_uring->cached_refs++;
1756: ctx->cached_sq_head++;
1757: (*left)--;
1758: }
1759:
1760: if (unlikely(sqe_flags & ~SQE_COMMON_FLAGS)) {
1761: /* enforce forwards compatibility on users */
1762: if (sqe_flags & ~SQE_VALID_FLAGS)
1763: return io_init_fail_req(req, -EINVAL);
1764: if (sqe_flags & IOSQE_BUFFER_SELECT) {
1765: if (!def->buffer_select)
1766: return io_init_fail_req(req, -EOPNOTSUPP);
1767: req->buf_index = READ_ONCE(sqe->buf_group);
1768: }
1769: if (sqe_flags & IOSQE_CQE_SKIP_SUCCESS)
1770: ctx->drain_disabled = true;
1771: if (sqe_flags & IOSQE_IO_DRAIN) {
1772: if (ctx->drain_disabled)
1773: return io_init_fail_req(req, -EOPNOTSUPP);
1774: io_init_drain(ctx);
1775: }
1776: }
1777: if (unlikely(ctx->op_restricted || ctx->drain_active || ctx->drain_next)) {
1778: if (!io_check_restriction(ctx, req, sqe_flags))
1779: return io_init_fail_req(req, -EACCES);
1780: /* knock it to the slow queue path, will be drained there */
1781: if (ctx->drain_active)
1782: req->flags |= REQ_F_FORCE_ASYNC;
1783: /* if there is no link, we're at "next" request and need to drain */
1784: if (unlikely(ctx->drain_next) && !ctx->submit_state.link.head) {
1785: ctx->drain_next = false;
1786: ctx->drain_active = true;
1787: req->flags |= REQ_F_IO_DRAIN | REQ_F_FORCE_ASYNC;
1788: }
1789: }
1790:
1791: if (!def->ioprio && sqe->ioprio)
1792: return io_init_fail_req(req, -EINVAL);
1793: if (!def->iopoll && (ctx->flags & IORING_SETUP_IOPOLL))
1794: return io_init_fail_req(req, -EINVAL);
1795:
1796: if (def->needs_file) {
1797: struct io_submit_state *state = &ctx->submit_state;
1798:
1799: req->cqe.fd = READ_ONCE(sqe->fd);
1800:
1801: /*
1802: * Plug now if we have more than 2 IO left after this, and the
1803: * target is potentially a read/write to block based storage.
1804: */
1805: if (state->need_plug && def->plug) {
1806: state->plug_started = true;
1807: state->need_plug = false;
1808: blk_start_plug_nr_ios(&state->plug, state->submit_nr);
1809: }
1810: }
1811:
1812: personality = READ_ONCE(sqe->personality);
1813: if (personality) {
1814: int ret;
1815:
1816: req->creds = xa_load(&ctx->personalities, personality);
1817: if (!req->creds)
1818: return io_init_fail_req(req, -EINVAL);
1819: get_cred(req->creds);
1820: ret = security_uring_override_creds(req->creds);
1821: if (ret) {
1822: put_cred(req->creds);
1823: return io_init_fail_req(req, ret);
1824: }
1825: req->flags |= REQ_F_CREDS;
1826: }
1827:
1828: return def->prep(req, sqe);
1829: }
SourceFile:io_uring/io_uring.c]
|
| 9/2 |
2026/02/23 15:40 |
llm |
expert |
0m
Model:
Tokens:
input: 7608
output: 38
thoughts: 114
Thoughts: **Analyzing the IOSQE_CQE_SKIP_SUCCESS Flag**
Okay, so I'm looking at this `io_init_req` function and specifically lines 1769 and 1770. It looks like the `IOSQE_CQE_SKIP_SUCCESS` flag in `sqe_flags` triggers a write to `ctx->drain_disabled`. Hmm, interesting. The report shows a write to the memory address `0xffff8881438eb004` of 2 bytes. This makes me want to immediately confirm the size and type of the `drain_disabled` field within the `io_ring_ctx` structure. Is it a boolean, a short, or something else? Understanding the data type will be crucial in interpreting the implications of this flag and potential side effects in this context. I need to make sure I understand this variable's role.
|
| 10/2 |
2026/02/23 15:40 |
tool |
codesearch-struct-layout |
0m
Args: map[ContextFile:io_uring/io_uring.c Name:io_ring_ctx]
Results: map[Fields:[map[Name: OffsetBits:0 SizeBits:512] map[Name: OffsetBits:512 SizeBits:3584] map[Name: OffsetBits:4096 SizeBits:512] map[Name: OffsetBits:4608 SizeBits:512] map[Name: OffsetBits:5120 SizeBits:512] map[Name:completion_lock OffsetBits:5632 SizeBits:32] map[Name:cq_overflow_list OffsetBits:5696 SizeBits:128] map[Name:waitid_list OffsetBits:5824 SizeBits:64] map[Name:futex_list OffsetBits:5888 SizeBits:64] map[Name:futex_cache OffsetBits:5952 SizeBits:192] map[Name:sq_creds OffsetBits:6144 SizeBits:64] map[Name:sq_data OffsetBits:6208 SizeBits:64] map[Name:sqo_sq_wait OffsetBits:6272 SizeBits:192] map[Name:sqd_list OffsetBits:6464 SizeBits:128] map[Name:file_alloc_start OffsetBits:6592 SizeBits:32] map[Name:file_alloc_end OffsetBits:6624 SizeBits:32] map[Name:poll_wq OffsetBits:6656 SizeBits:192] map[Name:restrictions OffsetBits:6848 SizeBits:320] map[Name:zcrx_ctxs OffsetBits:7168 SizeBits:128] map[Name:pers_next OffsetBits:7296 SizeBits:32] map[Name:personalities OffsetBits:7360 SizeBits:128] map[Name:hash_map OffsetBits:7488 SizeBits:64] map[Name:user OffsetBits:7552 SizeBits:64] map[Name:mm_account OffsetBits:7616 SizeBits:64] map[Name:tctx_list OffsetBits:7680 SizeBits:128] map[Name:tctx_lock OffsetBits:7808 SizeBits:256] map[Name:fallback_llist OffsetBits:8064 SizeBits:64] map[Name:fallback_work OffsetBits:8128 SizeBits:704] map[Name:exit_work OffsetBits:8832 SizeBits:256] map[Name:ref_comp OffsetBits:9088 SizeBits:256] map[Name:iowq_limits OffsetBits:9344 SizeBits:64] map[Name:poll_wq_task_work OffsetBits:9408 SizeBits:128] map[Name:defer_list OffsetBits:9536 SizeBits:128] map[Name:nr_drained OffsetBits:9664 SizeBits:32] map[Name:nr_req_allocated OffsetBits:9696 SizeBits:32] map[Name:napi_list OffsetBits:9728 SizeBits:128] map[Name:napi_lock OffsetBits:9856 SizeBits:32] map[Name:napi_busy_poll_dt OffsetBits:9920 SizeBits:64] map[Name:napi_prefer_busy_poll OffsetBits:9984 SizeBits:8] map[Name:napi_track_mode OffsetBits:9992 SizeBits:8] map[Name:napi_ht OffsetBits:10048 SizeBits:1024] map[Name:mmap_lock OffsetBits:11072 SizeBits:256] map[Name:sq_region OffsetBits:11328 SizeBits:192] map[Name:ring_region OffsetBits:11520 SizeBits:192] map[Name:param_region OffsetBits:11712 SizeBits:192]]]
|
| 11/2 |
2026/02/23 15:40 |
llm |
expert |
0m
Model:
Tokens:
input: 9009
output: 43
thoughts: 47
Thoughts: **Investigating the `io_ring_ctx` Structure**
Okay, so I'm taking a look at the `io_ring_ctx` layout, and it's immediately apparent this structure is substantial. My immediate concern is that the output I'm seeing is either truncated or simply not displaying all the fields. I need to get a full picture here.
My goal now is to track down where the `drain_disabled` field is defined within the `struct io_ring_ctx`. Understanding its location and context within the structure is crucial for my analysis.
|
| 12/2 |
2026/02/23 15:40 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:io_uring/io_uring.c IncludeLines:true Name:io_ring_ctx]
Results: map[SourceCode: 271: struct io_ring_ctx {
272: /* const or read-mostly hot data */
273: struct {
274: unsigned int flags;
275: unsigned int drain_next: 1;
276: unsigned int op_restricted: 1;
277: unsigned int reg_restricted: 1;
278: unsigned int off_timeout_used: 1;
279: unsigned int drain_active: 1;
280: unsigned int has_evfd: 1;
281: /* all CQEs should be posted only by the submitter task */
282: unsigned int task_complete: 1;
283: unsigned int lockless_cq: 1;
284: unsigned int syscall_iopoll: 1;
285: unsigned int poll_activated: 1;
286: unsigned int drain_disabled: 1;
287: unsigned int compat: 1;
288: unsigned int iowq_limits_set : 1;
289:
290: struct task_struct *submitter_task;
291: struct io_rings *rings;
292: /* cache of ->restrictions.bpf_filters->filters */
293: struct io_bpf_filter __rcu **bpf_filters;
294: struct percpu_ref refs;
295:
296: clockid_t clockid;
297: enum tk_offsets clock_offset;
298:
299: enum task_work_notify_mode notify_method;
300: unsigned sq_thread_idle;
301: } ____cacheline_aligned_in_smp;
302:
303: /* submission data */
304: struct {
305: struct mutex uring_lock;
306:
307: /*
308: * Ring buffer of indices into array of io_uring_sqe, which is
309: * mmapped by the application using the IORING_OFF_SQES offset.
310: *
311: * This indirection could e.g. be used to assign fixed
312: * io_uring_sqe entries to operations and only submit them to
313: * the queue when needed.
314: *
315: * The kernel modifies neither the indices array nor the entries
316: * array.
317: */
318: u32 *sq_array;
319: struct io_uring_sqe *sq_sqes;
320: unsigned cached_sq_head;
321: unsigned sq_entries;
322:
323: /*
324: * Fixed resources fast path, should be accessed only under
325: * uring_lock, and updated through io_uring_register(2)
326: */
327: atomic_t cancel_seq;
328:
329: /*
330: * ->iopoll_list is protected by the ctx->uring_lock for
331: * io_uring instances that don't use IORING_SETUP_SQPOLL.
332: * For SQPOLL, only the single threaded io_sq_thread() will
333: * manipulate the list, hence no extra locking is needed there.
334: */
335: bool poll_multi_queue;
336: struct list_head iopoll_list;
337:
338: struct io_file_table file_table;
339: struct io_rsrc_data buf_table;
340: struct io_alloc_cache node_cache;
341: struct io_alloc_cache imu_cache;
342:
343: struct io_submit_state submit_state;
344:
345: /*
346: * Modifications are protected by ->uring_lock and ->mmap_lock.
347: * The buffer list's io mapped region should be stable once
348: * published.
349: */
350: struct xarray io_bl_xa;
351:
352: struct io_hash_table cancel_table;
353: struct io_alloc_cache apoll_cache;
354: struct io_alloc_cache netmsg_cache;
355: struct io_alloc_cache rw_cache;
356: struct io_alloc_cache cmd_cache;
357:
358: /*
359: * Any cancelable uring_cmd is added to this list in
360: * ->uring_cmd() by io_uring_cmd_insert_cancelable()
361: */
362: struct hlist_head cancelable_uring_cmd;
363: /*
364: * For Hybrid IOPOLL, runtime in hybrid polling, without
365: * scheduling time
366: */
367: u64 hybrid_poll_time;
368: } ____cacheline_aligned_in_smp;
369:
370: struct {
371: /*
372: * We cache a range of free CQEs we can use, once exhausted it
373: * should go through a slower range setup, see __io_get_cqe()
374: */
375: struct io_uring_cqe *cqe_cached;
376: struct io_uring_cqe *cqe_sentinel;
377:
378: unsigned cached_cq_tail;
379: unsigned cq_entries;
380: struct io_ev_fd __rcu *io_ev_fd;
381:
382: void *cq_wait_arg;
383: size_t cq_wait_size;
384: } ____cacheline_aligned_in_smp;
385:
386: /*
387: * task_work and async notification delivery cacheline. Expected to
388: * regularly bounce b/w CPUs.
389: */
390: struct {
391: struct llist_head work_llist;
392: struct llist_head retry_llist;
393: unsigned long check_cq;
394: atomic_t cq_wait_nr;
395: atomic_t cq_timeouts;
396: struct wait_queue_head cq_wait;
397: } ____cacheline_aligned_in_smp;
398:
399: /* timeouts */
400: struct {
401: raw_spinlock_t timeout_lock;
402: struct list_head timeout_list;
403: struct list_head ltimeout_list;
404: unsigned cq_last_tm_flush;
405: } ____cacheline_aligned_in_smp;
406:
407: spinlock_t completion_lock;
408:
409: struct list_head cq_overflow_list;
410:
411: struct hlist_head waitid_list;
412:
413: #ifdef CONFIG_FUTEX
414: struct hlist_head futex_list;
415: struct io_alloc_cache futex_cache;
416: #endif
417:
418: const struct cred *sq_creds; /* cred used for __io_sq_thread() */
419: struct io_sq_data *sq_data; /* if using sq thread polling */
420:
421: struct wait_queue_head sqo_sq_wait;
422: struct list_head sqd_list;
423:
424: unsigned int file_alloc_start;
425: unsigned int file_alloc_end;
426:
427: /* Keep this last, we don't need it for the fast path */
428: struct wait_queue_head poll_wq;
429: struct io_restriction restrictions;
430:
431: /* Stores zcrx object pointers of type struct io_zcrx_ifq */
432: struct xarray zcrx_ctxs;
433:
434: u32 pers_next;
435: struct xarray personalities;
436:
437: /* hashed buffered write serialization */
438: struct io_wq_hash *hash_map;
439:
440: /* Only used for accounting purposes */
441: struct user_struct *user;
442: struct mm_struct *mm_account;
443:
444: /*
445: * List of tctx nodes for this ctx, protected by tctx_lock. For
446: * cancelation purposes, nests under uring_lock.
447: */
448: struct list_head tctx_list;
449: struct mutex tctx_lock;
450:
451: /* ctx exit and cancelation */
452: struct llist_head fallback_llist;
453: struct delayed_work fallback_work;
454: struct work_struct exit_work;
455: struct completion ref_comp;
456:
457: /* io-wq management, e.g. thread count */
458: u32 iowq_limits[2];
459:
460: struct callback_head poll_wq_task_work;
461: struct list_head defer_list;
462: unsigned nr_drained;
463:
464: /* protected by ->completion_lock */
465: unsigned nr_req_allocated;
466:
467: #ifdef CONFIG_NET_RX_BUSY_POLL
468: struct list_head napi_list; /* track busy poll napi_id */
469: spinlock_t napi_lock; /* napi_list lock */
470:
471: /* napi busy poll default timeout */
472: ktime_t napi_busy_poll_dt;
473: bool napi_prefer_busy_poll;
474: u8 napi_track_mode;
475:
476: DECLARE_HASHTABLE(napi_ht, 4);
477: #endif
478:
479: /*
480: * Protection for resize vs mmap races - both the mmap and resize
481: * side will need to grab this lock, to prevent either side from
482: * being run concurrently with the other.
483: */
484: struct mutex mmap_lock;
485:
486: struct io_mapped_region sq_region;
487: struct io_mapped_region ring_region;
488: /* used for optimised request parameter and wait argument passing */
489: struct io_mapped_region param_region;
490: };
SourceFile:include/linux/io_uring_types.h]
|
| 13/2 |
2026/02/23 15:40 |
llm |
expert |
0m
Model:
Tokens:
input: 12491
output: 48
thoughts: 195
Thoughts: Okay, let me break this down.
**Investigating `drain_disabled` in `io_ring_ctx`**
Alright, the `codesearch-definition-source` search for `io_ring_ctx` pointed me to `include/linux/io_uring_types.h`, or at least that's where I *think* it's coming from. I should probably double-check that this wasn't inferred somehow. However, the search result explicitly mentioned `SourceFile: io_uring/io_uring.c`, though the snippet in the result does look like it could be from a header. No matter, I found it! Specifically, `drain_disabled` is at line 286. Yep, it's a bitfield:
```c
286: unsigned int drain_disabled: 1;
```
Interesting. I'm seeing the write to it as `ctx->drain_disabled = true;` on line 1770 of `io_uring/io_uring.c`.
Now, the next logical step is to understand how this flag is actually *used*. I'll need to look at the read operation, probably in `__do_sys_io_uring_enter` around line 2624. That should give me a good picture of its purpose within the context of the io_uring system call.
|
| 14/2 |
2026/02/23 15:41 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:io_uring/io_uring.c IncludeLines:true Name:__do_sys_io_uring_enter]
Results: map[SourceCode:2538: SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
2539: u32, min_complete, u32, flags, const void __user *, argp,
2540: size_t, argsz)
2541: {
2542: struct io_ring_ctx *ctx;
2543: struct file *file;
2544: long ret;
2545:
2546: if (unlikely(flags & ~IORING_ENTER_FLAGS))
2547: return -EINVAL;
2548:
2549: /*
2550: * Ring fd has been registered via IORING_REGISTER_RING_FDS, we
2551: * need only dereference our task private array to find it.
2552: */
2553: if (flags & IORING_ENTER_REGISTERED_RING) {
2554: struct io_uring_task *tctx = current->io_uring;
2555:
2556: if (unlikely(!tctx || fd >= IO_RINGFD_REG_MAX))
2557: return -EINVAL;
2558: fd = array_index_nospec(fd, IO_RINGFD_REG_MAX);
2559: file = tctx->registered_rings[fd];
2560: if (unlikely(!file))
2561: return -EBADF;
2562: } else {
2563: file = fget(fd);
2564: if (unlikely(!file))
2565: return -EBADF;
2566: ret = -EOPNOTSUPP;
2567: if (unlikely(!io_is_uring_fops(file)))
2568: goto out;
2569: }
2570:
2571: ctx = file->private_data;
2572: ret = -EBADFD;
2573: /*
2574: * Keep IORING_SETUP_R_DISABLED check before submitter_task load
2575: * in io_uring_add_tctx_node() -> __io_uring_add_tctx_node_from_submit()
2576: */
2577: if (unlikely(smp_load_acquire(&ctx->flags) & IORING_SETUP_R_DISABLED))
2578: goto out;
2579:
2580: /*
2581: * For SQ polling, the thread will do all submissions and completions.
2582: * Just return the requested submit count, and wake the thread if
2583: * we were asked to.
2584: */
2585: ret = 0;
2586: if (ctx->flags & IORING_SETUP_SQPOLL) {
2587: if (unlikely(ctx->sq_data->thread == NULL)) {
2588: ret = -EOWNERDEAD;
2589: goto out;
2590: }
2591: if (flags & IORING_ENTER_SQ_WAKEUP)
2592: wake_up(&ctx->sq_data->wait);
2593: if (flags & IORING_ENTER_SQ_WAIT)
2594: io_sqpoll_wait_sq(ctx);
2595:
2596: ret = to_submit;
2597: } else if (to_submit) {
2598: ret = io_uring_add_tctx_node(ctx);
2599: if (unlikely(ret))
2600: goto out;
2601:
2602: mutex_lock(&ctx->uring_lock);
2603: ret = io_submit_sqes(ctx, to_submit);
2604: if (ret != to_submit) {
2605: mutex_unlock(&ctx->uring_lock);
2606: goto out;
2607: }
2608: if (flags & IORING_ENTER_GETEVENTS) {
2609: if (ctx->syscall_iopoll)
2610: goto iopoll_locked;
2611: /*
2612: * Ignore errors, we'll soon call io_cqring_wait() and
2613: * it should handle ownership problems if any.
2614: */
2615: if (ctx->flags & IORING_SETUP_DEFER_TASKRUN)
2616: (void)io_run_local_work_locked(ctx, min_complete);
2617: }
2618: mutex_unlock(&ctx->uring_lock);
2619: }
2620:
2621: if (flags & IORING_ENTER_GETEVENTS) {
2622: int ret2;
2623:
2624: if (ctx->syscall_iopoll) {
2625: /*
2626: * We disallow the app entering submit/complete with
2627: * polling, but we still need to lock the ring to
2628: * prevent racing with polled issue that got punted to
2629: * a workqueue.
2630: */
2631: mutex_lock(&ctx->uring_lock);
2632: iopoll_locked:
2633: ret2 = io_validate_ext_arg(ctx, flags, argp, argsz);
2634: if (likely(!ret2))
2635: ret2 = io_iopoll_check(ctx, min_complete);
2636: mutex_unlock(&ctx->uring_lock);
2637: } else {
2638: struct ext_arg ext_arg = { .argsz = argsz };
2639:
2640: ret2 = io_get_ext_arg(ctx, flags, argp, &ext_arg);
2641: if (likely(!ret2))
2642: ret2 = io_cqring_wait(ctx, min_complete, flags,
2643: &ext_arg);
2644: }
2645:
2646: if (!ret) {
2647: ret = ret2;
2648:
2649: /*
2650: * EBADR indicates that one or more CQE were dropped.
2651: * Once the user has been informed we can clear the bit
2652: * as they are obviously ok with those drops.
2653: */
2654: if (unlikely(ret2 == -EBADR))
2655: clear_bit(IO_CHECK_CQ_DROPPED_BIT,
2656: &ctx->check_cq);
2657: }
2658: }
2659: out:
2660: if (!(flags & IORING_ENTER_REGISTERED_RING))
2661: fput(file);
2662: return ret;
2663: }
SourceFile:io_uring/io_uring.c]
|
| 15/2 |
2026/02/23 15:41 |
llm |
expert |
0m
Model:
Tokens:
input: 14978
output: 28
thoughts: 771
Thoughts: **Analyzing a Potential Data Race in io_uring**
Okay, I'm looking at this KCSAN report, and I'm immediately noticing something interesting in the `io_uring` code. The report highlights a potential data race between a read of `syscall_iopoll` (at line 2624) and a write to `drain_disabled` (at line 1770) within the `io_ring_ctx` structure. The stack trace clearly shows the conflicting accesses occurring within `__do_sys_io_uring_enter` and `__se_sys_io_uring_enter`.
My initial thought is that I don't see `drain_disabled` being directly *read* at line 2624, which, according to the report, is the location where `syscall_iopoll` is checked. The crucial point here is the bitfield packing within `io_ring_ctx`. I know that because `syscall_iopoll` and `drain_disabled` are both bitfields within the same `unsigned int`, writes to one *could* affect reads from the other, depending on how the compiler generates the code.
The report indicates a read of 2 bytes from address `0xffff8881438eb004` which, in the context of the bitfields, is highly suspect. Reading `syscall_iopoll` involves reading the whole `unsigned int` containing it, and likely reading the byte or half word containing it.. The write to `drain_disabled` is at 1770: `ctx->drain_disabled = true;`, so I think I see a read/write race condition happening.
Specifically, the write to `drain_disabled` is `ctx->drain_disabled = true;`. If the compiler is doing a read-modify-write for the bitfield, it's reading the *entire* `unsigned int` value, then setting bit 11 (or thereabouts) and rewriting the whole word. The read at line 2624, is `if (ctx->syscall_iopoll) {`, which is checking bit 9 of the same variable. This means a concurrent write could interfere with this read.
My concern is whether this race is *actually* harmful. I know that `syscall_iopoll` is likely set during initialization. But, if `drain_disabled` is being changed concurrently, the read-modify-write could overwrite the bit containing `syscall_iopoll`. I need to verify whether `syscall_iopoll` is ever written to after initialization, just to be sure. It could be harmless. I should check where `syscall_iopoll` is written, just in case.
|
| 16/2 |
2026/02/23 15:41 |
tool |
codesearch-find-references |
0m
Args: map[Name:io_ring_ctx::syscall_iopoll]
Results: map[References:<nil> TruncatedOutput:false]
|
| 17/2 |
2026/02/23 15:41 |
llm |
expert |
0m
Model:
Tokens:
input: 16371
output: 18
thoughts: 57
Thoughts: Okay, let's see...
**Investigating a Potentially Missing Reference**
Hmm, I was expecting `codesearch-find-references` to turn something up for `io_ring_ctx::syscall_iopoll`, but it came back empty. That's odd. Could it be a bitfield definition? Perhaps I used the wrong search syntax, or the tooling just isn't handling this particular case well. Okay, let's back up and try a more broad approach. I'll fire up a `grep` for just `syscall_iopoll`. That should catch anything, regardless of how it's declared or used. It's a slightly blunter instrument, but should uncover any instances of that symbol.
|
| 18/2 |
2026/02/23 15:41 |
tool |
grepper |
0m
Args: map[Expression:syscall_iopoll]
Results: map[Output:include/linux/io_uring_types.h=271=struct io_ring_ctx {
--
include/linux/io_uring_types.h-283- unsigned int lockless_cq: 1;
include/linux/io_uring_types.h:284: unsigned int syscall_iopoll: 1;
include/linux/io_uring_types.h-285- unsigned int poll_activated: 1;
--
io_uring/io_uring.c=500=static inline void __io_cq_unlock_post(struct io_ring_ctx *ctx)
--
io_uring/io_uring.c-506- /* IOPOLL rings only need to wake up if it's also SQPOLL */
io_uring/io_uring.c:507: if (!ctx->syscall_iopoll)
io_uring/io_uring.c-508- io_cqring_wake(ctx);
--
io_uring/io_uring.c=2538=SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
--
io_uring/io_uring.c-2608- if (flags & IORING_ENTER_GETEVENTS) {
io_uring/io_uring.c:2609: if (ctx->syscall_iopoll)
io_uring/io_uring.c-2610- goto iopoll_locked;
--
io_uring/io_uring.c-2623-
io_uring/io_uring.c:2624: if (ctx->syscall_iopoll) {
io_uring/io_uring.c-2625- /*
--
io_uring/io_uring.c=2929=static __cold int io_uring_create(struct io_ctx_config *config)
--
io_uring/io_uring.c-2972- !(ctx->flags & IORING_SETUP_SQPOLL))
io_uring/io_uring.c:2973: ctx->syscall_iopoll = 1;
io_uring/io_uring.c-2974-
]
|
| 19/2 |
2026/02/23 15:41 |
llm |
expert |
0m
Model:
Tokens:
input: 17153
output: 17
thoughts: 60
Thoughts: **Analyzing the io_uring Context Initialization**
Okay, so I'm looking at the `io_uring_create` function, specifically how the context (`ctx`) is initialized. I see that the `syscall_iopoll` flag is being set to 1 right here:
```c
2973: ctx->syscall_iopoll = 1;
```
Interesting... It seems this is done only during the context's creation, at least judging from this snippet. This initial assignment provides a crucial setup for later operations within the io_uring system.
Now, I need to understand what this flag actually *means* and how it impacts the overall behavior. My next step is to examine the code that utilizes this `syscall_iopoll` flag. Specifically, I need to check the state of `drain_disabled`. Understanding the role of `drain_disabled` will help clarify the function of `syscall_iopoll`.
|
| 20/2 |
2026/02/23 15:41 |
tool |
grepper |
0m
Args: map[Expression:drain_disabled]
Results: map[Output:include/linux/io_uring_types.h=271=struct io_ring_ctx {
--
include/linux/io_uring_types.h-285- unsigned int poll_activated: 1;
include/linux/io_uring_types.h:286: unsigned int drain_disabled: 1;
include/linux/io_uring_types.h-287- unsigned int compat: 1;
--
io_uring/io_uring.c=1715=static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
--
io_uring/io_uring.c-1769- if (sqe_flags & IOSQE_CQE_SKIP_SUCCESS)
io_uring/io_uring.c:1770: ctx->drain_disabled = true;
io_uring/io_uring.c-1771- if (sqe_flags & IOSQE_IO_DRAIN) {
io_uring/io_uring.c:1772: if (ctx->drain_disabled)
io_uring/io_uring.c-1773- return io_init_fail_req(req, -EOPNOTSUPP);
]
|
| 21/2 |
2026/02/23 15:41 |
llm |
expert |
0m
Model:
Tokens:
input: 17745
output: 21
thoughts: 79
Thoughts: Okay, let me think this through.
**Analyzing the `drain_disabled` Flag in io_uring Initialization**
Right, so I'm looking at this `drain_disabled` variable, and it's being set within the `io_init_req` function. It seems the key trigger is the `IOSQE_CQE_SKIP_SUCCESS` flag being present on a request. Hmm, so that suggests this flag is tied to requests that don't need a completion queue entry for successful operations.
But here's where it gets interesting β and potentially problematic. If *multiple* requests are submitted with this `IOSQE_CQE_SKIP_SUCCESS` flag, the code sets `ctx->drain_disabled = true` for *each* of them. Fair enough, that seems expected. However, and here's the red flag that's buzzing in my mind... is it *ever* reset back to `false`? I need to check the code very carefully. It seems that if it's set to true, it's just... stuck there, potentially indefinitely. That's not the usual practice, that's not how these things are handled, normally there's a corresponding reset. I need to dig deeper into the codebase to confirm if there's a mechanism to revert this condition. I need to verify that there isn't a possible resource leak here.
|
| 22/2 |
2026/02/23 15:41 |
tool |
grepper |
0m
Error:
Args: map[Expression:drain_disabled.*=.*false]
Results:
|
| 23/2 |
2026/02/23 15:41 |
llm |
expert |
0m
Model:
Tokens:
input: 18152
output: 17
thoughts: 417
Thoughts: **Analyzing Potential Race Conditions with Bitfields**
Okay, so I'm looking at this code and it seems like `drain_disabled` is only ever set to `true`. My initial thought is that there's a race condition between a write to `ctx->drain_disabled` (setting it to `true`) and a read in an `if (ctx->syscall_iopoll)` statement. Since they're bitfields within the same word in memory, the write operation is actually a read-modify-write.
If `syscall_iopoll` itself were being changed concurrently, I'd have a serious problem. However, I believe `syscall_iopoll` is initialized at creation and doesn't change after that point. So, that's good. But I need to be more thorough here.
Hold on... are there *other* bitfields in that same word that *could* be changing? Let me quickly scan that struct definition... aha! There are several other bitfields. I see `drain_next` and `drain_active` β those are the two that jump out at me as potentially problematic. They seem like they might be modified elsewhere. Let's dig deeper and specifically check `drain_next` for now.
|
| 24/2 |
2026/02/23 15:41 |
tool |
grepper |
0m
Args: map[Expression:drain_next]
Results: map[Output:include/linux/io_uring_types.h=271=struct io_ring_ctx {
--
include/linux/io_uring_types.h-274- unsigned int flags;
include/linux/io_uring_types.h:275: unsigned int drain_next: 1;
include/linux/io_uring_types.h-276- unsigned int op_restricted: 1;
--
io_uring/io_uring.c=1690=static void io_init_drain(struct io_ring_ctx *ctx)
--
io_uring/io_uring.c-1703- head->flags |= REQ_F_IO_DRAIN | REQ_F_FORCE_ASYNC;
io_uring/io_uring.c:1704: ctx->drain_next = true;
io_uring/io_uring.c-1705- }
--
io_uring/io_uring.c=1715=static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
--
io_uring/io_uring.c-1776- }
io_uring/io_uring.c:1777: if (unlikely(ctx->op_restricted || ctx->drain_active || ctx->drain_next)) {
io_uring/io_uring.c-1778- if (!io_check_restriction(ctx, req, sqe_flags))
--
io_uring/io_uring.c-1783- /* if there is no link, we're at "next" request and need to drain */
io_uring/io_uring.c:1784: if (unlikely(ctx->drain_next) && !ctx->submit_state.link.head) {
io_uring/io_uring.c:1785: ctx->drain_next = false;
io_uring/io_uring.c-1786- ctx->drain_active = true;
]
|
| 25/2 |
2026/02/23 15:41 |
llm |
expert |
0m
Model:
Tokens:
input: 19354
output: 42
thoughts: 131
Thoughts: **Analyzing the IO_URING Lock and Write Path**
Okay, so I'm digging into this IO_URING code and I've noticed a crucial detail about `drain_next` and `drain_active`. It looks like these variables are also modified within `io_init_req`. This is immediately interesting because `io_init_req` is, as I recall, called while holding the `uring_lock`.
Now, looking at the write stack trace: `io_submit_sqes` calls `io_submit_sqe`, which then calls `io_init_req`. So far, so good, this makes sense. The real question that's bugging me is where `io_submit_sqes` comes from. It's called from `__io_sq_thread`.
The critical question here is whether or not `__io_sq_thread` holds the `uring_lock` when it calls `io_submit_sqes`. This is the potential race condition I'm concerned about. If it doesn't, we have a problem. If it does, things might be alright, depending on how that lock is held.
Time to consult the source. Let's head over to `io_uring/sqpoll.c` and check out the `io_sq_thread` function to confirm whether the lock is held in that context. This is going to be key to understanding the thread safety of this write path.
|
| 26/2 |
2026/02/23 15:41 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:io_uring/sqpoll.c IncludeLines:true Name:io_sq_thread]
Results: map[SourceCode: 293: static int io_sq_thread(void *data)
294: {
295: struct llist_node *retry_list = NULL;
296: struct io_sq_data *sqd = data;
297: struct io_ring_ctx *ctx;
298: unsigned long timeout = 0;
299: char buf[TASK_COMM_LEN] = {};
300: DEFINE_WAIT(wait);
301:
302: /* offload context creation failed, just exit */
303: if (!current->io_uring) {
304: mutex_lock(&sqd->lock);
305: rcu_assign_pointer(sqd->thread, NULL);
306: put_task_struct(current);
307: mutex_unlock(&sqd->lock);
308: goto err_out;
309: }
310:
311: snprintf(buf, sizeof(buf), "iou-sqp-%d", sqd->task_pid);
312: set_task_comm(current, buf);
313:
314: /* reset to our pid after we've set task_comm, for fdinfo */
315: sqd->task_pid = current->pid;
316:
317: if (sqd->sq_cpu != -1) {
318: set_cpus_allowed_ptr(current, cpumask_of(sqd->sq_cpu));
319: } else {
320: set_cpus_allowed_ptr(current, cpu_online_mask);
321: sqd->sq_cpu = raw_smp_processor_id();
322: }
323:
324: /*
325: * Force audit context to get setup, in case we do prep side async
326: * operations that would trigger an audit call before any issue side
327: * audit has been done.
328: */
329: audit_uring_entry(IORING_OP_NOP);
330: audit_uring_exit(true, 0);
331:
332: mutex_lock(&sqd->lock);
333: while (1) {
334: bool cap_entries, sqt_spin = false;
335: struct io_sq_time ist = { };
336:
337: if (io_sqd_events_pending(sqd) || signal_pending(current)) {
338: if (io_sqd_handle_event(sqd))
339: break;
340: timeout = jiffies + sqd->sq_thread_idle;
341: }
342:
343: cap_entries = !list_is_singular(&sqd->ctx_list);
344: list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) {
345: int ret = __io_sq_thread(ctx, sqd, cap_entries, &ist);
346:
347: if (!sqt_spin && (ret > 0 || !list_empty(&ctx->iopoll_list)))
348: sqt_spin = true;
349: }
350: if (io_sq_tw(&retry_list, IORING_TW_CAP_ENTRIES_VALUE))
351: sqt_spin = true;
352:
353: list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) {
354: if (io_napi(ctx)) {
355: io_sq_start_worktime(&ist);
356: io_napi_sqpoll_busy_poll(ctx);
357: }
358: }
359:
360: io_sq_update_worktime(sqd, &ist);
361:
362: if (sqt_spin || !time_after(jiffies, timeout)) {
363: if (sqt_spin)
364: timeout = jiffies + sqd->sq_thread_idle;
365: if (unlikely(need_resched())) {
366: mutex_unlock(&sqd->lock);
367: cond_resched();
368: mutex_lock(&sqd->lock);
369: sqd->sq_cpu = raw_smp_processor_id();
370: }
371: continue;
372: }
373:
374: prepare_to_wait(&sqd->wait, &wait, TASK_INTERRUPTIBLE);
375: if (!io_sqd_events_pending(sqd) && !io_sq_tw_pending(retry_list)) {
376: bool needs_sched = true;
377:
378: list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) {
379: atomic_or(IORING_SQ_NEED_WAKEUP,
380: &ctx->rings->sq_flags);
381: if ((ctx->flags & IORING_SETUP_IOPOLL) &&
382: !list_empty(&ctx->iopoll_list)) {
383: needs_sched = false;
384: break;
385: }
386:
387: /*
388: * Ensure the store of the wakeup flag is not
389: * reordered with the load of the SQ tail
390: */
391: smp_mb__after_atomic();
392:
393: if (io_sqring_entries(ctx)) {
394: needs_sched = false;
395: break;
396: }
397: }
398:
399: if (needs_sched) {
400: mutex_unlock(&sqd->lock);
401: schedule();
402: mutex_lock(&sqd->lock);
403: sqd->sq_cpu = raw_smp_processor_id();
404: }
405: list_for_each_entry(ctx, &sqd->ctx_list, sqd_list)
406: atomic_andnot(IORING_SQ_NEED_WAKEUP,
407: &ctx->rings->sq_flags);
408: }
409:
410: finish_wait(&sqd->wait, &wait);
411: timeout = jiffies + sqd->sq_thread_idle;
412: }
413:
414: if (retry_list)
415: io_sq_tw(&retry_list, UINT_MAX);
416:
417: io_uring_cancel_generic(true, sqd);
418: rcu_assign_pointer(sqd->thread, NULL);
419: put_task_struct(current);
420: list_for_each_entry(ctx, &sqd->ctx_list, sqd_list)
421: atomic_or(IORING_SQ_NEED_WAKEUP, &ctx->rings->sq_flags);
422: io_run_task_work();
423: mutex_unlock(&sqd->lock);
424: err_out:
425: complete(&sqd->exited);
426: do_exit(0);
427: }
SourceFile:io_uring/sqpoll.c]
|
| 27/2 |
2026/02/23 15:41 |
llm |
expert |
0m
Model:
Tokens:
input: 21989
output: 43
thoughts: 28
Thoughts: Here's my summary, as the thought process unfolds:
**Digging into the I/O Submission Queue Thread**
Okay, so the `io_sq_thread` function is the one that kicks off the whole I/O submission process. Let's start by seeing where it leads. The code's telling me it's calling `__io_sq_thread`. That's the next logical step. Right, I need to get a better handle on what `__io_sq_thread` is doing specifically to see how the I/O submission pipeline is set up, what data it's processing, and if any critical section is in place. Time to dive into the definition of `__io_sq_thread`.
|
| 28/2 |
2026/02/23 15:41 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:io_uring/sqpoll.c IncludeLines:true Name:__io_sq_thread]
Results: map[SourceCode: 204: static int __io_sq_thread(struct io_ring_ctx *ctx, struct io_sq_data *sqd,
205: bool cap_entries, struct io_sq_time *ist)
206: {
207: unsigned int to_submit;
208: int ret = 0;
209:
210: to_submit = io_sqring_entries(ctx);
211: /* if we're handling multiple rings, cap submit size for fairness */
212: if (cap_entries && to_submit > IORING_SQPOLL_CAP_ENTRIES_VALUE)
213: to_submit = IORING_SQPOLL_CAP_ENTRIES_VALUE;
214:
215: if (to_submit || !list_empty(&ctx->iopoll_list)) {
216: const struct cred *creds = NULL;
217:
218: io_sq_start_worktime(ist);
219:
220: if (ctx->sq_creds != current_cred())
221: creds = override_creds(ctx->sq_creds);
222:
223: mutex_lock(&ctx->uring_lock);
224: if (!list_empty(&ctx->iopoll_list))
225: io_do_iopoll(ctx, true);
226:
227: /*
228: * Don't submit if refs are dying, good for io_uring_register(),
229: * but also it is relied upon by io_ring_exit_work()
230: */
231: if (to_submit && likely(!percpu_ref_is_dying(&ctx->refs)) &&
232: !(ctx->flags & IORING_SETUP_R_DISABLED))
233: ret = io_submit_sqes(ctx, to_submit);
234: mutex_unlock(&ctx->uring_lock);
235:
236: if (to_submit && wq_has_sleeper(&ctx->sqo_sq_wait))
237: wake_up(&ctx->sqo_sq_wait);
238: if (creds)
239: revert_creds(creds);
240: }
241:
242: return ret;
243: }
SourceFile:io_uring/sqpoll.c]
|
| 29/2 |
2026/02/23 15:41 |
llm |
expert |
0m
Model:
Tokens:
input: 22910
output: 17
thoughts: 1182
Thoughts: **Data Race Analysis in io_uring with SQPOLL**
Okay, so I've been tracing the execution flow and I've zeroed in on a potential data race within the io_uring subsystem, specifically when SQPOLL is enabled. Let me break down my thinking step-by-step.
First, I confirmed that `__io_sq_thread` holds the `ctx->uring_lock` when calling `io_submit_sqes`. That's standard practice, protecting shared data.
Now, I'm focusing on `io_uring_enter`. I've noticed something interesting. When `IORING_SETUP_SQPOLL` is set, `io_uring_enter` *doesn't* acquire `uring_lock` before reading `ctx->syscall_iopoll` at line 2624 of the code. That's unusual and warrants a closer look.
Hang on... if `IORING_SETUP_SQPOLL` is enabled, then `ctx->syscall_iopoll` is definitely *not* set. Let's confirm that in `io_uring_create`:
```c
!(ctx->flags & IORING_SETUP_SQPOLL)
ctx->syscall_iopoll = 1;
```
Right, if `SQPOLL` is on, `syscall_iopoll` is 0; if `SQPOLL` is off, `syscall_iopoll` is 1.
The report mentions a write from `io_sq_thread`. If that's the case, then `SQPOLL` *is* enabled. This means `ctx->syscall_iopoll` should be 0. So, we're looking at a read:
```c
if (ctx->syscall_iopoll) {
```
in `io_uring_enter`. And, given `SQPOLL` is on, this is within the `if (ctx->flags & IORING_SETUP_SQPOLL)` block at line 2586. No lock is taken, and then it reads `ctx->syscall_iopoll`.
Here's the problem: The write is happening in `io_sq_thread` which, of course, runs because `SQPOLL` is enabled. This write is to `ctx->drain_disabled`, and that variable is in the same *word* as `ctx->syscall_iopoll`. So, we have a clear race condition:
* **Thread 1 (SQPOLL thread):** `ctx->drain_disabled = true;` (under `uring_lock`)
* **Thread 2 (User thread in `io_uring_enter`):** `if (ctx->syscall_iopoll)` (NO `uring_lock`)
Since `drain_disabled` and `syscall_iopoll` are bitfields *within* the same word, this screams data race. But, is it harmful?
The write to `drain_disabled` is a read-modify-write operation. The read of `syscall_iopoll` is just a read. Since `syscall_iopoll` is never modified after context creation, the read will always see the same value UNLESS the read-modify-write somehow corrupts it.
A read-modify-write on one bit *shouldn't* affect other bits, but if the compiler uses a *non-atomic* read-modify-write and another thread is also doing a RMW on the *same* word, we have a big problem. But, in this case, Thread 2 is *only reading*. If the read is non-atomic, it will see either the old or the new value, but the `syscall_iopoll` bit should stay the same (0 in our scenario).
Wait... what if Thread 2 *was* also writing to *another* bitfield in the same word? Let's check `io_uring_enter` to see if it writes to any other bitfields in that word without the `uring_lock`.
In `io_uring_enter` I've found it reads `ctx->flags` and `ctx->syscall_iopoll`, and reads `ctx->flags` again. It doesn't appear to be writing to *any* bitfields in that struct without a lock.
Oh wait! What about `poll_activated`?
```c
unsigned int poll_activated: 1;
```
I need to see where `poll_activated` is being modified.
|
| 30/2 |
2026/02/23 15:42 |
tool |
grepper |
0m
Args: map[Expression:poll_activated]
Results: map[Output:include/linux/io_uring_types.h=271=struct io_ring_ctx {
--
include/linux/io_uring_types.h-284- unsigned int syscall_iopoll: 1;
include/linux/io_uring_types.h:285: unsigned int poll_activated: 1;
include/linux/io_uring_types.h-286- unsigned int drain_disabled: 1;
--
io_uring/io_uring.c=478=void __io_commit_cqring_flush(struct io_ring_ctx *ctx)
io_uring/io_uring.c-479-{
io_uring/io_uring.c:480: if (ctx->poll_activated)
io_uring/io_uring.c-481- io_poll_wq_wake(ctx);
--
io_uring/io_uring.c=2200=static __cold void io_activate_pollwq_cb(struct callback_head *cb)
--
io_uring/io_uring.c-2205- mutex_lock(&ctx->uring_lock);
io_uring/io_uring.c:2206: ctx->poll_activated = true;
io_uring/io_uring.c-2207- mutex_unlock(&ctx->uring_lock);
--
io_uring/io_uring.c=2217=__cold void io_activate_pollwq(struct io_ring_ctx *ctx)
--
io_uring/io_uring.c-2220- /* already activated or in progress */
io_uring/io_uring.c:2221: if (ctx->poll_activated || ctx->poll_wq_task_work.func)
io_uring/io_uring.c-2222- goto out;
--
io_uring/io_uring.c=2239=static __poll_t io_uring_poll(struct file *file, poll_table *wait)
--
io_uring/io_uring.c-2243-
io_uring/io_uring.c:2244: if (unlikely(!ctx->poll_activated))
io_uring/io_uring.c-2245- io_activate_pollwq(ctx);
--
io_uring/io_uring.c=2929=static __cold int io_uring_create(struct io_ctx_config *config)
--
io_uring/io_uring.c-2962- if (!ctx->task_complete)
io_uring/io_uring.c:2963: ctx->poll_activated = true;
io_uring/io_uring.c-2964-
--
io_uring/io_uring.h=473=static inline void io_commit_cqring_flush(struct io_ring_ctx *ctx)
--
io_uring/io_uring.h-475- if (unlikely(ctx->off_timeout_used ||
io_uring/io_uring.h:476: ctx->has_evfd || ctx->poll_activated))
io_uring/io_uring.h-477- __io_commit_cqring_flush(ctx);
]
|
| 31/2 |
2026/02/23 15:42 |
llm |
expert |
0m
Model:
Tokens:
input: 25882
output: 19
thoughts: 801
Thoughts: **Analyzing Potential Race Conditions in io_uring Bitfield Access**
Okay, let's break this down. My initial observation is that the `poll_activated` flag within the `io_ring_ctx` is modified in multiple places: `io_activate_pollwq_cb` and `io_uring_create`. I also see it's accessed via `io_uring_poll`, which calls `io_activate_pollwq` if it's not already set. `io_activate_pollwq` itself then does a double-check on `ctx->poll_activated` and queues a task work if needed. `io_activate_pollwq_cb` is where the crucial write to `ctx->poll_activated = true` actually happens, and that write is definitely protected by `uring_lock`.
The crux of the matter is bitfields. I'm reminded of the classic bitfield race condition example:
```c
struct {
int a:1;
int b:1;
} x;
```
Where concurrent writes to `x.a` and `x.b` by different threads can result in data corruption because they are RMW operations on the same word. In this case, we have several bitfields. Itβs absolutely critical that all writes to these bitfields be synchronized.
I know that `io_init_req` is called under `uring_lock`, and that `io_activate_pollwq_cb` *is* also under `uring_lock`, but `io_uring_create` is at initialization time, so I'm not worried about that.
I'm thinking now about how `io_submit_sqes` fits into the picture. Let's see... `io_init_req` is called from `io_submit_sqes`. And, in `io_uring_enter`, `io_submit_sqes` *is* called under `uring_lock` if `SQPOLL` is *not* set. If `SQPOLL` *is* set, then `io_submit_sqes` is called from the SQPOLL thread, *but still* under `uring_lock`. So, at first glance, *all* the bitfield writes I've seen appear to be protected.
However, I need to double-check that this conclusion is sound. Let's make sure, what about `drain_next` and `drain_active`? They are modified in `io_init_req` and `io_init_drain`, which are both called from `io_submit_sqes` and that one is under the `uring_lock`, so it seems safe.
But I still need to be thorough. I need to make sure I haven't missed any. Okay, what about `off_timeout_used`?
```c
278: unsigned int off_timeout_used: 1;
```
Right, I need to track down all the instances of *that* bitfield and verify its protection as well. The analysis isn't done yet, but so far things are looking good, it appears that `uring_lock` is providing the necessary synchronization.
|
| 32/2 |
2026/02/23 15:42 |
tool |
grepper |
0m
Args: map[Expression:off_timeout_used]
Results: map[Output:include/linux/io_uring_types.h=271=struct io_ring_ctx {
--
include/linux/io_uring_types.h-277- unsigned int reg_restricted: 1;
include/linux/io_uring_types.h:278: unsigned int off_timeout_used: 1;
include/linux/io_uring_types.h-279- unsigned int drain_active: 1;
--
io_uring/io_uring.c=478=void __io_commit_cqring_flush(struct io_ring_ctx *ctx)
--
io_uring/io_uring.c-481- io_poll_wq_wake(ctx);
io_uring/io_uring.c:482: if (ctx->off_timeout_used)
io_uring/io_uring.c-483- io_flush_timeouts(ctx);
--
io_uring/io_uring.h=473=static inline void io_commit_cqring_flush(struct io_ring_ctx *ctx)
io_uring/io_uring.h-474-{
io_uring/io_uring.h:475: if (unlikely(ctx->off_timeout_used ||
io_uring/io_uring.h-476- ctx->has_evfd || ctx->poll_activated))
--
io_uring/timeout.c=515=static int __io_timeout_prep(struct io_kiocb *req,
--
io_uring/timeout.c-541- timeout->off = off;
io_uring/timeout.c:542: if (unlikely(off && !req->ctx->off_timeout_used))
io_uring/timeout.c:543: req->ctx->off_timeout_used = true;
io_uring/timeout.c-544- /*
]
|
| 33/2 |
2026/02/23 15:42 |
llm |
expert |
0m
Model:
Tokens:
input: 27870
output: 21
thoughts: 6287
Thoughts: **Analysis of Data Race in io_uring Bitfields**
Okay, so I'm looking at a KCSAN report flagging a data race in `io_uring` code, specifically around bitfields within the `io_ring_ctx` structure. The race involves a write to `ctx->drain_disabled` (and `off_timeout_used`), which is protected by `uring_lock`, and a read of `ctx->syscall_iopoll`, which isn't.
My initial thought is that if all writers are under the lock, shouldn't there be no race *between* writers? That's correct, but the race is between a writer (holding the lock) and a reader that *doesn't* hold the lock. The write operation involves `io_sq_thread` which calls `__io_sq_thread`, which in turn calls `io_submit_sqes`, and so on down the call stack, finally setting `ctx->drain_disabled = true;` while holding the `uring_lock`. The reader, in this scenario, is `io_uring_enter`. It's reading the `syscall_iopoll` value without the lock.
Since these are bitfields, I'm thinking about the implications of the C standard and how the compiler handles bitfield accesses. The key here is whether the read of `syscall_iopoll` can be affected by the write to `drain_disabled`, despite them being different bits within the same memory word. Even if they are different bits, the way the compiler does RMW operations can cause a torn read, even on x86, depending on the compiler's generated code. I start considering potential compiler optimizations, like the compiler re-using the cached value of `syscall_iopoll` instead of re-reading it.
However, KCSAN is complaining about any race, and, because these are bitfields, it's a data race and the C standard makes a big deal about such situations. I consider using `READ_ONCE` and `WRITE_ONCE` but it is not possible to use `WRITE_ONCE` on a bitfield directly, so a workaround of `READ_ONCE` then write the whole word would be required. The bitfields might even be benign, in the scenario that the value changes only from `false` to `true`, and not the reverse, but KCSAN still complains because the kernel is very strict about data races.
The value changed from 0x0200 to 0x0608. This is a change of bits 3, 9, and 10 of the struct.
After looking at the code and the offsets for the bitfields, I confirm the race is between the writer setting `drain_disabled` (bit 10) and a reader checking `syscall_iopoll` (bit 8). The critical point is that the read of `syscall_iopoll` can potentially see an intermediate value if the write is not atomic. Since `syscall_iopoll` is set at ring creation and never modified, even an incorrect read would be harmless *in this specific case* from the perspective of program correctness.
I then focus on the code itself in `io_uring_enter`:
```c
2624: if (ctx->syscall_iopoll) {
2625: /*
2626: * We disallow the app entering submit/complete with
2627: * polling, but we still need to lock the ring to
2628: * prevent racing with polled issue that got punted to
2629: * a workqueue.
2630: */
2631: mutex_lock(&ctx->uring_lock);
2632: iopoll_locked:
2633: ret2 = io_validate_ext_arg(ctx, flags, argp, argsz);
2634: if (likely(!ret2))
2635: ret2 = io_iopoll_check(ctx, min_complete);
2636: mutex_unlock(&ctx->uring_lock);
2637: } else {
2638: struct ext_arg ext_arg = { .argsz = argsz };
2639:
2640: ret2 = io_get_ext_arg(ctx, flags, argp, &ext_arg);
2641: if (likely(!ret2))
2642: ret2 = io_cqring_wait(ctx, min_complete, flags,
2643: &ext_arg);
26
|
| 34/2 |
2026/02/23 15:43 |
tool |
grepper |
0m
Args: map[Expression:iowq_limits_set]
Results: map[Output:include/linux/io_uring_types.h=271=struct io_ring_ctx {
--
include/linux/io_uring_types.h-287- unsigned int compat: 1;
include/linux/io_uring_types.h:288: unsigned int iowq_limits_set : 1;
include/linux/io_uring_types.h-289-
--
io_uring/register.c=344=static __cold int io_register_iowq_max_workers(struct io_ring_ctx *ctx,
--
io_uring/register.c-386- ctx->iowq_limits[i] = new_count[i];
io_uring/register.c:387: ctx->iowq_limits_set = true;
io_uring/register.c-388-
--
io_uring/tctx.c=112=int __io_uring_add_tctx_node(struct io_ring_ctx *ctx)
--
io_uring/tctx.c-123- tctx = current->io_uring;
io_uring/tctx.c:124: if (ctx->iowq_limits_set) {
io_uring/tctx.c-125- unsigned int limits[2] = { ctx->iowq_limits[0],
]
|
| 35/2 |
2026/02/23 15:43 |
llm |
expert |
0m
Model:
Tokens:
input: 35553
output: 43
thoughts: 321
Thoughts: **Analyzing io_uring Locking for Concurrency**
Okay, so I'm looking at how `iowq_limits_set` gets set. It looks like it's done in `io_register_iowq_max_workers`, which is called within the `io_uring_register` syscall. That makes sense. Now, a key question here is whether `io_uring_register` holds the `uring_lock`. Yep, confirmed. The code explicitly takes the `uring_lock` within that function.
Alright, so it *looks* like all writers are holding the `uring_lock`. That's a good starting point. Now, what about the readers? Are any accessing data without the lock? Looks like the only readers not holding the lock are reading stuff that's either constant or only ever set to `true`. That seems safe, but I need to make sure I haven't missed anything subtle.
Now, I need to focus on these `drain_next` and `drain_active` flags. They're being toggled, but I *thought* they were only ever accessed under the `uring_lock`. I need to double-check that. Let me quickly grep for those. Right, `drain_next` and `drain_active` appear in `io_init_drain` and `io_init_req`. Both of those are called from `io_submit_sqes` which is under the `uring_lock`, so that's good. But wait, `io_check_restriction` also uses them:
```c
1777: if (unlikely(ctx->op_restricted || ctx->drain_active || ctx->drain_next)) {
1778: if (!io_check_restriction(ctx, req, sqe_flags))
```
And `io_init_req` *does* call `io_check_restriction`. That's important. I need to know where `io_check_restriction` is used to make sure I'm not missing any data races. Let's see if there are any other places those flags are accessed. I need to go look at the implementation of `io_check_restriction`.
|
| 36/2 |
2026/02/23 15:43 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:io_uring/io_uring.c IncludeLines:true Name:io_check_restriction]
Results: map[SourceCode:1665: /*
1666: * Check SQE restrictions (opcode and flags).
1667: *
1668: * Returns 'true' if SQE is allowed, 'false' otherwise.
1669: */
1670: static inline bool io_check_restriction(struct io_ring_ctx *ctx,
1671: struct io_kiocb *req,
1672: unsigned int sqe_flags)
1673: {
1674: if (!ctx->op_restricted)
1675: return true;
1676: if (!test_bit(req->opcode, ctx->restrictions.sqe_op))
1677: return false;
1678:
1679: if ((sqe_flags & ctx->restrictions.sqe_flags_required) !=
1680: ctx->restrictions.sqe_flags_required)
1681: return false;
1682:
1683: if (sqe_flags & ~(ctx->restrictions.sqe_flags_allowed |
1684: ctx->restrictions.sqe_flags_required))
1685: return false;
1686:
1687: return true;
1688: }
SourceFile:io_uring/io_uring.c]
|
| 37/2 |
2026/02/23 15:43 |
llm |
expert |
0m
Model:
Tokens:
input: 36759
output: 19
thoughts: 3431
Thoughts: **Benign Data Race Analysis: A Deep Dive**
Okay, let's break this down. We have `io_check_restriction` called from `io_init_req`, and that's our starting point. The crucial bits being toggled, `drain_next` and `drain_active`, are exclusively accessed under the `uring_lock`. That's good. Now, looking at the bitfields accessed without `uring_lock`, they are either constant β like `syscall_iopoll` and `compat` β or only ever set to true, like `drain_disabled`, `off_timeout_used`, `poll_activated`, and `iowq_limits_set`.
The issue, as KCSAN flagged, is a potential data race. Specifically, a write to `drain_disabled` (setting it to `true`) racing with a read of `syscall_iopoll`, which, importantly, is a constant 0. They share the same memory word, and KCSAN picks it up. But the key here is whether it's actually harmful. "Benign" data races, the ones we can live with, don't lead to memory corruption or crashes, and happen on simple variables. This checks out.
But let's not be too quick to dismiss. Can `drain_disabled` be set multiple times? Yes, `io_init_req` sets it when `IOSQE_CQE_SKIP_SUCCESS` is present. If multiple threads, say, the SQPOLL thread and another calling `io_uring_enter`, were doing this, they'd both be holding the `uring_lock`, right? But with `SQPOLL` enabled, only the SQPOLL thread should be submitting. Let me double-check `io_uring_enter`... Ah, yes. If `SQPOLL` is enabled, the function doesn't call `io_submit_sqes` directly. It just returns `to_submit` β the user is responsible for waking up the SQPOLL thread. If `SQPOLL` is NOT enabled, then any thread calling `io_uring_enter` will take `uring_lock` before calling `io_submit_sqes`.
So, only one writer is ever in play for these bitfields at a time, for a given context. The race is always between that single writer (holding `uring_lock`) and readers (without the lock).
This solidifies the benign nature of the race.
Another observation: the value changed from `0x0200` to `0x0608`. Bit 9 was 1. Bit 10 became 1. Bit 3 became 1. And bit 9 stayed 1. Others remained 0.
If bit 9 (`poll_activated`) was already 1, it was set earlier. If bits 10 (`drain_disabled`) and 3 (`off_timeout_used`) were set in the same `io_init_req` call, the write was potentially a load-modify-store sequence. The reader *could* see a partially updated word. But bit 8 (`syscall_iopoll`) would *always* be 0. Or the compiler could have written `0x0608` directly. Either is fine. The only issue would be a scenario where the compiler uses `store word, (old_word & ~mask) | new_bits` and the `old_word` has the "wrong" value, but `old_word` is read from memory so that's not possible.
The typical "harmful" race happens between two writers. Here, it is only a single writer.
I'm comfortable saying this is benign.
Wait, do I recall any history of this type of issue in `io_uring`? I *feel* like I have seen a fix (or something similar) by moving bitfields to separate words or using `READ_ONCE`. But I can't look at the future or previous versions, so it is best to only judge by the current situation.
The race is specifically between `ctx->drain_disabled` (write) and `ctx->syscall_iopoll` (read). Both are bitfields in `struct io_ring_ctx`. They share the same memory location. The write is protected by `uring_lock`. The read is not. `syscall_iopoll` is constant after creation. `drain_disabled` is only ever set to `true`. Thus, the race is harmless.
Now, let's confirm the address, `0xffff8881438eb004`, as the bitfield. `io_ring_ctx` layout: `flags` at offset 0. Bitfields start after `flags`. `unsigned int` is 4 bytes.
|
| 38/2 |
2026/02/23 15:43 |
tool |
set-results |
0m
Args: map[Benign:true Confident:true]
Results: map[Benign:true Confident:true]
|
| 39/2 |
2026/02/23 15:43 |
llm |
expert |
0m
Model:
Tokens:
input: 41251
output: 697
thoughts: 134
Thoughts: **My Analysis Concluded: A Benign Bitfield Race**
Alright, the deep dive is done. I've pinpointed the exact bitfields at play here β `drain_disabled` and `syscall_iopoll` β and mapped out their access patterns. I can confidently say that the race condition, while present, is completely benign.
Here's the breakdown: It's a race between a write to `drain_disabled` and a read of `syscall_iopoll`. Both of these fields reside within the same word of the `struct io_ring_ctx`, so we have co-location, which is important to consider.
Now, the crucial aspect is the nature of `syscall_iopoll`. This one is *constant* after initialization; it never changes. `drain_disabled`, on the other hand, is only ever set to `true`, and not false.
Furthermore, all the *writes* to this critical data are properly guarded by `uring_lock`. The *reads*, however, are not *all* protected.
The key to the benign nature of this condition is that the bit being read (`syscall_iopoll`) is effectively immutable, and the write to `drain_disabled` has no effect on this other bit of data. So, the worst that can happen is a read reflecting an older state of the shared word, which is also benign. We're safe here.
|