aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm/mmu.c
diff options
context:
space:
mode:
authorAvi Kivity <avi@qumranet.com>2007-03-30 07:02:32 -0400
committerAvi Kivity <avi@qumranet.com>2007-05-03 03:52:28 -0400
commit954bbbc236afe23b368abdf4942f313a5f6e1d50 (patch)
tree4c990bff08f7a9a13980deb68a85e091065bb1ec /drivers/kvm/mmu.c
parente0fa826f969c262c23908953bf85add487cc2e6c (diff)
KVM: Simply gfn_to_page()
Mapping a guest page to a host page is a common operation. Currently, one has first to find the memory slot where the page belongs (gfn_to_memslot), then locate the page itself (gfn_to_page()). This is clumsy, and also won't work well with memory aliases. So simplify gfn_to_page() not to require memory slot translation first, and instead do it internally. Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm/mmu.c')
-rw-r--r--drivers/kvm/mmu.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index 376800a33968..8bdb9ca1811c 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -390,13 +390,11 @@ static void rmap_write_protect(struct kvm_vcpu *vcpu, u64 gfn)
390{ 390{
391 struct kvm *kvm = vcpu->kvm; 391 struct kvm *kvm = vcpu->kvm;
392 struct page *page; 392 struct page *page;
393 struct kvm_memory_slot *slot;
394 struct kvm_rmap_desc *desc; 393 struct kvm_rmap_desc *desc;
395 u64 *spte; 394 u64 *spte;
396 395
397 slot = gfn_to_memslot(kvm, gfn); 396 page = gfn_to_page(kvm, gfn);
398 BUG_ON(!slot); 397 BUG_ON(!page);
399 page = gfn_to_page(slot, gfn);
400 398
401 while (page_private(page)) { 399 while (page_private(page)) {
402 if (!(page_private(page) & 1)) 400 if (!(page_private(page) & 1))
@@ -711,14 +709,12 @@ hpa_t safe_gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa)
711 709
712hpa_t gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa) 710hpa_t gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa)
713{ 711{
714 struct kvm_memory_slot *slot;
715 struct page *page; 712 struct page *page;
716 713
717 ASSERT((gpa & HPA_ERR_MASK) == 0); 714 ASSERT((gpa & HPA_ERR_MASK) == 0);
718 slot = gfn_to_memslot(vcpu->kvm, gpa >> PAGE_SHIFT); 715 page = gfn_to_page(vcpu->kvm, gpa >> PAGE_SHIFT);
719 if (!slot) 716 if (!page)
720 return gpa | HPA_ERR_MASK; 717 return gpa | HPA_ERR_MASK;
721 page = gfn_to_page(slot, gpa >> PAGE_SHIFT);
722 return ((hpa_t)page_to_pfn(page) << PAGE_SHIFT) 718 return ((hpa_t)page_to_pfn(page) << PAGE_SHIFT)
723 | (gpa & (PAGE_SIZE-1)); 719 | (gpa & (PAGE_SIZE-1));
724} 720}