From patchwork Mon Sep 17 21:35:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10603497 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6BF471508 for ; Mon, 17 Sep 2018 22:20:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E8E72A835 for ; Mon, 17 Sep 2018 22:20:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 531982A7B0; Mon, 17 Sep 2018 22:20:36 +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=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,T_DKIM_INVALID 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 DD1272A76B for ; Mon, 17 Sep 2018 22:20:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728202AbeIRDt1 (ORCPT ); Mon, 17 Sep 2018 23:49:27 -0400 Received: from out002.mailprotect.be ([83.217.72.86]:36931 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728023AbeIRDt1 (ORCPT ); Mon, 17 Sep 2018 23:49:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=227ZhvLDPT6kbAc7yXMDneFwaiqr/l/EeS7UAUBotSc=; b=TTv5D2sI5553 CxvOZoRwRd0BLI6orueO3msRh/aNFvJsbohwfi4PUaWeZcHtlKu94J88cPCuOBZUaFPBo6nMvV2cx XO3bfBo95Sf/qKn39kNrCrl+bUENlhJTftk5i7jw/oGkjQKaaJN9YMPqo/LoWuUxJERk4S1pedlVQ Xae5nPA4vvAX8qj0aNa7m4LMZRx2W03SR/9+noeaGjdZTbOV7DCZO8Aa7o9Lp+fHQ+X5/w3RMmNxJ N6MkopddXKDKMRwn5Am3vPpyfmkt4ldeI+DxpH03PMQKqCrTYBfi8FSoHDTh2lIcMuSOLEoVyQyVc g65UbKJisWcVfLt4uEGo5Q==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1g21C7-0002jU-5L; Mon, 17 Sep 2018 23:36:35 +0200 Received: from asus.hsd1.ca.comcast.net (c-174-62-111-89.hsd1.ca.comcast.net [174.62.111.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id E8BF5C0771; Mon, 17 Sep 2018 23:36:32 +0200 (CEST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Christoph Hellwig , target-devel@vger.kernel.org, Bart Van Assche , Nicholas Bellinger , Mike Christie , Hannes Reinecke , stable@vger.kernel.org Subject: [PATCH 13/17] target/core: Avoid that LUN reset sporadically triggers data corruption Date: Mon, 17 Sep 2018 14:35:50 -0700 Message-Id: <20180917213554.987-14-bvanassche@acm.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180917213554.987-1-bvanassche@acm.org> References: <20180917213554.987-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.02) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5kVqA2dtAWGPMJ2Mihl7xJF602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3WlZa4xKvcBORT2AGmYYKfa2w4nwtOiKlIdftXY5+/HTLBPB4loq3vFboQ7gxpx2K5q243j OywFphhx6RtIX3/eBU519jxvHYi8yYUXqBwxztbjuU58k6ddZEUemp+2z708nJwgsskeL6jfWDvk QqiSTWUth/bIg1D/4cblfXFvIrwhcbIgt0qoJA65s+aV0TNSu4Q1sJN0pTPPGPEcb1FCr3OnWExh FqqXKjnbUDBzcE+0HNyHhfqG0xcyQsZuCSPCjEi4ZwcU35NfL3zG7gtHj8xG2HbE6AX2FmEJ2JNQ xdpvnw+pYth8G0cQXB2J3taT9DS0dkB4Cnwl7xB5kr0QjBtk6zyNLmG5bRMyUWLGmHSsrvE5ol3t DswyoeVJL6fJ0IdteI/zTbpcDI9MsmV317NirEYyqwqMBGrw8ELiqO024LKrdtbNRVNrB1ymm5TN sFlW4xzv3KSabGJbxYTPMIwgbvzZDfnPtxft9hhq2K+cGqR018mIinnrbkyUvY39mkdHzbUjd6PR fLJZDPRgASJFC/49WOPBr5nlEUI4xL3dT292+RbQjttUVlvdrnQK1sSC7J3Hv785O0oOR7DFJ8f1 27NbbfLBGyoHMieTevVmyL2W0wef24nctTTtGWg/yUagnQaXyaC6KIW3Zw2W4ALym497HobEjrNo 920r6J7h+6WGdIozr5wlI+42MBS2BmRxGQKegzOmzXDxmXJaEt/rrhd0Ad/KzJc3ipVTvDLBaj7x n3y04yFb3o8g6ZY8w82pDoLhPk/lf5mMYW2AUV8ShebT8U8Xw9HTDfreWc6MR/KF9WYMVDiJkeBJ ugHtjJJ9zWA1YcmbfLIiESkK13UupgL/nVjDr83pKqAAV1C/LbdJldJ8xntHMcYfWXY/0ZGUgCz6 J0vyjCq2codJfJXroJbe3tWHWhaZBVomye7J//0XCxCMJn8bXo41UD1l14eTZ9+J4NUPiLLTxmKL KRxciOek6ii6SBLP4eECdy8Q8VZY22my9mmJfVrcFBg= X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be 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: Nicholas Bellinger Cc: Mike Christie Cc: Christoph Hellwig Cc: Hannes Reinecke 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 2750a2c7b563..6e419396c1e4 100644 --- a/drivers/target/target_core_tmr.c +++ b/drivers/target/target_core_tmr.c @@ -90,7 +90,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; @@ -108,7 +108,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); @@ -165,7 +165,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; spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); @@ -349,7 +350,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;