Skip to content

Commit a041f47

Browse files
committed
Merge tag 'io_uring-6.12-20241018' of git://git.kernel.dk/linux
Pull io_uring fixes from Jens Axboe: - Fix a regression this merge window where cloning of registered buffers didn't take into account the dummy_ubuf - Fix a race with reading how many SQRING entries are available, causing userspace to need to loop around io_uring_sqring_wait() rather than being able to rely on SQEs being available when it returned - Ensure that the SQPOLL thread is TASK_RUNNING before running task_work off the cancelation exit path * tag 'io_uring-6.12-20241018' of git://git.kernel.dk/linux: io_uring/sqpoll: ensure task state is TASK_RUNNING when running task_work io_uring/rsrc: ignore dummy_ubuf for buffer cloning io_uring/sqpoll: close race on waiting for sqring entries
2 parents b04ae0f + 8f7033a commit a041f47

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

io_uring/io_uring.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,14 @@ static inline bool io_sqring_full(struct io_ring_ctx *ctx)
284284
{
285285
struct io_rings *r = ctx->rings;
286286

287-
return READ_ONCE(r->sq.tail) - ctx->cached_sq_head == ctx->sq_entries;
287+
/*
288+
* SQPOLL must use the actual sqring head, as using the cached_sq_head
289+
* is race prone if the SQPOLL thread has grabbed entries but not yet
290+
* committed them to the ring. For !SQPOLL, this doesn't matter, but
291+
* since this helper is just used for SQPOLL sqring waits (or POLLOUT),
292+
* just read the actual sqring head unconditionally.
293+
*/
294+
return READ_ONCE(r->sq.tail) - READ_ONCE(r->sq.head) == ctx->sq_entries;
288295
}
289296

290297
static inline unsigned int io_sqring_entries(struct io_ring_ctx *ctx)
@@ -320,6 +327,7 @@ static inline int io_run_task_work(void)
320327
if (current->io_uring) {
321328
unsigned int count = 0;
322329

330+
__set_current_state(TASK_RUNNING);
323331
tctx_task_work_run(current->io_uring, UINT_MAX, &count);
324332
if (count)
325333
ret = true;

io_uring/rsrc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,8 @@ static int io_clone_buffers(struct io_ring_ctx *ctx, struct io_ring_ctx *src_ctx
11761176
for (i = 0; i < nbufs; i++) {
11771177
struct io_mapped_ubuf *src = src_ctx->user_bufs[i];
11781178

1179-
refcount_inc(&src->refs);
1179+
if (src != &dummy_ubuf)
1180+
refcount_inc(&src->refs);
11801181
user_bufs[i] = src;
11811182
}
11821183

0 commit comments

Comments
 (0)