Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH v2] PCI: Quirk devices with broken MRRS function under PCIE_BUS_PERFORMANCE mode
@ 2026-11-30 15:43 Feng Tang
  2026-11-30 15:54 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Feng Tang @ 2026-11-30 15:43 UTC (permalink / raw)
  To: Bjorn Helgaas, Christoph Hellwig, Niklas Cassel
  Cc: linux-pci, linux-kernel, Feng Tang, Anju Zheng

During stability test with "pci=pcie_bus_perf" cmdline parameter, there
was a bug that running 'mount' on one commercial NVMe disk failed on an
arm64 server, raised PCIe RAS error of "Malformed TLP", and panic the
kernel. The issue can't be reproduced after removing "pci=pcie_bus_perf".

The NVMe device has MPS(Max Payload Size) capability of 256 bytes while
its corresponding Root Port is capable of 512 bytes. When enabling
PCIE_BUS_PERFORMANCE mode, its MPS and MRRS(Max Read Request Size) are
both set to 256, while the Root Port's are both set to 512. But the
NVMe device doesn't comply with PCIe spec (v6.3), Section 7.5.3.4:

"
Max_Read_Request_Size - This field sets the maximum Read Request size
for the Function as a Requester. The Function must not generate Read
Requests with a size exceeding the set value
"

that it doesn't honor the MRRS setting, and sends out Memory Read request
with length of 512 bytes, and when Root Port replies CplD packet with 512
bytes payload which exceeds device's MPS, PCIe RAS error is issued.

The problem can be reproduced on some arm64 server and Intel server.

This caused some data damage, and there were quite a few NVMe cards of
the same type damaged (though we are not sure these are directly related).

So add a quirk for this kind of devices which don't honor MRRS part of
PCIe spec, and under PCIE_BUS_PERFORMANCE mode, limit the MPS/MRRS of
the corresponding Root Port and its children to avoid the problem.

Reported-by: Anju Zheng <zaj01616726@alibaba-inc.com>
Suggested-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Feng Tang <feng.tang@linux.alibaba.com>
---
Changelog:

  since v1:  
    * Limit the mps/mrrs from Root Port first, then top-down. (Sashiko)
    * Use correct vendor named VID instead of raw magic value (Niklas Cassel)
  
  since RFC: 
    * Add a quirk for devices identified to have broken MRRS (Christoph Hellwig)

 drivers/pci/probe.c  | 54 ++++++++++++++++++++++++++++++++++++++++----
 drivers/pci/quirks.c | 23 +++++++++++++++++++
 include/linux/pci.h  |  1 +
 3 files changed, 73 insertions(+), 5 deletions(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 27008e2ea5af..f7fa417e6dde 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -3025,6 +3025,23 @@ static int pcie_bus_configure_set(struct pci_dev *dev, void *data)
 	return 0;
 }
 
+/*
+ * Find the smallest mps of devices with broken MRRS function
+ * under a Root Port, if they exist
+ */
+static int pcie_find_sbmps(struct pci_dev *dev, void *data)
+{
+	u8 *sbmps = data;
+
+	if (!pci_is_pcie(dev))
+		return 0;
+
+	if (dev->broken_mrrs && *sbmps > dev->pcie_mpss)
+		*sbmps = dev->pcie_mpss;
+
+	return 0;
+}
+
 /*
  * pcie_bus_configure_settings() requires that pci_walk_bus work in a top-down,
  * parents then children fashion.  If this changes, then this code will not
@@ -3033,11 +3050,12 @@ static int pcie_bus_configure_set(struct pci_dev *dev, void *data)
 void pcie_bus_configure_settings(struct pci_bus *bus)
 {
 	u8 smpss = 0;
+	struct pci_dev *bridge = bus->self;
 
-	if (!bus->self)
+	if (!bridge)
 		return;
 
-	if (!pci_is_pcie(bus->self))
+	if (!pci_is_pcie(bridge))
 		return;
 
 	/*
@@ -3049,13 +3067,39 @@ void pcie_bus_configure_settings(struct pci_bus *bus)
 		smpss = 0;
 
 	if (pcie_bus_config == PCIE_BUS_SAFE) {
-		smpss = bus->self->pcie_mpss;
+		smpss = bridge->pcie_mpss;
 
-		pcie_find_smpss(bus->self, &smpss);
+		pcie_find_smpss(bridge, &smpss);
 		pci_walk_bus(bus, pcie_find_smpss, &smpss);
 	}
 
-	pcie_bus_configure_set(bus->self, &smpss);
+	if (pcie_bus_config == PCIE_BUS_PERFORMANCE &&
+	    pci_pcie_type(bridge) == PCI_EXP_TYPE_ROOT_PORT) {
+		u8 sbmps = bridge->pcie_mpss;
+
+		/*
+		 * There are devices with broken MRRS function, that they issue
+		 * Memory Read Requests with length larger than their MRRS, and
+		 * the corresponding Root Port may return CplD packet with
+		 * length larger than device's MPS, triggering "Malformed TLP"
+		 * AER error.
+		 *
+		 * Limit Root Port's MPS/MRRS down to the smallest mps of all
+		 * broken devices under it to avoid such issue.
+		 */
+		pci_walk_bus(bus, pcie_find_sbmps, &sbmps);
+		if (pcie_set_mps(bridge, 128 << sbmps))
+			pci_warn(bridge, "Can't set Max Payload Size to %d\n",
+				 128 << sbmps);
+
+		pcie_write_mrrs(bridge);
+		pci_info(bridge, "Max Payload Size set to %4d/%4d, Max Read Rq %4d\n",
+			 pcie_get_mps(bridge), 128 << bridge->pcie_mpss,
+			 pcie_get_readrq(bridge));
+	} else {
+		pcie_bus_configure_set(bridge, &smpss);
+	}
+
 	pci_walk_bus(bus, pcie_bus_configure_set, &smpss);
 }
 EXPORT_SYMBOL_GPL(pcie_bus_configure_settings);
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index de9bbccda21f..3c5441010628 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -6423,3 +6423,26 @@ static void pci_mask_replay_timer_timeout(struct pci_dev *pdev)
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_GLI, 0x9750, pci_mask_replay_timer_timeout);
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_GLI, 0x9755, pci_mask_replay_timer_timeout);
 #endif
+
+/*
+ * Some commercial NVMe devices do not honor their Max_Read_Request_Size: they
+ * issue Memory Read Requests with length larger than the MRRS the kernel set
+ * (while under PERFORMANCE mode, the kernel sets MRRS <= MPS), which breaks
+ * PCIe spec (v6.3), Sec 7.5.3.4.
+ *
+ * Under PERFORMANCE mode, the upstream Root Port may be set with a larger MPS
+ * than the device, so it could reply CplD packets with length larger than
+ * device's MPS.  The device then reports them as Malformed TLPs, raising PCIe
+ * RAS error or Machine Check Error(for x86 platform).
+ *
+ * Flag such devices so that later on its corresponding Root Port's MPS can be
+ * limited down to match the device, keeping CplD packet's length within the
+ * device's MPS.
+ *
+ * This only affects PCIE_BUS_PERFORMANCE mode.
+ */
+static void quirk_broken_mrrs(struct pci_dev *dev)
+{
+	dev->broken_mrrs = 1;
+}
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SAMSUNG, 0xa80a, quirk_broken_mrrs);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index d31a8d107b1e..adeafed52ff6 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -504,6 +504,7 @@ struct pci_dev {
 	 */
 	unsigned int	external_facing:1;
 	unsigned int	broken_intx_masking:1;	/* INTx masking can't be used */
+	unsigned int	broken_mrrs:1;		/* Issues read request with length > MRRS */
 	unsigned int	io_window_1k:1;		/* Intel bridge 1K I/O windows */
 	unsigned int	irq_managed:1;
 	unsigned int	non_compliant_bars:1;	/* Broken BARs; ignore them */
-- 
2.39.5 (Apple Git-154)


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] PCI: Quirk devices with broken MRRS function under PCIE_BUS_PERFORMANCE mode
  2026-11-30 15:43 [PATCH v2] PCI: Quirk devices with broken MRRS function under PCIE_BUS_PERFORMANCE mode Feng Tang
@ 2026-11-30 15:54 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-30 15:54 UTC (permalink / raw)
  To: Feng Tang; +Cc: linux-pci

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] PCI: pcie_find_sbmps() ignores smaller MPSS on intermediate
  bridges
--

commit 71fbc43c3b824c6971cd3594dc63449905c21a34
Author: Feng Tang <feng.tang@linux.alibaba.com>

PCI: Quirk devices with broken MRRS function under PCIE_BUS_PERFORMANCE mode

This commit adds a quirk flag for PCIe devices that issue read requests
exceeding their configured MRRS, and clamps the upstream Root Port's MPS
and MRRS to the smallest MPSS among broken devices under it when running
in PCIE_BUS_PERFORMANCE mode.

> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index 2e84fc3d5df96..6e4b78b156f17 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -3041,6 +3041,23 @@ static int pcie_bus_configure_set(struct pci_dev *dev, void *data)
>  	return 0;
>  }
>  
> +/*
> + * Find the smallest mps of devices with broken MRRS function
> + * under a Root Port, if they exist
> + */
> +static int pcie_find_sbmps(struct pci_dev *dev, void *data)
> +{
> +	u8 *sbmps = data;
> +
> +	if (!pci_is_pcie(dev))
> +		return 0;
> +
> +	if (dev->broken_mrrs && *sbmps > dev->pcie_mpss)
> +		*sbmps = dev->pcie_mpss;
> +
> +	return 0;
> +}
> +
>  /*
>   * pcie_bus_configure_settings() requires that pci_walk_bus work in a top-down,
>   * parents then children fashion.  If this changes, then this code will not
> @@ -3049,11 +3066,12 @@ static int pcie_bus_configure_set(struct pci_dev *dev, void *data)
>  void pcie_bus_configure_settings(struct pci_bus *bus)
>  {
>  	u8 smpss = 0;
> +	struct pci_dev *bridge = bus->self;
>  
> -	if (!bus->self)
> +	if (!bridge)
>  		return;
>  
> -	if (!pci_is_pcie(bus->self))
> +	if (!pci_is_pcie(bridge))
>  		return;
>  
>  	/*
> @@ -3065,13 +3083,39 @@ void pcie_bus_configure_settings(struct pci_bus *bus)
>  		smpss = 0;
>  
>  	if (pcie_bus_config == PCIE_BUS_SAFE) {
> -		smpss = bus->self->pcie_mpss;
> +		smpss = bridge->pcie_mpss;
>  
> -		pcie_find_smpss(bus->self, &smpss);
> +		pcie_find_smpss(bridge, &smpss);
>  		pci_walk_bus(bus, pcie_find_smpss, &smpss);
>  	}
>  
> -	pcie_bus_configure_set(bus->self, &smpss);
> +	if (pcie_bus_config == PCIE_BUS_PERFORMANCE &&
> +	    pci_pcie_type(bridge) == PCI_EXP_TYPE_ROOT_PORT) {
> +		u8 sbmps = bridge->pcie_mpss;
> +
> +		/*
> +		 * There are devices with broken MRRS function, that they issue
> +		 * Memory Read Requests with length larger than their MRRS, and
> +		 * the corresponding Root Port may return CplD packet with
> +		 * length larger than device's MPS, triggering "Malformed TLP"
> +		 * AER error.
> +		 *
> +		 * Limit Root Port's MPS/MRRS down to the smallest mps of all
> +		 * broken devices under it to avoid such issue.
> +		 */
> +		pci_walk_bus(bus, pcie_find_sbmps, &sbmps);

[Severity: Medium]
Does pcie_find_sbmps() leave the Root Port's MPS larger than the
endpoint's effective MPS when a broken_mrrs device sits behind an
intermediate switch or bridge with a smaller pcie_mpss?

pcie_find_sbmps() only checks dev->pcie_mpss on the broken_mrrs endpoint
itself, whereas the subsequent top-down walk in pcie_write_mps() clamps
each device's MPS to min(mps, pcie_get_mps(dev->bus->self)).  If a Root
Port supports 512B, an intermediate switch supports 128B, and the
broken_mrrs endpoint supports 256B, the Root Port is set to 256B while
the switch and endpoint are clamped to 128B, so the Root Port can still
return 256B CplD packets that trigger Malformed TLP errors.

Also, gating this block on pci_pcie_type(bridge) == PCI_EXP_TYPE_ROOT_PORT
skips the clamp completely when pcie_bus_configure_settings() is called
during hotplug below a switch downstream port.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130154317.69012-1-feng.tang@linux.alibaba.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-30 15:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 15:43 [PATCH v2] PCI: Quirk devices with broken MRRS function under PCIE_BUS_PERFORMANCE mode Feng Tang
2026-11-30 15:54 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox