From patchwork Wed Feb 15 00:25:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 9573085 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CAD64600F6 for ; Wed, 15 Feb 2017 00:26:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE62A283F4 for ; Wed, 15 Feb 2017 00:26:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B192B2842B; Wed, 15 Feb 2017 00:26:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5189D283F4 for ; Wed, 15 Feb 2017 00:26:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750930AbdBOA0s (ORCPT ); Tue, 14 Feb 2017 19:26:48 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:10895 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750902AbdBOA0r (ORCPT ); Tue, 14 Feb 2017 19:26:47 -0500 X-IronPort-AV: E=Sophos;i="5.33,348,1477929600"; d="scan'208";a="86867837" Received: from unknown (HELO milsmgep15.sandisk.com) ([63.163.107.21]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2017 08:26:20 +0800 Received: from MILHUBIP04.sdcorp.global.sandisk.com (Unknown_Domain [10.201.67.162]) (using TLS with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by (Symantec Messaging Gateway) with SMTP id BB.E4.57638.C20A3A85; Tue, 14 Feb 2017 16:26:20 -0800 (PST) Received: from milsmgip11.sandisk.com (10.177.8.100) by MILHUBIP04.sdcorp.global.sandisk.com (10.177.9.97) with Microsoft SMTP Server id 14.3.319.2; Tue, 14 Feb 2017 16:26:15 -0800 X-AuditID: 0ac94369-26dee9800001e126-75-58a3a02c71ad Received: from exp-402881.sdcorp.global.sandisk.com ( [10.177.9.6]) by (Symantec Messaging Gateway) with SMTP id AE.7D.11415.720A3A85; Tue, 14 Feb 2017 16:26:15 -0800 (PST) From: Bart Van Assche To: "Nicholas A . Bellinger" CC: , Bart Van Assche , Hannes Reinecke , Christoph Hellwig , Andy Grover , David Disseldorp , Subject: [PATCH v6 19/33] target: Avoid that LUN reset sporadically triggers data corruption Date: Tue, 14 Feb 2017 16:25:58 -0800 Message-ID: <20170215002612.14566-20-bart.vanassche@sandisk.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170215002612.14566-1-bart.vanassche@sandisk.com> References: <20170215002612.14566-1-bart.vanassche@sandisk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrHLMWRmVeSWpSXmKPExsXCddJ5ka7OgsURBuvfmVjsn/WMyeLr/+ks Fgve7GWzWLn6KJNF2+ozjBYLNj5itGhd+pbJgd3j/vYjTB67bzawebzfd5XNY/2Wqywem09X e3zeJBfAFsVlk5Kak1mWWqRvl8CVcXG1YsF28YoVU76xNzCuEO5i5OSQEDCRmPH2KmsXIxeH kMBSJomOXX0sEM4ORon+hZ2MMFU7t89igkhsZJSY8OgdG0iCTcBI4tv7mSwgtgiQvbpnGVgR s8BXRonGvX+ZQBLCAjESUy8vYgaxWQRUJZq+tbGD2LwCDhKtDdeYITbIS+xqu8gKYnMCxWfs OAk0lANom73EozPWIDMlBJaxStxse8gI0SsocXLmE7DFzAISEgdfvACbIySgLnFyyXymCYxC s5CUzUJStoCRaRWjWG5mTnFuemqBoalecWJeSmZxtl5yfu4mRkgsZO5gvPvE+xCjAAejEg/v CdnFEUKsiWXFlbmHGCU4mJVEeNnqgUK8KYmVValF+fFFpTmpxYcYpTlYlMR5z8lMjRASSE8s Sc1OTS1ILYLJMnFwSjUwbvGutlt7dIW+z7uHRyxKW5xd3jwMX7twgkXXuzm7zf6dCNBg/Nxw Sndl+crExuUslnOndN16U/pz6Tzt/WsUlnsYF87iU2vwK+8xS97blqXPwVj35+h1rwyf7jUV kzlnZu3+OnlPkcNfrcUxwSe77vWuC1+2+PRHk7O5f76Xsl+L3aHSZPxtpRJLcUaioRZzUXEi AP7/DpeBAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrDJMWRmVeSWpSXmKPExsXCtZGTTVd9weIIg2MvVCz2z3rGZHHwZxuj xdf/01ksFrzZy2axcvVRJou21WcYLRZsfMRo0br0LZMDh8f97UeYPHbfbGDzeL/vKpvHtDXn mTzWb7nK4rH5dLXH501yAexRXDYpqTmZZalF+nYJXBkXVysWbBevWDHlG3sD4wrhLkZODgkB E4md22cxgdhCAusZJWY3eoLYbAJGEt/ez2QBsUWA7NU9y4BquDiYBb4zSlybtwesQVggRmLq 5UXMIDaLgKpE07c2dhCbV8BB4uihuSwQC+QldrVdZAWxOYHiM3acBIpzAC2zl3h0xnoCI/cC RoZVjGK5mTnFuemZBYaGesWJeSmZxdl6yfm5mxgh4RO5g/HpRPNDjEwcnFINjPPnuJzdu+NX tMi21BM7vwjHrDqfZdvYqv8zzVLaR2SC/DWnNd83aNucZChXOXpTW/navGN3DrZ57739hTVy X81GgTNPFA4H/Dbfc+qzh57PdTn9ZZlpkwV2m1asq/xdJB766+byjAkrp5QxW08OmPbsZ22J 74mCjR82r6wWTHlbIHB7+awNHN1KLMUZiYZazEXFiQAWYiTpzwEAAA== MIME-Version: 1.0 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If on an initiator system a LUN reset is issued while I/O is in progress with queue depth > 1, avoid that data corruption occurs as follows: - The initiator submits a READ (a). - The initiator submits a LUN reset before READ (a) completes. - The target responds that the LUN reset succeeded after READ (a) has been marked as CMD_T_COMPLETE and before .queue_status() has been called. - The initiator receives the LUN reset response and frees the tag used by READ (a). - The initiator submits READ (b) and reuses the tag of READ (a). - The initiator receives the response for READ (a) and interprets this as a completion for READ (b). - The initiator receives the completion for READ (b) and discards it. With the SRP initiator and target drivers and when running fio concurrently with sg_reset -d it only takes a few minutes to reproduce this. Signed-off-by: Bart Van Assche Fixes: commit febe562c20df ("target: Fix LUN_RESET active I/O handling for ACK_KREF") Cc: Hannes Reinecke Cc: Christoph Hellwig Cc: Andy Grover Cc: David Disseldorp Cc: --- drivers/target/target_core_tmr.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c index 32ea7c61d6ac..16e748eb32d2 100644 --- a/drivers/target/target_core_tmr.c +++ b/drivers/target/target_core_tmr.c @@ -109,7 +109,7 @@ static int target_check_cdb_and_preempt(struct list_head *list, return 1; } -static bool __target_check_io_state(struct se_cmd *se_cmd, +static bool __target_check_io_state(struct se_cmd *se_cmd, u32 skip_flags, struct se_session *tmr_sess, int tas) { struct se_session *sess = se_cmd->se_sess; @@ -127,7 +127,7 @@ static bool __target_check_io_state(struct se_cmd *se_cmd, * long as se_cmd->cmd_kref is still active unless zero. */ spin_lock(&se_cmd->t_state_lock); - if (se_cmd->transport_state & (CMD_T_COMPLETE | CMD_T_FABRIC_STOP)) { + if (se_cmd->transport_state & (skip_flags | CMD_T_FABRIC_STOP)) { pr_debug("Attempted to abort io tag: %llu already complete or" " fabric stop, skipping\n", se_cmd->tag); spin_unlock(&se_cmd->t_state_lock); @@ -182,7 +182,8 @@ void core_tmr_abort_task( printk("ABORT_TASK: Found referenced %s task_tag: %llu\n", se_cmd->se_tfo->get_fabric_name(), ref_tag); - if (!__target_check_io_state(se_cmd, se_sess, 0)) + if (!__target_check_io_state(se_cmd, CMD_T_COMPLETE, se_sess, + 0)) continue; list_del_init(&se_cmd->se_cmd_list); @@ -354,7 +355,7 @@ static void core_tmr_drain_state_list( continue; spin_lock(&sess->sess_cmd_lock); - rc = __target_check_io_state(cmd, tmr_sess, tas); + rc = __target_check_io_state(cmd, 0, tmr_sess, tas); spin_unlock(&sess->sess_cmd_lock); if (!rc) continue;