Skip to contentSkip to conversation

xen/igd: fixup device id before registering rom

PATCH Superseded Chuck Zmudzinski 3 participants 10 messages Jul 9 – Jul 26 1 message not in the archive

v3 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

v3 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

Changes in v3:
- whitespace fix in first patch
- fix Cc address for qemu-stable

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 v3 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

Changes in v3:
- whitespace fix at line 380 of xen_pt_graphics.c
- fix Cc address for qemu-stable

 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

Re: [PATCH v3 1/3] xen/igd: get PCH info from host sysfs

Sorry I am not the maintainer/reviewer of Xen IGD passthrough, just out of my personal interest

Quoted 40 lines · Chuck Zmudzinski

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

Changes in v3:
- whitespace fix at line 380 of xen_pt_graphics.c
- fix Cc address for qemu-stable

 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 +0 -0
index 0fe9c0a..474606e 100644

hw/xen/xen_pt.c static void xen_pt_realize(PCIDevice *d, Error **errp) · line 870

Quoted 5 lines
hw/xen/xen_pt.c +1 -1
@@ -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);

The errp need to be handled here if any error occurs.

Quoted 67 lines
hw/xen/xen_pt.c +0 -0
     }
 
     /* Handle real device's MMIO/PIO BARs */
hw/xen/xen_pt_graphics.c +56 -0
index 7df9344..2ef941e 100644
@@ -376,8 +376,75 @@ static void pt_graphics_register_types(void)
 }
 type_init(pt_graphics_register_types)
 
+static void xen_pt_get_host_pch_info(PCIDevice *dev, uint16_t *pch_dev_id,
+                                     uint8_t *pch_rev_id, Error **errp)
+{
+    FILE *fp1, *fp2;
+    char *endptr;
+    char device_id[7], rev[5];
+    size_t len;
+    const char *device = "/sys/bus/pci/devices/0000:00:1f.0/device";
+    const char *revision = "/sys/bus/pci/devices/0000:00:1f.0/revision";
+    unsigned long val;
+
+    fp1 = fopen(device, "r");
+    if (fp1 == NULL) {
+        error_setg_errno(errp, errno, "Cannot open %s", device);
+        return;
+    }
+    fp2 = fopen(revision, "r");
+    if (fp2 == NULL) {
+        fclose(fp1);
+        error_setg_errno(errp, errno, "Cannot open %s", revision);
+        return;
+    }
+
+    len = fread(device_id, 1, 7, fp1);
+    if (!len) {
+        fclose(fp1);
+        fclose(fp2);
+        error_setg(errp, "Cannot read %s", device);
+        return;
+    }
+    len = fread(rev, 1, 5, fp2);
+    if (!len) {
+        fclose(fp1);
+        fclose(fp2);
+        error_setg(errp, "Cannot read %s", revision);
+        return;
+    }
+    fclose(fp1);
+    fclose(fp2);
+
+    val = strtoul(device_id, &endptr, 16);
+    if (val > 0xffff) {
+        error_setg(errp, "PCH device id is out of range: 0x%lx", val);
+        return;
+    }
+    if ((endptr > device_id) && (errno != ERANGE) &&
+        (errno != EINVAL)) {
+        *pch_dev_id = (uint16_t)val;
+    } else {
+        error_setg_errno(errp, errno, "device id strtoul "
+                                      "conversion failed");
+        return;
+    }
+    val = strtoul(rev, &endptr, 16);
+    if (val > 0xff) {
+        error_setg(errp, "PCH revision is out of range: 0x%lx", val);

hw/xen/xen_pt_graphics.c static void pt_graphics_register_types(void) · line 444

Quoted 10 lines
hw/xen/xen_pt_graphics.c +10 -0
+        return;
+    }
+    if ((endptr > rev) && (errno != ERANGE) && (errno != EINVAL)) {
+        *pch_rev_id = (uint8_t)val;
+    } else {
+        error_setg_errno(errp, errno, "revision strtoul "
+                                      "conversion failed");
+    }
+}
+

It would be better to reuse existing xen_host_pci_device_get() to read host LPC bridge ids instead of parsing it on our own here.

Quoted 48 lines
hw/xen/xen_pt_graphics.c +13 -3
 void xen_igd_passthrough_isa_bridge_create(XenPCIPassthroughState *s,
-                                           XenHostPCIDevice *dev)
+                                           XenHostPCIDevice *dev,
+                                           Error **errp)
 {
     PCIBus *bus = pci_get_bus(&s->dev);
     struct PCIDevice *bridge_dev;
@@ -394,7 +461,16 @@ void xen_igd_passthrough_isa_bridge_create(XenPCIPassthroughState *s,
         }
     }
 
-    if (pch_dev_id == 0xffff) {
+    /* Newer devices get PCH infos from host sysfs */
+    if ((pch_dev_id == 0xffff) || !pch_rev_id) {
+        xen_pt_get_host_pch_info(&s->dev, &pch_dev_id, &pch_rev_id, errp);
+    }
+
+    XEN_PT_LOG(&s->dev, "PCH device id: 0x%x\n", pch_dev_id);
+    XEN_PT_LOG(&s->dev, "PCH revision: 0x%x\n", pch_rev_id);
+
+    if ((pch_dev_id == 0xffff) || !pch_rev_id) {
+        error_setg(errp, "failed to get PCH device id or revision");
         return;
     }
 
@@ -406,7 +482,7 @@ void xen_igd_passthrough_isa_bridge_create(XenPCIPassthroughState *s,
      * Note that vendor id is always PCI_VENDOR_ID_INTEL.
      */
     if (!bridge_dev) {
-        fprintf(stderr, "set igd-passthrough-isa-bridge failed!\n");
+        error_setg(errp, "set igd-passthrough-isa-bridge failed!");
         return;
     }
     pci_config_set_device_id(bridge_dev->config, pch_dev_id);
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)
 {
#4 lore raw

Re: [PATCH v3 1/3] xen/igd: get PCH info from host sysfs

Quoted 2 lines · Tomita Moeko

Sorry I am not the maintainer/reviewer of Xen IGD passthrough, just out of my personal interest

I appreciate your review. Thanks!

Quoted 122 lines · Chuck Zmudzinski
Quoted 40 lines

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

Changes in v3:
- whitespace fix at line 380 of xen_pt_graphics.c
- fix Cc address for qemu-stable

 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 +0 -0
index 0fe9c0a..474606e 100644

hw/xen/xen_pt.c static void xen_pt_realize(PCIDevice *d, Error **errp) · line 870

Quoted 5 lines
hw/xen/xen_pt.c +1 -1
@@ -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);

The errp need to be handled here if any error occurs.

Quoted 72 lines
hw/xen/xen_pt.c +0 -0
     }
 
     /* Handle real device's MMIO/PIO BARs */
hw/xen/xen_pt_graphics.c +61 -0
index 7df9344..2ef941e 100644
@@ -376,8 +376,75 @@ static void pt_graphics_register_types(void)
 }
 type_init(pt_graphics_register_types)
 
+static void xen_pt_get_host_pch_info(PCIDevice *dev, uint16_t *pch_dev_id,
+                                     uint8_t *pch_rev_id, Error **errp)
+{
+    FILE *fp1, *fp2;
+    char *endptr;
+    char device_id[7], rev[5];
+    size_t len;
+    const char *device = "/sys/bus/pci/devices/0000:00:1f.0/device";
+    const char *revision = "/sys/bus/pci/devices/0000:00:1f.0/revision";
+    unsigned long val;
+
+    fp1 = fopen(device, "r");
+    if (fp1 == NULL) {
+        error_setg_errno(errp, errno, "Cannot open %s", device);
+        return;
+    }
+    fp2 = fopen(revision, "r");
+    if (fp2 == NULL) {
+        fclose(fp1);
+        error_setg_errno(errp, errno, "Cannot open %s", revision);
+        return;
+    }
+
+    len = fread(device_id, 1, 7, fp1);
+    if (!len) {
+        fclose(fp1);
+        fclose(fp2);
+        error_setg(errp, "Cannot read %s", device);
+        return;
+    }
+    len = fread(rev, 1, 5, fp2);
+    if (!len) {
+        fclose(fp1);
+        fclose(fp2);
+        error_setg(errp, "Cannot read %s", revision);
+        return;
+    }
+    fclose(fp1);
+    fclose(fp2);
+
+    val = strtoul(device_id, &endptr, 16);
+    if (val > 0xffff) {
+        error_setg(errp, "PCH device id is out of range: 0x%lx", val);
+        return;
+    }
+    if ((endptr > device_id) && (errno != ERANGE) &&
+        (errno != EINVAL)) {
+        *pch_dev_id = (uint16_t)val;
+    } else {
+        error_setg_errno(errp, errno, "device id strtoul "
+                                      "conversion failed");
+        return;
+    }
+    val = strtoul(rev, &endptr, 16);
+    if (val > 0xff) {
+        error_setg(errp, "PCH revision is out of range: 0x%lx", val);
+        return;
+    }
+    if ((endptr > rev) && (errno != ERANGE) && (errno != EINVAL)) {
+        *pch_rev_id = (uint8_t)val;
+    } else {
Quoted 8 lines

hw/xen/xen_pt_graphics.c static void pt_graphics_register_types(void) · line 444

Quoted 5 lines
hw/xen/xen_pt_graphics.c +5 -0
+        error_setg_errno(errp, errno, "revision strtoul "
+                                      "conversion failed");
+    }
+}
+

It would be better to reuse existing xen_host_pci_device_get() to read host LPC bridge ids instead of parsing it on our own here.

Ah yes, I see how that can be done and I agree that would be better. I will re-write xen_pt_get_host_pch_info() using the functions declared in xen-host-pci-device.h for the next version of this patch.

Quoted 50 lines
Quoted 49 lines
hw/xen/xen_pt_graphics.c +13 -3
 void xen_igd_passthrough_isa_bridge_create(XenPCIPassthroughState *s,
-                                           XenHostPCIDevice *dev)
+                                           XenHostPCIDevice *dev,
+                                           Error **errp)
 {
     PCIBus *bus = pci_get_bus(&s->dev);
     struct PCIDevice *bridge_dev;
@@ -394,7 +461,16 @@ void xen_igd_passthrough_isa_bridge_create(XenPCIPassthroughState *s,
         }
     }
 
-    if (pch_dev_id == 0xffff) {
+    /* Newer devices get PCH infos from host sysfs */
+    if ((pch_dev_id == 0xffff) || !pch_rev_id) {
+        xen_pt_get_host_pch_info(&s->dev, &pch_dev_id, &pch_rev_id, errp);
+    }
+
+    XEN_PT_LOG(&s->dev, "PCH device id: 0x%x\n", pch_dev_id);
+    XEN_PT_LOG(&s->dev, "PCH revision: 0x%x\n", pch_rev_id);
+
+    if ((pch_dev_id == 0xffff) || !pch_rev_id) {
+        error_setg(errp, "failed to get PCH device id or revision");
         return;
     }
 
@@ -406,7 +482,7 @@ void xen_igd_passthrough_isa_bridge_create(XenPCIPassthroughState *s,
      * Note that vendor id is always PCI_VENDOR_ID_INTEL.
      */
     if (!bridge_dev) {
-        fprintf(stderr, "set igd-passthrough-isa-bridge failed!\n");
+        error_setg(errp, "set igd-passthrough-isa-bridge failed!");
         return;
     }
     pci_config_set_device_id(bridge_dev->config, pch_dev_id);
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)
 {
#5 lore raw

Re: [PATCH v3 1/3] xen/igd: get PCH info from host sysfs

In reply to Tomita Moeko
Quoted 29 lines · Tomita Moeko
Quoted 29 lines

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

Changes in v3:
- whitespace fix at line 380 of xen_pt_graphics.c
- fix Cc address for qemu-stable

 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 +0 -0
index 0fe9c0a..474606e 100644
@@ -867,7 +867,7 @@ static void xen_pt_realize(PCIDevice *d, Error **errp)
         }
 
Quoted 5 lines

hw/xen/xen_pt.c static void xen_pt_realize(PCIDevice *d, Error **errp) · line 870

Quoted 3 lines
hw/xen/xen_pt.c +1 -1
         /* 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);

The errp need to be handled here if any error occurs.

Do you mean calling it like this as a supported way to handle an error:

    xen_igd_passthrough_isa_bridge_create(s, &s->real_device, &error_fatal);

IIUC, that would cause Qemu to exit(1) here if there was any error.

I didn't do that because I thought if there was an error one of the parents (pci or qdev) would handle the error appropriately since we are passing 'errp' from xen_pt_realize which I think comes from pci and qdev, but maybe not. I have not tested how an error is handled with this version of the patch and I am certainly no expert in how error handling should be done here, so thanks for alerting me to this question.

I have also seen in the Qemu source the use of local_err and maybe using &error_fatal is something like using a local_err instead of the errp from xen_pt_realize.

I will accept any suggestions from more knowledgeable people about how best to handle the errors here. I can also do some tests by faking an error here and make sure the the error does get handled. I do think if the LPC bridge creation fails it should be a fatal error and if am reading the current code we have correctly, we currently just print a message to stderr if bridge creation fails without doing anything about that error. I also think maybe if for some reason we can't get a revision number for the LPC bridge, maybe that should not be a fatal error.

I will make sure the next version of the patch will not be posted until I have verified the errors are handled appropriately.

Cheers,

Chuck

#6 lore raw

Re: [PATCH v3 1/3] xen/igd: get PCH info from host sysfs

Quoted 54 lines · Chuck Zmudzinski
Quoted 29 lines · Tomita Moeko
Quoted 29 lines

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

Changes in v3:
- whitespace fix at line 380 of xen_pt_graphics.c
- fix Cc address for qemu-stable

 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 +0 -0
index 0fe9c0a..474606e 100644
@@ -867,7 +867,7 @@ static void xen_pt_realize(PCIDevice *d, Error **errp)
         }
 
Quoted 5 lines

hw/xen/xen_pt.c static void xen_pt_realize(PCIDevice *d, Error **errp) · line 870

Quoted 3 lines
hw/xen/xen_pt.c +1 -1
         /* 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);

The errp need to be handled here if any error occurs.

Do you mean calling it like this as a supported way to handle an error:

    xen_igd_passthrough_isa_bridge_create(s, &s->real_device, &error_fatal);

IIUC, that would cause Qemu to exit(1) here if there was any error.

I didn't do that because I thought if there was an error one of the parents (pci or qdev) would handle the error appropriately since we are passing 'errp' from xen_pt_realize which I think comes from pci and qdev, but maybe not. I have not tested how an error is handled with this version of the patch and I am certainly no expert in how error handling should be done here, so thanks for alerting me to this question.

I have also seen in the Qemu source the use of local_err and maybe using &error_fatal is something like using a local_err instead of the errp from xen_pt_realize.

Quoted 9 lines

I will accept any suggestions from more knowledgeable people about how best to handle the errors here. I can also do some tests by faking an error here and make sure the the error does get handled. I do think if the LPC bridge creation fails it should be a fatal error and if am reading the current code we have correctly, we currently just print a message to stderr if bridge creation fails without doing anything about that error. I also think maybe if for some reason we can't get a revision number for the LPC bridge, maybe that should not be a fatal error.

Here I mean, since you've changed the function to use errp, then it should be handled as other function calls in xen_pt_realize() like

    xen_igd_passthrough_isa_bridge_create(s, &s->real_device, errp);
    if (errp) {
        xen_host_pci_device_put(&s->real_device);  // cleanup
        return;
    }

The realized function is called in device_set_realized() with

    dc->realize(dev, &local_err);
    if (local_err != NULL) {
        goto fail;
    }

In your code, if any error occurs, though it contiunes, it would be still treated as a failure. I'm not sure if this failure would have any impact to further steps in xen_pt_realize(), but since it ultimately fails, fail fast is always preferred.

If you think the error can be ignored, then keep using current fprintf() or error_report() would be the best choice.

Thanks,
Moeko

Quoted 6 lines

I will make sure the next version of the patch will not be posted until I have verified the errors are handled appropriately.

Cheers,

Chuck

#7 lore raw

PATCH v3 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

Changes in v3:
- fix Cc address for qemu-stable

 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
#8 lore raw

Re: [PATCH v3 2/3] xen/igd: don't register rom bar twice

Quoted 7 lines · 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")

Please follow the QEMU standard way to reference a commit <at-least-12-digits-of-SHA-commit-id> (“Fixed commit subject”)

https://www.qemu.org/docs/master/devel/submitting-a-patch.html#write-a-meaningful-commit-message

Quoted 35 lines

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

Changes in v3:
- fix Cc address for qemu-stable

 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. */
#9 lore raw

Re: [PATCH v3 2/3] xen/igd: don't register rom bar twice

Quoted 6 lines · Tomita Moeko
Quoted 4 lines · 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.

Quoted 6 lines
Quoted 3 lines

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

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

Please follow the QEMU standard way to reference a commit <at-least-12-digits-of-SHA-commit-id> (“Fixed commit subject”)

OK, I will do that for the next version. Thanks,

Chuck

#10 lore raw

PATCH v3 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

Changes in v3:
- fix Cc address for qemu-stable

 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