* [PATCH v5 0/3] vfio/igd: Fix garbled screen on IGD passthrough with legacy VBIOS
@ 2026-07-07 8:35 Tomita Moeko
2026-07-07 8:35 ` [PATCH v5 1/3] hw/pci: Introduce romfile_fixup hook in PCIDevice Tomita Moeko
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Tomita Moeko @ 2026-07-07 8:35 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Williamson, Cédric Le Goater, Michael S. Tsirkin,
Tomita Moeko, K S Maan
This series fixes the regression that on IGD passthrough with legacy
BIOS boot and VBIOS, the screen is garbled during BIOS POST and GRUB
(which uses standard VGA output routines), starting from QEMU 10.0.
Though the kernel i915 driver still works, it reports an error about
the initial GTT programmed by VBIOS is using invalid address.
i915 0000:00:02.0: [drm] *ERROR* Initial plane programming using invalid range, dma_addr=0x00000000db200000 ((null) [0x00000000baf00000-0x00000000beefffff])
With the help of AI disassembling the VBIOS image dumped from host, it
is found that the VBIOS itself implements a routine like:
uint32_t get_BDSM() {
static uint32_t saved = 0;
if (saved != 0) {
return saved;
}
return read_pci_config(BDSM_REG);
}
And the saved value is not cleared after initialization. Given that IGD
devices don't have a real ROM BAR, the VBIOS image read by default from
host is actually the VBIOS shadow RAM region, containing host-side
modifications like the saved BDSM value above during POST. When the
image is executed in guest, it still uses the saved host BDSM (HPA)
instead of the value programmed by SeaBIOS in config space (GPA). This
address mismatch leads to the garbled screen and i915 error.
The previous solution, c4c45e943e51 ("vfio/pci: Intel graphics legacy
mode assignment"), adjusts GTT entry addresses to (addr - host BDSM +
guest BDSM) to workaround that. But it is removed in 5aed8b0f0be2
("vfio/igd: Remove GTT write quirk in IO BAR 4") due to inconsistent
values in MMIO BAR0 and IO BAR4. Considering it's unsafe to expose HPA
to guest, a ROM quirk clearing the saved value in VBIOS image is
introduced to fix the issue.
During debugging, it is also found that IGD VBIOS ROM doesn't always
match the actual IGD device ID, due to the fact that IGD of the same
CPU family has multiple device IDs but shares the same ROM image.
However, SeaBIOS checks the device ID strictly and refuses to run if
IDs does not match. Currently only the default path, reading ROM from
kernel patches the device ID, but the romfile path doesn't. So the ROM
ID patching logic is also refactored in this patch series to also handle
the romfile path.
These changes are tested on Haswell platform with legacy BIOS boot, by
K S Maan. Thanks to K S Maan for continuous help on locating and testing
the issue!
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3093
Reported-by: K S Maan <kirandeepmaan45@gmail.com>
Changelog:
v5:
* Keep the current ID and checksum patching logic in vfio_pci_load_rom()
since it is not IGD-specific, as pointed out by Alex. The IGD-specific
quirk is now invoked after the generic patching. The ID and checksum
patching is duplicated in vfio_igd_legacy_rom_quirk() to handle the
romfile path, since the generic patching is not invoked on romfile.
* Picked up the Michael's Acked-by on patch 1.
* Reduced from 4 to 3 patches.
Link: https://lore.kernel.org/all/20260701182035.96010-1-tomitamoeko@gmail.com/t
v4:
* Reworked per review feedback to keep IGD-specific workarounds out of
the generic PCI code. Instead of recalculating the checksum in
hw/pci/pci.c, a single generic romfile_fixup hook is added for device-
specific ROM patching. Now both kernel ROM BAR and romfile paths share
the same quirk, so the saved BDSM in user-provided romfile will also
get cleared.
* Reduced from 7 to 4 patches.
Link: https://lore.kernel.org/all/20260617100646.28326-1-tomitamoeko@gmail.com/t
v3:
* Refactor ROM checksum calculation and patching logic as Alex's comment
* Fix boundary checks as comments in v2.
Link: https://lore.kernel.org/all/20260608134559.23971-1-tomitamoeko@gmail.com/t
v2:
* New patch 2/7 to fix regression with EFI option ROMs
* Refine logic in ROM ID and checksum patching
* Reorder patch 4 and 5 for cleaner bisection
* Address comments from v1
Link: https://lore.kernel.org/all/20260603173355.36121-1-tomitamoeko@gmail.com/t
Tomita Moeko (3):
hw/pci: Introduce romfile_fixup hook in PCIDevice
vfio/igd: Patch device ID for romfile-provided VBIOS
vfio/igd: Clear saved BDSM in legacy VBIOS ROM at load time
hw/pci/pci.c | 4 ++
hw/vfio/igd-stubs.c | 5 ++
hw/vfio/igd.c | 129 ++++++++++++++++++++++++++++++++++++
hw/vfio/pci-quirks.c | 5 ++
hw/vfio/pci.c | 2 +
hw/vfio/pci.h | 3 +
hw/vfio/trace-events | 1 +
include/hw/pci/pci_device.h | 1 +
8 files changed, 150 insertions(+)
--
2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v5 1/3] hw/pci: Introduce romfile_fixup hook in PCIDevice
2026-07-07 8:35 [PATCH v5 0/3] vfio/igd: Fix garbled screen on IGD passthrough with legacy VBIOS Tomita Moeko
@ 2026-07-07 8:35 ` Tomita Moeko
2026-07-07 8:35 ` [PATCH v5 2/3] vfio/igd: Patch device ID for romfile-provided VBIOS Tomita Moeko
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Tomita Moeko @ 2026-07-07 8:35 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Williamson, Cédric Le Goater, Michael S. Tsirkin,
Tomita Moeko, K S Maan
Some devices, such as VFIO IGD passthrough, require device-specific
fixups on the romfile provided by user. Add an optional romfile_fixup
hook to PCIDevice. When set, it is invoked from pci_add_option_rom()
right after the image is loaded, receiving the ROM buffer and its
size. This provides a place to post-process a loaded romfile without
leaking device-specific logic into the generic PCI core.
Reported-by: K S Maan <kirandeepmaan45@gmail.com>
Signed-off-by: Tomita Moeko <tomitamoeko@gmail.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/pci/pci.c | 4 ++++
include/hw/pci/pci_device.h | 1 +
2 files changed, 5 insertions(+)
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index d3191609e2..04372074ff 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -2639,6 +2639,10 @@ static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom,
/* Only the default rom images will be patched (if needed). */
pci_patch_ids(pdev, ptr, size);
}
+
+ if (pdev->romfile_fixup) {
+ pdev->romfile_fixup(pdev, ptr, size);
+ }
}
pci_register_bar(pdev, PCI_ROM_SLOT, 0, &pdev->rom);
diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h
index 5cac6e1688..a65e77018c 100644
--- a/include/hw/pci/pci_device.h
+++ b/include/hw/pci/pci_device.h
@@ -159,6 +159,7 @@ struct PCIDevice {
bool has_rom;
MemoryRegion rom;
int32_t rom_bar;
+ void (*romfile_fixup)(PCIDevice *pdev, uint8_t *ptr, uint32_t size);
/* INTx routing notifier */
PCIINTxRoutingNotifier intx_routing_notifier;
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v5 2/3] vfio/igd: Patch device ID for romfile-provided VBIOS
2026-07-07 8:35 [PATCH v5 0/3] vfio/igd: Fix garbled screen on IGD passthrough with legacy VBIOS Tomita Moeko
2026-07-07 8:35 ` [PATCH v5 1/3] hw/pci: Introduce romfile_fixup hook in PCIDevice Tomita Moeko
@ 2026-07-07 8:35 ` Tomita Moeko
2026-07-07 8:35 ` [PATCH v5 3/3] vfio/igd: Clear saved BDSM in legacy VBIOS ROM at load time Tomita Moeko
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Tomita Moeko @ 2026-07-07 8:35 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Williamson, Cédric Le Goater, Michael S. Tsirkin,
Tomita Moeko, K S Maan
Multiple IGD devices of the same generation share the same rom,
the device ID in its PCIR structure may not match. As SeaBIOS checks
the device ID strictly and refuses to run the VBIOS on a mismatch,
the ID has to be patched.
For a ROM read from the kernel ROM BAR, vfio_pci_load_rom() already
patches the device ID and recomputes the checksum. A VBIOS provided by
the user via romfile, however, is loaded by the generic PCI core and
does not receive this IGD-specific fixup.
Introduce vfio_igd_legacy_rom_quirk() in igd.c, which patches the
device ID and recomputes the (known bogus) checksum of a Gen 6-9 IGD
legacy VBIOS. This is registered as romfile_fixup hook when a romfile
is configured so that the romfile-provided VBIOS then receives the
same fixup as one read from the kernel ROM BAR.
Reported-by: K S Maan <kirandeepmaan45@gmail.com>
Signed-off-by: Tomita Moeko <tomitamoeko@gmail.com>
---
hw/vfio/igd-stubs.c | 5 +++++
hw/vfio/igd.c | 53 ++++++++++++++++++++++++++++++++++++++++++++
hw/vfio/pci.h | 2 ++
hw/vfio/trace-events | 1 +
4 files changed, 61 insertions(+)
diff --git a/hw/vfio/igd-stubs.c b/hw/vfio/igd-stubs.c
index f7687d9091..29110f7568 100644
--- a/hw/vfio/igd-stubs.c
+++ b/hw/vfio/igd-stubs.c
@@ -18,3 +18,8 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
{
return true;
}
+
+void vfio_igd_legacy_rom_quirk(PCIDevice *pdev, uint8_t *ptr, uint32_t size)
+{
+ return;
+}
diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c
index e091f21b6a..a5c1b57ce4 100644
--- a/hw/vfio/igd.c
+++ b/hw/vfio/igd.c
@@ -610,6 +610,10 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
goto error;
}
+ if (pdev->romfile) {
+ pdev->romfile_fixup = vfio_igd_legacy_rom_quirk;
+ }
+
/*
* ASLS (OpRegion address) is read-only, emulated
* It contains HPA, guest firmware need to reprogram it with GPA.
@@ -724,3 +728,52 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
return vfio_pci_igd_config_quirk(vdev, errp);
}
+
+void vfio_igd_legacy_rom_quirk(PCIDevice *pdev, uint8_t *ptr, uint32_t size)
+{
+ VFIOPCIDevice *vdev = VFIO_PCI_DEVICE(pdev);
+ int gen;
+ uint16_t pcir_offset;
+ uint8_t checksum = 0;
+ uint32_t i;
+
+ if (!vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, PCI_ANY_ID) ||
+ !vfio_is_vga(vdev) || !vdev->vga) {
+ return;
+ }
+
+ /* Only Gen 6~9 devices have legacy VBIOS as Option ROM */
+ gen = igd_gen(vdev);
+ if (gen < 6 || gen > 9) {
+ return;
+ }
+
+ if (pci_get_word(ptr) != 0xaa55) {
+ return;
+ }
+
+ /* Must be a legacy ROM */
+ pcir_offset = pci_get_word(ptr + 0x18);
+ if (pcir_offset + 0x14 >= size || memcmp(ptr + pcir_offset, "PCIR", 4) ||
+ pci_get_byte(ptr + pcir_offset + 0x14) != 0x00) {
+ return;
+ }
+
+ /*
+ * Patch device ID as multiple IGD devices share the same rom with possible
+ * non-matching IDs. This duplicates with vfio_pci_load_rom(), but required
+ * for romfile.
+ */
+ pci_set_word(ptr + pcir_offset + 6, vdev->device_id);
+
+ /*
+ * IGD roms are known to have bogus checksums. No matter we changed the
+ * device ID or not, we need to recalculate the checksum and patch it.
+ */
+ for (i = 0; i < size; i++) {
+ checksum += ptr[i];
+ }
+ ((uint8_t *)ptr)[6] -= checksum;
+
+ trace_vfio_pci_igd_vbios_patched(vdev->vbasedev.name);
+}
diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
index cf56711587..65a1385ce3 100644
--- a/hw/vfio/pci.h
+++ b/hw/vfio/pci.h
@@ -253,8 +253,10 @@ void vfio_setup_resetfn_quirk(VFIOPCIDevice *vdev);
bool vfio_add_virt_caps(VFIOPCIDevice *vdev, Error **errp);
void vfio_quirk_reset(VFIOPCIDevice *vdev);
VFIOQuirk *vfio_quirk_alloc(int nr_mem);
+
void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr);
bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp);
+void vfio_igd_legacy_rom_quirk(PCIDevice *pdev, uint8_t *ptr, uint32_t size);
extern const PropertyInfo qdev_prop_nv_gpudirect_clique;
diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
index 4c28b3291c..e472a65a44 100644
--- a/hw/vfio/trace-events
+++ b/hw/vfio/trace-events
@@ -90,6 +90,7 @@ vfio_pci_igd_bar4_write(const char *name, uint32_t index, uint32_t data, uint32_
vfio_pci_igd_bdsm_enabled(const char *name, int size) "%s %dMB"
vfio_pci_igd_host_bridge_enabled(const char *name) "%s"
vfio_pci_igd_lpc_bridge_enabled(const char *name) "%s"
+vfio_pci_igd_vbios_patched(const char *name) "%s"
# listener.c
vfio_iommu_map_notify(const char *op, uint64_t iova_start, uint64_t iova_end) "iommu %s @ 0x%"PRIx64" - 0x%"PRIx64
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v5 3/3] vfio/igd: Clear saved BDSM in legacy VBIOS ROM at load time
2026-07-07 8:35 [PATCH v5 0/3] vfio/igd: Fix garbled screen on IGD passthrough with legacy VBIOS Tomita Moeko
2026-07-07 8:35 ` [PATCH v5 1/3] hw/pci: Introduce romfile_fixup hook in PCIDevice Tomita Moeko
2026-07-07 8:35 ` [PATCH v5 2/3] vfio/igd: Patch device ID for romfile-provided VBIOS Tomita Moeko
@ 2026-07-07 8:35 ` Tomita Moeko
2026-07-07 12:47 ` [PATCH v5 0/3] vfio/igd: Fix garbled screen on IGD passthrough with legacy VBIOS K S Maan
2026-07-08 4:31 ` Alex Williamson
4 siblings, 0 replies; 6+ messages in thread
From: Tomita Moeko @ 2026-07-07 8:35 UTC (permalink / raw)
To: qemu-devel
Cc: Alex Williamson, Cédric Le Goater, Michael S. Tsirkin,
Tomita Moeko, K S Maan
IGD does not come with a ROM BAR [1], the ROM BAR read by default from
kernel is actually the host VBIOS shadow RAM region that contains host
modifications on boot. With AI-assisted reverse engineering on VBIOS
binaries, it is observed that VBIOS saves BDSM register value on first
access and uses saved value if present.
When the image is executed in guest, since there is already a saved HPA
in VBIOS, it keeps using that value instead of the GPA programmed by
SeaBIOS in BDSM register in PCI config space, causing VBIOS to program
GTT entries with wrong address, resulting in garbled output in BIOS
POST and the error below detected by i915 driver.
i915 0000:00:02.0: [drm] *ERROR* Initial plane programming using invalid range, dma_addr=0x00000000db200000 ((null) [0x00000000baf00000-0x00000000beefffff])
The previous solution, c4c45e943e51 ("vfio/pci: Intel graphics legacy
mode assignment"), adjusts GTT entry addresses to (addr - host BDSM +
guest BDSM) to workaround that. But it is removed in 5aed8b0f0be2
("vfio/igd: Remove GTT write quirk in IO BAR 4") due to inconsistent
values in MMIO BAR0 and IO BAR4.
Considering it's unsafe to expose HPA to guest, a ROM quirk clearing
the saved value in VBIOS image is introduced. It searches the BDSM
accessor routine by matching a 19-byte signature anchored on the unique
`mov $0x105e,%ax` instruction, then locate the offset of saved BDSM and
clears it. This makes the routine fall through to the PCI config read
on the first call inside the guest.
The quirk is now also invoked from vfio_pci_load_rom(), so the fix
applies to the VBIOS whether it is read from the kernel ROM BAR or
supplied through romfile.
[1] 3.5.15, 4th Generation Intel Core Processor Family Datasheet Vol. 2
https://www.intel.com/content/dam/www/public/us/en/documents/datasheets/4th-gen-core-family-desktop-vol-2-datasheet.pdf
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3093
Reported-by: K S Maan <kirandeepmaan45@gmail.com>
Signed-off-by: Tomita Moeko <tomitamoeko@gmail.com>
---
hw/vfio/igd.c | 76 ++++++++++++++++++++++++++++++++++++++++++++
hw/vfio/pci-quirks.c | 5 +++
hw/vfio/pci.c | 2 ++
hw/vfio/pci.h | 1 +
4 files changed, 84 insertions(+)
diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c
index a5c1b57ce4..d26744a6c6 100644
--- a/hw/vfio/igd.c
+++ b/hw/vfio/igd.c
@@ -729,11 +729,81 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
return vfio_pci_igd_config_quirk(vdev, errp);
}
+/*
+ * IGD ROM BAR read from kernel is actually the host VBIOS shadow RAM region,
+ * which contains host modifications. In Gen 6-9 VBIOS, the routine below is
+ * used to get BDSM value when programming the initial GTT.
+ * xx xx xx xx v: .long ? # saved value
+ * 66 53 push %ebx
+ * 66 2e 83 3e xx xx 00 cmpl $0x0,%cs:v # is saved value empty?
+ * 74 07 je 1f # if zero, go compute
+ * 66 2e a1 xx xx mov %cs:v,%eax # else return saved value
+ * eb 0f jmp 2f
+ * b8 5e 10 1: mov $0x105e,%ax # dev 00:02.0, offset 5E
+ * e8 xx xx call pci_read_cfg_word
+ * 66 c1 e0 10 shl $0x10,%eax # left shift 16 bits
+ * 66 2e a3 xx xx mov %eax,%cs:v # save the result
+ * 66 5b 2: pop %ebx
+ * c3 ret
+ * When running the VBIOS in guest, saved value still reflects the host stolen
+ * memory base address, which is not correct in guest. So we need to patch the
+ * VBIOS to clear the saved value.
+ *
+ * The unique 19-byte starts at `cmpl $0,%cs:v` and ends at `mov $0x105e,%ax`
+ * anchors the match to the routine. Both `cs:` displacements must reference
+ * the same offset.
+ */
+static int igd_vbios_find_saved_bdsm(const uint8_t *rom, size_t rom_size,
+ uint16_t *bdsm_offset)
+{
+ static const uint8_t start[] = { 0x66, 0x2e, 0x83, 0x3e };
+ static const uint8_t middle[] = { 0x00, 0x74, 0x07, 0x66, 0x2e, 0xa1 };
+ static const uint8_t end[] = { 0xeb, 0x0f, 0xb8, 0x5e, 0x10 };
+ uint16_t val;
+ size_t i;
+ bool found = false;
+
+ if (rom_size < 19) {
+ return -ENOENT;
+ }
+
+ for (i = 0; i + 19 <= rom_size; i++) {
+ if (memcmp(rom + i, start, sizeof(start)) != 0 ||
+ memcmp(rom + i + 6, middle, sizeof(middle)) != 0 ||
+ memcmp(rom + i + 14, end, sizeof(end)) != 0) {
+ continue;
+ }
+
+ /* same saved value address? */
+ if (rom[i + 4] != rom[i + 12] || rom[i + 5] != rom[i + 13]) {
+ continue;
+ }
+
+ if (found) {
+ return -EEXIST;
+ }
+
+ val = rom[i + 4] | ((uint16_t)rom[i + 5] << 8);
+ if (val + sizeof(uint32_t) <= rom_size) {
+ *bdsm_offset = val;
+ found = true;
+ }
+ }
+
+ if (!found) {
+ return -ENOENT;
+ }
+
+ return 0;
+}
+
void vfio_igd_legacy_rom_quirk(PCIDevice *pdev, uint8_t *ptr, uint32_t size)
{
VFIOPCIDevice *vdev = VFIO_PCI_DEVICE(pdev);
int gen;
uint16_t pcir_offset;
+ int ret;
+ uint16_t bdsm_offset = 0;
uint8_t checksum = 0;
uint32_t i;
@@ -766,6 +836,12 @@ void vfio_igd_legacy_rom_quirk(PCIDevice *pdev, uint8_t *ptr, uint32_t size)
*/
pci_set_word(ptr + pcir_offset + 6, vdev->device_id);
+ /* Search and clear the saved BDSM value */
+ ret = igd_vbios_find_saved_bdsm(ptr, size, &bdsm_offset);
+ if (ret == 0) {
+ memset(ptr + bdsm_offset, 0, sizeof(uint32_t));
+ }
+
/*
* IGD roms are known to have bogus checksums. No matter we changed the
* device ID or not, we need to recalculate the checksum and patch it.
diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
index bccf31751f..496a79a3ca 100644
--- a/hw/vfio/pci-quirks.c
+++ b/hw/vfio/pci-quirks.c
@@ -1592,3 +1592,8 @@ bool vfio_add_virt_caps(VFIOPCIDevice *vdev, Error **errp)
return true;
}
+
+void vfio_rom_quirk_setup(VFIOPCIDevice *vdev)
+{
+ vfio_igd_legacy_rom_quirk(PCI_DEVICE(vdev), vdev->rom, vdev->rom_size);
+}
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 4d822b96b5..c40a6f7ca6 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -1114,6 +1114,8 @@ static void vfio_pci_load_rom(VFIOPCIDevice *vdev)
data[6] = -csum;
}
}
+
+ vfio_rom_quirk_setup(vdev);
}
/* "Raw" read of underlying config space. */
diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
index 65a1385ce3..fb70113e3a 100644
--- a/hw/vfio/pci.h
+++ b/hw/vfio/pci.h
@@ -251,6 +251,7 @@ void vfio_bar_quirk_exit(VFIOPCIDevice *vdev, int nr);
void vfio_bar_quirk_finalize(VFIOPCIDevice *vdev, int nr);
void vfio_setup_resetfn_quirk(VFIOPCIDevice *vdev);
bool vfio_add_virt_caps(VFIOPCIDevice *vdev, Error **errp);
+void vfio_rom_quirk_setup(VFIOPCIDevice *vdev);
void vfio_quirk_reset(VFIOPCIDevice *vdev);
VFIOQuirk *vfio_quirk_alloc(int nr_mem);
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v5 0/3] vfio/igd: Fix garbled screen on IGD passthrough with legacy VBIOS
2026-07-07 8:35 [PATCH v5 0/3] vfio/igd: Fix garbled screen on IGD passthrough with legacy VBIOS Tomita Moeko
` (2 preceding siblings ...)
2026-07-07 8:35 ` [PATCH v5 3/3] vfio/igd: Clear saved BDSM in legacy VBIOS ROM at load time Tomita Moeko
@ 2026-07-07 12:47 ` K S Maan
2026-07-08 4:31 ` Alex Williamson
4 siblings, 0 replies; 6+ messages in thread
From: K S Maan @ 2026-07-07 12:47 UTC (permalink / raw)
To: Tomita Moeko, qemu-devel
Cc: Alex Williamson, Cédric Le Goater, Michael S. Tsirkin
Tested-by: K S Maan <kirandeepmaan45@gmail.com>
On 7/7/26 2:05 PM, Tomita Moeko wrote:
> This series fixes the regression that on IGD passthrough with legacy
> BIOS boot and VBIOS, the screen is garbled during BIOS POST and GRUB
> (which uses standard VGA output routines), starting from QEMU 10.0.
> Though the kernel i915 driver still works, it reports an error about
> the initial GTT programmed by VBIOS is using invalid address.
>
> i915 0000:00:02.0: [drm] *ERROR* Initial plane programming using invalid range, dma_addr=0x00000000db200000 ((null) [0x00000000baf00000-0x00000000beefffff])
>
> With the help of AI disassembling the VBIOS image dumped from host, it
> is found that the VBIOS itself implements a routine like:
>
> uint32_t get_BDSM() {
> static uint32_t saved = 0;
> if (saved != 0) {
> return saved;
> }
> return read_pci_config(BDSM_REG);
> }
>
> And the saved value is not cleared after initialization. Given that IGD
> devices don't have a real ROM BAR, the VBIOS image read by default from
> host is actually the VBIOS shadow RAM region, containing host-side
> modifications like the saved BDSM value above during POST. When the
> image is executed in guest, it still uses the saved host BDSM (HPA)
> instead of the value programmed by SeaBIOS in config space (GPA). This
> address mismatch leads to the garbled screen and i915 error.
>
> The previous solution, c4c45e943e51 ("vfio/pci: Intel graphics legacy
> mode assignment"), adjusts GTT entry addresses to (addr - host BDSM +
> guest BDSM) to workaround that. But it is removed in 5aed8b0f0be2
> ("vfio/igd: Remove GTT write quirk in IO BAR 4") due to inconsistent
> values in MMIO BAR0 and IO BAR4. Considering it's unsafe to expose HPA
> to guest, a ROM quirk clearing the saved value in VBIOS image is
> introduced to fix the issue.
>
> During debugging, it is also found that IGD VBIOS ROM doesn't always
> match the actual IGD device ID, due to the fact that IGD of the same
> CPU family has multiple device IDs but shares the same ROM image.
> However, SeaBIOS checks the device ID strictly and refuses to run if
> IDs does not match. Currently only the default path, reading ROM from
> kernel patches the device ID, but the romfile path doesn't. So the ROM
> ID patching logic is also refactored in this patch series to also handle
> the romfile path.
>
> These changes are tested on Haswell platform with legacy BIOS boot, by
> K S Maan. Thanks to K S Maan for continuous help on locating and testing
> the issue!
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3093
> Reported-by: K S Maan <kirandeepmaan45@gmail.com>
>
> Changelog:
> v5:
> * Keep the current ID and checksum patching logic in vfio_pci_load_rom()
> since it is not IGD-specific, as pointed out by Alex. The IGD-specific
> quirk is now invoked after the generic patching. The ID and checksum
> patching is duplicated in vfio_igd_legacy_rom_quirk() to handle the
> romfile path, since the generic patching is not invoked on romfile.
> * Picked up the Michael's Acked-by on patch 1.
> * Reduced from 4 to 3 patches.
> Link: https://lore.kernel.org/all/20260701182035.96010-1-tomitamoeko@gmail.com/t
>
> v4:
> * Reworked per review feedback to keep IGD-specific workarounds out of
> the generic PCI code. Instead of recalculating the checksum in
> hw/pci/pci.c, a single generic romfile_fixup hook is added for device-
> specific ROM patching. Now both kernel ROM BAR and romfile paths share
> the same quirk, so the saved BDSM in user-provided romfile will also
> get cleared.
> * Reduced from 7 to 4 patches.
> Link: https://lore.kernel.org/all/20260617100646.28326-1-tomitamoeko@gmail.com/t
>
> v3:
> * Refactor ROM checksum calculation and patching logic as Alex's comment
> * Fix boundary checks as comments in v2.
> Link: https://lore.kernel.org/all/20260608134559.23971-1-tomitamoeko@gmail.com/t
>
> v2:
> * New patch 2/7 to fix regression with EFI option ROMs
> * Refine logic in ROM ID and checksum patching
> * Reorder patch 4 and 5 for cleaner bisection
> * Address comments from v1
> Link: https://lore.kernel.org/all/20260603173355.36121-1-tomitamoeko@gmail.com/t
>
> Tomita Moeko (3):
> hw/pci: Introduce romfile_fixup hook in PCIDevice
> vfio/igd: Patch device ID for romfile-provided VBIOS
> vfio/igd: Clear saved BDSM in legacy VBIOS ROM at load time
>
> hw/pci/pci.c | 4 ++
> hw/vfio/igd-stubs.c | 5 ++
> hw/vfio/igd.c | 129 ++++++++++++++++++++++++++++++++++++
> hw/vfio/pci-quirks.c | 5 ++
> hw/vfio/pci.c | 2 +
> hw/vfio/pci.h | 3 +
> hw/vfio/trace-events | 1 +
> include/hw/pci/pci_device.h | 1 +
> 8 files changed, 150 insertions(+)
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 0/3] vfio/igd: Fix garbled screen on IGD passthrough with legacy VBIOS
2026-07-07 8:35 [PATCH v5 0/3] vfio/igd: Fix garbled screen on IGD passthrough with legacy VBIOS Tomita Moeko
` (3 preceding siblings ...)
2026-07-07 12:47 ` [PATCH v5 0/3] vfio/igd: Fix garbled screen on IGD passthrough with legacy VBIOS K S Maan
@ 2026-07-08 4:31 ` Alex Williamson
4 siblings, 0 replies; 6+ messages in thread
From: Alex Williamson @ 2026-07-08 4:31 UTC (permalink / raw)
To: Tomita Moeko
Cc: qemu-devel, Cédric Le Goater, Michael S. Tsirkin, K S Maan,
alex
On Tue, 7 Jul 2026 16:35:47 +0800
Tomita Moeko <tomitamoeko@gmail.com> wrote:
> This series fixes the regression that on IGD passthrough with legacy
> BIOS boot and VBIOS, the screen is garbled during BIOS POST and GRUB
> (which uses standard VGA output routines), starting from QEMU 10.0.
> Though the kernel i915 driver still works, it reports an error about
> the initial GTT programmed by VBIOS is using invalid address.
>
> i915 0000:00:02.0: [drm] *ERROR* Initial plane programming using invalid range, dma_addr=0x00000000db200000 ((null) [0x00000000baf00000-0x00000000beefffff])
>
> With the help of AI disassembling the VBIOS image dumped from host, it
> is found that the VBIOS itself implements a routine like:
>
> uint32_t get_BDSM() {
> static uint32_t saved = 0;
> if (saved != 0) {
> return saved;
> }
> return read_pci_config(BDSM_REG);
> }
>
> And the saved value is not cleared after initialization. Given that IGD
> devices don't have a real ROM BAR, the VBIOS image read by default from
> host is actually the VBIOS shadow RAM region, containing host-side
> modifications like the saved BDSM value above during POST. When the
> image is executed in guest, it still uses the saved host BDSM (HPA)
> instead of the value programmed by SeaBIOS in config space (GPA). This
> address mismatch leads to the garbled screen and i915 error.
>
> The previous solution, c4c45e943e51 ("vfio/pci: Intel graphics legacy
> mode assignment"), adjusts GTT entry addresses to (addr - host BDSM +
> guest BDSM) to workaround that. But it is removed in 5aed8b0f0be2
> ("vfio/igd: Remove GTT write quirk in IO BAR 4") due to inconsistent
> values in MMIO BAR0 and IO BAR4. Considering it's unsafe to expose HPA
> to guest, a ROM quirk clearing the saved value in VBIOS image is
> introduced to fix the issue.
How is it unsafe to expose an HPA? The initial values in the PCI BARs
expose their HPAs, it's not unsafe. The issue here is that the host
value is latched into the BIOS, which breaks the virtualization since
we're not mapping the GTT at the same address in the VM.
> During debugging, it is also found that IGD VBIOS ROM doesn't always
> match the actual IGD device ID, due to the fact that IGD of the same
> CPU family has multiple device IDs but shares the same ROM image.
> However, SeaBIOS checks the device ID strictly and refuses to run if
> IDs does not match. Currently only the default path, reading ROM from
> kernel patches the device ID, but the romfile path doesn't. So the ROM
> ID patching logic is also refactored in this patch series to also handle
> the romfile path.
This is a separate feature from the regression fix. Up until now we've
only modified the ROM as provided through the vfio interface as the
user is out of the loop. Once the user is in the loop and providing
the ROM via a file, we've always assumed it's the user's responsibility
to fixup the ROM and QEMU should pass it through unmodified. I have a
tool[1] in my github that has served this purpose, allowing a device ID
to be written into the ROM image and the checksum recalculated. We've
always required a ROM provided as a romfile to be pre-modified to match
the device ID. Even the existing fixup in the PCI code is only for
default ROMs, not the PCIDevice.romfile image.
As I understand this series, we're using the rationale that removing
the GTT hack introduced a regression in QEMU and the fix we've
discovered for that regression requires clearing a field in the ROM
image, therefore we want to do that regardless of whether the ROM image
is provided through vfio or by the user... and while we're already
mangling the user provided image, we might as well fixup the device ID.
Also, as I'm reading the gitlab issue resolved by patch 3, it's
reported against the ROM read through vfio path, not the romfile path.
So for the issue presented, this could be a single patch that adds an
igd callout/stub to vfio_pci_load_rom() to zero the BDSM field, and
we'd require the romfile path to provide a pristine ROM image, with
matching device ID (already a requirement) and now the BDSM workaround.
Given that QEMU 11.1 is already in soft-freeze, that sounds more like
the self-contained, no additional feature fix that we need.
Effectively patch 3 with the BDSM zeroing directly wired through
vfio_pci_load_rom() and a Fixes: tag referencing the 10.0 commit
removing the previous GTT hack. Thanks,
Alex
[1]https://github.com/awilliam/rom-parser
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-07-08 4:32 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-07 8:35 [PATCH v5 0/3] vfio/igd: Fix garbled screen on IGD passthrough with legacy VBIOS Tomita Moeko
2026-07-07 8:35 ` [PATCH v5 1/3] hw/pci: Introduce romfile_fixup hook in PCIDevice Tomita Moeko
2026-07-07 8:35 ` [PATCH v5 2/3] vfio/igd: Patch device ID for romfile-provided VBIOS Tomita Moeko
2026-07-07 8:35 ` [PATCH v5 3/3] vfio/igd: Clear saved BDSM in legacy VBIOS ROM at load time Tomita Moeko
2026-07-07 12:47 ` [PATCH v5 0/3] vfio/igd: Fix garbled screen on IGD passthrough with legacy VBIOS K S Maan
2026-07-08 4:31 ` Alex Williamson
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.