From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.171.202.116 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796116112; b=CRrfkqUWmQO7XlXK63LTABlXcVfttRzTeEpRNS+Yhf4a6bxNDsgqYrAsVaRgU1x6JwvQ aIqtHReCrKpJWqYolXfvqHHPv1CGxWu/D+GalUsDNb9PTqvR9I+DJRmDU18zZUSTFzHDi nqG0D1pPQkkuCbZ/cTSxvnyXIYd5680Q2qKTx/8Kha+SfkNb9mEDZeoZxBTUl46GGYaBZ Y+NNk6cXQtUF6IOhYY+nqcqGqhdiipRdoQ92LQf8xfF8NyB9on7XzBFTQ2SdtLLWWyyjf 4kLrvTYwoSUDg5EJU4U6Hz57w3SMs3Ki80yifVF70FL8h6HDPdZ4yxahbbQVwpey09w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796116112; h=DMARC-Filter:Received:Received:Received:DKIM-Signature:Message-ID: Subject:From:To:Cc:Date:In-Reply-To:References:Content-Type: Content-Transfer-Encoding:User-Agent:MIME-Version: X-Last-TLS-Session-Version; bh=/wSDl5Ec379F6JOmnq89IotCj89o0SXFLy+kS51INwY=; b=Ae5BeTktzdTUJPHNC5pNvDlW38ZUKxjZyxj9QBb/eEciFiEfs1ow8X0KDlMgOII0SwLE NpHfJ2mLDjctSxc41+XhuFqqNAlmKMDqsynx4wB6oGDvHoyi7l/PvFkzFv2IlJ0TCG+9y KgYPHvl786jFGdwTaZ9q3X96VEsnRZlPNFm0J9/oOEHur9wnWsMEX5RgMUy/iJJCKkZwE r8jyGVfd5aYqMaRf3N104Pp7mS8nYOZ3TIhGuv4yzdBtoOiLcEl/f2FNi6NFv798yBZ7Q m7LkMzlfYinOYfBFhKkDt8g83gBHjqDy5zOz22ouk6imdZ5sMSI2Mm4v67ujDGMiarw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=iSXIv0La; arc=none smtp.remote-ip=185.171.202.116 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (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 EC8A5606A329 for ; Tue, 1 Dec 2026 09:08:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EC8A5606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=iSXIv0La Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 0B1EEC2B9CB; Tue, 1 Dec 2026 09:08:40 +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-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 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/