[Devel,RHEL7,COMMIT] ms/KVM: x86: reset MMU on KVM_SET_VCPU_EVENTS

Submitted by Konstantin Khorenko on March 31, 2017, 12:58 p.m.

Details

Message ID 201703311258.v2VCwA29000679@finist_cl7.x64_64.work.ct
State New
Series "KVM: x86: reset MMU on KVM_SET_VCPU_EVENTS"
Headers show

Commit Message

Konstantin Khorenko March 31, 2017, 12:58 p.m.
The commit is pushed to "branch-rh7-3.10.0-514.10.2.vz7.29.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-514.10.2.vz7.29.9
------>
commit b36e7eda7523c63eac6cc524191c38b9ab9e7177
Author: Xiao Guangrong <guangrong.xiao@linux.intel.com>
Date:   Sat Dec 24 10:00:42 2016 +0100

    ms/KVM: x86: reset MMU on KVM_SET_VCPU_EVENTS
    
    Otherwise, mismatch between the smm bit in hflags and the MMU role
    can cause a NULL pointer dereference.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    (cherry picked from commit 6ef4e07ecd2db21025c446327ecf34414366498b)
    
    https://jira.sw.ru/browse/PSBM-62341
    
    Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
---
 arch/x86/kvm/x86.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 81104d2..e692050 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3184,6 +3184,8 @@  static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu,
 	memset(&events->reserved, 0, sizeof(events->reserved));
 }
 
+static void kvm_set_hflags(struct kvm_vcpu *vcpu, unsigned emul_flags);
+
 static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
 					      struct kvm_vcpu_events *events)
 {
@@ -3220,10 +3222,13 @@  static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
 		vcpu->arch.apic->sipi_vector = events->sipi_vector;
 
 	if (events->flags & KVM_VCPUEVENT_VALID_SMM) {
+		u32 hflags = vcpu->arch.hflags;
 		if (events->smi.smm)
-			vcpu->arch.hflags |= HF_SMM_MASK;
+			hflags |= HF_SMM_MASK;
 		else
-			vcpu->arch.hflags &= ~HF_SMM_MASK;
+			hflags &= ~HF_SMM_MASK;
+		kvm_set_hflags(vcpu, hflags);
+
 		vcpu->arch.smi_pending = events->smi.pending;
 		if (events->smi.smm_inside_nmi)
 			vcpu->arch.hflags |= HF_SMM_INSIDE_NMI_MASK;