[Devel] [PATCH RHEL7 COMMIT] KVM: x86: Don't re-execute instruction when not passing CR2 value

Konstantin Khorenko khorenko at virtuozzo.com
Tue Nov 13 14:10:44 MSK 2018


The commit is pushed to "branch-rh7-3.10.0-862.20.2.vz7.73.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-862.20.2.vz7.73.3
------>
commit f71ad559618a89d336cafded7c73023313d08a88
Author: Liran Alon <liran.alon at oracle.com>
Date:   Thu Nov 8 19:31:37 2018 +0300

    KVM: x86: Don't re-execute instruction when not passing CR2 value
    
    In case of instruction-decode failure or emulation failure,
    x86_emulate_instruction() will call reexecute_instruction() which will
    attempt to use the cr2 value passed to x86_emulate_instruction().
    However, when x86_emulate_instruction() is called from
    emulate_instruction(), cr2 is not passed (passed as 0) and therefore
    it doesn't make sense to execute reexecute_instruction() logic at all.
    
    Fixes: 51d8b66199e9 ("KVM: cleanup emulate_instruction")
    
    Signed-off-by: Liran Alon <liran.alon at oracle.com>
    Reviewed-by: Nikita Leshenko <nikita.leshchenko at oracle.com>
    Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk at oracle.com>
    Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk at oracle.com>
    Reviewed-by: Wanpeng Li <wanpeng.li at hotmail.com>
    Signed-off-by: Radim Krčmář <rkrcmar at redhat.com>
    
    (cherry picked from commit 9b8ae63798cb97e785a667ff27e43fa6220cb734)
    https://jira.sw.ru/browse/PSBM-89859
    
    Signed-off-by: Roman Kagan <rkagan at virtuozzo.com>
---
 arch/x86/include/asm/kvm_host.h | 3 ++-
 arch/x86/kvm/vmx.c              | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 3f30c2e28007..e66f7b837904 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1125,7 +1125,8 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, unsigned long cr2,
 static inline int emulate_instruction(struct kvm_vcpu *vcpu,
 			int emulation_type)
 {
-	return x86_emulate_instruction(vcpu, 0, emulation_type, NULL, 0);
+	return x86_emulate_instruction(vcpu, 0,
+			emulation_type | EMULTYPE_NO_REEXECUTE, NULL, 0);
 }
 
 void kvm_enable_efer_bits(u64);
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 757d14ce4aff..caa5dc3030b2 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -6643,7 +6643,7 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)
 		if (test_bit(KVM_REQ_EVENT, &vcpu->requests))
 			return 1;
 
-		err = emulate_instruction(vcpu, EMULTYPE_NO_REEXECUTE);
+		err = emulate_instruction(vcpu, 0);
 
 		if (err == EMULATE_USER_EXIT) {
 			++vcpu->stat.mmio_exits;



More information about the Devel mailing list