Fixes generation of unreferenced PCI capabilities inside cell configs
on AMD systems. They occur due to removal of the IOMMU from the PCI
devices list after its capabilities have been collected.

Signed-off-by: Andrej Utz <andrej....@st.oth-regensburg.de>
---
 pyjailhouse/sysfs_parser.py    | 19 +------------------
 tools/jailhouse-config-create  | 24 ++++++++++++++++++++++--
 tools/jailhouse-hardware-check |  2 +-
 3 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/pyjailhouse/sysfs_parser.py b/pyjailhouse/sysfs_parser.py
index e59586cd..8debf460 100644
--- a/pyjailhouse/sysfs_parser.py
+++ b/pyjailhouse/sysfs_parser.py
@@ -280,31 +280,14 @@ def parse_ioports():
 
 
 def parse_pcidevices():
-    int_src_cnt = 0
     devices = []
-    caps = []
     basedir = '/sys/bus/pci/devices'
     list = input_listdir(basedir, ['*/config'])
     for dir in list:
         d = PCIDevice.parse_pcidevice_sysfsdir(basedir, dir)
         if d is not None:
-            if d.caps:
-                duplicate = False
-                # look for duplicate capability patterns
-                for d2 in devices:
-                    if d2.caps == d.caps:
-                        # reused existing capability list, but record all users
-                        d2.caps[0].comments.append(str(d))
-                        d.caps_start = d2.caps_start
-                        duplicate = True
-                        break
-                if not duplicate:
-                    d.caps[0].comments.append(str(d))
-                    d.caps_start = len(caps)
-                    caps.extend(d.caps)
-            int_src_cnt += max(d.num_msi_vectors, d.num_msix_vectors)
             devices.append(d)
-    return (devices, caps, int_src_cnt)
+    return devices
 
 
 def parse_madt():
diff --git a/tools/jailhouse-config-create b/tools/jailhouse-config-create
index 709cf2ef..0f75be4f 100755
--- a/tools/jailhouse-config-create
+++ b/tools/jailhouse-config-create
@@ -253,7 +253,7 @@ cpu_count = count_cpus()
 mmconfig = MMConfig.parse()
 
 # Query devices
-(pci_devices, pci_caps, int_src_count) = sysfs_parser.parse_pcidevices()
+pci_devices = sysfs_parser.parse_pcidevices()
 (mem_regions, dmar_regions) = sysfs_parser.parse_iomem(pci_devices)
 (port_regions, pm_timer_base) = sysfs_parser.parse_ioports()
 ioapics = sysfs_parser.parse_madt()
@@ -266,7 +266,27 @@ else:
 mem_regions += extra_memregs
 
 IOAPIC_MAX_PINS = 120
-int_src_count += IOAPIC_MAX_PINS
+int_src_count = IOAPIC_MAX_PINS
+
+# Collect all PCI capabilities
+pci_caps = []
+for i,d in enumerate(pci_devices):
+    if d.caps:
+        duplicate = False
+        # look for duplicate capability patterns
+        for d2 in pci_devices[:i]:
+            if d2.caps == d.caps:
+                # reused existing capability list, but record all users
+                d2.caps[0].comments.append(str(d))
+                d.caps_start = d2.caps_start
+                duplicate = True
+                break
+        if not duplicate:
+            d.caps[0].comments.append(str(d))
+            d.caps_start = len(pci_caps)
+            pci_caps.extend(d.caps)
+    int_src_count += max(d.num_msi_vectors, d.num_msix_vectors)
+
 vtd_interrupt_limit = 2**math.ceil(math.log(int_src_count, 2))
 
 # Determine hypervisor memory
diff --git a/tools/jailhouse-hardware-check b/tools/jailhouse-hardware-check
index 9e90250d..f9b2cf58 100755
--- a/tools/jailhouse-hardware-check
+++ b/tools/jailhouse-hardware-check
@@ -127,7 +127,7 @@ if os.uname()[4] not in ('x86_64', 'i686'):
 
 
 ioapics = sysfs_parser.parse_madt()
-pci_devices, _, _ = sysfs_parser.parse_pcidevices()
+pci_devices = sysfs_parser.parse_pcidevices()
 
 (cpu_vendor, cpu_features, cpu_count) = parse_cpuinfo()
 
-- 
2.27.0

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jailhouse-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jailhouse-dev/20200609131143.2133316-2-andrej.utz%40st.oth-regensburg.de.

Reply via email to