]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
io_uring: cancel all task's requests on exit
authorPavel Begunkov <asml.silence@gmail.com>
Mon, 15 Jun 2020 07:24:04 +0000 (10:24 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Aug 2020 09:42:08 +0000 (11:42 +0200)
[ Upstream commit 44e728b8aae0bb6d4229129083974f9dea43f50b ]

If a process is going away, io_uring_flush() will cancel only 1
request with a matching pid. Cancel all of them

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/io-wq.c
fs/io-wq.h
fs/io_uring.c

index 6d2e8ccc229e342297e6dff014cf535d2201fa47..2bfa9117bc28968ede00ac16d9db24ad363620a2 100644 (file)
@@ -1022,20 +1022,6 @@ enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork)
        return io_wq_cancel_cb(wq, io_wq_io_cb_cancel_data, (void *)cwork, false);
 }
 
-static bool io_wq_pid_match(struct io_wq_work *work, void *data)
-{
-       pid_t pid = (pid_t) (unsigned long) data;
-
-       return work->task_pid == pid;
-}
-
-enum io_wq_cancel io_wq_cancel_pid(struct io_wq *wq, pid_t pid)
-{
-       void *data = (void *) (unsigned long) pid;
-
-       return io_wq_cancel_cb(wq, io_wq_pid_match, data, false);
-}
-
 struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
 {
        int ret = -ENOMEM, node;
index 8902903831f252140b8aabe17ce88552f019b9f1..df8a4cd3236db1cd57424277006a7cb23e0b3302 100644 (file)
@@ -129,7 +129,6 @@ static inline bool io_wq_is_hashed(struct io_wq_work *work)
 
 void io_wq_cancel_all(struct io_wq *wq);
 enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork);
-enum io_wq_cancel io_wq_cancel_pid(struct io_wq *wq, pid_t pid);
 
 typedef bool (work_cancel_fn)(struct io_wq_work *, void *);
 
index cf327055467732a9b129c90d324982149c4e7634..9bb23edf2363ae009308a98de89a022f292f5f43 100644 (file)
@@ -7720,6 +7720,13 @@ static void io_uring_cancel_files(struct io_ring_ctx *ctx,
        }
 }
 
+static bool io_cancel_pid_cb(struct io_wq_work *work, void *data)
+{
+       pid_t pid = (pid_t) (unsigned long) data;
+
+       return work->task_pid == pid;
+}
+
 static int io_uring_flush(struct file *file, void *data)
 {
        struct io_ring_ctx *ctx = file->private_data;
@@ -7729,8 +7736,11 @@ static int io_uring_flush(struct file *file, void *data)
        /*
         * If the task is going away, cancel work it may have pending
         */
-       if (fatal_signal_pending(current) || (current->flags & PF_EXITING))
-               io_wq_cancel_pid(ctx->io_wq, task_pid_vnr(current));
+       if (fatal_signal_pending(current) || (current->flags & PF_EXITING)) {
+               void *data = (void *) (unsigned long)task_pid_vnr(current);
+
+               io_wq_cancel_cb(ctx->io_wq, io_cancel_pid_cb, data, true);
+       }
 
        return 0;
 }