Skip to content

Commit

Permalink
KVM: Fix load_guest_segment_descriptor() to inject page fault
Browse files Browse the repository at this point in the history
This patch injects page fault when reading descriptor in
load_guest_segment_descriptor() fails with FAULT.

Effects of this injection: This function is used by
kvm_load_segment_descriptor() which is necessary for the
following instructions:

 - mov seg,r/m16
 - jmp far
 - pop ?s

This patch makes it possible to emulate the page faults
generated by these instructions. But be sure that unless
we change the kvm_load_segment_descriptor()'s ret value
propagation this patch has no effect.

Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
  • Loading branch information
Takuya Yoshikawa authored and Marcelo Tosatti committed Mar 1, 2010
1 parent 8b9f441 commit 6f55048
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -4713,16 +4713,23 @@ static int load_guest_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector,
{
struct descriptor_table dtable;
u16 index = selector >> 3;
int ret;
u32 err;
gva_t addr;

get_segment_descriptor_dtable(vcpu, selector, &dtable);

if (dtable.limit < index * 8 + 7) {
kvm_queue_exception_e(vcpu, GP_VECTOR, selector & 0xfffc);
return X86EMUL_PROPAGATE_FAULT;
}
return kvm_read_guest_virt_system(dtable.base + index*8,
seg_desc, sizeof(*seg_desc),
vcpu, NULL);
addr = dtable.base + index * 8;
ret = kvm_read_guest_virt_system(addr, seg_desc, sizeof(*seg_desc),
vcpu, &err);
if (ret == X86EMUL_PROPAGATE_FAULT)
kvm_inject_page_fault(vcpu, addr, err);

return ret;
}

/* allowed just for 8 bytes segments */
Expand Down

0 comments on commit 6f55048

Please sign in to comment.