Skip to contentSkip to conversation

vfio/igd: Fix incorrect error propagation in vfio_pci_igd_opregion_detect()

PATCH Applied Tomita Moeko 4 participants 5 messages May 22, 2025 – May 27, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 vfio/igd: Fix incorrect error propagation in vfio_pci_igd_opregion_detect()

In vfio_pci_igd_opregion_detect(), errp will be set when the device does not have OpRegion or is hotplugged. This errp will be propagated to pci_qdev_realize(), which interprets it as failure, causing unexpected termination on devices without OpRegion like SR-IOV VFs or discrete GPUs. Fix it by not setting errp in vfio_pci_igd_opregion_detect().

This patch also checks if the device has OpRegion before hotplug status to prevent unwanted warning messages on non-IGD devices.

Fixes c0273e77f2d7 ("vfio/igd: Detect IGD device by OpRegion")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2968

---
v2:
* Add Tested-by from Edmund Raile. Thanks for the contribution.
* Rebased on vfio-next
* Fix typos.

 hw/vfio/igd.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
hw/vfio/igd.c +10 -12
index 5b6341c5bf..e7a9d1ffc1 100644
@@ -187,23 +187,21 @@ static bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev,
 }
 
 static bool vfio_pci_igd_opregion_detect(VFIOPCIDevice *vdev,
-                                         struct vfio_region_info **opregion,
-                                         Error **errp)
+                                         struct vfio_region_info **opregion)
 {
     int ret;
 
-    /* Hotplugging is not supported for opregion access */
-    if (vdev->pdev.qdev.hotplugged) {
-        error_setg(errp, "IGD OpRegion is not supported on hotplugged device");
-        return false;
-    }
-
     ret = vfio_device_get_region_info_type(&vdev->vbasedev,
                     VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL,
                     VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION, opregion);
     if (ret) {
-        error_setg_errno(errp, -ret,
-                         "Device does not support IGD OpRegion feature");
+        return false;
+    }
+
+    /* Hotplugging is not supported for opregion access */
+    if (vdev->pdev.qdev.hotplugged) {
+        warn_report("IGD device detected, but OpRegion is not supported "
+                    "on hotplugged device.");
         return false;
     }
 
@@ -524,7 +522,7 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
     }
 
     /* IGD device always comes with OpRegion */
-    if (!vfio_pci_igd_opregion_detect(vdev, &opregion, errp)) {
+    if (!vfio_pci_igd_opregion_detect(vdev, &opregion)) {
         return true;
     }
     info_report("OpRegion detected on Intel display %x.", vdev->device_id);
@@ -695,7 +693,7 @@ static bool vfio_pci_kvmgt_config_quirk(VFIOPCIDevice *vdev, Error **errp)
         return true;
     }
 
-    if (!vfio_pci_igd_opregion_detect(vdev, &opregion, errp)) {
+    if (!vfio_pci_igd_opregion_detect(vdev, &opregion)) {
         /* Should never reach here, KVMGT always emulates OpRegion */
         return false;
     }
Signature · 1 line
2.47.2
#1 lore raw
Quoted 15 lines · Tomita Moeko

In vfio_pci_igd_opregion_detect(), errp will be set when the device does not have OpRegion or is hotplugged. This errp will be propagated to pci_qdev_realize(), which interprets it as failure, causing unexpected termination on devices without OpRegion like SR-IOV VFs or discrete GPUs. Fix it by not setting errp in vfio_pci_igd_opregion_detect().

This patch also checks if the device has OpRegion before hotplug status to prevent unwanted warning messages on non-IGD devices.

Fixes c0273e77f2d7 ("vfio/igd: Detect IGD device by OpRegion")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2968

Quoted 5 lines

---
v2:
* Add Tested-by from Edmund Raile. Thanks for the contribution.
* Rebased on vfio-next
* Fix typos.

Edmund, Alex,

Could you please send a R-b ?

Thanks,

C.

Quoted 57 lines
  hw/vfio/igd.c | 22 ++++++++++------------
  1 file changed, 10 insertions(+), 12 deletions(-)
hw/vfio/igd.c +10 -12
index 5b6341c5bf..e7a9d1ffc1 100644
@@ -187,23 +187,21 @@ static bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev,
  }
 
  static bool vfio_pci_igd_opregion_detect(VFIOPCIDevice *vdev,
-                                         struct vfio_region_info **opregion,
-                                         Error **errp)
+                                         struct vfio_region_info **opregion)
  {
      int ret;
 
-    /* Hotplugging is not supported for opregion access */
-    if (vdev->pdev.qdev.hotplugged) {
-        error_setg(errp, "IGD OpRegion is not supported on hotplugged device");
-        return false;
-    }
-
      ret = vfio_device_get_region_info_type(&vdev->vbasedev,
                      VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL,
                      VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION, opregion);
      if (ret) {
-        error_setg_errno(errp, -ret,
-                         "Device does not support IGD OpRegion feature");
+        return false;
+    }
+
+    /* Hotplugging is not supported for opregion access */
+    if (vdev->pdev.qdev.hotplugged) {
+        warn_report("IGD device detected, but OpRegion is not supported "
+                    "on hotplugged device.");
          return false;
      }
 
@@ -524,7 +522,7 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
      }
 
      /* IGD device always comes with OpRegion */
-    if (!vfio_pci_igd_opregion_detect(vdev, &opregion, errp)) {
+    if (!vfio_pci_igd_opregion_detect(vdev, &opregion)) {
          return true;
      }
      info_report("OpRegion detected on Intel display %x.", vdev->device_id);
@@ -695,7 +693,7 @@ static bool vfio_pci_kvmgt_config_quirk(VFIOPCIDevice *vdev, Error **errp)
          return true;
      }
 
-    if (!vfio_pci_igd_opregion_detect(vdev, &opregion, errp)) {
+    if (!vfio_pci_igd_opregion_detect(vdev, &opregion)) {
          /* Should never reach here, KVMGT always emulates OpRegion */
          return false;
      }
Reviewed-by on v2 1/1
#2 lore raw
In reply to Tomita Moeko
Quoted 79 lines · Tomita Moeko

CAUTION: External Email!!
In vfio_pci_igd_opregion_detect(), errp will be set when the device does not have OpRegion or is hotplugged. This errp will be propagated to pci_qdev_realize(), which interprets it as failure, causing unexpected termination on devices without OpRegion like SR-IOV VFs or discrete GPUs. Fix it by not setting errp in vfio_pci_igd_opregion_detect().

This patch also checks if the device has OpRegion before hotplug status to prevent unwanted warning messages on non-IGD devices.

Fixes c0273e77f2d7 ("vfio/igd: Detect IGD device by OpRegion")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2968

Link:
https://nospamproxywebp.beckhoff.com/enQsig/link?id=BAgAAAAj8c-WONVzfKgAAADmRaWv_N_avwh8a-Dl3O4H3pR965lOOKR-43wVWf50WdSoe9B4Wv2fq8emKTcbeXye68bbantO4fwl6q0bN5NRQx16YrOybz2CuWJTyfpKjJ5YwhtHz96quiRzGwAIYA3dUXP76q7AcPyJ5yJJ4os6LN0ddEHmY1m2Y6IweyOwr341q60D6Ep7ynj0HljuwgLLta9dAkT9AgX10Br9Ji37_26kU2LxvGQ1

---
v2:
* Add Tested-by from Edmund Raile. Thanks for the contribution.
* Rebased on vfio-next
* Fix typos.

 hw/vfio/igd.c | 22 ++++++++++------------

 1 file changed, 10 insertions(+), 12 deletions(-)
hw/vfio/igd.c +0 -0
index 5b6341c5bf..e7a9d1ffc1 100644
@@ -187,23 +187,21 @@ static bool vfio_pci_igd_opregion_init(VFIOPCIDevice
 *vdev,
  }


 static bool vfio_pci_igd_opregion_detect(VFIOPCIDevice *vdev,
-                                         struct vfio_region_info **opregion, -                                         Error **errp)
+                                         struct vfio_region_info **opregion) {
     int ret;

-    /* Hotplugging is not supported for opregion access */
-    if (vdev->pdev.qdev.hotplugged) {
-        error_setg(errp, "IGD OpRegion is not supported on hotplugged device");
-        return false;
-    }
-
     ret = vfio_device_get_region_info_type(&vdev->vbasedev, VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL, VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION, opregion); if (ret) {
-        error_setg_errno(errp, -ret,
-                         "Device does not support IGD OpRegion feature"); +        return false;
+    }
+
+    /* Hotplugging is not supported for opregion access */
+    if (vdev->pdev.qdev.hotplugged) {
+        warn_report("IGD device detected, but OpRegion is not supported " +                    "on hotplugged device.");
         return false;
     }

hw/vfio/igd.c +0 -0
@@ -524,7 +522,7 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev,
 Error **errp)
      }


     /* IGD device always comes with OpRegion */
-    if (!vfio_pci_igd_opregion_detect(vdev, &opregion, errp)) { +    if (!vfio_pci_igd_opregion_detect(vdev, &opregion)) { return true;
     }
     info_report("OpRegion detected on Intel display %x.", vdev->device_id);

hw/vfio/igd.c +0 -0
@@ -695,7 +693,7 @@ static bool vfio_pci_kvmgt_config_quirk(VFIOPCIDevice
 *vdev, Error **errp)
          return true;
      }
Quoted 6 lines


-    if (!vfio_pci_igd_opregion_detect(vdev, &opregion, errp)) { +    if (!vfio_pci_igd_opregion_detect(vdev, &opregion)) { /* Should never reach here, KVMGT always emulates OpRegion */ return false;
     }

Signature · 2 lines
Kind regards,
Corvin
#3 lore raw
In reply to Tomita Moeko
Quoted 15 lines · Tomita Moeko

In vfio_pci_igd_opregion_detect(), errp will be set when the device does not have OpRegion or is hotplugged. This errp will be propagated to pci_qdev_realize(), which interprets it as failure, causing unexpected termination on devices without OpRegion like SR-IOV VFs or discrete GPUs. Fix it by not setting errp in vfio_pci_igd_opregion_detect().

This patch also checks if the device has OpRegion before hotplug status to prevent unwanted warning messages on non-IGD devices.

Fixes c0273e77f2d7 ("vfio/igd: Detect IGD device by OpRegion")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2968

Quoted 9 lines

---
v2:
* Add Tested-by from Edmund Raile. Thanks for the contribution.
* Rebased on vfio-next
* Fix typos.

  hw/vfio/igd.c | 22 ++++++++++------------
  1 file changed, 10 insertions(+), 12 deletions(-)

Applied to vfio-next.

Thanks,

C.

Reviewed-by on v2 1/1
#4 lore raw
In reply to Tomita Moeko
Quoted 70 lines · On Thu, 22 May 2025 23:16:36 +0800 Tomita Moeko <[email protected]> wrote:

In vfio_pci_igd_opregion_detect(), errp will be set when the device does not have OpRegion or is hotplugged. This errp will be propagated to pci_qdev_realize(), which interprets it as failure, causing unexpected termination on devices without OpRegion like SR-IOV VFs or discrete GPUs. Fix it by not setting errp in vfio_pci_igd_opregion_detect().

This patch also checks if the device has OpRegion before hotplug status to prevent unwanted warning messages on non-IGD devices.

Fixes c0273e77f2d7 ("vfio/igd: Detect IGD device by OpRegion")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2968

---
v2:
* Add Tested-by from Edmund Raile. Thanks for the contribution.
* Rebased on vfio-next
* Fix typos.

 hw/vfio/igd.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
hw/vfio/igd.c +9 -11
index 5b6341c5bf..e7a9d1ffc1 100644
@@ -187,23 +187,21 @@ static bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev,
 }
 
 static bool vfio_pci_igd_opregion_detect(VFIOPCIDevice *vdev,
-                                         struct vfio_region_info **opregion,
-                                         Error **errp)
+                                         struct vfio_region_info **opregion)
 {
     int ret;
 
-    /* Hotplugging is not supported for opregion access */
-    if (vdev->pdev.qdev.hotplugged) {
-        error_setg(errp, "IGD OpRegion is not supported on hotplugged device");
-        return false;
-    }
-
     ret = vfio_device_get_region_info_type(&vdev->vbasedev,
                     VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL,
                     VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION, opregion);
     if (ret) {
-        error_setg_errno(errp, -ret,
-                         "Device does not support IGD OpRegion feature");
+        return false;
+    }
+
+    /* Hotplugging is not supported for opregion access */
+    if (vdev->pdev.qdev.hotplugged) {
+        warn_report("IGD device detected, but OpRegion is not supported "
+                    "on hotplugged device.");
         return false;
     }
 
@@ -524,7 +522,7 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
     }
 
     /* IGD device always comes with OpRegion */
-    if (!vfio_pci_igd_opregion_detect(vdev, &opregion, errp)) {
+    if (!vfio_pci_igd_opregion_detect(vdev, &opregion)) {
         return true;
     }
     info_report("OpRegion detected on Intel display %x.", vdev->device_id);

hw/vfio/igd.c static bool vfio_pci_kvmgt_config_quirk(VFIOPCIDevice *vdev, Error **errp) · line 699

Quoted 8 lines
hw/vfio/igd.c +1 -1
@@ -695,7 +693,7 @@ static bool vfio_pci_kvmgt_config_quirk(VFIOPCIDevice *vdev, Error **errp)
         return true;
     }
 
-    if (!vfio_pci_igd_opregion_detect(vdev, &opregion, errp)) {
+    if (!vfio_pci_igd_opregion_detect(vdev, &opregion)) {
         /* Should never reach here, KVMGT always emulates OpRegion */
         return false;
     }

LGTM