Skip to content

Commit 8cb4a9a

Browse files
sean-jctorvalds
authored andcommitted
x86/cpufeatures: Add CPUID_LNX_5 to track recently added Linux-defined word
Add CPUID_LNX_5 to track cpufeatures' word 21, and add the appropriate compile-time assert in KVM to prevent direct lookups on the features in CPUID_LNX_5. KVM uses X86_FEATURE_* flags to manage guest CPUID, and so must translate features that are scattered by Linux from the Linux-defined bit to the hardware-defined bit, i.e. should never try to directly access scattered features in guest CPUID. Opportunistically add NR_CPUID_WORDS to enum cpuid_leafs, along with a compile-time assert in KVM's CPUID infrastructure to ensure that future additions update cpuid_leafs along with NCAPINTS. No functional change intended. Fixes: 7f274e6 ("x86/cpufeatures: Add new word for scattered features") Cc: Sandipan Das <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> Acked-by: Dave Hansen <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent c88b9b4 commit 8cb4a9a

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

arch/x86/include/asm/cpufeature.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ enum cpuid_leafs
3333
CPUID_7_EDX,
3434
CPUID_8000_001F_EAX,
3535
CPUID_8000_0021_EAX,
36+
CPUID_LNX_5,
37+
NR_CPUID_WORDS,
3638
};
3739

3840
#define X86_CAP_FMT_NUM "%d:%d"

arch/x86/kvm/reverse_cpuid.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,12 @@ static const struct cpuid_reg reverse_cpuid[] = {
102102
*/
103103
static __always_inline void reverse_cpuid_check(unsigned int x86_leaf)
104104
{
105+
BUILD_BUG_ON(NR_CPUID_WORDS != NCAPINTS);
105106
BUILD_BUG_ON(x86_leaf == CPUID_LNX_1);
106107
BUILD_BUG_ON(x86_leaf == CPUID_LNX_2);
107108
BUILD_BUG_ON(x86_leaf == CPUID_LNX_3);
108109
BUILD_BUG_ON(x86_leaf == CPUID_LNX_4);
110+
BUILD_BUG_ON(x86_leaf == CPUID_LNX_5);
109111
BUILD_BUG_ON(x86_leaf >= ARRAY_SIZE(reverse_cpuid));
110112
BUILD_BUG_ON(reverse_cpuid[x86_leaf].function == 0);
111113
}

0 commit comments

Comments
 (0)