All of lore.kernel.org
 help / color / mirror / Atom feed
From: Srirangan Madhavan <smadhavan@nvidia.com>
To: Alison Schofield <alison.schofield@intel.com>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Dave Jiang <dave.jiang@intel.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Ira Weiny <iweiny@kernel.org>,
	Jonathan Cameron <jic23@kernel.org>,
	Vishal Verma <vishal.l.verma@intel.com>,
	linux-cxl@vger.kernel.org, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Li Ming <ming.li@zohomail.com>,
	Joshua Machauer <machaujo@amazon.de>,
	Alex Williamson <alex.williamson@redhat.com>,
	vsethi@nvidia.com, alwilliamson@nvidia.com,
	Sai Yashwanth Reddy Kancherla <skancherla@nvidia.com>,
	Vishal Aslot <vaslot@nvidia.com>,
	Manish Honap <mhonap@nvidia.com>, Jiandi An <jan@nvidia.com>,
	Richard Cheng <icheng@nvidia.com>,
	linux-tegra@vger.kernel.org,
	Alejandro Lucero Palau <alejandro.lucero-palau@amd.com>,
	Srirangan Madhavan <smadhavan@nvidia.com>
Subject: [PATCH v18 14/19] PCI/CXL: Reject reset with unsafe function scope
Date: Sat,  5 Dec 2026 04:14:48 +0000	[thread overview]
Message-ID: <20261205041453.3946529-15-smadhavan@nvidia.com> (raw)
In-Reply-To: <20261205041453.3946529-1-smadhavan@nvidia.com>

The per-device PCI reset interface must not reset sibling functions.
Reject cxl_reset and cxl_bus for VFs, multifunction devices, including
function 0 of an ARI device that has other functions, and PFs with enabled
VFs.

Suggested-by: Alex Williamson <alwilliamson@nvidia.com>
Link: https://lore.kernel.org/linux-cxl/20260626160846.426e71b6@nvidia.com/
Link: https://lore.kernel.org/linux-cxl/6a50441e2bb5e_3cabcb1003e@djbw-dev.notmuch/
Signed-off-by: Srirangan Madhavan <smadhavan@nvidia.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Richard Cheng <icheng@nvidia.com>

---
Changes in v18:
- Also reject function 0 of an ARI device when other functions share the
  bus, since ->multifunction is not set for it (Sashiko)
  https://sashiko.dev/#/patchset/20261105185917.2667656-1-smadhavan@nvidia.com?part=14
- Check for ARI siblings only when the reset executes. While reset methods
  are probed, the device is not on its bus list yet and its siblings are not
  enumerated, so the check could not tell whether siblings exist and rejected
  cxl_reset and cxl_bus for the first device on an ARI-forwarding bus. Found
  while testing on an ARM64 system with a CXL Type 2 device.
- Keep Bjorn's Acked-by and Richard's Reviewed-by, since only the point
  where the sibling check runs changed
---
 drivers/pci/cxl.c | 10 ++++++++++
 drivers/pci/pci.c | 13 +++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/drivers/pci/cxl.c b/drivers/pci/cxl.c
index c90715c5a6d5..0c60f6d7bb4f 100644
--- a/drivers/pci/cxl.c
+++ b/drivers/pci/cxl.c
@@ -579,6 +579,16 @@ int cxl_reset_function(struct pci_dev *pdev, bool probe)
 	u16 dvsec, cap, ctrl;
 	int rc;
 
+	/*
+	 * ->multifunction is not set for function 0 of an ARI device, so look
+	 * for siblings on the bus. Skip this when probing: @pdev is not on the
+	 * bus list yet and its siblings are not enumerated.
+	 */
+	if (pdev->is_virtfn || pdev->multifunction || pci_num_vf(pdev) ||
+	    (!probe && pci_ari_enabled(pdev->bus) &&
+	     !list_is_singular(&pdev->bus->devices)))
+		return -ENOTTY;
+
 	rc = cxl_pci_device_dvsec(pdev, &dvsec, &cap);
 	if (rc)
 		return rc;
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7c6f2aba8144..5a8338340d23 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5064,6 +5064,19 @@ static int cxl_reset_bus_function(struct pci_dev *dev, bool probe)
 	u16 dvsec, reg, val;
 	int rc;
 
+	/*
+	 * Reject VFs and multifunction devices before walking the bridge's
+	 * capabilities: every VF behind the same bridge would repeat the walk.
+	 *
+	 * ->multifunction is not set for function 0 of an ARI device, so look
+	 * for siblings on the bus. Skip this when probing: @dev is not on the
+	 * bus list yet and its siblings are not enumerated.
+	 */
+	if (dev->is_virtfn || dev->multifunction || pci_num_vf(dev) ||
+	    (!probe && pci_ari_enabled(dev->bus) &&
+	     !list_is_singular(&dev->bus->devices)))
+		return -ENOTTY;
+
 	bridge = pci_upstream_bridge(dev);
 	if (!bridge)
 		return -ENOTTY;
-- 
2.43.0


  parent reply	other threads:[~2026-12-05  4:16 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  4:14 [PATCH v18 00/19] PCI/CXL: Add CXL reset support for Type 2 devices Srirangan Madhavan
2026-12-05  4:14 ` [PATCH v18 01/19] cxl: Clarify decoder interleave limit Srirangan Madhavan
2026-12-05  4:14 ` [PATCH v18 02/19] cxl: Share CXL port upstream PCI device lookup Srirangan Madhavan
2026-12-05  4:14 ` [PATCH v18 03/19] cxl: Move decoder declarations to shared header Srirangan Madhavan
2026-12-05  4:14 ` [PATCH v18 04/19] cxl: Embed decoder configuration in a standalone structure Srirangan Madhavan
2026-12-05  4:14 ` [PATCH v18 05/19] cxl: Introduce endpoint HDM decoder settings Srirangan Madhavan
2026-12-05  4:30   ` sashiko-bot
2026-12-05  4:14 ` [PATCH v18 06/19] cxl: Move HDM decoder helpers to built-in code Srirangan Madhavan
2026-12-05  4:14 ` [PATCH v18 07/19] cxl: Share HDM decoder register unpacking Srirangan Madhavan
2026-12-05  4:30   ` sashiko-bot
2026-12-05  4:14 ` [PATCH v18 08/19] cxl: Move cxl_rwsem into built-in code Srirangan Madhavan
2026-12-05  4:14 ` [PATCH v18 09/19] cxl: Refresh cached PCI HDM decoder settings Srirangan Madhavan
2026-12-05  4:38   ` sashiko-bot
2026-12-05  4:14 ` [PATCH v18 10/19] cxl: Build register block helpers into the kernel Srirangan Madhavan
2026-12-05  4:14 ` [PATCH v18 11/19] PCI/CXL: Cache endpoint HDM state during PCI enumeration Srirangan Madhavan
2026-12-05  4:44   ` sashiko-bot
2026-12-05  4:14 ` [PATCH v18 12/19] PCI/CXL: Add CXL Device Reset sequencing Srirangan Madhavan
2026-12-05  4:38   ` sashiko-bot
2026-12-05  4:14 ` [PATCH v18 13/19] cxl: Validate and synchronize HDM ranges around reset Srirangan Madhavan
2026-12-05  4:47   ` sashiko-bot
2026-12-05  4:14 ` Srirangan Madhavan [this message]
2026-12-05  4:43   ` [PATCH v18 14/19] PCI/CXL: Reject reset with unsafe function scope sashiko-bot
2026-12-05  4:14 ` [PATCH v18 15/19] PCI/CXL: Restore CXL state after PCI reset Srirangan Madhavan
2026-12-05  4:50   ` sashiko-bot
2026-12-05  4:14 ` [PATCH v18 16/19] PCI/CXL: Expose CXL Reset as a PCI reset method Srirangan Madhavan
2026-12-05  4:48   ` sashiko-bot
2026-12-05  4:14 ` [PATCH v18 17/19] PCI/CXL: Restore CXL state after CXL bus reset Srirangan Madhavan
2026-12-05  4:47   ` sashiko-bot
2026-12-05  4:14 ` [PATCH v18 18/19] PCI/CXL: Flush host and device caches for " Srirangan Madhavan
2026-12-05  4:54   ` sashiko-bot
2026-12-05  4:14 ` [PATCH v18 19/19] cxl: Add KUnit checks for HDM decoder unpacking Srirangan Madhavan
2026-12-05  4:38   ` sashiko-bot
2026-12-05  4:54 ` [PATCH v18 00/19] PCI/CXL: Add CXL reset support for Type 2 devices sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261205041453.3946529-15-smadhavan@nvidia.com \
    --to=smadhavan@nvidia.com \
    --cc=alejandro.lucero-palau@amd.com \
    --cc=alex.williamson@redhat.com \
    --cc=alison.schofield@intel.com \
    --cc=alwilliamson@nvidia.com \
    --cc=bhelgaas@google.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=icheng@nvidia.com \
    --cc=iweiny@kernel.org \
    --cc=jan@nvidia.com \
    --cc=jic23@kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=machaujo@amazon.de \
    --cc=mhonap@nvidia.com \
    --cc=ming.li@zohomail.com \
    --cc=skancherla@nvidia.com \
    --cc=vaslot@nvidia.com \
    --cc=vishal.l.verma@intel.com \
    --cc=vsethi@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.