Skip to content

Commit ca4f113

Browse files
ahunter6bonzini
authored andcommitted
KVM: x86: Do not use kvm_rip_read() unconditionally in KVM tracepoints
Not all VMs allow access to RIP. Check guest_state_protected before calling kvm_rip_read(). This avoids, for example, hitting WARN_ON_ONCE in vt_cache_reg() for TDX VMs. Fixes: 81bf912b2c15 ("KVM: TDX: Implement TDX vcpu enter/exit path") Signed-off-by: Adrian Hunter <[email protected]> Message-ID: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 268cbfe commit ca4f113

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

arch/x86/kvm/trace.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
#undef TRACE_SYSTEM
1212
#define TRACE_SYSTEM kvm
1313

14+
#ifdef CREATE_TRACE_POINTS
15+
#define tracing_kvm_rip_read(vcpu) ({ \
16+
typeof(vcpu) __vcpu = vcpu; \
17+
__vcpu->arch.guest_state_protected ? 0 : kvm_rip_read(__vcpu); \
18+
})
19+
#endif
20+
1421
/*
1522
* Tracepoint for guest mode entry.
1623
*/
@@ -28,7 +35,7 @@ TRACE_EVENT(kvm_entry,
2835

2936
TP_fast_assign(
3037
__entry->vcpu_id = vcpu->vcpu_id;
31-
__entry->rip = kvm_rip_read(vcpu);
38+
__entry->rip = tracing_kvm_rip_read(vcpu);
3239
__entry->immediate_exit = force_immediate_exit;
3340

3441
kvm_x86_call(get_entry_info)(vcpu, &__entry->intr_info,
@@ -319,7 +326,7 @@ TRACE_EVENT(name, \
319326
), \
320327
\
321328
TP_fast_assign( \
322-
__entry->guest_rip = kvm_rip_read(vcpu); \
329+
__entry->guest_rip = tracing_kvm_rip_read(vcpu); \
323330
__entry->isa = isa; \
324331
__entry->vcpu_id = vcpu->vcpu_id; \
325332
__entry->requests = READ_ONCE(vcpu->requests); \
@@ -423,7 +430,7 @@ TRACE_EVENT(kvm_page_fault,
423430

424431
TP_fast_assign(
425432
__entry->vcpu_id = vcpu->vcpu_id;
426-
__entry->guest_rip = kvm_rip_read(vcpu);
433+
__entry->guest_rip = tracing_kvm_rip_read(vcpu);
427434
__entry->fault_address = fault_address;
428435
__entry->error_code = error_code;
429436
),

0 commit comments

Comments
 (0)