From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.246.84.56 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796122233; b=tq5R7IHLG14QthA/e4zPzNcDbhBc/PGIyUNzG5ijwOoXOOnhRP5plpIM/U8LOZ4L8ZgZ 9sCPK3H8w6bXx1x+fq6mzCifFGWCvLQe893b8wJB3E3P/BlgSw9+az0gi6vcj0w8nRUH2 HH2Bywe79hb6XaF7X8MuYsdaKrA/eM6JnSKIZcFEDXqi5BlWbZaW7FzBjlMenNudqZ7iC s6Or1/BhvU8lxE8qTpU5Ok+f73MzPYlgfNcEzYFmmeBIPbD1tybaOGx4ubBzxbWveqql6 EyziSWxuXNtvhBTeYoq1bO6qKB7bM83h01XX8+b+4X8YvP3P6zkqZ20416aN21PZq2w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796122233; 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=4Tv0oV5C9m/n9QRfc7H0C1aJjG28CMx86L4citRYnis=; b=nngluz9+8G084y/eK0ux63lOVn8zmePDMIQUpy81PNPgDe1r9rijPRZixyg6F9475NXq IL3Hq/ifM/QuwnnPlT3lMD6cdMATpjCJeIR1bJ6a2sKAeeYO6L/qGllMCDDPDBWs8jCwq f9leOWPDa0Ct37f8Q4nPJ5e8qX6n6BzGJGBSo4KK0tqvgcC5+vzBQU3faaMTskYYkJYTT kqpmWKkopeR5ZEJ+gtZGawNlDAS3FXsP3uot8iF1rdmnv7+9zPxQePWb1qzd2vIvEC2If riOssJVER4TUUNNmgRUjjFqPIdiD8BtDKiAEk2+5K3UX/RMSV4DozB9ZfwT98R2ZRAw== 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=ZrQQXgbR; arc=none smtp.remote-ip=185.246.84.56 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 51A96606A31A for ; Tue, 1 Dec 2026 10:50:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 51A96606A31A 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=ZrQQXgbR Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 7D7361A188F; Tue, 1 Dec 2026 10:50:31 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 422B6603CB; Tue, 1 Dec 2026 10:50:31 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id C5AAA11EA12F0; Tue, 01 Dec 2026 11:50:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796122226; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=4Tv0oV5C9m/n9QRfc7H0C1aJjG28CMx86L4citRYnis=; b=ZrQQXgbRRoh21M+rubPn68thw/FxDXHiT4ttEVKmsc0/2AF0DIU6wgL5w70/pTWDA/Dci1 p47d51DRRcA3pM/gxXpQDdEFxifqhdohcA/k5bkhKEHtZ8pFnnklunOC5OYNoXa9bbYJW1 MS0ycPp1igXwWFvRaHiELKf4k1h/e62aeQ2shs0x+oFsisq3poP3W7JsRTlN6gGN5PSLi4 T0bREe/VGXq2dR721DjdJKBcLF6bQqp/HmtEbytTIr/jr4A9LOwnMo/UaXSvPtuPdfG1hb UX0fevV8t5j7hw24moWFOyZB8lev0ZXltReSO8CdtXviJYAi2D2dxOI2q3fs4A== Message-ID: <4c2839a6fb889d0b66d6b6da03a74bce85849ab6.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 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 Date: Tue, 01 Dec 2026 11:50:15 +0100 In-Reply-To: References: <20261126-fix_deadlock_1126-v2-1-c0ed50bc7b04@oss.qualcomm.com> <237a9b5170ecbda43074cfb07b3eb04458dc1b9d.camel@bootlin.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-kernel@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 Le mardi 01 d=C3=A9cembre 2026 =C3=A0 11:08 +0100, Lukas Wunner a =C3=A9cri= t=C2=A0: > On Tue, Dec 01, 2026 at 10:08:18AM +0100, Paul Cercueil wrote: > > Le dimanche 29 novembre 2026 =C3=A0 22:06 +0100, Lukas Wunner a =C3=A9c= rit : > > > 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(). > >=20 > > Manivannan said in the v7's cover letter: > > https://lore.kernel.org/linux-pci/20260310-pci-port-reset-v7-0-9dd00ccc= 25ab@oss.qualcomm.com/ > >=20 > > "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." > >=20 > > On the pciehp side, > >=20 > > pciehp_unconfigure_device() > > =C2=A0 pci_lock_rescan_remove() > > =C2=A0 pci_stop_and_remove_bus_device() > > =C2=A0=C2=A0=C2=A0 pci_remove_bus_device() > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pci_destroy_dev() > >=20 > > So if you don't get the unscan lock in the reset path, which can happen= in > > parallel, you risk a use-after-free. >=20 > 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. >=20 > 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(). >=20 > It's unclear to me which device you expect to be removed in parallel: > The Root Port?=C2=A0 That can't happen via pciehp.=C2=A0 The Root Port si= ts at > the top of the hierarchy, there's no hotplug-capable port above it > which pciehp could bind to. >=20 > I guess the Root Port could be removed if the user exercises the "remove" > attribute in sysfs.=C2=A0 But again, the right way to protect against tha= t is > to acquire a reference on the Root Port. Yes, I agree. I was just trying to show why the pci_lock_rescan_remove() wa= s used there, I am not arguing that it was the best solution. > But maybe I'm missing something and you want to protect a different devic= e > than the Root Port against removal? >=20 > 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. I'll send a patch to change it to a reference grab. Cheers, -Paul