Commit 1dd7a4f1 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: VMX: Skip emulation required checks during pmode/rmode transitions

Don't refresh "emulation required" when stuffing segments during
transitions to/from real mode when running without unrestricted guest.
The checks are unnecessary as vmx_set_cr0() unconditionally rechecks
"emulation required".  They also happen to be broken, as enter_pmode()
and enter_rmode() run with a stale vcpu->arch.cr0.
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Message-Id: <20210713163324.627647-29-seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 32437c2a
...@@ -2719,6 +2719,8 @@ static __init int alloc_kvm_area(void) ...@@ -2719,6 +2719,8 @@ static __init int alloc_kvm_area(void)
return 0; return 0;
} }
static void __vmx_set_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg);
static void fix_pmode_seg(struct kvm_vcpu *vcpu, int seg, static void fix_pmode_seg(struct kvm_vcpu *vcpu, int seg,
struct kvm_segment *save) struct kvm_segment *save)
{ {
...@@ -2735,7 +2737,7 @@ static void fix_pmode_seg(struct kvm_vcpu *vcpu, int seg, ...@@ -2735,7 +2737,7 @@ static void fix_pmode_seg(struct kvm_vcpu *vcpu, int seg,
save->dpl = save->selector & SEGMENT_RPL_MASK; save->dpl = save->selector & SEGMENT_RPL_MASK;
save->s = 1; save->s = 1;
} }
vmx_set_segment(vcpu, save, seg); __vmx_set_segment(vcpu, save, seg);
} }
static void enter_pmode(struct kvm_vcpu *vcpu) static void enter_pmode(struct kvm_vcpu *vcpu)
...@@ -2756,7 +2758,7 @@ static void enter_pmode(struct kvm_vcpu *vcpu) ...@@ -2756,7 +2758,7 @@ static void enter_pmode(struct kvm_vcpu *vcpu)
vmx->rmode.vm86_active = 0; vmx->rmode.vm86_active = 0;
vmx_set_segment(vcpu, &vmx->rmode.segs[VCPU_SREG_TR], VCPU_SREG_TR); __vmx_set_segment(vcpu, &vmx->rmode.segs[VCPU_SREG_TR], VCPU_SREG_TR);
flags = vmcs_readl(GUEST_RFLAGS); flags = vmcs_readl(GUEST_RFLAGS);
flags &= RMODE_GUEST_OWNED_EFLAGS_BITS; flags &= RMODE_GUEST_OWNED_EFLAGS_BITS;
...@@ -3291,7 +3293,7 @@ static u32 vmx_segment_access_rights(struct kvm_segment *var) ...@@ -3291,7 +3293,7 @@ static u32 vmx_segment_access_rights(struct kvm_segment *var)
return ar; return ar;
} }
void vmx_set_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg) static void __vmx_set_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg)
{ {
struct vcpu_vmx *vmx = to_vmx(vcpu); struct vcpu_vmx *vmx = to_vmx(vcpu);
const struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg]; const struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
...@@ -3304,7 +3306,7 @@ void vmx_set_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg) ...@@ -3304,7 +3306,7 @@ void vmx_set_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg)
vmcs_write16(sf->selector, var->selector); vmcs_write16(sf->selector, var->selector);
else if (var->s) else if (var->s)
fix_rmode_seg(seg, &vmx->rmode.segs[seg]); fix_rmode_seg(seg, &vmx->rmode.segs[seg]);
goto out; return;
} }
vmcs_writel(sf->base, var->base); vmcs_writel(sf->base, var->base);
...@@ -3326,9 +3328,13 @@ void vmx_set_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg) ...@@ -3326,9 +3328,13 @@ void vmx_set_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg)
var->type |= 0x1; /* Accessed */ var->type |= 0x1; /* Accessed */
vmcs_write32(sf->ar_bytes, vmx_segment_access_rights(var)); vmcs_write32(sf->ar_bytes, vmx_segment_access_rights(var));
}
out: void vmx_set_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg)
vmx->emulation_required = emulation_required(vcpu); {
__vmx_set_segment(vcpu, var, seg);
to_vmx(vcpu)->emulation_required = emulation_required(vcpu);
} }
static void vmx_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l) static void vmx_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l)
......
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