Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'io_uring-6.5-2023-07-03' of git://git.kernel.dk/linux

Pull io_uring fixes from Jens Axboe:
"The fix for the msghdr->msg_inq assigned value being wrong, using -1
instead of -1U for the signed type.

Also a fix for ensuring when we're trying to run task_work on an
exiting task, that we wait for it. This is not really a correctness
thing as the work is being canceled, but it does help with ensuring
file descriptors are closed when the task has exited."

* tag 'io_uring-6.5-2023-07-03' of git://git.kernel.dk/linux:
io_uring: flush offloaded and delayed task_work on exit
io_uring: remove io_fallback_tw() forward declaration
io_uring/net: use proper value for msg_inq

+36 -21
+32 -17
io_uring/io_uring.c
··· 149 149 static void io_queue_sqe(struct io_kiocb *req); 150 150 static void io_move_task_work_from_local(struct io_ring_ctx *ctx); 151 151 static void __io_submit_flush_completions(struct io_ring_ctx *ctx); 152 - static __cold void io_fallback_tw(struct io_uring_task *tctx); 153 152 154 153 struct kmem_cache *req_cachep; 155 154 ··· 1237 1238 return cmpxchg(&head->first, old, new); 1238 1239 } 1239 1240 1241 + static __cold void io_fallback_tw(struct io_uring_task *tctx, bool sync) 1242 + { 1243 + struct llist_node *node = llist_del_all(&tctx->task_list); 1244 + struct io_ring_ctx *last_ctx = NULL; 1245 + struct io_kiocb *req; 1246 + 1247 + while (node) { 1248 + req = container_of(node, struct io_kiocb, io_task_work.node); 1249 + node = node->next; 1250 + if (sync && last_ctx != req->ctx) { 1251 + if (last_ctx) { 1252 + flush_delayed_work(&last_ctx->fallback_work); 1253 + percpu_ref_put(&last_ctx->refs); 1254 + } 1255 + last_ctx = req->ctx; 1256 + percpu_ref_get(&last_ctx->refs); 1257 + } 1258 + if (llist_add(&req->io_task_work.node, 1259 + &req->ctx->fallback_llist)) 1260 + schedule_delayed_work(&req->ctx->fallback_work, 1); 1261 + } 1262 + 1263 + if (last_ctx) { 1264 + flush_delayed_work(&last_ctx->fallback_work); 1265 + percpu_ref_put(&last_ctx->refs); 1266 + } 1267 + } 1268 + 1240 1269 void tctx_task_work(struct callback_head *cb) 1241 1270 { 1242 1271 struct io_tw_state ts = {}; ··· 1277 1250 unsigned int count = 0; 1278 1251 1279 1252 if (unlikely(current->flags & PF_EXITING)) { 1280 - io_fallback_tw(tctx); 1253 + io_fallback_tw(tctx, true); 1281 1254 return; 1282 1255 } 1283 1256 ··· 1304 1277 io_uring_drop_tctx_refs(current); 1305 1278 1306 1279 trace_io_uring_task_work_run(tctx, count, loops); 1307 - } 1308 - 1309 - static __cold void io_fallback_tw(struct io_uring_task *tctx) 1310 - { 1311 - struct llist_node *node = llist_del_all(&tctx->task_list); 1312 - struct io_kiocb *req; 1313 - 1314 - while (node) { 1315 - req = container_of(node, struct io_kiocb, io_task_work.node); 1316 - node = node->next; 1317 - if (llist_add(&req->io_task_work.node, 1318 - &req->ctx->fallback_llist)) 1319 - schedule_delayed_work(&req->ctx->fallback_work, 1); 1320 - } 1321 1280 } 1322 1281 1323 1282 static inline void io_req_local_work_add(struct io_kiocb *req, unsigned flags) ··· 1372 1359 if (likely(!task_work_add(req->task, &tctx->task_work, ctx->notify_method))) 1373 1360 return; 1374 1361 1375 - io_fallback_tw(tctx); 1362 + io_fallback_tw(tctx, false); 1376 1363 } 1377 1364 1378 1365 void __io_req_task_work_add(struct io_kiocb *req, unsigned flags) ··· 3121 3108 */ 3122 3109 if (ctx->rings) 3123 3110 io_kill_timeouts(ctx, NULL, true); 3111 + 3112 + flush_delayed_work(&ctx->fallback_work); 3124 3113 3125 3114 INIT_WORK(&ctx->exit_work, io_ring_exit_work); 3126 3115 /*
+4 -4
io_uring/net.c
··· 631 631 unsigned int cflags; 632 632 633 633 cflags = io_put_kbuf(req, issue_flags); 634 - if (msg->msg_inq && msg->msg_inq != -1U) 634 + if (msg->msg_inq && msg->msg_inq != -1) 635 635 cflags |= IORING_CQE_F_SOCK_NONEMPTY; 636 636 637 637 if (!(req->flags & REQ_F_APOLL_MULTISHOT)) { ··· 646 646 io_recv_prep_retry(req); 647 647 /* Known not-empty or unknown state, retry */ 648 648 if (cflags & IORING_CQE_F_SOCK_NONEMPTY || 649 - msg->msg_inq == -1U) 649 + msg->msg_inq == -1) 650 650 return false; 651 651 if (issue_flags & IO_URING_F_MULTISHOT) 652 652 *ret = IOU_ISSUE_SKIP_COMPLETE; ··· 805 805 flags |= MSG_DONTWAIT; 806 806 807 807 kmsg->msg.msg_get_inq = 1; 808 - kmsg->msg.msg_inq = -1U; 808 + kmsg->msg.msg_inq = -1; 809 809 if (req->flags & REQ_F_APOLL_MULTISHOT) { 810 810 ret = io_recvmsg_multishot(sock, sr, kmsg, flags, 811 811 &mshot_finished); ··· 903 903 if (unlikely(ret)) 904 904 goto out_free; 905 905 906 - msg.msg_inq = -1U; 906 + msg.msg_inq = -1; 907 907 msg.msg_flags = 0; 908 908 909 909 flags = sr->msg_flags;