Skip to content

Commit

Permalink
KVM: x86: cleanup enter_rmode()
Browse files Browse the repository at this point in the history
vmx_set_efer() sets uret->data but, in fact if the value of uret->data
will be used vmx_setup_uret_msrs() will have rewritten it with the value
returned by update_transition_efer().  uret->data is consumed if and only
if uret->load_into_hardware is true, and vmx_setup_uret_msrs() takes care
of (a) updating uret->data before setting uret->load_into_hardware to true
(b) setting uret->load_into_hardware to false if uret->data isn't updated.

Opportunistically use "vmx" directly instead of redoing to_vmx().

Signed-off-by: Zhenzhong Duan <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
duanzhenzhong authored and bonzini committed Apr 2, 2022
1 parent 8809931 commit b76edfe
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions arch/x86/kvm/vmx/vmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -2866,21 +2866,17 @@ static void enter_rmode(struct kvm_vcpu *vcpu)
int vmx_set_efer(struct kvm_vcpu *vcpu, u64 efer)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
struct vmx_uret_msr *msr = vmx_find_uret_msr(vmx, MSR_EFER);

/* Nothing to do if hardware doesn't support EFER. */
if (!msr)
if (!vmx_find_uret_msr(vmx, MSR_EFER))
return 0;

vcpu->arch.efer = efer;
if (efer & EFER_LMA) {
vm_entry_controls_setbit(to_vmx(vcpu), VM_ENTRY_IA32E_MODE);
msr->data = efer;
} else {
vm_entry_controls_clearbit(to_vmx(vcpu), VM_ENTRY_IA32E_MODE);
if (efer & EFER_LMA)
vm_entry_controls_setbit(vmx, VM_ENTRY_IA32E_MODE);
else
vm_entry_controls_clearbit(vmx, VM_ENTRY_IA32E_MODE);

msr->data = efer & ~EFER_LME;
}
vmx_setup_uret_msrs(vmx);
return 0;
}
Expand Down

0 comments on commit b76edfe

Please sign in to comment.