Skip to contentSkip to conversation

KVM: nVMX: fixes for preemption timer migration

PATCH Superseded Paolo Bonzini 3 participants 4 messages Jul 9, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Paolo Bonzini

author maintainer
#0 lore raw

PATCH 1/1 KVM: nVMX: fixes for preemption timer migration

Commit 850448f35aaf ("KVM: nVMX: Fix VMX preemption timer migration", 2020-06-01) accidentally broke nVMX live migration from older version by changing the userspace ABI. Restore it and, while at it, ensure that vmx->nested.has_preemption_timer_deadline is always initialized according to the KVM_STATE_VMX_PREEMPTION_TIMER_DEADLINE flag.

Cc Makarand Sonare <[email protected]>
Fixes 850448f35aaf ("KVM: nVMX: Fix VMX preemption timer migration")
---
 arch/x86/include/uapi/asm/kvm.h | 5 +++--
 arch/x86/kvm/vmx/nested.c       | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)
arch/x86/include/uapi/asm/kvm.h +3 -2
index 17c5a038f42d..0780f97c1850 100644
@@ -408,14 +408,15 @@ struct kvm_vmx_nested_state_data {
 };
 
 struct kvm_vmx_nested_state_hdr {
-	__u32 flags;
 	__u64 vmxon_pa;
 	__u64 vmcs12_pa;
-	__u64 preemption_timer_deadline;
 
 	struct {
 		__u16 flags;
 	} smm;
+
+	__u32 flags;
+	__u64 preemption_timer_deadline;
 };
 
 struct kvm_svm_nested_state_data {
arch/x86/kvm/vmx/nested.c +2 -1
index b26655104d4a..3fc2411edc92 100644
@@ -6180,7 +6180,8 @@ static int vmx_set_nested_state(struct kvm_vcpu *vcpu,
 		vmx->nested.has_preemption_timer_deadline = true;
 		vmx->nested.preemption_timer_deadline =
 			kvm_state->hdr.vmx.preemption_timer_deadline;
-	}
+	} else
+		vmx->nested.has_preemption_timer_deadline = false;
 
 	if (nested_vmx_check_controls(vcpu, vmcs12) ||
 	    nested_vmx_check_host_state(vcpu, vmcs12) ||
Signature · 1 line
2.26.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 42 lines · Paolo Bonzini

Commit 850448f35aaf ("KVM: nVMX: Fix VMX preemption timer migration", 2020-06-01) accidentally broke nVMX live migration from older version by changing the userspace ABI. Restore it and, while at it, ensure that vmx->nested.has_preemption_timer_deadline is always initialized according to the KVM_STATE_VMX_PREEMPTION_TIMER_DEADLINE flag.

Cc Makarand Sonare <[email protected]>
Fixes 850448f35aaf ("KVM: nVMX: Fix VMX preemption timer migration")
---
 arch/x86/include/uapi/asm/kvm.h | 5 +++--
 arch/x86/kvm/vmx/nested.c       | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)
arch/x86/include/uapi/asm/kvm.h +3 -2
index 17c5a038f42d..0780f97c1850 100644
@@ -408,14 +408,15 @@ struct kvm_vmx_nested_state_data {
 };
 
 struct kvm_vmx_nested_state_hdr {
-       __u32 flags;
        __u64 vmxon_pa;
        __u64 vmcs12_pa;
-       __u64 preemption_timer_deadline;
 
        struct {
                __u16 flags;
        } smm;
+
+       __u32 flags;
+       __u64 preemption_timer_deadline;
 };
 
 struct kvm_svm_nested_state_data {
arch/x86/kvm/vmx/nested.c +0 -0
index b26655104d4a..3fc2411edc92 100644

arch/x86/kvm/vmx/nested.c static int vmx_set_nested_state(struct kvm_vcpu *vcpu, · line 6184

Quoted 6 lines
arch/x86/kvm/vmx/nested.c +2 -1
@@ -6180,7 +6180,8 @@ static int vmx_set_nested_state(struct kvm_vcpu *vcpu,
                vmx->nested.has_preemption_timer_deadline = true;
                vmx->nested.preemption_timer_deadline =
                        kvm_state->hdr.vmx.preemption_timer_deadline;
-       }
+       } else
+               vmx->nested.has_preemption_timer_deadline = false;

Doesn't the coding standard require braces around the else clause?

author maintainer
#2 lore raw
Quoted 37 lines · Jim Mattson
Quoted 36 lines · Paolo Bonzini

Commit 850448f35aaf ("KVM: nVMX: Fix VMX preemption timer migration", 2020-06-01) accidentally broke nVMX live migration from older version by changing the userspace ABI. Restore it and, while at it, ensure that vmx->nested.has_preemption_timer_deadline is always initialized according to the KVM_STATE_VMX_PREEMPTION_TIMER_DEADLINE flag.

Cc Makarand Sonare <[email protected]>
Fixes 850448f35aaf ("KVM: nVMX: Fix VMX preemption timer migration")
---
 arch/x86/include/uapi/asm/kvm.h | 5 +++--
 arch/x86/kvm/vmx/nested.c       | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)
arch/x86/include/uapi/asm/kvm.h +3 -2
index 17c5a038f42d..0780f97c1850 100644
@@ -408,14 +408,15 @@ struct kvm_vmx_nested_state_data {
 };
 
 struct kvm_vmx_nested_state_hdr {
-       __u32 flags;
        __u64 vmxon_pa;
        __u64 vmcs12_pa;
-       __u64 preemption_timer_deadline;
 
        struct {
                __u16 flags;
        } smm;
+
+       __u32 flags;
+       __u64 preemption_timer_deadline;
 };
 
Quoted 14 lines

arch/x86/kvm/vmx/nested.c static int vmx_set_nested_state(struct kvm_vcpu *vcpu, · line 6184

Quoted 12 lines
arch/x86/include/uapi/asm/kvm.h +0 -0
 struct kvm_svm_nested_state_data {
arch/x86/kvm/vmx/nested.c +2 -1
index b26655104d4a..3fc2411edc92 100644
@@ -6180,7 +6180,8 @@ static int vmx_set_nested_state(struct kvm_vcpu *vcpu,
                vmx->nested.has_preemption_timer_deadline = true;
                vmx->nested.preemption_timer_deadline =
                        kvm_state->hdr.vmx.preemption_timer_deadline;
-       }
+       } else
+               vmx->nested.has_preemption_timer_deadline = false;

Doesn't the coding standard require braces around the else clause?

Yes, indeed.

Paolo

Quoted 2 lines
Reviewed-by
#3 lore raw
In reply to Jim Mattson
Quoted 29 lines · Jim Mattson
Quoted 28 lines · Paolo Bonzini

Commit 850448f35aaf ("KVM: nVMX: Fix VMX preemption timer migration", 2020-06-01) accidentally broke nVMX live migration from older version by changing the userspace ABI. Restore it and, while at it, ensure that vmx->nested.has_preemption_timer_deadline is always initialized according to the KVM_STATE_VMX_PREEMPTION_TIMER_DEADLINE flag.

Cc Makarand Sonare <[email protected]>
Fixes 850448f35aaf ("KVM: nVMX: Fix VMX preemption timer migration")
---
 arch/x86/include/uapi/asm/kvm.h | 5 +++--
 arch/x86/kvm/vmx/nested.c       | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)
arch/x86/include/uapi/asm/kvm.h +0 -2
index 17c5a038f42d..0780f97c1850 100644
@@ -408,14 +408,15 @@ struct kvm_vmx_nested_state_data {
 };
 
 struct kvm_vmx_nested_state_hdr {
-       __u32 flags;
        __u64 vmxon_pa;
        __u64 vmcs12_pa;
-       __u64 preemption_timer_deadline;
 
Quoted 8 lines

arch/x86/include/uapi/asm/kvm.h struct kvm_vmx_nested_state_data { · line 421

Quoted 8 lines
arch/x86/include/uapi/asm/kvm.h +3 -0
        struct {
                __u16 flags;
        } smm;
+
+       __u32 flags;
+       __u64 preemption_timer_deadline;
 };
 

Oops!

Quoted 6 lines
Quoted 6 lines
arch/x86/include/uapi/asm/kvm.h +0 -0
 struct kvm_svm_nested_state_data {
arch/x86/kvm/vmx/nested.c +0 -0
index b26655104d4a..3fc2411edc92 100644
@@ -6180,7 +6180,8 @@ static int vmx_set_nested_state(struct kvm_vcpu *vcpu,
Quoted 9 lines

arch/x86/kvm/vmx/nested.c static int vmx_set_nested_state(struct kvm_vcpu *vcpu, · line 6184

Quoted 6 lines
arch/x86/kvm/vmx/nested.c +2 -1
                vmx->nested.has_preemption_timer_deadline = true;
                vmx->nested.preemption_timer_deadline =
                        kvm_state->hdr.vmx.preemption_timer_deadline;
-       }
+       } else
+               vmx->nested.has_preemption_timer_deadline = false;

Doesn't the coding standard require braces around the else clause?

I think so... for if/else where at least one of them is multiline.

Quoted 1 line

Looks good to me,