qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] vfio/igd: Legacy mode fixes after introduction of
@ 2025-07-23 16:09 Tomita Moeko
  2025-07-23 16:09 ` [PATCH 1/2] vfio/igd: Require host VGA decode for legacy mode Tomita Moeko
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Tomita Moeko @ 2025-07-23 16:09 UTC (permalink / raw)
  To: Alex Williamson, Cédric Le Goater; +Cc: qemu-devel, Tomita Moeko

This patchset aims to fix 2 bugs on legacy mode brought by commit
a59d06305fff ("vfio/pci: Introduce x-pci-class-code option").

1. QEMU tries to enable VGA access on device emulated to VGA controller.
2. pci_register_vga() is not called after calling vfio_populate_vga().


Tomita Moeko (2):
  vfio/igd: Require host VGA decode for legacy mode
  vfio/igd: Fix VGA regions are not exposed in legacy mode

 docs/igd-assign.txt |  1 +
 hw/vfio/igd.c       | 19 ++++++++++++-------
 hw/vfio/pci.c       | 13 ++++++++++---
 hw/vfio/pci.h       |  1 +
 4 files changed, 24 insertions(+), 10 deletions(-)

-- 
2.47.2



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

* [PATCH 1/2] vfio/igd: Require host VGA decode for legacy mode
  2025-07-23 16:09 [PATCH 0/2] vfio/igd: Legacy mode fixes after introduction of Tomita Moeko
@ 2025-07-23 16:09 ` Tomita Moeko
  2025-07-23 16:09 ` [PATCH 2/2] vfio/igd: Fix VGA regions are not exposed in " Tomita Moeko
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Tomita Moeko @ 2025-07-23 16:09 UTC (permalink / raw)
  To: Alex Williamson, Cédric Le Goater, Tomita Moeko; +Cc: qemu-devel

Commit a59d06305fff ("vfio/pci: Introduce x-pci-class-code option")
allows user to expose non-VGA IGD device as VGA controller to the
guest. However, legacy mode requires host VGA range access. Check
that GGC.IVD == 0 before enabling legacy mode to ensure IGD is a real
VGA device claiming host VGA ranges.

Signed-off-by: Tomita Moeko <tomitamoeko@gmail.com>
---
 docs/igd-assign.txt |  1 +
 hw/vfio/igd.c       | 11 ++++++-----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/docs/igd-assign.txt b/docs/igd-assign.txt
index af4e8391fc..e54040335b 100644
--- a/docs/igd-assign.txt
+++ b/docs/igd-assign.txt
@@ -48,6 +48,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)
+* IGD claims VGA cycles on host (IGD is VGA controller on host)
 * Machine type is i440fx
 * IGD is assigned to guest BDF 00:02.0
 * ROM BAR or romfile is present
diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c
index e7a9d1ffc1..5b1ad1a804 100644
--- a/hw/vfio/igd.c
+++ b/hw/vfio/igd.c
@@ -113,6 +113,7 @@ static int igd_gen(VFIOPCIDevice *vdev)
 #define IGD_BDSM 0x5c /* Base Data of Stolen Memory */
 #define IGD_BDSM_GEN11 0xc0 /* Base Data of Stolen Memory of gen 11 and later */
 
+#define IGD_GMCH_VGA_DISABLE        BIT(1)
 #define IGD_GMCH_GEN6_GMS_SHIFT     3       /* SNB_GMCH in i915 */
 #define IGD_GMCH_GEN6_GMS_MASK      0x1f
 #define IGD_GMCH_GEN8_GMS_SHIFT     8       /* BDW_GMCH in i915 */
@@ -533,12 +534,14 @@ 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)
+     * - IGD claims VGA cycles on host
      * - 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) &&
+        !(gmch & IGD_GMCH_VGA_DISABLE) &&
         !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)))) {
@@ -568,12 +571,10 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
         }
 
         /*
-         * If IGD VGA Disable is clear (expected) and VGA is not already
-         * enabled, try to enable it. Probably shouldn't be using legacy mode
-         * without VGA, but also no point in us enabling VGA if disabled in
-         * hardware.
+         * If VGA is not already enabled, try to enable it. We shouldn't be
+         * using legacy mode without VGA.
          */
-        if (!(gmch & 0x2) && !vdev->vga && !vfio_populate_vga(vdev, &err)) {
+        if (!vdev->vga && !vfio_populate_vga(vdev, &err)) {
             error_setg(&err, "Unable to enable VGA access");
             goto error;
         }
-- 
2.47.2



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

* [PATCH 2/2] vfio/igd: Fix VGA regions are not exposed in legacy mode
  2025-07-23 16:09 [PATCH 0/2] vfio/igd: Legacy mode fixes after introduction of Tomita Moeko
  2025-07-23 16:09 ` [PATCH 1/2] vfio/igd: Require host VGA decode for legacy mode Tomita Moeko
@ 2025-07-23 16:09 ` Tomita Moeko
  2025-07-28 15:46 ` [PATCH 0/2] vfio/igd: Legacy mode fixes after introduction of Alex Williamson
  2025-07-28 17:24 ` Cédric Le Goater
  3 siblings, 0 replies; 5+ messages in thread
From: Tomita Moeko @ 2025-07-23 16:09 UTC (permalink / raw)
  To: Alex Williamson, Cédric Le Goater, Tomita Moeko; +Cc: qemu-devel

In commit a59d06305fff ("vfio/pci: Introduce x-pci-class-code option"),
pci_register_vga() has been moved ouside of vfio_populate_vga(). As a
result, IGD VGA ranges are no longer properly exposed to guest.

To fix this, call pci_register_vga() after vfio_populate_vga() legacy
mode. A wrapper function vfio_pci_config_register_vga() is introduced
to handle it.

Fixes: a59d06305fff ("vfio/pci: Introduce x-pci-class-code option")
Signed-off-by: Tomita Moeko <tomitamoeko@gmail.com>
---
 hw/vfio/igd.c | 10 +++++++---
 hw/vfio/pci.c | 13 ++++++++++---
 hw/vfio/pci.h |  1 +
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c
index 5b1ad1a804..ee0767b0b8 100644
--- a/hw/vfio/igd.c
+++ b/hw/vfio/igd.c
@@ -574,9 +574,13 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
          * If VGA is not already enabled, try to enable it. We shouldn't be
          * using legacy mode without VGA.
          */
-        if (!vdev->vga && !vfio_populate_vga(vdev, &err)) {
-            error_setg(&err, "Unable to enable VGA access");
-            goto error;
+        if (!vdev->vga) {
+            if (vfio_populate_vga(vdev, &err)) {
+                vfio_pci_config_register_vga(vdev);
+            } else {
+                error_setg(&err, "Unable to enable VGA access");
+                goto error;
+            }
         }
 
         /* Enable OpRegion and LPC bridge quirk */
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 15136f94f8..d5ea4a5a83 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -3172,6 +3172,15 @@ static void vfio_unregister_req_notifier(VFIOPCIDevice *vdev)
     vdev->req_enabled = false;
 }
 
+void vfio_pci_config_register_vga(VFIOPCIDevice *vdev)
+{
+    assert(vdev->vga != NULL);
+
+    pci_register_vga(&vdev->pdev, &vdev->vga->region[QEMU_PCI_VGA_MEM].mem,
+                     &vdev->vga->region[QEMU_PCI_VGA_IO_LO].mem,
+                     &vdev->vga->region[QEMU_PCI_VGA_IO_HI].mem);
+}
+
 bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)
 {
     PCIDevice *pdev = &vdev->pdev;
@@ -3293,9 +3302,7 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)
     vfio_bars_register(vdev);
 
     if (vdev->vga && vfio_is_vga(vdev)) {
-        pci_register_vga(&vdev->pdev, &vdev->vga->region[QEMU_PCI_VGA_MEM].mem,
-                         &vdev->vga->region[QEMU_PCI_VGA_IO_LO].mem,
-                         &vdev->vga->region[QEMU_PCI_VGA_IO_HI].mem);
+        vfio_pci_config_register_vga(vdev);
     }
 
     return true;
diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
index 44cae5afd6..810a842f4a 100644
--- a/hw/vfio/pci.h
+++ b/hw/vfio/pci.h
@@ -255,6 +255,7 @@ extern const VMStateDescription vfio_display_vmstate;
 
 void vfio_pci_bars_exit(VFIOPCIDevice *vdev);
 bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp);
+void vfio_pci_config_register_vga(VFIOPCIDevice *vdev);
 bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp);
 bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, Error **errp);
 void vfio_pci_intx_eoi(VFIODevice *vbasedev);
-- 
2.47.2



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

* Re: [PATCH 0/2] vfio/igd: Legacy mode fixes after introduction of
  2025-07-23 16:09 [PATCH 0/2] vfio/igd: Legacy mode fixes after introduction of Tomita Moeko
  2025-07-23 16:09 ` [PATCH 1/2] vfio/igd: Require host VGA decode for legacy mode Tomita Moeko
  2025-07-23 16:09 ` [PATCH 2/2] vfio/igd: Fix VGA regions are not exposed in " Tomita Moeko
@ 2025-07-28 15:46 ` Alex Williamson
  2025-07-28 17:24 ` Cédric Le Goater
  3 siblings, 0 replies; 5+ messages in thread
From: Alex Williamson @ 2025-07-28 15:46 UTC (permalink / raw)
  To: Tomita Moeko; +Cc: Cédric Le Goater, qemu-devel

On Thu, 24 Jul 2025 00:09:04 +0800
Tomita Moeko <tomitamoeko@gmail.com> wrote:

> This patchset aims to fix 2 bugs on legacy mode brought by commit
> a59d06305fff ("vfio/pci: Introduce x-pci-class-code option").
> 
> 1. QEMU tries to enable VGA access on device emulated to VGA controller.
> 2. pci_register_vga() is not called after calling vfio_populate_vga().
> 
> 
> Tomita Moeko (2):
>   vfio/igd: Require host VGA decode for legacy mode
>   vfio/igd: Fix VGA regions are not exposed in legacy mode
> 
>  docs/igd-assign.txt |  1 +
>  hw/vfio/igd.c       | 19 ++++++++++++-------
>  hw/vfio/pci.c       | 13 ++++++++++---
>  hw/vfio/pci.h       |  1 +
>  4 files changed, 24 insertions(+), 10 deletions(-)
> 

Reviewed-by: Alex Williamson <alex.williamson@redhat.com>



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

* Re: [PATCH 0/2] vfio/igd: Legacy mode fixes after introduction of
  2025-07-23 16:09 [PATCH 0/2] vfio/igd: Legacy mode fixes after introduction of Tomita Moeko
                   ` (2 preceding siblings ...)
  2025-07-28 15:46 ` [PATCH 0/2] vfio/igd: Legacy mode fixes after introduction of Alex Williamson
@ 2025-07-28 17:24 ` Cédric Le Goater
  3 siblings, 0 replies; 5+ messages in thread
From: Cédric Le Goater @ 2025-07-28 17:24 UTC (permalink / raw)
  To: Tomita Moeko, Alex Williamson; +Cc: qemu-devel

On 7/23/25 18:09, Tomita Moeko wrote:
> This patchset aims to fix 2 bugs on legacy mode brought by commit
> a59d06305fff ("vfio/pci: Introduce x-pci-class-code option").
> 
> 1. QEMU tries to enable VGA access on device emulated to VGA controller.
> 2. pci_register_vga() is not called after calling vfio_populate_vga().
> 
> 
> Tomita Moeko (2):
>    vfio/igd: Require host VGA decode for legacy mode
>    vfio/igd: Fix VGA regions are not exposed in legacy mode
> 
>   docs/igd-assign.txt |  1 +
>   hw/vfio/igd.c       | 19 ++++++++++++-------
>   hw/vfio/pci.c       | 13 ++++++++++---
>   hw/vfio/pci.h       |  1 +
>   4 files changed, 24 insertions(+), 10 deletions(-)
> 


Applied to vfio-next.

Thanks,

C.




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

end of thread, other threads:[~2025-07-28 17:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-23 16:09 [PATCH 0/2] vfio/igd: Legacy mode fixes after introduction of Tomita Moeko
2025-07-23 16:09 ` [PATCH 1/2] vfio/igd: Require host VGA decode for legacy mode Tomita Moeko
2025-07-23 16:09 ` [PATCH 2/2] vfio/igd: Fix VGA regions are not exposed in " Tomita Moeko
2025-07-28 15:46 ` [PATCH 0/2] vfio/igd: Legacy mode fixes after introduction of Alex Williamson
2025-07-28 17:24 ` Cédric Le Goater

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).