]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: x86: Trace re-injected exceptions
authorSean Christopherson <seanjc@google.com>
Sun, 1 May 2022 22:07:31 +0000 (00:07 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 8 Jun 2022 08:46:55 +0000 (04:46 -0400)
Trace exceptions that are re-injected, not just those that KVM is
injecting for the first time.  Debugging re-injection bugs is painful
enough as is, not having visibility into what KVM is doing only makes
things worse.

Delay propagating pending=>injected in the non-reinjection path so that
the tracing can properly identify reinjected exceptions.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
Message-Id: <25470690a38b4d2b32b6204875dd35676c65c9f2.1651440202.git.maciej.szmigiero@oracle.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/trace.h
arch/x86/kvm/x86.c

index de47625175692d2a158a01be381a4358fdef510a..d07428e660e3b5e4614f95ea6fb88c8fef731e99 100644 (file)
@@ -358,25 +358,29 @@ TRACE_EVENT(kvm_inj_virq,
  * Tracepoint for kvm interrupt injection:
  */
 TRACE_EVENT(kvm_inj_exception,
-       TP_PROTO(unsigned exception, bool has_error, unsigned error_code),
-       TP_ARGS(exception, has_error, error_code),
+       TP_PROTO(unsigned exception, bool has_error, unsigned error_code,
+                bool reinjected),
+       TP_ARGS(exception, has_error, error_code, reinjected),
 
        TP_STRUCT__entry(
                __field(        u8,     exception       )
                __field(        u8,     has_error       )
                __field(        u32,    error_code      )
+               __field(        bool,   reinjected      )
        ),
 
        TP_fast_assign(
                __entry->exception      = exception;
                __entry->has_error      = has_error;
                __entry->error_code     = error_code;
+               __entry->reinjected     = reinjected;
        ),
 
-       TP_printk("%s (0x%x)",
+       TP_printk("%s (0x%x)%s",
                  __print_symbolic(__entry->exception, kvm_trace_sym_exc),
                  /* FIXME: don't print error_code if not present */
-                 __entry->has_error ? __entry->error_code : 0)
+                 __entry->has_error ? __entry->error_code : 0,
+                 __entry->reinjected ? " [reinjected]" : "")
 );
 
 /*
index 921b1139c3030fb4c063d7f732e054ab61d97efc..c9f3ad89bf4c901c2c36e64a7c9b21176e16aa57 100644 (file)
@@ -9408,6 +9408,11 @@ int kvm_check_nested_events(struct kvm_vcpu *vcpu)
 
 static void kvm_inject_exception(struct kvm_vcpu *vcpu)
 {
+       trace_kvm_inj_exception(vcpu->arch.exception.nr,
+                               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_queue_exception)(vcpu);
@@ -9465,13 +9470,6 @@ static int inject_pending_event(struct kvm_vcpu *vcpu, bool *req_immediate_exit)
 
        /* try to inject new event if pending */
        if (vcpu->arch.exception.pending) {
-               trace_kvm_inj_exception(vcpu->arch.exception.nr,
-                                       vcpu->arch.exception.has_error_code,
-                                       vcpu->arch.exception.error_code);
-
-               vcpu->arch.exception.pending = false;
-               vcpu->arch.exception.injected = true;
-
                if (exception_type(vcpu->arch.exception.nr) == EXCPT_FAULT)
                        __kvm_set_rflags(vcpu, kvm_get_rflags(vcpu) |
                                             X86_EFLAGS_RF);
@@ -9485,6 +9483,10 @@ static int inject_pending_event(struct kvm_vcpu *vcpu, bool *req_immediate_exit)
                }
 
                kvm_inject_exception(vcpu);
+
+               vcpu->arch.exception.pending = false;
+               vcpu->arch.exception.injected = true;
+
                can_inject = false;
        }