Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2293000imc; Tue, 12 Mar 2019 10:44:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxd+ZvaDYYrBxFEhnbLUHYsZ7fcJx71NX6yvUw3hfA/O+/VYxejIDUYjJs2JSdhji486e9U X-Received: by 2002:a63:eb0f:: with SMTP id t15mr36727451pgh.252.1552412695659; Tue, 12 Mar 2019 10:44:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552412695; cv=none; d=google.com; s=arc-20160816; b=i8ubxrehcgwDtve7N+ockgX2tQnUguq+RUALpkMEhxVWQkaQPVs1txXG6/kllG1lYk vbiR1/JrRfn80Wi66P0FAJwY9+D3E2F4+qbazEAsNvxLBpEK4GirmyOBYY1qu7V1Q3FX oSbEMHggXuB71oOcTlBPPmCpnfrm4b/4uqGOobBmHw2Be2TI3yZu4qt8TgkE/S19d/yd L/XE6HDQwMeX9zgrtLJ8w27LXzaeUms3gwW60MRJccCW/SAZN1F+FXoYvm/o0L+qlrrr 1LYMhDgFY36+k9s5XX+PeqSGtGH4JSh07PvNVjv4Hw4mmfKYPjKn4sq3TsJHu89aEqmA beQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rEGLD4z6TNYkYBlSunLuuicAyb5soAbE+j/ififgyPw=; b=Ip/uUGeb6mpLRDhirvulFNWVxhvygxs1k0lieHXcQmeaRH5Es009JjrqVoCThL1pgd gxTIsP6pebMcbdBQk/N8evjJJV0UXMrhMl8PpslagcHqbb5PWQ4lOvcjv3FdhLbYgE71 cjRI8Er+kydN4HOjfePVTGS0vyMB7YxL+V+4ukYnHi+aRsKXFLezEciiSb0jwUoTOj3o dw4CbT1Ty/977IxDQeSgLZllX7iOIN6xRkJ4ukkUwYp7odZaQx/Z1n7i6mjB8MXBpqhG 5+yQeDBGb//fvXfzqCXEJNEQyHH4ii7gh6AbzRHL7baD67V9/u3sffE4XhxXgn9ESFxf wsGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v9pBe3md; 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 be11si8247687plb.355.2019.03.12.10.44.40; Tue, 12 Mar 2019 10:44:55 -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=@kernel.org header.s=default header.b=v9pBe3md; 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 S1728929AbfCLRP6 (ORCPT + 99 others); Tue, 12 Mar 2019 13:15:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:54826 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727763AbfCLRPD (ORCPT ); Tue, 12 Mar 2019 13:15:03 -0400 Received: from localhost (unknown [104.133.8.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9EDC72186A; Tue, 12 Mar 2019 17:15:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552410902; bh=uZK6svuTGTsJPB6jVBSDZ9T5wbLPxxb76qbIAGxGxcE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v9pBe3mdfNL3uhfqhSG4jloV79I2XBO8h9/XmtPkZyh4NZaBBvExuD6Sz0+REJU1T K/WFfBLRwg+38zJ53y3lky0nRnpIRI6iMpBvtG+/C+MSNpQQ+ngmmzvQ58dxsNyRQn uIeAzCjBQjTrPaGP0fmAlWsFAJgr4WsI7Cvu3KSo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alex Gagniuc , Keith Busch , Alex Gagniuc , Christoph Hellwig , Sasha Levin Subject: [PATCH 4.19 116/149] nvme-pci: fix rapid add remove sequence Date: Tue, 12 Mar 2019 10:08:54 -0700 Message-Id: <20190312170359.204366963@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190312170349.421581206@linuxfoundation.org> References: <20190312170349.421581206@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 5c959d73dba6495ec01d04c206ee679d61ccb2b0 ] A surprise removal may fail to tear down request queues if it is racing with the initial asynchronous probe. If that happens, the remove path won't see the queue resources to tear down, and the controller reset path may create a new request queue on a removed device, but will not be able to make forward progress, deadlocking the pci removal. Protect setting up non-blocking resources from a shutdown by holding the same mutex, and transition to the CONNECTING state after these resources are initialized so the probe path may see the dead controller state before dispatching new IO. Link: https://bugzilla.kernel.org/show_bug.cgi?id=202081 Reported-by: Alex Gagniuc Signed-off-by: Keith Busch Tested-by: Alex Gagniuc Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/host/pci.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index f46313f441ec..6398ffbce6de 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -2260,16 +2260,7 @@ static void nvme_reset_work(struct work_struct *work) if (dev->ctrl.ctrl_config & NVME_CC_ENABLE) nvme_dev_disable(dev, false); - /* - * Introduce CONNECTING state from nvme-fc/rdma transports to mark the - * initializing procedure here. - */ - if (!nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_CONNECTING)) { - dev_warn(dev->ctrl.device, - "failed to mark controller CONNECTING\n"); - goto out; - } - + mutex_lock(&dev->shutdown_lock); result = nvme_pci_enable(dev); if (result) goto out; @@ -2288,6 +2279,17 @@ static void nvme_reset_work(struct work_struct *work) */ dev->ctrl.max_hw_sectors = NVME_MAX_KB_SZ << 1; dev->ctrl.max_segments = NVME_MAX_SEGS; + mutex_unlock(&dev->shutdown_lock); + + /* + * Introduce CONNECTING state from nvme-fc/rdma transports to mark the + * initializing procedure here. + */ + if (!nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_CONNECTING)) { + dev_warn(dev->ctrl.device, + "failed to mark controller CONNECTING\n"); + goto out; + } result = nvme_init_identify(&dev->ctrl); if (result) -- 2.19.1