Skip to content

Commit 4504b5c

Browse files
Luwei Kangrkrcmar
authored andcommitted
kvm: x86: Add AVX512_4VNNIW and AVX512_4FMAPS support
Add two new AVX512 subfeatures support for KVM guest. AVX512_4VNNIW: Vector instructions for deep learning enhanced word variable precision. AVX512_4FMAPS: Vector instructions for deep learning floating-point single precision. Reviewed-by: Borislav Petkov <[email protected]> Signed-off-by: He Chen <[email protected]> Signed-off-by: Luwei Kang <[email protected]> [Changed subject tags.] Signed-off-by: Radim Krčmář <[email protected]>
1 parent 283c95d commit 4504b5c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

arch/x86/kvm/cpuid.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/export.h>
1717
#include <linux/vmalloc.h>
1818
#include <linux/uaccess.h>
19+
#include <asm/processor.h>
1920
#include <asm/fpu/internal.h> /* For use_eager_fpu. Ugh! */
2021
#include <asm/user.h>
2122
#include <asm/fpu/xstate.h>
@@ -65,6 +66,11 @@ u64 kvm_supported_xcr0(void)
6566

6667
#define F(x) bit(X86_FEATURE_##x)
6768

69+
/* These are scattered features in cpufeatures.h. */
70+
#define KVM_CPUID_BIT_AVX512_4VNNIW 2
71+
#define KVM_CPUID_BIT_AVX512_4FMAPS 3
72+
#define KF(x) bit(KVM_CPUID_BIT_##x)
73+
6874
int kvm_update_cpuid(struct kvm_vcpu *vcpu)
6975
{
7076
struct kvm_cpuid_entry2 *best;
@@ -376,6 +382,10 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
376382
/* cpuid 7.0.ecx*/
377383
const u32 kvm_cpuid_7_0_ecx_x86_features = F(PKU) | 0 /*OSPKE*/;
378384

385+
/* cpuid 7.0.edx*/
386+
const u32 kvm_cpuid_7_0_edx_x86_features =
387+
KF(AVX512_4VNNIW) | KF(AVX512_4FMAPS);
388+
379389
/* all calls to cpuid_count() should be made on the same cpu */
380390
get_cpu();
381391

@@ -458,12 +468,14 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
458468
/* PKU is not yet implemented for shadow paging. */
459469
if (!tdp_enabled)
460470
entry->ecx &= ~F(PKU);
471+
entry->edx &= kvm_cpuid_7_0_edx_x86_features;
472+
entry->edx &= get_scattered_cpuid_leaf(7, 0, CPUID_EDX);
461473
} else {
462474
entry->ebx = 0;
463475
entry->ecx = 0;
476+
entry->edx = 0;
464477
}
465478
entry->eax = 0;
466-
entry->edx = 0;
467479
break;
468480
}
469481
case 9:

0 commit comments

Comments
 (0)