board_inspector: check if BAR base is 0

It is seen occasionally that a memory/port BAR of a PCI device is
programmed with the address 0 which is clearly invalid. This patch
gracefully handles this case by printing an error to warn the users that
this device cannot be passed through to any VM.

Tracked-On: #6298
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
Junjie Mao
2021-07-21 16:41:13 +08:00
committed by Xie, Nanlin
parent 7f3016e678
commit 3c707408ec

View File

@@ -74,6 +74,9 @@ def parse_device(bus_node, device_path):
resource_type = bar.resource_type
base = bar.base
if os.path.exists(resource_path):
if bar.base == 0:
logging.warning(f"PCI {device_name}: BAR {idx} exists but is programmed with all 0. This device cannot be passed through to any VM.")
else:
resource_node = get_node(device_node, f"./resource[@type = '{resource_type}' and @min = '{hex(base)}']")
if resource_node is None:
size = os.path.getsize(resource_path)
@@ -86,7 +89,7 @@ def parse_device(bus_node, device_path):
resource_node.set("width", "64")
resource_node.set("prefetchable", str(bar.prefetchable))
elif bar.base != 0:
logging.error(f"Cannot detect the size of BAR {idx}")
logging.warning(f"PCI {device_name}: Cannot detect the size of BAR {idx}")
if isinstance(bar, MemoryBar64):
idx += 2
else: