KVM: x86: Do not use kvm_rip_read() unconditionally for KVM_PROFILING

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

authored by Adrian Hunter and committed by Paolo Bonzini 38e93267 ca4f113b

+2 -1
+2 -1
arch/x86/kvm/x86.c
··· 11098 /* 11099 * Profile KVM exit RIPs: 11100 */ 11101 - if (unlikely(prof_on == KVM_PROFILING)) { 11102 unsigned long rip = kvm_rip_read(vcpu); 11103 profile_hit(KVM_PROFILING, (void *)rip); 11104 }
··· 11098 /* 11099 * Profile KVM exit RIPs: 11100 */ 11101 + if (unlikely(prof_on == KVM_PROFILING && 11102 + !vcpu->arch.guest_state_protected)) { 11103 unsigned long rip = kvm_rip_read(vcpu); 11104 profile_hit(KVM_PROFILING, (void *)rip); 11105 }