提交 b67ca1f9 编写于 作者: J Jens Axboe 提交者: Shile Zhang

io_uring: ensure poll commands clear ->sqe

commit 6cc47d1d2a9b631f62405f56df651975c7587a97 upstream.

If we end up getting woken in poll (due to a signal), then we may need
to punt the poll request to an async worker. When we do that, we look up
the list to queue at, deferefencing req->submit.sqe, however that is
only set for requests we initially decided to queue async.

This fixes a crash with poll command usage and wakeups that need to punt
to async context.

Fixes: 54a91f3bb9b9 ("io_uring: limit parallelism of buffered writes")
Signed-off-by: NJens Axboe <axboe@kernel.dk>
Signed-off-by: NJoseph Qi <joseph.qi@linux.alibaba.com>
Reviewed-by: NXiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
上级 a2a0db0f
...@@ -445,16 +445,15 @@ static void __io_commit_cqring(struct io_ring_ctx *ctx) ...@@ -445,16 +445,15 @@ static void __io_commit_cqring(struct io_ring_ctx *ctx)
static inline void io_queue_async_work(struct io_ring_ctx *ctx, static inline void io_queue_async_work(struct io_ring_ctx *ctx,
struct io_kiocb *req) struct io_kiocb *req)
{ {
int rw; int rw = 0;
switch (req->submit.sqe->opcode) { if (req->submit.sqe) {
case IORING_OP_WRITEV: switch (req->submit.sqe->opcode) {
case IORING_OP_WRITE_FIXED: case IORING_OP_WRITEV:
rw = !(req->rw.ki_flags & IOCB_DIRECT); case IORING_OP_WRITE_FIXED:
break; rw = !(req->rw.ki_flags & IOCB_DIRECT);
default: break;
rw = 0; }
break;
} }
queue_work(ctx->sqo_wq[rw], &req->work); queue_work(ctx->sqo_wq[rw], &req->work);
...@@ -1713,6 +1712,7 @@ static int io_poll_add(struct io_kiocb *req, const struct io_uring_sqe *sqe) ...@@ -1713,6 +1712,7 @@ static int io_poll_add(struct io_kiocb *req, const struct io_uring_sqe *sqe)
if (!poll->file) if (!poll->file)
return -EBADF; return -EBADF;
req->submit.sqe = NULL;
INIT_WORK(&req->work, io_poll_complete_work); INIT_WORK(&req->work, io_poll_complete_work);
events = READ_ONCE(sqe->poll_events); events = READ_ONCE(sqe->poll_events);
poll->events = demangle_poll(events) | EPOLLERR | EPOLLHUP; poll->events = demangle_poll(events) | EPOLLERR | EPOLLHUP;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册