From b03e568ea9eb609f85a0a496c83a5f27ce18498e Mon Sep 17 00:00:00 2001 From: Stefano Stabellini Date: Fri, 26 Jan 2018 09:19:31 -0800 Subject: [PATCH] x86/boot: turn the selftests ASSERT into a warning On selftests failure, print a very visible warning instead of crashing over an ASSERT. Signed-off-by: Stefano Stabellini Reviewed-by: Andrew Cooper Adjust to print extra information in the case of a failure Signed-off-by: Andrew Cooper --- xen/arch/x86/extable.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/extable.c b/xen/arch/x86/extable.c index 72f30d9060..a6430a6d8d 100644 --- a/xen/arch/x86/extable.c +++ b/xen/arch/x86/extable.c @@ -9,6 +9,7 @@ #include #include #include +#include #define EX_FIELD(ptr, field) ((unsigned long)&(ptr)->field + (ptr)->field) @@ -145,6 +146,7 @@ static int __init stub_selftest(void) }; unsigned long addr = this_cpu(stubs.addr) + STUB_BUF_SIZE / 2; unsigned int i; + bool fail = false; printk("Running stub recovery selftests...\n"); @@ -152,7 +154,7 @@ static int __init stub_selftest(void) { uint8_t *ptr = map_domain_page(_mfn(this_cpu(stubs.mfn))) + (addr & ~PAGE_MASK); - unsigned long res = ~0; + union stub_exception_token res = { .raw = ~0 }; memset(ptr, 0xcc, STUB_BUF_SIZE / 2); memcpy(ptr, tests[i].opc, ARRAY_SIZE(tests[i].opc)); @@ -168,9 +170,22 @@ static int __init stub_selftest(void) _ASM_EXTABLE(.Lret%=, .Lfix%=) : [exn] "+m" (res) : [stb] "r" (addr), "a" (tests[i].rax)); - ASSERT(res == tests[i].res.raw); + + if ( res.raw != tests[i].res.raw ) + { + printk("Selftest %u failed: Opc %*ph " + "expected %u[%04x], got %u[%04x]\n", + i, (int)ARRAY_SIZE(tests[i].opc), tests[i].opc, + tests[i].res.fields.trapnr, tests[i].res.fields.ec, + res.fields.trapnr, res.fields.ec); + + fail = true; + } } + if ( fail ) + warning_add("SELFTEST FAILURE: CORRECT BEHAVIOR CANNOT BE GUARANTEED\n"); + return 0; } __initcall(stub_selftest); -- 2.30.2