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 E479A606A31A for ; Tue, 1 Dec 2026 10:08:48 +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=v+91yOlw 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:In-Reply-To: Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date: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=kLDDkCPIF1oLGF/k34ctVE5+qy9QEFnfAXqf1etq86k=; b=v+91yOlwfv6J+z0+jGr7iyEil4 Bh2dMpZSnhRT2UesQ24To++8kWET0CxktmXBLUSekBcO/sBLlEA+VfkXjLoh5F+8aI09MOz8pMtJ1 yEMHP7RdnV8CwxKpTFPddGUtVyp5MD4SrkCPCbB+xo7WugJdq8oX+eUv8p3wzEWqiS8plEQeb2og2 8gzDuQSf4iDg+Kz7tae77lTnqivuZ61TrqdVms+j528TyykL1pbS7Zqk4h7pt3Fj8yPRDB7BAU+eE cdgDpkyAwaJ4qhxnX9SuiSk/XFglEtg/vVQpsK0oxodtGwsyvJpxB7yJabt8OBeCoFvwC3J2Z7Ygb wJbW7y0Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYKmq-00000007J64-24Ck; Tue, 01 Dec 2026 10:08:36 +0000 Received: from mailout3.hostsharing.net ([144.76.133.104]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYKmn-00000007J42-1toS for linux-arm-kernel@lists.infradead.org; Tue, 01 Dec 2026 10:08:35 +0000 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-Archived-By: 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_020833_645124_E8B3AB95 X-CRM114-Status: GOOD ( 18.99 ) X-Spam-Score: -2.6 (--) 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=-3.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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 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