KVM: x86: Get exit_reason as part of kvm_x86_ops.get_exit_info
authorDavid Edmondson <david.edmondson@oracle.com>
Mon, 20 Sep 2021 10:37:35 +0000 (11:37 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 25 Oct 2021 10:48:24 +0000 (06:48 -0400)
Extend the get_exit_info static call to provide the reason for the VM
exit. Modify relevant trace points to use this rather than extracting
the reason in the caller.

Signed-off-by: David Edmondson <david.edmondson@oracle.com>
Reviewed-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20210920103737.2696756-3-david.edmondson@oracle.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/svm/svm.c
arch/x86/kvm/trace.h
arch/x86/kvm/vmx/nested.c
arch/x86/kvm/vmx/vmx.c

index c8530ea136aa6824a3963edd021d410879697a04..0b8a9ea7a47b067f767e7dc50d761e202b6ed1b7 100644 (file)
@@ -1412,10 +1412,11 @@ struct kvm_x86_ops {
        void (*write_tsc_multiplier)(struct kvm_vcpu *vcpu, u64 multiplier);
 
        /*
-        * Retrieve somewhat arbitrary exit information.  Intended to be used
-        * only from within tracepoints to avoid VMREADs when tracing is off.
+        * Retrieve somewhat arbitrary exit information.  Intended to
+        * be used only from within tracepoints or error paths.
         */
-       void (*get_exit_info)(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2,
+       void (*get_exit_info)(struct kvm_vcpu *vcpu, u32 *reason,
+                             u64 *info1, u64 *info2,
                              u32 *exit_int_info, u32 *exit_int_info_err_code);
 
        int (*check_intercept)(struct kvm_vcpu *vcpu,
index a2a4e9b42750c2251efe6755c98e55ed4d7ed220..21bb81710e0f64485a0455040e0b51728ee05d62 100644 (file)
@@ -3362,11 +3362,13 @@ int svm_invoke_exit_handler(struct kvm_vcpu *vcpu, u64 exit_code)
        return svm_exit_handlers[exit_code](vcpu);
 }
 
-static void svm_get_exit_info(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2,
+static void svm_get_exit_info(struct kvm_vcpu *vcpu, u32 *reason,
+                             u64 *info1, u64 *info2,
                              u32 *intr_info, u32 *error_code)
 {
        struct vmcb_control_area *control = &to_svm(vcpu)->vmcb->control;
 
+       *reason = control->exit_code;
        *info1 = control->exit_info_1;
        *info2 = control->exit_info_2;
        *intr_info = control->exit_int_info;
@@ -3383,7 +3385,7 @@ static int handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
        struct kvm_run *kvm_run = vcpu->run;
        u32 exit_code = svm->vmcb->control.exit_code;
 
-       trace_kvm_exit(exit_code, vcpu, KVM_ISA_SVM);
+       trace_kvm_exit(vcpu, KVM_ISA_SVM);
 
        /* SEV-ES guests must use the CR write traps to track CR registers. */
        if (!sev_es_guest(vcpu->kvm)) {
@@ -3396,7 +3398,7 @@ static int handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
        if (is_guest_mode(vcpu)) {
                int vmexit;
 
-               trace_kvm_nested_vmexit(exit_code, vcpu, KVM_ISA_SVM);
+               trace_kvm_nested_vmexit(vcpu, KVM_ISA_SVM);
 
                vmexit = nested_svm_exit_special(svm);
 
index 03ebe368333efdc9ad7af0878b0f73fd8636424a..953b0fcb21ee85765c195caf57263dc98826d1ac 100644 (file)
@@ -288,8 +288,8 @@ TRACE_EVENT(kvm_apic,
 
 #define TRACE_EVENT_KVM_EXIT(name)                                          \
 TRACE_EVENT(name,                                                           \
-       TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu, u32 isa),  \
-       TP_ARGS(exit_reason, vcpu, isa),                                     \
+       TP_PROTO(struct kvm_vcpu *vcpu, u32 isa),                            \
+       TP_ARGS(vcpu, isa),                                                  \
                                                                             \
        TP_STRUCT__entry(                                                    \
                __field(        unsigned int,   exit_reason     )            \
@@ -303,11 +303,12 @@ TRACE_EVENT(name,                                                      \
        ),                                                                   \
                                                                             \
        TP_fast_assign(                                                      \
-               __entry->exit_reason    = exit_reason;                       \
                __entry->guest_rip      = kvm_rip_read(vcpu);                \
                __entry->isa            = isa;                               \
                __entry->vcpu_id        = vcpu->vcpu_id;                     \
-               static_call(kvm_x86_get_exit_info)(vcpu, &__entry->info1,    \
+               static_call(kvm_x86_get_exit_info)(vcpu,                     \
+                                         &__entry->exit_reason,             \
+                                         &__entry->info1,                   \
                                          &__entry->info2,                   \
                                          &__entry->intr_info,               \
                                          &__entry->error_code);             \
index af1bbb73430a9bba82efb70aba1fa70715865300..b4ee5e9f9e201d47b34b4aea25e5208a94c2b79c 100644 (file)
@@ -6066,7 +6066,7 @@ bool nested_vmx_reflect_vmexit(struct kvm_vcpu *vcpu)
                goto reflect_vmexit;
        }
 
-       trace_kvm_nested_vmexit(exit_reason.full, vcpu, KVM_ISA_VMX);
+       trace_kvm_nested_vmexit(vcpu, KVM_ISA_VMX);
 
        /* If L0 (KVM) wants the exit, it trumps L1's desires. */
        if (nested_vmx_l0_wants_exit(vcpu, exit_reason))
index c11688f64e80c64a25d35ca4d778fc4a2b3d71d2..85ce11dac8fdbcaa63b164d42fdb81fad7d013de 100644 (file)
@@ -5658,11 +5658,13 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = {
 static const int kvm_vmx_max_exit_handlers =
        ARRAY_SIZE(kvm_vmx_exit_handlers);
 
-static void vmx_get_exit_info(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2,
+static void vmx_get_exit_info(struct kvm_vcpu *vcpu, u32 *reason,
+                             u64 *info1, u64 *info2,
                              u32 *intr_info, u32 *error_code)
 {
        struct vcpu_vmx *vmx = to_vmx(vcpu);
 
+       *reason = vmx->exit_reason.full;
        *info1 = vmx_get_exit_qual(vcpu);
        if (!(vmx->exit_reason.failed_vmentry)) {
                *info2 = vmx->idt_vectoring_info;
@@ -6814,7 +6816,7 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu)
        if (likely(!vmx->exit_reason.failed_vmentry))
                vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
 
-       trace_kvm_exit(vmx->exit_reason.full, vcpu, KVM_ISA_VMX);
+       trace_kvm_exit(vcpu, KVM_ISA_VMX);
 
        if (unlikely(vmx->exit_reason.failed_vmentry))
                return EXIT_FASTPATH_NONE;