vfio/igd: Legacy mode fixes after introduction of
cover vfio/igd: Legacy mode fixes after introduction of
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(-)
Signature · 1 line
2.47.2
PATCH 1/2 vfio/igd: Require host VGA decode for legacy mode
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.
--- docs/igd-assign.txt | 1 + hw/vfio/igd.c | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-)
docs/igd-assign.txt +1 -0
@@ -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
hw/vfio/igd.c +6 -5
@@ -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; }
Signature · 1 line
2.47.2
PATCH 2/2 vfio/igd: Fix VGA regions are not exposed in legacy mode
In reply to Tomita MoekoIn 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.
--- hw/vfio/igd.c | 10 +++++++--- hw/vfio/pci.c | 13 ++++++++++--- hw/vfio/pci.h | 1 + 3 files changed, 18 insertions(+), 6 deletions(-)
hw/vfio/igd.c +7 -3
@@ -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 */
hw/vfio/pci.c +10 -3
@@ -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;
hw/vfio/pci.h +1 -0
@@ -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);
Signature · 1 line
2.47.2
Quoted 11 lines · On Thu, 24 Jul 2025 00:09:04 +0800 Tomita Moeko <[email protected]> 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 callingvfio_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
Quoted 6 lines
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(-)
Cédric Le Goater
AppliedQuoted 11 lines · 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 callingvfio_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
Quoted 6 lines
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.