From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=144.76.133.104 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796119705; b=vPhEzDtVGOjxU9QIkN340P2DAIcftDdliPrrNV5sm/Ma4Na6d0FfFjFBlTQe57DzoFm+ 5F2YGMXO4WemANHXu1ejUXyTQT+o2BD7ltkhQQI4cfNjb5G88anF+AMCMFTndskF+IoDM aca+A5QPhPQcMYOl07dANrs+LWm5ET39DNH2Y33zhtV0C2n573O9eHh7Ic5hJrw7cndwe qDZexuhCPQEVmr713HXGbf+Ogko/zAoZh2VVq+6ag9A/EzggXR/Vzytvthu5vXGBf4jfQ W1tMmcvocsqqs7e2iSnr5d4BvLyVnT+kQ+JNeLEKRXk3YmTWiYMHRiqhavjq/ialMLQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796119705; h=DMARC-Filter:Received:Received:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition: Content-Transfer-Encoding:In-Reply-To; bh=kLDDkCPIF1oLGF/k34ctVE5+qy9QEFnfAXqf1etq86k=; b=xv6I/0c0jSeqYyHSRljoPSqQRL105Cdq0ea0ORS9SttCGmJ9xnm9ZAa4iA0bIsSq42GG ynxOO4RYogBn1zHGNbxLVhnF7FDp18XO1V0HIaQ9Xhq2Ghf2/qZ+NjvOpJDs143e3WHYG h56T4K9IoCTPsDPhygcVSWChYx8p5IbrtieE0hd0ymbrn4WDrjEtu228n7lkGw4treE0W 0rQLTNJs3U7L8hjv07JwcYJnusCmHskgTK3Ay7av3hCKRcDx1QM9LHsHRD4/p1E7O4Uch hqpCSAuX3RTJaAqPCc7jZzyfGsqMZR4XNU+i3mcuBi5/ag6tvWZvn1Q3TELBDsr55EA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=wunner.de; spf=pass smtp.mailfrom=wunner.de; arc=none smtp.remote-ip=144.76.133.104 Received: from mailout3.hostsharing.net (mailout3.hostsharing.net [144.76.133.104]) (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 A11B5606A329; Tue, 1 Dec 2026 10:08:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A11B5606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=wunner.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wunner.de Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384 client-signature ECDSA (secp384r1) client-digest SHA384) (Client CN "*.hostsharing.net", Issuer "GlobalSign GCC R6 AlphaSSL CA 2025" (verified OK)) by mailout3.hostsharing.net (Postfix) with ESMTPS id 2D5D5C27; Tue, 01 Dec 2026 11:08:21 +0100 (CET) Received: by h08.hostsharing.net (Postfix, from userid 100393) id E6E4A6018CC7; Tue, 1 Dec 2026 11:08:20 +0100 (CET) Date: Tue, 1 Dec 2026 11:08:20 +0100 From: Lukas Wunner To: Paul Cercueil Cc: Qiang Yu , Will Deacon , Lorenzo Pieralisi , Krzysztof Wilczy??ski , 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 Subject: Re: [PATCH RFC v2] PCI: pciehp: Fix AB-BA deadlocks between reset_lock, pci_rescan_remove_lock and pci_slot_mutex Message-ID: References: <20261126-fix_deadlock_1126-v2-1-c0ed50bc7b04@oss.qualcomm.com> <237a9b5170ecbda43074cfb07b3eb04458dc1b9d.camel@bootlin.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <237a9b5170ecbda43074cfb07b3eb04458dc1b9d.camel@bootlin.com> On Tue, Dec 01, 2026 at 10:08:18AM +0100, Paul Cercueil wrote: > Le dimanche 29 novembre 2026 à 22:06 +0100, Lukas Wunner a écrit : > > Why is it necessary to lock rescan/remove for a reset? > > This looks wrong. I suggest removing pci_lock_rescan_remove() > > from pci_host_reset_root_port(). > > Manivannan said in the v7's cover letter: > https://lore.kernel.org/linux-pci/20260310-pci-port-reset-v7-0-9dd00ccc25ab@oss.qualcomm.com/ > > "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. The proper approach to avoid a use after free is to acquire a reference on the pci_dev which is at risk of being removed in parallel. E.g. in drivers/pci/pcie/aer.c, add_error_device() acquires a reference on the error-reporting device and that reference is released in aer_process_err_devices(). It's unclear to me which device you expect to be removed in parallel: The Root Port? That can't happen via pciehp. The Root Port sits at the top of the hierarchy, there's no hotplug-capable port above it which pciehp could bind to. I guess the Root Port could be removed if the user exercises the "remove" attribute in sysfs. But again, the right way to protect against that is to acquire a reference on the Root Port. But maybe I'm missing something and you want to protect a different device than the Root Port against removal? I've gone through the review feedback to v6 of Mani's series and I don't see anyone reporting a use-after-free, so it's unclear to me why the pci_lock_rescan_remove() was added in v7. Thanks, Lukas