Skip to contentSkip to conversation

vfio/pci: update igd matching conditions

PATCH Superseded Tomita Moeko 2 participants 3 messages Dec 29, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfio/pci: update igd matching conditions

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. Also checks if the device is at bdf 00:02.0 to avoid setting up igd-specific regions on Intel discrete GPUs.

---
 drivers/vfio/pci/vfio_pci.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/vfio/pci/vfio_pci.c +4 -2
index e727941f589d..051ef4ad3f43 100644
@@ -111,9 +111,11 @@ static int vfio_pci_open_device(struct vfio_device *core_vdev)
 	if (ret)
 		return ret;
 
-	if (vfio_pci_is_vga(pdev) &&
+	if (IS_ENABLED(CONFIG_VFIO_PCI_IGD) &&
 	    pdev->vendor == PCI_VENDOR_ID_INTEL &&
-	    IS_ENABLED(CONFIG_VFIO_PCI_IGD)) {
+	    ((pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA ||
+	     (pdev->class >> 8) == PCI_CLASS_DISPLAY_OTHER) &&
+	    pdev == pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(2, 0))) {
 		ret = vfio_pci_igd_init(vdev);
 		if (ret && ret != -ENODEV) {
 			pci_warn(pdev, "Failed to setup Intel IGD regions\n");
Signature · 1 line
2.45.2
#1 lore raw
Quoted 16 lines · On Sun, 29 Dec 2024 23:51:40 +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. Also checks if the device is at bdf 00:02.0 to avoid setting up igd-specific regions on Intel discrete GPUs.

---
 drivers/vfio/pci/vfio_pci.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/vfio/pci/vfio_pci.c +0 -0
index e727941f589d..051ef4ad3f43 100644

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

Quoted 8 lines
drivers/vfio/pci/vfio_pci.c +2 -2
@@ -111,9 +111,11 @@ static int vfio_pci_open_device(struct vfio_device *core_vdev)
 	if (ret)
 		return ret;
 
-	if (vfio_pci_is_vga(pdev) &&
+	if (IS_ENABLED(CONFIG_VFIO_PCI_IGD) &&
 	    pdev->vendor == PCI_VENDOR_ID_INTEL &&
-	    IS_ENABLED(CONFIG_VFIO_PCI_IGD)) {
+	    ((pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA ||

The above is vfio_pci_is_vga(pdev), maybe below should have a similar helper.

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

Quoted 2 lines
drivers/vfio/pci/vfio_pci.c +2 -0
+	     (pdev->class >> 8) == PCI_CLASS_DISPLAY_OTHER) &&
+	    pdev == pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(2, 0))) {

This increments the reference count on the device:

* Given a PCI domain, bus, and slot/function number, the desired PCI
* device is located in the list of PCI devices. If the device is
* found, its reference count is increased and this function returns a
* pointer to its data structure. The caller must decrement the
* reference count by calling pci_dev_put().

Quoted 3 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");
#2 lore raw
Quoted 22 lines · Alex Williamson
Quoted 19 lines · On Sun, 29 Dec 2024 23:51:40 +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. Also checks if the device is at bdf 00:02.0 to avoid setting up igd-specific regions on Intel discrete GPUs.

---
 drivers/vfio/pci/vfio_pci.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/vfio/pci/vfio_pci.c +0 -0
index e727941f589d..051ef4ad3f43 100644
@@ -111,9 +111,11 @@ static int vfio_pci_open_device(struct vfio_device *core_vdev)
 	if (ret)
 		return ret;
 
Quoted 8 lines

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

Quoted 5 lines
drivers/vfio/pci/vfio_pci.c +2 -2
-	if (vfio_pci_is_vga(pdev) &&
+	if (IS_ENABLED(CONFIG_VFIO_PCI_IGD) &&
 	    pdev->vendor == PCI_VENDOR_ID_INTEL &&
-	    IS_ENABLED(CONFIG_VFIO_PCI_IGD)) {
+	    ((pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA ||

The above is vfio_pci_is_vga(pdev), maybe below should have a similar helper.

There isn't, shall I create a new helper function? or just keep it as the match only happens here.

Quoted 10 lines

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

Quoted 2 lines
drivers/vfio/pci/vfio_pci.c +2 -0
+	     (pdev->class >> 8) == PCI_CLASS_DISPLAY_OTHER) &&
+	    pdev == pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(2, 0))) {

This increments the reference count on the device:

* Given a PCI domain, bus, and slot/function number, the desired PCI
* device is located in the list of PCI devices. If the device is
* found, its reference count is increased and this function returns a
* pointer to its data structure. The caller must decrement the
* reference count by calling pci_dev_put().

Sorry I missed that, will fix in v2.

Quoted 4 lines
Quoted 3 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");