Skip to content

Commit 1c450ff

Browse files
taosu-linuxsean-jc
authored andcommitted
KVM: x86: Advertise AVX10.1 CPUID to userspace
Advertise AVX10.1 related CPUIDs, i.e. report AVX10 support bit via CPUID.(EAX=07H, ECX=01H):EDX[bit 19] and new CPUID leaf 0x24H so that guest OS and applications can query the AVX10.1 CPUIDs directly. Intel AVX10 represents the first major new vector ISA since the introduction of Intel AVX512, which will establish a common, converged vector instruction set across all Intel architectures[1]. AVX10.1 is an early version of AVX10, that enumerates the Intel AVX512 instruction set at 128, 256, and 512 bits which is enabled on Granite Rapids. I.e., AVX10.1 is only a new CPUID enumeration with no new functionality. New features, e.g. Embedded Rounding and Suppress All Exceptions (SAE) will be introduced in AVX10.2. Advertising AVX10.1 is safe because there is nothing to enable for AVX10.1, i.e. it's purely a new way to enumerate support, thus there will never be anything for the kernel to enable. Note just the CPUID checking is changed when using AVX512 related instructions, e.g. if using one AVX512 instruction needs to check (AVX512 AND AVX512DQ), it can check ((AVX512 AND AVX512DQ) OR AVX10.1) after checking XCR0[7:5]. The versions of AVX10 are expected to be inclusive, e.g. version N+1 is a superset of version N. Per the spec, the version can never be 0, just advertise AVX10.1 if it's supported in hardware. Moreover, advertising AVX10_{128,256,512} needs to land in the same commit as advertising basic AVX10.1 support, otherwise KVM would advertise an impossible CPU model. E.g. a CPU with AVX512 but not AVX10.1/512 is impossible per the SDM. As more and more AVX related CPUIDs are added (it would have resulted in around 40-50 CPUID flags when developing AVX10), the versioning approach is introduced. But incrementing version numbers are bad for virtualization. E.g. if AVX10.2 has a feature that shouldn't be enumerated to guests for whatever reason, then KVM can't enumerate any "later" features either, because the only way to hide the problematic AVX10.2 feature is to set the version to AVX10.1 or lower[2]. But most AVX features are just passed through and don't have virtualization controls, so AVX10 should not be problematic in practice, so long as Intel honors their promise that future versions will be supersets of past versions. [1] https://cdrdv2.intel.com/v1/dl/getContent/784267 [2] https://lore.kernel.org/all/Zkz5Ak0PQlAN8DxK@google.com/ Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Tao Su <tao1.su@linux.intel.com> Link: https://lore.kernel.org/r/20240819062327.3269720-1-tao1.su@linux.intel.com [sean: minor changelog tweaks] Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 1448d4a commit 1c450ff

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

arch/x86/include/asm/cpuid.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ static __always_inline bool cpuid_function_is_indexed(u32 function)
179179
case 0x1d:
180180
case 0x1e:
181181
case 0x1f:
182+
case 0x24:
182183
case 0x8000001d:
183184
return true;
184185
}

arch/x86/kvm/cpuid.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ void kvm_set_cpu_caps(void)
705705

706706
kvm_cpu_cap_init_kvm_defined(CPUID_7_1_EDX,
707707
F(AVX_VNNI_INT8) | F(AVX_NE_CONVERT) | F(PREFETCHITI) |
708-
F(AMX_COMPLEX)
708+
F(AMX_COMPLEX) | F(AVX10)
709709
);
710710

711711
kvm_cpu_cap_init_kvm_defined(CPUID_7_2_EDX,
@@ -721,6 +721,10 @@ void kvm_set_cpu_caps(void)
721721
SF(SGX1) | SF(SGX2) | SF(SGX_EDECCSSA)
722722
);
723723

724+
kvm_cpu_cap_init_kvm_defined(CPUID_24_0_EBX,
725+
F(AVX10_128) | F(AVX10_256) | F(AVX10_512)
726+
);
727+
724728
kvm_cpu_cap_mask(CPUID_8000_0001_ECX,
725729
F(LAHF_LM) | F(CMP_LEGACY) | 0 /*SVM*/ | 0 /* ExtApicSpace */ |
726730
F(CR8_LEGACY) | F(ABM) | F(SSE4A) | F(MISALIGNSSE) |
@@ -949,7 +953,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
949953
switch (function) {
950954
case 0:
951955
/* Limited to the highest leaf implemented in KVM. */
952-
entry->eax = min(entry->eax, 0x1fU);
956+
entry->eax = min(entry->eax, 0x24U);
953957
break;
954958
case 1:
955959
cpuid_entry_override(entry, CPUID_1_EDX);
@@ -1174,6 +1178,28 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
11741178
break;
11751179
}
11761180
break;
1181+
case 0x24: {
1182+
u8 avx10_version;
1183+
1184+
if (!kvm_cpu_cap_has(X86_FEATURE_AVX10)) {
1185+
entry->eax = entry->ebx = entry->ecx = entry->edx = 0;
1186+
break;
1187+
}
1188+
1189+
/*
1190+
* The AVX10 version is encoded in EBX[7:0]. Note, the version
1191+
* is guaranteed to be >=1 if AVX10 is supported. Note #2, the
1192+
* version needs to be captured before overriding EBX features!
1193+
*/
1194+
avx10_version = min_t(u8, entry->ebx & 0xff, 1);
1195+
cpuid_entry_override(entry, CPUID_24_0_EBX);
1196+
entry->ebx |= avx10_version;
1197+
1198+
entry->eax = 0;
1199+
entry->ecx = 0;
1200+
entry->edx = 0;
1201+
break;
1202+
}
11771203
case KVM_CPUID_SIGNATURE: {
11781204
const u32 *sigptr = (const u32 *)KVM_SIGNATURE;
11791205
entry->eax = KVM_CPUID_FEATURES;

arch/x86/kvm/reverse_cpuid.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ enum kvm_only_cpuid_leafs {
1717
CPUID_8000_0007_EDX,
1818
CPUID_8000_0022_EAX,
1919
CPUID_7_2_EDX,
20+
CPUID_24_0_EBX,
2021
NR_KVM_CPU_CAPS,
2122

2223
NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS,
@@ -46,6 +47,7 @@ enum kvm_only_cpuid_leafs {
4647
#define X86_FEATURE_AVX_NE_CONVERT KVM_X86_FEATURE(CPUID_7_1_EDX, 5)
4748
#define X86_FEATURE_AMX_COMPLEX KVM_X86_FEATURE(CPUID_7_1_EDX, 8)
4849
#define X86_FEATURE_PREFETCHITI KVM_X86_FEATURE(CPUID_7_1_EDX, 14)
50+
#define X86_FEATURE_AVX10 KVM_X86_FEATURE(CPUID_7_1_EDX, 19)
4951

5052
/* Intel-defined sub-features, CPUID level 0x00000007:2 (EDX) */
5153
#define X86_FEATURE_INTEL_PSFD KVM_X86_FEATURE(CPUID_7_2_EDX, 0)
@@ -55,6 +57,11 @@ enum kvm_only_cpuid_leafs {
5557
#define KVM_X86_FEATURE_BHI_CTRL KVM_X86_FEATURE(CPUID_7_2_EDX, 4)
5658
#define X86_FEATURE_MCDT_NO KVM_X86_FEATURE(CPUID_7_2_EDX, 5)
5759

60+
/* Intel-defined sub-features, CPUID level 0x00000024:0 (EBX) */
61+
#define X86_FEATURE_AVX10_128 KVM_X86_FEATURE(CPUID_24_0_EBX, 16)
62+
#define X86_FEATURE_AVX10_256 KVM_X86_FEATURE(CPUID_24_0_EBX, 17)
63+
#define X86_FEATURE_AVX10_512 KVM_X86_FEATURE(CPUID_24_0_EBX, 18)
64+
5865
/* CPUID level 0x80000007 (EDX). */
5966
#define KVM_X86_FEATURE_CONSTANT_TSC KVM_X86_FEATURE(CPUID_8000_0007_EDX, 8)
6067

@@ -90,6 +97,7 @@ static const struct cpuid_reg reverse_cpuid[] = {
9097
[CPUID_8000_0021_EAX] = {0x80000021, 0, CPUID_EAX},
9198
[CPUID_8000_0022_EAX] = {0x80000022, 0, CPUID_EAX},
9299
[CPUID_7_2_EDX] = { 7, 2, CPUID_EDX},
100+
[CPUID_24_0_EBX] = { 0x24, 0, CPUID_EBX},
93101
};
94102

95103
/*

0 commit comments

Comments
 (0)