Re: [PATCH v3 1/3] KVM: x86: kvm_x86_ops.get_exit_info should include the exit reason

From: David Edmondson
Date: Fri Jul 30 2021 - 03:30:03 EST


On Thursday, 2021-07-29 at 22:27:28 GMT, Sean Christopherson wrote:

> Shortlog is a bit odd, "should" is subjective and makes this sound like a bug fix.
>
> KVM: x86: Get exit_reason as part of kvm_x86_ops.get_exit_info

Okay.

> On Thu, Jul 29, 2021, David Edmondson wrote:
>> Extend the get_exit_info static call to provide the reason for the VM
>> exit. Modify relevant trace points to use this rather than extracting
>> the reason in the caller.
>>
>> Signed-off-by: David Edmondson <david.edmondson@xxxxxxxxxx>
>> ---
>> -static void svm_get_exit_info(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2,
>> +static void svm_get_exit_info(struct kvm_vcpu *vcpu, u64 *reason,
>> + u64 *info1, u64 *info2,
>> u32 *intr_info, u32 *error_code)
>> {
>> struct vmcb_control_area *control = &to_svm(vcpu)->vmcb->control;
>>
>> + *reason = control->exit_code;
>> *info1 = control->exit_info_1;
>> *info2 = control->exit_info_2;
>> *intr_info = control->exit_int_info;
>
> ...
>
>> diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h
>> index b484141ea15b..2228565beda2 100644
>> --- a/arch/x86/kvm/trace.h
>> +++ b/arch/x86/kvm/trace.h
>> @@ -273,11 +273,11 @@ TRACE_EVENT(kvm_apic,
>>
>> #define TRACE_EVENT_KVM_EXIT(name) \
>> TRACE_EVENT(name, \
>> - TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu, u32 isa), \
>> - TP_ARGS(exit_reason, vcpu, isa), \
>> + TP_PROTO(struct kvm_vcpu *vcpu, u32 isa), \
>> + TP_ARGS(vcpu, isa), \
>> \
>> TP_STRUCT__entry( \
>> - __field( unsigned int, exit_reason ) \
>> + __field( u64, exit_reason ) \
>
> Converting to a u64 is unnecessary and misleading. vmcs.EXIT_REASON and
> vmcb.EXIT_CODE are both u32s, a.k.a. unsigned ints. There is vmcb.EXIT_CODE_HI,
> but that's not being included, and AFAICT isn't even sanity checked by KVM.

Thanks for pointing this out, I can only blame brain fade.

>> __field( unsigned long, guest_rip ) \
>> __field( u32, isa ) \
>> __field( u64, info1 ) \