Received: by 10.213.65.68 with SMTP id h4csp2118693imn; Sun, 8 Apr 2018 20:10:07 -0700 (PDT) X-Google-Smtp-Source: AIpwx493DMUlxeELyuK7V3QJJgCv41lc9XhrIWSKFoUJEAjwjajOJwMyqXzp7lcM2mbwGGk0GUyV X-Received: by 10.98.138.205 with SMTP id o74mr27879009pfk.114.1523243407730; Sun, 08 Apr 2018 20:10:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243407; cv=none; d=google.com; s=arc-20160816; b=EusSmoFsh0ltW0OZ3kU1BKBTWsMjTP56zltuRDilfzHtgPl357RBqTkia15/+flpuB c+0gerH/XRToo1Kh8x6bpYECOJUVqeve7Zmm0PCqtjNzswCOZ4LYDauLKAZ/XKs1Xzfp +nHVDTXJLp2CxYG+H0DGv1FMtGGcsRetw05LwHtIy7QJRlGgVn1KhWQcDnYf8E7yTFpP 05uXswvw48O3LLQfiwk9zFuOhvZtqeMjdxNk2yS3A3vVmQf7knN2roSP6nE1R8/gxHx8 cuYVMyjtLKNowrjVkYOZ6AFJxCTeVTGsBX9+iRenpP7LWUq50ePNYf3R2fQt8C8fCCLX TlTw== 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=9bAY5ZNTGffjTx57TVlw1PVfEb0OUE6f+PC5IWDjfUo=; b=CUaZCZgKxtGKi0HFL9YDwCPzh1i2TJVPTwH+xxxK/kQnGeOpEF2VYihPgPGqC887Wa cgV49zqXiQCUFg1/scdDWxfKopYSDX3eipvNl/luGAEyoCGZx7dYBiBuIeIVg1fagfR9 vINZdKExKRY0Ir0u+xryFyNddoM7JCQ22VmaQK/rHUHLV0NR7KC+7TrISROT4wWleYZH GSiP+CCY5Ho4igCqdsvYI+TNOvK1UYGHUv3TvdLr3nsUgraHJtB+ZqfdcUeyvSVSWc0/ f8YP4Vp9dkASFOHcHXd0uDsreNiHSTrq51/VidxKqVMP+wOzeaWzvAFtwFIctzU+AnCw l56A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=PkxRXfZT; 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 v8si9887110pfm.241.2018.04.08.20.09.30; Sun, 08 Apr 2018 20:10:07 -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=PkxRXfZT; 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 S933179AbeDICs5 (ORCPT + 99 others); Sun, 8 Apr 2018 22:48:57 -0400 Received: from mail-by2nam01on0099.outbound.protection.outlook.com ([104.47.34.99]:2811 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755330AbeDIA0g (ORCPT ); Sun, 8 Apr 2018 20:26:36 -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=9bAY5ZNTGffjTx57TVlw1PVfEb0OUE6f+PC5IWDjfUo=; b=PkxRXfZTeNE7MRU5FU+AFdpoidqVYbIjuKagOLppisASEuQkrWTVI1CTHdO5ObKoU1MHntyTlxmqhL6JbtwfRD7AAUkHPdLD4QVVZURbKhSJvTSj71pDvzJqdO/TK6q2esTLUVVH1rS7lk66T6V7UerqOD9W9y6Edm6SmQH0Gfo= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1015.namprd21.prod.outlook.com (52.132.133.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:26:30 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:26:30 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Rakesh Pandit , Christoph Hellwig , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 002/293] nvme-pci: fix multiple ctrl removal scheduling Thread-Topic: [PATCH AUTOSEL for 4.9 002/293] nvme-pci: fix multiple ctrl removal scheduling Thread-Index: AQHTz5jiabZzN+tEhkKG9rDuoA+X1A== Date: Mon, 9 Apr 2018 00:22:47 +0000 Message-ID: <20180409002239.163177-2-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-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;DM5PR2101MB1015;7:TnxaJ9RMUcIu26VGsaiMJ4LWl9XCZAjZP9Wpt0bS6UOy3CDm6Owyzi0Ersukw2PnH3WKKzjnQlpFpr2DXCDeTEdFdOmM1Ud/EezD0LcPzBYlhb2V19+FJBh3eP7vbOmv+4ToehqwhIj6TFuM/GKfm3bpZK7mIFhsVbaONfNaNxUoa5iQnNS9UZwoZIhLkOCiwUCJTB19jEuVm0WrQ1f3nV/+o31JKFj/FEQ0d1k3s6h+hynFYE/YIi3/ZQlNW58W;20:3b50G+wHdZCAWemQvntLjqqXXvVPR/pnmlZgIwzPYiHpYG6VTCK+cxMeEf9HERFUupvnSrlzumHsrXwGewIvbjp6g0RenXq7ApSL1fBPztZRVSCxXEWi0KLo6nfc7At9fwRGKxLCzsqGk5QdgU05uoiDiCQxignzn9wRAUN3wiE= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 885d5ee0-f68d-472f-f658-08d59db08a3d x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1015; x-ms-traffictypediagnostic: DM5PR2101MB1015: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(17755550239193); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(3231221)(944501327)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1015;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1015; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39860400002)(39380400002)(376002)(346002)(366004)(51234002)(189003)(199004)(53936002)(4326008)(478600001)(72206003)(3280700002)(2616005)(14454004)(305945005)(5250100002)(3660700001)(2501003)(2900100001)(54906003)(110136005)(86362001)(1076002)(107886003)(6506007)(36756003)(446003)(68736007)(6512007)(7736002)(486006)(2906002)(5660300001)(6436002)(3846002)(86612001)(6486002)(66066001)(11346002)(575784001)(476003)(6666003)(59450400001)(26005)(10090500001)(316002)(22452003)(8676002)(81156014)(81166006)(6116002)(105586002)(99286004)(186003)(106356001)(76176011)(25786009)(97736004)(10290500003)(102836004)(8936002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1015;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: pby+OspKorrhnoJefm8Ig+97aM5oqBrxwH4dSdiKrcVbBqz+xoTU/MWqkOIrsvQWkV6X+ghTzuX73YIRwZJGxv6GYWVjE8Y0pBKlpBbKjZwSIG2HbS2g0MGiRbh7oktHQKkqQf/tnRE2YI4dR3orvhffE/zhPhyAGWqM+GHhvQtpcHgD/KV6G2frSjEzHaS4MtzRVRDT3M0mUlArKQZvINWdUHeh7a5jR+c/vdSFVP6j9y/Ak/kHEBO3BciUZAJX/rCgdbB3hTfKw6+obEeZsmzmU4kldOpwS9DppH/2ZjVhRJBinsGpqW3WhQCz+F7CXha1Bu0Ax80F24Dtc+KUKs5imvwVNBx1ekeDKq04ZvAtQb1iXb4CYuJwLv7ToruwKCU/kF+0//MeDu4ZD4DlfcxFvl9pujMEBSbPEaSMH4c= 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: 885d5ee0-f68d-472f-f658-08d59db08a3d X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:22:47.0654 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1015 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rakesh Pandit [ Upstream commit 82b057caefaff2a891f821a617d939f46e03e844 ] Commit c5f6ce97c1210 tries to address multiple resets but fails as work_busy doesn't involve any synchronization and can fail. This is reproducible easily as can be seen by WARNING below which is triggered with line: WARN_ON(dev->ctrl.state =3D=3D NVME_CTRL_RESETTING) Allowing multiple resets can result in multiple controller removal as well if different conditions inside nvme_reset_work fail and which might deadlock on device_release_driver. [ 480.327007] WARNING: CPU: 3 PID: 150 at drivers/nvme/host/pci.c:1900 nvm= e_reset_work+0x36c/0xec0 [ 480.327008] Modules linked in: rfcomm fuse nf_conntrack_netbios_ns nf_co= nntrack_broadcast... [ 480.327044] btusb videobuf2_core ghash_clmulni_intel snd_hwdep cfg80211= acer_wmi hci_uart.. [ 480.327065] CPU: 3 PID: 150 Comm: kworker/u16:2 Not tainted 4.12.0-rc1+ = #13 [ 480.327065] Hardware name: Acer Predator G9-591/Mustang_SLS, BIOS V1.10 = 03/03/2016 [ 480.327066] Workqueue: nvme nvme_reset_work [ 480.327067] task: ffff880498ad8000 task.stack: ffffc90002218000 [ 480.327068] RIP: 0010:nvme_reset_work+0x36c/0xec0 [ 480.327069] RSP: 0018:ffffc9000221bdb8 EFLAGS: 00010246 [ 480.327070] RAX: 0000000000460000 RBX: ffff880498a98128 RCX: dead0000000= 00200 [ 480.327070] RDX: 0000000000000001 RSI: ffff8804b1028020 RDI: ffff880498a= 98128 [ 480.327071] RBP: ffffc9000221be50 R08: 0000000000000000 R09: 00000000000= 00000 [ 480.327071] R10: ffffc90001963ce8 R11: 000000000000020d R12: ffff880498a= 98000 [ 480.327072] R13: ffff880498a53500 R14: ffff880498a98130 R15: ffff880498a= 98128 [ 480.327072] FS: 0000000000000000(0000) GS:ffff8804c1cc0000(0000) knlGS:= 0000000000000000 [ 480.327073] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 480.327074] CR2: 00007ffcf3c37f78 CR3: 0000000001e09000 CR4: 00000000003= 406e0 [ 480.327074] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 00000000000= 00000 [ 480.327075] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 00000000000= 00400 [ 480.327075] Call Trace: [ 480.327079] ? __switch_to+0x227/0x400 [ 480.327081] process_one_work+0x18c/0x3a0 [ 480.327082] worker_thread+0x4e/0x3b0 [ 480.327084] kthread+0x109/0x140 [ 480.327085] ? process_one_work+0x3a0/0x3a0 [ 480.327087] ? kthread_park+0x60/0x60 [ 480.327102] ret_from_fork+0x2c/0x40 [ 480.327103] Code: e8 5a dc ff ff 85 c0 41 89 c1 0f..... This patch addresses the problem by using state of controller to decide whether reset should be queued or not as state change is synchronizated using controller spinlock. Also cancel_work_sync is used to make sure remove cancels the reset_work and waits for it to finish. This patch also changes return value from -ENODEV to more appropriate -EBUSY if nvme_reset fails to change state. Fixes: c5f6ce97c1210 ("nvme: don't schedule multiple resets") Signed-off-by: Rakesh Pandit Reviewed-by: Sagi Grimberg Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/host/pci.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index e48ecb9303ca..8cc856ecec95 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -1263,7 +1263,7 @@ static bool nvme_should_reset(struct nvme_dev *dev, u= 32 csts) bool nssro =3D dev->subsystem && (csts & NVME_CSTS_NSSRO); =20 /* If there is a reset ongoing, we shouldn't reset again. */ - if (work_busy(&dev->reset_work)) + if (dev->ctrl.state =3D=3D NVME_CTRL_RESETTING) return false; =20 /* We shouldn't reset unless the controller is on fatal error state @@ -1755,7 +1755,7 @@ static void nvme_reset_work(struct work_struct *work) struct nvme_dev *dev =3D container_of(work, struct nvme_dev, reset_work); int result =3D -ENODEV; =20 - if (WARN_ON(dev->ctrl.state =3D=3D NVME_CTRL_RESETTING)) + if (WARN_ON(dev->ctrl.state !=3D NVME_CTRL_RESETTING)) goto out; =20 /* @@ -1765,9 +1765,6 @@ static void nvme_reset_work(struct work_struct *work) if (dev->ctrl.ctrl_config & NVME_CC_ENABLE) nvme_dev_disable(dev, false); =20 - if (!nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_RESETTING)) - goto out; - result =3D nvme_pci_enable(dev); if (result) goto out; @@ -1841,8 +1838,8 @@ static int nvme_reset(struct nvme_dev *dev) { if (!dev->ctrl.admin_q || blk_queue_dying(dev->ctrl.admin_q)) return -ENODEV; - if (work_busy(&dev->reset_work)) - return -ENODEV; + if (!nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_RESETTING)) + return -EBUSY; if (!queue_work(nvme_workq, &dev->reset_work)) return -EBUSY; return 0; @@ -1944,6 +1941,7 @@ static int nvme_probe(struct pci_dev *pdev, const str= uct pci_device_id *id) if (result) goto release_pools; =20 + nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_RESETTING); dev_info(dev->ctrl.device, "pci function %s\n", dev_name(&pdev->dev)); =20 queue_work(nvme_workq, &dev->reset_work); @@ -1987,6 +1985,7 @@ static void nvme_remove(struct pci_dev *pdev) =20 nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_DELETING); =20 + cancel_work_sync(&dev->reset_work); pci_set_drvdata(pdev, NULL); =20 if (!pci_device_is_present(pdev)) { --=20 2.15.1