ublk: fail to start/recover/del device if interrupted by signal
Subsystems (2)
v2 cover ublk: fail to start/recover/del device if interrupted by signal
Hi
The 1st & 2nd patch fixes kernel oops if user interrupts the current ublk task.
The 3rd patch returns -EINTR if user interrupts the device deletion.
V2:
- add patch 2&3, as reported by Stefano
Ming Lei (3):
ublk: fail to start device if queue setup is interrupted
ublk: fail to recover device if queue setup is interrupted
ublk: return -EINTR if breaking from waiting for existed users in
DEL_DEV
drivers/block/ublk_drv.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
Signature · 1 line
2.40.1
PATCH v2 1/3 ublk: fail to start device if queue setup is interrupted
In ublk_ctrl_start_dev(), if wait_for_completion_interruptible() is interrupted by signal, queues aren't setup successfully yet, so we have to fail UBLK_CMD_START_DEV, otherwise kernel oops can be triggered.
Reported by German when working on qemu-storage-deamon which requires single thread ublk daemon.
--- drivers/block/ublk_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/ublk_drv.c +2 -1
@@ -1847,7 +1847,8 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub, struct io_uring_cmd *cmd)if (ublksrv_pid <=0 )return -EINVAL ; -wait_for_completion_interruptible (&ub->completion); +if (wait_for_completion_interruptible (&ub->completion) !=0 ) +return -EINTR ;schedule_delayed_work (&ub->monitor_work,UBLK_DAEMON_MONITOR_PERIOD );
Signature · 1 line
2.40.1
PATCH v2 2/3 ublk: fail to recover device if queue setup is interrupted
In reply to Ming LeiIn ublk_ctrl_end_recovery(), if wait_for_completion_interruptible() is interrupted by signal, queues aren't setup successfully yet, so we have to fail UBLK_CMD_END_USER_RECOVERY, otherwise kernel oops can be triggered.
--- drivers/block/ublk_drv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/block/ublk_drv.c +3 -1
@@ -2324,7 +2324,9 @@ static int ublk_ctrl_end_recovery(struct ublk_device *ub,pr_devel ("%s: Waiting for new ubq_daemons(nr: %d) are ready, dev id %d...\n" , __func__, ub->dev_info.nr_hw_queues, header->dev_id);/* wait until new ubq_daemon sending all FETCH_REQ */ -wait_for_completion_interruptible (&ub->completion); +if (wait_for_completion_interruptible (&ub->completion)) +return -EINTR ; +pr_devel ("%s: All new ubq_daemons(nr: %d) are ready, dev id %d\n" , __func__, ub->dev_info.nr_hw_queues, header->dev_id);
Signature · 1 line
2.40.1
Re: [PATCH V2 2/3] ublk: fail to recover device if queue setup is interrupted
Quoted 11 lines · Ming Lei
In
ublk_ctrl_end_recovery(), ifwait_for_completion_interruptible()is interrupted by signal, queues aren't setup successfully yet, so we have to failUBLK_CMD_END_USER_RECOVERY, otherwise kernel oops can be triggered.Fixes c732a852b419 ("ublk_drv: add START_USER_RECOVERY and END_USER_RECOVERY support")Reported-by Stefano Garzarella <[email protected]>Signed-off-by Ming Lei <[email protected]>---
drivers/block/ublk_drv.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 19 lines
drivers/block/ublk_drv.c +3
-1@@ -2324,7 +2324,9 @@ static int ublk_ctrl_end_recovery(struct ublk_device *ub,pr_devel ("%s: Waiting for new ubq_daemons(nr: %d) are ready, dev id %d...\n" , __func__, ub->dev_info.nr_hw_queues, header->dev_id);/* wait until new ubq_daemon sending all FETCH_REQ */ -wait_for_completion_interruptible (&ub->completion); +if (wait_for_completion_interruptible (&ub->completion)) +return -EINTR ; +pr_devel ("%s: All new ubq_daemons(nr: %d) are ready, dev id %d\n" , __func__, ub->dev_info.nr_hw_queues, header->dev_id);Signature · 1 line
2.40.1
PATCH v2 3/3 ublk: return -EINTR if breaking from waiting for existed users in DEL_DEV
In reply to Ming LeiIf user interrupts wait_event_interruptible() in ublk_ctrl_del_dev(), return -EINTR and let user know what happens.
--- drivers/block/ublk_drv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/ublk_drv.c +2 -2
@@ -2126,8 +2126,8 @@ static int ublk_ctrl_del_dev(struct ublk_device **p_ub)* - the device number is freed already, we will not find this * device via ublk_get_device_from_id() */ -wait_event_interruptible (ublk_idr_wq,ublk_idr_freed (idx)); - +if (wait_event_interruptible (ublk_idr_wq,ublk_idr_freed (idx))) +return -EINTR ;return 0 ; }
Signature · 1 line
2.40.1
Re: [PATCH V2 3/3] ublk: return -EINTR if breaking from waiting for existed users in DEL_DEV
Quoted 9 lines · Ming Lei
If user interrupts
wait_event_interruptible()inublk_ctrl_del_dev(), return-EINTRand let user know what happens.Fixes 0abe39dec065 ("block: ublk: improve handling device deletion")Reported-by Stefano Garzarella <[email protected]>Signed-off-by Ming Lei <[email protected]>---
drivers/block/ublk_drv.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 19 lines
drivers/block/ublk_drv.c +2
-2@@ -2126,8 +2126,8 @@ static int ublk_ctrl_del_dev(struct ublk_device **p_ub)* - the device number is freed already, we will not find this * device via ublk_get_device_from_id() */ -wait_event_interruptible (ublk_idr_wq,ublk_idr_freed (idx)); - +if (wait_event_interruptible (ublk_idr_wq,ublk_idr_freed (idx))) +return -EINTR ;return 0 ; }Signature · 1 line
2.40.1
Quoted 9 lines · Ming Lei
The 1st & 2nd patch fixes kernel oops if user interrupts the current ublk task.
The 3rd patch returns
-EINTRif user interrupts the device deletion.V2:
- add patch 2&3, as reported by Stefano[...]
Applied, thanks!
[1/3] ublk: fail to start device if queue setup is interrupted
commit: 53e7d08f6d6e214c40db1f51291bb2975c789dc2
[2/3] ublk: fail to recover device if queue setup is interrupted
commit: 0c0cbd4ebc375ceebc75c89df04b74f215fab23a
[3/3] ublk: return -EINTR if breaking from waiting for existed users in DEL_DEV
commit: 3e9dce80dbf91972aed972c743f539c396a34312Best regards,
Signature · 1 line
Jens Axboe