Merge tag 'io_uring-5.15-2021-10-22' of git://git.kernel.dk/linux-block

Pull io_uring fixes from Jens Axboe:
"Two fixes for the max workers limit API that was introduced this
series: one fix for an issue with that code, and one fixing a linked
timeout regression in this series"

* tag 'io_uring-5.15-2021-10-22' of git://git.kernel.dk/linux-block:
io_uring: apply worker limits to previous users
io_uring: fix ltimeout unprep
io_uring: apply max_workers limit to all future users
io-wq: max_worker fixes

+47 -14
+5 -2
fs/io-wq.c
··· 253 253 pr_warn_once("io-wq is not configured for unbound workers"); 254 254 255 255 raw_spin_lock(&wqe->lock); 256 - if (acct->nr_workers == acct->max_workers) { 256 + if (acct->nr_workers >= acct->max_workers) { 257 257 raw_spin_unlock(&wqe->lock); 258 258 return true; 259 259 } ··· 1291 1291 1292 1292 rcu_read_lock(); 1293 1293 for_each_node(node) { 1294 + struct io_wqe *wqe = wq->wqes[node]; 1294 1295 struct io_wqe_acct *acct; 1295 1296 1297 + raw_spin_lock(&wqe->lock); 1296 1298 for (i = 0; i < IO_WQ_ACCT_NR; i++) { 1297 - acct = &wq->wqes[node]->acct[i]; 1299 + acct = &wqe->acct[i]; 1298 1300 prev = max_t(int, acct->max_workers, prev); 1299 1301 if (new_count[i]) 1300 1302 acct->max_workers = new_count[i]; 1301 1303 new_count[i] = prev; 1302 1304 } 1305 + raw_spin_unlock(&wqe->lock); 1303 1306 } 1304 1307 rcu_read_unlock(); 1305 1308 return 0;
+42 -12
fs/io_uring.c
··· 456 456 struct work_struct exit_work; 457 457 struct list_head tctx_list; 458 458 struct completion ref_comp; 459 + u32 iowq_limits[2]; 460 + bool iowq_limits_set; 459 461 }; 460 462 }; 461 463 ··· 1368 1366 req->flags |= REQ_F_INFLIGHT; 1369 1367 atomic_inc(&current->io_uring->inflight_tracked); 1370 1368 } 1371 - } 1372 - 1373 - static inline void io_unprep_linked_timeout(struct io_kiocb *req) 1374 - { 1375 - req->flags &= ~REQ_F_LINK_TIMEOUT; 1376 1369 } 1377 1370 1378 1371 static struct io_kiocb *__io_prep_linked_timeout(struct io_kiocb *req) ··· 6980 6983 switch (io_arm_poll_handler(req)) { 6981 6984 case IO_APOLL_READY: 6982 6985 if (linked_timeout) 6983 - io_unprep_linked_timeout(req); 6986 + io_queue_linked_timeout(linked_timeout); 6984 6987 goto issue_sqe; 6985 6988 case IO_APOLL_ABORTED: 6986 6989 /* ··· 9635 9638 ret = io_uring_alloc_task_context(current, ctx); 9636 9639 if (unlikely(ret)) 9637 9640 return ret; 9641 + 9638 9642 tctx = current->io_uring; 9643 + if (ctx->iowq_limits_set) { 9644 + unsigned int limits[2] = { ctx->iowq_limits[0], 9645 + ctx->iowq_limits[1], }; 9646 + 9647 + ret = io_wq_max_workers(tctx->io_wq, limits); 9648 + if (ret) 9649 + return ret; 9650 + } 9639 9651 } 9640 9652 if (!xa_load(&tctx->xa, (unsigned long)ctx)) { 9641 9653 node = kmalloc(sizeof(*node), GFP_KERNEL); ··· 10649 10643 10650 10644 static int io_register_iowq_max_workers(struct io_ring_ctx *ctx, 10651 10645 void __user *arg) 10646 + __must_hold(&ctx->uring_lock) 10652 10647 { 10648 + struct io_tctx_node *node; 10653 10649 struct io_uring_task *tctx = NULL; 10654 10650 struct io_sq_data *sqd = NULL; 10655 10651 __u32 new_count[2]; ··· 10682 10674 tctx = current->io_uring; 10683 10675 } 10684 10676 10685 - ret = -EINVAL; 10686 - if (!tctx || !tctx->io_wq) 10687 - goto err; 10677 + BUILD_BUG_ON(sizeof(new_count) != sizeof(ctx->iowq_limits)); 10688 10678 10689 - ret = io_wq_max_workers(tctx->io_wq, new_count); 10690 - if (ret) 10691 - goto err; 10679 + memcpy(ctx->iowq_limits, new_count, sizeof(new_count)); 10680 + ctx->iowq_limits_set = true; 10681 + 10682 + ret = -EINVAL; 10683 + if (tctx && tctx->io_wq) { 10684 + ret = io_wq_max_workers(tctx->io_wq, new_count); 10685 + if (ret) 10686 + goto err; 10687 + } else { 10688 + memset(new_count, 0, sizeof(new_count)); 10689 + } 10692 10690 10693 10691 if (sqd) { 10694 10692 mutex_unlock(&sqd->lock); ··· 10704 10690 if (copy_to_user(arg, new_count, sizeof(new_count))) 10705 10691 return -EFAULT; 10706 10692 10693 + /* that's it for SQPOLL, only the SQPOLL task creates requests */ 10694 + if (sqd) 10695 + return 0; 10696 + 10697 + /* now propagate the restriction to all registered users */ 10698 + list_for_each_entry(node, &ctx->tctx_list, ctx_node) { 10699 + struct io_uring_task *tctx = node->task->io_uring; 10700 + 10701 + if (WARN_ON_ONCE(!tctx->io_wq)) 10702 + continue; 10703 + 10704 + for (i = 0; i < ARRAY_SIZE(new_count); i++) 10705 + new_count[i] = ctx->iowq_limits[i]; 10706 + /* ignore errors, it always returns zero anyway */ 10707 + (void)io_wq_max_workers(tctx->io_wq, new_count); 10708 + } 10707 10709 return 0; 10708 10710 err: 10709 10711 if (sqd) {