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 wenlingz
parent 1ad836e9a8
commit a39f2995ad
1 changed files with 15 additions and 12 deletions

View File

@ -82,19 +82,22 @@ def parse_device(bus_node, device_path):
resource_type = bar.resource_type
base = bar.base
if os.path.exists(resource_path):
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)
resource_node = add_child(device_node, "resource", None, type=resource_type, min=hex(base), max=hex(base + size - 1), len=hex(size))
resource_node.set("id", f"bar{idx}")
if isinstance(bar, MemoryBar32):
resource_node.set("width", "32")
resource_node.set("prefetchable", str(bar.prefetchable))
elif isinstance(bar, MemoryBar64):
resource_node.set("width", "64")
resource_node.set("prefetchable", str(bar.prefetchable))
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)
resource_node = add_child(device_node, "resource", None, type=resource_type, min=hex(base), max=hex(base + size - 1), len=hex(size))
resource_node.set("id", f"bar{idx}")
if isinstance(bar, MemoryBar32):
resource_node.set("width", "32")
resource_node.set("prefetchable", str(bar.prefetchable))
elif isinstance(bar, MemoryBar64):
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: