Re: [PATCH v2 2/2] scsi: ufs: core: Decouple CQ sweep from request iterator in MCQ

From: Bart Van Assche

Date: Fri Sep 25 2026 - 13:26:55 EST


On 9/23/26 10:02 AM, Bart Van Assche wrote:
On 9/23/26 4:18 AM, Stanley Jhu wrote:
Would DID_RESET be a better fit after a controller reset (including
ufshcd_eh_timed_out() right after ufshcd_link_recovery()), similar
to mpi3mr_flush_scmd() and mpt3sas's _scsih_flush_running_cmds()?
It reports what the driver actually knows at that point without
pulling the command into the SCSI error handler.

Calling scsi_done() from a .eh_host_reset_handler() implementation is
not allowed because calling scsi_done() for a command that is on the
SCSI error handler list corrupts that list. One of the functions called
by scsi_done() is scsi_complete(). From that function:

    INIT_LIST_HEAD(&cmd->eh_entry);

This corrupts the command lists maintained by the SCSI error handler,
e.g. work_q and done_q.

A correction: the INIT_LIST_HEAD(&cmd->eh_entry) statement is not
reached while SCSI host recovery is in progress because
SCMD_STATE_COMPLETE is set for all pending commands before the SCSI
host recovery starts. scsi_done() skips SCSI commands for which that
bit is set due to the following code:

if (unlikely(test_and_set_bit(SCMD_STATE_COMPLETE, &cmd->state)))
return;

Hence, the scmd->result value is ignored if scsi_done() is called
while SCSI host recovery is in progress.

Bart.