aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/x86.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r--arch/x86/kvm/x86.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 2134f3e0a516..c8a2793626ec 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -35,6 +35,7 @@
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/mman.h> 36#include <linux/mman.h>
37#include <linux/highmem.h> 37#include <linux/highmem.h>
38#include <linux/intel-iommu.h>
38 39
39#include <asm/uaccess.h> 40#include <asm/uaccess.h>
40#include <asm/msr.h> 41#include <asm/msr.h>
@@ -277,9 +278,18 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
277 278
278 list_add(&match->list, &kvm->arch.assigned_dev_head); 279 list_add(&match->list, &kvm->arch.assigned_dev_head);
279 280
281 if (assigned_dev->flags & KVM_DEV_ASSIGN_ENABLE_IOMMU) {
282 r = kvm_iommu_map_guest(kvm, match);
283 if (r)
284 goto out_list_del;
285 }
286
280out: 287out:
281 mutex_unlock(&kvm->lock); 288 mutex_unlock(&kvm->lock);
282 return r; 289 return r;
290out_list_del:
291 list_del(&match->list);
292 pci_release_regions(dev);
283out_disable: 293out_disable:
284 pci_disable_device(dev); 294 pci_disable_device(dev);
285out_put: 295out_put:
@@ -1147,6 +1157,9 @@ int kvm_dev_ioctl_check_extension(long ext)
1147 case KVM_CAP_PV_MMU: 1157 case KVM_CAP_PV_MMU:
1148 r = !tdp_enabled; 1158 r = !tdp_enabled;
1149 break; 1159 break;
1160 case KVM_CAP_IOMMU:
1161 r = intel_iommu_found();
1162 break;
1150 default: 1163 default:
1151 r = 0; 1164 r = 0;
1152 break; 1165 break;
@@ -4282,6 +4295,7 @@ static void kvm_free_vcpus(struct kvm *kvm)
4282 4295
4283void kvm_arch_destroy_vm(struct kvm *kvm) 4296void kvm_arch_destroy_vm(struct kvm *kvm)
4284{ 4297{
4298 kvm_iommu_unmap_guest(kvm);
4285 kvm_free_assigned_devices(kvm); 4299 kvm_free_assigned_devices(kvm);
4286 kvm_free_pit(kvm); 4300 kvm_free_pit(kvm);
4287 kfree(kvm->arch.vpic); 4301 kfree(kvm->arch.vpic);