Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp730224imm; Thu, 13 Sep 2018 06:57:49 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZEH2fvc+T2e9w8NKxGz5UMvxxKqLQothlELDPPrNuC9GxNOV7ZX+EGYhZWkYGC2h7fxSL7 X-Received: by 2002:a63:6a89:: with SMTP id f131-v6mr7494734pgc.165.1536847069833; Thu, 13 Sep 2018 06:57:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536847069; cv=none; d=google.com; s=arc-20160816; b=t0Ifz1Zhwm7kWs5N7Mp1DmEzgKV+iBpXGppaX3YRoXohaSUH80e6yAVfHvxsFD3X+w 9i2Q3vmExqAc4MI0Ps48N60E8a8VodFvRNN1bnDOGJHAnnFpbOaZm8hUEdZKzD8dj1K5 TS+IYNib1B+0XyYusDAgPnI+TjFFVO8LhALcvpiiMuumTXsHTwKLprchx/X98Aljp/gc XKBbrxusRezId5j3q2IcS91rakIACKT0KZmqm1pj9Q8ZudoaS81KT8bwb4LuStnKm/+E Vq62SeAEbN13GLGhJesFHzNFrSw7af5XubyAIeSn8bByRdTUeSsJZFyNLwD+AQ4Kd8b0 75cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=U7Ch3j/txieRFWbH4Iobrzjam/XtHTdiuhfG0LzSLnc=; b=Fvee3f2b94cFBMIDzoeAc4LiqUCfqMhA9V0gYEWeXUcQIGCKIDlSXKQpwk7+eyPMIA aW3ZQeg4UTHC0fNaLrQLj3Hcp7nFgVTfbaiFXj/vW1iYvVF8wgfgjvPVyXw2OEYmdK5N vdv1HLZhEf+qQ7PcekGIB9sVvbOWCQz7LU/1mAEyHSygR2WzIYOEWG+MuZ10zc7IR7tu PBXPbC8cNhs02jbaiRGCEqd8fSBdWrdAsOkHJiXv71Aq0l1oSKRZXsaCEYGYERC552HM tVEOP6vnBUbWMhL9OhMG8U4AnVI2acb1QZ7gl9y+DXxeSTvima2zxqdSm3SoJPFbnQ2y YNfg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 72-v6si4124036pfq.6.2018.09.13.06.57.35; Thu, 13 Sep 2018 06:57:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731353AbeIMTFp (ORCPT + 99 others); Thu, 13 Sep 2018 15:05:45 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34116 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729823AbeIMTFp (ORCPT ); Thu, 13 Sep 2018 15:05:45 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 2D9C9D19; Thu, 13 Sep 2018 13:56:07 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Myron Stowe , Bjorn Helgaas , Jon Mason , Keith Busch , Sinan Kaya , Dongdong Liu , Sasha Levin Subject: [PATCH 4.18 084/197] PCI: Match Root Ports MPS to endpoints MPSS as necessary Date: Thu, 13 Sep 2018 15:30:33 +0200 Message-Id: <20180913131844.891255417@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Myron Stowe [ Upstream commit 9f0e89359775ee21fe1ea732e34edb52aef5addf ] In commit 27d868b5e6cf ("PCI: Set MPS to match upstream bridge"), we made sure every device's MPS setting matches its upstream bridge, making it more likely that a hot-added device will work in a system with an optimized MPS configuration. Recently I've started encountering systems where the endpoint device's MPSS capability is less than its Root Port's current MPS value, thus the endpoint is not capable of matching its upstream bridge's MPS setting (see: bugzilla via "Link:" below). This leaves the system vulnerable - the upstream Root Port could respond with larger TLPs than the device can handle, and the device will consider them to be 'Malformed'. One could use the "pci=pcie_bus_safe" kernel parameter to work around the issue, but that forces a user to supply a kernel parameter to get the system to function reliably and may end up limiting MPS settings of other unrelated, sub-topologies which could benefit from maintaining their larger values. Augment Keith's approach to include tuning down a Root Port's MPS setting when its hot-added endpoint device is not capable of matching it. Link: https://bugzilla.kernel.org/show_bug.cgi?id=200527 Signed-off-by: Myron Stowe Signed-off-by: Bjorn Helgaas Acked-by: Jon Mason Cc: Keith Busch Cc: Sinan Kaya Cc: Dongdong Liu Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/pci/probe.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1725,7 +1725,7 @@ int pci_setup_device(struct pci_dev *dev static void pci_configure_mps(struct pci_dev *dev) { struct pci_dev *bridge = pci_upstream_bridge(dev); - int mps, p_mps, rc; + int mps, mpss, p_mps, rc; if (!pci_is_pcie(dev) || !bridge || !pci_is_pcie(bridge)) return; @@ -1753,6 +1753,14 @@ static void pci_configure_mps(struct pci if (pcie_bus_config != PCIE_BUS_DEFAULT) return; + mpss = 128 << dev->pcie_mpss; + if (mpss < p_mps && pci_pcie_type(bridge) == PCI_EXP_TYPE_ROOT_PORT) { + pcie_set_mps(bridge, mpss); + pci_info(dev, "Upstream bridge's Max Payload Size set to %d (was %d, max %d)\n", + mpss, p_mps, 128 << bridge->pcie_mpss); + p_mps = pcie_get_mps(bridge); + } + rc = pcie_set_mps(dev, p_mps); if (rc) { pci_warn(dev, "can't set Max Payload Size to %d; if necessary, use \"pci=pcie_bus_safe\" and report a bug\n", @@ -1761,7 +1769,7 @@ static void pci_configure_mps(struct pci } pci_info(dev, "Max Payload Size set to %d (was %d, max %d)\n", - p_mps, mps, 128 << dev->pcie_mpss); + p_mps, mps, mpss); } static struct hpp_type0 pci_default_type0 = {