]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-5.10/x86-cpufeatures-add-cpuid_lnx_5-to-track-recently-added-linux-defined-word.patch
Linux 5.4.274
[thirdparty/kernel/stable-queue.git] / queue-5.10 / x86-cpufeatures-add-cpuid_lnx_5-to-track-recently-added-linux-defined-word.patch
1 From 8cb4a9a82b21623dbb4b3051dd30d98356cf95bc Mon Sep 17 00:00:00 2001
2 From: Sean Christopherson <seanjc@google.com>
3 Date: Thu, 4 Apr 2024 17:16:14 -0700
4 Subject: x86/cpufeatures: Add CPUID_LNX_5 to track recently added Linux-defined word
5
6 From: Sean Christopherson <seanjc@google.com>
7
8 commit 8cb4a9a82b21623dbb4b3051dd30d98356cf95bc upstream.
9
10 Add CPUID_LNX_5 to track cpufeatures' word 21, and add the appropriate
11 compile-time assert in KVM to prevent direct lookups on the features in
12 CPUID_LNX_5. KVM uses X86_FEATURE_* flags to manage guest CPUID, and so
13 must translate features that are scattered by Linux from the Linux-defined
14 bit to the hardware-defined bit, i.e. should never try to directly access
15 scattered features in guest CPUID.
16
17 Opportunistically add NR_CPUID_WORDS to enum cpuid_leafs, along with a
18 compile-time assert in KVM's CPUID infrastructure to ensure that future
19 additions update cpuid_leafs along with NCAPINTS.
20
21 No functional change intended.
22
23 Fixes: 7f274e609f3d ("x86/cpufeatures: Add new word for scattered features")
24 Cc: Sandipan Das <sandipan.das@amd.com>
25 Signed-off-by: Sean Christopherson <seanjc@google.com>
26 Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
27 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
28 Signed-off-by: Daniel Sneddon <daniel.sneddon@linux.intel.com>
29 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
30 ---
31 arch/x86/include/asm/cpufeature.h | 2 ++
32 arch/x86/kvm/cpuid.h | 2 ++
33 2 files changed, 4 insertions(+)
34
35 --- a/arch/x86/include/asm/cpufeature.h
36 +++ b/arch/x86/include/asm/cpufeature.h
37 @@ -33,6 +33,8 @@ enum cpuid_leafs
38 CPUID_7_EDX,
39 CPUID_8000_001F_EAX,
40 CPUID_8000_0021_EAX,
41 + CPUID_LNX_5,
42 + NR_CPUID_WORDS,
43 };
44
45 #ifdef CONFIG_X86_FEATURE_NAMES
46 --- a/arch/x86/kvm/cpuid.h
47 +++ b/arch/x86/kvm/cpuid.h
48 @@ -76,10 +76,12 @@ static const struct cpuid_reg reverse_cp
49 */
50 static __always_inline void reverse_cpuid_check(unsigned int x86_leaf)
51 {
52 + BUILD_BUG_ON(NR_CPUID_WORDS != NCAPINTS);
53 BUILD_BUG_ON(x86_leaf == CPUID_LNX_1);
54 BUILD_BUG_ON(x86_leaf == CPUID_LNX_2);
55 BUILD_BUG_ON(x86_leaf == CPUID_LNX_3);
56 BUILD_BUG_ON(x86_leaf == CPUID_LNX_4);
57 + BUILD_BUG_ON(x86_leaf == CPUID_LNX_5);
58 BUILD_BUG_ON(x86_leaf >= ARRAY_SIZE(reverse_cpuid));
59 BUILD_BUG_ON(reverse_cpuid[x86_leaf].function == 0);
60 }