aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/x86.c
diff options
context:
space:
mode:
authorBen-Ami Yassour <benami@il.ibm.com>2008-09-13 20:48:28 -0400
committerAvi Kivity <avi@redhat.com>2008-10-15 08:25:04 -0400
commit62c476c7c7f25a5b245b9902a935636e6316e58c (patch)
tree6584591c7c345fcbb3c6d437203dc7f4a628573a /arch/x86/kvm/x86.c
parent387179464257921eb9aa3d15cc3ff194f6945a7c (diff)
KVM: Device Assignment with VT-d
Based on a patch by: Kay, Allen M <allen.m.kay@intel.com> This patch enables PCI device assignment based on VT-d support. When a device is assigned to the guest, the guest memory is pinned and the mapping is updated in the VT-d IOMMU. [Amit: Expose KVM_CAP_IOMMU so we can check if an IOMMU is present and also control enable/disable from userspace] Signed-off-by: Kay, Allen M <allen.m.kay@intel.com> Signed-off-by: Weidong Han <weidong.han@intel.com> Signed-off-by: Ben-Ami Yassour <benami@il.ibm.com> Signed-off-by: Amit Shah <amit.shah@qumranet.com> Acked-by: Mark Gross <mgross@linux.intel.com> Signed-off-by: Avi Kivity <avi@qumranet.com>
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);