Skip to content

Commit ef1a4a7

Browse files
committed
Merge tag 'io_uring-2023-01-06' of git://git.kernel.dk/linux
Pull io_uring fixes from Jens Axboe: "A few minor fixes that should go into the 6.2 release: - Fix for a memory leak in io-wq worker creation, if we ultimately end up canceling the worker creation before it gets created (me) - lockdep annotations for the CQ locking (Pavel) - A regression fix for CQ timeout handling (Pavel) - Ring pinning around deferred task_work fix (Pavel) - A trivial member move in struct io_ring_ctx, saving us some memory (me)" * tag 'io_uring-2023-01-06' of git://git.kernel.dk/linux: io_uring: fix CQ waiting timeout handling io_uring: move 'poll_multi_queue' bool in io_ring_ctx io_uring: lockdep annotate CQ locking io_uring: pin context while queueing deferred tw io_uring/io-wq: free worker if task_work creation is canceled
2 parents 93387d4 + 12521a5 commit ef1a4a7

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

include/linux/io_uring_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ struct io_ring_ctx {
292292
struct {
293293
spinlock_t completion_lock;
294294

295+
bool poll_multi_queue;
296+
295297
/*
296298
* ->iopoll_list is protected by the ctx->uring_lock for
297299
* io_uring instances that don't use IORING_SETUP_SQPOLL.
@@ -300,7 +302,6 @@ struct io_ring_ctx {
300302
*/
301303
struct io_wq_work_list iopoll_list;
302304
struct io_hash_table cancel_table;
303-
bool poll_multi_queue;
304305

305306
struct llist_head work_llist;
306307

io_uring/io-wq.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,7 @@ static void io_wq_cancel_tw_create(struct io_wq *wq)
12301230

12311231
worker = container_of(cb, struct io_worker, create_work);
12321232
io_worker_cancel_cb(worker);
1233+
kfree(worker);
12331234
}
12341235
}
12351236

io_uring/io_uring.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,8 @@ static bool io_cqring_event_overflow(struct io_ring_ctx *ctx, u64 user_data,
731731
size_t ocq_size = sizeof(struct io_overflow_cqe);
732732
bool is_cqe32 = (ctx->flags & IORING_SETUP_CQE32);
733733

734+
lockdep_assert_held(&ctx->completion_lock);
735+
734736
if (is_cqe32)
735737
ocq_size += sizeof(struct io_uring_cqe);
736738

@@ -820,9 +822,6 @@ static bool io_fill_cqe_aux(struct io_ring_ctx *ctx, u64 user_data, s32 res,
820822
{
821823
struct io_uring_cqe *cqe;
822824

823-
if (!ctx->task_complete)
824-
lockdep_assert_held(&ctx->completion_lock);
825-
826825
ctx->cq_extra++;
827826

828827
/*
@@ -1236,13 +1235,18 @@ static void io_req_local_work_add(struct io_kiocb *req)
12361235
{
12371236
struct io_ring_ctx *ctx = req->ctx;
12381237

1239-
if (!llist_add(&req->io_task_work.node, &ctx->work_llist))
1238+
percpu_ref_get(&ctx->refs);
1239+
1240+
if (!llist_add(&req->io_task_work.node, &ctx->work_llist)) {
1241+
percpu_ref_put(&ctx->refs);
12401242
return;
1243+
}
12411244
/* need it for the following io_cqring_wake() */
12421245
smp_mb__after_atomic();
12431246

12441247
if (unlikely(atomic_read(&req->task->io_uring->in_idle))) {
12451248
io_move_task_work_from_local(ctx);
1249+
percpu_ref_put(&ctx->refs);
12461250
return;
12471251
}
12481252

@@ -1252,6 +1256,7 @@ static void io_req_local_work_add(struct io_kiocb *req)
12521256
if (ctx->has_evfd)
12531257
io_eventfd_signal(ctx);
12541258
__io_cqring_wake(ctx);
1259+
percpu_ref_put(&ctx->refs);
12551260
}
12561261

12571262
void __io_req_task_work_add(struct io_kiocb *req, bool allow_local)
@@ -2465,7 +2470,7 @@ int io_run_task_work_sig(struct io_ring_ctx *ctx)
24652470
/* when returns >0, the caller should retry */
24662471
static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,
24672472
struct io_wait_queue *iowq,
2468-
ktime_t timeout)
2473+
ktime_t *timeout)
24692474
{
24702475
int ret;
24712476
unsigned long check_cq;
@@ -2483,7 +2488,7 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,
24832488
if (check_cq & BIT(IO_CHECK_CQ_DROPPED_BIT))
24842489
return -EBADR;
24852490
}
2486-
if (!schedule_hrtimeout(&timeout, HRTIMER_MODE_ABS))
2491+
if (!schedule_hrtimeout(timeout, HRTIMER_MODE_ABS))
24872492
return -ETIME;
24882493

24892494
/*
@@ -2559,7 +2564,7 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
25592564
}
25602565
prepare_to_wait_exclusive(&ctx->cq_wait, &iowq.wq,
25612566
TASK_INTERRUPTIBLE);
2562-
ret = io_cqring_wait_schedule(ctx, &iowq, timeout);
2567+
ret = io_cqring_wait_schedule(ctx, &iowq, &timeout);
25632568
if (__io_cqring_events_user(ctx) >= min_events)
25642569
break;
25652570
cond_resched();

io_uring/io_uring.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ bool __io_alloc_req_refill(struct io_ring_ctx *ctx);
7979
bool io_match_task_safe(struct io_kiocb *head, struct task_struct *task,
8080
bool cancel_all);
8181

82+
#define io_lockdep_assert_cq_locked(ctx) \
83+
do { \
84+
if (ctx->flags & IORING_SETUP_IOPOLL) { \
85+
lockdep_assert_held(&ctx->uring_lock); \
86+
} else if (!ctx->task_complete) { \
87+
lockdep_assert_held(&ctx->completion_lock); \
88+
} else if (ctx->submitter_task->flags & PF_EXITING) { \
89+
lockdep_assert(current_work()); \
90+
} else { \
91+
lockdep_assert(current == ctx->submitter_task); \
92+
} \
93+
} while (0)
94+
8295
static inline void io_req_task_work_add(struct io_kiocb *req)
8396
{
8497
__io_req_task_work_add(req, true);
@@ -92,6 +105,8 @@ void io_cq_unlock_post(struct io_ring_ctx *ctx);
92105
static inline struct io_uring_cqe *io_get_cqe_overflow(struct io_ring_ctx *ctx,
93106
bool overflow)
94107
{
108+
io_lockdep_assert_cq_locked(ctx);
109+
95110
if (likely(ctx->cqe_cached < ctx->cqe_sentinel)) {
96111
struct io_uring_cqe *cqe = ctx->cqe_cached;
97112

0 commit comments

Comments
 (0)