All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Fix SCSI & USB Storage CHECK CONDITION handling
@ 2019-09-26 22:08 Damien Le Moal
  2019-09-26 22:08 ` [PATCH 1/2] scsi: save/restore command resid for error handling Damien Le Moal
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Damien Le Moal @ 2019-09-26 22:08 UTC (permalink / raw)
  To: linux-scsi, Martin K . Petersen, linux-usb, usb-storage,
	Alan Stern, Greg Kroah-Hartman
  Cc: Justin Piszcz

If a non-passthrough command is terminated with a CHECK CONDITION, the
scsi error recovery code reuses the failed command scsi_cmnd structure
to process error recovery request sense. To preserve information
regarding the failed command, the functions scsi_eh_prep_cmnd() and
scsi_eh_restore_cmnd() respectively save and restore the original
command information. However, the resid field of the failed command
request structure is not preserved and reused for the request sense
handling, leading to the original command having an incorrect resid
when:
A) The command is not retried and terminated with an error
B) The command completes after retry and the underlying LLD does not set
   resid for a fully completed command (resid=0)

The first patch of this series addresses case (A) above by adding resid
as part of the command information saved using struct scsi_eh_save.

Case B can be observed with a WD My Book USB disks when a read or write
command is sent to the disk while the disk is in deep sleep mode
(spun down) due to a long period of inactivity (~30min).
In such case, the following command sequence happen:
1) The read or write command is terminated after a few seconds with
   CHECK CONDITION and an asc/ascq of 04/01 (LOGICAL UNIT IS IN PROCESS
   OF BECOMING READY)
2) In response to this failure, the USB mass storage driver triggers
   autosense processing, reusing the command descriptor to issue a
   request sense command with a 96B sense buffer size. The reply
   to this command gives a NOT READY / LOGICAL UNIT IS IN PROCESS
   OF BECOMING READY sense of 18B, resulting in a resid of 78B.
3) The original command is retried and failed again, with step 2
   repeated, until the drive spins up and becomes ready.
4) When the original command completes after the drive has become ready,
   the request sense command resid of 78B is seen by the scsi disk
   driver sd_done() function and wrongly generates a warning about the
   unaligned value reported.

This problem is fixed in patch 2 by always setting a command resid to 0
when there is no residual in usb_stor_Bulk_transport(). Note that
usb_stor_CB_transport() does not need changes since usb_stor_bulk_srb()
always sets the resid for a completed command, regardless of the
residual value.

Damien Le Moal (2):
  scsi: save/restore command resid for error handling
  usb: Clear scsi command resid when residue is 0

 drivers/scsi/scsi_error.c       | 2 ++
 drivers/usb/storage/transport.c | 9 +++++++++
 include/scsi/scsi_eh.h          | 1 +
 3 files changed, 12 insertions(+)

-- 
2.21.0


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

end of thread, other threads:[~2019-09-27 23:41 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-26 22:08 [PATCH 0/2] Fix SCSI & USB Storage CHECK CONDITION handling Damien Le Moal
2019-09-26 22:08 ` [PATCH 1/2] scsi: save/restore command resid for error handling Damien Le Moal
2019-09-27 19:20   ` Christoph Hellwig
2019-09-26 22:08 ` [PATCH 2/2] usb: Clear scsi command resid when residue is 0 Damien Le Moal
2019-09-26 23:57 ` [PATCH 0/2] Fix SCSI & USB Storage CHECK CONDITION handling Alan Stern
2019-09-27  0:17   ` Damien Le Moal
2019-09-27 16:34     ` Alan Stern
2019-09-27 20:51       ` Damien Le Moal
2019-09-27  0:54   ` Douglas Gilbert
2019-09-27 14:11     ` Alan Stern
2019-09-27 23:33       ` Finn Thain

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.