Skip to contentSkip to conversation

libxl+hvmloader: extend IGD check part 2

PATCH In review Marek Marczykowski-Górecki 4 participants 7 messages Apr 8, 2025 – May 21, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl+hvmloader: extend IGD check part 2

Consider also "Display controller" an IGD, not only "VGA compatible controller" in few more places.

Fixes 4191619e0893 ("libxl: extend IGD check")

---
Do you prefer this to be split into two patches (libxl, hvmloader)?

 tools/firmware/hvmloader/pci.c | 1 +
 tools/libs/light/libxl_pci.c   | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
tools/firmware/hvmloader/pci.c +1 -0
index c3c61ca060a6..1ee97a5b4b20 100644
@@ -173,6 +173,7 @@ void pci_setup(void)
         switch ( class )
         {
         case 0x0300:
+        case 0x0380:
             /* If emulated VGA is found, preserve it as primary VGA. */
             if ( (vendor_id == 0x1234) && (device_id == 0x1111) )
             {
tools/libs/light/libxl_pci.c +2 -1
index 1647fd6f4756..db1299832cce 100644
@@ -2575,7 +2575,8 @@ int libxl__grant_vga_iomem_permission(libxl__gc *gc, const uint32_t domid,
 
         if (sysfs_dev_get_class(gc, pci, &pci_device_class))
             continue;
-        if (pci_device_class != 0x030000) /* VGA class */
+        if (pci_device_class != 0x030000 && /* VGA class */
+                pci_device_class != 0x038000) /* Display class */
             continue;
 
         stubdom_domid = libxl_get_stubdom_id(CTX, domid);
Signature · 1 line
2.48.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Marek Marczykowski-Górecki

Consider also "Display controller" an IGD, not only "VGA compatible controller" in few more places.

Fixes 4191619e0893 ("libxl: extend IGD check")

---
Do you prefer this to be split into two patches (libxl, hvmloader)?

Probably not for something this trivial.

Quoted 10 lines
 tools/firmware/hvmloader/pci.c | 1 +
 tools/libs/light/libxl_pci.c   | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
tools/firmware/hvmloader/pci.c +0 -0
index c3c61ca060a6..1ee97a5b4b20 100644

tools/firmware/hvmloader/pci.c void pci_setup(void) · line 176

Quoted 4 lines
tools/firmware/hvmloader/pci.c +1 -0
@@ -173,6 +173,7 @@ void pci_setup(void)
         switch ( class )
         {
         case 0x0300:
+        case 0x0380:

Now we've got multiple, we should have /* VGA */ and /* Display */ comments like libxl has.

Can fix on commit.

#2 lore raw
Quoted 29 lines · Andrew Cooper
Quoted 7 lines · Marek Marczykowski-Górecki

Consider also "Display controller" an IGD, not only "VGA compatible controller" in few more places.

Fixes 4191619e0893 ("libxl: extend IGD check")

---
Do you prefer this to be split into two patches (libxl, hvmloader)?

Probably not for something this trivial.

Quoted 10 lines
 tools/firmware/hvmloader/pci.c | 1 +
 tools/libs/light/libxl_pci.c   | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
tools/firmware/hvmloader/pci.c +0 -0
index c3c61ca060a6..1ee97a5b4b20 100644

tools/firmware/hvmloader/pci.c void pci_setup(void) · line 176

Quoted 4 lines
tools/firmware/hvmloader/pci.c +1 -0
@@ -173,6 +173,7 @@ void pci_setup(void)
         switch ( class )
         {
         case 0x0300:
+        case 0x0380:

Now we've got multiple, we should have /* VGA */ and /* Display */ comments like libxl has.

Quoted 1 line

Can fix on commit.

Fine with me, thanks!

Quoted 1 line
Signature · 3 lines
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
#3 lore raw
In reply to Marek Marczykowski-Górecki

tools/libs/light/libxl_pci.c int libxl__grant_vga_iomem_permission(libxl__gc *gc, const uint32_t domid, · line 2579

Quoted 9 lines · Marek Marczykowski-Górecki
tools/libs/light/libxl_pci.c +2 -1
@@ -2575,7 +2575,8 @@ int libxl__grant_vga_iomem_permission(libxl__gc *gc, const uint32_t domid,
 
         if (sysfs_dev_get_class(gc, pci, &pci_device_class))
             continue;
-        if (pci_device_class != 0x030000) /* VGA class */
+        if (pci_device_class != 0x030000 && /* VGA class */
+                pci_device_class != 0x038000) /* Display class */

Nit: Indentation looks suspicious here (can likely also be adjusted while committing).

Jan

#4 lore raw
In reply to Marek Marczykowski-Górecki

tools/firmware/hvmloader/pci.c void pci_setup(void) · line 179

Quoted 10 lines · Marek Marczykowski-Górecki
tools/firmware/hvmloader/pci.c +1 -0
@@ -173,6 +173,7 @@ void pci_setup(void)
         switch ( class )
         {
         case 0x0300:
+        case 0x0380:
             /* If emulated VGA is found, preserve it as primary VGA. */
             if ( (vendor_id == 0x1234) && (device_id == 0x1111) )
             {

Unlike here, where vendor IDs are subsequently checked (and the sole question that arises is whether any of the combinations can actually come as Display rather than VGA), ...

tools/libs/light/libxl_pci.c int libxl__grant_vga_iomem_permission(libxl__gc *gc, const uint32_t domid, · line 2580

Quoted 10 lines
tools/libs/light/libxl_pci.c +2 -1
@@ -2575,7 +2575,8 @@ int libxl__grant_vga_iomem_permission(libxl__gc *gc, const uint32_t domid,
 
         if (sysfs_dev_get_class(gc, pci, &pci_device_class))
             continue;
-        if (pci_device_class != 0x030000) /* VGA class */
+        if (pci_device_class != 0x030000 && /* VGA class */
+                pci_device_class != 0x038000) /* Display class */
             continue;

... there's no such checking here, and instead very much VGA-specific things are being done then. Is that really in line with permitting Display class devices here as well?

Jan

#5 lore raw
Quoted 20 lines · Jan Beulich

tools/firmware/hvmloader/pci.c void pci_setup(void) · line 179

Quoted 10 lines · Marek Marczykowski-Górecki
tools/firmware/hvmloader/pci.c +1 -0
@@ -173,6 +173,7 @@ void pci_setup(void)
         switch ( class )
         {
         case 0x0300:
+        case 0x0380:
             /* If emulated VGA is found, preserve it as primary VGA. */
             if ( (vendor_id == 0x1234) && (device_id == 0x1111) )
             {

Unlike here, where vendor IDs are subsequently checked (and the sole question that arises is whether any of the combinations can actually come as Display rather than VGA), ...

Quoted 4 lines
tools/libs/light/libxl_pci.c +0 -0
@@ -2575,7 +2575,8 @@ int libxl__grant_vga_iomem_permission(libxl__gc *gc, const uint32_t domid,
 
Quoted 10 lines

tools/libs/light/libxl_pci.c int libxl__grant_vga_iomem_permission(libxl__gc *gc, const uint32_t domid, · line 2580

Quoted 6 lines
tools/libs/light/libxl_pci.c +2 -1
         if (sysfs_dev_get_class(gc, pci, &pci_device_class))
             continue;
-        if (pci_device_class != 0x030000) /* VGA class */
+        if (pci_device_class != 0x030000 && /* VGA class */
+                pci_device_class != 0x038000) /* Display class */
             continue;

... there's no such checking here, and instead very much VGA-specific things are being done then. Is that really in line with permitting Display class devices here as well?

Well, it was necessary to get IGD passthrough working. But I think upstream Xen still doesn't have all the pieces here. Specifically, Qubes's version includes (a variant of)
https://lore.kernel.org/xen-devel/87d74a21bde95cfc7c53fad56bf8f0e47724953e.1592171394.git.gorbak25@gmail.com/T/#m8644141760ee36d691434dfaf55031110492929b
and that adds here access not only to the video memory, but also vbios, which was needed to get it working.

Anyway, this code is reachable only if gfx_passthrou is enabled and currently this option is specific to IGD.

Signature · 3 lines
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
Acked-by on v1 1/1
#6 lore raw
In reply to Marek Marczykowski-Górecki
Quoted 29 lines · Marek Marczykowski-Górecki

Consider also "Display controller" an IGD, not only "VGA compatible controller" in few more places.

Fixes 4191619e0893 ("libxl: extend IGD check")

---
Do you prefer this to be split into two patches (libxl, hvmloader)?

 tools/firmware/hvmloader/pci.c | 1 +
 tools/libs/light/libxl_pci.c   | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
tools/firmware/hvmloader/pci.c +1 -0
index c3c61ca060a6..1ee97a5b4b20 100644
@@ -173,6 +173,7 @@ void pci_setup(void)
         switch ( class )
         {
         case 0x0300:
+        case 0x0380:
             /* If emulated VGA is found, preserve it as primary VGA. */
             if ( (vendor_id == 0x1234) && (device_id == 0x1111) )
             {
tools/libs/light/libxl_pci.c +0 -0
index 1647fd6f4756..db1299832cce 100644

tools/libs/light/libxl_pci.c int libxl__grant_vga_iomem_permission(libxl__gc *gc, const uint32_t domid, · line 2579

Quoted 6 lines
tools/libs/light/libxl_pci.c +2 -1
@@ -2575,7 +2575,8 @@ int libxl__grant_vga_iomem_permission(libxl__gc *gc, const uint32_t domid,
 
         if (sysfs_dev_get_class(gc, pci, &pci_device_class))
             continue;
-        if (pci_device_class != 0x030000) /* VGA class */
+        if (pci_device_class != 0x030000 && /* VGA class */
+                pci_device_class != 0x038000) /* Display class */

According to some not too random document on internet [1][2], the whole 0x03 would be the display class, with 0x0380 been other display controller. So it might be better to change the new comment to "Other display controller".

[1] https://pcisig.com/sites/default/files/files/PCI_Code-ID_r_1_12__v9_Jan_2020.pdf
[2] https://wiki.osdev.org/PCI#Class_Codes

Otherwise, change looks fine to me:

Thanks,

Signature · 1 line
Anthony PERARD