[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] tools/libxl: Skip invalid IRQs


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jason Andryuk <jason.andryuk@xxxxxxx>
  • Date: Mon, 7 Apr 2025 15:26:41 -0400
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pCKz0lPWiKqv7wZcTdrkgrcxezT+4JYBMlY1rOyPxAQ=; b=tIAEdccxbtL0P8geGXPSR7QKk1DtAs6r+n5hfzgEsqar1Xu6KEmp91QGonwF6dw8eHgaCPpjwjotBvltZB0Oq2s4qTKmKpDenbwdnhhjWLQXcNWC2YRQYpt2vpSuMVwHY6+t2YAvEAL5gU11JcjnBFFj6yBu8220jUYJ/6sl4MgZO+JShKwAeXnKFy0piA56z74v98KuiicaN1vg1DzrW1zmlnb2OAOvuLHVEAD52fKZaR4fd3g2pUf5oQh6a2b8iPtHNiQkP1I2xi/jAzTuCdco5LTX92pIhG3Xkp4XWhQR/qFeCfIvcAd/IGrITXQgfUv0MBT2l7yYOQObgszIqw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Yd4JHOipIFqCUCJrpbacXwzc4Krg5a/mBJ+e4hYHWEaDzx12uw9PnwIpKNuY32C3Cv4N0XO/GTHs4MKZmI24POT7iF9cpl8y0Ir99ONOsBZ9d4lRRUWSRzkX9ms46aFkPI8TzoFU+5EcDdOxEWCdqxR0IJFaOLjCdmpBUKWDyg7/Cl9U17HUcIXbTzSyx/rNdnCgs0/n2r186ttMKrFtMnO29x3s+DN2ar+ITf4dr06dlAgu42O7YlA2lu2Xa67jRafVVJUVioj/s0BIbILTjz5lQtcUuemge3QUYEDedS+3AfiMMRfyLNFHwuRp0GzUXT5W8Zlo3xoWDUw2TGS/kw==
  • Cc: Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>, Jason Andryuk <jason.andryuk@xxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>
  • Delivery-date: Mon, 07 Apr 2025 19:26:59 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

A PCI device's irq field is an 8-bit number.  A value of 0xff indicates
that the device is not connected.  Additionally, the Linux ACPI code can
convert these 0xff values to IRQ_NOTCONNECTED(0x80000000) because
"0x80000000 is guaranteed to be outside the available range of
interrupts and easy to distinguish from other possible incorrect
values."  When the hypercall to assign that IRQ fails, device
passthrough as a whole fails.

Add checking for a valid IRQ and skip the IRQ handling for PCI devices
outside that range.  This allows for passthrough of devices without
legacy IRQs.

Signed-off-by: Jason Andryuk <jason.andryuk@xxxxxxx>
---
 tools/libs/light/libxl_pci.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c
index 1647fd6f47..e0c8866792 100644
--- a/tools/libs/light/libxl_pci.c
+++ b/tools/libs/light/libxl_pci.c
@@ -26,6 +26,9 @@
 #define PCI_BDF_XSPATH         "%04x-%02x-%02x-%01x"
 #define PCI_PT_QDEV_ID         "pci-pt-%02x_%02x.%01x"
 
+/* PCI Interrupt Line is an 8-bit value, 0xff means disconnected. */
+#define PCI_IRQ_LINE_LIMIT     0xff
+
 static unsigned int pci_encode_bdf(libxl_device_pci *pci)
 {
     unsigned int value;
@@ -1495,7 +1498,8 @@ static void pci_add_dm_done(libxl__egc *egc,
             LOGED(ERROR, domainid, "Couldn't open %s", sysfs_path);
             goto out_no_irq;
         }
-        if ((fscanf(f, "%u", &irq) == 1) && irq) {
+        if ((fscanf(f, "%u", &irq) == 1) &&
+            irq > 0 && irq < PCI_IRQ_LINE_LIMIT) {
             r = xc_physdev_map_pirq(ctx->xch, domid, irq, &irq);
             if (r < 0) {
                 LOGED(ERROR, domainid, "xc_physdev_map_pirq irq=%d (error=%d)",
@@ -2257,7 +2261,8 @@ skip_bar:
             goto skip_legacy_irq;
         }
 
-        if ((fscanf(f, "%u", &irq) == 1) && irq) {
+        if ((fscanf(f, "%u", &irq) == 1) &&
+            irq > 0 && irq < PCI_IRQ_LINE_LIMIT) {
             rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq);
             if (rc < 0) {
                 /*
-- 
2.49.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.