Skip to content

Commit eecf398

Browse files
committed
KVM: x86: Use '0' for guest RIP if PMI encounters protected guest state
Explicitly return '0' for guest RIP when handling a PMI VM-Exit for a vCPU with protected guest state, i.e. when KVM can't read the real RIP. While there is no "right" value, and profiling a protect guest is rather futile, returning the last known RIP is worse than returning obviously "bad" data. E.g. for SEV-ES+, the last known RIP will often point somewhere in the guest's boot flow. Opportunistically add WARNs to effectively assert that the in_kernel() and get_ip() callbacks are restricted to the common PMI handler, as the return values for the protected guest state case are largely arbitrary, i.e. only make any sense whatsoever for PMIs, where the returned values have no functional impact and thus don't truly matter. Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> Link: https://lore.kernel.org/r/20241009175002.1118178-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 1c932fc commit eecf398

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

arch/x86/kvm/x86.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13214,6 +13214,8 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
1321413214

1321513215
bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu)
1321613216
{
13217+
WARN_ON_ONCE(!kvm_arch_pmi_in_guest(vcpu));
13218+
1321713219
if (vcpu->arch.guest_state_protected)
1321813220
return true;
1321913221

@@ -13222,6 +13224,11 @@ bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu)
1322213224

1322313225
unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu)
1322413226
{
13227+
WARN_ON_ONCE(!kvm_arch_pmi_in_guest(vcpu));
13228+
13229+
if (vcpu->arch.guest_state_protected)
13230+
return 0;
13231+
1322513232
return kvm_rip_read(vcpu);
1322613233
}
1322713234

0 commit comments

Comments
 (0)