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

Merge tag 'io_uring-5.9-2020-09-22' of git://git.kernel.dk/linux-block

Pull io_uring fixes from Jens Axboe:
"A few fixes - most of them regression fixes from this cycle, but also
a few stable heading fixes, and a build fix for the included demo tool
since some systems now actually have gettid() available"

* tag 'io_uring-5.9-2020-09-22' of git://git.kernel.dk/linux-block:
io_uring: fix openat/openat2 unified prep handling
io_uring: mark statx/files_update/epoll_ctl as non-SQPOLL
tools/io_uring: fix compile breakage
io_uring: don't use retry based buffered reads for non-async bdev
io_uring: don't re-setup vecs/iter in io_resumit_prep() is already there
io_uring: don't run task work on an exiting task
io_uring: drop 'ctx' ref on task work cancelation
io_uring: grab any needed state during defer prep

+40 -13
+38 -11
fs/io_uring.c
··· 1753 1753 struct io_ring_ctx *ctx = req->ctx; 1754 1754 int ret, notify; 1755 1755 1756 + if (tsk->flags & PF_EXITING) 1757 + return -ESRCH; 1758 + 1756 1759 /* 1757 1760 * SQPOLL kernel thread doesn't need notification, just a wakeup. For 1758 1761 * all other cases, use TWA_SIGNAL unconditionally to ensure we're ··· 1790 1787 static void io_req_task_cancel(struct callback_head *cb) 1791 1788 { 1792 1789 struct io_kiocb *req = container_of(cb, struct io_kiocb, task_work); 1790 + struct io_ring_ctx *ctx = req->ctx; 1793 1791 1794 1792 __io_req_task_cancel(req, -ECANCELED); 1793 + percpu_ref_put(&ctx->refs); 1795 1794 } 1796 1795 1797 1796 static void __io_req_task_submit(struct io_kiocb *req) ··· 2015 2010 2016 2011 static inline bool io_run_task_work(void) 2017 2012 { 2013 + /* 2014 + * Not safe to run on exiting task, and the task_work handling will 2015 + * not add work to such a task. 2016 + */ 2017 + if (unlikely(current->flags & PF_EXITING)) 2018 + return false; 2018 2019 if (current->task_works) { 2019 2020 __set_current_state(TASK_RUNNING); 2020 2021 task_work_run(); ··· 2294 2283 goto end_req; 2295 2284 } 2296 2285 2297 - ret = io_import_iovec(rw, req, &iovec, &iter, false); 2298 - if (ret < 0) 2299 - goto end_req; 2300 - ret = io_setup_async_rw(req, iovec, inline_vecs, &iter, false); 2301 - if (!ret) 2286 + if (!req->io) { 2287 + ret = io_import_iovec(rw, req, &iovec, &iter, false); 2288 + if (ret < 0) 2289 + goto end_req; 2290 + ret = io_setup_async_rw(req, iovec, inline_vecs, &iter, false); 2291 + if (!ret) 2292 + return true; 2293 + kfree(iovec); 2294 + } else { 2302 2295 return true; 2303 - kfree(iovec); 2296 + } 2304 2297 end_req: 2305 2298 req_set_fail_links(req); 2306 2299 io_req_complete(req, ret); ··· 3130 3115 struct iov_iter __iter, *iter = &__iter; 3131 3116 ssize_t io_size, ret, ret2; 3132 3117 size_t iov_count; 3118 + bool no_async; 3133 3119 3134 3120 if (req->io) 3135 3121 iter = &req->io->rw.iter; ··· 3148 3132 kiocb->ki_flags &= ~IOCB_NOWAIT; 3149 3133 3150 3134 /* If the file doesn't support async, just async punt */ 3151 - if (force_nonblock && !io_file_supports_async(req->file, READ)) 3135 + no_async = force_nonblock && !io_file_supports_async(req->file, READ); 3136 + if (no_async) 3152 3137 goto copy_iov; 3153 3138 3154 3139 ret = rw_verify_area(READ, req->file, io_kiocb_ppos(kiocb), iov_count); ··· 3193 3176 ret = ret2; 3194 3177 goto out_free; 3195 3178 } 3179 + if (no_async) 3180 + return -EAGAIN; 3196 3181 /* it's copied and will be cleaned with ->io */ 3197 3182 iovec = NULL; 3198 3183 /* now use our persistent iterator, if we aren't already */ ··· 3527 3508 const char __user *fname; 3528 3509 int ret; 3529 3510 3530 - if (unlikely(req->ctx->flags & (IORING_SETUP_IOPOLL|IORING_SETUP_SQPOLL))) 3531 - return -EINVAL; 3532 3511 if (unlikely(sqe->ioprio || sqe->buf_index)) 3533 3512 return -EINVAL; 3534 3513 if (unlikely(req->flags & REQ_F_FIXED_FILE)) ··· 3553 3536 { 3554 3537 u64 flags, mode; 3555 3538 3539 + if (unlikely(req->ctx->flags & (IORING_SETUP_IOPOLL|IORING_SETUP_SQPOLL))) 3540 + return -EINVAL; 3556 3541 if (req->flags & REQ_F_NEED_CLEANUP) 3557 3542 return 0; 3558 3543 mode = READ_ONCE(sqe->len); ··· 3569 3550 size_t len; 3570 3551 int ret; 3571 3552 3553 + if (unlikely(req->ctx->flags & (IORING_SETUP_IOPOLL|IORING_SETUP_SQPOLL))) 3554 + return -EINVAL; 3572 3555 if (req->flags & REQ_F_NEED_CLEANUP) 3573 3556 return 0; 3574 3557 how = u64_to_user_ptr(READ_ONCE(sqe->addr2)); ··· 3788 3767 #if defined(CONFIG_EPOLL) 3789 3768 if (sqe->ioprio || sqe->buf_index) 3790 3769 return -EINVAL; 3791 - if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) 3770 + if (unlikely(req->ctx->flags & (IORING_SETUP_IOPOLL | IORING_SETUP_SQPOLL))) 3792 3771 return -EINVAL; 3793 3772 3794 3773 req->epoll.epfd = READ_ONCE(sqe->fd); ··· 3903 3882 3904 3883 static int io_statx_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 3905 3884 { 3906 - if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) 3885 + if (unlikely(req->ctx->flags & (IORING_SETUP_IOPOLL | IORING_SETUP_SQPOLL))) 3907 3886 return -EINVAL; 3908 3887 if (sqe->ioprio || sqe->buf_index) 3909 3888 return -EINVAL; ··· 5420 5399 static int io_files_update_prep(struct io_kiocb *req, 5421 5400 const struct io_uring_sqe *sqe) 5422 5401 { 5402 + if (unlikely(req->ctx->flags & IORING_SETUP_SQPOLL)) 5403 + return -EINVAL; 5423 5404 if (unlikely(req->flags & (REQ_F_FIXED_FILE | REQ_F_BUFFER_SELECT))) 5424 5405 return -EINVAL; 5425 5406 if (sqe->ioprio || sqe->rw_flags) ··· 5471 5448 ret = io_prep_work_files(req); 5472 5449 if (unlikely(ret)) 5473 5450 return ret; 5451 + 5452 + io_prep_async_work(req); 5474 5453 5475 5454 switch (req->opcode) { 5476 5455 case IORING_OP_NOP: ··· 8205 8180 /* cancel this request, or head link requests */ 8206 8181 io_attempt_cancel(ctx, cancel_req); 8207 8182 io_put_req(cancel_req); 8183 + /* cancellations _may_ trigger task work */ 8184 + io_run_task_work(); 8208 8185 schedule(); 8209 8186 finish_wait(&ctx->inflight_wait, &wait); 8210 8187 }
+2 -2
tools/io_uring/io_uring-bench.c
··· 130 130 s->nr_files); 131 131 } 132 132 133 - static int gettid(void) 133 + static int lk_gettid(void) 134 134 { 135 135 return syscall(__NR_gettid); 136 136 } ··· 281 281 struct io_sq_ring *ring = &s->sq_ring; 282 282 int ret, prepped; 283 283 284 - printf("submitter=%d\n", gettid()); 284 + printf("submitter=%d\n", lk_gettid()); 285 285 286 286 srand48_r(pthread_self(), &s->rand); 287 287