Commit 19de40a8 authored by Joerg Roedel's avatar Joerg Roedel

KVM: change KVM to use IOMMU API

Signed-off-by: default avatarJoerg Roedel <joerg.roedel@amd.com>
parent 1aaf1183
...@@ -467,7 +467,7 @@ struct kvm_arch { ...@@ -467,7 +467,7 @@ struct kvm_arch {
struct kvm_sal_data rdv_sal_data; struct kvm_sal_data rdv_sal_data;
struct list_head assigned_dev_head; struct list_head assigned_dev_head;
struct dmar_domain *intel_iommu_domain; struct iommu_domain *iommu_domain;
struct hlist_head irq_ack_notifier_list; struct hlist_head irq_ack_notifier_list;
unsigned long irq_sources_bitmap; unsigned long irq_sources_bitmap;
......
...@@ -51,7 +51,7 @@ EXTRA_AFLAGS += -Ivirt/kvm -Iarch/ia64/kvm/ ...@@ -51,7 +51,7 @@ EXTRA_AFLAGS += -Ivirt/kvm -Iarch/ia64/kvm/
common-objs = $(addprefix ../../../virt/kvm/, kvm_main.o ioapic.o \ common-objs = $(addprefix ../../../virt/kvm/, kvm_main.o ioapic.o \
coalesced_mmio.o irq_comm.o) coalesced_mmio.o irq_comm.o)
ifeq ($(CONFIG_DMAR),y) ifeq ($(CONFIG_IOMMU_API),y)
common-objs += $(addprefix ../../../virt/kvm/, iommu.o) common-objs += $(addprefix ../../../virt/kvm/, iommu.o)
endif endif
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/hrtimer.h> #include <linux/hrtimer.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/iommu.h>
#include <linux/intel-iommu.h> #include <linux/intel-iommu.h>
#include <asm/pgtable.h> #include <asm/pgtable.h>
...@@ -188,7 +189,7 @@ int kvm_dev_ioctl_check_extension(long ext) ...@@ -188,7 +189,7 @@ int kvm_dev_ioctl_check_extension(long ext)
r = KVM_COALESCED_MMIO_PAGE_OFFSET; r = KVM_COALESCED_MMIO_PAGE_OFFSET;
break; break;
case KVM_CAP_IOMMU: case KVM_CAP_IOMMU:
r = intel_iommu_found(); r = iommu_found();
break; break;
default: default:
r = 0; r = 0;
......
...@@ -360,7 +360,7 @@ struct kvm_arch{ ...@@ -360,7 +360,7 @@ struct kvm_arch{
struct list_head active_mmu_pages; struct list_head active_mmu_pages;
struct list_head assigned_dev_head; struct list_head assigned_dev_head;
struct list_head oos_global_pages; struct list_head oos_global_pages;
struct dmar_domain *intel_iommu_domain; struct iommu_domain *iommu_domain;
struct kvm_pic *vpic; struct kvm_pic *vpic;
struct kvm_ioapic *vioapic; struct kvm_ioapic *vioapic;
struct kvm_pit *vpit; struct kvm_pit *vpit;
......
...@@ -7,7 +7,7 @@ common-objs = $(addprefix ../../../virt/kvm/, kvm_main.o ioapic.o \ ...@@ -7,7 +7,7 @@ common-objs = $(addprefix ../../../virt/kvm/, kvm_main.o ioapic.o \
ifeq ($(CONFIG_KVM_TRACE),y) ifeq ($(CONFIG_KVM_TRACE),y)
common-objs += $(addprefix ../../../virt/kvm/, kvm_trace.o) common-objs += $(addprefix ../../../virt/kvm/, kvm_trace.o)
endif endif
ifeq ($(CONFIG_DMAR),y) ifeq ($(CONFIG_IOMMU_API),y)
common-objs += $(addprefix ../../../virt/kvm/, iommu.o) common-objs += $(addprefix ../../../virt/kvm/, iommu.o)
endif endif
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/mman.h> #include <linux/mman.h>
#include <linux/highmem.h> #include <linux/highmem.h>
#include <linux/iommu.h>
#include <linux/intel-iommu.h> #include <linux/intel-iommu.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
...@@ -989,7 +990,7 @@ int kvm_dev_ioctl_check_extension(long ext) ...@@ -989,7 +990,7 @@ int kvm_dev_ioctl_check_extension(long ext)
r = !tdp_enabled; r = !tdp_enabled;
break; break;
case KVM_CAP_IOMMU: case KVM_CAP_IOMMU:
r = intel_iommu_found(); r = iommu_found();
break; break;
default: default:
r = 0; r = 0;
......
...@@ -328,7 +328,7 @@ void kvm_unregister_irq_ack_notifier(struct kvm_irq_ack_notifier *kian); ...@@ -328,7 +328,7 @@ void kvm_unregister_irq_ack_notifier(struct kvm_irq_ack_notifier *kian);
int kvm_request_irq_source_id(struct kvm *kvm); int kvm_request_irq_source_id(struct kvm *kvm);
void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id); void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id);
#ifdef CONFIG_DMAR #ifdef CONFIG_IOMMU_API
int kvm_iommu_map_pages(struct kvm *kvm, gfn_t base_gfn, int kvm_iommu_map_pages(struct kvm *kvm, gfn_t base_gfn,
unsigned long npages); unsigned long npages);
int kvm_iommu_map_guest(struct kvm *kvm); int kvm_iommu_map_guest(struct kvm *kvm);
...@@ -337,7 +337,7 @@ int kvm_assign_device(struct kvm *kvm, ...@@ -337,7 +337,7 @@ int kvm_assign_device(struct kvm *kvm,
struct kvm_assigned_dev_kernel *assigned_dev); struct kvm_assigned_dev_kernel *assigned_dev);
int kvm_deassign_device(struct kvm *kvm, int kvm_deassign_device(struct kvm *kvm,
struct kvm_assigned_dev_kernel *assigned_dev); struct kvm_assigned_dev_kernel *assigned_dev);
#else /* CONFIG_DMAR */ #else /* CONFIG_IOMMU_API */
static inline int kvm_iommu_map_pages(struct kvm *kvm, static inline int kvm_iommu_map_pages(struct kvm *kvm,
gfn_t base_gfn, gfn_t base_gfn,
unsigned long npages) unsigned long npages)
...@@ -366,7 +366,7 @@ static inline int kvm_deassign_device(struct kvm *kvm, ...@@ -366,7 +366,7 @@ static inline int kvm_deassign_device(struct kvm *kvm,
{ {
return 0; return 0;
} }
#endif /* CONFIG_DMAR */ #endif /* CONFIG_IOMMU_API */
static inline void kvm_guest_enter(void) static inline void kvm_guest_enter(void)
{ {
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <linux/kvm_host.h> #include <linux/kvm_host.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/dmar.h> #include <linux/dmar.h>
#include <linux/iommu.h>
#include <linux/intel-iommu.h> #include <linux/intel-iommu.h>
static int kvm_iommu_unmap_memslots(struct kvm *kvm); static int kvm_iommu_unmap_memslots(struct kvm *kvm);
...@@ -37,7 +38,7 @@ int kvm_iommu_map_pages(struct kvm *kvm, ...@@ -37,7 +38,7 @@ int kvm_iommu_map_pages(struct kvm *kvm,
gfn_t gfn = base_gfn; gfn_t gfn = base_gfn;
pfn_t pfn; pfn_t pfn;
int i, r = 0; int i, r = 0;
struct dmar_domain *domain = kvm->arch.intel_iommu_domain; struct iommu_domain *domain = kvm->arch.iommu_domain;
/* check if iommu exists and in use */ /* check if iommu exists and in use */
if (!domain) if (!domain)
...@@ -45,16 +46,15 @@ int kvm_iommu_map_pages(struct kvm *kvm, ...@@ -45,16 +46,15 @@ int kvm_iommu_map_pages(struct kvm *kvm,
for (i = 0; i < npages; i++) { for (i = 0; i < npages; i++) {
/* check if already mapped */ /* check if already mapped */
if (intel_iommu_iova_to_phys(domain, if (iommu_iova_to_phys(domain, gfn_to_gpa(gfn)))
gfn_to_gpa(gfn)))
continue; continue;
pfn = gfn_to_pfn(kvm, gfn); pfn = gfn_to_pfn(kvm, gfn);
r = intel_iommu_map_address(domain, r = iommu_map_range(domain,
gfn_to_gpa(gfn), gfn_to_gpa(gfn),
pfn_to_hpa(pfn), pfn_to_hpa(pfn),
PAGE_SIZE, PAGE_SIZE,
DMA_PTE_READ | DMA_PTE_WRITE); IOMMU_READ | IOMMU_WRITE);
if (r) { if (r) {
printk(KERN_ERR "kvm_iommu_map_address:" printk(KERN_ERR "kvm_iommu_map_address:"
"iommu failed to map pfn=%lx\n", pfn); "iommu failed to map pfn=%lx\n", pfn);
...@@ -88,7 +88,7 @@ int kvm_assign_device(struct kvm *kvm, ...@@ -88,7 +88,7 @@ int kvm_assign_device(struct kvm *kvm,
struct kvm_assigned_dev_kernel *assigned_dev) struct kvm_assigned_dev_kernel *assigned_dev)
{ {
struct pci_dev *pdev = NULL; struct pci_dev *pdev = NULL;
struct dmar_domain *domain = kvm->arch.intel_iommu_domain; struct iommu_domain *domain = kvm->arch.iommu_domain;
int r; int r;
/* check if iommu exists and in use */ /* check if iommu exists and in use */
...@@ -99,7 +99,7 @@ int kvm_assign_device(struct kvm *kvm, ...@@ -99,7 +99,7 @@ int kvm_assign_device(struct kvm *kvm,
if (pdev == NULL) if (pdev == NULL)
return -ENODEV; return -ENODEV;
r = intel_iommu_attach_device(domain, pdev); r = iommu_attach_device(domain, &pdev->dev);
if (r) { if (r) {
printk(KERN_ERR "assign device %x:%x.%x failed", printk(KERN_ERR "assign device %x:%x.%x failed",
pdev->bus->number, pdev->bus->number,
...@@ -119,7 +119,7 @@ int kvm_assign_device(struct kvm *kvm, ...@@ -119,7 +119,7 @@ int kvm_assign_device(struct kvm *kvm,
int kvm_deassign_device(struct kvm *kvm, int kvm_deassign_device(struct kvm *kvm,
struct kvm_assigned_dev_kernel *assigned_dev) struct kvm_assigned_dev_kernel *assigned_dev)
{ {
struct dmar_domain *domain = kvm->arch.intel_iommu_domain; struct iommu_domain *domain = kvm->arch.iommu_domain;
struct pci_dev *pdev = NULL; struct pci_dev *pdev = NULL;
/* check if iommu exists and in use */ /* check if iommu exists and in use */
...@@ -130,7 +130,7 @@ int kvm_deassign_device(struct kvm *kvm, ...@@ -130,7 +130,7 @@ int kvm_deassign_device(struct kvm *kvm,
if (pdev == NULL) if (pdev == NULL)
return -ENODEV; return -ENODEV;
intel_iommu_detach_device(domain, pdev); iommu_detach_device(domain, &pdev->dev);
printk(KERN_DEBUG "deassign device: host bdf = %x:%x:%x\n", printk(KERN_DEBUG "deassign device: host bdf = %x:%x:%x\n",
assigned_dev->host_busnr, assigned_dev->host_busnr,
...@@ -144,13 +144,13 @@ int kvm_iommu_map_guest(struct kvm *kvm) ...@@ -144,13 +144,13 @@ int kvm_iommu_map_guest(struct kvm *kvm)
{ {
int r; int r;
if (!intel_iommu_found()) { if (!iommu_found()) {
printk(KERN_ERR "%s: intel iommu not found\n", __func__); printk(KERN_ERR "%s: iommu not found\n", __func__);
return -ENODEV; return -ENODEV;
} }
kvm->arch.intel_iommu_domain = intel_iommu_alloc_domain(); kvm->arch.iommu_domain = iommu_domain_alloc();
if (!kvm->arch.intel_iommu_domain) if (!kvm->arch.iommu_domain)
return -ENOMEM; return -ENOMEM;
r = kvm_iommu_map_memslots(kvm); r = kvm_iommu_map_memslots(kvm);
...@@ -169,7 +169,7 @@ static void kvm_iommu_put_pages(struct kvm *kvm, ...@@ -169,7 +169,7 @@ static void kvm_iommu_put_pages(struct kvm *kvm,
{ {
gfn_t gfn = base_gfn; gfn_t gfn = base_gfn;
pfn_t pfn; pfn_t pfn;
struct dmar_domain *domain = kvm->arch.intel_iommu_domain; struct iommu_domain *domain = kvm->arch.iommu_domain;
unsigned long i; unsigned long i;
u64 phys; u64 phys;
...@@ -178,16 +178,13 @@ static void kvm_iommu_put_pages(struct kvm *kvm, ...@@ -178,16 +178,13 @@ static void kvm_iommu_put_pages(struct kvm *kvm,
return; return;
for (i = 0; i < npages; i++) { for (i = 0; i < npages; i++) {
phys = intel_iommu_iova_to_phys(domain, phys = iommu_iova_to_phys(domain, gfn_to_gpa(gfn));
gfn_to_gpa(gfn));
pfn = phys >> PAGE_SHIFT; pfn = phys >> PAGE_SHIFT;
kvm_release_pfn_clean(pfn); kvm_release_pfn_clean(pfn);
gfn++; gfn++;
} }
intel_iommu_unmap_address(domain, iommu_unmap_range(domain, gfn_to_gpa(base_gfn), PAGE_SIZE * npages);
gfn_to_gpa(base_gfn),
PAGE_SIZE * npages);
} }
static int kvm_iommu_unmap_memslots(struct kvm *kvm) static int kvm_iommu_unmap_memslots(struct kvm *kvm)
...@@ -205,13 +202,13 @@ static int kvm_iommu_unmap_memslots(struct kvm *kvm) ...@@ -205,13 +202,13 @@ static int kvm_iommu_unmap_memslots(struct kvm *kvm)
int kvm_iommu_unmap_guest(struct kvm *kvm) int kvm_iommu_unmap_guest(struct kvm *kvm)
{ {
struct dmar_domain *domain = kvm->arch.intel_iommu_domain; struct iommu_domain *domain = kvm->arch.iommu_domain;
/* check if iommu exists and in use */ /* check if iommu exists and in use */
if (!domain) if (!domain)
return 0; return 0;
kvm_iommu_unmap_memslots(kvm); kvm_iommu_unmap_memslots(kvm);
intel_iommu_free_domain(domain); iommu_domain_free(domain);
return 0; return 0;
} }
...@@ -504,7 +504,7 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm, ...@@ -504,7 +504,7 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
list_add(&match->list, &kvm->arch.assigned_dev_head); list_add(&match->list, &kvm->arch.assigned_dev_head);
if (assigned_dev->flags & KVM_DEV_ASSIGN_ENABLE_IOMMU) { if (assigned_dev->flags & KVM_DEV_ASSIGN_ENABLE_IOMMU) {
if (!kvm->arch.intel_iommu_domain) { if (!kvm->arch.iommu_domain) {
r = kvm_iommu_map_guest(kvm); r = kvm_iommu_map_guest(kvm);
if (r) if (r)
goto out_list_del; goto out_list_del;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment