Commit 2594ba0a authored by Marcelo Tosatti's avatar Marcelo Tosatti Committed by Greg Kroah-Hartman

KVM: task switch: segment base is linear address

(cherry picked from commit 98899aa0)

The segment base is always a linear address, so translate before
accessing guest memory.
Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: default avatarAvi Kivity <avi@qumranet.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent f6c6fd90
...@@ -3207,6 +3207,7 @@ static void get_segment_descritptor_dtable(struct kvm_vcpu *vcpu, ...@@ -3207,6 +3207,7 @@ static void get_segment_descritptor_dtable(struct kvm_vcpu *vcpu,
static int load_guest_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector, static int load_guest_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector,
struct desc_struct *seg_desc) struct desc_struct *seg_desc)
{ {
gpa_t gpa;
struct descriptor_table dtable; struct descriptor_table dtable;
u16 index = selector >> 3; u16 index = selector >> 3;
...@@ -3216,13 +3217,16 @@ static int load_guest_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector, ...@@ -3216,13 +3217,16 @@ static int load_guest_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector,
kvm_queue_exception_e(vcpu, GP_VECTOR, selector & 0xfffc); kvm_queue_exception_e(vcpu, GP_VECTOR, selector & 0xfffc);
return 1; return 1;
} }
return kvm_read_guest(vcpu->kvm, dtable.base + index * 8, seg_desc, 8); gpa = vcpu->arch.mmu.gva_to_gpa(vcpu, dtable.base);
gpa += index * 8;
return kvm_read_guest(vcpu->kvm, gpa, seg_desc, 8);
} }
/* allowed just for 8 bytes segments */ /* allowed just for 8 bytes segments */
static int save_guest_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector, static int save_guest_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector,
struct desc_struct *seg_desc) struct desc_struct *seg_desc)
{ {
gpa_t gpa;
struct descriptor_table dtable; struct descriptor_table dtable;
u16 index = selector >> 3; u16 index = selector >> 3;
...@@ -3230,7 +3234,9 @@ static int save_guest_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector, ...@@ -3230,7 +3234,9 @@ static int save_guest_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector,
if (dtable.limit < index * 8 + 7) if (dtable.limit < index * 8 + 7)
return 1; return 1;
return kvm_write_guest(vcpu->kvm, dtable.base + index * 8, seg_desc, 8); gpa = vcpu->arch.mmu.gva_to_gpa(vcpu, dtable.base);
gpa += index * 8;
return kvm_write_guest(vcpu->kvm, gpa, seg_desc, 8);
} }
static u32 get_tss_base_addr(struct kvm_vcpu *vcpu, static u32 get_tss_base_addr(struct kvm_vcpu *vcpu,
...@@ -3242,7 +3248,7 @@ static u32 get_tss_base_addr(struct kvm_vcpu *vcpu, ...@@ -3242,7 +3248,7 @@ static u32 get_tss_base_addr(struct kvm_vcpu *vcpu,
base_addr |= (seg_desc->base1 << 16); base_addr |= (seg_desc->base1 << 16);
base_addr |= (seg_desc->base2 << 24); base_addr |= (seg_desc->base2 << 24);
return base_addr; return vcpu->arch.mmu.gva_to_gpa(vcpu, base_addr);
} }
static int load_tss_segment32(struct kvm_vcpu *vcpu, static int load_tss_segment32(struct kvm_vcpu *vcpu,
......
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