x86: Testcase for wrong TF handling in syscall/sysret
cover x86: Testcase for wrong TF handling in syscall/sysret
Patch 1 creates a new testcase executable, and patch 2 tests the bug.
Paolo Bonzini (2):
x86: move syscall MSR testcase to separate test
x86: add testcase for syscall/sysret TF handling
lib/x86/processor.h | 4 ++ x86/Makefile.x86_64 | 1 + x86/msr.c | 19 --------- x86/syscall.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++ x86/unittests.cfg | 4 ++ 5 files changed, 117 insertions(+), 19 deletions(-) create mode 100644 x86/syscall.c
Signature · 1 line
2.13.1
PATCH 1/2 x86: move syscall MSR testcase to separate test
From: Paolo Bonzini <[email protected]>
The next patch will need to force AMD as the vendor. Do not pollute msr.flat with that; make a separate executable.
--- 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
x86/Makefile.x86_64 +1 -0
@@ -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
x86/msr.c +0 -19
@@ -94,23 +94,6 @@ static void test_msr_rw(int msr_index, unsigned long long input, unsigned long lreport ("%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 ); - asmvolatile ("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 (); }
x86/syscall.c new file +28 -0
@@ -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 ); + asmvolatile ("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 (); +}
x86/unittests.cfg +3 -0
@@ -151,6 +151,9 @@ file = s3.flat [sieve] file = sieve.flat +[syscall] +file = syscall.flat + [tsc] file = tsc.flat extra_params = -cpu kvm64,+rdtscp
Signature · 1 line
2.13.1
PATCH 2/2 x86: add testcase for syscall/sysret TF handling
In reply to Radim KrčmářFrom: Paolo Bonzini <[email protected]>
--- lib/x86/processor.h | 4 +++ x86/syscall.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ x86/unittests.cfg | 1 + 3 files changed, 85 insertions(+)
lib/x86/processor.h +4 -0
@@ -35,7 +35,11 @@#define X86_EFLAGS_AF 0x00000010#define X86_EFLAGS_ZF 0x00000040#define X86_EFLAGS_SF 0x00000080 +#define X86_EFLAGS_TF 0x00000100 +#define X86_EFLAGS_IF 0x00000200 +#define X86_EFLAGS_DF 0x00000400#define X86_EFLAGS_OF 0x00000800 +#define X86_EFLAGS_NT 0x00004000#define X86_EFLAGS_AC 0x00040000#define X86_IA32_EFER 0xc0000080
x86/syscall.c +80 -0
89 lines not on this page · raw message
x86/unittests.cfg +1 -0
@@ -153,6 +153,7 @@ file = sieve.flat [syscall] file = syscall.flat +extra_params = -cpu Opteron_G1,vendor=AuthenticAMD [tsc] file = tsc.flat
Signature · 1 line
2.13.1
2017-06-22 23:27 GMT+08:00 Radim Krčmář <[email protected]>:
Quoted 5 lines
Patch 1 creates a new testcase executable, and patch 2 tests the bug.
Paolo Bonzini (2):
x86: move syscall MSR testcase to separate test
x86: add testcase for syscall/sysret TF handling
./x86-run x86/syscall.flat
qemu-system-i386 -nodefaults -device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4 --enable-kvm -vnc none -serial stdio -device pci-testdev -machine accel=kvm -kernel x86/syscall.flat enabling apic
PASS: MSR_*STAR eager loading
Unhandled exception 6 #UD at ip 000000000040036e
error_code=0000 rflags=00010046 cs=0000003b
rax=0000000000000146 rcx=0000000000400365 rdx=0000000000000001 rbx=00000000c0000080
rbp=000000000044df80 rsi=0000000000400372 rdi=0000000000000001 r8=000000000040c70c r9=00000000000003f8 r10=0000000000000002 r11=0000000000000046
r12=00000000c0000081 r13=00000097cfdff1ab r14=00000097d130aad0 r15=0000000000000002
cr0=0000000080000011 cr2=0000000000000000 cr3=0000000000409000 cr4=0000000000000020
cr8=0000000000000000
STACK: @40036e 4002a2
I can encounter this w/ -cpu host or w/o -cpu host for both qemu-system-i386 and qemu-system-x86_64.
Regards,
Wanpeng Li
Quoted 12 lines
lib/x86/processor.h | 4 ++ x86/Makefile.x86_64 | 1 + x86/msr.c | 19 --------- x86/syscall.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++ x86/unittests.cfg | 4 ++ 5 files changed, 117 insertions(+), 19 deletions(-) create mode 100644 x86/syscall.c--
2.13.1
Paolo Bonzini
maintainerQuoted 27 lines · Wanpeng Li
2017-06-22 23:27 GMT+08:00 Radim Krčmář <[email protected]>:
Quoted 5 lines
Patch 1 creates a new testcase executable, and patch 2 tests the bug.
Paolo Bonzini (2):
x86: move syscall MSR testcase to separate test
x86: add testcase for syscall/sysret TF handling./x86-run x86/syscall.flat
qemu-system-i386 -nodefaults -device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4 --enable-kvm -vnc none -serial stdio -device pci-testdev -machine accel=kvm -kernel x86/syscall.flat enabling apic
PASS: MSR_*STAR eager loading
Unhandled exception 6 #UD at ip000000000040036e
error_code=0000 rflags=00010046 cs=0000003b
rax=0000000000000146 rcx=0000000000400365 rdx=0000000000000001 rbx=00000000c0000080
rbp=000000000044df80 rsi=0000000000400372 rdi=0000000000000001 r8=000000000040c70c r9=00000000000003f8 r10=0000000000000002 r11=0000000000000046
r12=00000000c0000081 r13=00000097cfdff1ab r14=00000097d130aad0 r15=0000000000000002
cr0=0000000080000011 cr2=0000000000000000 cr3=0000000000409000 cr4=0000000000000020
cr8=0000000000000000
STACK: @40036e 4002a2
Quoted 2 lines
I can encounter this w/ -cpu host or w/o -cpu host for both qemu-system-i386 and qemu-system-x86_64.
Correct. From x86/unittests.cfg:
[syscall]
file = syscall.flatextra_params = -cpu Opteron_G1,vendor=AuthenticAMD
Paolo