Commit d9048d32 authored by Mikhail Ershov's avatar Mikhail Ershov Committed by Avi Kivity

KVM: Use kvm_{read,write}_guest_virt() to read and write segment descriptors

Segment descriptors tables can be placed on two non-contiguous pages.
This patch makes reading segment descriptors by linear address.
Signed-off-by: default avatarMikhail Ershov <Mike.Ershov@gmail.com>
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent 7bdb5888
...@@ -4021,7 +4021,6 @@ static void get_segment_descriptor_dtable(struct kvm_vcpu *vcpu, ...@@ -4021,7 +4021,6 @@ static void get_segment_descriptor_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;
...@@ -4031,16 +4030,13 @@ static int load_guest_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector, ...@@ -4031,16 +4030,13 @@ 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;
} }
gpa = vcpu->arch.mmu.gva_to_gpa(vcpu, dtable.base); return kvm_read_guest_virt(dtable.base + index*8, seg_desc, sizeof(*seg_desc), vcpu);
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;
...@@ -4048,9 +4044,7 @@ static int save_guest_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector, ...@@ -4048,9 +4044,7 @@ 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;
gpa = vcpu->arch.mmu.gva_to_gpa(vcpu, dtable.base); return kvm_write_guest_virt(dtable.base + index*8, seg_desc, sizeof(*seg_desc), vcpu);
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,
......
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