Skip to contentSkip to conversation

KVM: nVMX: Reset vmxon_ptr upon VMXOFF emulation.

PATCH In review Yu Zhang 3 participants 5 messages Sep 9, 2021

Subsystems (3)
lore
Share & tools
lore

Yu Zhang

author
#0 lore raw

PATCH 1/1 KVM: nVMX: Reset vmxon_ptr upon VMXOFF emulation.

From: Vitaly Kuznetsov <[email protected]>

Currently, 'vmx->nested.vmxon_ptr' is not reset upon VMXOFF emulation. This is not a problem per se as we never access it when !vmx->nested.vmxon. But this should be done to avoid any issue in the future.

Also, initialize the vmxon_ptr when vcpu is created.

---
 arch/x86/kvm/vmx/nested.c | 1 +
 arch/x86/kvm/vmx/vmx.c    | 1 +
 2 files changed, 2 insertions(+)
arch/x86/kvm/vmx/nested.c +1 -0
index 90f34f12f883..e4260f67caac 100644
@@ -289,6 +289,7 @@ static void free_nested(struct kvm_vcpu *vcpu)
 	kvm_clear_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu);
 
 	vmx->nested.vmxon = false;
+	vmx->nested.vmxon_ptr = -1ull;
 	vmx->nested.smm.vmxon = false;
 	free_vpid(vmx->nested.vpid02);
 	vmx->nested.posted_intr_nv = -1;
arch/x86/kvm/vmx/vmx.c +1 -0
index 0c2c0d5ae873..9a3e35c038f2 100644
@@ -6886,6 +6886,7 @@ static int vmx_create_vcpu(struct kvm_vcpu *vcpu)
 
 	vcpu_setup_sgx_lepubkeyhash(vcpu);
 
+	vmx->nested.vmxon_ptr = -1ull;
 	vmx->nested.posted_intr_nv = -1;
 	vmx->nested.current_vmptr = -1ull;
 	vmx->nested.hv_evmcs_vmptr = EVMPTR_INVALID;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 10 lines · Yu Zhang

From: Vitaly Kuznetsov <[email protected]>

Currently, 'vmx->nested.vmxon_ptr' is not reset upon VMXOFF emulation. This is not a problem per se as we never access it when !vmx->nested.vmxon. But this should be done to avoid any issue in the future.

Also, initialize the vmxon_ptr when vcpu is created.

Thanks but even Suggested-by: would be enough :-)

Quoted 30 lines
---
 arch/x86/kvm/vmx/nested.c | 1 +
 arch/x86/kvm/vmx/vmx.c    | 1 +
 2 files changed, 2 insertions(+)
arch/x86/kvm/vmx/nested.c +1 -0
index 90f34f12f883..e4260f67caac 100644
@@ -289,6 +289,7 @@ static void free_nested(struct kvm_vcpu *vcpu)
 	kvm_clear_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu);
 
 	vmx->nested.vmxon = false;
+	vmx->nested.vmxon_ptr = -1ull;
 	vmx->nested.smm.vmxon = false;
 	free_vpid(vmx->nested.vpid02);
 	vmx->nested.posted_intr_nv = -1;
arch/x86/kvm/vmx/vmx.c +1 -0
index 0c2c0d5ae873..9a3e35c038f2 100644
@@ -6886,6 +6886,7 @@ static int vmx_create_vcpu(struct kvm_vcpu *vcpu)
 
 	vcpu_setup_sgx_lepubkeyhash(vcpu);
 
+	vmx->nested.vmxon_ptr = -1ull;
 	vmx->nested.posted_intr_nv = -1;
 	vmx->nested.current_vmptr = -1ull;
 	vmx->nested.hv_evmcs_vmptr = EVMPTR_INVALID;
Signature · 1 line
Vitaly
author
#2 lore raw
Quoted 3 lines · Vitaly Kuznetsov

Thanks but even Suggested-by: would be enough :-)

I just copied your code. And actually I should be the one to say thanks. :)

B.R.
Yu

#3 lore raw
In reply to Yu Zhang
Quoted 21 lines · Yu Zhang

From: Vitaly Kuznetsov <[email protected]>

Currently, 'vmx->nested.vmxon_ptr' is not reset upon VMXOFF emulation. This is not a problem per se as we never access it when !vmx->nested.vmxon. But this should be done to avoid any issue in the future.

Also, initialize the vmxon_ptr when vcpu is created.

---
 arch/x86/kvm/vmx/nested.c | 1 +
 arch/x86/kvm/vmx/vmx.c    | 1 +
 2 files changed, 2 insertions(+)
arch/x86/kvm/vmx/nested.c +0 -0
index 90f34f12f883..e4260f67caac 100644

arch/x86/kvm/vmx/nested.c static void free_nested(struct kvm_vcpu *vcpu) · line 292

Quoted 4 lines
arch/x86/kvm/vmx/nested.c +1 -0
@@ -289,6 +289,7 @@ static void free_nested(struct kvm_vcpu *vcpu)
 	kvm_clear_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu);
 
 	vmx->nested.vmxon = false;
+	vmx->nested.vmxon_ptr = -1ull;

Looks like the "-1ull" comes from current_vmptr and friends, but using INVALID_GPA is more appropriate. It's the same value, but less arbitrary. The other usage of -1ull for guest physical addresses should really be cleaned up, too.

author
#4 lore raw
Quoted 24 lines · Sean Christopherson
Quoted 23 lines · Yu Zhang

From: Vitaly Kuznetsov <[email protected]>

Currently, 'vmx->nested.vmxon_ptr' is not reset upon VMXOFF emulation. This is not a problem per se as we never access it when !vmx->nested.vmxon. But this should be done to avoid any issue in the future.

Also, initialize the vmxon_ptr when vcpu is created.

---
 arch/x86/kvm/vmx/nested.c | 1 +
 arch/x86/kvm/vmx/vmx.c    | 1 +
 2 files changed, 2 insertions(+)
arch/x86/kvm/vmx/nested.c +0 -0
index 90f34f12f883..e4260f67caac 100644
@@ -289,6 +289,7 @@ static void free_nested(struct kvm_vcpu *vcpu)
 	kvm_clear_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu);
 
Quoted 7 lines

arch/x86/kvm/vmx/nested.c static void free_nested(struct kvm_vcpu *vcpu) · line 292

Quoted 2 lines
arch/x86/kvm/vmx/nested.c +1 -0
 	vmx->nested.vmxon = false;
+	vmx->nested.vmxon_ptr = -1ull;

Looks like the "-1ull" comes from current_vmptr and friends, but using INVALID_GPA is more appropriate. It's the same value, but less arbitrary. The other usage of -1ull for guest physical addresses should really be cleaned up, too.

Indeed. I guess many "-1ull"s will be replaced in nested.c.

We need another cleanup patch for this cleanup patch, which comes from my first cleanup patch to just clean some comments.. :-) Anyway, thanks!

B.R.
Yu