Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 202250
b: refs/heads/master
c: 8fe681e
h: refs/heads/master
v: v3
  • Loading branch information
Gleb Natapov authored and Avi Kivity committed Aug 1, 2010
1 parent 90d4b2e commit 47b271d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f181b96d4c769b8915849eb9070c18116fd8d44e
refs/heads/master: 8fe681e984b6505d4d12125c0776399304803ec7
3 changes: 3 additions & 0 deletions trunk/arch/x86/include/asm/kvm_emulate.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ struct x86_emulate_ops {
int (*read_emulated)(unsigned long addr,
void *val,
unsigned int bytes,
unsigned int *error,
struct kvm_vcpu *vcpu);

/*
Expand All @@ -106,6 +107,7 @@ struct x86_emulate_ops {
int (*write_emulated)(unsigned long addr,
const void *val,
unsigned int bytes,
unsigned int *error,
struct kvm_vcpu *vcpu);

/*
Expand All @@ -120,6 +122,7 @@ struct x86_emulate_ops {
const void *old,
const void *new,
unsigned int bytes,
unsigned int *error,
struct kvm_vcpu *vcpu);

int (*pio_in_emulated)(int size, unsigned short port, void *val,
Expand Down
12 changes: 11 additions & 1 deletion trunk/arch/x86/kvm/emulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1277,14 +1277,18 @@ static int read_emulated(struct x86_emulate_ctxt *ctxt,
{
int rc;
struct read_cache *mc = &ctxt->decode.mem_read;
u32 err;

while (size) {
int n = min(size, 8u);
size -= n;
if (mc->pos < mc->end)
goto read_cached;

rc = ops->read_emulated(addr, mc->data + mc->end, n, ctxt->vcpu);
rc = ops->read_emulated(addr, mc->data + mc->end, n, &err,
ctxt->vcpu);
if (rc == X86EMUL_PROPAGATE_FAULT)
kvm_inject_page_fault(ctxt->vcpu, addr, err);
if (rc != X86EMUL_CONTINUE)
return rc;
mc->end += n;
Expand Down Expand Up @@ -1789,6 +1793,7 @@ static inline int writeback(struct x86_emulate_ctxt *ctxt,
{
int rc;
struct decode_cache *c = &ctxt->decode;
u32 err;

switch (c->dst.type) {
case OP_REG:
Expand Down Expand Up @@ -1817,13 +1822,18 @@ static inline int writeback(struct x86_emulate_ctxt *ctxt,
&c->dst.orig_val,
&c->dst.val,
c->dst.bytes,
&err,
ctxt->vcpu);
else
rc = ops->write_emulated(
(unsigned long)c->dst.ptr,
&c->dst.val,
c->dst.bytes,
&err,
ctxt->vcpu);
if (rc == X86EMUL_PROPAGATE_FAULT)
kvm_inject_page_fault(ctxt->vcpu,
(unsigned long)c->dst.ptr, err);
if (rc != X86EMUL_CONTINUE)
return rc;
break;
Expand Down
28 changes: 14 additions & 14 deletions trunk/arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -3346,10 +3346,10 @@ static int kvm_write_guest_virt_system(gva_t addr, void *val,
static int emulator_read_emulated(unsigned long addr,
void *val,
unsigned int bytes,
unsigned int *error_code,
struct kvm_vcpu *vcpu)
{
gpa_t gpa;
u32 error_code;

if (vcpu->mmio_read_completed) {
memcpy(val, vcpu->mmio_data, bytes);
Expand All @@ -3359,12 +3359,10 @@ static int emulator_read_emulated(unsigned long addr,
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) {
kvm_inject_page_fault(vcpu, addr, error_code);
if (gpa == UNMAPPED_GVA)
return X86EMUL_PROPAGATE_FAULT;
}

/* For APIC access vmexit */
if ((gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE)
Expand Down Expand Up @@ -3409,17 +3407,15 @@ int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
static int emulator_write_emulated_onepage(unsigned long addr,
const void *val,
unsigned int bytes,
unsigned int *error_code,
struct kvm_vcpu *vcpu)
{
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) {
kvm_inject_page_fault(vcpu, addr, error_code);
if (gpa == UNMAPPED_GVA)
return X86EMUL_PROPAGATE_FAULT;
}

/* For APIC access vmexit */
if ((gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE)
Expand Down Expand Up @@ -3449,21 +3445,24 @@ static int emulator_write_emulated_onepage(unsigned long addr,
int emulator_write_emulated(unsigned long addr,
const void *val,
unsigned int bytes,
unsigned int *error_code,
struct kvm_vcpu *vcpu)
{
/* Crossing a page boundary? */
if (((addr + bytes - 1) ^ addr) & PAGE_MASK) {
int rc, now;

now = -addr & ~PAGE_MASK;
rc = emulator_write_emulated_onepage(addr, val, now, vcpu);
rc = emulator_write_emulated_onepage(addr, val, now, error_code,
vcpu);
if (rc != X86EMUL_CONTINUE)
return rc;
addr += now;
val += now;
bytes -= now;
}
return emulator_write_emulated_onepage(addr, val, bytes, vcpu);
return emulator_write_emulated_onepage(addr, val, bytes, error_code,
vcpu);
}

#define CMPXCHG_TYPE(t, ptr, old, new) \
Expand All @@ -3480,6 +3479,7 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
const void *old,
const void *new,
unsigned int bytes,
unsigned int *error_code,
struct kvm_vcpu *vcpu)
{
gpa_t gpa;
Expand Down Expand Up @@ -3533,7 +3533,7 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
emul_write:
printk_once(KERN_WARNING "kvm: emulating exchange as write\n");

return emulator_write_emulated(addr, new, bytes, vcpu);
return emulator_write_emulated(addr, new, bytes, error_code, vcpu);
}

static int kernel_pio(struct kvm_vcpu *vcpu, void *pd)
Expand Down Expand Up @@ -4293,7 +4293,7 @@ int kvm_fix_hypercall(struct kvm_vcpu *vcpu)

kvm_x86_ops->patch_hypercall(vcpu, instruction);

return emulator_write_emulated(rip, instruction, 3, vcpu);
return emulator_write_emulated(rip, instruction, 3, NULL, vcpu);
}

void realmode_lgdt(struct kvm_vcpu *vcpu, u16 limit, unsigned long base)
Expand Down

0 comments on commit 47b271d

Please sign in to comment.