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 <adrian.hunter@intel.com>
Message-ID: <20250415104821.247234-2-adrian.hunter@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by Adrian Hunter and committed by Paolo Bonzini ca4f113b 268cbfe6

+10 -3
+10 -3
arch/x86/kvm/trace.h
··· 11 #undef TRACE_SYSTEM 12 #define TRACE_SYSTEM kvm 13 14 /* 15 * Tracepoint for guest mode entry. 16 */ ··· 35 36 TP_fast_assign( 37 __entry->vcpu_id = vcpu->vcpu_id; 38 - __entry->rip = kvm_rip_read(vcpu); 39 __entry->immediate_exit = force_immediate_exit; 40 41 kvm_x86_call(get_entry_info)(vcpu, &__entry->intr_info, ··· 326 ), \ 327 \ 328 TP_fast_assign( \ 329 - __entry->guest_rip = kvm_rip_read(vcpu); \ 330 __entry->isa = isa; \ 331 __entry->vcpu_id = vcpu->vcpu_id; \ 332 __entry->requests = READ_ONCE(vcpu->requests); \ ··· 430 431 TP_fast_assign( 432 __entry->vcpu_id = vcpu->vcpu_id; 433 - __entry->guest_rip = kvm_rip_read(vcpu); 434 __entry->fault_address = fault_address; 435 __entry->error_code = error_code; 436 ),
··· 11 #undef TRACE_SYSTEM 12 #define TRACE_SYSTEM kvm 13 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 + 21 /* 22 * Tracepoint for guest mode entry. 23 */ ··· 28 29 TP_fast_assign( 30 __entry->vcpu_id = vcpu->vcpu_id; 31 + __entry->rip = tracing_kvm_rip_read(vcpu); 32 __entry->immediate_exit = force_immediate_exit; 33 34 kvm_x86_call(get_entry_info)(vcpu, &__entry->intr_info, ··· 319 ), \ 320 \ 321 TP_fast_assign( \ 322 + __entry->guest_rip = tracing_kvm_rip_read(vcpu); \ 323 __entry->isa = isa; \ 324 __entry->vcpu_id = vcpu->vcpu_id; \ 325 __entry->requests = READ_ONCE(vcpu->requests); \ ··· 423 424 TP_fast_assign( 425 __entry->vcpu_id = vcpu->vcpu_id; 426 + __entry->guest_rip = tracing_kvm_rip_read(vcpu); 427 __entry->fault_address = fault_address; 428 __entry->error_code = error_code; 429 ),