Skip to contentSkip to conversation

vfio/pci: match IGD devices in display controller class

PATCH Applied Tomita Moeko 2 participants 3 messages Jan 23, 2025 – Feb 28, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 vfio/pci: match IGD devices in display controller class

IGD device can either expose as a VGA controller or display controller depending on whether it is configured as the primary display device in BIOS. In both cases, the OpRegion may be present. A new helper function vfio_pci_is_intel_display() is introduced to check if the device might be an IGD device.

---
Changelog:
v3:
* Removed BDF condition as Intel discrete GPUs does not have OpRegion
* Added a helper function to match all possible devices with base class
* Renamed from "vfio/pci: update igd matching conditions"

v2:
Fix misuse of pci_get_domain_bus_and_slot(), now only compares bdf without touching device reference count.

 drivers/vfio/pci/vfio_pci.c      | 4 +---
 drivers/vfio/pci/vfio_pci_igd.c  | 6 ++++++
 drivers/vfio/pci/vfio_pci_priv.h | 6 ++++++
 3 files changed, 13 insertions(+), 3 deletions(-)
drivers/vfio/pci/vfio_pci.c +1 -3
index e727941f589d..5f169496376a 100644
@@ -111,9 +111,7 @@ static int vfio_pci_open_device(struct vfio_device *core_vdev)
 	if (ret)
 		return ret;
 
-	if (vfio_pci_is_vga(pdev) &&
-	    pdev->vendor == PCI_VENDOR_ID_INTEL &&
-	    IS_ENABLED(CONFIG_VFIO_PCI_IGD)) {
+	if (vfio_pci_is_intel_display(pdev)) {
 		ret = vfio_pci_igd_init(vdev);
 		if (ret && ret != -ENODEV) {
 			pci_warn(pdev, "Failed to setup Intel IGD regions\n");
drivers/vfio/pci/vfio_pci_igd.c +6 -0
index dd70e2431bd7..ef490a4545f4 100644
@@ -435,6 +435,12 @@ static int vfio_pci_igd_cfg_init(struct vfio_pci_core_device *vdev)
 	return 0;
 }
 
+bool vfio_pci_is_intel_display(struct pci_dev *pdev)
+{
+	return (pdev->vendor == PCI_VENDOR_ID_INTEL) &&
+	       ((pdev->class >> 16) == PCI_BASE_CLASS_DISPLAY);
+}
+
 int vfio_pci_igd_init(struct vfio_pci_core_device *vdev)
 {
 	int ret;
drivers/vfio/pci/vfio_pci_priv.h +6 -0
index 5e4fa69aee16..a9972eacb293 100644
@@ -67,8 +67,14 @@ void vfio_pci_memory_unlock_and_restore(struct vfio_pci_core_device *vdev,
 					u16 cmd);
 
 #ifdef CONFIG_VFIO_PCI_IGD
+bool vfio_pci_is_intel_display(struct pci_dev *pdev);
 int vfio_pci_igd_init(struct vfio_pci_core_device *vdev);
 #else
+static inline bool vfio_pci_is_intel_display(struct pci_dev *pdev)
+{
+	return false;
+}
+
 static inline int vfio_pci_igd_init(struct vfio_pci_core_device *vdev)
 {
 	return -ENODEV;
Signature · 1 line
2.45.2
Reviewed-by on v3 1/1
#1 lore raw
Quoted 30 lines · On Fri, 24 Jan 2025 00:34:15 +0800 Tomita Moeko <[email protected]> wrote:

IGD device can either expose as a VGA controller or display controller depending on whether it is configured as the primary display device in BIOS. In both cases, the OpRegion may be present. A new helper function vfio_pci_is_intel_display() is introduced to check if the device might be an IGD device.

---
Changelog:
v3:
* Removed BDF condition as Intel discrete GPUs does not have OpRegion
* Added a helper function to match all possible devices with base class
* Renamed from "vfio/pci: update igd matching conditions"

v2:
Fix misuse of pci_get_domain_bus_and_slot(), now only compares bdf without touching device reference count.

 drivers/vfio/pci/vfio_pci.c      | 4 +---
 drivers/vfio/pci/vfio_pci_igd.c  | 6 ++++++
 drivers/vfio/pci/vfio_pci_priv.h | 6 ++++++
 3 files changed, 13 insertions(+), 3 deletions(-)
drivers/vfio/pci/vfio_pci.c +0 -0
index e727941f589d..5f169496376a 100644

drivers/vfio/pci/vfio_pci.c static int vfio_pci_open_device(struct vfio_device *core_vdev) · line 114

Quoted 7 lines
drivers/vfio/pci/vfio_pci.c +1 -3
@@ -111,9 +111,7 @@ static int vfio_pci_open_device(struct vfio_device *core_vdev)
 	if (ret)
 		return ret;
 
-	if (vfio_pci_is_vga(pdev) &&
-	    pdev->vendor == PCI_VENDOR_ID_INTEL &&
-	    IS_ENABLED(CONFIG_VFIO_PCI_IGD)) {
+	if (vfio_pci_is_intel_display(pdev)) {

I'd slightly prefer to keep:

    if (vfio_pci_is_intel_display(pdev) &&
        IS_ENABLED(CONFIG_VFIO_PCI_IGD)) {

as otherwise the helper function isn't entirely honest in the implied test. Not a huge deal though, so

Quoted 39 lines
drivers/vfio/pci/vfio_pci.c +0 -0
 		ret = vfio_pci_igd_init(vdev);
 		if (ret && ret != -ENODEV) {
 			pci_warn(pdev, "Failed to setup Intel IGD regions\n");
drivers/vfio/pci/vfio_pci_igd.c +6 -0
index dd70e2431bd7..ef490a4545f4 100644
@@ -435,6 +435,12 @@ static int vfio_pci_igd_cfg_init(struct vfio_pci_core_device *vdev)
 	return 0;
 }
 
+bool vfio_pci_is_intel_display(struct pci_dev *pdev)
+{
+	return (pdev->vendor == PCI_VENDOR_ID_INTEL) &&
+	       ((pdev->class >> 16) == PCI_BASE_CLASS_DISPLAY);
+}
+
 int vfio_pci_igd_init(struct vfio_pci_core_device *vdev)
 {
 	int ret;
drivers/vfio/pci/vfio_pci_priv.h +6 -0
index 5e4fa69aee16..a9972eacb293 100644
@@ -67,8 +67,14 @@ void vfio_pci_memory_unlock_and_restore(struct vfio_pci_core_device *vdev,
 					u16 cmd);
 
 #ifdef CONFIG_VFIO_PCI_IGD
+bool vfio_pci_is_intel_display(struct pci_dev *pdev);
 int vfio_pci_igd_init(struct vfio_pci_core_device *vdev);
 #else
+static inline bool vfio_pci_is_intel_display(struct pci_dev *pdev)
+{
+	return false;
+}
+
 static inline int vfio_pci_igd_init(struct vfio_pci_core_device *vdev)
 {
 	return -ENODEV;
#2 lore raw
In reply to Tomita Moeko
Quoted 8 lines · On Fri, 24 Jan 2025 00:34:15 +0800 Tomita Moeko <[email protected]> wrote:

IGD device can either expose as a VGA controller or display controller depending on whether it is configured as the primary display device in BIOS. In both cases, the OpRegion may be present. A new helper function vfio_pci_is_intel_display() is introduced to check if the device might be an IGD device.

---

Applied to vfio next branch for v6.15. Thanks,

Alex