ublk: set_params: properly check if parameters can be applied
Subsystems (2)
PATCH 1/1 ublk: set_params: properly check if parameters can be applied
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).
--- drivers/block/ublk_drv.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/block/ublk_drv.c +5 -2
@@ -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,
Signature · 1 line
Uday Shankar <[email protected]>
Quoted 27 lines · Uday Shankar
The parameters set by the
set_paramscall are only applied to the block device in thestart_devcall. So if a device has already been started, a subsequently issuedset_paramson that device will not have the desired effect, and should return an error. There is an existing check for this
-set_paramsfails 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 orFAIL_IOstates, soset_paramswill 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 bitUB_STATE_USEDis set on completion of thestart_dev; use it to detect and failset_paramscommands which arrive too late to be applied (afterstart_dev).Signed-off-by Uday Shankar <[email protected]>--- drivers/block/ublk_drv.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/block/ublk_drv.c +0
-1@@ -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 */
drivers/block/ublk_drv.c static int ublk_ctrl_set_params(struct ublk_device *ub, · line 2793
Quoted 10 lines
drivers/block/ublk_drv.c +5
-1mutex_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,
Thanks,
Ming
Quoted 13 lines · Uday Shankar
The parameters set by the
set_paramscall are only applied to the block device in thestart_devcall. So if a device has already been started, a subsequently issuedset_paramson that device will not have the desired effect, and should return an error. There is an existing check for this
-set_paramsfails 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 orFAIL_IOstates, soset_paramswill 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 bitUB_STATE_USEDis set on completion of thestart_dev; use it to detect and failset_paramscommands which arrive too late to be applied (afterstart_dev).
Quoted 1 line
[...]
Applied, thanks!
[1/1] ublk: set_params: properly check if parameters can be applied
(no commit info)
Best regards,
Signature · 1 line
Jens Axboe