linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2 0/3] ublk: fail to start/recover/del device if interrupted by signal
@ 2023-07-26 14:44 Ming Lei
  2023-07-26 14:45 ` [PATCH V2 1/3] ublk: fail to start device if queue setup is interrupted Ming Lei
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Ming Lei @ 2023-07-26 14:44 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, Stefano Garzarella, German Maglione, Ming Lei

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(-)

-- 
2.40.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH V2 1/3] ublk: fail to start device if queue setup is interrupted
  2023-07-26 14:44 [PATCH V2 0/3] ublk: fail to start/recover/del device if interrupted by signal Ming Lei
@ 2023-07-26 14:45 ` Ming Lei
  2023-07-26 14:45 ` [PATCH V2 2/3] ublk: fail to recover " Ming Lei
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Ming Lei @ 2023-07-26 14:45 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, Stefano Garzarella, German Maglione, Ming Lei

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.

Fixes: 71f28f3136af ("ublk_drv: add io_uring based userspace block driver")
Reported-by: German Maglione <gmaglione@redhat.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/block/ublk_drv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 1c823750c95a..7938221f4f7e 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -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);
 
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH V2 2/3] ublk: fail to recover device if queue setup is interrupted
  2023-07-26 14:44 [PATCH V2 0/3] ublk: fail to start/recover/del device if interrupted by signal Ming Lei
  2023-07-26 14:45 ` [PATCH V2 1/3] ublk: fail to start device if queue setup is interrupted Ming Lei
@ 2023-07-26 14:45 ` Ming Lei
  2023-07-27 13:04   ` Stefano Garzarella
  2023-07-26 14:45 ` [PATCH V2 3/3] ublk: return -EINTR if breaking from waiting for existed users in DEL_DEV Ming Lei
  2023-07-27 13:17 ` [PATCH V2 0/3] ublk: fail to start/recover/del device if interrupted by signal Jens Axboe
  3 siblings, 1 reply; 7+ messages in thread
From: Ming Lei @ 2023-07-26 14:45 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, Stefano Garzarella, German Maglione, Ming Lei

In 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.

Fixes: c732a852b419 ("ublk_drv: add START_USER_RECOVERY and END_USER_RECOVERY support")
Reported-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/block/ublk_drv.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 7938221f4f7e..9fcba3834e8d 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -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);
 
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH V2 3/3] ublk: return -EINTR if breaking from waiting for existed users in DEL_DEV
  2023-07-26 14:44 [PATCH V2 0/3] ublk: fail to start/recover/del device if interrupted by signal Ming Lei
  2023-07-26 14:45 ` [PATCH V2 1/3] ublk: fail to start device if queue setup is interrupted Ming Lei
  2023-07-26 14:45 ` [PATCH V2 2/3] ublk: fail to recover " Ming Lei
@ 2023-07-26 14:45 ` Ming Lei
  2023-07-27 13:05   ` Stefano Garzarella
  2023-07-27 13:17 ` [PATCH V2 0/3] ublk: fail to start/recover/del device if interrupted by signal Jens Axboe
  3 siblings, 1 reply; 7+ messages in thread
From: Ming Lei @ 2023-07-26 14:45 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, Stefano Garzarella, German Maglione, Ming Lei

If user interrupts wait_event_interruptible() in ublk_ctrl_del_dev(),
return -EINTR and let user know what happens.

Fixes: 0abe39dec065 ("block: ublk: improve handling device deletion")
Reported-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/block/ublk_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 9fcba3834e8d..21d2e71c5514 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -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;
 }
 
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH V2 2/3] ublk: fail to recover device if queue setup is interrupted
  2023-07-26 14:45 ` [PATCH V2 2/3] ublk: fail to recover " Ming Lei
@ 2023-07-27 13:04   ` Stefano Garzarella
  0 siblings, 0 replies; 7+ messages in thread
From: Stefano Garzarella @ 2023-07-27 13:04 UTC (permalink / raw)
  To: Ming Lei; +Cc: Jens Axboe, linux-block, German Maglione

On Wed, Jul 26, 2023 at 10:45:01PM +0800, Ming Lei wrote:
>In 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.
>
>Fixes: c732a852b419 ("ublk_drv: add START_USER_RECOVERY and END_USER_RECOVERY support")
>Reported-by: Stefano Garzarella <sgarzare@redhat.com>
>Signed-off-by: Ming Lei <ming.lei@redhat.com>
>---
> drivers/block/ublk_drv.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

>
>diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
>index 7938221f4f7e..9fcba3834e8d 100644
>--- a/drivers/block/ublk_drv.c
>+++ b/drivers/block/ublk_drv.c
>@@ -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);
>
>-- 
>2.40.1
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH V2 3/3] ublk: return -EINTR if breaking from waiting for existed users in DEL_DEV
  2023-07-26 14:45 ` [PATCH V2 3/3] ublk: return -EINTR if breaking from waiting for existed users in DEL_DEV Ming Lei
@ 2023-07-27 13:05   ` Stefano Garzarella
  0 siblings, 0 replies; 7+ messages in thread
From: Stefano Garzarella @ 2023-07-27 13:05 UTC (permalink / raw)
  To: Ming Lei; +Cc: Jens Axboe, linux-block, German Maglione

On Wed, Jul 26, 2023 at 10:45:02PM +0800, Ming Lei wrote:
>If user interrupts wait_event_interruptible() in ublk_ctrl_del_dev(),
>return -EINTR and let user know what happens.
>
>Fixes: 0abe39dec065 ("block: ublk: improve handling device deletion")
>Reported-by: Stefano Garzarella <sgarzare@redhat.com>
>Signed-off-by: Ming Lei <ming.lei@redhat.com>
>---
> drivers/block/ublk_drv.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

>
>diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
>index 9fcba3834e8d..21d2e71c5514 100644
>--- a/drivers/block/ublk_drv.c
>+++ b/drivers/block/ublk_drv.c
>@@ -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;
> }
>
>-- 
>2.40.1
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH V2 0/3] ublk: fail to start/recover/del device if interrupted by signal
  2023-07-26 14:44 [PATCH V2 0/3] ublk: fail to start/recover/del device if interrupted by signal Ming Lei
                   ` (2 preceding siblings ...)
  2023-07-26 14:45 ` [PATCH V2 3/3] ublk: return -EINTR if breaking from waiting for existed users in DEL_DEV Ming Lei
@ 2023-07-27 13:17 ` Jens Axboe
  3 siblings, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2023-07-27 13:17 UTC (permalink / raw)
  To: Ming Lei; +Cc: linux-block, Stefano Garzarella, German Maglione


On Wed, 26 Jul 2023 22:44:59 +0800, Ming Lei wrote:
> 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
> 
> [...]

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: 3e9dce80dbf91972aed972c743f539c396a34312

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-07-27 13:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-26 14:44 [PATCH V2 0/3] ublk: fail to start/recover/del device if interrupted by signal Ming Lei
2023-07-26 14:45 ` [PATCH V2 1/3] ublk: fail to start device if queue setup is interrupted Ming Lei
2023-07-26 14:45 ` [PATCH V2 2/3] ublk: fail to recover " Ming Lei
2023-07-27 13:04   ` Stefano Garzarella
2023-07-26 14:45 ` [PATCH V2 3/3] ublk: return -EINTR if breaking from waiting for existed users in DEL_DEV Ming Lei
2023-07-27 13:05   ` Stefano Garzarella
2023-07-27 13:17 ` [PATCH V2 0/3] ublk: fail to start/recover/del device if interrupted by signal Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).