Re: [PATCH 1/7] KVM: x86: add SPEC_CTRL and IBPB_SUPPORT accessors

From: Paolo Bonzini
Date: Tue Jan 09 2018 - 05:32:42 EST


On 08/01/2018 20:09, Liran Alon wrote:
>>
>> +static inline bool cpu_has_spec_ctrl(void)
>> +{
>> +ÂÂÂ u32 eax, ebx, ecx, edx;
>> +ÂÂÂ cpuid_count(7, 0, &eax, &ebx, &ecx, &edx);
>> +
>> +ÂÂÂ return edx & bit(KVM_CPUID_BIT_SPEC_CTRL);
>
> Why not just "return cpuid_edx(7) & bit(KVM_CPUID_BIT_SPEC_CTRL);"?
> This is also consistent with how cpu_has_ibpb_support() is written.

Leaf 7 explicitly requires you to clear ECX (there could be a leaf for
EAX=7,ECX=1 in the future). Even though cpuid_edx does do that, it's
not clear from the function that cpuid_edx(7) would work.

Paolo