Skip to content

Commit 6c41468

Browse files
sean-jcbonzini
authored andcommitted
KVM: x86: Clear "has_error_code", not "error_code", for RM exception injection
When injecting an exception into a vCPU in Real Mode, suppress the error code by clearing the flag that tracks whether the error code is valid, not by clearing the error code itself. The "typo" was introduced by recent fix for SVM's funky Paged Real Mode. Opportunistically hoist the logic above the tracepoint so that the trace is coherent with respect to what is actually injected (this was also the behavior prior to the buggy commit). Fixes: b97f074 ("KVM: x86: determine if an exception has an error code only when injecting it.") Cc: [email protected] Cc: Maxim Levitsky <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 0dc9022 commit 6c41468

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

arch/x86/kvm/x86.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9908,13 +9908,20 @@ int kvm_check_nested_events(struct kvm_vcpu *vcpu)
99089908

99099909
static void kvm_inject_exception(struct kvm_vcpu *vcpu)
99109910
{
9911+
/*
9912+
* Suppress the error code if the vCPU is in Real Mode, as Real Mode
9913+
* exceptions don't report error codes. The presence of an error code
9914+
* is carried with the exception and only stripped when the exception
9915+
* is injected as intercepted #PF VM-Exits for AMD's Paged Real Mode do
9916+
* report an error code despite the CPU being in Real Mode.
9917+
*/
9918+
vcpu->arch.exception.has_error_code &= is_protmode(vcpu);
9919+
99119920
trace_kvm_inj_exception(vcpu->arch.exception.vector,
99129921
vcpu->arch.exception.has_error_code,
99139922
vcpu->arch.exception.error_code,
99149923
vcpu->arch.exception.injected);
99159924

9916-
if (vcpu->arch.exception.error_code && !is_protmode(vcpu))
9917-
vcpu->arch.exception.error_code = false;
99189925
static_call(kvm_x86_inject_exception)(vcpu);
99199926
}
99209927

0 commit comments

Comments
 (0)