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