Commit ee69c92b authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: x86: Return bool instead of int for CR4 and SREGS validity checks

Rework the common CR4 and SREGS checks to return a bool instead of an
int, i.e. true/false instead of 0/-EINVAL, and add "is" to the name to
clarify the polarity of the return value (which is effectively inverted
by this change).

No functional changed intended.
Signed-off-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
Message-Id: <20201007014417.29276-6-sean.j.christopherson@intel.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent c2fe3cd4
...@@ -254,7 +254,7 @@ static bool nested_vmcb_checks(struct vcpu_svm *svm, struct vmcb *vmcb12) ...@@ -254,7 +254,7 @@ static bool nested_vmcb_checks(struct vcpu_svm *svm, struct vmcb *vmcb12)
(vmcb12->save.cr3 & MSR_CR3_LONG_MBZ_MASK)) (vmcb12->save.cr3 & MSR_CR3_LONG_MBZ_MASK))
return false; return false;
} }
if (kvm_valid_cr4(&svm->vcpu, vmcb12->save.cr4)) if (!kvm_is_valid_cr4(&svm->vcpu, vmcb12->save.cr4))
return false; return false;
return nested_vmcb_check_controls(&vmcb12->control); return nested_vmcb_check_controls(&vmcb12->control);
......
...@@ -3100,7 +3100,7 @@ static bool vmx_is_valid_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) ...@@ -3100,7 +3100,7 @@ static bool vmx_is_valid_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
/* /*
* We operate under the default treatment of SMM, so VMX cannot be * We operate under the default treatment of SMM, so VMX cannot be
* enabled under SMM. Note, whether or not VMXE is allowed at all is * enabled under SMM. Note, whether or not VMXE is allowed at all is
* handled by kvm_valid_cr4(). * handled by kvm_is_valid_cr4().
*/ */
if ((cr4 & X86_CR4_VMXE) && is_smm(vcpu)) if ((cr4 & X86_CR4_VMXE) && is_smm(vcpu))
return false; return false;
......
...@@ -964,20 +964,17 @@ int kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr) ...@@ -964,20 +964,17 @@ int kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr)
} }
EXPORT_SYMBOL_GPL(kvm_set_xcr); EXPORT_SYMBOL_GPL(kvm_set_xcr);
int kvm_valid_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) bool kvm_is_valid_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
{ {
if (cr4 & cr4_reserved_bits) if (cr4 & cr4_reserved_bits)
return -EINVAL; return false;
if (cr4 & vcpu->arch.cr4_guest_rsvd_bits) if (cr4 & vcpu->arch.cr4_guest_rsvd_bits)
return -EINVAL; return false;
if (!kvm_x86_ops.is_valid_cr4(vcpu, cr4))
return -EINVAL;
return 0; return kvm_x86_ops.is_valid_cr4(vcpu, cr4);
} }
EXPORT_SYMBOL_GPL(kvm_valid_cr4); EXPORT_SYMBOL_GPL(kvm_is_valid_cr4);
int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
{ {
...@@ -986,7 +983,7 @@ int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) ...@@ -986,7 +983,7 @@ int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
X86_CR4_SMEP; X86_CR4_SMEP;
unsigned long mmu_role_bits = pdptr_bits | X86_CR4_SMAP | X86_CR4_PKE; unsigned long mmu_role_bits = pdptr_bits | X86_CR4_SMAP | X86_CR4_PKE;
if (kvm_valid_cr4(vcpu, cr4)) if (!kvm_is_valid_cr4(vcpu, cr4))
return 1; return 1;
if (is_long_mode(vcpu)) { if (is_long_mode(vcpu)) {
...@@ -9535,7 +9532,7 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int idt_index, ...@@ -9535,7 +9532,7 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int idt_index,
} }
EXPORT_SYMBOL_GPL(kvm_task_switch); EXPORT_SYMBOL_GPL(kvm_task_switch);
static int kvm_valid_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) static bool kvm_is_valid_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
{ {
if ((sregs->efer & EFER_LME) && (sregs->cr0 & X86_CR0_PG)) { if ((sregs->efer & EFER_LME) && (sregs->cr0 & X86_CR0_PG)) {
/* /*
...@@ -9543,19 +9540,18 @@ static int kvm_valid_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) ...@@ -9543,19 +9540,18 @@ static int kvm_valid_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
* 64-bit mode (though maybe in a 32-bit code segment). * 64-bit mode (though maybe in a 32-bit code segment).
* CR4.PAE and EFER.LMA must be set. * CR4.PAE and EFER.LMA must be set.
*/ */
if (!(sregs->cr4 & X86_CR4_PAE) if (!(sregs->cr4 & X86_CR4_PAE) || !(sregs->efer & EFER_LMA))
|| !(sregs->efer & EFER_LMA)) return false;
return -EINVAL;
} else { } else {
/* /*
* Not in 64-bit mode: EFER.LMA is clear and the code * Not in 64-bit mode: EFER.LMA is clear and the code
* segment cannot be 64-bit. * segment cannot be 64-bit.
*/ */
if (sregs->efer & EFER_LMA || sregs->cs.l) if (sregs->efer & EFER_LMA || sregs->cs.l)
return -EINVAL; return false;
} }
return kvm_valid_cr4(vcpu, sregs->cr4); return kvm_is_valid_cr4(vcpu, sregs->cr4);
} }
static int __set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) static int __set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
...@@ -9567,7 +9563,7 @@ static int __set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) ...@@ -9567,7 +9563,7 @@ static int __set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
struct desc_ptr dt; struct desc_ptr dt;
int ret = -EINVAL; int ret = -EINVAL;
if (kvm_valid_sregs(vcpu, sregs)) if (!kvm_is_valid_sregs(vcpu, sregs))
goto out; goto out;
apic_base_msr.data = sregs->apic_base; apic_base_msr.data = sregs->apic_base;
......
...@@ -369,7 +369,7 @@ static inline bool kvm_dr6_valid(u64 data) ...@@ -369,7 +369,7 @@ static inline bool kvm_dr6_valid(u64 data)
void kvm_load_guest_xsave_state(struct kvm_vcpu *vcpu); void kvm_load_guest_xsave_state(struct kvm_vcpu *vcpu);
void kvm_load_host_xsave_state(struct kvm_vcpu *vcpu); void kvm_load_host_xsave_state(struct kvm_vcpu *vcpu);
int kvm_spec_ctrl_test_value(u64 value); int kvm_spec_ctrl_test_value(u64 value);
int kvm_valid_cr4(struct kvm_vcpu *vcpu, unsigned long cr4); bool kvm_is_valid_cr4(struct kvm_vcpu *vcpu, unsigned long cr4);
bool kvm_vcpu_exit_request(struct kvm_vcpu *vcpu); bool kvm_vcpu_exit_request(struct kvm_vcpu *vcpu);
int kvm_handle_memory_failure(struct kvm_vcpu *vcpu, int r, int kvm_handle_memory_failure(struct kvm_vcpu *vcpu, int r,
struct x86_exception *e); struct x86_exception *e);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment