Skip to contentSkip to conversation

vfio/pci: update igd matching conditions

PATCH In review Tomita Moeko 2 participants 3 messages Dec 30, 2024 – Jan 4, 2025

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

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

---
Changelog:
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 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/vfio/pci/vfio_pci.c +5 -3
index e727941f589d..906a1db46d15 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) &&
-	    pdev->vendor == PCI_VENDOR_ID_INTEL &&
-	    IS_ENABLED(CONFIG_VFIO_PCI_IGD)) {
+	if (IS_ENABLED(CONFIG_VFIO_PCI_IGD) &&
+	    (pdev->vendor == PCI_VENDOR_ID_INTEL) &&
+	    (((pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA) ||
+	     ((pdev->class >> 8) == PCI_CLASS_DISPLAY_OTHER)) &&
+	    (pci_dev_id(pdev) == PCI_DEVID(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 23 lines · On Tue, 31 Dec 2024 00:10:54 +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.

---
Changelog:
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 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/vfio/pci/vfio_pci.c +0 -0
index e727941f589d..906a1db46d15 100644
@@ -111,9 +111,11 @@ static int vfio_pci_open_device(struct vfio_device *core_vdev)
 	if (ret)

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

Quoted 10 lines
drivers/vfio/pci/vfio_pci.c +5 -3
 		return ret;
 
-	if (vfio_pci_is_vga(pdev) &&
-	    pdev->vendor == PCI_VENDOR_ID_INTEL &&
-	    IS_ENABLED(CONFIG_VFIO_PCI_IGD)) {
+	if (IS_ENABLED(CONFIG_VFIO_PCI_IGD) &&
+	    (pdev->vendor == PCI_VENDOR_ID_INTEL) &&
+	    (((pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA) ||
+	     ((pdev->class >> 8) == PCI_CLASS_DISPLAY_OTHER)) &&
+	    (pci_dev_id(pdev) == PCI_DEVID(0, PCI_DEVFN(2, 0)))) {

Sorry I wasn't available to reply on previous thread before v2 was posted, but given that we have vfio_pci_is_vga() we should use it rather than duplicate the contents. I think that suggests we should create a similar helper for display_other. Alternatively we should maybe consider if it's sufficient to use just the base class.

The DEVID of course does not include the domain, which make it a rather suspect check already. What do the discrete cards report at 0xfc in config space? If it's zero or -1 or points to something that we can't memremap() or points to contents that doesn't include the opregion signature, then we'll already exit out of vfio_pci_igd_init(). Is there actually a case that we're actually configuring IGD specific regions for a discrete card? Thanks,

Alex

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 28 lines · Alex Williamson
Quoted 25 lines · On Tue, 31 Dec 2024 00:10:54 +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.

---
Changelog:
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 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/vfio/pci/vfio_pci.c +0 -0
index e727941f589d..906a1db46d15 100644
@@ -111,9 +111,11 @@ static int vfio_pci_open_device(struct vfio_device *core_vdev)
 	if (ret)
 		return ret;
 
Quoted 14 lines

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

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

Sorry I wasn't available to reply on previous thread before v2 was posted, but given that we have vfio_pci_is_vga() we should use it rather than duplicate the contents. I think that suggests we should create a similar helper for display_other. Alternatively we should maybe consider if it's sufficient to use just the base class.

I think using the base class is okay here. AFAIK intel doesn't has any devices reported as XGA or 3D controller.

Quoted 9 lines

The DEVID of course does not include the domain, which make it a rather suspect check already. What do the discrete cards report at 0xfc in config space? If it's zero or -1 or points to something that we can't memremap() or points to contents that doesn't include the opregion signature, then we'll already exit out of vfio_pci_igd_init(). Is there actually a case that we're actually configuring IGD specific regions for a discrete card? Thanks,

Alex

Checking (pci_domain_nr(pdev->bus) == 0) seems okay. I tried on a discrate Arc A770, there is 0 at 0xFC, so vfio_pci_igd_init() returns with -NODEV and the device is skipped. Shall I remove the BDF check? It seems to be unnecessary, my intention is to ensure it is really an igd since it can only be at 0000:00:02.0.

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");