Skip to content

Commit 062768f

Browse files
trueptolemysean-jc
authored andcommitted
KVM: x86: Advertise AVX10_VNNI_INT CPUID to userspace
Define and advertise AVX10_VNNI_INT CPUID to userspace when it's supported by the host. AVX10_VNNI_INT (0x24.0x1.ECX[bit 2]) is a discrete feature bit introduced on Intel Diamond Rapids, which enumerates the support for EVEX VPDP* instructions for INT8/INT16 [*]. Since this feature has no actual kernel usages, define it as a KVM-only feature in reverse_cpuid.h. Advertise new CPUID subleaf 0x24.0x1 with AVX10_VNNI_INT bit to userspace for guest use. It's safe since no additional enabling work is needed in the host kernel. [*]: Intel Advanced Vector Extensions 10.2 Architecture Specification (rev 5.0). 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-5-zhao1.liu@intel.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 2ff8fb1 commit 062768f

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,7 @@ enum kvm_only_cpuid_leafs {
777777
CPUID_8000_0021_ECX,
778778
CPUID_7_1_ECX,
779779
CPUID_1E_1_EAX,
780+
CPUID_24_1_ECX,
780781
NR_KVM_CPU_CAPS,
781782

782783
NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS,

arch/x86/kvm/cpuid.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,10 @@ void kvm_set_cpu_caps(void)
10841084
F(AVX10_512),
10851085
);
10861086

1087+
kvm_cpu_cap_init(CPUID_24_1_ECX,
1088+
F(AVX10_VNNI_INT),
1089+
);
1090+
10871091
kvm_cpu_cap_init(CPUID_8000_0001_ECX,
10881092
F(LAHF_LM),
10891093
F(CMP_LEGACY),
@@ -1661,6 +1665,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
16611665
break;
16621666
}
16631667

1668+
max_idx = entry->eax = min(entry->eax, 1u);
16641669
/*
16651670
* The AVX10 version is encoded in EBX[7:0]. Note, the version
16661671
* is guaranteed to be >=1 if AVX10 is supported. Note #2, the
@@ -1670,9 +1675,20 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
16701675
cpuid_entry_override(entry, CPUID_24_0_EBX);
16711676
entry->ebx |= avx10_version;
16721677

1673-
entry->eax = 0;
16741678
entry->ecx = 0;
16751679
entry->edx = 0;
1680+
1681+
/* KVM only supports up to 0x24.0x1, capped above via min(). */
1682+
if (max_idx >= 1) {
1683+
entry = do_host_cpuid(array, function, 1);
1684+
if (!entry)
1685+
goto out;
1686+
1687+
cpuid_entry_override(entry, CPUID_24_1_ECX);
1688+
entry->eax = 0;
1689+
entry->ebx = 0;
1690+
entry->edx = 0;
1691+
}
16761692
break;
16771693
}
16781694
case KVM_CPUID_SIGNATURE: {

arch/x86/kvm/reverse_cpuid.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
#define X86_FEATURE_AVX10_256 KVM_X86_FEATURE(CPUID_24_0_EBX, 17)
6464
#define X86_FEATURE_AVX10_512 KVM_X86_FEATURE(CPUID_24_0_EBX, 18)
6565

66+
/* Intel-defined sub-features, CPUID level 0x00000024:1 (ECX) */
67+
#define X86_FEATURE_AVX10_VNNI_INT KVM_X86_FEATURE(CPUID_24_1_ECX, 2)
68+
6669
/* CPUID level 0x80000007 (EDX). */
6770
#define KVM_X86_FEATURE_CONSTANT_TSC KVM_X86_FEATURE(CPUID_8000_0007_EDX, 8)
6871

@@ -105,6 +108,7 @@ static const struct cpuid_reg reverse_cpuid[] = {
105108
[CPUID_8000_0021_ECX] = {0x80000021, 0, CPUID_ECX},
106109
[CPUID_7_1_ECX] = { 7, 1, CPUID_ECX},
107110
[CPUID_1E_1_EAX] = { 0x1e, 1, CPUID_EAX},
111+
[CPUID_24_1_ECX] = { 0x24, 1, CPUID_ECX},
108112
};
109113

110114
/*

0 commit comments

Comments
 (0)