KVM: x86: Clear "has_error_code", not "error_code", for RM exception injection
[linux-block.git] / arch / x86 / kvm / x86.c
index 45017576ad5efc9ba7b071edc352a8eec82c2e48..7d6f98b7635fcd2a95c6f4f9355f41e9913f456a 100644 (file)
@@ -9908,13 +9908,20 @@ int kvm_check_nested_events(struct kvm_vcpu *vcpu)
 
 static void kvm_inject_exception(struct kvm_vcpu *vcpu)
 {
+       /*
+        * Suppress the error code if the vCPU is in Real Mode, as Real Mode
+        * exceptions don't report error codes.  The presence of an error code
+        * is carried with the exception and only stripped when the exception
+        * is injected as intercepted #PF VM-Exits for AMD's Paged Real Mode do
+        * report an error code despite the CPU being in Real Mode.
+        */
+       vcpu->arch.exception.has_error_code &= is_protmode(vcpu);
+
        trace_kvm_inj_exception(vcpu->arch.exception.vector,
                                vcpu->arch.exception.has_error_code,
                                vcpu->arch.exception.error_code,
                                vcpu->arch.exception.injected);
 
-       if (vcpu->arch.exception.error_code && !is_protmode(vcpu))
-               vcpu->arch.exception.error_code = false;
        static_call(kvm_x86_inject_exception)(vcpu);
 }