History

KVM: x86: Add KVM_RUN_X86_GUEST_MODE kvm_run flag

When a vCPU is interrupted by a signal while running a nested guest, KVM will exit to userspace with L2 state. However, userspace has no way to know whether it sees L1 or L2 state (besides calling KVM_GET_STATS_FD, which does not have a stable ABI). This causes multiple problems: The simplest one is L2 state corruption when userspace marks the sregs as dirty. See this mailing list thread [1] for a complete discussion. Another problem is that if userspace decides to continue by emulating instructions, it will unknowingly emulate with L2 state as if L1 doesn't exist, which can be considered a weird guest escape. Introduce a new flag, KVM_RUN_X86_GUEST_MODE, in the kvm_run data structure, which is set when the vCPU exited while running a nested guest. Also introduce a new capability, KVM_CAP_X86_GUEST_MODE, to advertise the functionality to userspace. [1] https://lore.kernel.org/kvm/20240416123558.212040-1-julian.stecklina@cyberus-technology.de/T/#m280aadcb2e10ae02c191a7dc4ed4b711a74b1f55

Thomas Prescher committed 2 years ago

Commit 85542ad1 parent 508f0c74 files · +22 −0Browse files

Showing the changes to include/uapi (1 of 4 files). Show all

Unified · Split

include/uapi/linux/kvm.h+1−0
@@ -918,6 +918,7 @@ struct kvm_enable_cap { · 917 unmodified lines
918918 #define KVM_CAP_GUEST_MEMFD 234
919919 #define KVM_CAP_VM_TYPES 235
920920 #define KVM_CAP_X86_APIC_BUS_CYCLES_NS 236
921+#define KVM_CAP_X86_GUEST_MODE 237
921922
922923 struct kvm_irq_routing_irqchip {
923924 __u32 irqchip;