public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ublk: set_params: properly check if parameters can be applied
@ 2025-03-04 21:34 Uday Shankar
  2025-03-05  2:34 ` Ming Lei
  2025-03-05 14:45 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Uday Shankar @ 2025-03-04 21:34 UTC (permalink / raw)
  To: Ming Lei, Jens Axboe; +Cc: linux-block, Uday Shankar

The parameters set by the set_params call are only applied to the block
device in the start_dev call. So if a device has already been started, a
subsequently issued set_params on that device will not have the desired
effect, and should return an error. There is an existing check for this
- set_params fails on devices in the LIVE state. But this check is not
sufficient to cover the recovery case. In this case, the device will be
in the QUIESCED or FAIL_IO states, so set_params will succeed. But this
success is misleading, because the parameters will not be applied, since
the device has already been started (by a previous ublk server). The bit
UB_STATE_USED is set on completion of the start_dev; use it to detect
and fail set_params commands which arrive too late to be applied (after
start_dev).

Signed-off-by: Uday Shankar <ushankar@purestorage.com>
---
 drivers/block/ublk_drv.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 2955900ee713c5d8f3cbc2a69f6f6058348e5253..aa34594c76ad02b1480b9ef4a2bd52a095ca6f3f 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -2782,9 +2782,12 @@ static int ublk_ctrl_set_params(struct ublk_device *ub,
 	if (ph.len > sizeof(struct ublk_params))
 		ph.len = sizeof(struct ublk_params);
 
-	/* parameters can only be changed when device isn't live */
 	mutex_lock(&ub->mutex);
-	if (ub->dev_info.state == UBLK_S_DEV_LIVE) {
+	if (test_bit(UB_STATE_USED, &ub->state)) {
+		/*
+		 * Parameters can only be changed when device hasn't
+		 * been started yet
+		 */
 		ret = -EACCES;
 	} else if (copy_from_user(&ub->params, argp, ph.len)) {
 		ret = -EFAULT;

---
base-commit: 6499457f08ac23a1ad16653b67af7f04ff5dd9e2
change-id: 20250304-set_params-d27f384f2957

Best regards,
-- 
Uday Shankar <ushankar@purestorage.com>


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

* Re: [PATCH] ublk: set_params: properly check if parameters can be applied
  2025-03-04 21:34 [PATCH] ublk: set_params: properly check if parameters can be applied Uday Shankar
@ 2025-03-05  2:34 ` Ming Lei
  2025-03-05 14:45 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Ming Lei @ 2025-03-05  2:34 UTC (permalink / raw)
  To: Uday Shankar; +Cc: Jens Axboe, linux-block

On Tue, Mar 04, 2025 at 02:34:26PM -0700, Uday Shankar wrote:
> The parameters set by the set_params call are only applied to the block
> device in the start_dev call. So if a device has already been started, a
> subsequently issued set_params on that device will not have the desired
> effect, and should return an error. There is an existing check for this
> - set_params fails on devices in the LIVE state. But this check is not
> sufficient to cover the recovery case. In this case, the device will be
> in the QUIESCED or FAIL_IO states, so set_params will succeed. But this
> success is misleading, because the parameters will not be applied, since
> the device has already been started (by a previous ublk server). The bit
> UB_STATE_USED is set on completion of the start_dev; use it to detect
> and fail set_params commands which arrive too late to be applied (after
> start_dev).
> 
> Signed-off-by: Uday Shankar <ushankar@purestorage.com>
> ---
>  drivers/block/ublk_drv.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index 2955900ee713c5d8f3cbc2a69f6f6058348e5253..aa34594c76ad02b1480b9ef4a2bd52a095ca6f3f 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -2782,9 +2782,12 @@ static int ublk_ctrl_set_params(struct ublk_device *ub,
>  	if (ph.len > sizeof(struct ublk_params))
>  		ph.len = sizeof(struct ublk_params);
>  
> -	/* parameters can only be changed when device isn't live */
>  	mutex_lock(&ub->mutex);
> -	if (ub->dev_info.state == UBLK_S_DEV_LIVE) {
> +	if (test_bit(UB_STATE_USED, &ub->state)) {
> +		/*
> +		 * Parameters can only be changed when device hasn't
> +		 * been started yet
> +		 */
>  		ret = -EACCES;
>  	} else if (copy_from_user(&ub->params, argp, ph.len)) {
>  		ret = -EFAULT;

Good catch,

Fixes: 0aa73170eba5 ("ublk_drv: add SET_PARAMS/GET_PARAMS control command")
Reviewed-by: Ming Lei <ming.lei@redhat.com>


Thanks,
Ming


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

* Re: [PATCH] ublk: set_params: properly check if parameters can be applied
  2025-03-04 21:34 [PATCH] ublk: set_params: properly check if parameters can be applied Uday Shankar
  2025-03-05  2:34 ` Ming Lei
@ 2025-03-05 14:45 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2025-03-05 14:45 UTC (permalink / raw)
  To: Ming Lei, Uday Shankar; +Cc: linux-block


On Tue, 04 Mar 2025 14:34:26 -0700, Uday Shankar wrote:
> The parameters set by the set_params call are only applied to the block
> device in the start_dev call. So if a device has already been started, a
> subsequently issued set_params on that device will not have the desired
> effect, and should return an error. There is an existing check for this
> - set_params fails on devices in the LIVE state. But this check is not
> sufficient to cover the recovery case. In this case, the device will be
> in the QUIESCED or FAIL_IO states, so set_params will succeed. But this
> success is misleading, because the parameters will not be applied, since
> the device has already been started (by a previous ublk server). The bit
> UB_STATE_USED is set on completion of the start_dev; use it to detect
> and fail set_params commands which arrive too late to be applied (after
> start_dev).
> 
> [...]

Applied, thanks!

[1/1] ublk: set_params: properly check if parameters can be applied
      (no commit info)

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2025-03-05 14:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-04 21:34 [PATCH] ublk: set_params: properly check if parameters can be applied Uday Shankar
2025-03-05  2:34 ` Ming Lei
2025-03-05 14:45 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox