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=1796052752; b=pQiIb/9B60wYm35W1KxcJJ+pqrvjlll1CxkAnnYoYKAFoHjXv+jkKv5jjE7DGgwrt7GZ 3UHSPwVUvbHacG0HS7wVM90rVto9rt6wxflf1H4H7XwDscqPil2FejrckzP2GLIseMjWl LLZIW4+yXxM8y8YeILZnam0Djt5h74LtLrGlY7BS0TyTzKF5LPzHEwR7henFqzmm1d22N HSRA7VxNLk44HDWrFtEqaji2x3sg9HTGkqvZdzgJInMCsRj2utMSItR8h3j0P7QKuPT9V n4oKvg/ZHk0clS0C5wqY9Oy7O1+DURsljtQ/RkhVfgPUTX72n7x4K748sA9TsQ4rgUw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796052752; h=DMARC-Filter:Received:Received:Received:DKIM-Signature:From:To:Cc: Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding:X-Last-TLS-Session-Version; bh=tfVjeAsvvyO5KDDcWyextwtnebBURtG6Bw7XCX01/5Y=; b=gpket9RrE1UOH6r8pRrHlLTmc7vkNYlOnRpTjKGbjcEcosQ2gj6RTC+P6ANQjalrCiho YqPygZ4eXMkAbG102POVanCkroCHQOwRglcwKYbfwohttQmMpFmfiKbJswyMDhGdfuQet QsUV6g1ykOcLJM2oKKmv85dfDFY8KDi5ie0ILEoaFq9A8psEgwSorE6IvrSbknRY5wMBV vv18EkzcihUoQx3rKjB2hgTYSZhIqeSNpeJs6CYaGL0dlCQQojqHbUheOAVeN9MQU2YOE XZerpEQFN+Jj1r8bGk2hNZ+n7jxHFb4ydF4epQIK9ojFXQSwISdl8bdjCK0sHKwMNLA== 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=D6VsnalI; 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 27ABA606A320 for ; Mon, 30 Nov 2026 15:32:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 27ABA606A320 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=D6VsnalI Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 918ADC2AC6A; Mon, 30 Nov 2026 15:32:40 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 71F2C6007C; Mon, 30 Nov 2026 15:32:30 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 2732A11EA00C4; Mon, 30 Nov 2026 16:32:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796052749; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding; bh=tfVjeAsvvyO5KDDcWyextwtnebBURtG6Bw7XCX01/5Y=; b=D6VsnalI+D2REM7SNMjxdsC0xSKQUUMv9QzHHK+WRSKF1Z+ZA48Xi0qhRcvHv/afmG43X8 ECweVMEJOuQdVPgC3ZML84jgykz3yDlnoP3w6lBKwxsvdSN2ErQR5vFbJ047AAELIeZ1AE A7YxiAt2+uoE074ZS9oCHDGryggsmLTuXCR+S6R0KaajnWAY91Xl0tIfB7F+yev8f3anu1 rVxCNMwVbqEW58+Bv3fcwycc/rVwspA8SwkCFflb7Ou0ieNUly+TUef2q9USVPqkMR9Pka RBloDInChTbc3bLKQIILGViLRlJkOImjPZ4LRRRvJTNT27ERuO4vo2HhAwFbNg== From: Paul Cercueil To: Bjorn Helgaas Cc: Manivannan Sadhasivam , Thomas Petazzoni , linux-pci@vger.kernel.org, Paul Cercueil , stable@vger.kernel.org Subject: [PATCH] PCI: Fix root port reset lock ordering Date: Mon, 30 Nov 2026 16:32:18 +0100 Message-ID: <20261130153218.189926-1-paul.cercueil@bootlin.com> X-Mailer: git-send-email 2.47.3 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 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 Currently, pci_host_reset_root_port() calls pci_lock_rescan_remove(), to protect pci_bus_error_reset(). The reset function then calls pci_reset_bridge(), then pci_slot_reset(), pci_reset_hotplug_slot(), which will call the .reset_slot callback. For a pciehp root port, this calls the pciehp_reset_slot() function, which will grab the 'reset_lock'. On the other hand, the pciehp IRQ handler pciehp_ist() gets the 'reset_lock' first, then calls pciehp_handle_presence_or_link_change(), which will call pciehp_enable_slot(), __pciehp_enable_slot(), board_added(), then finally pciehp_configure_device(), which will call pci_lock_rescan_remove(). Address this ABBA locking issue by temporarily releasing the 'reset_lock' in pciehp_{un}configure_device, just to grab the rescan lock before locking the 'reset_lock' once again. Fixes: 4c99bace4f4e ("PCI: host-common: Add link down handling for Root Ports") Cc: stable@vger.kernel.org Signed-off-by: Paul Cercueil --- drivers/pci/hotplug/pciehp_pci.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/pci/hotplug/pciehp_pci.c b/drivers/pci/hotplug/pciehp_pci.c index 65e50bee1a8c..20549c83870e 100644 --- a/drivers/pci/hotplug/pciehp_pci.c +++ b/drivers/pci/hotplug/pciehp_pci.c @@ -21,11 +21,28 @@ #include "../pci.h" #include "pciehp.h" +static inline void pciehp_lock_rescan_remove(struct controller *ctrl) +{ + /* + * pciehp_ist() calls us holding reset_lock, whereas the error-reset + * path takes pci_rescan_remove_lock before reset_lock. Drop the + * reader to acquire the rescan lock as the outermost lock, then + * reacquire reset_lock below it so the order rescan lock -> + * reset_lock is preserved. + */ + lockdep_assert_held_read(&ctrl->reset_lock); + up_read(&ctrl->reset_lock); + + pci_lock_rescan_remove(); + down_read_nested(&ctrl->reset_lock, ctrl->depth); +} + /** * pciehp_configure_device() - enumerate PCI devices below a hotplug bridge * @ctrl: PCIe hotplug controller * * Enumerate PCI devices below a hotplug bridge and add them to the system. + * The caller must hold @ctrl->reset_lock for reading. * Return 0 on success, %-EEXIST if the devices are already enumerated or * %-ENODEV if enumeration failed. */ @@ -36,7 +53,7 @@ int pciehp_configure_device(struct controller *ctrl) struct pci_bus *parent = bridge->subordinate; int num, ret = 0; - pci_lock_rescan_remove(); + pciehp_lock_rescan_remove(ctrl); dev = pci_get_slot(parent, PCI_DEVFN(0, 0)); if (dev) { @@ -91,6 +108,7 @@ int pciehp_configure_device(struct controller *ctrl) * Unbind PCI devices below a hotplug bridge from their drivers and remove * them from the system. Safely removed devices are quiesced. Surprise * removed devices are marked as such to prevent further accesses. + * The caller must hold @ctrl->reset_lock for reading. */ void pciehp_unconfigure_device(struct controller *ctrl, bool presence) { @@ -104,7 +122,7 @@ void pciehp_unconfigure_device(struct controller *ctrl, bool presence) if (!presence) pci_walk_bus(parent, pci_dev_set_disconnected, NULL); - pci_lock_rescan_remove(); + pciehp_lock_rescan_remove(ctrl); /* * Stopping an SR-IOV PF device removes all the associated VFs, -- 2.47.3