From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.110 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796053403; b=cKCiPSjbeelB3nfedbQp/Gy/d/N0OS1gbY78opY88y89Mb8/CZT0A6K1WHYfEc7sqVYx hFGzHS4LXhMEKkozJrmg93uUX8o9Kc2MP04wy0y8wVmZrTbZLKFCTbkFRPMangINAOKcS fD+/swLfNMKICjB4OccVDAO+8fubYQ5nF8KztceS+NF1FLkjVGGgF1VZmdOVZ+zcH5lLg oaLwFFlCUiPqicMXQM9fbUyY7SxTlNsd2TAMHNBg6Nk50xUTWkq6FH5CQJROSCZJcmcEx zLOgpptjKKRtryNQfxYjBzwcWPyLtSNx1ucsWTIeb0uhQFIpfGStbP/f8qI8uUR81FQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796053403; h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:From:To:Cc: Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=6AdmKUB2HNfD5NFllLOK46x19weihkcR+GphEB1c7/c=; b=bVH3+UoiMbLo+X0wBhmdd0Nb0qcgnDJYfOI25K0zx1ozt87JW8/V780c4cEG70G0MjeL TYynPWMs1ysv6kGseoLw7HQzVMsw0SjMU5m4juruLGtFpCi7818CJBWCLXhuc4k09Q3h3 Hucv6HJD/zVhg+GcLNHIvCZEguYekVG7ZK8aW0NeKbu3Lg1EhZklBSYCZCkG5qNSrWJBz 4FqxAvn6iBpsHU7NCCqwg0uY9FmFgjZE6rSOD+JaZGqEh1CrsaCoPPgaUyxGXQ36WlLAh 6MIQSamtIh1pfm2nq0Dz/lrm4ED97laC8zr5twv94KO1n5ztoUW8976FNnXwm82Wwpg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=rqmZC3dK; arc=none smtp.remote-ip=115.124.30.110 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) (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 BC2D2606A329; Mon, 30 Nov 2026 15:43:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BC2D2606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=rqmZC3dK DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1796053398; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=6AdmKUB2HNfD5NFllLOK46x19weihkcR+GphEB1c7/c=; b=rqmZC3dK7X5AtLLIBu46nS8cevfox3xBFfl0eQcyZiAb1mXfqbT9o+Yb8e+KtiR4o8G+H8dwIlAIYm0XkgxNrTiWaxccw5YyxpUGjAx2kT6xyNDvvJVyvPFVC3gge5fVIDYe6D6sx3gD8xCVaruIdcM8BK3x0vJgqre7i9Y9HxQ= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam011083073210;MF=feng.tang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0XFp6mL0_1796053397; Received: from localhost(mailfrom:feng.tang@linux.alibaba.com fp:SMTPD_---0XFp6mL0_1796053397 cluster:ay36) by smtp.aliyun-inc.com; Mon, 30 Nov 2026 23:43:18 +0800 From: Feng Tang To: Bjorn Helgaas , Christoph Hellwig , Niklas Cassel Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Feng Tang , Anju Zheng Subject: [PATCH v2] PCI: Quirk devices with broken MRRS function under PCIE_BUS_PERFORMANCE mode Date: Mon, 30 Nov 2026 23:43:17 +0800 Message-Id: <20261130154317.69012-1-feng.tang@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) X-Mailing-List: linux-kernel@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 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 Suggested-by: Christoph Hellwig Signed-off-by: Feng Tang --- 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)