Skip to contentSkip to conversation

xen/igd: fixes for Intel IGD passthrough

PATCH Superseded Chuck Zmudzinski 1 participant 4 messages Jul 9 1 message not in the archive

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

v2 cover xen/igd: fixes for Intel IGD passthrough

This patch series aims to fix long-standing bugs that need to be backported to all currently supported stable versions.

This series fixes three bugs that cause problems ranging from a dark screen in the guest until the guest OS graphics drivers are loaded to an assert failure that prevents the guest from starting.

To test these patches, it is necessary to test with older Intel IGD devices that have support for legacy VGA bios.

The patches have been tested using Xen 4.21 and Seabios 1.17 on Fedora 44 using an Intel NUC7i5BNK with an i5-7260U processor and have been verified to fix the bugs as described in the individual patches.

Changes in v2:
- close open files before setting errp
- improvements to readability and style
- small corrections to the commit messages
- add stable to Cc list

Chuck Zmudzinski (3):
xen/igd: get PCH info from host sysfs
xen/igd: don't register rom bar twice
xen/igd: fixup device id before registering rom

 hw/xen/xen_pt.c          |  5 ++-
 hw/xen/xen_pt_graphics.c | 85 ++++++++++++++++++++++++++++++++++++++--
 hw/xen/xen_pt_load_rom.c | 18 ++++++---
 include/hw/xen/xen_igd.h |  3 +-
 4 files changed, 99 insertions(+), 12 deletions(-)
Signature · 1 line
2.52.0
#2 lore raw

PATCH v2 1/3 xen/igd: get PCH info from host sysfs

The igd_combo_id_infos[] data is more than 10 years out of date with many Intel IGD devices missing from igd_combo_id_infos[]. This means that many devices that could be supported will not work with the current implementation.

For newer devices not listed in igd_combo_id_infos[], get infos from the host sysfs to enable support for the newer devices not listed in igd_combo_id_infos[].

Introduce the helper function xen_pt_get_host_pch_info to facilitate getting the necessary information from sysfs.

Also, use errp in xen_igd_passthrough_isa_bridge_create to set errors from xen_pt_get_host_pch_info.

---
Changes in v2:
- call error_setg* after closing files instead of before closing files
- in last line of commit message change "to propagate errors" to "to set errors"
- add stable to Cc list

 hw/xen/xen_pt.c          |  2 +-
 hw/xen/xen_pt_graphics.c | 82 ++++++++++++++++++++++++++++++++++++++--
 include/hw/xen/xen_igd.h |  3 +-
 3 files changed, 82 insertions(+), 5 deletions(-)
hw/xen/xen_pt.c +1 -1
index 0fe9c0a..474606e 100644
@@ -867,7 +867,7 @@ static void xen_pt_realize(PCIDevice *d, Error **errp)
         }
 
         /* Register ISA bridge for passthrough GFX. */
-        xen_igd_passthrough_isa_bridge_create(s, &s->real_device);
+        xen_igd_passthrough_isa_bridge_create(s, &s->real_device, errp);
     }
 
     /* Handle real device's MMIO/PIO BARs */
hw/xen/xen_pt_graphics.c +79 -3

101 lines not on this page · raw message

include/hw/xen/xen_igd.h +2 -1
index 7ffca06..da51f09 100644
@@ -22,7 +22,8 @@ uint32_t igd_read_opregion(XenPCIPassthroughState *s);
 void xen_igd_reserve_slot(PCIBus *pci_bus);
 void igd_write_opregion(XenPCIPassthroughState *s, uint32_t val);
 void xen_igd_passthrough_isa_bridge_create(XenPCIPassthroughState *s,
-                                           XenHostPCIDevice *dev);
+                                           XenHostPCIDevice *dev,
+                                           Error **errp);
 
 static inline bool is_igd_vga_passthrough(XenHostPCIDevice *dev)
 {
Signature · 1 line
2.52.0
#3 lore raw

PATCH v2 2/3 xen/igd: don't register rom bar twice

In reply to Chuck Zmudzinski

This also fixes a failed assertion in pci [1] for Qemu version 10 and higher when passing through an Intel IGD with an option ROM to the guest.

[1] f6fc01c ("hw/pci: Assert a bar is not registered multiple times")

Fixes 881213f ("xen, gfx passthrough: retrieve VGA BIOS to work")

---
Changes in v2:
- get 'pcibus_t romsize' instead of 'PCIIORegion region'
- move definition of romsize to the top of the function and make it constant
- add stable to Cc list

 hw/xen/xen_pt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/xen/xen_pt.c +2 -1
index 474606e..8b30b61 100644
@@ -459,6 +459,7 @@ static int xen_pt_register_regions(XenPCIPassthroughState *s, uint16_t *cmd)
 {
     int i = 0;
     XenHostPCIDevice *d = &s->real_device;
+    const pcibus_t romsize = s->dev.io_regions[PCI_ROM_SLOT].size;
 
     /* Register PIO/MMIO BARs */
     for (i = 0; i < PCI_ROM_SLOT; i++) {
@@ -495,7 +496,7 @@ static int xen_pt_register_regions(XenPCIPassthroughState *s, uint16_t *cmd)
     }
 
     /* Register expansion ROM address */
-    if (d->rom.base_addr && d->rom.size) {
+    if (!romsize && d->rom.base_addr && d->rom.size) {
         uint32_t bar_data = 0;
 
         /* Re-set BAR reported by OS, otherwise ROM can't be read. */
Signature · 1 line
2.52.0
#4 lore raw

PATCH v2 3/3 xen/igd: fixup device id before registering rom

In reply to Chuck Zmudzinski

With the current implementation, Seabios does not see the fixup of the device id done here and consequently Seabios does not load the VGA bios and the guest screen does not light up until the guest OS graphics driver is loaded. So there is no VGA output from the passed through Intel IGD from either Seabios or the guest bootloader with the current implementation in cases when the device id needs fixing.

Fix this by waiting until after doing fixup of the device id before registering the option ROM. With this patch, Seabios sees the fixup done here and loads the VGA bios, and both Seabios and the guest bootloader light up the guest screen in cases when fixup of the device id is needed.

Also, remove unused header hw/core/loader.h.

---
Changes in v2:
- add a period to the end of the last sentence of the commit message
- add stable to Cc list

 hw/xen/xen_pt_graphics.c |  3 +++
 hw/xen/xen_pt_load_rom.c | 18 ++++++++++++------
 2 files changed, 15 insertions(+), 6 deletions(-)
hw/xen/xen_pt_graphics.c +3 -0
index 2ef941e..aface0b 100644
@@ -222,6 +222,9 @@ void xen_pt_setup_vga(XenPCIPassthroughState *s, XenHostPCIDevice *dev,
         }
     }
 
+    pci_register_bar(&s->dev, PCI_ROM_SLOT, 0, &s->dev.rom);
+    s->dev.has_rom = true;
+
     /* Currently we fixed this address as a primary for legacy BIOS. */
     physical_memory_write(0xc0000, bios, bios_size);
 }
hw/xen/xen_pt_load_rom.c +12 -6
index 319efca..407b630 100644
@@ -4,14 +4,22 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
-#include "hw/core/loader.h"
 #include "hw/pci/pci.h"
 #include "xen_pt.h"
 
 /*
- * Scan the assigned devices for the devices that have an option ROM, and then
- * load the corresponding ROM data to RAM. If an error occurs while loading an
- * option ROM, we just ignore that option ROM and continue with the next one.
+ * Normally xen_pt_register_regions will handle loading the option ROM,
+ * but in some cases, such as for the Intel IGD, the option ROM might
+ * need to be modified.
+ *
+ * For such cases, use this function to get a pointer to the option ROM
+ * from sysfs. Caller has the responsibility to edit the option ROM as
+ * needed, call pci_register_bar to register the modified option ROM,
+ * and set has_rom to true for the PCI device.
+ *
+ * This function must be called before xen_pt_register_regions is called
+ * because if xen_pt_register_regions is called first, it will register
+ * the option ROM and any attempt to register it again will fail.
  */
 void *pci_assign_dev_load_option_rom(PCIDevice *dev,
                                      int *size, unsigned int domain,
@@ -76,8 +84,6 @@ void *pci_assign_dev_load_option_rom(PCIDevice *dev,
         goto close_rom;
     }
 
-    pci_register_bar(dev, PCI_ROM_SLOT, 0, &dev->rom);
-    dev->has_rom = true;
     *size = st.st_size;
 close_rom:
     /* Write "0" to disable ROM */
Signature · 1 line
2.52.0