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
Showing the changes to include/uapi (1 of 4 files). Show all
Unified · Split
| @@ -918,6 +918,7 @@ struct kvm_enable_cap { · 917 unmodified lines | |||
| 918 | #define KVM_CAP_GUEST_MEMFD 234 | 918 | #define KVM_CAP_GUEST_MEMFD 234 |
| 919 | #define KVM_CAP_VM_TYPES 235 | 919 | #define KVM_CAP_VM_TYPES 235 |
| 920 | #define KVM_CAP_X86_APIC_BUS_CYCLES_NS 236 | 920 | #define KVM_CAP_X86_APIC_BUS_CYCLES_NS 236 |
| 921 | #define KVM_CAP_X86_GUEST_MODE 237 | ||
| 921 | 922 | ||
| 922 | struct kvm_irq_routing_irqchip { | 923 | struct kvm_irq_routing_irqchip { |
| 923 | __u32 irqchip; | 924 | __u32 irqchip; |