From: Amit Shah Subject: Re: [PATCH 2/2] KVM: Device assignemnt with VT-d Date: Tue, 26 Aug 2008 13:02:23 +0530 Message-ID: <200808261302.24043.amit.shah@qumranet.com> References: <1218118487-7657-1-git-send-email-benami@il.ibm.com> <200808221314.02434.amit.shah@qumranet.com> <48AF0302.8060805@qumranet.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Cc: Ben-Ami Yassour , kvm@vger.kernel.org, Muli Ben-Yehuda , weidong.han@intel.com, "Kay, Allen M" To: Avi Kivity Return-path: Received: from mis011-2.exch011.intermedia.net ([64.78.17.183]:54775 "EHLO mis011-2.exch011.intermedia.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751686AbYHZHdX (ORCPT ); Tue, 26 Aug 2008 03:33:23 -0400 In-Reply-To: <48AF0302.8060805@qumranet.com> Content-Disposition: inline Sender: kvm-owner@vger.kernel.org List-ID: * On Friday 22 Aug 2008 23:48:42 Avi Kivity wrote: > Amit Shah wrote: > > diff --git a/include/linux/kvm.h b/include/linux/kvm.h > > index d9ef7d3..2956e35 100644 > > --- a/include/linux/kvm.h > > +++ b/include/linux/kvm.h > > @@ -495,4 +495,6 @@ struct kvm_assigned_irq { > > __u32 flags; > > }; > > > > +#define KVM_DEV_ASSIGN_USE_VTD (1 << 1) > > + > > #endif > > (1 >> 0)? > > This is a userspace inteface, so use a generic name like iommu. We also > need a KVM_CAP so userspace can check whether an iommu is present or not. How about this? diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 29f94ba..38ab48b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -277,10 +277,11 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm, list_add(&match->list, &kvm->arch.assigned_dev_head); - /* currenlty iommu is required for handling dma */ - r = kvm_iommu_map_guest(kvm, match); - if (r) - goto out_list_del; + if (assigned_dev->flags & KVM_DEV_ASSIGN_ENABLE_IOMMU) { + r = kvm_iommu_map_guest(kvm, match); + if (r) + goto out_list_del; + } out: mutex_unlock(&kvm->lock); @@ -1154,6 +1155,9 @@ int kvm_dev_ioctl_check_extension(long ext) case KVM_CAP_PV_MMU: r = !tdp_enabled; break; + case KVM_CAP_IOMMU: + r = intel_iommu_found(); + break; default: r = 0; break; diff --git a/include/linux/kvm.h b/include/linux/kvm.h index d9ef7d3..f2eafe1 100644 --- a/include/linux/kvm.h +++ b/include/linux/kvm.h @@ -384,6 +384,7 @@ struct kvm_trace_rec { #define KVM_CAP_COALESCED_MMIO 15 #define KVM_CAP_SYNC_MMU 16 /* Changes to host mmap are reflected in guest */ #define KVM_CAP_DEVICE_ASSIGNMENT 17 +#define KVM_CAP_IOMMU 18 /* * ioctls for VM fds @@ -495,4 +496,6 @@ struct kvm_assigned_irq { __u32 flags; }; +#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) + #endif