Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4439188imw; Tue, 12 Jul 2022 08:00:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vjAyczzlpFGbZZseYDtSC7czAGPse/MbWj5oQrHlh+Gqc55NtpZrLLXA5S4BW7ORctXhaZ X-Received: by 2002:a05:6a00:1a49:b0:528:6ea0:14e2 with SMTP id h9-20020a056a001a4900b005286ea014e2mr24023038pfv.22.1657638024011; Tue, 12 Jul 2022 08:00:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657638024; cv=none; d=google.com; s=arc-20160816; b=NQ+u6eNeE0U7GzKnVkdRyrGL9jR1KrTyX9vbsGsE8JlGNe5yKUreKLc6fGqpgoHL2Y nFbs9y8MSDGMcVx7eXlDqJF9MDzvEw7cs20ijBgD81VLdeSodFBZEA+AgNIxQxFmkhuo qE0Jf/JXZX44oRh0S2oiXKSypmLAqvpngRgZ/GrkxsahWqifw8HjRXsJNmBXh3g4dCWX 0Z78P8iC80Y0KhlUlH5DhfJsM++1U10EGzbu+jCEZK3wP7SNodKIu8ZGsinyYneyzSmY fuyoyn8lpq4mOkxAl1hll2pM7rEXY/fDJYPW8SySJ9UZvQjH83Dlx4NmBbaMSrly2Sm0 ZvIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Ci9+hRJezweXnUdxfNXU0S2jAjRlYyWnCLRP1irvXYs=; b=yOq+qeIT0tVdAsf+V8d+ihad2Pxlt0aIy05cHNJih82RFJEPn7X0fT8Ola19l86xrb nitXHppe1uMINCOlvWt/mVBrXV+RBrfGQGUGdttEd620msNwZmQVVxC3odCZ+vrupRqI Zx0CPBnovwS7m0UlIF1z/EKh1N3+pvUVQeN41KDOqQUuu2HROpUSq9Z8xSs/mAl2S3yL zMX1q8+TiglYBpirORNxRhvMsiyVohgrA3FOr36vSComOw11UktxySbPWrhZ7MfFwqvM JL9ko75OxUbtQPwEtSaUZ2fvkDS9zm333ucjgUHwAdlfEZ+h4FaggEjWd9qonc1piC1h 0+BQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VRPNWMYB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 4-20020a631744000000b004129cfad33dsi13687635pgx.206.2022.07.12.08.00.08; Tue, 12 Jul 2022 08:00:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VRPNWMYB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233311AbiGLORw (ORCPT + 99 others); Tue, 12 Jul 2022 10:17:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233391AbiGLORg (ORCPT ); Tue, 12 Jul 2022 10:17:36 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A633B31D5 for ; Tue, 12 Jul 2022 07:17:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 149AEB816E1 for ; Tue, 12 Jul 2022 14:17:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C733C341CD; Tue, 12 Jul 2022 14:17:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657635451; bh=4k4HRuM7gfop9Mz8eN6pF7c8Y7aZaQnTyFpt9VK42+g=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VRPNWMYBMg/S8KALz1C0TbpcTHoDupuy9XwR4wVf5K9TGpU+JiAXJGIjbBBg6wYNE +d+AFDvEGqZZsaSoFZShVTE/D1gR7lEad4QzeNoA95xIXjGpuxUKzcq7iXVIc3CVVK Pg31zJbXodgWOUP2P1/sojB4ihv4hy5zWrX4gSoZ+bYZB4oyCe+3GGXYj1BG8dZ2T+ SnihCayMpZDPhwIvsWTLpPfn/VfbMRRWEAuEO2q9imBlhbX6XNlxeZydNC5SfRz4UC bRVhmpXM3U2ZR10wRQmx5etcHfXkc4iCNyexPULuWVnFEstqjeQlPXaGM3e4JANZhZ Ezy4vS3NJ/REA== Date: Tue, 12 Jul 2022 08:17:28 -0600 From: Keith Busch To: Niklas Schnelle Cc: Christoph Hellwig , Stefan Roese , Matthew Rosato , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] nvme-pci: fix hang during error recovery when the PCI device is isolated Message-ID: References: <20220712124453.2227362-1-schnelle@linux.ibm.com> <20220712124453.2227362-2-schnelle@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220712124453.2227362-2-schnelle@linux.ibm.com> X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 12, 2022 at 02:44:53PM +0200, Niklas Schnelle wrote: > On s390 and powerpc PCI devices are isolated when an error is detected > and driver->err_handler->error_detected is called with an inaccessible > PCI device and PCI channel state set to pci_channel_io_frozen > (see Step 1 in Documentation/PCI/pci-error-recovery.rst). > > In the case of NVMe devices nvme_error_detected() then calls > nvme_dev_disable(dev, false) and requests a reset. After a successful > reset the device is accessible again and nvme_slot_reset() resets the > controller and queues nvme_reset_work() which then recovers the > controller. > > Since commit b98235d3a471 ("nvme-pci: harden drive presence detect in > nvme_dev_disable()") however nvme_dev_disable() no longer freezes the > queues if pci_device_is_present() returns false. This is the case for an > isolated PCI device. In principle this makes sense as there are no > accessible hardware queues to run. The problem though is that for > a previously live reset controller with online queues nvme_reset_work() > calls nvme_wait_freeze() which, without the freeze having been > initiated, then hangs forever. Fix this by starting the freeze in > nvme_slot_reset() which is the earliest point where we know the device > should be accessible again. > > Fixes: b98235d3a471 ("nvme-pci: harden drive presence detect in nvme_dev_disable()") > Signed-off-by: Niklas Schnelle Oh, we've messed up the expected sequence. The mistaken assumption is a device not present means we're about to unbind from it, but it could appear that way just for normal error handling and reset, so we need to preserve the previous handling. The offending commit really just wants to avoid the register access (which we shouldn't have to do, but hey, broken hardware...). So let's keep the sequence the same as before and just skip the register read. Does this work for you? --- diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index fdfee3e590db..c40e82cee735 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c static void nvme_dev_remove_admin(struct nvme_dev *dev) @@ -2690,9 +2772,11 @@ static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown) struct pci_dev *pdev = to_pci_dev(dev->dev); mutex_lock(&dev->shutdown_lock); - if (pci_device_is_present(pdev) && pci_is_enabled(pdev)) { - u32 csts = readl(dev->bar + NVME_REG_CSTS); + if (pci_is_enabled(pdev)) { + u32 csts = ~0; + if (pci_device_is_present(pdev)) + csts = readl(dev->bar + NVME_REG_CSTS); if (dev->ctrl.state == NVME_CTRL_LIVE || dev->ctrl.state == NVME_CTRL_RESETTING) { freeze = true; --