From 59b6d7b4040c231ed2312a7d018be76c62dca8db Mon Sep 17 00:00:00 2001 From: Shiqing Gao Date: Mon, 4 Jul 2022 09:47:59 +0800 Subject: [PATCH] dm: verify the "iasl" version This patch does: - define IASL_MIN_VER in the top-level Makefile and pass it Device Model - verify the "iasl" version at run time if "iasl" version is older than IASL_MIN_VER, refuse to launch the post-launched VM and exit directly. Tracked-On: #7880 Signed-off-by: Shiqing Gao Acked-by: Wang, Yu1 --- Makefile | 3 ++- devicemodel/Makefile | 2 ++ devicemodel/core/main.c | 7 ++++++ devicemodel/hw/platform/acpi/acpi.c | 36 +++++++++++++++++++++++++++++ devicemodel/include/acpi.h | 1 + 5 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b0cdf47bf..1e263b77c 100644 --- a/Makefile +++ b/Makefile @@ -86,6 +86,7 @@ ASL_COMPILER ?= $(shell which iasl) DPKG_BIN ?= $(shell which dpkg) YARN_BIN ?= $(shell which yarn) CARGO_BIN ?= $(shell which cargo) +IASL_MIN_VER = "20190703" .PHONY: all hypervisor devicemodel tools life_mngr doc all: hypervisor devicemodel tools @@ -132,7 +133,7 @@ hvapplydiffconfig: @$(MAKE) applydiffconfig $(HV_MAKEOPTS) PATCH=$(abspath $(PATCH)) devicemodel: tools - $(MAKE) -C $(T)/devicemodel DM_OBJDIR=$(DM_OUT) DM_BUILD_VERSION=$(BUILD_VERSION) DM_BUILD_TAG=$(BUILD_TAG) TOOLS_OUT=$(TOOLS_OUT) RELEASE=$(RELEASE) + $(MAKE) -C $(T)/devicemodel DM_OBJDIR=$(DM_OUT) DM_BUILD_VERSION=$(BUILD_VERSION) DM_BUILD_TAG=$(BUILD_TAG) TOOLS_OUT=$(TOOLS_OUT) RELEASE=$(RELEASE) IASL_MIN_VER=$(IASL_MIN_VER) tools: mkdir -p $(TOOLS_OUT) diff --git a/devicemodel/Makefile b/devicemodel/Makefile index fc69e1d57..1b0b27384 100644 --- a/devicemodel/Makefile +++ b/devicemodel/Makefile @@ -45,6 +45,8 @@ CFLAGS += -I$(SYSROOT)/usr/include/SDL2 CFLAGS += -I$(SYSROOT)/usr/include/EGL CFLAGS += -I$(SYSROOT)/usr/include/GLES2 +CFLAGS += -DIASL_MIN_VER=\"$(IASL_MIN_VER)\" + GCC_MAJOR=$(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1) GCC_MINOR=$(shell echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1) diff --git a/devicemodel/core/main.c b/devicemodel/core/main.c index 7a3b46e4f..924a6b5d6 100644 --- a/devicemodel/core/main.c +++ b/devicemodel/core/main.c @@ -1034,6 +1034,13 @@ main(int argc, char *argv[]) exit(1); } + if (check_iasl_version() != 0) { + pr_err("Please install iasl tool with version >= %s from https://www.acpica.org/downloads, " + "and provide the path to iasl (by using --iasl) if it's not on the PATH \n", + IASL_MIN_VER); + exit(1); + } + argc -= optind; argv += optind; diff --git a/devicemodel/hw/platform/acpi/acpi.c b/devicemodel/hw/platform/acpi/acpi.c index a0a5fe583..c5f6a40af 100644 --- a/devicemodel/hw/platform/acpi/acpi.c +++ b/devicemodel/hw/platform/acpi/acpi.c @@ -96,6 +96,9 @@ #define ASL_TEMPLATE "dm.XXXXXXX" #define ASL_SUFFIX ".aml" +#define ASL_VER_PATTERN "ASL+ Optimizing Compiler/Disassembler version " +#define ASL_VER_STR_LEN 256 + static char asl_compiler[MAXPATHLEN] = {0}; uint64_t audio_nhlt_len = 0; @@ -1150,6 +1153,39 @@ acrn_parse_iasl(char *arg) return -1; } +int +check_iasl_version(void) +{ + int ret = -1; + static char cmd_iasl_ver[MAXPATHLEN + 10]; + static char buf[ASL_VER_STR_LEN]; + char *ver_str, *cp; + uint32_t ver, min_ver; + + snprintf(cmd_iasl_ver, sizeof(cmd_iasl_ver), + "%s -v", asl_compiler); + FILE *fd_iasl_ver = popen(cmd_iasl_ver, "r"); + + if (fd_iasl_ver != NULL) + { + while (fgets(buf, ASL_VER_STR_LEN, fd_iasl_ver) != NULL) { + if (strstr(buf, ASL_VER_PATTERN)) { + ver_str = buf + strlen(ASL_VER_PATTERN); + pr_info("iasl version: %s", ver_str); + + if ((!dm_strtoui(ver_str, &cp, 10, &ver)) && + (!dm_strtoui(IASL_MIN_VER, &cp, 10, &min_ver)) && + (ver >= min_ver)) { + ret = 0; + } + } + } + + pclose(fd_iasl_ver); + } + return ret; +} + int get_iasl_compiler(void) { diff --git a/devicemodel/include/acpi.h b/devicemodel/include/acpi.h index 0f46e3885..b8d088a09 100644 --- a/devicemodel/include/acpi.h +++ b/devicemodel/include/acpi.h @@ -123,5 +123,6 @@ int lapic_to_pcpu(int lapic); int parse_madt(void); int acrn_parse_iasl(char *arg); int get_iasl_compiler(void); +int check_iasl_version(void); #endif /* _ACPI_H_ */