Re: [PATCH 16/61] KVM: x86: Encapsulate CPUID entries and metadata in struct

From: Vitaly Kuznetsov
Date: Mon Feb 24 2020 - 18:12:29 EST


Sean Christopherson <sean.j.christopherson@xxxxxxxxx> writes:

> On Fri, Feb 21, 2020 at 03:58:47PM +0100, Vitaly Kuznetsov wrote:
>> Sean Christopherson <sean.j.christopherson@xxxxxxxxx> writes:
>>
>
>> > + if (!entry)
>> > goto out;
>> > }
>> > break;
>> > @@ -802,22 +814,22 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
>> > return r;
>> > }
>> >
>> > -static int do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 func,
>> > - int *nent, int maxnent, unsigned int type)
>> > +static int do_cpuid_func(struct kvm_cpuid_array *array, u32 func,
>> > + unsigned int type)
>> > {
>> > - if (*nent >= maxnent)
>> > + if (array->nent >= array->maxnent)
>> > return -E2BIG;
>> >
>> > if (type == KVM_GET_EMULATED_CPUID)
>> > - return __do_cpuid_func_emulated(entry, func, nent, maxnent);
>> > + return __do_cpuid_func_emulated(array, func);
>>
>> Would it make sense to move 'if (array->nent >= array->maxnent)' check
>> to __do_cpuid_func_emulated() to match do_host_cpuid()?
>
> I considered doing exactly that. IIRC, I opted not to because at this
> point in the series, the initial call to do_host_cpuid() is something like
> halfway down the massive __do_cpuid_func(), and eliminating the early check
> didn't feel quite right, e.g. there is a fair amount of unnecessary code
> that runs before hitting the first do_host_cpuid().
>
> What if I add a patch towards the end of the series to move this check into
> __do_cpuid_func_emulated(), i.e. after __do_cpuid_func() has been trimmed
> down to size and the early check really is superfluous.
>

Works for me, thanks!

--
Vitaly