From fec1f87adc57ba14d9608fe06ca9da112b8ccc44 Mon Sep 17 00:00:00 2001 From: "Yang,Yu-chu" Date: Mon, 14 Jun 2021 13:52:30 -0700 Subject: [PATCH] config-tools: do not exit when the board inspector runs in hypervisor While running in a nested environment, such as qemu, parse the board information should be allowed even it is not in a native environment. Replace the error with warning message and does not exit the program. Tracked-On: #6208 Signed-off-by: Yang,Yu-chu --- misc/config_tools/board_inspector/cli.py | 12 ++++++++++ .../board_inspector/cpuparser/__init__.py | 12 ++++++++++ .../board_inspector/cpuparser/cpuids.py | 1 + .../extractors/10-processors.py | 14 +---------- .../board_inspector/legacy/board_parser.py | 23 ------------------- 5 files changed, 26 insertions(+), 36 deletions(-) diff --git a/misc/config_tools/board_inspector/cli.py b/misc/config_tools/board_inspector/cli.py index aae880113..56fed8fb9 100755 --- a/misc/config_tools/board_inspector/cli.py +++ b/misc/config_tools/board_inspector/cli.py @@ -11,11 +11,23 @@ import subprocess import lxml.etree import argparse from importlib import import_module +from cpuparser import parse_cpuid, get_online_cpu_ids script_dir = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(script_dir)) +def native_check(): + cpu_ids = get_online_cpu_ids() + cpu_id = cpu_ids.pop(0) + leaf_1 = parse_cpuid(1, 0, cpu_id) + if leaf_1.hypervisor != 0: + logging.warning(f"Board inspector is running inside a Virtual Machine (VM). Running ACRN inside a VM is only" \ + "supported under KVM/QEMU. Unexpected results may occur when deviating from that combination.") + def main(board_name, board_xml, args): + # Check if this is native os + native_check() + try: # First invoke the legacy board parser to create the board XML ... legacy_parser = os.path.join(script_dir, "legacy", "board_parser.py") diff --git a/misc/config_tools/board_inspector/cpuparser/__init__.py b/misc/config_tools/board_inspector/cpuparser/__init__.py index 708778bb4..897bfd98c 100644 --- a/misc/config_tools/board_inspector/cpuparser/__init__.py +++ b/misc/config_tools/board_inspector/cpuparser/__init__.py @@ -59,3 +59,15 @@ def parse_cpuid(leaf, subleaf, cpu_id): return None else: return None + +def get_online_cpu_ids(): + acc = list() + with open("/sys/devices/system/cpu/online", "r") as f: + line = f.read().strip() + for r in line.split(","): + if r.find("-") > 0: + first, last = tuple(map(int, r.split("-"))) + acc.extend(range(first, last + 1)) + else: + acc.append(int(r)) + return acc diff --git a/misc/config_tools/board_inspector/cpuparser/cpuids.py b/misc/config_tools/board_inspector/cpuparser/cpuids.py index 5a37aaccc..521b3d31b 100644 --- a/misc/config_tools/board_inspector/cpuparser/cpuids.py +++ b/misc/config_tools/board_inspector/cpuparser/cpuids.py @@ -75,6 +75,7 @@ class LEAF_1(CPUID): avx = cpuidfield(ECX, 28, 28) f16c = cpuidfield(ECX, 29, 29) rdrand = cpuidfield(ECX, 30, 30) + hypervisor = cpuidfield(ECX, 31, 31) fpu = cpuidfield(EDX, 0, 0) vme = cpuidfield(EDX, 1, 1) diff --git a/misc/config_tools/board_inspector/extractors/10-processors.py b/misc/config_tools/board_inspector/extractors/10-processors.py index 4318d7dac..fe758c96b 100644 --- a/misc/config_tools/board_inspector/extractors/10-processors.py +++ b/misc/config_tools/board_inspector/extractors/10-processors.py @@ -6,7 +6,7 @@ import logging import lxml.etree -from cpuparser import parse_cpuid +from cpuparser import parse_cpuid, get_online_cpu_ids from extractors.helpers import add_child, get_node level_types = { @@ -17,18 +17,6 @@ level_types = { 5: "die", } -def get_online_cpu_ids(): - acc = list() - with open("/sys/devices/system/cpu/online", "r") as f: - line = f.read().strip() - for r in line.split(","): - if r.find("-") > 0: - first, last = tuple(map(int, r.split("-"))) - acc.extend(range(first, last + 1)) - else: - acc.append(int(r)) - return acc - def get_parent(processors_node, topo_level, topo_id): n = get_node(processors_node, f"//{topo_level}[@id='{topo_id}']") return n diff --git a/misc/config_tools/board_inspector/legacy/board_parser.py b/misc/config_tools/board_inspector/legacy/board_parser.py index f09ff9886..698c5682e 100755 --- a/misc/config_tools/board_inspector/legacy/board_parser.py +++ b/misc/config_tools/board_inspector/legacy/board_parser.py @@ -30,25 +30,6 @@ def check_permission(): parser_lib.print_red("You need run this tool with root privileges (sudo)!") sys.exit(1) - -def native_check(): - """Check if this is natvie os""" - cmd = "cpuid -r -l 0x01" - res = parser_lib.cmd_execute(cmd) - while True: - line = parser_lib.decode_stdout(res) - - if line: - - if len(line.split()) <= 2: - continue - - reg_value = line.split()[4].split('=')[1] - break - - return int(reg_value, 16) & 0x80000000 == 0 - - def vendor_check(): """Check the CPU vendor""" with open("/proc/cpuinfo", 'r') as f_node: @@ -91,10 +72,6 @@ def check_env(): parser_lib.print_yel("Need CPUID version >= 20170122") sys.exit(1) - if not native_check(): - parser_lib.print_red("Please run this tools in a native OS environment!") - sys.exit(1) - if os.path.exists(OUTPUT): shutil.rmtree(OUTPUT)