]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ublk: look up ublk task via its pid in timeout handler
authorMing Lei <ming.lei@redhat.com>
Sun, 13 Jul 2025 14:33:57 +0000 (22:33 +0800)
committerJens Axboe <axboe@kernel.dk>
Tue, 15 Jul 2025 14:04:16 +0000 (08:04 -0600)
Look up ublk process via its pid in timeout handler, so we can avoid to
touch io->task, because it is fragile to touch task structure.

It is fine to kill ublk server process and this way is simpler.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20250713143415.2857561-3-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/ublk_drv.c

index 2b894de29823c4439082b693bf40a43a66a3ad49..7d1d8bd979c5e66311484d62473af6e0952693d4 100644 (file)
@@ -1368,14 +1368,23 @@ static void ublk_queue_cmd_list(struct ublk_io *io, struct rq_list *l)
 static enum blk_eh_timer_return ublk_timeout(struct request *rq)
 {
        struct ublk_queue *ubq = rq->mq_hctx->driver_data;
-       struct ublk_io *io = &ubq->ios[rq->tag];
-
-       if (ubq->flags & UBLK_F_UNPRIVILEGED_DEV) {
-               send_sig(SIGKILL, io->task, 0);
-               return BLK_EH_DONE;
-       }
-
-       return BLK_EH_RESET_TIMER;
+       pid_t tgid = ubq->dev->ublksrv_tgid;
+       struct task_struct *p;
+       struct pid *pid;
+
+       if (!(ubq->flags & UBLK_F_UNPRIVILEGED_DEV))
+               return BLK_EH_RESET_TIMER;
+
+       if (unlikely(!tgid))
+               return BLK_EH_RESET_TIMER;
+
+       rcu_read_lock();
+       pid = find_vpid(tgid);
+       p = pid_task(pid, PIDTYPE_PID);
+       if (p)
+               send_sig(SIGKILL, p, 0);
+       rcu_read_unlock();
+       return BLK_EH_DONE;
 }
 
 static blk_status_t ublk_prep_req(struct ublk_queue *ubq, struct request *rq,