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

From: Borislav Petkov
Date: Tue Nov 01 2016 - 04:48:27 EST


On Tue, Nov 01, 2016 at 03:48:50PM +0800, He Chen wrote:
> 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++) {

Right, we can improve that by keeping cpuid_bit.level sorted so that you
can break out early if the level is exceeded. For that please sort it
and add a comment stating that the leaf should be kept sorted ontop of
it.

And then you do something like this:

u32 get_scattered_cpuid_leaf(unsigned int level, unsigned int sub_leaf,
enum cpuid_regs reg)
{
u32 cpuid_val = 0;

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

if (level < cb->level)
continue;

if (level > cb->level)
break;

if (cb->reg == reg && sub_leaf == cb->sub_leaf) {
if (cpu_has(cb->feature))
cpuid_val |= BIT(cb->bit);
}
}

return cpuid_val;
}

Completely untested, of course.

--
Regards/Gruss,
Boris.

ECO tip #101: Trim your mails when you reply.