Received: by 10.192.165.148 with SMTP id m20csp2477558imm; Sun, 22 Apr 2018 07:52:43 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/hapHGLKRlrC8NDHhIam0NwvBLvj07X9So/KzCjv0SpF+ujQ8aMoLMhwqYSALhrzZHr1Em X-Received: by 2002:a17:902:7c02:: with SMTP id x2-v6mr17979244pll.186.1524408763457; Sun, 22 Apr 2018 07:52:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524408763; cv=none; d=google.com; s=arc-20160816; b=pd63CqeHMV4ggHOY5mXEndGqHUMzApEJyU1iq1i+4ckLx/n8hcVFR0pGJOhw8HweKm 9aMEgGxLMdVXSa/A9DT+85VhrO0PGf1mSFlFj7MYVEYDHc15D89KWwD09Qy/Vq7VVHKL EKzG2wyLjD3iCTV5MF8HBBkCNyslU3Ktg5eCZ7VsAPkqwkm8xPV9EBMQvK+RwjPzCv8I n6KtIRCzHybdEwabNK+oHqWReZ1zPLEXTtLGHa6IMkqAF98nX3efRhWyFJHLPyT97OJY ukFG9ifK503+bVKQuYUKtNjM0Dktc0VVd83MDLL8IzyhkcjKgS8vI4JtycV0RqjXuzwV +VKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=54HABwodHcGn2nXlQ/XgFb1/GGQjS4mwA3xkBvfZO+A=; b=nbgWVVi3VtbpWlh4vcwal4TjV4pnSwnz4qihoEA33p5Kkjm+hfFNBhK37u9y3yyVea Y/qNAGZQZZ83FBPKJcYlO3hTB6H2sj04yAYM7qzyjwoxVjuW6gnzkYGid9WHRZk4o5+E 1tx5QW+fvvFVwTzaakilRBU1pkjPMLhV+RMBVsG4UEcw6De31qZlkYDIcaO5zW4I5xxK 2C/PU1gZK4NdoLStScXnlriOjCInIUQue8ftCvGfRwLCiPU0I5xLI7c6TjE2PqekxEZA pN5aOkGAyOaxm5ySjXjTRRWK1NbWnIrvm2dzRVb2E5r1GEo9sUlAGFOGKztJxyYmMJty F1Mw== 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 u36si2611775pgn.213.2018.04.22.07.52.29; Sun, 22 Apr 2018 07:52:43 -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 S1756912AbeDVOP3 (ORCPT + 99 others); Sun, 22 Apr 2018 10:15:29 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:56836 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756709AbeDVOPZ (ORCPT ); Sun, 22 Apr 2018 10:15:25 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 3AC5A4A5; Sun, 22 Apr 2018 14:15:24 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alex Williamson Subject: [PATCH 4.9 59/95] vfio/pci: Virtualize Maximum Read Request Size Date: Sun, 22 Apr 2018 15:53:28 +0200 Message-Id: <20180422135212.838753130@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135210.432103639@linuxfoundation.org> References: <20180422135210.432103639@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alex Williamson commit cf0d53ba4947aad6e471491d5b20a567cbe92e56 upstream. MRRS defines the maximum read request size a device is allowed to make. Drivers will often increase this to allow more data transfer with a single request. Completions to this request are bound by the MPS setting for the bus. Aside from device quirks (none known), it doesn't seem to make sense to set an MRRS value less than MPS, yet this is a likely scenario given that user drivers do not have a system-wide view of the PCI topology. Virtualize MRRS such that the user can set MRRS >= MPS, but use MPS as the floor value that we'll write to hardware. Signed-off-by: Alex Williamson Signed-off-by: Greg Kroah-Hartman --- drivers/vfio/pci/vfio_pci_config.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) --- a/drivers/vfio/pci/vfio_pci_config.c +++ b/drivers/vfio/pci/vfio_pci_config.c @@ -810,6 +810,7 @@ static int vfio_exp_config_write(struct { __le16 *ctrl = (__le16 *)(vdev->vconfig + pos - offset + PCI_EXP_DEVCTL); + int readrq = le16_to_cpu(*ctrl) & PCI_EXP_DEVCTL_READRQ; count = vfio_default_config_write(vdev, pos, count, perm, offset, val); if (count < 0) @@ -835,6 +836,27 @@ static int vfio_exp_config_write(struct pci_try_reset_function(vdev->pdev); } + /* + * MPS is virtualized to the user, writes do not change the physical + * register since determining a proper MPS value requires a system wide + * device view. The MRRS is largely independent of MPS, but since the + * user does not have that system-wide view, they might set a safe, but + * inefficiently low value. Here we allow writes through to hardware, + * but we set the floor to the physical device MPS setting, so that + * we can at least use full TLPs, as defined by the MPS value. + * + * NB, if any devices actually depend on an artificially low MRRS + * setting, this will need to be revisited, perhaps with a quirk + * though pcie_set_readrq(). + */ + if (readrq != (le16_to_cpu(*ctrl) & PCI_EXP_DEVCTL_READRQ)) { + readrq = 128 << + ((le16_to_cpu(*ctrl) & PCI_EXP_DEVCTL_READRQ) >> 12); + readrq = max(readrq, pcie_get_mps(vdev->pdev)); + + pcie_set_readrq(vdev->pdev, readrq); + } + return count; } @@ -853,11 +875,12 @@ static int __init init_pci_cap_exp_perm( * Allow writes to device control fields, except devctl_phantom, * which could confuse IOMMU, MPS, which can break communication * with other physical devices, and the ARI bit in devctl2, which - * is set at probe time. FLR gets virtualized via our writefn. + * is set at probe time. FLR and MRRS get virtualized via our + * writefn. */ p_setw(perm, PCI_EXP_DEVCTL, - PCI_EXP_DEVCTL_BCR_FLR | PCI_EXP_DEVCTL_PAYLOAD, - ~PCI_EXP_DEVCTL_PHANTOM); + PCI_EXP_DEVCTL_BCR_FLR | PCI_EXP_DEVCTL_PAYLOAD | + PCI_EXP_DEVCTL_READRQ, ~PCI_EXP_DEVCTL_PHANTOM); p_setw(perm, PCI_EXP_DEVCTL2, NO_VIRT, ~PCI_EXP_DEVCTL2_ARI); return 0; }