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=1796055066; b=xx6on9FSUQ2KHTiP32950GjE1KvjGV0FzoS8Di0wo1xo/EzTnDS0s3BKZQ2EXz8cCAHi Jb9omsxEcx87Y3K6d10tyd4MI5jx2fQw3WnroX3MQsqW12qHicUjDVQGF6n4a7XnRSWnp VOk1lphGWncmTX0F7fJSxg2/Jb9/Schktcjn4ZUsreG9oaMXzdzyovUerlTFFhpgDJrcM aPj9IsMiNzek/uwy9yYr5guLx9k+jqZh4HOR4c4OnzNYSwYVpPuihZZ57icPyeTwdEEXI UnW63/AAi5Sp7R+cfdmzNfiVHH8CvluBRjwZZuT01Oyi1G1Ol/4V5jA6u23B7XfyI1Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796055066; 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=jmMsAy0H4Qa3FJ9RoLsHf0NXZFT9xPxvX6qqA7PkVRk=; b=G9rg1uAyMXEhm8Y/QulsR0EW+/R/V7vktI/aELtWXNqCcDh6MnlJSS+3nlzzqIyCRvLO nvRT5899rL6aAxPFpC0sp1xsjahzKTtyzyWInnO3khRNTZ7LRLQiPMJuwno/+SPpr+hOL E82C+vbv2aGTW5CZk0fHZS/LHPhcrpr3kBfDAbFfkLWn01HbEEYTwdMrEvxrQa+GRxSak hhIZewDfqf0nKBRqxqZDbvbaSOk/HDvt/Oa5n1uYb9B9kSM1SlIJFhqEDkh82kwIO/cK6 BYpv9rRATu/u10+I7DkAl4busOfpCSSiHWegRi/JQb4Vc4hxqOT0oW27tBqEUVYtVFg== 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=yp62K5TC; 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 B9CF9606A320; Mon, 30 Nov 2026 16:11:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B9CF9606A320 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=yp62K5TC Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id F38F1C2AC6E; Mon, 30 Nov 2026 16:11:12 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id CDD6B6007C; Mon, 30 Nov 2026 16:11:02 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id D3A6111EA018C; Mon, 30 Nov 2026 17:10:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796055062; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=jmMsAy0H4Qa3FJ9RoLsHf0NXZFT9xPxvX6qqA7PkVRk=; b=yp62K5TCRPDLRbt1ztFVecdY9uQfLIhEn5zykGqD79w3Ogb7+VXjJvOtl9FGMRvPf8f4gN KBbzmzvLc/sJOIxr0KQpDe7RDMx6gvVkT8ZB5FjZB5BNERiZkvpAAKKYPcw8un8DMeWW0d ymePxa9zGa6SJ00m0k51oIAjoAG0zHMGsrmtqnNrLxPCMISffV1lxvijHJcioHk/pL58/+ HHBI/qdWnYNMfV2CWklVHJdLTiTO7ibOagr3rK8grMbEMH5K7uoAp9h1FXEv1rKHW1rxbu GTQQCFbA8sHtlXumo0W+KgTmPAVwa1jjkR8ZJkq028byXtHLv5Z3r1lX7GwuUg== Message-ID: <85496e523aa151992d17858ccd141d05f0aca0b6.camel@bootlin.com> Subject: Re: [PATCH] PCI: Fix root port reset lock ordering From: Paul Cercueil To: sashiko-reviews@lists.linux.dev Cc: linux-pci@vger.kernel.org, Bjorn Helgaas , Manivannan Sadhasivam , Thomas Petazzoni , stable@vger.kernel.org Date: Mon, 30 Nov 2026 17:10:56 +0100 In-Reply-To: References: <20261130153218.189926-1-paul.cercueil@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-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 Sashiko, Le lundi 30 novembre 2026 =C3=A0 15:45 +0000, sashiko-bot@kernel.org a =C3= =A9crit=C2=A0: > Thank you for your contribution! Sashiko AI review found 1 potential > issue to consider: > - [High] PCI: pciehp: ABBA deadlock with pci_slot_mutex in > =C2=A0 pciehp_lock_rescan_remove() > -- >=20 > commit 70e71b321e54d0d7c6157b8dbdebfb52c2965df1 > Author: Paul Cercueil >=20 > PCI: Fix root port reset lock ordering >=20 > This commit adds pciehp_lock_rescan_remove() to temporarily release > ctrl->reset_lock while acquiring pci_rescan_remove_lock in > pciehp_configure_device() and pciehp_unconfigure_device(). >=20 > > diff --git a/drivers/pci/hotplug/pciehp_pci.c > > b/drivers/pci/hotplug/pciehp_pci.c > > index 65e50bee1a8c0..20549c83870e2 100644 > > --- a/drivers/pci/hotplug/pciehp_pci.c > > +++ b/drivers/pci/hotplug/pciehp_pci.c > > @@ -21,11 +21,28 @@ > > =C2=A0#include "../pci.h" > > =C2=A0#include "pciehp.h" > > =C2=A0 > > +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.=C2=A0 Drop th= e > > + * 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); > > +} >=20 > [Severity: High] > Does re-acquiring ctrl->reset_lock here leave an ABBA deadlock with > pci_slot_mutex? >=20 > CPU0=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=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=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 CPU1 > ----=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=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=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ---- > down_read(&ctrl->reset_lock) > =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=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=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 mutex_lock(&pci_slot_mutex) > mutex_lock(&pci_slot_mutex) > =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=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=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 down_write(&ctrl->reset_lock) >=20 > =C2=A0*** DEADLOCK *** >=20 > CPU0: pciehp_ist() -> ... -> pciehp_configure_device() -> > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pciehp_lock_rescan_remove() -> pci_scan_sl= ot() -> ... -> > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pci_setup_device() -> pci_dev_assign_slot(= ) > CPU1: aer_root_reset() -> pci_bus_error_reset() -> pci_reset_bridge() -> > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pci_slot_reset() -> pci_reset_hotplug_slot= () -> pciehp_reset_slot() >=20 > In pciehp_configure_device(), pci_scan_slot() and pci_hp_add_bridge() run > while ctrl->reset_lock is held and take pci_slot_mutex via > pci_dev_assign_slot().=C2=A0 Meanwhile, pci_reset_bridge() takes pci_slot= _mutex > before calling into pciehp_reset_slot(), which takes ctrl->reset_lock for > writing. Ok, that's a deadlock, but it's also a pre-existing one and unrelated to my= fix. This patch only fixes the rescan lock / reset_lock inversion introduced by = the link-down recovery path, so I'd like to keep it scoped to that. > In pci_host_reset_root_port(), where pci_rescan_remove_lock is held aroun= d > pci_bus_error_reset(), the lock order is pci_rescan_remove_lock -> > pci_slot_mutex -> ctrl->reset_lock, which triggers a lockdep circular > locking splat against pciehp_configure_device() (pci_rescan_remove_lock -= > > ctrl->reset_lock -> pci_slot_mutex).=C2=A0 Callers of pci_reset_bridge() = that do > not hold pci_rescan_remove_lock, such as aer_root_reset() and > reset_subordinate_store(), can deadlock at runtime with > pciehp_configure_device(). This is BS. How do you see a deadlock here, while also saying that both pci_host_reset_root_port() and pciehp_configure_device() start by grabbing = the rescan lock? -Paul