summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Christopherson <seanjc@google.com>2024-11-27 17:33:51 -0800
committerSean Christopherson <seanjc@google.com>2024-12-18 14:19:47 -0800
commit6eac4d99a9677a35947aa115bbc60266def40c3e (patch)
tree8cf585a413b76e8d3f2bf9556867f4a9bb793031
parent3cc359ca29adadb94f4551b0cf40bb2352c28361 (diff)
KVM: x86: Add a macro to init CPUID features that are 64-bit only
Add a macro to mask-in feature flags that are supported only on 64-bit kernels/KVM. In addition to reducing overall #ifdeffery, using a macro will allow hardening the kvm_cpu_cap initialization sequences to assert that the features being advertised are indeed included in the word being initialized. And arguably using *F() macros through is more readable. No functional change intended. Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com> Link: https://lore.kernel.org/r/20241128013424.4096668-25-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
-rw-r--r--arch/x86/kvm/cpuid.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 5546ec572392..bd1d54e25414 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -663,17 +663,14 @@ static __always_inline void kvm_cpu_cap_init(enum cpuid_leafs leaf, u32 mask)
(boot_cpu_has(X86_FEATURE_##name) ? F(name) : 0); \
})
+/* Features that KVM supports only on 64-bit kernels. */
+#define X86_64_F(name) \
+({ \
+ (IS_ENABLED(CONFIG_X86_64) ? F(name) : 0); \
+})
+
void kvm_set_cpu_caps(void)
{
-#ifdef CONFIG_X86_64
- unsigned int f_gbpages = F(GBPAGES);
- unsigned int f_lm = F(LM);
- unsigned int f_xfd = F(XFD);
-#else
- unsigned int f_gbpages = 0;
- unsigned int f_lm = 0;
- unsigned int f_xfd = 0;
-#endif
memset(kvm_cpu_caps, 0, sizeof(kvm_cpu_caps));
BUILD_BUG_ON(sizeof(kvm_cpu_caps) - (NKVMCAPINTS * sizeof(*kvm_cpu_caps)) >
@@ -880,7 +877,7 @@ void kvm_set_cpu_caps(void)
F(XSAVEC) |
F(XGETBV1) |
F(XSAVES) |
- f_xfd
+ X86_64_F(XFD)
);
kvm_cpu_cap_init_kvm_defined(CPUID_12_EAX,
@@ -941,10 +938,10 @@ void kvm_set_cpu_caps(void)
F(MMX) |
F(FXSR) |
F(FXSR_OPT) |
- f_gbpages |
+ X86_64_F(GBPAGES) |
F(RDTSCP) |
0 /* Reserved */ |
- f_lm |
+ X86_64_F(LM) |
F(3DNOWEXT) |
F(3DNOW)
);
@@ -1078,6 +1075,7 @@ EXPORT_SYMBOL_GPL(kvm_set_cpu_caps);
#undef F
#undef SF
+#undef X86_64_F
struct kvm_cpuid_array {
struct kvm_cpuid_entry2 *entries;