Received: by 10.192.165.156 with SMTP id m28csp1124549imm; Wed, 11 Apr 2018 12:54:58 -0700 (PDT) X-Google-Smtp-Source: AIpwx489H2Q5BeRmkncMIlZrURquyi6BcnEOCsbU22mKlRenxW6OYJ8KAwoT9eX6VKR7sZZONZDa X-Received: by 10.99.3.17 with SMTP id 17mr3014370pgd.163.1523476498585; Wed, 11 Apr 2018 12:54:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523476498; cv=none; d=google.com; s=arc-20160816; b=Po5dnySkdvf159dZZGe8tlDzblb4+Abmt9/h133Ew5ngJvV7LASHuaNe+mQjgeRrWI qW5vO9u6xwsG8AGIo3lK6BjO/tiURCPp0iNNgOcWdIVQBueKqpdPdB5pKPXIkKgnxGCJ im+lM4daBJvFfBxAGz//KXIG2CXg7/aF+j78wMxvHzhFx+fanLNQHBlJryEAUe2V9ujq zxQm8iM8E8IbfkcxvqjVJxtOq8V1TaitXAIitUzBnanJkBt47yJO8KIZZj45QOJBZIdh tuIbVt+RWL92Pbp3MLHRpDTwtZObXsmfP8OFQV9/pPQVptj95lGuFMtQW0ZTj/UaYfRM yxCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=0RFtYbL+Zrdr6+CrfrvT7CVeS7k/lgw91O2itOBeg8c=; b=iVDSCHlfW3sefRVDYKXE/+YzpIqBeT6KNoB4LIoN09D+Iu5n/h59OgwcaY8iy6DYgX u/ecINzHtAzQVJg0X12n/WzQzqN3347Xz+XlVCRNw+xXx2r4feClE/TJByNDI0bEKocD pYtipckAepsm/ZIAbu06X5s3RlsG5tcbpQuw0elPFKjoQ6m4DBt/3y7sFit2tQt0xbo+ e2aQwEgWYkBDpWciYDyJCSfSlucWRj0nq2oImKTpiRE13Y7YZ+HbleLJLzbw1xm0Taor u/fBFUXamaDC12mOHUhT23YCLK7X3HYr/dCFWIvu8KNJRWAuyjc0xZR95jGWR9soHQ4x 6UjQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a61-v6si1737986pla.271.2018.04.11.12.54.22; Wed, 11 Apr 2018 12:54:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756558AbeDKS6i (ORCPT + 99 others); Wed, 11 Apr 2018 14:58:38 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:36738 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933961AbeDKS6g (ORCPT ); Wed, 11 Apr 2018 14:58:36 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 9EF1EDE8; Wed, 11 Apr 2018 18:58:35 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rafael David Tinoco , Lee Duncan , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.9 134/310] scsi: libiscsi: Allow sd_shutdown on bad transport Date: Wed, 11 Apr 2018 20:34:33 +0200 Message-Id: <20180411183628.227193305@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183622.305902791@linuxfoundation.org> References: <20180411183622.305902791@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rafael David Tinoco [ Upstream commit d754941225a7dbc61f6dd2173fa9498049f9a7ee ] If, for any reason, userland shuts down iscsi transport interfaces before proper logouts - like when logging in to LUNs manually, without logging out on server shutdown, or when automated scripts can't umount/logout from logged LUNs - kernel will hang forever on its sd_sync_cache() logic, after issuing the SYNCHRONIZE_CACHE cmd to all still existent paths. PID: 1 TASK: ffff8801a69b8000 CPU: 1 COMMAND: "systemd-shutdow" #0 [ffff8801a69c3a30] __schedule at ffffffff8183e9ee #1 [ffff8801a69c3a80] schedule at ffffffff8183f0d5 #2 [ffff8801a69c3a98] schedule_timeout at ffffffff81842199 #3 [ffff8801a69c3b40] io_schedule_timeout at ffffffff8183e604 #4 [ffff8801a69c3b70] wait_for_completion_io_timeout at ffffffff8183fc6c #5 [ffff8801a69c3bd0] blk_execute_rq at ffffffff813cfe10 #6 [ffff8801a69c3c88] scsi_execute at ffffffff815c3fc7 #7 [ffff8801a69c3cc8] scsi_execute_req_flags at ffffffff815c60fe #8 [ffff8801a69c3d30] sd_sync_cache at ffffffff815d37d7 #9 [ffff8801a69c3da8] sd_shutdown at ffffffff815d3c3c This happens because iscsi_eh_cmd_timed_out(), the transport layer timeout helper, would tell the queue timeout function (scsi_times_out) to reset the request timer over and over, until the session state is back to logged in state. Unfortunately, during server shutdown, this might never happen again. Other option would be "not to handle" the issue in the transport layer. That would trigger the error handler logic, which would also need the session state to be logged in again. Best option, for such case, is to tell upper layers that the command was handled during the transport layer error handler helper, marking it as DID_NO_CONNECT, which will allow completion and inform about the problem. After the session was marked as ISCSI_STATE_FAILED, due to the first timeout during the server shutdown phase, all subsequent cmds will fail to be queued, allowing upper logic to fail faster. Signed-off-by: Rafael David Tinoco Reviewed-by: Lee Duncan Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/libiscsi.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -1695,6 +1695,15 @@ int iscsi_queuecommand(struct Scsi_Host */ switch (session->state) { case ISCSI_STATE_FAILED: + /* + * cmds should fail during shutdown, if the session + * state is bad, allowing completion to happen + */ + if (unlikely(system_state != SYSTEM_RUNNING)) { + reason = FAILURE_SESSION_FAILED; + sc->result = DID_NO_CONNECT << 16; + break; + } case ISCSI_STATE_IN_RECOVERY: reason = FAILURE_SESSION_IN_RECOVERY; sc->result = DID_IMM_RETRY << 16; @@ -1980,6 +1989,19 @@ static enum blk_eh_timer_return iscsi_eh if (session->state != ISCSI_STATE_LOGGED_IN) { /* + * During shutdown, if session is prematurely disconnected, + * recovery won't happen and there will be hung cmds. Not + * handling cmds would trigger EH, also bad in this case. + * Instead, handle cmd, allow completion to happen and let + * upper layer to deal with the result. + */ + if (unlikely(system_state != SYSTEM_RUNNING)) { + sc->result = DID_NO_CONNECT << 16; + ISCSI_DBG_EH(session, "sc on shutdown, handled\n"); + rc = BLK_EH_HANDLED; + goto done; + } + /* * We are probably in the middle of iscsi recovery so let * that complete and handle the error. */ @@ -2083,7 +2105,7 @@ done: task->last_timeout = jiffies; spin_unlock(&session->frwd_lock); ISCSI_DBG_EH(session, "return %s\n", rc == BLK_EH_RESET_TIMER ? - "timer reset" : "nh"); + "timer reset" : "shutdown or nh"); return rc; }