From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796085680; b=1hScCrd069dmWlvlnbA606ShRl9MnXVeBuJopSRPLgkKgrvQaptDH51QkMNCHb59Uxd4 AGX2clQdds3xbtWJ1hGc1zvKngAHrsNUDZMyJt1hVhdIqJqgifczgD4XclHUdd3xTIaD/ eCWyw4W/TdKf7NM1CP88rAtEMHyecDhQvLsYOmzB9h1q/cxdOfq0iTsaG/i0HVntrzPw6 Suk5UuNjRV8FVSM5tmykGUq593G0HEy2itGGjvucuaB9gYCA7VgoI122SDMe8zYobwTen TXsu+bIUBQeVBLR3kXV1dQvHmBHi12pEvACJFp+M4t1QVg5lCPVirNfkRMH/Y33tKaw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796085680; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=Af9VCZywyTQMThWUzxXK6NO/q0YGWoTS857ILrofZEc=; b=274BfNqWy5f1h3ddDdkmu6lp1Q10Lg48B3+IO4aQQfvompTj7AeG/udiappBKeVBvDHj WrW43vcRnjfAu9gI1iNEpJgc4vffC2rfGALSkVFgj5jBFK+ZVfjsq2cROeEkWI/K5zYmL oW6y0OsJPT6nx37vYGvzqqXQHLC88+IgpNuh4p49cT/mU+/vtDcQz1hAmp1+XGRt+kzc4 QcBV8Y34CCFDX5nE3MkGaca4rskIpThputV8Ra/4JAr6tSDQM+hqVCX0j5lDkBL5uxUaR whSM8fXrLH8woLgUUgyli9X4cq0u0wD14VEhlEHsKnO1DeIrJ7MD8ozqKmv1ESayE3g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lUU2n2ZC; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C4C4606A31A; Tue, 1 Dec 2026 00:41:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lUU2n2ZC Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CF741F000C1; Tue, 1 Dec 2026 00:41:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796085679; bh=Af9VCZywyTQMThWUzxXK6NO/q0YGWoTS857ILrofZEc=; h=Date:From:To:Cc:Subject:In-Reply-To; b=lUU2n2ZCa5IK2wm2HDRv5tuGWyxe1QBeXWWQP1nJLsqy8iF4EAlFTKRK6An/mjHL4 5SSwJLvNJPCcTjG1L4yz/MrN+JwHj49NIX6G9ciBmWywJKlb7ZXWVMTR+mYsewZ1/z DuyeUjn2tqiMJuTGm8kZ4yTFjC8fReYJJggO3la2u6Z2mKDyaCKRBEX3oMM12xhwnO Mj/BKWl3NcbDHAn0ciBUbUWND2YpC3RHB5eXEL6ZFKyB/4ARSeetlAiLZroAAwuKBN s9qswDX4ipuLyH5EsrKep7+ym90UI5693zKZVLLJW7A39+Vchdqi+0DHRJ048i8pl2 Xwn1VQXODlDtA== Date: Mon, 30 Nov 2026 18:41:18 -0600 From: Bjorn Helgaas To: Feng Tang Cc: Bjorn Helgaas , Christoph Hellwig , Niklas Cassel , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Anju Zheng , Kanchan Joshi , Nitesh Shetty , Judy Brock Subject: Re: [PATCH v2] PCI: Quirk devices with broken MRRS function under PCIE_BUS_PERFORMANCE mode Message-ID: <20261201004118.GA403831@bhelgaas> 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261130154317.69012-1-feng.tang@linux.alibaba.com> [+cc Samsung folks since this apparently affects a Samsung device] On Mon, Nov 30, 2026 at 11:43:17PM +0800, Feng Tang wrote: > 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". Do you have the dmesg log for this error? The TLP header should confirm that the completion with data actually came from the Root Port, i.e., not from a peer-to-peer transfer. > 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. IIUC you have: Root Port: MPS=512 MRRS=512 NVMe: MPS=256 MRRS=256 and the NVMe device with MRRS=256 initiates memory read requests with length=512, which indeed sounds like an issue with the NVMe device. Do you have "lspci -vv" output for the hierarchy? There's a nice discussion of MPS and MRRS in the "Understanding Performance of PCI Express Systems" whitepaper at https://docs.amd.com/v/u/en-US/wp350, which claims that "every device in the hierarchy must use the same MPS setting, and the setting must not exceed the capability of any device within the hierarchy." In the PCIE_BUS_PERFORMANCE case, Linux doesn't actually observe that advice: it sets the Root Port MPS to the maximum it supports (512 in this case) even though the NVMe only supports 256. Linux sets the NVMe MRRS to its MPS (256) and assumes that since the NVMe never initiates a read larger than 256, it will never receive a completion TLP larger than 256. I assume you've done similar testing on other NVMe devices with PCIE_BUS_PERFORMANCE and found that they *do* correctly observe their MRRS settings? > 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) >