“5a2448b14f0b472a9d4154e341e6dd00f80cdf8f”上不存在“test/git@gitcode.net:openanolis/dragonwell8_jdk.git”
提交 62ca1710 编写于 作者: P Pavel Begunkov 提交者: Zheng Zengkai

io_uring: deduplicate failing task_work_add

mainline inclusion
from mainline-5.12-rc1
commit eab30c4d
category: bugfix
bugzilla: 182869 https://gitee.com/openeuler/kernel/issues/I4DDEL

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=eab30c4d20dc761d463445e5130421863ff81505

---------------------------

When io_req_task_work_add() fails, the request will be cancelled by
enqueueing via task_works of io-wq. Extract a function for that.
Signed-off-by: NPavel Begunkov <asml.silence@gmail.com>
Signed-off-by: NJens Axboe <axboe@kernel.dk>

Conflicts:
	fs/io_uring.c
	[ 355fb9e2("io_uring: remove 'twa_signal_ok' deadlock
	  work-around") is not applied. ]
Signed-off-by: NZhihao Cheng <chengzhihao1@huawei.com>
Reviewed-by: NZhang Yi <yi.zhang@huawei.com>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 98d3ad1d
...@@ -2056,6 +2056,16 @@ static int io_req_task_work_add(struct io_kiocb *req, bool twa_signal_ok) ...@@ -2056,6 +2056,16 @@ static int io_req_task_work_add(struct io_kiocb *req, bool twa_signal_ok)
return ret; return ret;
} }
static void io_req_task_work_add_fallback(struct io_kiocb *req,
void (*cb)(struct callback_head *))
{
struct task_struct *tsk = io_wq_get_task(req->ctx->io_wq);
init_task_work(&req->task_work, cb);
task_work_add(tsk, &req->task_work, TWA_NONE);
wake_up_process(tsk);
}
static void __io_req_task_cancel(struct io_kiocb *req, int error) static void __io_req_task_cancel(struct io_kiocb *req, int error)
{ {
struct io_ring_ctx *ctx = req->ctx; struct io_ring_ctx *ctx = req->ctx;
...@@ -2111,14 +2121,8 @@ static void io_req_task_queue(struct io_kiocb *req) ...@@ -2111,14 +2121,8 @@ static void io_req_task_queue(struct io_kiocb *req)
percpu_ref_get(&req->ctx->refs); percpu_ref_get(&req->ctx->refs);
ret = io_req_task_work_add(req, true); ret = io_req_task_work_add(req, true);
if (unlikely(ret)) { if (unlikely(ret))
struct task_struct *tsk; io_req_task_work_add_fallback(req, io_req_task_cancel);
init_task_work(&req->task_work, io_req_task_cancel);
tsk = io_wq_get_task(req->ctx->io_wq);
task_work_add(tsk, &req->task_work, TWA_NONE);
wake_up_process(tsk);
}
} }
static void io_queue_next(struct io_kiocb *req) static void io_queue_next(struct io_kiocb *req)
...@@ -2237,13 +2241,8 @@ static void io_free_req_deferred(struct io_kiocb *req) ...@@ -2237,13 +2241,8 @@ static void io_free_req_deferred(struct io_kiocb *req)
init_task_work(&req->task_work, io_put_req_deferred_cb); init_task_work(&req->task_work, io_put_req_deferred_cb);
ret = io_req_task_work_add(req, true); ret = io_req_task_work_add(req, true);
if (unlikely(ret)) { if (unlikely(ret))
struct task_struct *tsk; io_req_task_work_add_fallback(req, io_put_req_deferred_cb);
tsk = io_wq_get_task(req->ctx->io_wq);
task_work_add(tsk, &req->task_work, TWA_NONE);
wake_up_process(tsk);
}
} }
static inline void io_put_req_deferred(struct io_kiocb *req, int refs) static inline void io_put_req_deferred(struct io_kiocb *req, int refs)
...@@ -3343,15 +3342,8 @@ static int io_async_buf_func(struct wait_queue_entry *wait, unsigned mode, ...@@ -3343,15 +3342,8 @@ static int io_async_buf_func(struct wait_queue_entry *wait, unsigned mode,
/* submit ref gets dropped, acquire a new one */ /* submit ref gets dropped, acquire a new one */
refcount_inc(&req->refs); refcount_inc(&req->refs);
ret = io_req_task_work_add(req, true); ret = io_req_task_work_add(req, true);
if (unlikely(ret)) { if (unlikely(ret))
struct task_struct *tsk; io_req_task_work_add_fallback(req, io_req_task_cancel);
/* queue just for cancelation */
init_task_work(&req->task_work, io_req_task_cancel);
tsk = io_wq_get_task(req->ctx->io_wq);
task_work_add(tsk, &req->task_work, TWA_NONE);
wake_up_process(tsk);
}
return 1; return 1;
} }
...@@ -4961,12 +4953,8 @@ static int __io_async_wake(struct io_kiocb *req, struct io_poll_iocb *poll, ...@@ -4961,12 +4953,8 @@ static int __io_async_wake(struct io_kiocb *req, struct io_poll_iocb *poll,
*/ */
ret = io_req_task_work_add(req, twa_signal_ok); ret = io_req_task_work_add(req, twa_signal_ok);
if (unlikely(ret)) { if (unlikely(ret)) {
struct task_struct *tsk;
WRITE_ONCE(poll->canceled, true); WRITE_ONCE(poll->canceled, true);
tsk = io_wq_get_task(req->ctx->io_wq); io_req_task_work_add_fallback(req, func);
task_work_add(tsk, &req->task_work, TWA_NONE);
wake_up_process(tsk);
} }
return 1; return 1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册