Skip to contentSkip to conversation

hw/pci/pci-hmp-cmds: Avoid displaying bogus size in 'info pci'

PATCH-for-9.1? Philippe Mathieu-Daudé 2 participants 5 messages Aug 1, 2024

lore
Share & tools
lore
#0 lore raw

When BAR aren't configured, we get:

(qemu) info pci

    Bus  0, device   0, function 0:
      Host bridge: PCI device dead:beef
        ...
        BAR4: 32 bit memory at 0xffffffffffffffff [0x00000ffe].
        BAR5: I/O at 0xffffffffffffffff [0x0ffe].

Improve logging to not display bogus sizes:

BAR4: 32 bit memory (not configured)
BAR5: I/O (not configured)

Remove trailing dot which is not used in other commands format.

---
 hw/pci/pci-hmp-cmds.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
hw/pci/pci-hmp-cmds.c +18 -8
index b09fce9377..8421c3f74a 100644
@@ -83,15 +83,25 @@ static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
         monitor_printf(mon, "      BAR%" PRId64 ": ", region->value->bar);
 
         if (!strcmp(region->value->type, "io")) {
-            monitor_printf(mon, "I/O at 0x%04" PRIx64
-                                " [0x%04" PRIx64 "].\n",
-                           addr, addr + size - 1);
+            if (addr != UINT64_MAX) {
+                monitor_printf(mon, "I/O at 0x%04" PRIx64
+                                    " [0x%04" PRIx64 "]\n",
+                               addr, addr + size - 1);
+            } else {
+                monitor_printf(mon, "I/O (not configured)\n");
+            }
         } else {
-            monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
-                               " [0x%08" PRIx64 "].\n",
-                           region->value->mem_type_64 ? 64 : 32,
-                           region->value->prefetch ? " prefetchable" : "",
-                           addr, addr + size - 1);
+            if (addr != UINT64_MAX) {
+                monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
+                                   " [0x%08" PRIx64 "]\n",
+                               region->value->mem_type_64 ? 64 : 32,
+                               region->value->prefetch ? " prefetchable" : "",
+                               addr, addr + size - 1);
+            } else {
+                monitor_printf(mon, "%d bit%s memory (not configured)\n",
+                               region->value->mem_type_64 ? 64 : 32,
+                               region->value->prefetch ? " prefetchable" : "");
+            }
         }
     }
 
Signature · 1 line
2.45.2
#1 lore raw
Quoted 48 lines · Philippe Mathieu-Daudé

When BAR aren't configured, we get:

(qemu) info pci

    Bus  0, device   0, function 0:
      Host bridge: PCI device dead:beef
        ...
        BAR4: 32 bit memory at 0xffffffffffffffff [0x00000ffe].
        BAR5: I/O at 0xffffffffffffffff [0x0ffe].

Improve logging to not display bogus sizes:

BAR4: 32 bit memory (not configured)
BAR5: I/O (not configured)

Remove trailing dot which is not used in other commands format.

---
 hw/pci/pci-hmp-cmds.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
hw/pci/pci-hmp-cmds.c +10 -8
index b09fce9377..8421c3f74a 100644
@@ -83,15 +83,25 @@ static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
         monitor_printf(mon, "      BAR%" PRId64 ": ", region->value->bar);
 
         if (!strcmp(region->value->type, "io")) {
-            monitor_printf(mon, "I/O at 0x%04" PRIx64
-                                " [0x%04" PRIx64 "].\n",
-                           addr, addr + size - 1);
+            if (addr != UINT64_MAX) {
+                monitor_printf(mon, "I/O at 0x%04" PRIx64
+                                    " [0x%04" PRIx64 "]\n",
+                               addr, addr + size - 1);
+            } else {
+                monitor_printf(mon, "I/O (not configured)\n");
+            }
         } else {
-            monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
-                               " [0x%08" PRIx64 "].\n",
-                           region->value->mem_type_64 ? 64 : 32,
-                           region->value->prefetch ? " prefetchable" : "",
-                           addr, addr + size - 1);
+            if (addr != UINT64_MAX) {
+                monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
+                                   " [0x%08" PRIx64 "]\n",

hw/pci/pci-hmp-cmds.c static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) · line 106

Quoted 10 lines
hw/pci/pci-hmp-cmds.c +8 -0
+                               region->value->mem_type_64 ? 64 : 32,
+                               region->value->prefetch ? " prefetchable" : "",
+                               addr, addr + size - 1);
+            } else {
+                monitor_printf(mon, "%d bit%s memory (not configured)\n",
+                               region->value->mem_type_64 ? 64 : 32,
+                               region->value->prefetch ? " prefetchable" : "");
+            }
         }
     }

what makes bar unconfigured is that memory space is disabled, not that it has a special value.

Quoted 3 lines
Signature · 2 lines
-- 
2.45.2
#2 lore raw
Quoted 54 lines · Michael S. Tsirkin
Quoted 53 lines · Philippe Mathieu-Daudé

When BAR aren't configured, we get:

(qemu) info pci

     Bus  0, device   0, function 0:
       Host bridge: PCI device dead:beef
         ...
         BAR4: 32 bit memory at 0xffffffffffffffff [0x00000ffe].
         BAR5: I/O at 0xffffffffffffffff [0x0ffe].

Improve logging to not display bogus sizes:

BAR4: 32 bit memory (not configured)
BAR5: I/O (not configured)

Remove trailing dot which is not used in other commands format.

---
  hw/pci/pci-hmp-cmds.c | 26 ++++++++++++++++++--------
  1 file changed, 18 insertions(+), 8 deletions(-)
hw/pci/pci-hmp-cmds.c +15 -8
index b09fce9377..8421c3f74a 100644
@@ -83,15 +83,25 @@ static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
          monitor_printf(mon, "      BAR%" PRId64 ": ", region->value->bar);
 
          if (!strcmp(region->value->type, "io")) {
-            monitor_printf(mon, "I/O at 0x%04" PRIx64
-                                " [0x%04" PRIx64 "].\n",
-                           addr, addr + size - 1);
+            if (addr != UINT64_MAX) {
+                monitor_printf(mon, "I/O at 0x%04" PRIx64
+                                    " [0x%04" PRIx64 "]\n",
+                               addr, addr + size - 1);
+            } else {
+                monitor_printf(mon, "I/O (not configured)\n");
+            }
          } else {
-            monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
-                               " [0x%08" PRIx64 "].\n",
-                           region->value->mem_type_64 ? 64 : 32,
-                           region->value->prefetch ? " prefetchable" : "",
-                           addr, addr + size - 1);
+            if (addr != UINT64_MAX) {
+                monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
+                                   " [0x%08" PRIx64 "]\n",
+                               region->value->mem_type_64 ? 64 : 32,
+                               region->value->prefetch ? " prefetchable" : "",
+                               addr, addr + size - 1);
+            } else {
+                monitor_printf(mon, "%d bit%s memory (not configured)\n",
Quoted 8 lines

hw/pci/pci-hmp-cmds.c static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) · line 106

Quoted 5 lines
hw/pci/pci-hmp-cmds.c +3 -0
+                               region->value->mem_type_64 ? 64 : 32,
+                               region->value->prefetch ? " prefetchable" : "");
+            }
          }
      }

what makes bar unconfigured is that memory space is disabled, not that it has a special value.

I tried to add a PciMemoryRegion::enabled field then realized unmapped regions are advertised using addr = PCI_BAR_UNMAPPED (which is UINT64_MAX):

typedef struct PCIIORegion {
pcibus_t addr; /* current PCI mapping address. -1 means not mapped */
#define PCI_BAR_UNMAPPED (~(pcibus_t)0)

OK if I respin this patch with s/UINT64_MAX/PCI_BAR_UNMAPPED/?

#3 lore raw
Quoted 72 lines · Philippe Mathieu-Daudé
Quoted 58 lines · Michael S. Tsirkin
Quoted 57 lines · Philippe Mathieu-Daudé

When BAR aren't configured, we get:

   (qemu) info pci
     Bus  0, device   0, function 0:
       Host bridge: PCI device dead:beef
         ...
         BAR4: 32 bit memory at 0xffffffffffffffff [0x00000ffe].
         BAR5: I/O at 0xffffffffffffffff [0x0ffe].

Improve logging to not display bogus sizes:

       BAR4: 32 bit memory (not configured)
       BAR5: I/O (not configured)

Remove trailing dot which is not used in other commands format.

---
  hw/pci/pci-hmp-cmds.c | 26 ++++++++++++++++++--------

  1 file changed, 18 insertions(+), 8 deletions(-)
hw/pci/pci-hmp-cmds.c +16 -8
index b09fce9377..8421c3f74a 100644
@@ -83,15 +83,25 @@ static void hmp_info_pci_device(Monitor *mon, 
 const PciDeviceInfo *dev)
           monitor_printf(mon, "      BAR%" PRId64 ": ", region->value->bar);
           if (!strcmp(region->value->type, "io")) {
-            monitor_printf(mon, "I/O at 0x%04" PRIx64
-                                " [0x%04" PRIx64 "].\n",
-                           addr, addr + size - 1);
+            if (addr != UINT64_MAX) {
+                monitor_printf(mon, "I/O at 0x%04" PRIx64
+                                    " [0x%04" PRIx64 "]\n",
+                               addr, addr + size - 1);
+            } else {
+                monitor_printf(mon, "I/O (not configured)\n");
+            }
           } else {
-            monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
-                               " [0x%08" PRIx64 "].\n",
-                           region->value->mem_type_64 ? 64 : 32,
-                           region->value->prefetch ? " prefetchable" 
 : "",
-                           addr, addr + size - 1);
+            if (addr != UINT64_MAX) {
+                monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
+                                   " [0x%08" PRIx64 "]\n",
+                               region->value->mem_type_64 ? 64 : 32,
+                               region->value->prefetch ? " 
 prefetchable" : "",
+                               addr, addr + size - 1);
+            } else {
+                monitor_printf(mon, "%d bit%s memory (not 
 configured)\n",
+                               region->value->mem_type_64 ? 64 : 32,
Quoted 8 lines
Quoted 5 lines
hw/pci/pci-hmp-cmds.c +1 -0
+                               region->value->prefetch ? " 

prefetchable" : "");
+            }
          }
      }

what makes bar unconfigured is that memory space is disabled, not that it has a special value.

I tried to add a PciMemoryRegion::enabled field then realized unmapped regions are advertised using addr = PCI_BAR_UNMAPPED (which is UINT64_MAX):

Quoted 5 lines

typedef struct PCIIORegion {
  pcibus_t addr; /* current PCI mapping address. -1 means not mapped */
#define PCI_BAR_UNMAPPED (~(pcibus_t)0)

OK if I respin this patch with s/UINT64_MAX/PCI_BAR_UNMAPPED/?

and s/configured/mapped/ in printf.

#4 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 67 lines · Philippe Mathieu-Daudé
Quoted 53 lines · Michael S. Tsirkin
Quoted 52 lines · Philippe Mathieu-Daudé

When BAR aren't configured, we get:

(qemu) info pci

     Bus  0, device   0, function 0:
       Host bridge: PCI device dead:beef
         ...
         BAR4: 32 bit memory at 0xffffffffffffffff [0x00000ffe].
         BAR5: I/O at 0xffffffffffffffff [0x0ffe].

Improve logging to not display bogus sizes:

BAR4: 32 bit memory (not configured)
BAR5: I/O (not configured)

Remove trailing dot which is not used in other commands format.

---
  hw/pci/pci-hmp-cmds.c | 26 ++++++++++++++++++--------
  1 file changed, 18 insertions(+), 8 deletions(-)
hw/pci/pci-hmp-cmds.c +15 -8
index b09fce9377..8421c3f74a 100644
@@ -83,15 +83,25 @@ static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
          monitor_printf(mon, "      BAR%" PRId64 ": ", region->value->bar);
          if (!strcmp(region->value->type, "io")) {
-            monitor_printf(mon, "I/O at 0x%04" PRIx64
-                                " [0x%04" PRIx64 "].\n",
-                           addr, addr + size - 1);
+            if (addr != UINT64_MAX) {
+                monitor_printf(mon, "I/O at 0x%04" PRIx64
+                                    " [0x%04" PRIx64 "]\n",
+                               addr, addr + size - 1);
+            } else {
+                monitor_printf(mon, "I/O (not configured)\n");
+            }
          } else {
-            monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
-                               " [0x%08" PRIx64 "].\n",
-                           region->value->mem_type_64 ? 64 : 32,
-                           region->value->prefetch ? " prefetchable" : "",
-                           addr, addr + size - 1);
+            if (addr != UINT64_MAX) {
+                monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
+                                   " [0x%08" PRIx64 "]\n",
+                               region->value->mem_type_64 ? 64 : 32,
+                               region->value->prefetch ? " prefetchable" : "",
+                               addr, addr + size - 1);
+            } else {
+                monitor_printf(mon, "%d bit%s memory (not configured)\n",
Quoted 8 lines

hw/pci/pci-hmp-cmds.c static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) · line 106

Quoted 5 lines
hw/pci/pci-hmp-cmds.c +3 -0
+                               region->value->mem_type_64 ? 64 : 32,
+                               region->value->prefetch ? " prefetchable" : "");
+            }
          }
      }

what makes bar unconfigured is that memory space is disabled, not that it has a special value.

I tried to add a PciMemoryRegion::enabled field then realized unmapped regions are advertised using addr = PCI_BAR_UNMAPPED (which is UINT64_MAX):

Quoted 5 lines

typedef struct PCIIORegion {
pcibus_t addr; /* current PCI mapping address. -1 means not mapped */
#define PCI_BAR_UNMAPPED (~(pcibus_t)0)

OK if I respin this patch with s/UINT64_MAX/PCI_BAR_UNMAPPED/?

ok