From patchwork Fri May 13 22:15:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Cyr X-Patchwork-Id: 9093931 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5D94DBF29F for ; Fri, 13 May 2016 22:16:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 658582012B for ; Fri, 13 May 2016 22:16:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5264E20125 for ; Fri, 13 May 2016 22:16:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753848AbcEMWQL (ORCPT ); Fri, 13 May 2016 18:16:11 -0400 Received: from e35.co.us.ibm.com ([32.97.110.153]:54902 "EHLO e35.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753808AbcEMWQK (ORCPT ); Fri, 13 May 2016 18:16:10 -0400 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 13 May 2016 16:16:09 -0600 Received: from d03dlp01.boulder.ibm.com (9.17.202.177) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 13 May 2016 16:16:05 -0600 X-IBM-Helo: d03dlp01.boulder.ibm.com X-IBM-MailFrom: mikecyr@linux.vnet.ibm.com X-IBM-RcptTo: bcm-kernel-feedback-list@broadcom.com; jonmason@broadcom.com; rjui@broadcom.com; sbranden@broadcom.com; nab@linux-iscsi.org; linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org; linux-scsi@vger.kernel.org; target-devel@vger.kernel.org Received: from b01cxnp22034.gho.pok.ibm.com (b01cxnp22034.gho.pok.ibm.com [9.57.198.24]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id 812151FF0023; Fri, 13 May 2016 16:15:49 -0600 (MDT) Received: from b01ledav03.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u4DMG4Qm36438206; Fri, 13 May 2016 22:16:04 GMT Received: from b01ledav03.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 15257B204D; Fri, 13 May 2016 18:16:04 -0400 (EDT) Received: from vscsi-mike.rch.stglabs.ibm.com (unknown [9.5.249.31]) by b01ledav03.gho.pok.ibm.com (Postfix) with ESMTP id 8E076B2046; Fri, 13 May 2016 18:16:03 -0400 (EDT) From: Michael Cyr To: nab@linux-iscsi.org Cc: rjui@broadcom.com, sbranden@broadcom.com, jonmason@broadcom.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, Michael Cyr Subject: [PATCH] Fix for hang of Ordered task in TCM Date: Fri, 13 May 2016 17:15:41 -0500 Message-Id: <1463177741-4385-1-git-send-email-mikecyr@linux.vnet.ibm.com> X-Mailer: git-send-email 2.5.0 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16051322-0013-0000-0000-00003E951764 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If a command with a Simple task attribute is failed due to a Unit Attention, then a subsequent command with an Ordered task attribute will hang forever. The reason for this is that the Unit Attention status is checked for in target_setup_cmd_from_cdb, before the call to target_execute_cmd, which calls target_handle_task_attr, which in turn increments dev->simple_cmds. However, transport_generic_request_failure still calls transport_complete_task_attr, which will decrement dev->simple_cmds. In this case, simple_cmds is now -1. So when a command with the Ordered task attribute is sent, target_handle_task_attr sees that dev->simple_cmds is not 0, so it decides it can't execute the command until all the (nonexistent) Simple commands have completed. The solution I've implemented is to move target_scsi3_ua_check, as well as target_alua_state_check and target_check_reservation, into target_execute_cmd, after the call to target_handle_task_attr. I believe this is actually the correct way this should be handled. According to SAM-4 r14, under section 5.14: "h) if a command other than INQUIRY, REPORT LUNS, REQUEST SENSE, or NOTIFY DATA TRANSFER DEVICE enters the enabled command state while a unit attention condition exists for the SCSI initiator port associated with the I_T nexus on which the command was received, the device server shall terminate the command with a CHECK CONDITION status. The device server shall provide sense data that reports a unit attention condition for the SCSI initiator port that sent the command on the I_T nexus." But according to section 8.5 and 8.6, a command which is not yet executed because of the presence of other tasks in the task set (i.e., one for which target_handle_task_attr returns true) would not enter the enabled command state; it would be in the dormant command state. target_execute_cmd would get called when a command entered the enabled command state, and thus that is the appropriate place to check for Unit Attenion. Similarly, though not quite as explicit, section 5.3.3 tells us that a Reservation Conflict status has a lower precedence than a Unit Attention, and so this would also seem to be the appropriate place to call target_check_reservation. I'm less sure about target_alua_state_check, since I'm not very familiar with ALUA. Signed-off-by: Michael Cyr --- drivers/target/target_core_transport.c | 41 ++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 6c089af..2ee5502 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -1303,23 +1303,6 @@ target_setup_cmd_from_cdb(struct se_cmd *cmd, unsigned char *cdb) trace_target_sequencer_start(cmd); - /* - * Check for an existing UNIT ATTENTION condition - */ - ret = target_scsi3_ua_check(cmd); - if (ret) - return ret; - - ret = target_alua_state_check(cmd); - if (ret) - return ret; - - ret = target_check_reservation(cmd); - if (ret) { - cmd->scsi_status = SAM_STAT_RESERVATION_CONFLICT; - return ret; - } - ret = dev->transport->parse_cdb(cmd); if (ret == TCM_UNSUPPORTED_SCSI_OPCODE) pr_warn_ratelimited("%s/%s: Unsupported SCSI Opcode 0x%02x, sending CHECK_CONDITION.\n", @@ -1865,6 +1848,8 @@ static int __transport_check_aborted_status(struct se_cmd *, int); void target_execute_cmd(struct se_cmd *cmd) { + sense_reason_t ret; + /* * Determine if frontend context caller is requesting the stopping of * this command for frontend exceptions. @@ -1899,6 +1884,28 @@ void target_execute_cmd(struct se_cmd *cmd) return; } + /* + * Check for an existing UNIT ATTENTION condition + */ + ret = target_scsi3_ua_check(cmd); + if (ret) { + transport_generic_request_failure(cmd, ret); + return; + } + + ret = target_alua_state_check(cmd); + if (ret) { + transport_generic_request_failure(cmd, ret); + return; + } + + ret = target_check_reservation(cmd); + if (ret) { + cmd->scsi_status = SAM_STAT_RESERVATION_CONFLICT; + transport_generic_request_failure(cmd, ret); + return; + } + __target_execute_cmd(cmd); } EXPORT_SYMBOL(target_execute_cmd);