From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796123937; b=NQVdrStrF+G54QndYf+PV/ybtCSfLkzElQ2FQ/j1FNg4797QnvePDKD9fgu+NvkUkfah iVpzL09zZrKRgLUyQ2IKOT/VYOef88D3bVSp8Pmhpzc/dOBxtFYfc9xdm1QQ1Ijyr50xI I9mTmvV2vGolw5WTzbh3SDP676g4tF55Q5sVDGzUjrufrYKRJ/6/UpcZHdYDExIV9k652 uVTjOLSryPPMI+OmQSvJJiS+MzThNn4hDNPaGlef8dImX0qE8mVDkO10r5xJg3fygX5GV xdkRNP99uFCIDBHc6UmkLPUfYJuxOJfuC6EWNfjsyMgEJb0F8TNt8UNhqjhk/KICMZw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796123937; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=F2kluHzOQp7wfP8it9qmzC6QBbSr9F3eIrQ7iSR+owA=; b=SBNpKZkt9RUtivtevp33BCkZjqfSNH9lA+UJ28qQA0CaQBISiRxzcrfjSvLhlfnb7kgW ENTMLDN3htLr4FJGk/G5vPWPianybVBy/2MfUappj+JWaAKAS28C/I13kF3xQ7EUL8C9s KHRSukp1nkfbmvL87JsmwtaY0F/69iAip4TF2tgdfeOf6WBpSMF9vb7sY11T9dcFuo2P1 YXSgssehGGxO/FdxD+x6kaAdV3ISda9SNCDlMtgIMpUqjBBlkR5w54HvhwIiX3NdfNRhf 3M5jhRgShy5MLJQY843ViGLkPPC3GOLE1CtYug5Ohtxe9lk5ET1Tak+IgtvtBjbYI/Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=V4B68dJG; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E63D606A33F for ; Tue, 1 Dec 2026 11:18:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=V4B68dJG Received: by smtp.kernel.org (Postfix) with ESMTPSA id 074C01F00893; Tue, 1 Dec 2026 11:18:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796123937; bh=F2kluHzOQp7wfP8it9qmzC6QBbSr9F3eIrQ7iSR+owA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=V4B68dJGNT4YIUyjYgPPGiJMkXIUD2vnqTfoJtCgWPO7Lk9U3/L/HdZl0efqvzf9L 4QaixyS6Sh/shLRNL15368vl27cMHkmogNEHaQ4suViToeZzf461EXdGizd+Bg1WsM l1VgoCNmwPDX0HLKGGHWFYBctv7nU4cGnYwDTTgBgvhWDHfOhwTBlauUm9cRRusdk7 bRE4af5aKPuqnmJaWQi+kLBaEodnuc8VUoOZxPJps7oD+UkdgtggJiLifozr1c2LeM 3jscRKulFH8CbnoN/pFLC2RkqTNYWgap0Zz3JGn8RG/qjnLXsG0TQjf6RC4ZOZdAx+ NpGQC5jaXGJVg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] PCI: Fix root port reset lock ordering issue Reply-To: sashiko-reviews@lists.linux.dev To: "Paul Cercueil" Cc: linux-pci@vger.kernel.org In-Reply-To: <20261201110130.87336-1-paul.cercueil@bootlin.com> References: <20261201110130.87336-1-paul.cercueil@bootlin.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 11:18:56 +0000 X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] PCI: pci_host_reset_root_port() leaves subordinate bus devices unprotected - [High] PCI: ABBA deadlock remains between pci_reset_bridge() and pciehp_ist() - [Medium] PCI: pci_host_reset_root_port() drops port ref inside pcie_do_recovery() -- commit 46b7cfcd0b5a0c434fbfd94302c48b513dec7fea Author: Paul Cercueil PCI: Fix root port reset lock ordering issue This commit replaces pci_lock_rescan_remove() in pci_host_reset_root_port() with a pci_dev_get() reference on the Root Port to avoid an ABBA deadlock with pciehp's reset_lock. > diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/contr= oller/pci-host-common.c > index 35ee51cf9d067..157328f393f48 100644 > --- a/drivers/pci/controller/pci-host-common.c > +++ b/drivers/pci/controller/pci-host-common.c > @@ -327,11 +327,10 @@ EXPORT_SYMBOL_GPL(pci_host_common_d3cold_possible); > =20 > static pci_ers_result_t pci_host_reset_root_port(struct pci_dev *dev) > { > + struct pci_dev *pdev __free(pci_dev_put) =3D pci_dev_get(dev); > int ret; > =20 > - pci_lock_rescan_remove(); > ret =3D pci_bus_error_reset(dev); > - pci_unlock_rescan_remove(); > if (ret) { > pci_err(dev, "Failed to reset Root Port: %d\n", ret); > return PCI_ERS_RESULT_DISCONNECT; [Severity: High] Does taking a reference on the Root Port dev leave its subordinate device list (dev->subordinate->devices) unprotected against pciehp_unconfigure_device() and pciehp_configure_device()? dev here is the Root Port itself, whereas pciehp removes and frees child devices on dev->subordinate->devices. Inside pci_bus_error_reset() -> pci_reset_bridge() -> pci_slot_reset() (and pci_bus_reset()), pci_slot_resettable(), __pci_bus_lock() and __pci_bus_unlock() walk bus->devices without holding pci_rescan_remove_lock, pci_bus_sem or ctrl->reset_lock. Meanwhile, pciehp_unconfigure_device() drops ctrl->reset_lock around pci_stop_and_remove_bus_device(), relying on pci_lock_rescan_remove() for serialization: CPU0 CPU1 pci_host_reset_root_port(dev) pciehp_ist() pci_bus_error_reset(dev) pciehp_unconfigure_device() ... pci_lock_rescan_remove() pci_slot_reset() up_read(&ctrl->reset_lock) pci_slot_lock() pci_stop_and_remove_bus_device() __pci_bus_lock() ... list_for_each_entry(child, pci_destroy_dev(child) &bus->devices, list_del(&child->bus_list) bus_list) put_device(&child->dev) pci_dev_lock(child) <-- use-after-free Similarly, if pciehp_configure_device() adds new devices via pci_scan_slot() and then drops ctrl->reset_lock around pci_bus_add_devices(), __pci_bus_unlock() can walk bus->devices and call pci_dev_unlock() on newly added child devices that __pci_bus_lock() never locked. [Severity: High] Does an ABBA deadlock still remain between pci_reset_bridge() and pciehp_ist() via pci_slot_mutex and ctrl->reset_lock? Even without pci_rescan_remove_lock, the two paths described in the commit message still take pci_slot_mutex and ctrl->reset_lock in opposite orders: CPU0 CPU1 ---- ---- lock(&pci_slot_mutex) lock(&ctrl->reset_lock) lock(&ctrl->reset_lock) lock(&pci_slot_mutex) *** DEADLOCK *** CPU0: pci_host_reset_root_port() -> pci_bus_error_reset() -> pci_reset_bridge() -> pci_slot_reset() -> pci_reset_hotplug_slot() -> pciehp_reset_slot() CPU1: pciehp_ist() -> ... -> pciehp_configure_device() -> pci_scan_slot() -> pci_scan_single_device() -> pci_scan_device() -> pci_setup_device() -> pci_dev_assign_slot() [Severity: Medium] When CONFIG_PCIEAER is enabled, does scoping pci_dev_get(dev) to pci_host_reset_root_port() drop the Root Port reference before pcie_do_recovery() finishes using it? pci_host_recover_root_port() passes pci_host_reset_root_port as the reset_subordinates callback to pcie_do_recovery(port, ...), and callers of pci_host_handle_link_down(port) do not hold a reference on port. Because pdev uses __free(pci_dev_put) inside pci_host_reset_root_port(), the reference is released as soon as reset_subordinates(bridge) returns, while pcie_do_recovery() continues to dereference bridge and dev during the post-reset walk and AER status cleanup. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201110130.8733= 6-1-paul.cercueil@bootlin.com?part=3D1