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

From: Luc, Piotr
Date: Fri Oct 28 2016 - 06:13:12 EST


On Fri, 2016-10-28 at 17:12 +0800, He Chen wrote:
> The spec can be found in Intel Software Developer Manual or in
> Instruction Set Extensions Programming Reference.
>
> Signed-off-by: Luwei Kang <luwei.kang@xxxxxxxxx>
> Signed-off-by: He Chen <he.chen@xxxxxxxxxxxxxxx>
> ---
> Âarch/x86/kvm/cpuid.c | 7 ++++++-
> Â1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index afa7bbb..328b169 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -376,6 +376,10 @@ static inline int __do_cpuid_ent(struct
> kvm_cpuid_entry2 *entry, u32 function,
> Â /* cpuid 7.0.ecx*/
> Â const u32 kvm_cpuid_7_0_ecx_x86_features = F(PKU) | 0
> /*OSPKE*/;
> Â
> + /* cpuid 7.0.edx*/
> + const u32 kvm_cpuid_7_0_edx_x86_features =
> +ÂÂÂÂÂÂÂÂ0x4 /* AVX512-4VNNIW */ | 0x8 /* AVX512-4FMAPS */;
> +
> Â /* all calls to cpuid_count() should be made on the same cpu
> */
> Â get_cpu();
> Â
> @@ -458,12 +462,13 @@ static inline int __do_cpuid_ent(struct
> kvm_cpuid_entry2 *entry, u32 function,
> Â /* PKU is not yet implemented for shadow
> paging. */
> Â if (!tdp_enabled)
> Â entry->ecx &= ~F(PKU);
> +ÂÂÂÂÂÂÂÂÂÂÂÂentry->edx &= kvm_cpuid_7_0_edx_x86_features;

The cpu_mask() is missed here.
I understand that it doesn't work for this scattered features but the
bits in edx must be zeroed if corresponding flags were cleared in
fpu__xstate_clear_all_cpu_caps.
So this implies more work unfortunately.

> Â } else {
> Â entry->ebx = 0;
> Â entry->ecx = 0;
> +ÂÂÂÂÂÂÂÂÂÂÂÂentry->edx = 0;
> Â }
> Â entry->eax = 0;
> - entry->edx = 0;
> Â break;
> Â }
> Â case 9: