9ae3a8
From 7197c8b9234f26922ce7c6f3d7784b2604bdaafd Mon Sep 17 00:00:00 2001
9ae3a8
From: Alex Williamson <alex.williamson@redhat.com>
9ae3a8
Date: Thu, 21 Nov 2013 21:08:58 +0100
9ae3a8
Subject: [PATCH 10/14] vfio-pci: Fix multifunction=on
9ae3a8
9ae3a8
RH-Author: Alex Williamson <alex.williamson@redhat.com>
9ae3a8
Message-id: <20131121210817.12705.22782.stgit@bling.home>
9ae3a8
Patchwork-id: 55844
9ae3a8
O-Subject: [RHEL7 qemu-kvm PATCH] vfio-pci: Fix multifunction=on
9ae3a8
Bugzilla: 1029275
9ae3a8
RH-Acked-by: Amos Kong <akong@redhat.com>
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
RH-Acked-by: Bandan Das <bsd@redhat.com>
9ae3a8
9ae3a8
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1029275
9ae3a8
Brew: https://brewweb.devel.redhat.com/taskinfo?taskID=6627360
9ae3a8
Upstream: 187d62327aca39afbb038d13d7cd6bf2d11640d3
9ae3a8
9ae3a8
When an assigned device is initialized it copies the device config
9ae3a8
space into the emulated config space.  Unfortunately multifunction is
9ae3a8
setup prior to the device initfn and gets clobbered.  We need to
9ae3a8
restore it just like pci-assign does.
9ae3a8
9ae3a8
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
9ae3a8
Reviewed-by: Bandan Das <bsd@redhat.com>
9ae3a8
Message-id: 20131112185059.7262.33780.stgit@bling.home
9ae3a8
Cc: qemu-stable@nongnu.org
9ae3a8
Signed-off-by: Anthony Liguori <aliguori@amazon.com>
9ae3a8
---
9ae3a8
 hw/misc/vfio.c |    7 +++++++
9ae3a8
 1 file changed, 7 insertions(+)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 hw/misc/vfio.c |    7 +++++++
9ae3a8
 1 files changed, 7 insertions(+), 0 deletions(-)
9ae3a8
9ae3a8
diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
9ae3a8
index b7f213b..5a6925c 100644
9ae3a8
--- a/hw/misc/vfio.c
9ae3a8
+++ b/hw/misc/vfio.c
9ae3a8
@@ -3625,6 +3625,13 @@ static int vfio_initfn(PCIDevice *pdev)
9ae3a8
     vdev->emulated_config_bits[PCI_HEADER_TYPE] =
9ae3a8
                                               PCI_HEADER_TYPE_MULTI_FUNCTION;
9ae3a8
 
9ae3a8
+    /* Restore or clear multifunction, this is always controlled by QEMU */
9ae3a8
+    if (vdev->pdev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
9ae3a8
+        vdev->pdev.config[PCI_HEADER_TYPE] |= PCI_HEADER_TYPE_MULTI_FUNCTION;
9ae3a8
+    } else {
9ae3a8
+        vdev->pdev.config[PCI_HEADER_TYPE] &= ~PCI_HEADER_TYPE_MULTI_FUNCTION;
9ae3a8
+    }
9ae3a8
+
9ae3a8
     /*
9ae3a8
      * Clear host resource mapping info.  If we choose not to register a
9ae3a8
      * BAR, such as might be the case with the option ROM, we can get
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8