Skip to content

Commit 3e633e7

Browse files
Maxim Levitskysean-jc
authored andcommitted
KVM: x86: Add interrupt injection information to the kvm_entry tracepoint
Add VMX/SVM specific interrupt injection info the kvm_entry tracepoint. As is done with kvm_exit, gather the information via a kvm_x86_ops hook to avoid the moderately costly VMREADs on VMX when the tracepoint isn't enabled. Opportunistically rename the parameters in the get_exit_info() declaration to match the names used by both SVM and VMX. Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com> Link: https://lore.kernel.org/r/20240910200350.264245-2-mlevitsk@redhat.com [sean: drop is_guest_mode() change, use intr_info/error_code for names] Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 62e41f6 commit 3e633e7

File tree

7 files changed

+43
-3
lines changed

7 files changed

+43
-3
lines changed

arch/x86/include/asm/kvm-x86-ops.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ KVM_X86_OP(get_l2_tsc_multiplier)
100100
KVM_X86_OP(write_tsc_offset)
101101
KVM_X86_OP(write_tsc_multiplier)
102102
KVM_X86_OP(get_exit_info)
103+
KVM_X86_OP(get_entry_info)
103104
KVM_X86_OP(check_intercept)
104105
KVM_X86_OP(handle_exit_irqoff)
105106
KVM_X86_OP_OPTIONAL(update_cpu_dirty_logging)

arch/x86/include/asm/kvm_host.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,12 +1770,15 @@ struct kvm_x86_ops {
17701770
void (*write_tsc_multiplier)(struct kvm_vcpu *vcpu);
17711771

17721772
/*
1773-
* Retrieve somewhat arbitrary exit information. Intended to
1773+
* Retrieve somewhat arbitrary exit/entry information. Intended to
17741774
* be used only from within tracepoints or error paths.
17751775
*/
17761776
void (*get_exit_info)(struct kvm_vcpu *vcpu, u32 *reason,
17771777
u64 *info1, u64 *info2,
1778-
u32 *exit_int_info, u32 *exit_int_info_err_code);
1778+
u32 *intr_info, u32 *error_code);
1779+
1780+
void (*get_entry_info)(struct kvm_vcpu *vcpu,
1781+
u32 *intr_info, u32 *error_code);
17791782

17801783
int (*check_intercept)(struct kvm_vcpu *vcpu,
17811784
struct x86_instruction_info *info,

arch/x86/kvm/svm/svm.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3542,6 +3542,21 @@ static void svm_get_exit_info(struct kvm_vcpu *vcpu, u32 *reason,
35423542
*error_code = 0;
35433543
}
35443544

3545+
static void svm_get_entry_info(struct kvm_vcpu *vcpu, u32 *intr_info,
3546+
u32 *error_code)
3547+
{
3548+
struct vmcb_control_area *control = &to_svm(vcpu)->vmcb->control;
3549+
3550+
*intr_info = control->event_inj;
3551+
3552+
if ((*intr_info & SVM_EXITINTINFO_VALID) &&
3553+
(*intr_info & SVM_EXITINTINFO_VALID_ERR))
3554+
*error_code = control->event_inj_err;
3555+
else
3556+
*error_code = 0;
3557+
3558+
}
3559+
35453560
static int svm_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
35463561
{
35473562
struct vcpu_svm *svm = to_svm(vcpu);
@@ -5082,6 +5097,7 @@ static struct kvm_x86_ops svm_x86_ops __initdata = {
50825097
.required_apicv_inhibits = AVIC_REQUIRED_APICV_INHIBITS,
50835098

50845099
.get_exit_info = svm_get_exit_info,
5100+
.get_entry_info = svm_get_entry_info,
50855101

50865102
.vcpu_after_set_cpuid = svm_vcpu_after_set_cpuid,
50875103

arch/x86/kvm/trace.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,22 @@ TRACE_EVENT(kvm_entry,
2222
__field( unsigned int, vcpu_id )
2323
__field( unsigned long, rip )
2424
__field( bool, immediate_exit )
25+
__field( u32, intr_info )
26+
__field( u32, error_code )
2527
),
2628

2729
TP_fast_assign(
2830
__entry->vcpu_id = vcpu->vcpu_id;
2931
__entry->rip = kvm_rip_read(vcpu);
3032
__entry->immediate_exit = force_immediate_exit;
33+
34+
kvm_x86_call(get_entry_info)(vcpu, &__entry->intr_info,
35+
&__entry->error_code);
3136
),
3237

33-
TP_printk("vcpu %u, rip 0x%lx%s", __entry->vcpu_id, __entry->rip,
38+
TP_printk("vcpu %u, rip 0x%lx intr_info 0x%08x error_code 0x%08x%s",
39+
__entry->vcpu_id, __entry->rip,
40+
__entry->intr_info, __entry->error_code,
3441
__entry->immediate_exit ? "[immediate exit]" : "")
3542
);
3643

arch/x86/kvm/vmx/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ struct kvm_x86_ops vt_x86_ops __initdata = {
111111
.get_mt_mask = vmx_get_mt_mask,
112112

113113
.get_exit_info = vmx_get_exit_info,
114+
.get_entry_info = vmx_get_entry_info,
114115

115116
.vcpu_after_set_cpuid = vmx_vcpu_after_set_cpuid,
116117

arch/x86/kvm/vmx/vmx.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6194,6 +6194,15 @@ void vmx_get_exit_info(struct kvm_vcpu *vcpu, u32 *reason,
61946194
}
61956195
}
61966196

6197+
void vmx_get_entry_info(struct kvm_vcpu *vcpu, u32 *intr_info, u32 *error_code)
6198+
{
6199+
*intr_info = vmcs_read32(VM_ENTRY_INTR_INFO_FIELD);
6200+
if (is_exception_with_error_code(*intr_info))
6201+
*error_code = vmcs_read32(VM_ENTRY_EXCEPTION_ERROR_CODE);
6202+
else
6203+
*error_code = 0;
6204+
}
6205+
61976206
static void vmx_destroy_pml_buffer(struct vcpu_vmx *vmx)
61986207
{
61996208
if (vmx->pml_pg) {

arch/x86/kvm/vmx/x86_ops.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,11 @@ void vmx_load_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap);
104104
int vmx_set_tss_addr(struct kvm *kvm, unsigned int addr);
105105
int vmx_set_identity_map_addr(struct kvm *kvm, u64 ident_addr);
106106
u8 vmx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio);
107+
107108
void vmx_get_exit_info(struct kvm_vcpu *vcpu, u32 *reason,
108109
u64 *info1, u64 *info2, u32 *intr_info, u32 *error_code);
110+
void vmx_get_entry_info(struct kvm_vcpu *vcpu, u32 *intr_info, u32 *error_code);
111+
109112
u64 vmx_get_l2_tsc_offset(struct kvm_vcpu *vcpu);
110113
u64 vmx_get_l2_tsc_multiplier(struct kvm_vcpu *vcpu);
111114
void vmx_write_tsc_offset(struct kvm_vcpu *vcpu);

0 commit comments

Comments
 (0)