vfio queue
The following changes since commit 92c05be4dfb59a71033d4c57dac944b29f7dabf0:
Merge tag 'pull-qga-2025-07-28' of https://repo.or.cz/qemu/armbru into staging (2025-07-28 09:31:19 -0400)
are available in the Git repository at:
https://github.com/legoater/qemu/ tags/pull-vfio-20250729
for you to fetch changes up to 0db7e4cb62026196f06755c77f943294d9879e5a:
vfio/igd: Fix VGA regions are not exposed in legacy mode (2025-07-28 17:52:34 +0200)
----------------------------------------------------------------
vfio queue:
* Fixed regression introduced by the use-legacy-x86-rom property
* Fixed regressions on IGD passthrough in legacy mode
* Fixed region mappings of sub-page BARs after CPR
* Removed build of SEV on 32-bit hosts
----------------------------------------------------------------
Cédric Le Goater (2):
hw/i386: Fix 'use-legacy-x86-rom' property compatibility
i386: Build SEV only for 64-bit target
Steve Sistare (1):
vfio: fix sub-page bar after cpr
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/pci.h | 2 ++ hw/vfio/types.h | 2 ++ hw/core/machine.c | 2 +- hw/i386/microvm.c | 2 +- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 2 +- hw/vfio/cpr.c | 2 ++ hw/vfio/igd.c | 19 ++++++++++++------- hw/vfio/pci.c | 29 ++++++++++++++++++++++++----- hw/i386/Kconfig | 2 +- 11 files changed, 48 insertions(+), 17 deletions(-)
[PULL 3/5] vfio: fix sub-page bar after cpr
From: Steve Sistare <[email protected]>
Regions for sub-page BARs are normally mapped here, in response to the guest writing to PCI config space:
vfio_pci_write_config()
pci_default_write_config()
pci_update_mappings()
memory_region_add_subregion()
vfio_sub_page_bar_update_mapping()
... vfio_dma_map()However, after CPR, the guest does not reconfigure the device and the code path above is not taken. To fix, in vfio_cpr_pci_post_load, call vfio_sub_page_bar_update_mapping for each sub-page BAR with a valid address.
--- hw/vfio/pci.h | 1 + hw/vfio/cpr.c | 2 ++ hw/vfio/pci.c | 14 ++++++++++++++ 3 files changed, 17 insertions(+)
hw/vfio/pci.h +1 -0
@@ -219,6 +219,7 @@ void vfio_pci_write_config(PCIDevice *pdev,uint64_t vfio_vga_read (void *opaque,hwaddr addr,unsigned size);void vfio_vga_write (void *opaque,hwaddr addr,uint64_t data,unsigned size); +void vfio_sub_page_bar_update_mappings (VFIOPCIDevice *vdev);bool vfio_opt_rom_in_denylist (VFIOPCIDevice *vdev);bool vfio_config_quirk_setup (VFIOPCIDevice *vdev,Error **errp);void vfio_vga_quirk_setup (VFIOPCIDevice *vdev);
hw/vfio/cpr.c +2 -0
@@ -116,6 +116,8 @@ static int vfio_cpr_pci_post_load(void *opaque, int version_id)PCIDevice *pdev = &vdev->pdev;int nr_vectors; +vfio_sub_page_bar_update_mappings (vdev); +if (msix_enabled (pdev)) {vfio_pci_msix_set_notifiers (vdev); nr_vectors = vdev->msix->entries;
hw/vfio/pci.c +14 -0
@@ -2824,6 +2824,20 @@ static int vfio_pci_load_config(VFIODevice *vbasedev, QEMUFile *f)return ret; } +void vfio_sub_page_bar_update_mappings (VFIOPCIDevice *vdev) +{ +PCIDevice *pdev = &vdev->pdev; +int page_size =qemu_real_host_page_size (); +int bar; + +for (bar =0 ; bar <PCI_ROM_SLOT ; bar++) { +PCIIORegion *r = &pdev->io_regions[bar]; +if (r->addr !=PCI_BAR_UNMAPPED && r->size >0 && r->size < page_size) { +vfio_sub_page_bar_update_mapping (pdev, bar); + } + } +} +static VFIODeviceOps vfio_pci_ops = { .vfio_compute_needs_reset = vfio_pci_compute_needs_reset, .vfio_hot_reset_multi = vfio_pci_hot_reset_multi,
Signature · 1 line
2.50.1
[PULL 5/5] vfio/igd: Fix VGA regions are not exposed in legacy mode
In reply to Cédric Le GoaterFrom: Tomita Moeko <[email protected]>
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.
--- hw/vfio/pci.h | 1 + hw/vfio/igd.c | 10 +++++++--- hw/vfio/pci.c | 13 ++++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-)
hw/vfio/pci.h +1 -0
@@ -253,6 +253,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);
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
@@ -3162,6 +3162,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;
@@ -3283,9 +3292,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;
Signature · 1 line
2.50.1
[PULL 4/5] vfio/igd: Require host VGA decode for legacy mode
In reply to Cédric Le GoaterFrom: Tomita Moeko <[email protected]>
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.50.1
[PULL 1/5] hw/i386: Fix 'use-legacy-x86-rom' property compatibility
In reply to Cédric Le GoaterCommit 350785d41d8b ("ramfb: Add property to control if load the romfile") introduced the use-legacy-x86-rom property for the vfio-pci-nohotplug device, allowing control over VGA BIOS ROM loading. However, the property compatibility setting was incorrectly applied to the vfio-pci device instead, which causes all vfio-pci devices to fail to load. This change fixes the issue by ensuring the property is set on the correct device.
--- hw/vfio/types.h | 2 ++ hw/core/machine.c | 2 +- hw/i386/microvm.c | 2 +- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 2 +- hw/vfio/pci.c | 2 -- 6 files changed, 6 insertions(+), 6 deletions(-)
hw/vfio/types.h +2 -0
@@ -18,4 +18,6 @@#define TYPE_VFIO_PCI "vfio-pci"/* TYPE_VFIO_PCI shares struct VFIOPCIDevice. */ +#define TYPE_VFIO_PCI_NOHOTPLUG "vfio-pci-nohotplug" +#endif /* HW_VFIO_VFIO_TYPES_H */
hw/core/machine.c +1 -1
@@ -41,7 +41,7 @@ GlobalProperty hw_compat_10_0[] = { { "scsi-hd", "dpofua", "off" }, { "vfio-pci", "x-migration-load-config-after-iter", "off" }, { "ramfb", "use-legacy-x86-rom", "true"}, - { "vfio-pci", "use-legacy-x86-rom", "true" }, + { "vfio-pci-nohotplug", "use-legacy-x86-rom", "true" }, };const size_t hw_compat_10_0_len =G_N_ELEMENTS (hw_compat_10_0);
hw/i386/microvm.c +1 -1
@@ -635,7 +635,7 @@ GlobalProperty microvm_properties[] = {*/ { "pcie-root-port", "io-reserve", "0" }, { TYPE_RAMFB_DEVICE, "use-legacy-x86-rom", "true" }, - { TYPE_VFIO_PCI, "use-legacy-x86-rom", "true" }, + { TYPE_VFIO_PCI_NOHOTPLUG, "use-legacy-x86-rom", "true" }, };static void microvm_class_init (ObjectClass *oc,const void *data)
hw/i386/pc_piix.c +1 -1
@@ -80,7 +80,7 @@ static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };static GlobalProperty pc_piix_compat_defaults[] = { {TYPE_RAMFB_DEVICE ,"use-legacy-x86-rom" ,"true" }, - {TYPE_VFIO_PCI ,"use-legacy-x86-rom" ,"true" }, + {TYPE_VFIO_PCI_NOHOTPLUG ,"use-legacy-x86-rom" ,"true" }, };static const size_t pc_piix_compat_defaults_len =G_N_ELEMENTS (pc_piix_compat_defaults);
hw/i386/pc_q35.c +1 -1
@@ -69,7 +69,7 @@static GlobalProperty pc_q35_compat_defaults[] = { {TYPE_VIRTIO_IOMMU_PCI ,"aw-bits" ,"39" }, {TYPE_RAMFB_DEVICE ,"use-legacy-x86-rom" ,"true" }, - {TYPE_VFIO_PCI ,"use-legacy-x86-rom" ,"true" }, + {TYPE_VFIO_PCI_NOHOTPLUG ,"use-legacy-x86-rom" ,"true" }, };static const size_t pc_q35_compat_defaults_len =G_N_ELEMENTS (pc_q35_compat_defaults);
hw/vfio/pci.c +0 -2
@@ -49,8 +49,6 @@#include "vfio-migration-internal.h" #include "vfio-helpers.h" -#define TYPE_VFIO_PCI_NOHOTPLUG "vfio-pci-nohotplug" -/* Protected by BQL */ static KVMRouteChange vfio_route_change;
Signature · 1 line
2.50.1
[PULL 2/5] i386: Build SEV only for 64-bit target
In reply to Cédric Le GoaterRecent changes broke build on 32-bit host. Since there is no 32-bit support, restrict SEV to 64-bit.
--- hw/i386/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/Kconfig +1 -1
@@ -4,7 +4,7 @@ config X86_FW_OVMF config SEV bool select X86_FW_OVMF - depends on KVM + depends on KVM && X86_64 config SGX bool
Signature · 1 line
2.50.1
Stefan Hajnoczi
AppliedApplied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/10.1 for any user-visible changes.