diff options
author | Avi Kivity <avi@qumranet.com> | 2007-02-12 03:54:36 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-02-12 12:48:40 -0500 |
commit | e119d117a1d16e71876144188c0e0b3ecb8aeede (patch) | |
tree | 54c1ba0f055ea4c7aa306fb9f4563b1ad96f019d /drivers/kvm/paging_tmpl.h | |
parent | a0610ddf6be6465049a5da448d7e6c5e821240e6 (diff) |
[PATCH] kvm: Fix gva_to_gpa()
gva_to_gpa() needs to be updated to the new walk_addr() calling convention,
otherwise it may oops under some circumstances.
Use the opportunity to remove all the code duplication in gva_to_gpa(), which
essentially repeats the calculations in walk_addr().
Signed-off-by: Avi Kivity <avi@qumranet.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/kvm/paging_tmpl.h')
-rw-r--r-- | drivers/kvm/paging_tmpl.h | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h index 149fa45fd9a5..b6b90e9e1301 100644 --- a/drivers/kvm/paging_tmpl.h +++ b/drivers/kvm/paging_tmpl.h | |||
@@ -443,31 +443,17 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr, | |||
443 | static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr) | 443 | static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr) |
444 | { | 444 | { |
445 | struct guest_walker walker; | 445 | struct guest_walker walker; |
446 | pt_element_t guest_pte; | 446 | gpa_t gpa = UNMAPPED_GVA; |
447 | gpa_t gpa; | 447 | int r; |
448 | |||
449 | FNAME(walk_addr)(&walker, vcpu, vaddr, 0, 0, 0); | ||
450 | guest_pte = *walker.ptep; | ||
451 | FNAME(release_walker)(&walker); | ||
452 | |||
453 | if (!is_present_pte(guest_pte)) | ||
454 | return UNMAPPED_GVA; | ||
455 | |||
456 | if (walker.level == PT_DIRECTORY_LEVEL) { | ||
457 | ASSERT((guest_pte & PT_PAGE_SIZE_MASK)); | ||
458 | ASSERT(PTTYPE == 64 || is_pse(vcpu)); | ||
459 | 448 | ||
460 | gpa = (guest_pte & PT_DIR_BASE_ADDR_MASK) | (vaddr & | 449 | r = FNAME(walk_addr)(&walker, vcpu, vaddr, 0, 0, 0); |
461 | (PT_LEVEL_MASK(PT_PAGE_TABLE_LEVEL) | ~PAGE_MASK)); | ||
462 | 450 | ||
463 | if (PTTYPE == 32 && is_cpuid_PSE36()) | 451 | if (r) { |
464 | gpa |= (guest_pte & PT32_DIR_PSE36_MASK) << | 452 | gpa = (gpa_t)walker.gfn << PAGE_SHIFT; |
465 | (32 - PT32_DIR_PSE36_SHIFT); | 453 | gpa |= vaddr & ~PAGE_MASK; |
466 | } else { | ||
467 | gpa = (guest_pte & PT_BASE_ADDR_MASK); | ||
468 | gpa |= (vaddr & ~PAGE_MASK); | ||
469 | } | 454 | } |
470 | 455 | ||
456 | FNAME(release_walker)(&walker); | ||
471 | return gpa; | 457 | return gpa; |
472 | } | 458 | } |
473 | 459 | ||