Received: by 10.213.65.68 with SMTP id h4csp1864346imn; Mon, 19 Mar 2018 15:38:20 -0700 (PDT) X-Google-Smtp-Source: AG47ELtDoxd38w6GL3yfwmlLGyHGGH0umQGWFIS3G63b6s8VY08/dESbW479vEig7cKuwAs9UcIM X-Received: by 10.98.254.5 with SMTP id z5mr11266124pfh.53.1521499100096; Mon, 19 Mar 2018 15:38:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521499100; cv=none; d=google.com; s=arc-20160816; b=x9JjtoTHsFgkZHBK5/TzeJvMxLRioX8KgsNP/hjg1qdV3W/is4kENjWUOYA3ma9Frq XhYAGxQDUOXhxK5pe6mA/0cf9A+9vX9KcowlRZuyK6FrOc17F9Ec2GjThbvAeu0UYS3Q 7eeR08ZatXQiUXtu53Nm8W75mq2d1XqryMpCgSplJ2o8QFdnq/I44hC/8dKS0fhCNNOe DGbgNd9nCmdFnbkjAoPQ89hS8tRbnIqYooPmqIpxQEphDLopqlddRbmMvWYv27ZfD/I9 Eb0sCOK87CRE7Ei2ltsnSLW/WLjzPpiDashAINI7Xs7sck6LeWB9VyHNvrUr8Wiclp5x huCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=deZ4f9jrUmmBex2xyB2YBviy5UOxE/WsFEfWPq9GzaY=; b=GhmXxYqs4cpLlgmLWVnfiTWXq1DI6HmuG40sPYAUR7Izmr59F4pskIlXlbmg0QRfQN 6Yhy4/MD4mfErbbhasZcg6Tt+5gHE1Q5JgF8uPHGGA5W+edfVsA3Wbj3TCm09zWkF07Q uvjBm9PWXf/vq1MErzblDCKoBA0EQUt1OKQnBuEXDB67iFDn6UMe5feoMss49i/9wzNE 6Cqbj0K09VvWz0h7w2t1/Bt0oRrY2MFJtC7Y2rwHK31NdRu7gYRMlSQMXn3J5b3RZlKl a0ooOIUSZRgQDPdn0/DvZTjHthqSZaYoOuEcXRaaMTRD1rkpZZv4TpT/HnctbKxwHq1r sNLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=VhTqssGK; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o5si146120pgp.16.2018.03.19.15.38.05; Mon, 19 Mar 2018 15:38:20 -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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=VhTqssGK; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936618AbeCSWcs (ORCPT + 99 others); Mon, 19 Mar 2018 18:32:48 -0400 Received: from mail-cys01nam02on0114.outbound.protection.outlook.com ([104.47.37.114]:45246 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933743AbeCSPsQ (ORCPT ); Mon, 19 Mar 2018 11:48:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=deZ4f9jrUmmBex2xyB2YBviy5UOxE/WsFEfWPq9GzaY=; b=VhTqssGKk7p9fmvPVNMbskDVc77iji7eLuTutk2qtOngcAR+OBPIg7Lb9pE6gxTlbRqi+yx7VuC8cIV3MuKytDwMbbW3LQV/f+4TGkJnPq/DQo+zO5fvDorDI90UQVqsBwRGNI9TuMDh4aLL9HcYMaP8mK00TphPfy6LuyfBmhU= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0998.namprd21.prod.outlook.com (52.132.133.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.631.0; Mon, 19 Mar 2018 15:48:08 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62%5]) with mapi id 15.20.0631.004; Mon, 19 Mar 2018 15:48:07 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Rafael David Tinoco , "Martin K . Petersen" , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 042/124] scsi: libiscsi: Allow sd_shutdown on bad transport Thread-Topic: [PATCH AUTOSEL for 4.15 042/124] scsi: libiscsi: Allow sd_shutdown on bad transport Thread-Index: AQHTv5me19rM7eGT10efgf7r5+aZxQ== Date: Mon, 19 Mar 2018 15:47:43 +0000 Message-ID: <20180319154645.11350-42-alexander.levin@microsoft.com> References: <20180319154645.11350-1-alexander.levin@microsoft.com> In-Reply-To: <20180319154645.11350-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0998;7:/VOGyAs1kCYgWC68t63RCDN3YRhsUVnsDJx71ZAAUYZUgETC5xVP3jlW7THspL83ecNTmQ9Dtq843mk1zu6Y8a+qDCAjE8ZSlaYAGCW8Nfi/zyHrYol4k65ipcJgJWMJOzFlL8yLHrRrIZXqFCRhPao244BGO/1AdEG+zJfjLpNHDozdgM764GK15Iys5e7Xo7J/BZQfQQgsaoSNwA7yMde/SoykXAI3LTYUyvfYVfCokpmaNPLjeKuIzgOWhb/8;20:qezdnEJCSNzsKBVgbV8x18JFxBOQb+VHqH2mdKMOgX+FPYU/P4Nujum9/0ai0ZCl6WzqJnAvYGt4ACJ/gZdeB8FtFhNJb/zJkvGztSee9V/En199Erhx3YheBdw1bD+5nAWRmAIbQoQtJf0T9J0yYRlHaC2nizG/cOPyrVgl12I= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 60553372-dc19-46df-7e7e-08d58db0cf9c x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0998; x-ms-traffictypediagnostic: DM5PR2101MB0998: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(158342451672863)(89211679590171)(146099531331640)(198206253151910); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3231221)(944501300)(52105095)(3002001)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0998;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0998; x-forefront-prvs: 06167FAD59 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(39860400002)(366004)(376002)(396003)(346002)(199004)(189003)(3846002)(6116002)(8936002)(6486002)(102836004)(68736007)(6506007)(2900100001)(22452003)(25786009)(3660700001)(7736002)(76176011)(6512007)(72206003)(86362001)(575784001)(53936002)(8676002)(81156014)(6436002)(81166006)(305945005)(478600001)(99286004)(2950100002)(14454004)(6666003)(10290500003)(186003)(107886003)(2501003)(106356001)(26005)(86612001)(97736004)(5660300001)(10090500001)(110136005)(54906003)(316002)(2906002)(66066001)(105586002)(4326008)(36756003)(3280700002)(1076002)(5250100002)(59450400001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0998;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: HXz1ncxq68gMMSniyBaGRB87X38H/hKlQrD5VAvn8hk4Us66TODL1YB0hO7xfLmAxvcfts/gkW9Rv8SNHVq0JDblvwzaTisI4tXZirnX/ob/HTgp0z8fumWNj1TQvI3cTIAhl4wElHsSW0dEia00rWU8uJ8r1R5kk1mefQ56BXyem95JYcCgVoVoOSuO/8AjOrwa0WyRTcjoOWDVmPeb+DQgesI+kLdDTlwvgvgi35QgiYAilnowNguyO/q4um4feBH+y+6fRUS85t7KWJKADNBWazq36KzGgOFLIavUabOANh89qUhJW0locnEGamVvLYt+KiCX2PTVoDH6aEH8Pg== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 60553372-dc19-46df-7e7e-08d58db0cf9c X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2018 15:47:43.0699 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0998 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/scsi/libiscsi.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index 9c50d2d9f27c..785d1c55d152 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -1696,6 +1696,15 @@ int iscsi_queuecommand(struct Scsi_Host *host, struc= t scsi_cmnd *sc) */ 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 !=3D SYSTEM_RUNNING)) { + reason =3D FAILURE_SESSION_FAILED; + sc->result =3D DID_NO_CONNECT << 16; + break; + } case ISCSI_STATE_IN_RECOVERY: reason =3D FAILURE_SESSION_IN_RECOVERY; sc->result =3D DID_IMM_RETRY << 16; @@ -1978,6 +1987,19 @@ enum blk_eh_timer_return iscsi_eh_cmd_timed_out(stru= ct scsi_cmnd *sc) } =20 if (session->state !=3D 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 !=3D SYSTEM_RUNNING)) { + sc->result =3D DID_NO_CONNECT << 16; + ISCSI_DBG_EH(session, "sc on shutdown, handled\n"); + rc =3D BLK_EH_HANDLED; + goto done; + } /* * We are probably in the middle of iscsi recovery so let * that complete and handle the error. @@ -2082,7 +2104,7 @@ enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struc= t scsi_cmnd *sc) task->last_timeout =3D jiffies; spin_unlock(&session->frwd_lock); ISCSI_DBG_EH(session, "return %s\n", rc =3D=3D BLK_EH_RESET_TIMER ? - "timer reset" : "nh"); + "timer reset" : "shutdown or nh"); return rc; } EXPORT_SYMBOL_GPL(iscsi_eh_cmd_timed_out); --=20 2.14.1