]> rtime.felk.cvut.cz Git - jailhouse.git/commitdiff
tools: config-create: Do not enter infinite over disabled PCI devices
authorJan Kiszka <jan.kiszka@siemens.com>
Tue, 28 Jun 2016 15:11:00 +0000 (17:11 +0200)
committerJan Kiszka <jan.kiszka@siemens.com>
Tue, 28 Jun 2016 15:11:00 +0000 (17:11 +0200)
If a PCI device is disabled, e.g. a secondary GPU, we may not see its
config space anymore while it is still listed. With config all 0xff, we
will then enter an infinite loop while trying to make sense of the
capability list. Prevent this, issuing a warning that we will skip this
device.

Reported-by: Thomas Pettinger <thomas.pettinger@tum.de>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
tools/jailhouse-config-create

index 49a002e9418bb14313f05da218ba4266252d492e..f0d65ed014032c9a0c032524d5daae0ad020374f 100755 (executable)
@@ -340,6 +340,10 @@ class PCIDevice:
     def parse_pcidevice_sysfsdir(basedir, dir):
         dpath = os.path.join(basedir, dir)
         f = input_open(os.path.join(dpath, 'config'), 'rb')
+        (vendor_device,) = struct.unpack('<I', f.read(4))
+        if vendor_device == 0xffffffff:
+            print('WARNING: Ignoring apparently disabled PCI device %s' % dir)
+            return None
         f.seek(0x0A)
         (classcode,) = struct.unpack('<H', f.read(2))
         f.close()