Received: by 10.192.165.148 with SMTP id m20csp2464374imm; Sun, 22 Apr 2018 07:35:18 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/v+6G4SQO5NTDE+AT0H82a1iMex5zmgDCQRKyTF+HPvLGSa3ukmmhUA4Fn8VfT1l3iAAX0 X-Received: by 10.98.95.198 with SMTP id t189mr16318653pfb.244.1524407718324; Sun, 22 Apr 2018 07:35:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524407718; cv=none; d=google.com; s=arc-20160816; b=BuHiKIn546IQM7hUtUbN9cXmO1R1IIp5xm9bU2Ok3+aBvsY2/5/0+xYfDs3V0Hnlmh rc+7u4yP7FpA6/7nQ//pckHACqqF6LsChaacAzKCvwy7XK+YQg9tsJacRPYVCYAFvDV3 oh1jvsJB/SWfdCiYKcZZM7aZDx+43nTSzQFgWcw/ibpRdj8Jc40TIAJ7dUQozM9tl2xb U3f4yeg7pTJecAOa48/X/mcK84gFHmQpQMSyE6ummc5SbupTCMBh+Hwh047bPNwZOZ9H DQ1nlrfI3VwHUIcck1PtZLF0jinBfnphcV1MMoz32Pxi8sJ1Z3KrDcbFJYPtJjyC7EkK 7Mcw== 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=P1pav3ZJGCYZ5yhGSMd0DjMe2abob3Pnlffi0Wbi8uo=; b=V4ae2PZwux9QhTwE9vOdsPgZ9P4R5fLWdjsA/3/G7YMxawsebivJv4NzNC97Di/f9E mysxD5xrJq2PwIUFIT2iE6uIv0C6USfD5tMMilCGmnj4YtyBwkXHiJS4K0GCDvukJQ02 KTB+VOz6c2JrM2MGETXOC0sgiEnWvge3sbKb2TY2q73ISLFr4EcXOVBtZn0tL+iwUvaD 0Lv9OGZvqM2WpcShMZyFt6Ls9vsyJIsQ1BUFObWSF0/KjTDGCjMI/DPLJYWwWg0m4iog 1VBFE01ETaS0UtcO9yT5TCYM/lG4Fh356sd20hmx/KPbaXnmLnmlM4uMDMYjQVHOFnMD gYLA== 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 p188si8224645pga.206.2018.04.22.07.35.04; Sun, 22 Apr 2018 07:35:18 -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 S1757369AbeDVOeA (ORCPT + 99 others); Sun, 22 Apr 2018 10:34:00 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:59794 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754011AbeDVOTe (ORCPT ); Sun, 22 Apr 2018 10:19:34 -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 EEB5015; Sun, 22 Apr 2018 14:19:33 +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.4 73/97] vfio/pci: Virtualize Maximum Read Request Size Date: Sun, 22 Apr 2018 15:53:51 +0200 Message-Id: <20180422135309.234572729@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135304.577223025@linuxfoundation.org> References: <20180422135304.577223025@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.4-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 @@ -758,6 +758,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) @@ -783,6 +784,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; } @@ -801,11 +823,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; }