Skip to contentSkip to conversation

tools/libs/light: fix BAR memory address truncation

PATCH Superseded Jiqian Chen 4 participants 6 messages Oct 13, 2025 – Oct 23, 2025

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tools/libs/light: fix BAR memory address truncation

64-bit BAR memory address is truncated when removing a passthrough pci device from guest since it uses "unsigned int".

So, change to use 64-bit type to fix this problem.

Fixes b0a1af61678b ("libxenlight: implement pci passthrough")

---
cc: Anthony PERARD <[email protected]>
cc: Juergen Gross <[email protected]>
---
v1->v2 changes:
* Change to use uint64_t instead of unsigned long long and change corresponding fscanf and LOGED parameters.

---
 tools/libs/light/libxl_pci.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
tools/libs/light/libxl_pci.c +5 -4
index 2ea2caeb6624..ae416a162360 100644
@@ -2001,7 +2001,8 @@ static void pci_remove_detached(libxl__egc *egc,
 {
     STATE_AO_GC(prs->aodev->ao);
     libxl_ctx *ctx = libxl__gc_owner(gc);
-    unsigned int start = 0, end = 0, flags = 0, size = 0, irq = 0;
+    uint64_t start = 0, end = 0, flags = 0, size = 0;
+    unsigned int irq = 0;
     int i, stubdomid = 0;
     const char *sysfs_path;
     FILE *f;
@@ -2031,7 +2032,7 @@ static void pci_remove_detached(libxl__egc *egc,
     }
 
     for (i = 0; i < PROC_PCI_NUM_RESOURCES; i++) {
-        if (fscanf(f, "0x%x 0x%x 0x%x\n", &start, &end, &flags) != 3)
+        if (fscanf(f, "0x%"SCNx64" 0x%"SCNx64" 0x%"SCNx64"\n", &start, &end, &flags) != 3)
             continue;
         size = end - start + 1;
         if (start) {
@@ -2040,7 +2041,7 @@ static void pci_remove_detached(libxl__egc *egc,
                                                  size, 0);
                 if (rc < 0)
                     LOGED(ERROR, domid,
-                          "xc_domain_ioport_permission error 0x%x/0x%x",
+                          "xc_domain_ioport_permission error %#"PRIx64"/%#"PRIx64,
                           start,
                           size);
             } else {
@@ -2050,7 +2051,7 @@ static void pci_remove_detached(libxl__egc *egc,
                                                 0);
                 if (rc < 0)
                     LOGED(ERROR, domid,
-                          "xc_domain_iomem_permission error 0x%x/0x%x",
+                          "xc_domain_ioport_permission error %#"PRIx64"/%#"PRIx64,
                           start,
                           size);
             }
Signature · 1 line
2.34.1
#2 lore raw
In reply to Jiqian Chen

tools/libs/light/libxl_pci.c static void pci_remove_detached(libxl__egc *egc, · line 2035

Quoted 6 lines · Jiqian Chen
tools/libs/light/libxl_pci.c +1 -1
@@ -2031,7 +2032,7 @@ static void pci_remove_detached(libxl__egc *egc,
     }
 
     for (i = 0; i < PROC_PCI_NUM_RESOURCES; i++) {
-        if (fscanf(f, "0x%x 0x%x 0x%x\n", &start, &end, &flags) != 3)
+        if (fscanf(f, "0x%"SCNx64" 0x%"SCNx64" 0x%"SCNx64"\n", &start, &end, &flags) != 3)

This line has now grown too long, where it can easily be wrapped (unlike ...

tools/libs/light/libxl_pci.c static void pci_remove_detached(libxl__egc *egc, · line 2044

Quoted 6 lines
tools/libs/light/libxl_pci.c +1 -1
@@ -2040,7 +2041,7 @@ static void pci_remove_detached(libxl__egc *egc,
                                                  size, 0);
                 if (rc < 0)
                     LOGED(ERROR, domid,
-                          "xc_domain_ioport_permission error 0x%x/0x%x",
+                          "xc_domain_ioport_permission error %#"PRIx64"/%#"PRIx64,

... here and ...

tools/libs/light/libxl_pci.c static void pci_remove_detached(libxl__egc *egc, · line 2054

Quoted 6 lines
tools/libs/light/libxl_pci.c +1 -1
@@ -2050,7 +2051,7 @@ static void pci_remove_detached(libxl__egc *egc,
                                                 0);
                 if (rc < 0)
                     LOGED(ERROR, domid,
-                          "xc_domain_iomem_permission error 0x%x/0x%x",
+                          "xc_domain_ioport_permission error %#"PRIx64"/%#"PRIx64,

... here, where we prefer to keep the entire format string on a single line). Can likely be addressed while committing.

Jan

#3 lore raw
Quoted 19 lines · Jan Beulich

tools/libs/light/libxl_pci.c static void pci_remove_detached(libxl__egc *egc, · line 2035

Quoted 6 lines · Jiqian Chen
tools/libs/light/libxl_pci.c +1 -1
@@ -2031,7 +2032,7 @@ static void pci_remove_detached(libxl__egc *egc,
     }
 
     for (i = 0; i < PROC_PCI_NUM_RESOURCES; i++) {
-        if (fscanf(f, "0x%x 0x%x 0x%x\n", &start, &end, &flags) != 3)
+        if (fscanf(f, "0x%"SCNx64" 0x%"SCNx64" 0x%"SCNx64"\n", &start, &end, &flags) != 3)

This line has now grown too long, where it can easily be wrapped (unlike ...

tools/libs/light/libxl_pci.c static void pci_remove_detached(libxl__egc *egc, · line 2044

Quoted 6 lines
tools/libs/light/libxl_pci.c +1 -1
@@ -2040,7 +2041,7 @@ static void pci_remove_detached(libxl__egc *egc,
                                                  size, 0);
                 if (rc < 0)
                     LOGED(ERROR, domid,
-                          "xc_domain_ioport_permission error 0x%x/0x%x",
+                          "xc_domain_ioport_permission error %#"PRIx64"/%#"PRIx64,

... here and ...

Quoted 9 lines

tools/libs/light/libxl_pci.c static void pci_remove_detached(libxl__egc *egc, · line 2054

Quoted 6 lines
tools/libs/light/libxl_pci.c +1 -1
@@ -2050,7 +2051,7 @@ static void pci_remove_detached(libxl__egc *egc,
                                                 0);
                 if (rc < 0)
                     LOGED(ERROR, domid,
-                          "xc_domain_iomem_permission error 0x%x/0x%x",
+                          "xc_domain_ioport_permission error %#"PRIx64"/%#"PRIx64,

... here, where we prefer to keep the entire format string on a single line). Can likely be addressed while committing.

Yes, thanks for helping me address this.

Quoted 2 lines

Jan

Signature · 2 lines
Best regards,
Jiqian Chen.
#4 lore raw
In reply to Jiqian Chen
Quoted 14 lines · Jiqian Chen
tools/libs/light/libxl_pci.c +1 -1
index 2ea2caeb6624..ae416a162360 100644
@@ -2040,7 +2041,7 @@ static void pci_remove_detached(libxl__egc *egc,
                                                  size, 0);
                 if (rc < 0)
                     LOGED(ERROR, domid,
-                          "xc_domain_ioport_permission error 0x%x/0x%x",
+                          "xc_domain_ioport_permission error %#"PRIx64"/%#"PRIx64,
                           start,
                           size);
             } else {

tools/libs/light/libxl_pci.c static void pci_remove_detached(libxl__egc *egc, · line 2054

Quoted 5 lines
tools/libs/light/libxl_pci.c +1 -1
@@ -2050,7 +2051,7 @@ static void pci_remove_detached(libxl__egc *egc,
                                                 0);
                 if (rc < 0)
                     LOGED(ERROR, domid,
-                          "xc_domain_iomem_permission error 0x%x/0x%x",
+                          "xc_domain_ioport_permission error %#"PRIx64"/%#"PRIx64,

Why does this message refer to "xc_domain_ioport_permission" now instead of "xc_domain_iomem_permission" ? (I'm guessing overzealous copy/past ;-) from the previous error message)

Cheers,

Signature · 1 line
Anthony PERARD
#5 lore raw
Quoted 16 lines · Anthony PERARD
Quoted 15 lines · Jiqian Chen
tools/libs/light/libxl_pci.c +1 -1
index 2ea2caeb6624..ae416a162360 100644
@@ -2040,7 +2041,7 @@ static void pci_remove_detached(libxl__egc *egc,
                                                  size, 0);
                 if (rc < 0)
                     LOGED(ERROR, domid,
-                          "xc_domain_ioport_permission error 0x%x/0x%x",
+                          "xc_domain_ioport_permission error %#"PRIx64"/%#"PRIx64,
                           start,
                           size);
             } else {
@@ -2050,7 +2051,7 @@ static void pci_remove_detached(libxl__egc *egc,
                                                 0);
Quoted 8 lines

tools/libs/light/libxl_pci.c static void pci_remove_detached(libxl__egc *egc, · line 2054

Quoted 4 lines
tools/libs/light/libxl_pci.c +1 -1
                 if (rc < 0)
                     LOGED(ERROR, domid,
-                          "xc_domain_iomem_permission error 0x%x/0x%x",
+                          "xc_domain_ioport_permission error %#"PRIx64"/%#"PRIx64,

Why does this message refer to "xc_domain_ioport_permission" now instead of "xc_domain_iomem_permission" ? (I'm guessing overzealous copy/past ;-) from the previous error message)

Sorry, will change.

Quoted 3 lines

Cheers,

Signature · 2 lines
Best regards,
Jiqian Chen.