Skip to content

Commit df3b8ca

Browse files
isilencekdave
authored andcommitted
io_uring/cmd: let cmds to know about dying task
When the taks that submitted a request is dying, a task work for that request might get run by a kernel thread or even worse by a half dismantled task. We can't just cancel the task work without running the callback as the cmd might need to do some clean up, so pass a flag instead. If set, it's not safe to access any task resources and the callback is expected to cancel the cmd ASAP. Reviewed-by: Jens Axboe <[email protected]> Reviewed-by: Ming Lei <[email protected]> Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 1cc86ae commit df3b8ca

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

include/linux/io_uring_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ enum io_uring_cmd_flags {
3737
/* set when uring wants to cancel a previously issued command */
3838
IO_URING_F_CANCEL = (1 << 11),
3939
IO_URING_F_COMPAT = (1 << 12),
40+
IO_URING_F_TASK_DEAD = (1 << 13),
4041
};
4142

4243
struct io_wq_work_node {

io_uring/uring_cmd.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,13 @@ EXPORT_SYMBOL_GPL(io_uring_cmd_mark_cancelable);
119119
static void io_uring_cmd_work(struct io_kiocb *req, struct io_tw_state *ts)
120120
{
121121
struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);
122+
unsigned int flags = IO_URING_F_COMPLETE_DEFER;
123+
124+
if (current->flags & (PF_EXITING | PF_KTHREAD))
125+
flags |= IO_URING_F_TASK_DEAD;
122126

123127
/* task_work executor checks the deffered list completion */
124-
ioucmd->task_work_cb(ioucmd, IO_URING_F_COMPLETE_DEFER);
128+
ioucmd->task_work_cb(ioucmd, flags);
125129
}
126130

127131
void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,

0 commit comments

Comments
 (0)