kvm: nVMX: VMCLEAR should not cause the vCPU to shut down
PATCH 1/1 kvm: nVMX: VMCLEAR should not cause the vCPU to shut down
VMCLEAR should silently ignore a failure to clear the launch state of the VMCS referenced by the operand.
--- arch/x86/kvm/vmx.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-)
arch/x86/kvm/vmx.c +4 -18
@@ -7259,9 +7259,8 @@ static int handle_vmoff(struct kvm_vcpu *vcpu)static int handle_vmclear (struct kvm_vcpu *vcpu) {struct vcpu_vmx *vmx =to_vmx (vcpu); +u32 zero =0 ;gpa_t vmptr; -struct vmcs12 *vmcs12; -struct page *page;if (!nested_vmx_check_permission (vcpu))return 1 ;
@@ -7272,22 +7271,9 @@ static int handle_vmclear(struct kvm_vcpu *vcpu)if (vmptr == vmx->nested.current_vmptr)nested_release_vmcs12 (vmx); - page =nested_get_page (vcpu, vmptr); -if (page ==NULL ) { -/* -* For accurate processor emulation, VMCLEAR beyond available -* physical memory should do nothing at all. However, it is -* possible that a nested vmx bug, not a guest hypervisor bug, -* resulted in this case, so let's shut down before doing any -* more damage: -*/ -kvm_make_request (KVM_REQ_TRIPLE_FAULT , vcpu); -return 1 ; - } - vmcs12 =kmap (page); - vmcs12->launch_state =0 ; -kunmap (page); -nested_release_page (page); +kvm_write_guest (vcpu->kvm, + vmptr + offsetof(struct vmcs12 , launch_state), + &zero,sizeof (zero));nested_free_vmcs02 (vmx, vmptr);
Signature · 1 line
2.12.0.rc1.440.g5b76565f74-goog
2017-03-02 12:41-0800, Jim Mattson:
Quoted 26 lines
VMCLEAR should silently ignore a failure to clear the launch state of the VMCS referenced by the operand.
Signed-off-by Jim Mattson <[email protected]>--- arch/x86/kvm/vmx.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-)arch/x86/kvm/vmx.c +1
-2@@ -7259,9 +7259,8 @@ static int handle_vmoff(struct kvm_vcpu *vcpu)static int handle_vmclear (struct kvm_vcpu *vcpu) {struct vcpu_vmx *vmx =to_vmx (vcpu); +u32 zero =0 ;gpa_t vmptr; -struct vmcs12 *vmcs12; -struct page *page;if (!nested_vmx_check_permission (vcpu))return 1 ;@@ -7272,22 +7271,9 @@ static int handle_vmclear(struct kvm_vcpu *vcpu)if (vmptr == vmx->nested.current_vmptr)nested_release_vmcs12 (vmx);
arch/x86/kvm/vmx.c static int handle_vmclear(struct kvm_vcpu *vcpu) · line 7283
Quoted 10 lines
arch/x86/kvm/vmx.c +0
-9- page =nested_get_page (vcpu, vmptr); -if (page ==NULL ) { -/* -* For accurate processor emulation, VMCLEAR beyond available -* physical memory should do nothing at all. However, it is -* possible that a nested vmx bug, not a guest hypervisor bug, -* resulted in this case, so let's shut down before doing any -* more damage: -*/
(Consciously introducing bugs in order to somewhat mitigate possible
bugs is not desirable.)
arch/x86/kvm/vmx.c static int handle_vmclear(struct kvm_vcpu *vcpu) · line 7274
Quoted 8 lines
arch/x86/kvm/vmx.c +1
-7-kvm_make_request (KVM_REQ_TRIPLE_FAULT , vcpu); -return 1 ; - } - vmcs12 =kmap (page); - vmcs12->launch_state =0 ; -kunmap (page); -nested_release_page (page); + kvm_write_guest(vcpu->kvm,
I have changed this line to
kvm_vcpu_write_guest(vcpu
and applied to kvm/queue (planning to merge in 4.11-rc2).
The change makes a difference if the guest is using VMX inside SMM and I don't see a reason to avoid the SMM address space in that case. Let me know what you think,
thanks.
arch/x86/kvm/vmx.c static int handle_vmclear(struct kvm_vcpu *vcpu) · line 7276
Quoted 2 lines
arch/x86/kvm/vmx.c +2
-0+ vmptr + offsetof(struct vmcs12 , launch_state), + &zero, sizeof(zero));
(Could have also been kvm_vcpu_write_guest_page(), but that is only
performance gain.)
Quoted 6 lines
arch/x86/kvm/vmx.c +0
-0nested_free_vmcs02 (vmx, vmptr);Signature · 1 line
2.12.0.rc1.440.g5b76565f74-goog
That sounds good to me.
Thanks!
--jim
Quoted 74 lines · Radim Krčmář
2017-03-02 12:41-0800, Jim Mattson:
Quoted 26 lines
VMCLEAR should silently ignore a failure to clear the launch state of the VMCS referenced by the operand.
Signed-off-by Jim Mattson <[email protected]>--- arch/x86/kvm/vmx.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-)arch/x86/kvm/vmx.c +1
-2@@ -7259,9 +7259,8 @@ static int handle_vmoff(struct kvm_vcpu *vcpu)static int handle_vmclear (struct kvm_vcpu *vcpu) {struct vcpu_vmx *vmx =to_vmx (vcpu); +u32 zero =0 ;gpa_t vmptr; -struct vmcs12 *vmcs12; -struct page *page;if (!nested_vmx_check_permission (vcpu))return 1 ;@@ -7272,22 +7271,9 @@ static int handle_vmclear(struct kvm_vcpu *vcpu)if (vmptr == vmx->nested.current_vmptr)nested_release_vmcs12 (vmx);arch/x86/kvm/vmx.c static int handle_vmclear(struct kvm_vcpu *vcpu) · line 7283
Quoted 10 lines
arch/x86/kvm/vmx.c +0
-9- page =nested_get_page (vcpu, vmptr); -if (page ==NULL ) { -/* -* For accurate processor emulation, VMCLEAR beyond available -* physical memory should do nothing at all. However, it is -* possible that a nested vmx bug, not a guest hypervisor bug, -* resulted in this case, so let's shut down before doing any -* more damage: -*/ (Consciously introducing bugs in order to somewhat mitigate possible
bugs is not desirable.)arch/x86/kvm/vmx.c static int handle_vmclear(struct kvm_vcpu *vcpu) · line 7274
Quoted 8 lines
arch/x86/kvm/vmx.c +1
-7-kvm_make_request (KVM_REQ_TRIPLE_FAULT , vcpu); -return 1 ; - } - vmcs12 =kmap (page); - vmcs12->launch_state =0 ; -kunmap (page); -nested_release_page (page); + kvm_write_guest(vcpu->kvm,I have changed this line to
kvm_vcpu_write_guest(vcpu
and applied to kvm/queue (planning to merge in 4.11-rc2).
The change makes a difference if the guest is using VMX inside SMM and I don't see a reason to avoid the SMM address space in that case. Let me know what you think,
thanks.
arch/x86/kvm/vmx.c static int handle_vmclear(struct kvm_vcpu *vcpu) · line 7276
Quoted 2 lines
arch/x86/kvm/vmx.c +2
-0+ vmptr + offsetof(struct vmcs12 , launch_state), + &zero, sizeof(zero));(Could have also been
kvm_vcpu_write_guest_page(), but that is only
performance gain.)Quoted 6 lines
arch/x86/kvm/vmx.c +0
-1nested_free_vmcs02 (vmx, vmptr); --2.12.0.rc1.440.g5b76565f74-goog