From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7606326E175; Tue, 8 Apr 2025 12:54:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744116854; cv=none; b=XE3zR+FWDvqx3GPunqDrmth0o42x+D+EgF4tvji4NxRtJMtpEfjEBSc8sARcTRNfjSjk49oldOzQmNM2GAg2bLtnTzT/kzqXScrrdKUHE7J2fyaypF0L1kbUwcIoLkRbTtf3d8NGRv0MxIxHnhwx2ChGIyAa/2DVxcZWHeOfuZI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744116854; c=relaxed/simple; bh=MxmOkvkeCxdILuwE2dy5dywz6rC9K4q2/ykqL5t+Fxc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OmDL/v/K+AhFPXwQFmDsnYNWZTV8VoFRUI8JAnxu820X1v1F8fiT2BnQUXb3Ud0adKJxThUhgDp10wbfA31GveRGrzAuGvbLrTzvUNZuM3no2MklWtZS6vRccwDlbFGGjaVYzNESOsJKbT4kVzX2d3YRGS38qwJkPi70ltMSjMQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=2QHpZKIU; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="2QHpZKIU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07476C4CEE5; Tue, 8 Apr 2025 12:54:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1744116854; bh=MxmOkvkeCxdILuwE2dy5dywz6rC9K4q2/ykqL5t+Fxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2QHpZKIUEUFzBvUiISY0Vg9SSKVyIcT0/YNAtjcVGprJyP15NhA7BZ89CJoGq7pcv /ciachJxOPBHGdS57+7y6X7AhIksWBD+45HLLFBnOZ/KVly4BxM+qGGj+a631vCY4v F2MBs4nhtdFehvk4XhyV/x9pF7bqEwYDQ2/SNWtQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Nilay Shroff , Keith Busch , Sasha Levin Subject: [PATCH 6.12 292/423] nvme-pci: fix stuck reset on concurrent DPC and HP Date: Tue, 8 Apr 2025 12:50:18 +0200 Message-ID: <20250408104852.584469223@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408104845.675475678@linuxfoundation.org> References: <20250408104845.675475678@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Keith Busch [ Upstream commit 3f674e7b670b7b7d9261935820e4eba3c059f835 ] The PCIe error handling has the nvme driver quiesce the device, attempt to restart it, then wait for that restart to complete. A PCIe DPC event also toggles the PCIe link. If the slot doesn't have out-of-band presence detection, this will trigger a pciehp re-enumeration. The error handling that calls nvme_error_resume is holding the device lock while this happens. This lock blocks pciehp's request to disconnect the driver from proceeding. Meanwhile the nvme's reset can't make forward progress because its device isn't there anymore with outstanding IO, and the timeout handler won't do anything to fix it because the device is undergoing error handling. End result: deadlocked. Fix this by having the timeout handler short cut the disabling for a disconnected PCIe device. The downside is that we're relying on an IO timeout to clean up this mess, which could be a minute by default. Tested-by: Nilay Shroff Reviewed-by: Nilay Shroff Signed-off-by: Keith Busch Signed-off-by: Sasha Levin --- drivers/nvme/host/pci.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 833a67b79e13c..af45a1b865ee1 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -1413,9 +1413,20 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req) struct nvme_dev *dev = nvmeq->dev; struct request *abort_req; struct nvme_command cmd = { }; + struct pci_dev *pdev = to_pci_dev(dev->dev); u32 csts = readl(dev->bar + NVME_REG_CSTS); u8 opcode; + /* + * Shutdown the device immediately if we see it is disconnected. This + * unblocks PCIe error handling if the nvme driver is waiting in + * error_resume for a device that has been removed. We can't unbind the + * driver while the driver's error callback is waiting to complete, so + * we're relying on a timeout to break that deadlock if a removal + * occurs while reset work is running. + */ + if (pci_dev_is_disconnected(pdev)) + nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_DELETING); if (nvme_state_terminal(&dev->ctrl)) goto disable; @@ -1423,7 +1434,7 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req) * the recovery mechanism will surely fail. */ mb(); - if (pci_channel_offline(to_pci_dev(dev->dev))) + if (pci_channel_offline(pdev)) return BLK_EH_RESET_TIMER; /* -- 2.39.5