Blame SOURCES/kvm-vfio-pci-Add-option-to-disable-GeForce-quirks.patch

4a2fec
From 7047cb9155990dec1ee27b2ce65445a13ef40f00 Mon Sep 17 00:00:00 2001
4a2fec
From: Alex Williamson <alex.williamson@redhat.com>
4a2fec
Date: Tue, 13 Feb 2018 19:04:41 +0100
4a2fec
Subject: [PATCH 14/15] vfio/pci: Add option to disable GeForce quirks
4a2fec
4a2fec
RH-Author: Alex Williamson <alex.williamson@redhat.com>
4a2fec
Message-id: <20180213190441.27565.45691.stgit@gimli.home>
4a2fec
Patchwork-id: 78998
4a2fec
O-Subject: [RHEL-7.5 qemu-kvm-rhev PATCH v2 1/2] vfio/pci: Add option to disable GeForce quirks
4a2fec
Bugzilla: 1508330
4a2fec
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
4a2fec
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
4a2fec
RH-Acked-by: Marcel Apfelbaum <marcel@redhat.com>
4a2fec
4a2fec
These quirks are necessary for GeForce, but not for Quadro/GRID/Tesla
4a2fec
assignment.  Leaving them enabled is fully functional and provides the
4a2fec
most compatibility, but due to the unique NVIDIA MSI ACK behavior[1],
4a2fec
it also introduces latency in re-triggering the MSI interrupt.  This
4a2fec
overhead is typically negligible, but has been shown to adversely
4a2fec
affect some (very) high interrupt rate applications.  This adds the
4a2fec
vfio-pci device option "x-no-geforce-quirks=" which can be set to
4a2fec
"on" to disable this additional overhead.
4a2fec
4a2fec
A follow-on optimization for GeForce might be to make use of an
4a2fec
ioeventfd to allow KVM to trigger an irqfd in the kernel vfio-pci
4a2fec
driver, avoiding the bounce through userspace to handle this device
4a2fec
write.
4a2fec
4a2fec
[1] Background: the NVIDIA driver has been observed to issue a write
4a2fec
to the MMIO mirror of PCI config space in BAR0 in order to allow the
4a2fec
MSI interrupt for the device to retrigger.  Older reports indicated a
4a2fec
write of 0xff to the (read-only) MSI capability ID register, while
4a2fec
more recently a write of 0x0 is observed at config space offset 0x704,
4a2fec
non-architected, extended config space of the device (BAR0 offset
4a2fec
0x88704).  Virtualization of this range is only required for GeForce.
4a2fec
4a2fec
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
4a2fec
(cherry picked from commit db32d0f43839627f54a1a7f8eee17baa770f52d2)
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 hw/vfio/pci-quirks.c | 9 ++++++---
4a2fec
 hw/vfio/pci.c        | 2 ++
4a2fec
 hw/vfio/pci.h        | 1 +
4a2fec
 3 files changed, 9 insertions(+), 3 deletions(-)
4a2fec
4a2fec
diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
4a2fec
index 4199771..e875cca 100644
4a2fec
--- a/hw/vfio/pci-quirks.c
4a2fec
+++ b/hw/vfio/pci-quirks.c
4a2fec
@@ -541,7 +541,8 @@ static void vfio_vga_probe_nvidia_3d0_quirk(VFIOPCIDevice *vdev)
4a2fec
     VFIOQuirk *quirk;
4a2fec
     VFIONvidia3d0Quirk *data;
4a2fec
 
4a2fec
-    if (!vfio_pci_is(vdev, PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID) ||
4a2fec
+    if (vdev->no_geforce_quirks ||
4a2fec
+        !vfio_pci_is(vdev, PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID) ||
4a2fec
         !vdev->bars[1].region.size) {
4a2fec
         return;
4a2fec
     }
4a2fec
@@ -659,7 +660,8 @@ static void vfio_probe_nvidia_bar5_quirk(VFIOPCIDevice *vdev, int nr)
4a2fec
     VFIONvidiaBAR5Quirk *bar5;
4a2fec
     VFIOConfigWindowQuirk *window;
4a2fec
 
4a2fec
-    if (!vfio_pci_is(vdev, PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID) ||
4a2fec
+    if (vdev->no_geforce_quirks ||
4a2fec
+        !vfio_pci_is(vdev, PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID) ||
4a2fec
         !vdev->vga || nr != 5 || !vdev->bars[5].ioport) {
4a2fec
         return;
4a2fec
     }
4a2fec
@@ -753,7 +755,8 @@ static void vfio_probe_nvidia_bar0_quirk(VFIOPCIDevice *vdev, int nr)
4a2fec
     VFIOQuirk *quirk;
4a2fec
     VFIOConfigMirrorQuirk *mirror;
4a2fec
 
4a2fec
-    if (!vfio_pci_is(vdev, PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID) ||
4a2fec
+    if (vdev->no_geforce_quirks ||
4a2fec
+        !vfio_pci_is(vdev, PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID) ||
4a2fec
         !vfio_is_vga(vdev) || nr != 0) {
4a2fec
         return;
4a2fec
     }
4a2fec
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
4a2fec
index b3a2889..4cfb780 100644
4a2fec
--- a/hw/vfio/pci.c
4a2fec
+++ b/hw/vfio/pci.c
4a2fec
@@ -2992,6 +2992,8 @@ static Property vfio_pci_dev_properties[] = {
4a2fec
     DEFINE_PROP_BOOL("x-no-kvm-intx", VFIOPCIDevice, no_kvm_intx, false),
4a2fec
     DEFINE_PROP_BOOL("x-no-kvm-msi", VFIOPCIDevice, no_kvm_msi, false),
4a2fec
     DEFINE_PROP_BOOL("x-no-kvm-msix", VFIOPCIDevice, no_kvm_msix, false),
4a2fec
+    DEFINE_PROP_BOOL("x-no-geforce-quirks", VFIOPCIDevice,
4a2fec
+                     no_geforce_quirks, false),
4a2fec
     DEFINE_PROP_UINT32("x-pci-vendor-id", VFIOPCIDevice, vendor_id, PCI_ANY_ID),
4a2fec
     DEFINE_PROP_UINT32("x-pci-device-id", VFIOPCIDevice, device_id, PCI_ANY_ID),
4a2fec
     DEFINE_PROP_UINT32("x-pci-sub-vendor-id", VFIOPCIDevice,
4a2fec
diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
4a2fec
index a8366bb..ed9172d 100644
4a2fec
--- a/hw/vfio/pci.h
4a2fec
+++ b/hw/vfio/pci.h
4a2fec
@@ -143,6 +143,7 @@ typedef struct VFIOPCIDevice {
4a2fec
     bool no_kvm_intx;
4a2fec
     bool no_kvm_msi;
4a2fec
     bool no_kvm_msix;
4a2fec
+    bool no_geforce_quirks;
4a2fec
 } VFIOPCIDevice;
4a2fec
 
4a2fec
 uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len);
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec