Commit bcc55cba authored by Avi Kivity's avatar Avi Kivity

KVM: x86 emulator: make emulator memory callbacks return full exception

This way, they can return #GP, not just #PF.
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
parent da9cb575
...@@ -70,7 +70,8 @@ struct x86_emulate_ops { ...@@ -70,7 +70,8 @@ struct x86_emulate_ops {
* @bytes: [IN ] Number of bytes to read from memory. * @bytes: [IN ] Number of bytes to read from memory.
*/ */
int (*read_std)(unsigned long addr, void *val, int (*read_std)(unsigned long addr, void *val,
unsigned int bytes, struct kvm_vcpu *vcpu, u32 *error); unsigned int bytes, struct kvm_vcpu *vcpu,
struct x86_exception *fault);
/* /*
* write_std: Write bytes of standard (non-emulated/special) memory. * write_std: Write bytes of standard (non-emulated/special) memory.
...@@ -80,7 +81,8 @@ struct x86_emulate_ops { ...@@ -80,7 +81,8 @@ struct x86_emulate_ops {
* @bytes: [IN ] Number of bytes to write to memory. * @bytes: [IN ] Number of bytes to write to memory.
*/ */
int (*write_std)(unsigned long addr, void *val, int (*write_std)(unsigned long addr, void *val,
unsigned int bytes, struct kvm_vcpu *vcpu, u32 *error); unsigned int bytes, struct kvm_vcpu *vcpu,
struct x86_exception *fault);
/* /*
* fetch: Read bytes of standard (non-emulated/special) memory. * fetch: Read bytes of standard (non-emulated/special) memory.
* Used for instruction fetch. * Used for instruction fetch.
...@@ -89,7 +91,8 @@ struct x86_emulate_ops { ...@@ -89,7 +91,8 @@ struct x86_emulate_ops {
* @bytes: [IN ] Number of bytes to read from memory. * @bytes: [IN ] Number of bytes to read from memory.
*/ */
int (*fetch)(unsigned long addr, void *val, int (*fetch)(unsigned long addr, void *val,
unsigned int bytes, struct kvm_vcpu *vcpu, u32 *error); unsigned int bytes, struct kvm_vcpu *vcpu,
struct x86_exception *fault);
/* /*
* read_emulated: Read bytes from emulated/special memory area. * read_emulated: Read bytes from emulated/special memory area.
...@@ -100,7 +103,7 @@ struct x86_emulate_ops { ...@@ -100,7 +103,7 @@ struct x86_emulate_ops {
int (*read_emulated)(unsigned long addr, int (*read_emulated)(unsigned long addr,
void *val, void *val,
unsigned int bytes, unsigned int bytes,
unsigned int *error, struct x86_exception *fault,
struct kvm_vcpu *vcpu); struct kvm_vcpu *vcpu);
/* /*
...@@ -113,7 +116,7 @@ struct x86_emulate_ops { ...@@ -113,7 +116,7 @@ struct x86_emulate_ops {
int (*write_emulated)(unsigned long addr, int (*write_emulated)(unsigned long addr,
const void *val, const void *val,
unsigned int bytes, unsigned int bytes,
unsigned int *error, struct x86_exception *fault,
struct kvm_vcpu *vcpu); struct kvm_vcpu *vcpu);
/* /*
...@@ -128,7 +131,7 @@ struct x86_emulate_ops { ...@@ -128,7 +131,7 @@ struct x86_emulate_ops {
const void *old, const void *old,
const void *new, const void *new,
unsigned int bytes, unsigned int bytes,
unsigned int *error, struct x86_exception *fault,
struct kvm_vcpu *vcpu); struct kvm_vcpu *vcpu);
int (*pio_in_emulated)(int size, unsigned short port, void *val, int (*pio_in_emulated)(int size, unsigned short port, void *val,
......
...@@ -512,7 +512,7 @@ static int do_fetch_insn_byte(struct x86_emulate_ctxt *ctxt, ...@@ -512,7 +512,7 @@ static int do_fetch_insn_byte(struct x86_emulate_ctxt *ctxt,
cur_size = fc->end - fc->start; cur_size = fc->end - fc->start;
size = min(15UL - cur_size, PAGE_SIZE - offset_in_page(eip)); size = min(15UL - cur_size, PAGE_SIZE - offset_in_page(eip));
rc = ops->fetch(ctxt->cs_base + eip, fc->data + cur_size, rc = ops->fetch(ctxt->cs_base + eip, fc->data + cur_size,
size, ctxt->vcpu, NULL); size, ctxt->vcpu, &ctxt->exception);
if (rc != X86EMUL_CONTINUE) if (rc != X86EMUL_CONTINUE)
return rc; return rc;
fc->end += size; fc->end += size;
...@@ -565,12 +565,12 @@ static int read_descriptor(struct x86_emulate_ctxt *ctxt, ...@@ -565,12 +565,12 @@ static int read_descriptor(struct x86_emulate_ctxt *ctxt,
op_bytes = 3; op_bytes = 3;
*address = 0; *address = 0;
rc = ops->read_std(linear(ctxt, addr), (unsigned long *)size, 2, rc = ops->read_std(linear(ctxt, addr), (unsigned long *)size, 2,
ctxt->vcpu, NULL); ctxt->vcpu, &ctxt->exception);
if (rc != X86EMUL_CONTINUE) if (rc != X86EMUL_CONTINUE)
return rc; return rc;
addr.ea += 2; addr.ea += 2;
rc = ops->read_std(linear(ctxt, addr), address, op_bytes, rc = ops->read_std(linear(ctxt, addr), address, op_bytes,
ctxt->vcpu, NULL); ctxt->vcpu, &ctxt->exception);
return rc; return rc;
} }
...@@ -816,7 +816,6 @@ static int read_emulated(struct x86_emulate_ctxt *ctxt, ...@@ -816,7 +816,6 @@ static int read_emulated(struct x86_emulate_ctxt *ctxt,
{ {
int rc; int rc;
struct read_cache *mc = &ctxt->decode.mem_read; struct read_cache *mc = &ctxt->decode.mem_read;
u32 err;
while (size) { while (size) {
int n = min(size, 8u); int n = min(size, 8u);
...@@ -824,10 +823,8 @@ static int read_emulated(struct x86_emulate_ctxt *ctxt, ...@@ -824,10 +823,8 @@ static int read_emulated(struct x86_emulate_ctxt *ctxt,
if (mc->pos < mc->end) if (mc->pos < mc->end)
goto read_cached; goto read_cached;
rc = ops->read_emulated(addr, mc->data + mc->end, n, &err, rc = ops->read_emulated(addr, mc->data + mc->end, n,
ctxt->vcpu); &ctxt->exception, ctxt->vcpu);
if (rc == X86EMUL_PROPAGATE_FAULT)
emulate_pf(ctxt);
if (rc != X86EMUL_CONTINUE) if (rc != X86EMUL_CONTINUE)
return rc; return rc;
mc->end += n; mc->end += n;
...@@ -902,7 +899,6 @@ static int read_segment_descriptor(struct x86_emulate_ctxt *ctxt, ...@@ -902,7 +899,6 @@ static int read_segment_descriptor(struct x86_emulate_ctxt *ctxt,
struct desc_ptr dt; struct desc_ptr dt;
u16 index = selector >> 3; u16 index = selector >> 3;
int ret; int ret;
u32 err;
ulong addr; ulong addr;
get_descriptor_table_ptr(ctxt, ops, selector, &dt); get_descriptor_table_ptr(ctxt, ops, selector, &dt);
...@@ -912,9 +908,8 @@ static int read_segment_descriptor(struct x86_emulate_ctxt *ctxt, ...@@ -912,9 +908,8 @@ static int read_segment_descriptor(struct x86_emulate_ctxt *ctxt,
return X86EMUL_PROPAGATE_FAULT; return X86EMUL_PROPAGATE_FAULT;
} }
addr = dt.address + index * 8; addr = dt.address + index * 8;
ret = ops->read_std(addr, desc, sizeof *desc, ctxt->vcpu, &err); ret = ops->read_std(addr, desc, sizeof *desc, ctxt->vcpu,
if (ret == X86EMUL_PROPAGATE_FAULT) &ctxt->exception);
emulate_pf(ctxt);
return ret; return ret;
} }
...@@ -926,7 +921,6 @@ static int write_segment_descriptor(struct x86_emulate_ctxt *ctxt, ...@@ -926,7 +921,6 @@ static int write_segment_descriptor(struct x86_emulate_ctxt *ctxt,
{ {
struct desc_ptr dt; struct desc_ptr dt;
u16 index = selector >> 3; u16 index = selector >> 3;
u32 err;
ulong addr; ulong addr;
int ret; int ret;
...@@ -938,9 +932,8 @@ static int write_segment_descriptor(struct x86_emulate_ctxt *ctxt, ...@@ -938,9 +932,8 @@ static int write_segment_descriptor(struct x86_emulate_ctxt *ctxt,
} }
addr = dt.address + index * 8; addr = dt.address + index * 8;
ret = ops->write_std(addr, desc, sizeof *desc, ctxt->vcpu, &err); ret = ops->write_std(addr, desc, sizeof *desc, ctxt->vcpu,
if (ret == X86EMUL_PROPAGATE_FAULT) &ctxt->exception);
emulate_pf(ctxt);
return ret; return ret;
} }
...@@ -1087,7 +1080,6 @@ static inline int writeback(struct x86_emulate_ctxt *ctxt, ...@@ -1087,7 +1080,6 @@ static inline int writeback(struct x86_emulate_ctxt *ctxt,
{ {
int rc; int rc;
struct decode_cache *c = &ctxt->decode; struct decode_cache *c = &ctxt->decode;
u32 err;
switch (c->dst.type) { switch (c->dst.type) {
case OP_REG: case OP_REG:
...@@ -1100,17 +1092,15 @@ static inline int writeback(struct x86_emulate_ctxt *ctxt, ...@@ -1100,17 +1092,15 @@ static inline int writeback(struct x86_emulate_ctxt *ctxt,
&c->dst.orig_val, &c->dst.orig_val,
&c->dst.val, &c->dst.val,
c->dst.bytes, c->dst.bytes,
&err, &ctxt->exception,
ctxt->vcpu); ctxt->vcpu);
else else
rc = ops->write_emulated( rc = ops->write_emulated(
linear(ctxt, c->dst.addr.mem), linear(ctxt, c->dst.addr.mem),
&c->dst.val, &c->dst.val,
c->dst.bytes, c->dst.bytes,
&err, &ctxt->exception,
ctxt->vcpu); ctxt->vcpu);
if (rc == X86EMUL_PROPAGATE_FAULT)
emulate_pf(ctxt);
if (rc != X86EMUL_CONTINUE) if (rc != X86EMUL_CONTINUE)
return rc; return rc;
break; break;
...@@ -1283,7 +1273,6 @@ int emulate_int_real(struct x86_emulate_ctxt *ctxt, ...@@ -1283,7 +1273,6 @@ int emulate_int_real(struct x86_emulate_ctxt *ctxt,
gva_t cs_addr; gva_t cs_addr;
gva_t eip_addr; gva_t eip_addr;
u16 cs, eip; u16 cs, eip;
u32 err;
/* TODO: Add limit checks */ /* TODO: Add limit checks */
c->src.val = ctxt->eflags; c->src.val = ctxt->eflags;
...@@ -1313,11 +1302,11 @@ int emulate_int_real(struct x86_emulate_ctxt *ctxt, ...@@ -1313,11 +1302,11 @@ int emulate_int_real(struct x86_emulate_ctxt *ctxt,
eip_addr = dt.address + (irq << 2); eip_addr = dt.address + (irq << 2);
cs_addr = dt.address + (irq << 2) + 2; cs_addr = dt.address + (irq << 2) + 2;
rc = ops->read_std(cs_addr, &cs, 2, ctxt->vcpu, &err); rc = ops->read_std(cs_addr, &cs, 2, ctxt->vcpu, &ctxt->exception);
if (rc != X86EMUL_CONTINUE) if (rc != X86EMUL_CONTINUE)
return rc; return rc;
rc = ops->read_std(eip_addr, &eip, 2, ctxt->vcpu, &err); rc = ops->read_std(eip_addr, &eip, 2, ctxt->vcpu, &ctxt->exception);
if (rc != X86EMUL_CONTINUE) if (rc != X86EMUL_CONTINUE)
return rc; return rc;
...@@ -1930,33 +1919,27 @@ static int task_switch_16(struct x86_emulate_ctxt *ctxt, ...@@ -1930,33 +1919,27 @@ static int task_switch_16(struct x86_emulate_ctxt *ctxt,
{ {
struct tss_segment_16 tss_seg; struct tss_segment_16 tss_seg;
int ret; int ret;
u32 err, new_tss_base = get_desc_base(new_desc); u32 new_tss_base = get_desc_base(new_desc);
ret = ops->read_std(old_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu, ret = ops->read_std(old_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu,
&err); &ctxt->exception);
if (ret == X86EMUL_PROPAGATE_FAULT) { if (ret == X86EMUL_PROPAGATE_FAULT)
/* FIXME: need to provide precise fault address */ /* FIXME: need to provide precise fault address */
emulate_pf(ctxt);
return ret; return ret;
}
save_state_to_tss16(ctxt, ops, &tss_seg); save_state_to_tss16(ctxt, ops, &tss_seg);
ret = ops->write_std(old_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu, ret = ops->write_std(old_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu,
&err); &ctxt->exception);
if (ret == X86EMUL_PROPAGATE_FAULT) { if (ret == X86EMUL_PROPAGATE_FAULT)
/* FIXME: need to provide precise fault address */ /* FIXME: need to provide precise fault address */
emulate_pf(ctxt);
return ret; return ret;
}
ret = ops->read_std(new_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu, ret = ops->read_std(new_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu,
&err); &ctxt->exception);
if (ret == X86EMUL_PROPAGATE_FAULT) { if (ret == X86EMUL_PROPAGATE_FAULT)
/* FIXME: need to provide precise fault address */ /* FIXME: need to provide precise fault address */
emulate_pf(ctxt);
return ret; return ret;
}
if (old_tss_sel != 0xffff) { if (old_tss_sel != 0xffff) {
tss_seg.prev_task_link = old_tss_sel; tss_seg.prev_task_link = old_tss_sel;
...@@ -1964,12 +1947,10 @@ static int task_switch_16(struct x86_emulate_ctxt *ctxt, ...@@ -1964,12 +1947,10 @@ static int task_switch_16(struct x86_emulate_ctxt *ctxt,
ret = ops->write_std(new_tss_base, ret = ops->write_std(new_tss_base,
&tss_seg.prev_task_link, &tss_seg.prev_task_link,
sizeof tss_seg.prev_task_link, sizeof tss_seg.prev_task_link,
ctxt->vcpu, &err); ctxt->vcpu, &ctxt->exception);
if (ret == X86EMUL_PROPAGATE_FAULT) { if (ret == X86EMUL_PROPAGATE_FAULT)
/* FIXME: need to provide precise fault address */ /* FIXME: need to provide precise fault address */
emulate_pf(ctxt);
return ret; return ret;
}
} }
return load_state_from_tss16(ctxt, ops, &tss_seg); return load_state_from_tss16(ctxt, ops, &tss_seg);
...@@ -2072,33 +2053,27 @@ static int task_switch_32(struct x86_emulate_ctxt *ctxt, ...@@ -2072,33 +2053,27 @@ static int task_switch_32(struct x86_emulate_ctxt *ctxt,
{ {
struct tss_segment_32 tss_seg; struct tss_segment_32 tss_seg;
int ret; int ret;
u32 err, new_tss_base = get_desc_base(new_desc); u32 new_tss_base = get_desc_base(new_desc);
ret = ops->read_std(old_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu, ret = ops->read_std(old_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu,
&err); &ctxt->exception);
if (ret == X86EMUL_PROPAGATE_FAULT) { if (ret == X86EMUL_PROPAGATE_FAULT)
/* FIXME: need to provide precise fault address */ /* FIXME: need to provide precise fault address */
emulate_pf(ctxt);
return ret; return ret;
}
save_state_to_tss32(ctxt, ops, &tss_seg); save_state_to_tss32(ctxt, ops, &tss_seg);
ret = ops->write_std(old_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu, ret = ops->write_std(old_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu,
&err); &ctxt->exception);
if (ret == X86EMUL_PROPAGATE_FAULT) { if (ret == X86EMUL_PROPAGATE_FAULT)
/* FIXME: need to provide precise fault address */ /* FIXME: need to provide precise fault address */
emulate_pf(ctxt);
return ret; return ret;
}
ret = ops->read_std(new_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu, ret = ops->read_std(new_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu,
&err); &ctxt->exception);
if (ret == X86EMUL_PROPAGATE_FAULT) { if (ret == X86EMUL_PROPAGATE_FAULT)
/* FIXME: need to provide precise fault address */ /* FIXME: need to provide precise fault address */
emulate_pf(ctxt);
return ret; return ret;
}
if (old_tss_sel != 0xffff) { if (old_tss_sel != 0xffff) {
tss_seg.prev_task_link = old_tss_sel; tss_seg.prev_task_link = old_tss_sel;
...@@ -2106,12 +2081,10 @@ static int task_switch_32(struct x86_emulate_ctxt *ctxt, ...@@ -2106,12 +2081,10 @@ static int task_switch_32(struct x86_emulate_ctxt *ctxt,
ret = ops->write_std(new_tss_base, ret = ops->write_std(new_tss_base,
&tss_seg.prev_task_link, &tss_seg.prev_task_link,
sizeof tss_seg.prev_task_link, sizeof tss_seg.prev_task_link,
ctxt->vcpu, &err); ctxt->vcpu, &ctxt->exception);
if (ret == X86EMUL_PROPAGATE_FAULT) { if (ret == X86EMUL_PROPAGATE_FAULT)
/* FIXME: need to provide precise fault address */ /* FIXME: need to provide precise fault address */
emulate_pf(ctxt);
return ret; return ret;
}
} }
return load_state_from_tss32(ctxt, ops, &tss_seg); return load_state_from_tss32(ctxt, ops, &tss_seg);
......
...@@ -3642,24 +3642,31 @@ gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva, u32 *error) ...@@ -3642,24 +3642,31 @@ gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva, u32 *error)
return vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, 0, error); return vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, 0, error);
} }
static int make_page_fault(struct x86_exception *exception, u32 error)
{
exception->vector = PF_VECTOR;
exception->error_code_valid = true;
exception->error_code = error;
return X86EMUL_PROPAGATE_FAULT;
}
static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes, static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes,
struct kvm_vcpu *vcpu, u32 access, struct kvm_vcpu *vcpu, u32 access,
u32 *error) struct x86_exception *exception)
{ {
void *data = val; void *data = val;
int r = X86EMUL_CONTINUE; int r = X86EMUL_CONTINUE;
u32 error;
while (bytes) { while (bytes) {
gpa_t gpa = vcpu->arch.walk_mmu->gva_to_gpa(vcpu, addr, access, gpa_t gpa = vcpu->arch.walk_mmu->gva_to_gpa(vcpu, addr, access,
error); &error);
unsigned offset = addr & (PAGE_SIZE-1); unsigned offset = addr & (PAGE_SIZE-1);
unsigned toread = min(bytes, (unsigned)PAGE_SIZE - offset); unsigned toread = min(bytes, (unsigned)PAGE_SIZE - offset);
int ret; int ret;
if (gpa == UNMAPPED_GVA) { if (gpa == UNMAPPED_GVA)
r = X86EMUL_PROPAGATE_FAULT; return make_page_fault(exception, error);
goto out;
}
ret = kvm_read_guest(vcpu->kvm, gpa, data, toread); ret = kvm_read_guest(vcpu->kvm, gpa, data, toread);
if (ret < 0) { if (ret < 0) {
r = X86EMUL_IO_NEEDED; r = X86EMUL_IO_NEEDED;
...@@ -3676,47 +3683,50 @@ static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes, ...@@ -3676,47 +3683,50 @@ static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes,
/* used for instruction fetching */ /* used for instruction fetching */
static int kvm_fetch_guest_virt(gva_t addr, void *val, unsigned int bytes, static int kvm_fetch_guest_virt(gva_t addr, void *val, unsigned int bytes,
struct kvm_vcpu *vcpu, u32 *error) struct kvm_vcpu *vcpu,
struct x86_exception *exception)
{ {
u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0; u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0;
return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, return kvm_read_guest_virt_helper(addr, val, bytes, vcpu,
access | PFERR_FETCH_MASK, error); access | PFERR_FETCH_MASK,
exception);
} }
static int kvm_read_guest_virt(gva_t addr, void *val, unsigned int bytes, static int kvm_read_guest_virt(gva_t addr, void *val, unsigned int bytes,
struct kvm_vcpu *vcpu, u32 *error) struct kvm_vcpu *vcpu,
struct x86_exception *exception)
{ {
u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0; u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0;
return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, access, return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, access,
error); exception);
} }
static int kvm_read_guest_virt_system(gva_t addr, void *val, unsigned int bytes, static int kvm_read_guest_virt_system(gva_t addr, void *val, unsigned int bytes,
struct kvm_vcpu *vcpu, u32 *error) struct kvm_vcpu *vcpu,
struct x86_exception *exception)
{ {
return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, 0, error); return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, 0, exception);
} }
static int kvm_write_guest_virt_system(gva_t addr, void *val, static int kvm_write_guest_virt_system(gva_t addr, void *val,
unsigned int bytes, unsigned int bytes,
struct kvm_vcpu *vcpu, struct kvm_vcpu *vcpu,
u32 *error) struct x86_exception *exception)
{ {
void *data = val; void *data = val;
int r = X86EMUL_CONTINUE; int r = X86EMUL_CONTINUE;
u32 error;
while (bytes) { while (bytes) {
gpa_t gpa = vcpu->arch.walk_mmu->gva_to_gpa(vcpu, addr, gpa_t gpa = vcpu->arch.walk_mmu->gva_to_gpa(vcpu, addr,
PFERR_WRITE_MASK, PFERR_WRITE_MASK,
error); &error);
unsigned offset = addr & (PAGE_SIZE-1); unsigned offset = addr & (PAGE_SIZE-1);
unsigned towrite = min(bytes, (unsigned)PAGE_SIZE - offset); unsigned towrite = min(bytes, (unsigned)PAGE_SIZE - offset);
int ret; int ret;
if (gpa == UNMAPPED_GVA) { if (gpa == UNMAPPED_GVA)
r = X86EMUL_PROPAGATE_FAULT; return make_page_fault(exception, error);
goto out;
}
ret = kvm_write_guest(vcpu->kvm, gpa, data, towrite); ret = kvm_write_guest(vcpu->kvm, gpa, data, towrite);
if (ret < 0) { if (ret < 0) {
r = X86EMUL_IO_NEEDED; r = X86EMUL_IO_NEEDED;
...@@ -3734,10 +3744,11 @@ static int kvm_write_guest_virt_system(gva_t addr, void *val, ...@@ -3734,10 +3744,11 @@ static int kvm_write_guest_virt_system(gva_t addr, void *val,
static int emulator_read_emulated(unsigned long addr, static int emulator_read_emulated(unsigned long addr,
void *val, void *val,
unsigned int bytes, unsigned int bytes,
unsigned int *error_code, struct x86_exception *exception,
struct kvm_vcpu *vcpu) struct kvm_vcpu *vcpu)
{ {
gpa_t gpa; gpa_t gpa;
u32 error_code;
if (vcpu->mmio_read_completed) { if (vcpu->mmio_read_completed) {
memcpy(val, vcpu->mmio_data, bytes); memcpy(val, vcpu->mmio_data, bytes);
...@@ -3747,17 +3758,17 @@ static int emulator_read_emulated(unsigned long addr, ...@@ -3747,17 +3758,17 @@ static int emulator_read_emulated(unsigned long addr,
return X86EMUL_CONTINUE; return X86EMUL_CONTINUE;
} }
gpa = kvm_mmu_gva_to_gpa_read(vcpu, addr, error_code); gpa = kvm_mmu_gva_to_gpa_read(vcpu, addr, &error_code);
if (gpa == UNMAPPED_GVA) if (gpa == UNMAPPED_GVA)
return X86EMUL_PROPAGATE_FAULT; return make_page_fault(exception, error_code);
/* For APIC access vmexit */ /* For APIC access vmexit */
if ((gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE) if ((gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE)
goto mmio; goto mmio;
if (kvm_read_guest_virt(addr, val, bytes, vcpu, NULL) if (kvm_read_guest_virt(addr, val, bytes, vcpu, exception)
== X86EMUL_CONTINUE) == X86EMUL_CONTINUE)
return X86EMUL_CONTINUE; return X86EMUL_CONTINUE;
mmio: mmio:
...@@ -3781,7 +3792,7 @@ static int emulator_read_emulated(unsigned long addr, ...@@ -3781,7 +3792,7 @@ static int emulator_read_emulated(unsigned long addr,
} }
int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa, int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
const void *val, int bytes) const void *val, int bytes)
{ {
int ret; int ret;
...@@ -3795,15 +3806,16 @@ int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa, ...@@ -3795,15 +3806,16 @@ int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
static int emulator_write_emulated_onepage(unsigned long addr, static int emulator_write_emulated_onepage(unsigned long addr,
const void *val, const void *val,
unsigned int bytes, unsigned int bytes,
unsigned int *error_code, struct x86_exception *exception,
struct kvm_vcpu *vcpu) struct kvm_vcpu *vcpu)
{ {
gpa_t gpa; gpa_t gpa;
u32 error_code;
gpa = kvm_mmu_gva_to_gpa_write(vcpu, addr, error_code); gpa = kvm_mmu_gva_to_gpa_write(vcpu, addr, &error_code);
if (gpa == UNMAPPED_GVA) if (gpa == UNMAPPED_GVA)
return X86EMUL_PROPAGATE_FAULT; return make_page_fault(exception, error_code);
/* For APIC access vmexit */ /* For APIC access vmexit */
if ((gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE) if ((gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE)
...@@ -3833,7 +3845,7 @@ static int emulator_write_emulated_onepage(unsigned long addr, ...@@ -3833,7 +3845,7 @@ static int emulator_write_emulated_onepage(unsigned long addr,
int emulator_write_emulated(unsigned long addr, int emulator_write_emulated(unsigned long addr,
const void *val, const void *val,
unsigned int bytes, unsigned int bytes,
unsigned int *error_code, struct x86_exception *exception,
struct kvm_vcpu *vcpu) struct kvm_vcpu *vcpu)
{ {
/* Crossing a page boundary? */ /* Crossing a page boundary? */
...@@ -3841,7 +3853,7 @@ int emulator_write_emulated(unsigned long addr, ...@@ -3841,7 +3853,7 @@ int emulator_write_emulated(unsigned long addr,
int rc, now; int rc, now;
now = -addr & ~PAGE_MASK; now = -addr & ~PAGE_MASK;
rc = emulator_write_emulated_onepage(addr, val, now, error_code, rc = emulator_write_emulated_onepage(addr, val, now, exception,
vcpu); vcpu);
if (rc != X86EMUL_CONTINUE) if (rc != X86EMUL_CONTINUE)
return rc; return rc;
...@@ -3849,7 +3861,7 @@ int emulator_write_emulated(unsigned long addr, ...@@ -3849,7 +3861,7 @@ int emulator_write_emulated(unsigned long addr,
val += now; val += now;
bytes -= now; bytes -= now;
} }
return emulator_write_emulated_onepage(addr, val, bytes, error_code, return emulator_write_emulated_onepage(addr, val, bytes, exception,
vcpu); vcpu);
} }
...@@ -3867,7 +3879,7 @@ static int emulator_cmpxchg_emulated(unsigned long addr, ...@@ -3867,7 +3879,7 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
const void *old, const void *old,
const void *new, const void *new,
unsigned int bytes, unsigned int bytes,
unsigned int *error_code, struct x86_exception *exception,
struct kvm_vcpu *vcpu) struct kvm_vcpu *vcpu)
{ {
gpa_t gpa; gpa_t gpa;
...@@ -3925,7 +3937,7 @@ static int emulator_cmpxchg_emulated(unsigned long addr, ...@@ -3925,7 +3937,7 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
emul_write: emul_write:
printk_once(KERN_WARNING "kvm: emulating exchange as write\n"); printk_once(KERN_WARNING "kvm: emulating exchange as write\n");
return emulator_write_emulated(addr, new, bytes, error_code, vcpu); return emulator_write_emulated(addr, new, bytes, exception, vcpu);
} }
static int kernel_pio(struct kvm_vcpu *vcpu, void *pd) static int kernel_pio(struct kvm_vcpu *vcpu, void *pd)
......
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