KVM: nVMX: Fix VMX preemption timer migration
Subsystems (4)
PATCH v3 1/1 KVM: nVMX: Fix VMX preemption timer migration
From: Peter Shier <[email protected]>
Add new field to hold preemption timer remaining until expiration appended to struct kvm_vmx_nested_state_data. This is to prevent the first VM-Enter after migration from incorrectly restarting the timer with the full timer value instead of partially decayed timer value. KVM_SET_NESTED_STATE restarts timer using migrated state regardless of whether L1 sets VM_EXIT_SAVE_VMX_PREEMPTION_TIMER.
Fixes cf8b84f48a593 ("kvm: nVMX: Prepare for checkpointing L2 state")
Signed-off-by Peter Shier <[email protected]>
Signed-off-by Makarand Sonare <[email protected]>
Change-Id I6446aba5a547afa667f0ef4620b1b76115bf3753
--- Documentation/virt/kvm/api.rst | 4 ++ arch/x86/include/uapi/asm/kvm.h | 2 + arch/x86/kvm/vmx/nested.c | 58 +++++++++++++++++++++++---- arch/x86/kvm/vmx/vmx.h | 1 + arch/x86/kvm/x86.c | 1 + include/uapi/linux/kvm.h | 1 + tools/arch/x86/include/uapi/asm/kvm.h | 2 + 7 files changed, 62 insertions(+), 7 deletions(-)
Documentation/virt/kvm/api.rst +4 -0
@@ -4326,6 +4326,9 @@ Errors: #define KVM_STATE_NESTED_RUN_PENDING 0x00000002 #define KVM_STATE_NESTED_EVMCS 0x00000004 + /* Available with KVM_CAP_NESTED_STATE_PREEMPTION_TIMER */ + #define KVM_STATE_NESTED_PREEMPTION_TIMER 0x00000010 + #define KVM_STATE_NESTED_FORMAT_VMX 0 #define KVM_STATE_NESTED_FORMAT_SVM 1
@@ -4346,6 +4349,7 @@ Errors: struct kvm_vmx_nested_state_data { __u8 vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE]; __u8 shadow_vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE]; + __u32 preemption_timer_remaining; }; This ioctl copies the vcpu's nested virtualization state from the kernel to
arch/x86/include/uapi/asm/kvm.h +2 -0
@@ -391,6 +391,7 @@ struct kvm_sync_regs {#define KVM_STATE_NESTED_RUN_PENDING 0x00000002#define KVM_STATE_NESTED_EVMCS 0x00000004#define KVM_STATE_NESTED_MTF_PENDING 0x00000008 +#define KVM_STATE_NESTED_PREEMPTION_TIMER 0x00000010#define KVM_STATE_NESTED_SMM_GUEST_MODE 0x00000001#define KVM_STATE_NESTED_SMM_VMXON 0x00000002
@@ -400,6 +401,7 @@ struct kvm_sync_regs {struct kvm_vmx_nested_state_data {__u8 vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE ];__u8 shadow_vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE ]; +__u32 preemption_timer_remaining; };struct kvm_vmx_nested_state_hdr {
arch/x86/kvm/vmx/nested.c +51 -7
108 lines not on this page · raw message
arch/x86/kvm/vmx/vmx.h +1 -0
@@ -167,6 +167,7 @@ struct nested_vmx {u16 posted_intr_nv;struct hrtimer preemption_timer; +u32 preemption_timer_remaining;bool preemption_timer_expired;/* to migrate it to L2 if VM_ENTRY_LOAD_DEBUG_CONTROLS is off */
arch/x86/kvm/x86.c +1 -0
@@ -3374,6 +3374,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_GET_MSR_FEATURES :case KVM_CAP_MSR_PLATFORM_INFO :case KVM_CAP_EXCEPTION_PAYLOAD : +case KVM_CAP_NESTED_STATE_PREEMPTION_TIMER : r =1 ;break ;case KVM_CAP_SYNC_REGS :
include/uapi/linux/kvm.h +1 -0
@@ -1017,6 +1017,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_S390_VCPU_RESETS 179#define KVM_CAP_S390_PROTECTED 180#define KVM_CAP_PPC_SECURE_GUEST 181 +#define KVM_CAP_NESTED_STATE_PREEMPTION_TIMER 182#ifdef KVM_CAP_IRQ_ROUTING
tools/arch/x86/include/uapi/asm/kvm.h +2 -0
@@ -391,6 +391,8 @@ struct kvm_sync_regs {#define KVM_STATE_NESTED_RUN_PENDING 0x00000002#define KVM_STATE_NESTED_EVMCS 0x00000004#define KVM_STATE_NESTED_MTF_PENDING 0x00000008 +/* Available with KVM_CAP_NESTED_STATE_PREEMPTION_TIMER */ +#define KVM_STATE_NESTED_PREEMPTION_TIMER 0x00000010#define KVM_STATE_NESTED_SMM_GUEST_MODE 0x00000001#define KVM_STATE_NESTED_SMM_VMXON 0x00000002
Signature · 1 line
2.26.1.301.g55bc3eb7cb9-goog