Skip to content

Commit 2d6cd68

Browse files
committed
KVM: VMX: Move MSR_IA32_FEAT_CTL.LOCKED check into "is valid" helper
Move the check on IA32_FEATURE_CONTROL being locked, i.e. read-only from the guest, into the helper to check the overall validity of the incoming value. Opportunistically rename the helper to make it clear that it returns a bool. No functional change intended. Signed-off-by: Sean Christopherson <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d2a00af commit 2d6cd68

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,8 +1850,8 @@ bool nested_vmx_allowed(struct kvm_vcpu *vcpu)
18501850
FEAT_CTL_SGX_ENABLED | \
18511851
FEAT_CTL_LMCE_ENABLED)
18521852

1853-
static inline bool vmx_feature_control_msr_valid(struct vcpu_vmx *vmx,
1854-
struct msr_data *msr)
1853+
static inline bool is_vmx_feature_control_msr_valid(struct vcpu_vmx *vmx,
1854+
struct msr_data *msr)
18551855
{
18561856
uint64_t valid_bits;
18571857

@@ -1862,6 +1862,10 @@ static inline bool vmx_feature_control_msr_valid(struct vcpu_vmx *vmx,
18621862
WARN_ON_ONCE(vmx->msr_ia32_feature_control_valid_bits &
18631863
~KVM_SUPPORTED_FEATURE_CONTROL);
18641864

1865+
if (!msr->host_initiated &&
1866+
(vmx->msr_ia32_feature_control & FEAT_CTL_LOCKED))
1867+
return false;
1868+
18651869
if (msr->host_initiated)
18661870
valid_bits = KVM_SUPPORTED_FEATURE_CONTROL;
18671871
else
@@ -2266,10 +2270,9 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
22662270
vcpu->arch.mcg_ext_ctl = data;
22672271
break;
22682272
case MSR_IA32_FEAT_CTL:
2269-
if (!vmx_feature_control_msr_valid(vmx, msr_info) ||
2270-
(to_vmx(vcpu)->msr_ia32_feature_control &
2271-
FEAT_CTL_LOCKED && !msr_info->host_initiated))
2273+
if (!is_vmx_feature_control_msr_valid(vmx, msr_info))
22722274
return 1;
2275+
22732276
vmx->msr_ia32_feature_control = data;
22742277
if (msr_info->host_initiated && data == 0)
22752278
vmx_leave_nested(vcpu);

0 commit comments

Comments
 (0)