Skip to content

Commit 047c722

Browse files
sean-jcbonzini
authored andcommitted
KVM: x86: Update KVM-only leaf handling to allow for 100% KVM-only leafs
Rename kvm_cpu_cap_init_scattered() to kvm_cpu_cap_init_kvm_defined() in anticipation of adding KVM-only CPUID leafs that aren't recognized by the kernel and thus not scattered, i.e. for leafs that are 100% KVM-defined. Adjust/add comments to kvm_only_cpuid_leafs and KVM_X86_FEATURE to document how to create new kvm_only_cpuid_leafs entries for scattered features as well as features that are entirely unknown to the kernel. No functional change intended. Signed-off-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent c4690d0 commit 047c722

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

arch/x86/kvm/cpuid.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,9 @@ static __always_inline void __kvm_cpu_cap_mask(unsigned int leaf)
549549
}
550550

551551
static __always_inline
552-
void kvm_cpu_cap_init_scattered(enum kvm_only_cpuid_leafs leaf, u32 mask)
552+
void kvm_cpu_cap_init_kvm_defined(enum kvm_only_cpuid_leafs leaf, u32 mask)
553553
{
554-
/* Use kvm_cpu_cap_mask for non-scattered leafs. */
554+
/* Use kvm_cpu_cap_mask for leafs that aren't KVM-only. */
555555
BUILD_BUG_ON(leaf < NCAPINTS);
556556

557557
kvm_cpu_caps[leaf] = mask;
@@ -561,7 +561,7 @@ void kvm_cpu_cap_init_scattered(enum kvm_only_cpuid_leafs leaf, u32 mask)
561561

562562
static __always_inline void kvm_cpu_cap_mask(enum cpuid_leafs leaf, u32 mask)
563563
{
564-
/* Use kvm_cpu_cap_init_scattered for scattered leafs. */
564+
/* Use kvm_cpu_cap_init_kvm_defined for KVM-only leafs. */
565565
BUILD_BUG_ON(leaf >= NCAPINTS);
566566

567567
kvm_cpu_caps[leaf] &= mask;
@@ -670,7 +670,7 @@ void kvm_set_cpu_caps(void)
670670
F(XSAVEOPT) | F(XSAVEC) | F(XGETBV1) | F(XSAVES) | f_xfd
671671
);
672672

673-
kvm_cpu_cap_init_scattered(CPUID_12_EAX,
673+
kvm_cpu_cap_init_kvm_defined(CPUID_12_EAX,
674674
SF(SGX1) | SF(SGX2)
675675
);
676676

arch/x86/kvm/reverse_cpuid.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
#include <asm/cpufeatures.h>
88

99
/*
10-
* Hardware-defined CPUID leafs that are scattered in the kernel, but need to
11-
* be directly used by KVM. Note, these word values conflict with the kernel's
12-
* "bug" caps, but KVM doesn't use those.
10+
* Hardware-defined CPUID leafs that are either scattered by the kernel or are
11+
* unknown to the kernel, but need to be directly used by KVM. Note, these
12+
* word values conflict with the kernel's "bug" caps, but KVM doesn't use those.
1313
*/
1414
enum kvm_only_cpuid_leafs {
1515
CPUID_12_EAX = NCAPINTS,
@@ -18,6 +18,18 @@ enum kvm_only_cpuid_leafs {
1818
NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS,
1919
};
2020

21+
/*
22+
* Define a KVM-only feature flag.
23+
*
24+
* For features that are scattered by cpufeatures.h, __feature_translate() also
25+
* needs to be updated to translate the kernel-defined feature into the
26+
* KVM-defined feature.
27+
*
28+
* For features that are 100% KVM-only, i.e. not defined by cpufeatures.h,
29+
* forego the intermediate KVM_X86_FEATURE and directly define X86_FEATURE_* so
30+
* that X86_FEATURE_* can be used in KVM. No __feature_translate() handling is
31+
* needed in this case.
32+
*/
2133
#define KVM_X86_FEATURE(w, f) ((w)*32 + (f))
2234

2335
/* Intel-defined SGX sub-features, CPUID level 0x12 (EAX). */

0 commit comments

Comments
 (0)