aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm/mmu.c
diff options
context:
space:
mode:
authorAvi Kivity <avi@qumranet.com>2007-10-28 12:48:59 -0400
committerAvi Kivity <avi@qumranet.com>2008-01-30 10:52:57 -0500
commit3067714cf59bd4a6dbf788b709485bc62c1ff845 (patch)
tree4cdfba475258886666150e638568e6ad5e8c0e2f /drivers/kvm/mmu.c
parentc7e75a3db4ecd952e7a5562cea1b27007bf0c01c (diff)
KVM: Move page fault processing to common code
The code that dispatches the page fault and emulates if we failed to map is duplicated across vmx and svm. Merge it to simplify further bugfixing. Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm/mmu.c')
-rw-r--r--drivers/kvm/mmu.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index d9c5950cfae1..ace3cb86214b 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -1347,6 +1347,42 @@ void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)
1347 } 1347 }
1348} 1348}
1349 1349
1350int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u32 error_code)
1351{
1352 int r;
1353 enum emulation_result er;
1354
1355 mutex_lock(&vcpu->kvm->lock);
1356 r = vcpu->mmu.page_fault(vcpu, cr2, error_code);
1357 if (r < 0)
1358 goto out;
1359
1360 if (!r) {
1361 r = 1;
1362 goto out;
1363 }
1364
1365 er = emulate_instruction(vcpu, vcpu->run, cr2, error_code, 0);
1366 mutex_unlock(&vcpu->kvm->lock);
1367
1368 switch (er) {
1369 case EMULATE_DONE:
1370 return 1;
1371 case EMULATE_DO_MMIO:
1372 ++vcpu->stat.mmio_exits;
1373 return 0;
1374 case EMULATE_FAIL:
1375 kvm_report_emulation_failure(vcpu, "pagetable");
1376 return 1;
1377 default:
1378 BUG();
1379 }
1380out:
1381 mutex_unlock(&vcpu->kvm->lock);
1382 return r;
1383}
1384EXPORT_SYMBOL_GPL(kvm_mmu_page_fault);
1385
1350static void free_mmu_pages(struct kvm_vcpu *vcpu) 1386static void free_mmu_pages(struct kvm_vcpu *vcpu)
1351{ 1387{
1352 struct kvm_mmu_page *page; 1388 struct kvm_mmu_page *page;