diff options
Diffstat (limited to 'virt/kvm/iommu.c')
-rw-r--r-- | virt/kvm/iommu.c | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c index 15147583abd1..80fd3ad3b2de 100644 --- a/virt/kvm/iommu.c +++ b/virt/kvm/iommu.c | |||
@@ -32,10 +32,10 @@ static int kvm_iommu_unmap_memslots(struct kvm *kvm); | |||
32 | static void kvm_iommu_put_pages(struct kvm *kvm, | 32 | static void kvm_iommu_put_pages(struct kvm *kvm, |
33 | gfn_t base_gfn, unsigned long npages); | 33 | gfn_t base_gfn, unsigned long npages); |
34 | 34 | ||
35 | int kvm_iommu_map_pages(struct kvm *kvm, | 35 | int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot) |
36 | gfn_t base_gfn, unsigned long npages) | ||
37 | { | 36 | { |
38 | gfn_t gfn = base_gfn; | 37 | gfn_t gfn = slot->base_gfn; |
38 | unsigned long npages = slot->npages; | ||
39 | pfn_t pfn; | 39 | pfn_t pfn; |
40 | int i, r = 0; | 40 | int i, r = 0; |
41 | struct iommu_domain *domain = kvm->arch.iommu_domain; | 41 | struct iommu_domain *domain = kvm->arch.iommu_domain; |
@@ -54,7 +54,7 @@ int kvm_iommu_map_pages(struct kvm *kvm, | |||
54 | if (iommu_iova_to_phys(domain, gfn_to_gpa(gfn))) | 54 | if (iommu_iova_to_phys(domain, gfn_to_gpa(gfn))) |
55 | continue; | 55 | continue; |
56 | 56 | ||
57 | pfn = gfn_to_pfn(kvm, gfn); | 57 | pfn = gfn_to_pfn_memslot(kvm, slot, gfn); |
58 | r = iommu_map_range(domain, | 58 | r = iommu_map_range(domain, |
59 | gfn_to_gpa(gfn), | 59 | gfn_to_gpa(gfn), |
60 | pfn_to_hpa(pfn), | 60 | pfn_to_hpa(pfn), |
@@ -69,17 +69,19 @@ int kvm_iommu_map_pages(struct kvm *kvm, | |||
69 | return 0; | 69 | return 0; |
70 | 70 | ||
71 | unmap_pages: | 71 | unmap_pages: |
72 | kvm_iommu_put_pages(kvm, base_gfn, i); | 72 | kvm_iommu_put_pages(kvm, slot->base_gfn, i); |
73 | return r; | 73 | return r; |
74 | } | 74 | } |
75 | 75 | ||
76 | static int kvm_iommu_map_memslots(struct kvm *kvm) | 76 | static int kvm_iommu_map_memslots(struct kvm *kvm) |
77 | { | 77 | { |
78 | int i, r = 0; | 78 | int i, r = 0; |
79 | struct kvm_memslots *slots; | ||
80 | |||
81 | slots = rcu_dereference(kvm->memslots); | ||
79 | 82 | ||
80 | for (i = 0; i < kvm->nmemslots; i++) { | 83 | for (i = 0; i < slots->nmemslots; i++) { |
81 | r = kvm_iommu_map_pages(kvm, kvm->memslots[i].base_gfn, | 84 | r = kvm_iommu_map_pages(kvm, &slots->memslots[i]); |
82 | kvm->memslots[i].npages); | ||
83 | if (r) | 85 | if (r) |
84 | break; | 86 | break; |
85 | } | 87 | } |
@@ -104,7 +106,8 @@ int kvm_assign_device(struct kvm *kvm, | |||
104 | 106 | ||
105 | r = iommu_attach_device(domain, &pdev->dev); | 107 | r = iommu_attach_device(domain, &pdev->dev); |
106 | if (r) { | 108 | if (r) { |
107 | printk(KERN_ERR "assign device %x:%x.%x failed", | 109 | printk(KERN_ERR "assign device %x:%x:%x.%x failed", |
110 | pci_domain_nr(pdev->bus), | ||
108 | pdev->bus->number, | 111 | pdev->bus->number, |
109 | PCI_SLOT(pdev->devfn), | 112 | PCI_SLOT(pdev->devfn), |
110 | PCI_FUNC(pdev->devfn)); | 113 | PCI_FUNC(pdev->devfn)); |
@@ -125,7 +128,8 @@ int kvm_assign_device(struct kvm *kvm, | |||
125 | goto out_unmap; | 128 | goto out_unmap; |
126 | } | 129 | } |
127 | 130 | ||
128 | printk(KERN_DEBUG "assign device: host bdf = %x:%x:%x\n", | 131 | printk(KERN_DEBUG "assign device %x:%x:%x.%x\n", |
132 | assigned_dev->host_segnr, | ||
129 | assigned_dev->host_busnr, | 133 | assigned_dev->host_busnr, |
130 | PCI_SLOT(assigned_dev->host_devfn), | 134 | PCI_SLOT(assigned_dev->host_devfn), |
131 | PCI_FUNC(assigned_dev->host_devfn)); | 135 | PCI_FUNC(assigned_dev->host_devfn)); |
@@ -152,7 +156,8 @@ int kvm_deassign_device(struct kvm *kvm, | |||
152 | 156 | ||
153 | iommu_detach_device(domain, &pdev->dev); | 157 | iommu_detach_device(domain, &pdev->dev); |
154 | 158 | ||
155 | printk(KERN_DEBUG "deassign device: host bdf = %x:%x:%x\n", | 159 | printk(KERN_DEBUG "deassign device %x:%x:%x.%x\n", |
160 | assigned_dev->host_segnr, | ||
156 | assigned_dev->host_busnr, | 161 | assigned_dev->host_busnr, |
157 | PCI_SLOT(assigned_dev->host_devfn), | 162 | PCI_SLOT(assigned_dev->host_devfn), |
158 | PCI_FUNC(assigned_dev->host_devfn)); | 163 | PCI_FUNC(assigned_dev->host_devfn)); |
@@ -210,10 +215,13 @@ static void kvm_iommu_put_pages(struct kvm *kvm, | |||
210 | static int kvm_iommu_unmap_memslots(struct kvm *kvm) | 215 | static int kvm_iommu_unmap_memslots(struct kvm *kvm) |
211 | { | 216 | { |
212 | int i; | 217 | int i; |
218 | struct kvm_memslots *slots; | ||
219 | |||
220 | slots = rcu_dereference(kvm->memslots); | ||
213 | 221 | ||
214 | for (i = 0; i < kvm->nmemslots; i++) { | 222 | for (i = 0; i < slots->nmemslots; i++) { |
215 | kvm_iommu_put_pages(kvm, kvm->memslots[i].base_gfn, | 223 | kvm_iommu_put_pages(kvm, slots->memslots[i].base_gfn, |
216 | kvm->memslots[i].npages); | 224 | slots->memslots[i].npages); |
217 | } | 225 | } |
218 | 226 | ||
219 | return 0; | 227 | return 0; |