From ac05a7189b32029ed041be8f893673fdf643b8ba Mon Sep 17 00:00:00 2001 From: DCyan_Elite Date: Mon, 30 Oct 2023 09:30:26 +0800 Subject: [PATCH] Add case dump func used by "echo list > /sys/kernel/debug/tdx/tdx-test" Signed-off-by: DCyan_Elite --- tdx-compliance/tdx-compliance.c | 36 ++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/tdx-compliance/tdx-compliance.c b/tdx-compliance/tdx-compliance.c index 4e26930e..dd658bda 100644 --- a/tdx-compliance/tdx-compliance.c +++ b/tdx-compliance/tdx-compliance.c @@ -58,6 +58,7 @@ LIST_HEAD(cpuid_list); #define OPMASK_CPUID 1 #define OPMASK_CR 2 #define OPMASK_MSR 4 +#define OPMASK_DUMP 0x800 #define OPMASK_SINGLE 0x8000 #define CPUID_DUMP_PATTERN \ @@ -87,6 +88,17 @@ void parse_version(void) spec_version = (VER1_0 | VER1_5); } +static char* case_version(int ret) { + switch (ret) { + case VER1_0: + return "1.0"; + case VER1_5: + return "1.5"; + } + + return ""; +} + void parse_input(char* s) { memset(case_name, 0, sizeof(case_name)); @@ -209,6 +221,11 @@ static int run_all_msr(void) if (!(spec_version & t->version)) continue; + if (operation & 0x800) { + pr_buf("%s %s\n", t->name, case_version(t->version)); + continue; + } + if (t->pre_condition) t->pre_condition(t); if (t->run_msr_rw) @@ -278,6 +295,11 @@ static int run_all_cpuid(void) if (!(spec_version & t->version)) continue; + if (operation & 0x800) { + pr_buf("%s %s\n", t->name, case_version(t->version)); + continue; + } + run_cpuid(t); t->ret = check_results_cpuid(t); @@ -349,6 +371,11 @@ static int run_all_cr(void) if (!(spec_version & t->version)) continue; + if (operation & 0x800) { + pr_buf("%s %s\n", t->name, case_version(t->version)); + continue; + } + if (t->run_cr_get) t->reg.val = t->run_cr_get(); @@ -409,6 +436,8 @@ tdx_tests_proc_write(struct file *file, operation |= OPMASK_MSR; else if (strstr(case_name, "all")) operation |= OPMASK_CPUID | OPMASK_CR | OPMASK_MSR; + else if (strstr(case_name, "list")) + operation |= OPMASK_DUMP | OPMASK_CPUID | OPMASK_CR | OPMASK_MSR; else operation |= OPMASK_SINGLE | OPMASK_CPUID | OPMASK_CR | OPMASK_MSR; @@ -426,9 +455,10 @@ tdx_tests_proc_write(struct file *file, if (operation & OPMASK_MSR) run_all_msr(); - pr_buf("Total:%d, PASS:%d, FAIL:%d, SKIP:%d\n", - stat_total, stat_pass, stat_fail, - stat_total - stat_pass - stat_fail); + if (!(operation & OPMASK_DUMP)) + pr_buf("Total:%d, PASS:%d, FAIL:%d, SKIP:%d\n", + stat_total, stat_pass, stat_fail, + stat_total - stat_pass - stat_fail); kfree(str_input); operation = 0;