From: Paolo Bonzini <pbonzini@xxxxxxxxxx> The next patch will need to force AMD as the vendor. Do not pollute msr.flat with that; make a separate executable. Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx> Signed-off-by: Radim Krčmář <rkrcmar@xxxxxxxxxx> --- x86/Makefile.x86_64 | 1 + x86/msr.c | 19 ------------------- x86/syscall.c | 28 ++++++++++++++++++++++++++++ x86/unittests.cfg | 3 +++ 4 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 x86/syscall.c diff --git a/x86/Makefile.x86_64 b/x86/Makefile.x86_64 index 30f82a6aeeed..fd34cce5a286 100644 --- a/x86/Makefile.x86_64 +++ b/x86/Makefile.x86_64 @@ -12,6 +12,7 @@ tests = $(TEST_DIR)/access.flat $(TEST_DIR)/apic.flat \ $(TEST_DIR)/pcid.flat $(TEST_DIR)/debug.flat \ $(TEST_DIR)/ioapic.flat $(TEST_DIR)/memory.flat \ $(TEST_DIR)/pku.flat $(TEST_DIR)/hyperv_clock.flat +tests += $(TEST_DIR)/syscall.flat tests += $(TEST_DIR)/svm.flat tests += $(TEST_DIR)/vmx.flat tests += $(TEST_DIR)/tscdeadline_latency.flat diff --git a/x86/msr.c b/x86/msr.c index 1d4003144bb5..91351a3e4acd 100644 --- a/x86/msr.c +++ b/x86/msr.c @@ -94,23 +94,6 @@ static void test_msr_rw(int msr_index, unsigned long long input, unsigned long l report("%s", expected == r, sptr); } -static void test_syscall_lazy_load(void) -{ -#ifdef __x86_64__ - extern void syscall_target(); - u16 cs = read_cs(), ss = read_ss(); - ulong tmp; - - wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_SCE); - wrmsr(MSR_LSTAR, (ulong)syscall_target); - wrmsr(MSR_STAR, (uint64_t)cs << 32); - asm volatile("pushf; syscall; syscall_target: popf" : "=c"(tmp) : : "r11"); - write_ss(ss); - // will crash horribly if broken - report("MSR_*STAR eager loading", true); -#endif -} - int main(int ac, char **av) { int i, j; @@ -124,8 +107,6 @@ int main(int ac, char **av) } } - test_syscall_lazy_load(); - return report_summary(); } diff --git a/x86/syscall.c b/x86/syscall.c new file mode 100644 index 000000000000..d791edd6155d --- /dev/null +++ b/x86/syscall.c @@ -0,0 +1,28 @@ +/* msr tests */ + +#include "libcflat.h" +#include "processor.h" +#include "msr.h" +#include "desc.h" + +static void test_syscall_lazy_load(void) +{ + extern void syscall_target(); + u16 cs = read_cs(), ss = read_ss(); + ulong tmp; + + wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_SCE); + wrmsr(MSR_LSTAR, (ulong)syscall_target); + wrmsr(MSR_STAR, (uint64_t)cs << 32); + asm volatile("pushf; syscall; syscall_target: popf" : "=c"(tmp) : : "r11"); + write_ss(ss); + // will crash horribly if broken + report("MSR_*STAR eager loading", true); +} + +int main(int ac, char **av) +{ + test_syscall_lazy_load(); + + return report_summary(); +} diff --git a/x86/unittests.cfg b/x86/unittests.cfg index 3f3ad2a7daa5..2575ae6b3d5b 100644 --- a/x86/unittests.cfg +++ b/x86/unittests.cfg @@ -151,6 +151,9 @@ file = s3.flat [sieve] file = sieve.flat +[syscall] +file = syscall.flat + [tsc] file = tsc.flat extra_params = -cpu kvm64,+rdtscp -- 2.13.1