Skip to content

Commit 58cbaf6

Browse files
trueptolemysean-jc
authored andcommitted
KVM: x86: Advertise AMX CPUIDs in subleaf 0x1E.0x1 to userspace
Define and advertise AMX CPUIDs (0x1E.0x1) to userspace when the leaf is supported by the host. Intel Diamond Rapids adds new AMX instructions to support new formats and memory operations [*], and introduces the CPUID subleaf 0x1E.0x1 to centralize the discrete AMX feature bits within EAX. Since these AMX features have no actual kernel usages, define them as KVM-only features in reverse_cpuid.h. In addition to the new features, CPUID 0x1E.0x1.EAX[bits 0-3] are aliaseed positions of existing AMX feature bits distributed across the 0x7 leaves. To avoid duplicate feature names, name these aliases with an *_ALIAS suffix, and define them in reverse_cpuid.h as KVM-only features as well. Advertise new CPUID subleaf 0x1E.0x1 with its AMX CPUID feature bits to userspace for guest use. It's safe since no additional enabling work is needed in the host kernel. [*]: Intel Architecture Instruction Set Extensions and Future Features (rev.059). Tested-by: Xudong Hao <xudong.hao@intel.com> Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Link: https://patch.msgid.link/20251120050720.931449-3-zhao1.liu@intel.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent f24ef00 commit 58cbaf6

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ enum kvm_only_cpuid_leafs {
776776
CPUID_24_0_EBX,
777777
CPUID_8000_0021_ECX,
778778
CPUID_7_1_ECX,
779+
CPUID_1E_1_EAX,
779780
NR_KVM_CPU_CAPS,
780781

781782
NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS,

arch/x86/kvm/cpuid.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,17 @@ void kvm_set_cpu_caps(void)
10671067
SCATTERED_F(SGX_EDECCSSA),
10681068
);
10691069

1070+
kvm_cpu_cap_init(CPUID_1E_1_EAX,
1071+
F(AMX_INT8_ALIAS),
1072+
F(AMX_BF16_ALIAS),
1073+
F(AMX_COMPLEX_ALIAS),
1074+
F(AMX_FP16_ALIAS),
1075+
F(AMX_FP8),
1076+
F(AMX_TF32),
1077+
F(AMX_AVX512),
1078+
F(AMX_MOVRS),
1079+
);
1080+
10701081
kvm_cpu_cap_init(CPUID_24_0_EBX,
10711082
F(AVX10_128),
10721083
F(AVX10_256),
@@ -1627,6 +1638,20 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
16271638
entry->eax = entry->ebx = entry->ecx = entry->edx = 0;
16281639
break;
16291640
}
1641+
1642+
max_idx = entry->eax = min(entry->eax, 1u);
1643+
1644+
/* KVM only supports up to 0x1e.0x1, capped above via min(). */
1645+
if (max_idx >= 1) {
1646+
entry = do_host_cpuid(array, function, 1);
1647+
if (!entry)
1648+
goto out;
1649+
1650+
cpuid_entry_override(entry, CPUID_1E_1_EAX);
1651+
entry->ebx = 0;
1652+
entry->ecx = 0;
1653+
entry->edx = 0;
1654+
}
16301655
break;
16311656
case 0x24: {
16321657
u8 avx10_version;

arch/x86/kvm/reverse_cpuid.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@
4444
#define KVM_X86_FEATURE_BHI_CTRL KVM_X86_FEATURE(CPUID_7_2_EDX, 4)
4545
#define X86_FEATURE_MCDT_NO KVM_X86_FEATURE(CPUID_7_2_EDX, 5)
4646

47+
/*
48+
* Intel-defined sub-features, CPUID level 0x0000001E:1 (EAX). Note, several
49+
* of the bits are aliases to features of the same name that are enumerated via
50+
* various CPUID.0x7 sub-leafs.
51+
*/
52+
#define X86_FEATURE_AMX_INT8_ALIAS KVM_X86_FEATURE(CPUID_1E_1_EAX, 0)
53+
#define X86_FEATURE_AMX_BF16_ALIAS KVM_X86_FEATURE(CPUID_1E_1_EAX, 1)
54+
#define X86_FEATURE_AMX_COMPLEX_ALIAS KVM_X86_FEATURE(CPUID_1E_1_EAX, 2)
55+
#define X86_FEATURE_AMX_FP16_ALIAS KVM_X86_FEATURE(CPUID_1E_1_EAX, 3)
56+
#define X86_FEATURE_AMX_FP8 KVM_X86_FEATURE(CPUID_1E_1_EAX, 4)
57+
#define X86_FEATURE_AMX_TF32 KVM_X86_FEATURE(CPUID_1E_1_EAX, 6)
58+
#define X86_FEATURE_AMX_AVX512 KVM_X86_FEATURE(CPUID_1E_1_EAX, 7)
59+
#define X86_FEATURE_AMX_MOVRS KVM_X86_FEATURE(CPUID_1E_1_EAX, 8)
60+
4761
/* Intel-defined sub-features, CPUID level 0x00000024:0 (EBX) */
4862
#define X86_FEATURE_AVX10_128 KVM_X86_FEATURE(CPUID_24_0_EBX, 16)
4963
#define X86_FEATURE_AVX10_256 KVM_X86_FEATURE(CPUID_24_0_EBX, 17)
@@ -90,6 +104,7 @@ static const struct cpuid_reg reverse_cpuid[] = {
90104
[CPUID_24_0_EBX] = { 0x24, 0, CPUID_EBX},
91105
[CPUID_8000_0021_ECX] = {0x80000021, 0, CPUID_ECX},
92106
[CPUID_7_1_ECX] = { 7, 1, CPUID_ECX},
107+
[CPUID_1E_1_EAX] = { 0x1e, 1, CPUID_EAX},
93108
};
94109

95110
/*

0 commit comments

Comments
 (0)