Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 202402
b: refs/heads/master
c: a6f177e
h: refs/heads/master
v: v3
  • Loading branch information
Gleb Natapov authored and Avi Kivity committed Aug 2, 2010
1 parent 2a205ad commit 2ce9f78
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 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: edba23e51578f7cb6781461568489fc1825db4ac
refs/heads/master: a6f177efaa5856e22ed0d3c1e81e65b41654d083
32 changes: 25 additions & 7 deletions trunk/arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -3930,6 +3930,29 @@ static int handle_emulation_failure(struct kvm_vcpu *vcpu)
return EMULATE_FAIL;
}

static bool reexecute_instruction(struct kvm_vcpu *vcpu, gva_t gva)
{
gpa_t gpa;

/*
* if emulation was due to access to shadowed page table
* and it failed try to unshadow page and re-entetr the
* guest to let CPU execute the instruction.
*/
if (kvm_mmu_unprotect_page_virt(vcpu, gva))
return true;

gpa = kvm_mmu_gva_to_gpa_system(vcpu, gva, NULL);

if (gpa == UNMAPPED_GVA)
return true; /* let cpu generate fault */

if (!kvm_is_error_hva(gfn_to_hva(vcpu->kvm, gpa >> PAGE_SHIFT)))
return true;

return false;
}

int emulate_instruction(struct kvm_vcpu *vcpu,
unsigned long cr2,
u16 error_code,
Expand Down Expand Up @@ -3998,7 +4021,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu,

++vcpu->stat.insn_emulation;
if (r) {
if (kvm_mmu_unprotect_page_virt(vcpu, cr2))
if (reexecute_instruction(vcpu, cr2))
return EMULATE_DONE;
if (emulation_type & EMULTYPE_SKIP)
return EMULATE_FAIL;
Expand All @@ -4019,12 +4042,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
r = x86_emulate_insn(&vcpu->arch.emulate_ctxt, &emulate_ops);

if (r) { /* emulation failed */
/*
* if emulation was due to access to shadowed page table
* and it failed try to unshadow page and re-entetr the
* guest to let CPU execute the instruction.
*/
if (kvm_mmu_unprotect_page_virt(vcpu, cr2))
if (reexecute_instruction(vcpu, cr2))
return EMULATE_DONE;

return handle_emulation_failure(vcpu);
Expand Down

0 comments on commit 2ce9f78

Please sign in to comment.