Commit 0f52e4aa authored by Sean Christopherson's avatar Sean Christopherson

KVM: selftests: Convert the MONITOR/MWAIT test to use printf guest asserts

Convert x86's MONITOR/MWAIT test to use printf-based guest asserts.  Add a
macro to handle reporting failures to reduce the amount of copy+paste
needed for MONITOR vs. MWAIT.

Link: https://lore.kernel.org/r/20230729003643.1053367-25-seanjc@google.comSigned-off-by: default avatarSean Christopherson <seanjc@google.com>
parent bf6c760b
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#define USE_GUEST_ASSERT_PRINTF 1
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -16,14 +18,25 @@ enum monitor_mwait_testcases { ...@@ -16,14 +18,25 @@ enum monitor_mwait_testcases {
MWAIT_DISABLED = BIT(2), MWAIT_DISABLED = BIT(2),
}; };
/*
* If both MWAIT and its quirk are disabled, MONITOR/MWAIT should #UD, in all
* other scenarios KVM should emulate them as nops.
*/
#define GUEST_ASSERT_MONITOR_MWAIT(insn, testcase, vector) \
do { \
bool fault_wanted = ((testcase) & MWAIT_QUIRK_DISABLED) && \
((testcase) & MWAIT_DISABLED); \
\
if (fault_wanted) \
__GUEST_ASSERT((vector) == UD_VECTOR, \
"Expected #UD on " insn " for testcase '0x%x', got '0x%x'", vector); \
else \
__GUEST_ASSERT(!(vector), \
"Expected success on " insn " for testcase '0x%x', got '0x%x'", vector); \
} while (0)
static void guest_monitor_wait(int testcase) static void guest_monitor_wait(int testcase)
{ {
/*
* If both MWAIT and its quirk are disabled, MONITOR/MWAIT should #UD,
* in all other scenarios KVM should emulate them as nops.
*/
bool fault_wanted = (testcase & MWAIT_QUIRK_DISABLED) &&
(testcase & MWAIT_DISABLED);
u8 vector; u8 vector;
GUEST_SYNC(testcase); GUEST_SYNC(testcase);
...@@ -33,16 +46,10 @@ static void guest_monitor_wait(int testcase) ...@@ -33,16 +46,10 @@ static void guest_monitor_wait(int testcase)
* intercept checks, so the inputs for MONITOR and MWAIT must be valid. * intercept checks, so the inputs for MONITOR and MWAIT must be valid.
*/ */
vector = kvm_asm_safe("monitor", "a"(guest_monitor_wait), "c"(0), "d"(0)); vector = kvm_asm_safe("monitor", "a"(guest_monitor_wait), "c"(0), "d"(0));
if (fault_wanted) GUEST_ASSERT_MONITOR_MWAIT("MONITOR", testcase, vector);
GUEST_ASSERT_2(vector == UD_VECTOR, testcase, vector);
else
GUEST_ASSERT_2(!vector, testcase, vector);
vector = kvm_asm_safe("mwait", "a"(guest_monitor_wait), "c"(0), "d"(0)); vector = kvm_asm_safe("mwait", "a"(guest_monitor_wait), "c"(0), "d"(0));
if (fault_wanted) GUEST_ASSERT_MONITOR_MWAIT("MWAIT", testcase, vector);
GUEST_ASSERT_2(vector == UD_VECTOR, testcase, vector);
else
GUEST_ASSERT_2(!vector, testcase, vector);
} }
static void guest_code(void) static void guest_code(void)
...@@ -85,7 +92,7 @@ int main(int argc, char *argv[]) ...@@ -85,7 +92,7 @@ int main(int argc, char *argv[])
testcase = uc.args[1]; testcase = uc.args[1];
break; break;
case UCALL_ABORT: case UCALL_ABORT:
REPORT_GUEST_ASSERT_2(uc, "testcase = %lx, vector = %ld"); REPORT_GUEST_ASSERT(uc);
goto done; goto done;
case UCALL_DONE: case UCALL_DONE:
goto done; goto done;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment