Blame SOURCES/kvm-i386-do-kvm_put_msr_feature_control-first-thing-when.patch

586cba
From 8452a7925e18d6d57e2ac787b192097d4136b104 Mon Sep 17 00:00:00 2001
586cba
From: Vitaly Kuznetsov <vkuznets@redhat.com>
586cba
Date: Thu, 18 Aug 2022 17:01:13 +0200
586cba
Subject: [PATCH 2/2] i386: do kvm_put_msr_feature_control() first thing when
586cba
 vCPU is reset
586cba
586cba
RH-Author: Vitaly Kuznetsov <vkuznets@redhat.com>
586cba
RH-MergeRequest: 217: i386: fix 'system_reset' when the VM is in VMX root operation
586cba
RH-Bugzilla: 2117546
586cba
RH-Acked-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
586cba
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
586cba
RH-Acked-by: Peter Xu <peterx@redhat.com>
586cba
RH-Commit: [2/2] 08d5992691ba70561ce0a5b7f4504618f96a2ee6
586cba
586cba
kvm_put_sregs2() fails to reset 'locked' CR4/CR0 bits upon vCPU reset when
586cba
it is in VMX root operation. Do kvm_put_msr_feature_control() before
586cba
kvm_put_sregs2() to (possibly) kick vCPU out of VMX root operation. It also
586cba
seems logical to do kvm_put_msr_feature_control() before
586cba
kvm_put_nested_state() and not after it, especially when 'real' nested
586cba
state is set.
586cba
586cba
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
586cba
Message-Id: <20220818150113.479917-3-vkuznets@redhat.com>
586cba
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
586cba
(cherry picked from commit 45ed68a1a3a19754ade954d75a3c9d13ff560e5c)
586cba
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
586cba
---
586cba
 target/i386/kvm/kvm.c | 17 ++++++++++++-----
586cba
 1 file changed, 12 insertions(+), 5 deletions(-)
586cba
586cba
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
586cba
index 9feb98fe0b..ef70e2c85f 100644
586cba
--- a/target/i386/kvm/kvm.c
586cba
+++ b/target/i386/kvm/kvm.c
586cba
@@ -4356,6 +4356,18 @@ int kvm_arch_put_registers(CPUState *cpu, int level)
586cba
 
586cba
     assert(cpu_is_stopped(cpu) || qemu_cpu_is_self(cpu));
586cba
 
586cba
+    /*
586cba
+     * Put MSR_IA32_FEATURE_CONTROL first, this ensures the VM gets out of VMX
586cba
+     * root operation upon vCPU reset. kvm_put_msr_feature_control() should also
586cba
+     * preceed kvm_put_nested_state() when 'real' nested state is set.
586cba
+     */
586cba
+    if (level >= KVM_PUT_RESET_STATE) {
586cba
+        ret = kvm_put_msr_feature_control(x86_cpu);
586cba
+        if (ret < 0) {
586cba
+            return ret;
586cba
+        }
586cba
+    }
586cba
+
586cba
     /* must be before kvm_put_nested_state so that EFER.SVME is set */
586cba
     ret = has_sregs2 ? kvm_put_sregs2(x86_cpu) : kvm_put_sregs(x86_cpu);
586cba
     if (ret < 0) {
586cba
@@ -4367,11 +4379,6 @@ int kvm_arch_put_registers(CPUState *cpu, int level)
586cba
         if (ret < 0) {
586cba
             return ret;
586cba
         }
586cba
-
586cba
-        ret = kvm_put_msr_feature_control(x86_cpu);
586cba
-        if (ret < 0) {
586cba
-            return ret;
586cba
-        }
586cba
     }
586cba
 
586cba
     if (level == KVM_PUT_FULL_STATE) {
586cba
-- 
586cba
2.31.1
586cba