Commit baa7e81e authored by Avi Kivity's avatar Avi Kivity Committed by Marcelo Tosatti

KVM: VMX: Separate saving pre-realmode state from setting segments

Commit b246dd5d ("KVM: VMX: Fix KVM_SET_SREGS with big real mode
segments") moved fix_rmode_seg() to vmx_set_segment(), so that it is
applied not just on transitions to real mode, but also on KVM_SET_SREGS
(migration).  However fix_rmode_seg() not only munges the vmcs segments,
it also sets up the save area for us to restore when returning to
protected mode or to return in vmx_get_segment().

Move saving the segment into a new function, save_rmode_seg(), and
call it just during the transition.
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
parent dd856efa
...@@ -2768,7 +2768,7 @@ static gva_t rmode_tss_base(struct kvm *kvm) ...@@ -2768,7 +2768,7 @@ static gva_t rmode_tss_base(struct kvm *kvm)
return kvm->arch.tss_addr; return kvm->arch.tss_addr;
} }
static void fix_rmode_seg(int seg, struct kvm_save_segment *save) static void save_rmode_seg(int seg, struct kvm_save_segment *save)
{ {
struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg]; struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
...@@ -2776,6 +2776,12 @@ static void fix_rmode_seg(int seg, struct kvm_save_segment *save) ...@@ -2776,6 +2776,12 @@ static void fix_rmode_seg(int seg, struct kvm_save_segment *save)
save->base = vmcs_readl(sf->base); save->base = vmcs_readl(sf->base);
save->limit = vmcs_read32(sf->limit); save->limit = vmcs_read32(sf->limit);
save->ar = vmcs_read32(sf->ar_bytes); save->ar = vmcs_read32(sf->ar_bytes);
}
static void fix_rmode_seg(int seg, struct kvm_save_segment *save)
{
struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
vmcs_write16(sf->selector, save->base >> 4); vmcs_write16(sf->selector, save->base >> 4);
vmcs_write32(sf->base, save->base & 0xffff0); vmcs_write32(sf->base, save->base & 0xffff0);
vmcs_write32(sf->limit, 0xffff); vmcs_write32(sf->limit, 0xffff);
...@@ -2798,6 +2804,12 @@ static void enter_rmode(struct kvm_vcpu *vcpu) ...@@ -2798,6 +2804,12 @@ static void enter_rmode(struct kvm_vcpu *vcpu)
vmx->emulation_required = 1; vmx->emulation_required = 1;
vmx->rmode.vm86_active = 1; vmx->rmode.vm86_active = 1;
save_rmode_seg(VCPU_SREG_TR, &vmx->rmode.tr);
save_rmode_seg(VCPU_SREG_ES, &vmx->rmode.es);
save_rmode_seg(VCPU_SREG_DS, &vmx->rmode.ds);
save_rmode_seg(VCPU_SREG_FS, &vmx->rmode.fs);
save_rmode_seg(VCPU_SREG_GS, &vmx->rmode.gs);
/* /*
* Very old userspace does not call KVM_SET_TSS_ADDR before entering * Very old userspace does not call KVM_SET_TSS_ADDR before entering
* vcpu. Call it here with phys address pointing 16M below 4G. * vcpu. Call it here with phys address pointing 16M below 4G.
...@@ -2812,14 +2824,8 @@ static void enter_rmode(struct kvm_vcpu *vcpu) ...@@ -2812,14 +2824,8 @@ static void enter_rmode(struct kvm_vcpu *vcpu)
vmx_segment_cache_clear(vmx); vmx_segment_cache_clear(vmx);
vmx->rmode.tr.selector = vmcs_read16(GUEST_TR_SELECTOR);
vmx->rmode.tr.base = vmcs_readl(GUEST_TR_BASE);
vmcs_writel(GUEST_TR_BASE, rmode_tss_base(vcpu->kvm)); vmcs_writel(GUEST_TR_BASE, rmode_tss_base(vcpu->kvm));
vmx->rmode.tr.limit = vmcs_read32(GUEST_TR_LIMIT);
vmcs_write32(GUEST_TR_LIMIT, RMODE_TSS_SIZE - 1); vmcs_write32(GUEST_TR_LIMIT, RMODE_TSS_SIZE - 1);
vmx->rmode.tr.ar = vmcs_read32(GUEST_TR_AR_BYTES);
vmcs_write32(GUEST_TR_AR_BYTES, 0x008b); vmcs_write32(GUEST_TR_AR_BYTES, 0x008b);
flags = vmcs_readl(GUEST_RFLAGS); flags = vmcs_readl(GUEST_RFLAGS);
......
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