qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PULL 0/2] VFIO update 2020-06-11
@ 2020-06-11 19:04 Alex Williamson
  2020-06-11 19:04 ` [PULL 1/2] hw/vfio: Add VMD Passthrough Quirk Alex Williamson
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Alex Williamson @ 2020-06-11 19:04 UTC (permalink / raw)
  To: qemu-devel; +Cc: Thomas Huth, Philippe Mathieu-Daudé, Jon Derrick

The following changes since commit 3666f684761a3cccd86d13c752273be207ecade4:

  Merge remote-tracking branch 'remotes/ericb/tags/pull-bitmaps-2020-06-09' into staging (2020-06-11 15:35:44 +0100)

are available in the Git repository at:

  git://github.com/awilliam/qemu-vfio.git tags/vfio-update-20200611.0

for you to fetch changes up to 643a4eacef87a318cf71800a4fb2ae1f78c4b245:

  hw/vfio/pci-quirks: Fix broken legacy IGD passthrough (2020-06-11 11:36:40 -0600)

----------------------------------------------------------------
VFIO update 2020-06-11

 - Fix IGD split, include header to honor Kconfig (Thomas Huth)

 - New VMD device paravirt quirk (Jon Derrick)

----------------------------------------------------------------
Jon Derrick (1):
      hw/vfio: Add VMD Passthrough Quirk

Thomas Huth (1):
      hw/vfio/pci-quirks: Fix broken legacy IGD passthrough

 hw/vfio/pci-quirks.c | 85 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 73 insertions(+), 12 deletions(-)



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PULL 1/2] hw/vfio: Add VMD Passthrough Quirk
  2020-06-11 19:04 [PULL 0/2] VFIO update 2020-06-11 Alex Williamson
@ 2020-06-11 19:04 ` Alex Williamson
  2020-06-11 19:04 ` [PULL 2/2] hw/vfio/pci-quirks: Fix broken legacy IGD passthrough Alex Williamson
  2020-06-12 10:16 ` [PULL 0/2] VFIO update 2020-06-11 Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Alex Williamson @ 2020-06-11 19:04 UTC (permalink / raw)
  To: qemu-devel; +Cc: Jon Derrick

From: Jon Derrick <jonathan.derrick@intel.com>

The VMD endpoint provides a real PCIe domain to the guest, including
bridges and endpoints. Because the VMD domain is enumerated by the guest
kernel, the guest kernel will assign Guest Physical Addresses to the
downstream endpoint BARs and bridge windows.

When the guest kernel performs MMIO to VMD sub-devices, MMU will
translate from the guest address space to the physical address space.
Because the bridges have been programmed with guest addresses, the
bridges will reject the transaction containing physical addresses.

VMD device 28C0 natively assists passthrough by providing the Host
Physical Address in shadow registers accessible to the guest for bridge
window assignment. The shadow registers are valid if bit 1 is set in VMD
VMLOCK config register 0x70.

In order to support existing VMDs, this quirk provides the shadow
registers in a vendor-specific PCI capability to the vfio-passthrough
device for all VMD device ids which don't natively assist with
passthrough. The Linux VMD driver is updated to check for this new
vendor-specific capability.

Signed-off-by: Jon Derrick <jonathan.derrick@intel.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 hw/vfio/pci-quirks.c |   84 +++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 72 insertions(+), 12 deletions(-)

diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
index f2155ddb1d78..a1e615c54e06 100644
--- a/hw/vfio/pci-quirks.c
+++ b/hw/vfio/pci-quirks.c
@@ -1567,18 +1567,6 @@ static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice *vdev, Error **errp)
     return 0;
 }
 
-int vfio_add_virt_caps(VFIOPCIDevice *vdev, Error **errp)
-{
-    int ret;
-
-    ret = vfio_add_nv_gpudirect_cap(vdev, errp);
-    if (ret) {
-        return ret;
-    }
-
-    return 0;
-}
-
 static void vfio_pci_nvlink2_get_tgt(Object *obj, Visitor *v,
                                      const char *name,
                                      void *opaque, Error **errp)
@@ -1709,3 +1697,75 @@ free_exit:
 
     return ret;
 }
+
+/*
+ * The VMD endpoint provides a real PCIe domain to the guest and the guest
+ * kernel performs enumeration of the VMD sub-device domain. Guest transactions
+ * to VMD sub-devices go through MMU translation from guest addresses to
+ * physical addresses. When MMIO goes to an endpoint after being translated to
+ * physical addresses, the bridge rejects the transaction because the window
+ * has been programmed with guest addresses.
+ *
+ * VMD can use the Host Physical Address in order to correctly program the
+ * bridge windows in its PCIe domain. VMD device 28C0 has HPA shadow registers
+ * located at offset 0x2000 in MEMBAR2 (BAR 4). This quirk provides the HPA
+ * shadow registers in a vendor-specific capability register for devices
+ * without native support. The position of 0xE8-0xFF is in the reserved range
+ * of the VMD device capability space following the Power Management
+ * Capability.
+ */
+#define VMD_SHADOW_CAP_VER 1
+#define VMD_SHADOW_CAP_LEN 24
+static int vfio_add_vmd_shadow_cap(VFIOPCIDevice *vdev, Error **errp)
+{
+    uint8_t membar_phys[16];
+    int ret, pos = 0xE8;
+
+    if (!(vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, 0x201D) ||
+          vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, 0x467F) ||
+          vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, 0x4C3D) ||
+          vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, 0x9A0B))) {
+        return 0;
+    }
+
+    ret = pread(vdev->vbasedev.fd, membar_phys, 16,
+                vdev->config_offset + PCI_BASE_ADDRESS_2);
+    if (ret != 16) {
+        error_report("VMD %s cannot read MEMBARs (%d)",
+                     vdev->vbasedev.name, ret);
+        return -EFAULT;
+    }
+
+    ret = pci_add_capability(&vdev->pdev, PCI_CAP_ID_VNDR, pos,
+                             VMD_SHADOW_CAP_LEN, errp);
+    if (ret < 0) {
+        error_prepend(errp, "Failed to add VMD MEMBAR Shadow cap: ");
+        return ret;
+    }
+
+    memset(vdev->emulated_config_bits + pos, 0xFF, VMD_SHADOW_CAP_LEN);
+    pos += PCI_CAP_FLAGS;
+    pci_set_byte(vdev->pdev.config + pos++, VMD_SHADOW_CAP_LEN);
+    pci_set_byte(vdev->pdev.config + pos++, VMD_SHADOW_CAP_VER);
+    pci_set_long(vdev->pdev.config + pos, 0x53484457); /* SHDW */
+    memcpy(vdev->pdev.config + pos + 4, membar_phys, 16);
+
+    return 0;
+}
+
+int vfio_add_virt_caps(VFIOPCIDevice *vdev, Error **errp)
+{
+    int ret;
+
+    ret = vfio_add_nv_gpudirect_cap(vdev, errp);
+    if (ret) {
+        return ret;
+    }
+
+    ret = vfio_add_vmd_shadow_cap(vdev, errp);
+    if (ret) {
+        return ret;
+    }
+
+    return 0;
+}



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PULL 2/2] hw/vfio/pci-quirks: Fix broken legacy IGD passthrough
  2020-06-11 19:04 [PULL 0/2] VFIO update 2020-06-11 Alex Williamson
  2020-06-11 19:04 ` [PULL 1/2] hw/vfio: Add VMD Passthrough Quirk Alex Williamson
@ 2020-06-11 19:04 ` Alex Williamson
  2020-06-12 10:16 ` [PULL 0/2] VFIO update 2020-06-11 Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Alex Williamson @ 2020-06-11 19:04 UTC (permalink / raw)
  To: qemu-devel; +Cc: Thomas Huth, Philippe Mathieu-Daudé

From: Thomas Huth <thuth@redhat.com>

The #ifdef CONFIG_VFIO_IGD in pci-quirks.c is not working since the
required header config-devices.h is not included, so that the legacy
IGD passthrough is currently broken. Let's include the right header
to fix this issue.

Buglink: https://bugs.launchpad.net/qemu/+bug/1882784
Fixes: 29d62771c81d ("hw/vfio: Move the IGD quirk code to a separate file")
Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 hw/vfio/pci-quirks.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
index a1e615c54e06..d304c81148d3 100644
--- a/hw/vfio/pci-quirks.c
+++ b/hw/vfio/pci-quirks.c
@@ -11,6 +11,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "config-devices.h"
 #include "exec/memop.h"
 #include "qemu/units.h"
 #include "qemu/error-report.h"



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PULL 0/2] VFIO update 2020-06-11
  2020-06-11 19:04 [PULL 0/2] VFIO update 2020-06-11 Alex Williamson
  2020-06-11 19:04 ` [PULL 1/2] hw/vfio: Add VMD Passthrough Quirk Alex Williamson
  2020-06-11 19:04 ` [PULL 2/2] hw/vfio/pci-quirks: Fix broken legacy IGD passthrough Alex Williamson
@ 2020-06-12 10:16 ` Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2020-06-12 10:16 UTC (permalink / raw)
  To: Alex Williamson
  Cc: Thomas Huth, Philippe Mathieu-Daudé, QEMU Developers,
	Jon Derrick

On Thu, 11 Jun 2020 at 20:06, Alex Williamson
<alex.williamson@redhat.com> wrote:
>
> The following changes since commit 3666f684761a3cccd86d13c752273be207ecade4:
>
>   Merge remote-tracking branch 'remotes/ericb/tags/pull-bitmaps-2020-06-09' into staging (2020-06-11 15:35:44 +0100)
>
> are available in the Git repository at:
>
>   git://github.com/awilliam/qemu-vfio.git tags/vfio-update-20200611.0
>
> for you to fetch changes up to 643a4eacef87a318cf71800a4fb2ae1f78c4b245:
>
>   hw/vfio/pci-quirks: Fix broken legacy IGD passthrough (2020-06-11 11:36:40 -0600)
>
> ----------------------------------------------------------------
> VFIO update 2020-06-11
>
>  - Fix IGD split, include header to honor Kconfig (Thomas Huth)
>
>  - New VMD device paravirt quirk (Jon Derrick)
>


Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/5.1
for any user-visible changes.

-- PMM


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-06-12 10:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-11 19:04 [PULL 0/2] VFIO update 2020-06-11 Alex Williamson
2020-06-11 19:04 ` [PULL 1/2] hw/vfio: Add VMD Passthrough Quirk Alex Williamson
2020-06-11 19:04 ` [PULL 2/2] hw/vfio/pci-quirks: Fix broken legacy IGD passthrough Alex Williamson
2020-06-12 10:16 ` [PULL 0/2] VFIO update 2020-06-11 Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).