Re: [PATCH v2 00/14] KVM: x86: Remove emulation_result enums
From: Paolo Bonzini
Date: Wed Nov 06 2019 - 07:17:46 EST
On 06/11/19 01:58, Sean Christopherson wrote:
>> enum kvm_return {
>> KVM_RET_USER_EXIT = 0,
>> KVM_RET_GUEST = 1,
>> };
>>
>> and then consistently use them as return values? That way anyone who has not
>> worked on kvm before can still make sense of the code.
> Hmm, I think it'd make more sense to use #define instead of enum to
> hopefully make it clear that they aren't the *only* values that can be
> returned. That'd also prevent anyone from changing the return types from
> 'int' to 'enum kvm_return', which IMO would hurt readability overall.
>
> And maybe KVM_EXIT_TO_USERSPACE and KVM_RETURN_TO_GUEST?
That would be quite some work. Right now there is some consistency
between all of:
- x86_emulate_instruction and its callers
- vcpu->arch.complete_userspace_io
- vcpu_enter_guest/vcpu_block
- kvm_x86_ops->handle_exit
so it would be very easy to end up with a half-int-half-enum state that
is more confusing than before...
I'm more worried about cases where we have functions returning either 0
or -errno, but 0 lets you enter the guest. I'm not sure if the only one
is kvm_mmu_reload or there are others.
Paolo