From a39f2995ad696ee7b552466bc9d4dd28cfc9e88d Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Wed, 21 Jul 2021 16:41:13 +0800 Subject: [PATCH] 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 --- .../board_inspector/extractors/60-pci.py | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/misc/config_tools/board_inspector/extractors/60-pci.py b/misc/config_tools/board_inspector/extractors/60-pci.py index e42b8eeef..61c48434f 100644 --- a/misc/config_tools/board_inspector/extractors/60-pci.py +++ b/misc/config_tools/board_inspector/extractors/60-pci.py @@ -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: