Re: [PATCH] x86/cpuid: expose AVX512_4VNNIW and AVX512_4FMAPS features to kvm guest

From: He Chen
Date: Tue Nov 01 2016 - 03:49:45 EST


On Mon, Oct 31, 2016 at 12:41:32PM +0100, Paolo Bonzini wrote:
>
>
> On 31/10/2016 12:05, Borislav Petkov wrote:
> > On Mon, Oct 31, 2016 at 11:47:48AM +0100, Paolo Bonzini wrote:
> >> The information is all in arch/x86/kernel/cpu/scattered.c's cpuid_bits
> >> array. Borislav, would it be okay to export the cpuid_regs enum?
> >
> > Yeah, and kill the duplicated one in arch/x86/events/intel/pt.c too
> > please, while at it.
> >
> > I'd still put it all in arch/x86/kernel/cpu/scattered.c so that it is
> > close-by and call it from outside.
>
> Good. Chen, are you going to do this?
>

Sure.

Before sending a patch, let me check if my understanding is right...
I will add a helper in scattered.c like:

unsigned int get_scattered_cpuid_features(unsigned int level,
unsigned int sub_leaf, enum cpuid_regs reg)
{
u32 val = 0;
const struct cpuid_bit *cb;

for (cb = cpuid_bits; cb->feature; cb++) {

if (reg == cb->reg &&
level == cb->level &&
sub_leaf == cb->sub_leaf &&
boot_cpu_has(cb->feature))

val |= cb->bit;
}

return val;
}

And, when KVM wants to mask out features, it can be called outside like:

entry->edx &= kvm_cpuid_7_0_edx_x86_features;
entry->edx &= get_scatterd_cpuid_features(7, 0, CR_EDX);

Thanks,
-He