Skip to content

Commit 32ad73d

Browse files
Sean Christophersonsuryasaimadhu
authored andcommitted
x86/msr-index: Clean up bit defines for IA32_FEATURE_CONTROL MSR
As pointed out by Boris, the defines for bits in IA32_FEATURE_CONTROL are quite a mouthful, especially the VMX bits which must differentiate between enabling VMX inside and outside SMX (TXT) operation. Rename the MSR and its bit defines to abbreviate FEATURE_CONTROL as FEAT_CTL to make them a little friendlier on the eyes. Arguably, the MSR itself should keep the full IA32_FEATURE_CONTROL name to match Intel's SDM, but a future patch will add a dedicated Kconfig, file and functions for the MSR. Using the full name for those assets is rather unwieldy, so bite the bullet and use IA32_FEAT_CTL so that its nomenclature is consistent throughout the kernel. Opportunistically, fix a few other annoyances with the defines: - Relocate the bit defines so that they immediately follow the MSR define, e.g. aren't mistaken as belonging to MISC_FEATURE_CONTROL. - Add whitespace around the block of feature control defines to make it clear they're all related. - Use BIT() instead of manually encoding the bit shift. - Use "VMX" instead of "VMXON" to match the SDM. - Append "_ENABLED" to the LMCE (Local Machine Check Exception) bit to be consistent with the kernel's verbiage used for all other feature control bits. Note, the SDM refers to the LMCE bit as LMCE_ON, likely to differentiate it from IA32_MCG_EXT_CTL.LMCE_EN. Ignore the (literal) one-off usage of _ON, the SDM is simply "wrong". Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://lkml.kernel.org/r/20191221044513.21680-2-sean.j.christopherson@intel.com
1 parent d157aa0 commit 32ad73d

7 files changed

Lines changed: 41 additions & 39 deletions

File tree

‎arch/x86/include/asm/msr-index.h‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -558,19 +558,21 @@
558558
#define MSR_IA32_EBL_CR_POWERON 0x0000002a
559559
#define MSR_EBC_FREQUENCY_ID 0x0000002c
560560
#define MSR_SMI_COUNT 0x00000034
561-
#define MSR_IA32_FEATURE_CONTROL 0x0000003a
561+
562+
/* Referred to as IA32_FEATURE_CONTROL in Intel's SDM. */
563+
#define MSR_IA32_FEAT_CTL 0x0000003a
564+
#define FEAT_CTL_LOCKED BIT(0)
565+
#define FEAT_CTL_VMX_ENABLED_INSIDE_SMX BIT(1)
566+
#define FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX BIT(2)
567+
#define FEAT_CTL_LMCE_ENABLED BIT(20)
568+
562569
#define MSR_IA32_TSC_ADJUST 0x0000003b
563570
#define MSR_IA32_BNDCFGS 0x00000d90
564571

565572
#define MSR_IA32_BNDCFGS_RSVD 0x00000ffc
566573

567574
#define MSR_IA32_XSS 0x00000da0
568575

569-
#define FEATURE_CONTROL_LOCKED (1<<0)
570-
#define FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX (1<<1)
571-
#define FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX (1<<2)
572-
#define FEATURE_CONTROL_LMCE (1<<20)
573-
574576
#define MSR_IA32_APICBASE 0x0000001b
575577
#define MSR_IA32_APICBASE_BSP (1<<8)
576578
#define MSR_IA32_APICBASE_ENABLE (1<<11)

‎arch/x86/kernel/cpu/mce/intel.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ static bool lmce_supported(void)
115115

116116
/*
117117
* BIOS should indicate support for LMCE by setting bit 20 in
118-
* IA32_FEATURE_CONTROL without which touching MCG_EXT_CTL will
119-
* generate a #GP fault.
118+
* IA32_FEAT_CTL without which touching MCG_EXT_CTL will generate a #GP
119+
* fault.
120120
*/
121-
rdmsrl(MSR_IA32_FEATURE_CONTROL, tmp);
122-
if ((tmp & (FEATURE_CONTROL_LOCKED | FEATURE_CONTROL_LMCE)) ==
123-
(FEATURE_CONTROL_LOCKED | FEATURE_CONTROL_LMCE))
121+
rdmsrl(MSR_IA32_FEAT_CTL, tmp);
122+
if ((tmp & (FEAT_CTL_LOCKED | FEAT_CTL_LMCE_ENABLED)) ==
123+
(FEAT_CTL_LOCKED | FEAT_CTL_LMCE_ENABLED))
124124
return true;
125125

126126
return false;

‎arch/x86/kvm/vmx/nested.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4588,8 +4588,8 @@ static int handle_vmon(struct kvm_vcpu *vcpu)
45884588
gpa_t vmptr;
45894589
uint32_t revision;
45904590
struct vcpu_vmx *vmx = to_vmx(vcpu);
4591-
const u64 VMXON_NEEDED_FEATURES = FEATURE_CONTROL_LOCKED
4592-
| FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX;
4591+
const u64 VMXON_NEEDED_FEATURES = FEAT_CTL_LOCKED
4592+
| FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX;
45934593

45944594
/*
45954595
* The Intel VMX Instruction Reference lists a bunch of bits that are

‎arch/x86/kvm/vmx/vmx.c‎

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,11 +1839,11 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
18391839
case MSR_IA32_MCG_EXT_CTL:
18401840
if (!msr_info->host_initiated &&
18411841
!(vmx->msr_ia32_feature_control &
1842-
FEATURE_CONTROL_LMCE))
1842+
FEAT_CTL_LMCE_ENABLED))
18431843
return 1;
18441844
msr_info->data = vcpu->arch.mcg_ext_ctl;
18451845
break;
1846-
case MSR_IA32_FEATURE_CONTROL:
1846+
case MSR_IA32_FEAT_CTL:
18471847
msr_info->data = vmx->msr_ia32_feature_control;
18481848
break;
18491849
case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC:
@@ -2074,15 +2074,15 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
20742074
case MSR_IA32_MCG_EXT_CTL:
20752075
if ((!msr_info->host_initiated &&
20762076
!(to_vmx(vcpu)->msr_ia32_feature_control &
2077-
FEATURE_CONTROL_LMCE)) ||
2077+
FEAT_CTL_LMCE_ENABLED)) ||
20782078
(data & ~MCG_EXT_CTL_LMCE_EN))
20792079
return 1;
20802080
vcpu->arch.mcg_ext_ctl = data;
20812081
break;
2082-
case MSR_IA32_FEATURE_CONTROL:
2082+
case MSR_IA32_FEAT_CTL:
20832083
if (!vmx_feature_control_msr_valid(vcpu, data) ||
20842084
(to_vmx(vcpu)->msr_ia32_feature_control &
2085-
FEATURE_CONTROL_LOCKED && !msr_info->host_initiated))
2085+
FEAT_CTL_LOCKED && !msr_info->host_initiated))
20862086
return 1;
20872087
vmx->msr_ia32_feature_control = data;
20882088
if (msr_info->host_initiated && data == 0)
@@ -2206,22 +2206,22 @@ static __init int vmx_disabled_by_bios(void)
22062206
{
22072207
u64 msr;
22082208

2209-
rdmsrl(MSR_IA32_FEATURE_CONTROL, msr);
2210-
if (msr & FEATURE_CONTROL_LOCKED) {
2209+
rdmsrl(MSR_IA32_FEAT_CTL, msr);
2210+
if (msr & FEAT_CTL_LOCKED) {
22112211
/* launched w/ TXT and VMX disabled */
2212-
if (!(msr & FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX)
2212+
if (!(msr & FEAT_CTL_VMX_ENABLED_INSIDE_SMX)
22132213
&& tboot_enabled())
22142214
return 1;
22152215
/* launched w/o TXT and VMX only enabled w/ TXT */
2216-
if (!(msr & FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX)
2217-
&& (msr & FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX)
2216+
if (!(msr & FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX)
2217+
&& (msr & FEAT_CTL_VMX_ENABLED_INSIDE_SMX)
22182218
&& !tboot_enabled()) {
22192219
printk(KERN_WARNING "kvm: disable TXT in the BIOS or "
22202220
"activate TXT before enabling KVM\n");
22212221
return 1;
22222222
}
22232223
/* launched w/o TXT and VMX disabled */
2224-
if (!(msr & FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX)
2224+
if (!(msr & FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX)
22252225
&& !tboot_enabled())
22262226
return 1;
22272227
}
@@ -2269,16 +2269,16 @@ static int hardware_enable(void)
22692269
*/
22702270
crash_enable_local_vmclear(cpu);
22712271

2272-
rdmsrl(MSR_IA32_FEATURE_CONTROL, old);
2272+
rdmsrl(MSR_IA32_FEAT_CTL, old);
22732273

2274-
test_bits = FEATURE_CONTROL_LOCKED;
2275-
test_bits |= FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX;
2274+
test_bits = FEAT_CTL_LOCKED;
2275+
test_bits |= FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX;
22762276
if (tboot_enabled())
2277-
test_bits |= FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX;
2277+
test_bits |= FEAT_CTL_VMX_ENABLED_INSIDE_SMX;
22782278

22792279
if ((old & test_bits) != test_bits) {
22802280
/* enable and lock */
2281-
wrmsrl(MSR_IA32_FEATURE_CONTROL, old | test_bits);
2281+
wrmsrl(MSR_IA32_FEAT_CTL, old | test_bits);
22822282
}
22832283
kvm_cpu_vmxon(phys_addr);
22842284
if (enable_ept)
@@ -6801,7 +6801,7 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
68016801
vmx->nested.posted_intr_nv = -1;
68026802
vmx->nested.current_vmptr = -1ull;
68036803

6804-
vmx->msr_ia32_feature_control_valid_bits = FEATURE_CONTROL_LOCKED;
6804+
vmx->msr_ia32_feature_control_valid_bits = FEAT_CTL_LOCKED;
68056805

68066806
/*
68076807
* Enforce invariant: pi_desc.nv is always either POSTED_INTR_VECTOR
@@ -7099,12 +7099,12 @@ static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
70997099

71007100
if (nested_vmx_allowed(vcpu))
71017101
to_vmx(vcpu)->msr_ia32_feature_control_valid_bits |=
7102-
FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX |
7103-
FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX;
7102+
FEAT_CTL_VMX_ENABLED_INSIDE_SMX |
7103+
FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX;
71047104
else
71057105
to_vmx(vcpu)->msr_ia32_feature_control_valid_bits &=
7106-
~(FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX |
7107-
FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX);
7106+
~(FEAT_CTL_VMX_ENABLED_INSIDE_SMX |
7107+
FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX);
71087108

71097109
if (nested_vmx_allowed(vcpu)) {
71107110
nested_vmx_cr_fixed1_bits_update(vcpu);
@@ -7523,10 +7523,10 @@ static void vmx_setup_mce(struct kvm_vcpu *vcpu)
75237523
{
75247524
if (vcpu->arch.mcg_cap & MCG_LMCE_P)
75257525
to_vmx(vcpu)->msr_ia32_feature_control_valid_bits |=
7526-
FEATURE_CONTROL_LMCE;
7526+
FEAT_CTL_LMCE_ENABLED;
75277527
else
75287528
to_vmx(vcpu)->msr_ia32_feature_control_valid_bits &=
7529-
~FEATURE_CONTROL_LMCE;
7529+
~FEAT_CTL_LMCE_ENABLED;
75307530
}
75317531

75327532
static int vmx_smi_allowed(struct kvm_vcpu *vcpu)

‎arch/x86/kvm/vmx/vmx.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ struct vcpu_vmx {
289289

290290
/*
291291
* Only bits masked by msr_ia32_feature_control_valid_bits can be set in
292-
* msr_ia32_feature_control. FEATURE_CONTROL_LOCKED is always included
292+
* msr_ia32_feature_control. FEAT_CTL_LOCKED is always included
293293
* in msr_ia32_feature_control_valid_bits.
294294
*/
295295
u64 msr_ia32_feature_control;

‎arch/x86/kvm/x86.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ static const u32 msrs_to_save_all[] = {
11421142
MSR_CSTAR, MSR_KERNEL_GS_BASE, MSR_SYSCALL_MASK, MSR_LSTAR,
11431143
#endif
11441144
MSR_IA32_TSC, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA,
1145-
MSR_IA32_FEATURE_CONTROL, MSR_IA32_BNDCFGS, MSR_TSC_AUX,
1145+
MSR_IA32_FEAT_CTL, MSR_IA32_BNDCFGS, MSR_TSC_AUX,
11461146
MSR_IA32_SPEC_CTRL,
11471147
MSR_IA32_RTIT_CTL, MSR_IA32_RTIT_STATUS, MSR_IA32_RTIT_CR3_MATCH,
11481148
MSR_IA32_RTIT_OUTPUT_BASE, MSR_IA32_RTIT_OUTPUT_MASK,

‎drivers/idle/intel_idle.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ static void sklh_idle_state_table_update(void)
12841284
/* if SGX is present */
12851285
if (ebx & (1 << 2)) {
12861286

1287-
rdmsrl(MSR_IA32_FEATURE_CONTROL, msr);
1287+
rdmsrl(MSR_IA32_FEAT_CTL, msr);
12881288

12891289
/* if SGX is enabled */
12901290
if (msr & (1 << 18))

0 commit comments

Comments
 (0)