> Why? We are implementing a para-virtualization hypervisor, which doesn't allow guest to trigger soft interrupt > 0x20(but `int 0x80` works fine), so I want to replace `int 0x20` with a more common `syscall`. > it's do_ring3() should really be rolled into this framework. Yes, it is worth working on it, I'll do it in my part-time. > no existing test verifies that KVM injects #UD on SYSCALL without EFER.SCE > set, though it would be nice to add one. I am also interested in it, maybe do it later. > > + wrmsr(MSR_STAR, ((u64)(USER_CS32 << 16) | KERNEL_CS) << 32); > It doesn't matter at this time because this framework doesn't ses SYSRET, but > this should be USER_CS or USER_CS64. Oops, intel SDM vol.3 <chap 5.8.8> says: """ When SYSRET transfers control to 64-bit mode user code using REX.W, the processor gets the privilege level 3 target code segment, instruction pointer, stack segment, and flags as follows: • Target code segment — Reads a non-NULL selector from IA32_STAR[63:48] + 16. • Stack segment — IA32_STAR[63:48] + 8. """ Since the value of USER_CS is 0x4b in 64 bit mode, SS register points to 0x53 = 0x4b + 8, (offset is 0x50) But `gdt + offset(0x50)` hasn't been setup(so does DS register). > refs: https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/blob/master/lib/x86/desc.c#L34 > refs: https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/blob/master/x86/syscall.c#L68 Linux also does so, the reason is to reuse user segment descriptor in both 32/64 bit. > refs1: https://github.com/torvalds/linux/blob/46cf2c613f4b10eb12f749207b0fd2c1bfae3088/arch/x86/kernel/cpu/common.c#L1942 > refs2: https://github.com/torvalds/linux/blob/46cf2c613f4b10eb12f749207b0fd2c1bfae3088/arch/x86/include/asm/segment.h#L211 > refs3: https://github.com/torvalds/linux/blob/46cf2c613f4b10eb12f749207b0fd2c1bfae3088/arch/x86/kernel/cpu/common.c#L216 > And a concrete reason not to apply this patch: it causes the nVMX #AC test to fail: It's awkward, some KUT test cases results diffs on my different machines, which makes me don't know which result I could trust, so I only pay attention to the test cases that I care about. I'll keep an eye on the rest cases in the future.