Skip to content

Commit 8d83251

Browse files
jiangyilismgregkh
authored andcommitted
target: Fix COMPARE_AND_WRITE caw_sem leak during se_cmd quiesce
commit 1d6ef276594a781686058802996e09c8550fd767 upstream. This patch addresses a COMPARE_AND_WRITE se_device->caw_sem leak, that would be triggered during normal se_cmd shutdown or abort via __transport_wait_for_tasks(). This would occur because target_complete_cmd() would catch this early and do complete_all(&cmd->t_transport_stop_comp), but since target_complete_ok_work() or target_complete_failure_work() are never called to invoke se_cmd->transport_complete_callback(), the COMPARE_AND_WRITE specific callbacks never release caw_sem. To address this special case, go ahead and release caw_sem directly from target_complete_cmd(). (Remove '&& success' from check, to release caw_sem regardless of scsi_status - nab) Signed-off-by: Jiang Yi <jiangyilism@gmail.com> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f57b4ae commit 8d83251

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

drivers/target/target_core_transport.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,15 @@ void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status)
728728
if (cmd->transport_state & CMD_T_ABORTED ||
729729
cmd->transport_state & CMD_T_STOP) {
730730
spin_unlock_irqrestore(&cmd->t_state_lock, flags);
731+
/*
732+
* If COMPARE_AND_WRITE was stopped by __transport_wait_for_tasks(),
733+
* release se_device->caw_sem obtained by sbc_compare_and_write()
734+
* since target_complete_ok_work() or target_complete_failure_work()
735+
* won't be called to invoke the normal CAW completion callbacks.
736+
*/
737+
if (cmd->se_cmd_flags & SCF_COMPARE_AND_WRITE) {
738+
up(&dev->caw_sem);
739+
}
731740
complete_all(&cmd->t_transport_stop_comp);
732741
return;
733742
} else if (!success) {

0 commit comments

Comments
 (0)