Skip to contentSkip to conversation

vfio/igd: Detect IGD by OpRegion and enable OpRegion automatically

PATCH Applied Tomita Moeko 2 participants 12 messages May 5, 2025 – May 6, 2025

lore
Share & tools
lore
#0 lore raw

v3 cover vfio/igd: Detect IGD by OpRegion and enable OpRegion automatically

As proposed in a previous discussion [1], detect IGD devices based on whether it has VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION exposed by kernel and enables OpRegion access by default. This enables out-of-the-box display output support for IGD passthrough without having to manually set x-igd-opregion=on, which probably saves effort for libvirt users.

This patchset also limits legacy mode to Gen6-9 devices, as Intel no longer provides CSM support and VBIOS on newer IGD, and Seabios does not support setting up the 64 bit BDSM register on Gen 11+ devices. Exposing VGA ranges to guests by default on platforms without VGA mode support is undesirable.

Additionally, as we enables OpRegion on IGD devices by default, and Intel removes the BDSM register from Meteor Lake [2]. There seems to be no extra register quirks rather than OpRegion required on newer devices. To support them (and probably future devices), the generation limit is removed, with BDSM quirk only applied to known Gen 6-12 devices.

Note: I have not been able to test this on Meteor Lake or newer platforms due to lack of hardware.

[1] https://lore.kernel.org/qemu-devel/[email protected]
[2] https://edc.intel.com/content/www/us/en/design/publications/14th-generation-core-processors-cfg-and-mem-registers/d2-f0-processor-graphics-registers/

Changelog:
v3:
* Addressed a nit in patch #8

v2:
* Removed "Allow hotplugging with OpRegion enabled", hotplugging is always forbidden.
* Test device is not hotplugged and get opregion in a single function.
* Update documentation along with code changes.
* Minor code style fixes.

Tomita Moeko (9):
vfio/igd: Restrict legacy mode to Gen6-9 devices vfio/igd: Always emulate ASLS (OpRegion) register vfio/igd: Detect IGD device by OpRegion vfio/igd: Check vendor and device ID on GVT-g mdev vfio/igd: Check OpRegion support on GVT-g mdev vfio/igd: Enable OpRegion by default
vfio/igd: Allow overriding GMS with 0xf0 to 0xfe on Gen9+ vfio/igd: Only emulate GGC register when x-igd-gms is set vfio/igd: Remove generation limitation for IGD passthrough

 docs/igd-assign.txt |  11 ++-
 hw/vfio/igd.c       | 220 ++++++++++++++++++++++++++------------------
 hw/vfio/pci.c       |   2 +-
 3 files changed, 138 insertions(+), 95 deletions(-)
Signature · 1 line
2.47.2
#1 lore raw

PATCH v3 1/9 vfio/igd: Restrict legacy mode to Gen6-9 devices

Intel only provides legacy VBIOS for IGD up to Gen9, and there is no CSM support on later devices. Additionally, Seabios can only handle 32-bit BDSM register used until Gen9. Since legacy mode requires VGA capability, restrict it to Gen6 through Gen9 devices.

---
 docs/igd-assign.txt | 1 +
 hw/vfio/igd.c       | 6 +++++-
 2 files changed, 6 insertions(+), 1 deletion(-)
docs/igd-assign.txt +1 -0
index 3aed7956d5..95beb76812 100644
@@ -47,6 +47,7 @@ Intel document [1] shows how to dump VBIOS to file. For UEFI Option ROM, see
 
 QEMU also provides a "Legacy" mode that implicitly enables full functionality
 on IGD, it is automatically enabled when
+* IGD generation is 6 to 9 (Sandy Bridge to Comet Lake)
 * Machine type is i440fx
 * IGD is assigned to guest BDF 00:02.0
 * ROM BAR or romfile is present
hw/vfio/igd.c +5 -1
index d7e4728fdc..e06484c911 100644
@@ -517,11 +517,13 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
 
     /*
      * For backward compatibility, enable legacy mode when
+     * - Device geneation is 6 to 9 (including both)
      * - Machine type is i440fx (pc_piix)
      * - IGD device is at guest BDF 00:02.0
      * - Not manually disabled by x-igd-legacy-mode=off
      */
     if ((vdev->igd_legacy_mode != ON_OFF_AUTO_OFF) &&
+        (gen >= 6 && gen <= 9) &&
         !strcmp(MACHINE_GET_CLASS(qdev_get_machine())->family, "pc_piix") &&
         (&vdev->pdev == pci_find_device(pci_device_root_bus(&vdev->pdev),
         0, PCI_DEVFN(0x2, 0)))) {
@@ -566,7 +568,9 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
         vdev->features |= VFIO_FEATURE_ENABLE_IGD_LPC;
     } else if (vdev->igd_legacy_mode == ON_OFF_AUTO_ON) {
         error_setg(&err,
-                   "Machine is not i440fx or assigned BDF is not 00:02.0");
+                   "Machine is not i440fx, assigned BDF is not 00:02.0, "
+                   "or device %04x (gen %d) doesn't support legacy mode",
+                   vdev->device_id, gen);
         goto error;
     }
 
Signature · 1 line
2.47.2
#2 lore raw

PATCH v3 2/9 vfio/igd: Always emulate ASLS (OpRegion) register

In reply to Tomita Moeko

ASLS register represents the base address of OpRegion, and it is programmed with HPA. In IGD passthrough scenario, it needs to be reprogrammed with GPA by guest firmware. To prevent guest accessing wrong memory range, ASLS should always be emulated and cleared.

In GVT-g scenario, emulating ASLS is unnecessary as access is handled by kvmgt backend [1].

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/i915/gvt/cfg_space.c?h=v6.14#n295

---
 hw/vfio/igd.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
hw/vfio/igd.c +9 -5
index e06484c911..b1fce76f72 100644
@@ -182,10 +182,6 @@ static bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev,
 
     trace_vfio_pci_igd_opregion_enabled(vdev->vbasedev.name);
 
-    pci_set_long(vdev->pdev.config + IGD_ASLS, 0);
-    pci_set_long(vdev->pdev.wmask + IGD_ASLS, ~0);
-    pci_set_long(vdev->emulated_config_bits + IGD_ASLS, ~0);
-
     return true;
 }
 
@@ -584,7 +580,15 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
     if ((vdev->features & VFIO_FEATURE_ENABLE_IGD_LPC) &&
         !vfio_pci_igd_setup_lpc_bridge(vdev, errp)) {
         goto error;
-     }
+    }
+
+    /*
+     * ASLS (OpRegion address) is read-only, emulated
+     * It contains HPA, guest firmware need to reprogram it with GPA.
+     */
+    pci_set_long(vdev->pdev.config + IGD_ASLS, 0);
+    pci_set_long(vdev->pdev.wmask + IGD_ASLS, ~0);
+    pci_set_long(vdev->emulated_config_bits + IGD_ASLS, ~0);
 
     /*
      * Allow user to override dsm size using x-igd-gms option, in multiples of
Signature · 1 line
2.47.2
#3 lore raw

PATCH v3 3/9 vfio/igd: Detect IGD device by OpRegion

In reply to Tomita Moeko

There is currently no straightforward way to distinguish if a Intel graphics device is IGD or discrete GPU. However, only IGD devices have OpRegion. Use the presence of VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION to identify IGD devices. Still, OpRegion on hotplugged IGD device is not supported.

---
 hw/vfio/igd.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)
hw/vfio/igd.c +16 -14
index b1fce76f72..347253d08c 100644
@@ -185,9 +185,10 @@ static bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev,
     return true;
 }
 
-static bool vfio_pci_igd_setup_opregion(VFIOPCIDevice *vdev, Error **errp)
+static bool vfio_pci_igd_opregion_detect(VFIOPCIDevice *vdev,
+                                         struct vfio_region_info **opregion,
+                                         Error **errp)
 {
-    g_autofree struct vfio_region_info *opregion = NULL;
     int ret;
 
     /* Hotplugging is not supported for opregion access */
@@ -198,17 +199,13 @@ static bool vfio_pci_igd_setup_opregion(VFIOPCIDevice *vdev, Error **errp)
 
     ret = vfio_device_get_region_info_type(&vdev->vbasedev,
                     VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL,
-                    VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION, &opregion);
+                    VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION, opregion);
     if (ret) {
         error_setg_errno(errp, -ret,
                          "Device does not supports IGD OpRegion feature");
         return false;
     }
 
-    if (!vfio_pci_igd_opregion_init(vdev, opregion, errp)) {
-        return false;
-    }
-
     return true;
 }
 
@@ -480,6 +477,7 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr)
 
 static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
 {
+    g_autofree struct vfio_region_info *opregion = NULL;
     int ret, gen;
     uint64_t gms_size;
     uint64_t *bdsm_size;
@@ -487,16 +485,17 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
     bool legacy_mode_enabled = false;
     Error *err = NULL;
 
-    /*
-     * This must be an Intel VGA device at address 00:02.0 for us to even
-     * consider enabling legacy mode.  The vBIOS has dependencies on the
-     * PCI bus address.
-     */
     if (!vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, PCI_ANY_ID) ||
         !vfio_is_vga(vdev)) {
         return true;
     }
 
+    /* IGD device always comes with OpRegion */
+    if (!vfio_pci_igd_opregion_detect(vdev, &opregion, errp)) {
+        return true;
+    }
+    info_report("OpRegion detected on Intel display %x.", vdev->device_id);
+
     /*
      * IGD is not a standard, they like to change their specs often.  We
      * only attempt to support back to SandBridge and we hope that newer
@@ -572,7 +571,7 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
 
     /* Setup OpRegion access */
     if ((vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION) &&
-        !vfio_pci_igd_setup_opregion(vdev, errp)) {
+        !vfio_pci_igd_opregion_init(vdev, opregion, errp)) {
         goto error;
     }
 
@@ -672,8 +671,11 @@ error:
  */
 static bool vfio_pci_kvmgt_config_quirk(VFIOPCIDevice *vdev, Error **errp)
 {
+    g_autofree struct vfio_region_info *opregion = NULL;
+
     if ((vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION) &&
-        !vfio_pci_igd_setup_opregion(vdev, errp)) {
+        (!vfio_pci_igd_opregion_detect(vdev, &opregion, errp) ||
+         !vfio_pci_igd_opregion_init(vdev, opregion, errp))) {
         return false;
     }
 
Signature · 1 line
2.47.2
#4 lore raw

PATCH v3 4/9 vfio/igd: Check vendor and device ID on GVT-g mdev

In reply to Tomita Moeko

Check the vendor and device ID on GVT-g mdev to ensure it is a supported device [1]. This extra check is required for automatically enabling OpRegion access later.

Note that Cherryview and Gemini Lake are marked as supported here since current code cannot distinguish them with other Gen8 and Gen9 devices. Since mdev cannot be created on these devices, this has no functional impact.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/i915/intel_gvt.c?h=v6.14#n52

---
 hw/vfio/igd.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
hw/vfio/igd.c +12 -0
index 347253d08c..f5dd475028 100644
@@ -672,6 +672,18 @@ error:
 static bool vfio_pci_kvmgt_config_quirk(VFIOPCIDevice *vdev, Error **errp)
 {
     g_autofree struct vfio_region_info *opregion = NULL;
+    int gen;
+
+    if (!vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, PCI_ANY_ID) ||
+        !vfio_is_vga(vdev)) {
+        return true;
+    }
+
+    /* FIXME: Cherryview is Gen8, but don't support GVT-g */
+    gen = igd_gen(vdev);
+    if (gen != 8 && gen != 9) {
+        return true;
+    }
 
     if ((vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION) &&
         (!vfio_pci_igd_opregion_detect(vdev, &opregion, errp) ||
Signature · 1 line
2.47.2
#5 lore raw

PATCH v3 5/9 vfio/igd: Check OpRegion support on GVT-g mdev

In reply to Tomita Moeko

The Intel GVT-g backend kvmgt always emulates OpRegion for vGPU, make sure the OpRegion is present for enabling access to it automatically later.

Also, hotplugging GVT-g vGPU is now always disallowed regardless of OpRegion to prevent potential issues. Intel has never claimed support for GVT-g hotplugging.

---
 hw/vfio/igd.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
hw/vfio/igd.c +6 -2
index f5dd475028..9dec32818c 100644
@@ -685,9 +685,13 @@ static bool vfio_pci_kvmgt_config_quirk(VFIOPCIDevice *vdev, Error **errp)
         return true;
     }
 
+    if (!vfio_pci_igd_opregion_detect(vdev, &opregion, errp)) {
+        /* Should never reach here, KVMGT always emulates OpRegion */
+        return false;
+    }
+
     if ((vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION) &&
-        (!vfio_pci_igd_opregion_detect(vdev, &opregion, errp) ||
-         !vfio_pci_igd_opregion_init(vdev, opregion, errp))) {
+        !vfio_pci_igd_opregion_init(vdev, opregion, errp)) {
         return false;
     }
 
Signature · 1 line
2.47.2
#6 lore raw

PATCH v3 6/9 vfio/igd: Enable OpRegion by default

In reply to Tomita Moeko

As the presence of OpRegion is used to detect IGD device now, and guest driver usually depends on OpRegion to work. Enable OpRegion on IGD devices by default for out-of-the-box passthrough experience (except pre-boot display output), especially for libvirt users.

Example of IGD passthrough with libvirt:
<hostdev mode="subsystem" type="pci" managed="yes">
<source>

    <address domain="0x0000" bus="0x00" slot="0x02" function="0x0"/>

</source>
<rom file="/path/to/igd/rom"/>
<address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x0"/>
</hostdev>

---
 docs/igd-assign.txt | 4 ++--
 hw/vfio/pci.c       | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
docs/igd-assign.txt +2 -2
index 95beb76812..fc444503ff 100644
@@ -102,7 +102,7 @@ digital formats work well.
 
 Options
 =======
-* x-igd-opregion=[on|*off*]
+* x-igd-opregion=[*on*|off]
   Copy host IGD OpRegion and expose it to guest with fw_cfg
 
 * x-igd-lpc=[on|*off*]
@@ -124,7 +124,7 @@ Examples
 
 * Adding IGD with OpRegion and LPC ID hack, but without VGA ranges
   (For UEFI guests)
-  -device vfio-pci,host=00:02.0,id=hostdev0,addr=2.0,x-igd-legacy-mode=off,x-igd-opregion=on,x-igd-lpc=on,romfile=efi_oprom.rom
+  -device vfio-pci,host=00:02.0,id=hostdev0,addr=2.0,x-igd-legacy-mode=off,x-igd-lpc=on,romfile=efi_oprom.rom
 
 
 Guest firmware
hw/vfio/pci.c +1 -1
index 6908bcc0d3..e1fab21b47 100644
@@ -3385,7 +3385,7 @@ static const Property vfio_pci_dev_properties[] = {
     DEFINE_PROP_BIT("x-req", VFIOPCIDevice, features,
                     VFIO_FEATURE_ENABLE_REQ_BIT, true),
     DEFINE_PROP_BIT("x-igd-opregion", VFIOPCIDevice, features,
-                    VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT, false),
+                    VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT, true),
     DEFINE_PROP_BIT("x-igd-lpc", VFIOPCIDevice, features,
                     VFIO_FEATURE_ENABLE_IGD_LPC_BIT, false),
     DEFINE_PROP_ON_OFF_AUTO("x-igd-legacy-mode", VFIOPCIDevice,
Signature · 1 line
2.47.2
#7 lore raw

PATCH v3 7/9 vfio/igd: Allow overriding GMS with 0xf0 to 0xfe on Gen9+

In reply to Tomita Moeko

On Gen9 and later IGD devices, GMS 0xf0 to 0xfe represents 4MB to 60MB pre-allocated memory size in 4MB increments. Allow users overriding GMS with these values.

---
 hw/vfio/igd.c | 59 +++++++++++++++++++++++++++++++++++----------------
 1 file changed, 41 insertions(+), 18 deletions(-)
hw/vfio/igd.c +41 -18
index 9dec32818c..8ad9d723e2 100644
@@ -412,6 +412,44 @@ static bool vfio_pci_igd_setup_lpc_bridge(VFIOPCIDevice *vdev, Error **errp)
     return true;
 }
 
+static bool vfio_pci_igd_override_gms(int gen, uint32_t gms, uint32_t *gmch)
+{
+    bool ret = false;
+
+    if (gen == -1) {
+        error_report("x-igd-gms is not supported on this device");
+    } else if (gen < 8) {
+        if (gms <= 0x10) {
+            *gmch &= ~(IGD_GMCH_GEN6_GMS_MASK << IGD_GMCH_GEN6_GMS_SHIFT);
+            *gmch |= gms << IGD_GMCH_GEN6_GMS_SHIFT;
+            ret = true;
+        } else {
+            error_report(QERR_INVALID_PARAMETER_VALUE, "x-igd-gms", "0~0x10");
+        }
+    } else if (gen == 8) {
+        if (gms <= 0x40) {
+            *gmch &= ~(IGD_GMCH_GEN8_GMS_MASK << IGD_GMCH_GEN8_GMS_SHIFT);
+            *gmch |= gms << IGD_GMCH_GEN8_GMS_SHIFT;
+            ret = true;
+        } else {
+            error_report(QERR_INVALID_PARAMETER_VALUE, "x-igd-gms", "0~0x40");
+        }
+    } else {
+        /* 0x0  to 0x40: 32MB increments starting at 0MB */
+        /* 0xf0 to 0xfe: 4MB increments starting at 4MB */
+        if ((gms <= 0x40) || (gms >= 0xf0 && gms <= 0xfe)) {
+            *gmch &= ~(IGD_GMCH_GEN8_GMS_MASK << IGD_GMCH_GEN8_GMS_SHIFT);
+            *gmch |= gms << IGD_GMCH_GEN8_GMS_SHIFT;
+            ret = true;
+        } else {
+            error_report(QERR_INVALID_PARAMETER_VALUE,
+                         "x-igd-gms", "0~0x40 or 0xf0~0xfe");
+        }
+    }
+
+    return ret;
+}
+
 #define IGD_GGC_MMIO_OFFSET     0x108040
 #define IGD_BDSM_MMIO_OFFSET    0x1080C0
 
@@ -594,24 +632,9 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
      * 32MiB. This option should only be used when the desired size cannot be
      * set from DVMT Pre-Allocated option in host BIOS.
      */
-    if (vdev->igd_gms) {
-        if (gen < 8) {
-            if (vdev->igd_gms <= 0x10) {
-                gmch &= ~(IGD_GMCH_GEN6_GMS_MASK << IGD_GMCH_GEN6_GMS_SHIFT);
-                gmch |= vdev->igd_gms << IGD_GMCH_GEN6_GMS_SHIFT;
-            } else {
-                error_report(QERR_INVALID_PARAMETER_VALUE,
-                             "x-igd-gms", "0~0x10");
-            }
-        } else {
-            if (vdev->igd_gms <= 0x40) {
-                gmch &= ~(IGD_GMCH_GEN8_GMS_MASK << IGD_GMCH_GEN8_GMS_SHIFT);
-                gmch |= vdev->igd_gms << IGD_GMCH_GEN8_GMS_SHIFT;
-            } else {
-                error_report(QERR_INVALID_PARAMETER_VALUE,
-                             "x-igd-gms", "0~0x40");
-            }
-        }
+    if (vdev->igd_gms &&
+        !vfio_pci_igd_override_gms(gen, vdev->igd_gms, &gmch)) {
+        return false;
     }
 
     gms_size = igd_stolen_memory_size(gen, gmch);
Signature · 1 line
2.47.2
#8 lore raw

PATCH v3 8/9 vfio/igd: Only emulate GGC register when x-igd-gms is set

In reply to Tomita Moeko

x-igd-gms is used for overriding DSM region size in GGC register in both config space and MMIO BAR0, by default host value is used. There is no need to emulate it in default case.

---
 hw/vfio/igd.c | 49 ++++++++++++++++++++++++++-----------------------
 1 file changed, 26 insertions(+), 23 deletions(-)
hw/vfio/igd.c +26 -23
index 8ad9d723e2..886d44f017 100644
@@ -478,22 +478,24 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr)
         return;
     }
 
-    ggc_quirk = vfio_quirk_alloc(1);
-    ggc_mirror = ggc_quirk->data = g_malloc0(sizeof(*ggc_mirror));
-    ggc_mirror->mem = ggc_quirk->mem;
-    ggc_mirror->vdev = vdev;
-    ggc_mirror->bar = nr;
-    ggc_mirror->offset = IGD_GGC_MMIO_OFFSET;
-    ggc_mirror->config_offset = IGD_GMCH;
-
-    memory_region_init_io(ggc_mirror->mem, OBJECT(vdev),
-                          &vfio_generic_mirror_quirk, ggc_mirror,
-                          "vfio-igd-ggc-quirk", 2);
-    memory_region_add_subregion_overlap(vdev->bars[nr].region.mem,
-                                        ggc_mirror->offset, ggc_mirror->mem,
-                                        1);
+    if (vdev->igd_gms) {
+        ggc_quirk = vfio_quirk_alloc(1);
+        ggc_mirror = ggc_quirk->data = g_malloc0(sizeof(*ggc_mirror));
+        ggc_mirror->mem = ggc_quirk->mem;
+        ggc_mirror->vdev = vdev;
+        ggc_mirror->bar = nr;
+        ggc_mirror->offset = IGD_GGC_MMIO_OFFSET;
+        ggc_mirror->config_offset = IGD_GMCH;
 
-    QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, ggc_quirk, next);
+        memory_region_init_io(ggc_mirror->mem, OBJECT(vdev),
+                              &vfio_generic_mirror_quirk, ggc_mirror,
+                              "vfio-igd-ggc-quirk", 2);
+        memory_region_add_subregion_overlap(vdev->bars[nr].region.mem,
+                                            ggc_mirror->offset, ggc_mirror->mem,
+                                            1);
+
+        QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, ggc_quirk, next);
+    }
 
     bdsm_quirk = vfio_quirk_alloc(1);
     bdsm_mirror = bdsm_quirk->data = g_malloc0(sizeof(*bdsm_mirror));
@@ -632,9 +634,15 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
      * 32MiB. This option should only be used when the desired size cannot be
      * set from DVMT Pre-Allocated option in host BIOS.
      */
-    if (vdev->igd_gms &&
-        !vfio_pci_igd_override_gms(gen, vdev->igd_gms, &gmch)) {
-        return false;
+    if (vdev->igd_gms) {
+        if (!vfio_pci_igd_override_gms(gen, vdev->igd_gms, &gmch)) {
+            return false;
+        }
+
+        /* GMCH is read-only, emulated */
+        pci_set_long(vdev->pdev.config + IGD_GMCH, gmch);
+        pci_set_long(vdev->pdev.wmask + IGD_GMCH, 0);
+        pci_set_long(vdev->emulated_config_bits + IGD_GMCH, ~0);
     }
 
     gms_size = igd_stolen_memory_size(gen, gmch);
@@ -652,11 +660,6 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
     fw_cfg_add_file(fw_cfg_find(), "etc/igd-bdsm-size",
                     bdsm_size, sizeof(*bdsm_size));
 
-    /* GMCH is read-only, emulated */
-    pci_set_long(vdev->pdev.config + IGD_GMCH, gmch);
-    pci_set_long(vdev->pdev.wmask + IGD_GMCH, 0);
-    pci_set_long(vdev->emulated_config_bits + IGD_GMCH, ~0);
-
     /* BDSM is read-write, emulated.  The BIOS needs to be able to write it */
     if (gen < 11) {
         pci_set_long(vdev->pdev.config + IGD_BDSM, 0);
Signature · 1 line
2.47.2
#9 lore raw

PATCH v3 9/9 vfio/igd: Remove generation limitation for IGD passthrough

In reply to Tomita Moeko

Starting from Intel Core Ultra Series (Meteor Lake), Data Stolen Memory has became a part of LMEMBAR (MMIO BAR2) [1][2], meaning that BDSM and GGC register quirks are no longer needed on these platforms.

To support Meteor/Arrow/Lunar Lake and future IGD devices, remove the generation limitation in IGD passthrough, and apply BDSM and GGC quirks only to known Gen6-12 devices.

[1] https://edc.intel.com/content/www/us/en/design/publications/14th-generation-core-processors-cfg-and-mem-registers/d2-f0-processor-graphics-registers/
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/i915/gem/i915_gem_stolen.c?h=v6.14#n142

---
 docs/igd-assign.txt |  6 +++++
 hw/vfio/igd.c       | 58 ++++++++++++++++-----------------------------
 2 files changed, 27 insertions(+), 37 deletions(-)
docs/igd-assign.txt +6 -0
index fc444503ff..af4e8391fc 100644
@@ -157,6 +157,12 @@ fw_cfg requirements on the VM firmware:
    it's expected that this fw_cfg file is only relevant to a single PCI
    class VGA device with Intel vendor ID, appearing at PCI bus address 00:02.0.
 
+   Starting from Meteor Lake, IGD devices access stolen memory via its MMIO
+   BAR2 (LMEMBAR) and removed the BDSM register in config space. There is
+   no need for guest firmware to allocate data stolen memory in guest address
+   space and write it to BDSM register. Value of this fw_cfg file is 0 in
+   such case.
+
 Upstream Seabios has OpRegion and BDSM (pre-Gen11 device only) support.
 However, the support is not accepted by upstream EDK2/OVMF. A recommended
 solution is to create a virtual OpRom with following DXE drivers:
hw/vfio/igd.c +21 -37

104 lines not on this page · raw message

Signature · 1 line
2.47.2
Reviewed-by Corvin Köhne Reviewed-by Alex Williamson Tested-by Alex Williamson on the v3 series
#10 lore raw
In reply to Tomita Moeko
Quoted 50 lines · Tomita Moeko

As proposed in a previous discussion [1], detect IGD devices based on whether it has VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION exposed by kernel and enables OpRegion access by default. This enables out-of-the-box display output support for IGD passthrough without having to manually set x-igd-opregion=on, which probably saves effort for libvirt users.

This patchset also limits legacy mode to Gen6-9 devices, as Intel no longer provides CSM support and VBIOS on newer IGD, and Seabios does not support setting up the 64 bit BDSM register on Gen 11+ devices. Exposing VGA ranges to guests by default on platforms without VGA mode support is undesirable.

Additionally, as we enables OpRegion on IGD devices by default, and Intel removes the BDSM register from Meteor Lake [2]. There seems to be no extra register quirks rather than OpRegion required on newer devices. To support them (and probably future devices), the generation limit is removed, with BDSM quirk only applied to known Gen 6-12 devices.

Note: I have not been able to test this on Meteor Lake or newer platforms due to lack of hardware.

[1] https://lore.kernel.org/qemu-devel/[email protected]
[2] https://edc.intel.com/content/www/us/en/design/publications/14th-generation-core-processors-cfg-and-mem-registers/d2-f0-processor-graphics-registers/

Changelog:
v3:
* Addressed a nit in patch #8

v2:
* Removed "Allow hotplugging with OpRegion enabled", hotplugging is always forbidden.
* Test device is not hotplugged and get opregion in a single function.
* Update documentation along with code changes.
* Minor code style fixes.

Tomita Moeko (9):
vfio/igd: Restrict legacy mode to Gen6-9 devices vfio/igd: Always emulate ASLS (OpRegion) register vfio/igd: Detect IGD device by OpRegion vfio/igd: Check vendor and device ID on GVT-g mdev vfio/igd: Check OpRegion support on GVT-g mdev vfio/igd: Enable OpRegion by default
vfio/igd: Allow overriding GMS with 0xf0 to 0xfe on Gen9+ vfio/igd: Only emulate GGC register when x-igd-gms is set vfio/igd: Remove generation limitation for IGD passthrough

Quoted 5 lines
  docs/igd-assign.txt |  11 ++-
  hw/vfio/igd.c       | 220 ++++++++++++++++++++++++++------------------
  hw/vfio/pci.c       |   2 +-
  3 files changed, 138 insertions(+), 95 deletions(-)

.
Since Corvin and Alex had reviewed and tested the previous spin :

https://lore.kernel.org/qemu-devel/[email protected]/

let's add the trailers to v3 :

Moeko,

Please use b4 or equivalent to collect the trailers.

Thanks,

C.

#11 lore raw
In reply to Tomita Moeko
Quoted 50 lines · Tomita Moeko

As proposed in a previous discussion [1], detect IGD devices based on whether it has VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION exposed by kernel and enables OpRegion access by default. This enables out-of-the-box display output support for IGD passthrough without having to manually set x-igd-opregion=on, which probably saves effort for libvirt users.

This patchset also limits legacy mode to Gen6-9 devices, as Intel no longer provides CSM support and VBIOS on newer IGD, and Seabios does not support setting up the 64 bit BDSM register on Gen 11+ devices. Exposing VGA ranges to guests by default on platforms without VGA mode support is undesirable.

Additionally, as we enables OpRegion on IGD devices by default, and Intel removes the BDSM register from Meteor Lake [2]. There seems to be no extra register quirks rather than OpRegion required on newer devices. To support them (and probably future devices), the generation limit is removed, with BDSM quirk only applied to known Gen 6-12 devices.

Note: I have not been able to test this on Meteor Lake or newer platforms due to lack of hardware.

[1] https://lore.kernel.org/qemu-devel/[email protected]
[2] https://edc.intel.com/content/www/us/en/design/publications/14th-generation-core-processors-cfg-and-mem-registers/d2-f0-processor-graphics-registers/

Changelog:
v3:
* Addressed a nit in patch #8

v2:
* Removed "Allow hotplugging with OpRegion enabled", hotplugging is always forbidden.
* Test device is not hotplugged and get opregion in a single function.
* Update documentation along with code changes.
* Minor code style fixes.

Tomita Moeko (9):
vfio/igd: Restrict legacy mode to Gen6-9 devices vfio/igd: Always emulate ASLS (OpRegion) register vfio/igd: Detect IGD device by OpRegion vfio/igd: Check vendor and device ID on GVT-g mdev vfio/igd: Check OpRegion support on GVT-g mdev vfio/igd: Enable OpRegion by default
vfio/igd: Allow overriding GMS with 0xf0 to 0xfe on Gen9+ vfio/igd: Only emulate GGC register when x-igd-gms is set vfio/igd: Remove generation limitation for IGD passthrough

Quoted 5 lines
  docs/igd-assign.txt |  11 ++-
  hw/vfio/igd.c       | 220 ++++++++++++++++++++++++++------------------
  hw/vfio/pci.c       |   2 +-
  3 files changed, 138 insertions(+), 95 deletions(-)

Applied to vfio-next.

Thanks,

C.