Skip to content

Commit

Permalink
KVM: use gfn_to_pfn_memslot in kvm_iommu_map_pages
Browse files Browse the repository at this point in the history
So its possible to iommu map a memslot before making it visible to
kvm.

Signed-off-by: Marcelo Tosatti <[email protected]>
  • Loading branch information
matosatti committed Mar 1, 2010
1 parent 506f0d6 commit 3ad26d8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
3 changes: 1 addition & 2 deletions include/linux/kvm_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,7 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id);
#define KVM_IOMMU_CACHE_COHERENCY 0x1

#ifdef CONFIG_IOMMU_API
int kvm_iommu_map_pages(struct kvm *kvm, gfn_t base_gfn,
unsigned long npages);
int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot);
int kvm_iommu_map_guest(struct kvm *kvm);
int kvm_iommu_unmap_guest(struct kvm *kvm);
int kvm_assign_device(struct kvm *kvm,
Expand Down
13 changes: 6 additions & 7 deletions virt/kvm/iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ static int kvm_iommu_unmap_memslots(struct kvm *kvm);
static void kvm_iommu_put_pages(struct kvm *kvm,
gfn_t base_gfn, unsigned long npages);

int kvm_iommu_map_pages(struct kvm *kvm,
gfn_t base_gfn, unsigned long npages)
int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot)
{
gfn_t gfn = base_gfn;
gfn_t gfn = slot->base_gfn;
unsigned long npages = slot->npages;
pfn_t pfn;
int i, r = 0;
struct iommu_domain *domain = kvm->arch.iommu_domain;
Expand All @@ -54,7 +54,7 @@ int kvm_iommu_map_pages(struct kvm *kvm,
if (iommu_iova_to_phys(domain, gfn_to_gpa(gfn)))
continue;

pfn = gfn_to_pfn(kvm, gfn);
pfn = gfn_to_pfn_memslot(kvm, slot, gfn);
r = iommu_map_range(domain,
gfn_to_gpa(gfn),
pfn_to_hpa(pfn),
Expand All @@ -69,7 +69,7 @@ int kvm_iommu_map_pages(struct kvm *kvm,
return 0;

unmap_pages:
kvm_iommu_put_pages(kvm, base_gfn, i);
kvm_iommu_put_pages(kvm, slot->base_gfn, i);
return r;
}

Expand All @@ -81,8 +81,7 @@ static int kvm_iommu_map_memslots(struct kvm *kvm)
slots = kvm->memslots;

for (i = 0; i < slots->nmemslots; i++) {
r = kvm_iommu_map_pages(kvm, slots->memslots[i].base_gfn,
slots->memslots[i].npages);
r = kvm_iommu_map_pages(kvm, &slots->memslots[i]);
if (r)
break;
}
Expand Down
2 changes: 1 addition & 1 deletion virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
spin_unlock(&kvm->mmu_lock);
#ifdef CONFIG_DMAR
/* map the pages in iommu page table */
r = kvm_iommu_map_pages(kvm, base_gfn, npages);
r = kvm_iommu_map_pages(kvm, memslot);
if (r)
goto out;
#endif
Expand Down

0 comments on commit 3ad26d8

Please sign in to comment.