Skip to contentSkip to conversation

tools: Fix PVH dom0 passthrough with legacy irq

PATCH Superseded Jason Andryuk 3 participants 7 messages Feb 26, 2025 – Feb 28, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover tools: Fix PVH dom0 passthrough with legacy irq

A PCI device may not have a legacy IRQ assigned. This series allows passthrough of such a device to a guest.

It relies on a Linux change to xen-pciback to also handle missing legacy IRQs:
https://lore.kernel.org/xen-devel/[email protected]/T/#u

Jason Andryuk (2):
tools/ctrl: Silence missing GSI in xc_pcidev_get_gsi() tools/libxl: Skip missing PCI GSIs

 tools/libs/ctrl/xc_linux.c   |  3 ++-
 tools/libs/light/libxl_x86.c | 10 ++++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 tools/ctrl: Silence missing GSI in xc_pcidev_get_gsi()

It is valid for a PCI device to not have a legacy IRQ. In that case, do not print an error to keep the lgs clean.

This relies on pciback being updated to return -ENOENT for a missing GSI.

Fixes b93e5981d258 ("tools: Add new function to get gsi from dev")
---
 tools/libs/ctrl/xc_linux.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/libs/ctrl/xc_linux.c +2 -1
index 92591e49a1..c18f09392f 100644
@@ -78,7 +78,8 @@ int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf)
                 IOCTL_PRIVCMD_PCIDEV_GET_GSI, &dev_gsi);
 
     if (ret < 0) {
-        PERROR("Failed to get gsi from dev");
+        if (errno != ENOENT)
+            PERROR("Failed to get gsi from dev");
     } else {
         ret = dev_gsi.gsi;
     }
Signature · 1 line
2.34.1
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] tools/ctrl: Silence missing GSI in xc_pcidev_get_gsi()

Quoted 2 lines · Jason Andryuk

It is valid for a PCI device to not have a legacy IRQ. In that case, do not print an error to keep the lgs clean.

                                 ^ logs?
Quoted 6 lines

This relies on pciback being updated to return -ENOENT for a missing GSI.

Fixes b93e5981d258 ("tools: Add new function to get gsi from dev")
Quoted 9 lines
---
 tools/libs/ctrl/xc_linux.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/libs/ctrl/xc_linux.c +0 -0
index 92591e49a1..c18f09392f 100644

tools/libs/ctrl/xc_linux.c int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf) · line 82

Quoted 6 lines
tools/libs/ctrl/xc_linux.c +2 -1
@@ -78,7 +78,8 @@ int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf)
                 IOCTL_PRIVCMD_PCIDEV_GET_GSI, &dev_gsi);
 
     if (ret < 0) {
-        PERROR("Failed to get gsi from dev");
+        if (errno != ENOENT)
+            PERROR("Failed to get gsi from dev");

Nit: isn't the style of xc_pcidev_get_gsi() wrong? From what I see in this same file and all other files in libs/ctrl it should use the hypervisor coding style.

Thanks, Roger.

#3 lore raw

Re: [PATCH 1/2] tools/ctrl: Silence missing GSI in xc_pcidev_get_gsi()

In reply to Jason Andryuk
Quoted 17 lines · Jason Andryuk

It is valid for a PCI device to not have a legacy IRQ. In that case, do not print an error to keep the lgs clean.

This relies on pciback being updated to return -ENOENT for a missing GSI.

Fixes b93e5981d258 ("tools: Add new function to get gsi from dev")
---
 tools/libs/ctrl/xc_linux.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/libs/ctrl/xc_linux.c +0 -0
index 92591e49a1..c18f09392f 100644

tools/libs/ctrl/xc_linux.c int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf) · line 82

Quoted 6 lines
tools/libs/ctrl/xc_linux.c +2 -1
@@ -78,7 +78,8 @@ int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf)
                 IOCTL_PRIVCMD_PCIDEV_GET_GSI, &dev_gsi);
 
     if (ret < 0) {
-        PERROR("Failed to get gsi from dev");
+        if (errno != ENOENT)
+            PERROR("Failed to get gsi from dev");

While here, could you maybe print the S:B:D:F as part of the error message? (seeing as it's a function parameter).

Thanks, Roger.

#4 lore raw

PATCH 2/2 tools/libxl: Skip missing PCI GSIs

In reply to Jason Andryuk

A PCI device may not have a legacy IRQ. In that case, we don't need to do anything, so don't fail in libxl__arch_hvm_map_gsi() and libxl__arch_hvm_unmap_gsi().

Requires an updated pciback to return -ENOENT.

Fixes f97f885c7198 ("tools: Add new function to do PIRQ (un)map on PVH dom0")
---
 tools/libs/light/libxl_x86.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tools/libs/light/libxl_x86.c +8 -2
index a3164a3077..63208362af 100644
@@ -901,7 +901,10 @@ int libxl__arch_hvm_map_gsi(libxl__gc *gc, uint32_t sbdf, uint32_t domid)
     int pirq = -1, gsi, r;
 
     gsi = xc_pcidev_get_gsi(CTX->xch, sbdf);
-    if (gsi < 0) {
+    if (gsi == -1 && errno == ENOENT) {
+        LOGD(DEBUG, domid, "xc_pcidev_get_gsi no gsi");
+        return 0;
+    } else if (gsi < 0) {
         return ERROR_FAIL;
     }
 
@@ -925,7 +928,10 @@ int libxl__arch_hvm_unmap_gsi(libxl__gc *gc, uint32_t sbdf, uint32_t domid)
     int pirq = -1, gsi, r;
 
     gsi = xc_pcidev_get_gsi(CTX->xch, sbdf);
-    if (gsi < 0) {
+    if (gsi == -1 && errno == ENOENT) {
+        LOGD(DEBUG, domid, "xc_pcidev_get_gsi no gsi");
+        return 0;
+    } else if (gsi < 0) {
         return ERROR_FAIL;
     }
 
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH 2/2] tools/libxl: Skip missing PCI GSIs

Quoted 16 lines · Jason Andryuk
tools/libs/light/libxl_x86.c +4 -1
@@ -901,7 +901,10 @@ int libxl__arch_hvm_map_gsi(libxl__gc *gc, uint32_t sbdf, uint32_t domid)
     int pirq = -1, gsi, r;
 
     gsi = xc_pcidev_get_gsi(CTX->xch, sbdf);
-    if (gsi < 0) {
+    if (gsi == -1 && errno == ENOENT) {
+        LOGD(DEBUG, domid, "xc_pcidev_get_gsi no gsi");
+        return 0;
+    } else if (gsi < 0) {
         return ERROR_FAIL;
     }
 
@@ -925,7 +928,10 @@ int libxl__arch_hvm_unmap_gsi(libxl__gc *gc, uint32_t sbdf, uint32_t domid)
     int pirq = -1, gsi, r;

tools/libs/light/libxl_x86.c int libxl__arch_hvm_unmap_gsi(libxl__gc *gc, uint32_t sbdf, uint32_t domid) · line 937

Quoted 10 lines
tools/libs/light/libxl_x86.c +4 -1
 
     gsi = xc_pcidev_get_gsi(CTX->xch, sbdf);
-    if (gsi < 0) {
+    if (gsi == -1 && errno == ENOENT) {
+        LOGD(DEBUG, domid, "xc_pcidev_get_gsi no gsi");
+        return 0;
+    } else if (gsi < 0) {
         return ERROR_FAIL;
     }
 

Why the special-casing of the value -1?

Jan

#6 lore raw

Re: [PATCH 2/2] tools/libxl: Skip missing PCI GSIs

Quoted 7 lines · Jan Beulich
Quoted 6 lines · Jason Andryuk
tools/libs/light/libxl_x86.c +0 -0
@@ -925,7 +928,10 @@ int libxl__arch_hvm_unmap_gsi(libxl__gc *gc, uint32_t sbdf, uint32_t domid)
      int pirq = -1, gsi, r;
 
Quoted 11 lines

tools/libs/light/libxl_x86.c int libxl__arch_hvm_map_gsi(libxl__gc *gc, uint32_t sbdf, uint32_t domid) · line 910

Quoted 9 lines
tools/libs/light/libxl_x86.c +4 -1
      gsi = xc_pcidev_get_gsi(CTX->xch, sbdf);
-    if (gsi < 0) {
+    if (gsi == -1 && errno == ENOENT) {
+        LOGD(DEBUG, domid, "xc_pcidev_get_gsi no gsi");
+        return 0;
+    } else if (gsi < 0) {
          return ERROR_FAIL;
      }
 

Why the special-casing of the value -1?

No good reason. I'll restore it to < 0. I originally thought xc_pcidev_get_gsi() was returning -errno in gsi. That was not the case.

Regards,
Jason