From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A378606A320 for ; Tue, 1 Dec 2026 09:08:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=bQCW3zHC; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=iSXIv0La DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version: Content-Transfer-Encoding:Content-Type:References:In-Reply-To:Date:Cc:To:From :Subject:Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=/wSDl5Ec379F6JOmnq89IotCj89o0SXFLy+kS51INwY=; b=bQCW3zHC2uREMVJMOZC1ctbwEv EaaGI+GyaGpVDQgngXzl4Ydi+B0tH8w0GXx/VIw5UqN3dZ6t61AzFAwwZS8VXmoMyo6J+1SBcWUUb d1fkY+g0S1dA0ewx2B/LWUsU5BAwwZNMtX3QZOEIYvzvddBF1z+MYJAf/wFzLVf5Madib9boe5F/i gYhXfhOyes4z2zUqf2R+TFEo6AfUIhRh5QUrOFs9EjAzCXmUuGXpk/cU4mK++j5F5kxfXN1OkjyxN IFWr9goWUgn8MvrEhV1w4FLeATiRJ0rsWOR6D7EC2QEnZIbUcF703Fl2lejjoxp0jK0kqRCeiGPTK m6Gjyywg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYJqo-000000078yj-1p3J; Tue, 01 Dec 2026 09:08:38 +0000 Received: from smtpout-03.galae.net ([185.246.85.4]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYJqk-000000078vv-0Bxg for linux-arm-kernel@lists.infradead.org; Tue, 01 Dec 2026 09:08:36 +0000 Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id BC43C4E417C0; Tue, 1 Dec 2026 09:08:29 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 8293D603CB; Tue, 1 Dec 2026 09:08:29 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 351AE11EA0AF0; Tue, 01 Dec 2026 10:08:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796116108; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=/wSDl5Ec379F6JOmnq89IotCj89o0SXFLy+kS51INwY=; b=iSXIv0Lar3OVRWfTa4tpzYLh0QcuOUSRiqyifAQMYjqH/RNVrwBYq61FNVDpVw4uiitCky 9WSO0eT0/AISdJVY5fQv3gR2ZXC76pKvBQoiVFQ5VUOiXqq7JhbFVStjZkFVevMJHdYoJL 5JcHpoy4bmhlGjVFVUz3SCILrWMJTI3r6q9KYlBwV1cYGIx/8ce3rrhYSsxXdcdZV/BM4f 7kFg8VzspdjGqZywFMWZNiXPxH5uqno/xrukj894dM/zUYRxK2+DzgqSSRV6j2VeUAaq73 aUtlqaL6wA+Uq1b7HaZfCoNh+tzXOMxw22akWWUjgHaPoBJDOkfbgBwWiLTx6g== Message-ID: <237a9b5170ecbda43074cfb07b3eb04458dc1b9d.camel@bootlin.com> Subject: Re: [PATCH RFC v2] PCI: pciehp: Fix AB-BA deadlocks between reset_lock, pci_rescan_remove_lock and pci_slot_mutex From: Paul Cercueil To: Lukas Wunner , Qiang Yu Cc: Will Deacon , Lorenzo Pieralisi , Krzysztof =?UTF-8?Q?Wilczy=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Bjorn Helgaas , Nirmal Patel , Jonathan Derrick , Frank Li , Manivannan Sadhasivam , linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Thomas Petazzoni Date: Tue, 01 Dec 2026 10:08:18 +0100 In-Reply-To: References: <20261126-fix_deadlock_1126-v2-1-c0ed50bc7b04@oss.qualcomm.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2-0+deb13u1 X-Archived-By: MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_010834_224627_0163A63D X-CRM114-Status: GOOD ( 13.72 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-5.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Hi Lukas, Le dimanche 29 novembre 2026 =C3=A0 22:06 +0100, Lukas Wunner a =C3=A9crit= =C2=A0: > On Thu, Nov 26, 2026 at 12:26:45AM -0800, Qiang Yu wrote: > > Commit 5b3f7b7d062b ("PCI: pciehp: Avoid slot access during reset") > > introduced ctrl->reset_lock to serialize a Secondary Bus Reset (SBR) > > with the pciehp code paths that read the Link Active and Presence > > Detect bits, both of which flap during an SBR. > >=20 > > pciehp_ist() holds reset_lock across the whole event handling, > > including enumerating or de-enumerating the hotplugged devices. That > > nests two PCI core locks inside reset_lock, each taken in the opposite > > order by a concurrent SBR, causing two AB-BA deadlocks. >=20 > It looks like you're trying to fix two separate deadlocks in a single > patch.=C2=A0 Can this be split in two patches? >=20 > > A Root Port reset from link-down recovery takes them the other way > > round, pci_rescan_remove_lock -> reset_lock (the boot path, via > > pci_host_probe(), takes the same reverse order): > >=20 > > =C2=A0 qcom_pcie_global_irq_thread() > > =C2=A0=C2=A0=C2=A0 pci_host_handle_link_down() > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pci_host_reset_root_port() > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pci_lock_rescan_remove()=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 # pci_rescan_remove_lock > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pci_bus_error_reset() > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pci_reset_bridge= () > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pci_= slot_reset() > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 pci_reset_hotplug_slot() > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 pciehp_reset_slot()=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 # down_write(reset_lock) >=20 > Why is it necessary to lock rescan/remove for a reset? > This looks wrong.=C2=A0 I suggest removing pci_lock_rescan_remove() > from pci_host_reset_root_port(). Manivannan said in the v7's cover letter [1]: "Added pci_{lock/unlock}_rescan_remove() to guard pci_bus_error_reset() as = the device could be removed in-between due to Native hotplug interrupt." On the pciehp side, pciehp_unconfigure_device() pci_lock_rescan_remove() pci_stop_and_remove_bus_device() pci_remove_bus_device() pci_destroy_dev() So if you don't get the unscan lock in the reset path, which can happen in parallel, you risk a use-after-free. Cheers, -Paul =20 [1]: https://lore.kernel.org/linux-pci/20260310-pci-port-reset-v7-0-9dd00ccc25ab= @oss.qualcomm.com/