Commit cd5432c7 authored by Weitao Wang's avatar Weitao Wang Committed by Greg Kroah-Hartman

USB: UAS: return ENODEV when submit urbs fail with device not attached

In the scenario of entering hibernation with udisk in the system, if the
udisk was gone or resume fail in the thaw phase of hibernation. Its state
will be set to NOTATTACHED. At this point, usb_hub_wq was already freezed
and can't not handle disconnect event. Next, in the poweroff phase of
hibernation, SYNCHRONIZE_CACHE SCSI command will be sent to this udisk
when poweroff this scsi device, which will cause uas_submit_urbs to be
called to submit URB for sense/data/cmd pipe. However, these URBs will
submit fail as device was set to NOTATTACHED state. Then, uas_submit_urbs
will return a value SCSI_MLQUEUE_DEVICE_BUSY to the caller. That will lead
the SCSI layer go into an ugly loop and system fail to go into hibernation.

On the other hand, when we specially check for -ENODEV in function
uas_queuecommand_lck, returning DID_ERROR to SCSI layer will cause device
poweroff fail and system shutdown instead of entering hibernation.

To fix this issue, let uas_submit_urbs to return original generic error
when submitting URB failed. At the same time, we need to translate -ENODEV
to DID_NOT_CONNECT for the SCSI layer.
Suggested-by: default avatarOliver Neukum <oneukum@suse.com>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarWeitao Wang <WeitaoWang-oc@zhaoxin.com>
Link: https://lore.kernel.org/r/20240306180814.4897-1-WeitaoWang-oc@zhaoxin.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 4cece764
...@@ -533,7 +533,7 @@ static struct urb *uas_alloc_cmd_urb(struct uas_dev_info *devinfo, gfp_t gfp, ...@@ -533,7 +533,7 @@ static struct urb *uas_alloc_cmd_urb(struct uas_dev_info *devinfo, gfp_t gfp,
* daft to me. * daft to me.
*/ */
static struct urb *uas_submit_sense_urb(struct scsi_cmnd *cmnd, gfp_t gfp) static int uas_submit_sense_urb(struct scsi_cmnd *cmnd, gfp_t gfp)
{ {
struct uas_dev_info *devinfo = cmnd->device->hostdata; struct uas_dev_info *devinfo = cmnd->device->hostdata;
struct urb *urb; struct urb *urb;
...@@ -541,30 +541,28 @@ static struct urb *uas_submit_sense_urb(struct scsi_cmnd *cmnd, gfp_t gfp) ...@@ -541,30 +541,28 @@ static struct urb *uas_submit_sense_urb(struct scsi_cmnd *cmnd, gfp_t gfp)
urb = uas_alloc_sense_urb(devinfo, gfp, cmnd); urb = uas_alloc_sense_urb(devinfo, gfp, cmnd);
if (!urb) if (!urb)
return NULL; return -ENOMEM;
usb_anchor_urb(urb, &devinfo->sense_urbs); usb_anchor_urb(urb, &devinfo->sense_urbs);
err = usb_submit_urb(urb, gfp); err = usb_submit_urb(urb, gfp);
if (err) { if (err) {
usb_unanchor_urb(urb); usb_unanchor_urb(urb);
uas_log_cmd_state(cmnd, "sense submit err", err); uas_log_cmd_state(cmnd, "sense submit err", err);
usb_free_urb(urb); usb_free_urb(urb);
return NULL;
} }
return urb; return err;
} }
static int uas_submit_urbs(struct scsi_cmnd *cmnd, static int uas_submit_urbs(struct scsi_cmnd *cmnd,
struct uas_dev_info *devinfo) struct uas_dev_info *devinfo)
{ {
struct uas_cmd_info *cmdinfo = scsi_cmd_priv(cmnd); struct uas_cmd_info *cmdinfo = scsi_cmd_priv(cmnd);
struct urb *urb;
int err; int err;
lockdep_assert_held(&devinfo->lock); lockdep_assert_held(&devinfo->lock);
if (cmdinfo->state & SUBMIT_STATUS_URB) { if (cmdinfo->state & SUBMIT_STATUS_URB) {
urb = uas_submit_sense_urb(cmnd, GFP_ATOMIC); err = uas_submit_sense_urb(cmnd, GFP_ATOMIC);
if (!urb) if (err)
return SCSI_MLQUEUE_DEVICE_BUSY; return err;
cmdinfo->state &= ~SUBMIT_STATUS_URB; cmdinfo->state &= ~SUBMIT_STATUS_URB;
} }
...@@ -572,7 +570,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, ...@@ -572,7 +570,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd,
cmdinfo->data_in_urb = uas_alloc_data_urb(devinfo, GFP_ATOMIC, cmdinfo->data_in_urb = uas_alloc_data_urb(devinfo, GFP_ATOMIC,
cmnd, DMA_FROM_DEVICE); cmnd, DMA_FROM_DEVICE);
if (!cmdinfo->data_in_urb) if (!cmdinfo->data_in_urb)
return SCSI_MLQUEUE_DEVICE_BUSY; return -ENOMEM;
cmdinfo->state &= ~ALLOC_DATA_IN_URB; cmdinfo->state &= ~ALLOC_DATA_IN_URB;
} }
...@@ -582,7 +580,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, ...@@ -582,7 +580,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd,
if (err) { if (err) {
usb_unanchor_urb(cmdinfo->data_in_urb); usb_unanchor_urb(cmdinfo->data_in_urb);
uas_log_cmd_state(cmnd, "data in submit err", err); uas_log_cmd_state(cmnd, "data in submit err", err);
return SCSI_MLQUEUE_DEVICE_BUSY; return err;
} }
cmdinfo->state &= ~SUBMIT_DATA_IN_URB; cmdinfo->state &= ~SUBMIT_DATA_IN_URB;
cmdinfo->state |= DATA_IN_URB_INFLIGHT; cmdinfo->state |= DATA_IN_URB_INFLIGHT;
...@@ -592,7 +590,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, ...@@ -592,7 +590,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd,
cmdinfo->data_out_urb = uas_alloc_data_urb(devinfo, GFP_ATOMIC, cmdinfo->data_out_urb = uas_alloc_data_urb(devinfo, GFP_ATOMIC,
cmnd, DMA_TO_DEVICE); cmnd, DMA_TO_DEVICE);
if (!cmdinfo->data_out_urb) if (!cmdinfo->data_out_urb)
return SCSI_MLQUEUE_DEVICE_BUSY; return -ENOMEM;
cmdinfo->state &= ~ALLOC_DATA_OUT_URB; cmdinfo->state &= ~ALLOC_DATA_OUT_URB;
} }
...@@ -602,7 +600,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, ...@@ -602,7 +600,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd,
if (err) { if (err) {
usb_unanchor_urb(cmdinfo->data_out_urb); usb_unanchor_urb(cmdinfo->data_out_urb);
uas_log_cmd_state(cmnd, "data out submit err", err); uas_log_cmd_state(cmnd, "data out submit err", err);
return SCSI_MLQUEUE_DEVICE_BUSY; return err;
} }
cmdinfo->state &= ~SUBMIT_DATA_OUT_URB; cmdinfo->state &= ~SUBMIT_DATA_OUT_URB;
cmdinfo->state |= DATA_OUT_URB_INFLIGHT; cmdinfo->state |= DATA_OUT_URB_INFLIGHT;
...@@ -611,7 +609,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, ...@@ -611,7 +609,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd,
if (cmdinfo->state & ALLOC_CMD_URB) { if (cmdinfo->state & ALLOC_CMD_URB) {
cmdinfo->cmd_urb = uas_alloc_cmd_urb(devinfo, GFP_ATOMIC, cmnd); cmdinfo->cmd_urb = uas_alloc_cmd_urb(devinfo, GFP_ATOMIC, cmnd);
if (!cmdinfo->cmd_urb) if (!cmdinfo->cmd_urb)
return SCSI_MLQUEUE_DEVICE_BUSY; return -ENOMEM;
cmdinfo->state &= ~ALLOC_CMD_URB; cmdinfo->state &= ~ALLOC_CMD_URB;
} }
...@@ -621,7 +619,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, ...@@ -621,7 +619,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd,
if (err) { if (err) {
usb_unanchor_urb(cmdinfo->cmd_urb); usb_unanchor_urb(cmdinfo->cmd_urb);
uas_log_cmd_state(cmnd, "cmd submit err", err); uas_log_cmd_state(cmnd, "cmd submit err", err);
return SCSI_MLQUEUE_DEVICE_BUSY; return err;
} }
cmdinfo->cmd_urb = NULL; cmdinfo->cmd_urb = NULL;
cmdinfo->state &= ~SUBMIT_CMD_URB; cmdinfo->state &= ~SUBMIT_CMD_URB;
...@@ -698,7 +696,7 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd) ...@@ -698,7 +696,7 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd)
* of queueing, no matter how fatal the error * of queueing, no matter how fatal the error
*/ */
if (err == -ENODEV) { if (err == -ENODEV) {
set_host_byte(cmnd, DID_ERROR); set_host_byte(cmnd, DID_NO_CONNECT);
scsi_done(cmnd); scsi_done(cmnd);
goto zombie; goto zombie;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment