[PATCH RFC] PCI: Add warning about possible danger for pcie_bus_perf mode

Feng Tang posted 1 patch an hour ago
include/linux/pci.h | 12 ++++++++++++
1 file changed, 12 insertions(+)
[PATCH RFC] PCI: Add warning about possible danger for pcie_bus_perf mode
Posted by Feng Tang an hour ago
During stability test, there was a bug that running 'mount' on a type
of commercial NVME disk failed on an arm64 server and raised PCIe RAS
error and panic the kernel later, when using "pci=pcie_bus_perf" kernel
cmdline parameter.

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 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).

In this case, the kernel is innocent as it does make sure a device's MRRS
setting is no larger than its MPS setting, while the device breaks PCIe
spec. It could still be meaningful to warn about the possible danger.

Reported-by: Anju Zheng <zaj01616726@alibaba-inc.com>
Signed-off-by: Feng Tang <feng.tang@linux.alibaba.com>
---
 include/linux/pci.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/include/linux/pci.h b/include/linux/pci.h
index d31a8d107b1e..e115aa2e962a 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1192,6 +1192,18 @@ static inline int pci_has_flag(int flag) { return pci_flags & flag; }
 
 void pcie_bus_configure_settings(struct pci_bus *bus);
 
+/*
+ * Note: For PCIE_BUS_PERFORMANCE mode, it could be dangerous for a device
+ * that doesn't completely comply with PCIe spec about MPS and MRRS setting,
+ * as it allows the device and its corresponding root port to have different
+ * MPS settings.
+ *
+ * Kernel already makes sure a device's MRRS setting is no larger than its
+ * MPS setting. But there is real world case that some commercial NVME device
+ * sends out Memory Read request with length bigger than its MRRS (equals to
+ * its MPS),  and root port replies CplD packet with that bigger length, which
+ * triggers RAS/MCE errors on arm64 and x86 servers, causing data damage.
+ */
 enum pcie_bus_config_types {
 	PCIE_BUS_TUNE_OFF,	/* Don't touch MPS at all */
 	PCIE_BUS_DEFAULT,	/* Ensure MPS matches upstream bridge */
-- 
2.39.5 (Apple Git-154)