From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c6qVe-0001JC-Hx for qemu-devel@nongnu.org; Tue, 15 Nov 2016 22:03:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c6qVb-0003EH-EB for qemu-devel@nongnu.org; Tue, 15 Nov 2016 22:03:38 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:46955 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c6qVb-0003ED-9J for qemu-devel@nongnu.org; Tue, 15 Nov 2016 22:03:35 -0500 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uAG2xVpx061692 for ; Tue, 15 Nov 2016 22:03:34 -0500 Received: from e37.co.us.ibm.com (e37.co.us.ibm.com [32.97.110.158]) by mx0a-001b2d01.pphosted.com with ESMTP id 26req50wkq-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 15 Nov 2016 22:03:34 -0500 Received: from localhost by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 15 Nov 2016 20:03:33 -0700 Date: Wed, 16 Nov 2016 11:03:28 +0800 From: Dong Jia Shi References: <1479223805-22895-1-git-send-email-kwankhede@nvidia.com> <1479223805-22895-6-git-send-email-kwankhede@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1479223805-22895-6-git-send-email-kwankhede@nvidia.com> Message-Id: <20161116030328.GB5531@bjsdjshi@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [PATCH v13 05/22] vfio iommu: Added pin and unpin callback functions to vfio_iommu_driver_ops List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kirti Wankhede Cc: alex.williamson@redhat.com, pbonzini@redhat.com, kraxel@redhat.com, cjia@nvidia.com, qemu-devel@nongnu.org, kvm@vger.kernel.org, kevin.tian@intel.com, jike.song@intel.com, bjsdjshi@linux.vnet.ibm.com, linux-kernel@vger.kernel.org * Kirti Wankhede [2016-11-15 20:59:48 +0530]: Hi Kirti, > Added APIs for pining and unpining set of pages. These call back into > backend iommu module to actually pin and unpin pages. > Added two new callback functions to struct vfio_iommu_driver_ops. Backend > IOMMU module that supports pining and unpinning pages for mdev devices > should provide these functions. > > Renamed static functions in vfio_type1_iommu.c to resolve conflicts > > Signed-off-by: Kirti Wankhede > Signed-off-by: Neo Jia > Change-Id: Ia7417723aaae86bec2959ad9ae6c2915ddd340e0 > --- > drivers/vfio/vfio.c | 103 ++++++++++++++++++++++++++++++++++++++++ > drivers/vfio/vfio_iommu_type1.c | 20 ++++---- > include/linux/vfio.h | 14 +++++- > 3 files changed, 126 insertions(+), 11 deletions(-) > > diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c > index 2e83bdf007fe..3bf8a01bf67b 100644 > --- a/drivers/vfio/vfio.c > +++ b/drivers/vfio/vfio.c > @@ -1799,6 +1799,109 @@ void vfio_info_cap_shift(struct vfio_info_cap *caps, size_t offset) > } > EXPORT_SYMBOL_GPL(vfio_info_cap_shift); > > + > +/* > + * Pin a set of guest PFNs and return their associated host PFNs for local > + * domain only. > + * @dev [in] : device > + * @user_pfn [in]: array of user/guest PFNs to be unpinned. Number of user/guest > + * PFNs should not be greater than VFIO_PIN_PAGES_MAX_ENTRIES. Move the second sentence to the @npage section? > + * @npage [in] :count of elements in array. This count should not be greater > + * than PAGE_SIZE. And remove the second sentence here. > + * @prot [in] : protection flags > + * @phys_pfn[out] : array of host PFNs nit: I saw three differnt styles here: @xxx [in] :xxxxxxx @xxx [in]: xxxxxxx @xxx[out]: xxxxxxx Frankly speeking, I didn't think the [in|out] flags helps much. > + * Return error or number of pages pinned. > + */ > +int vfio_pin_pages(struct device *dev, unsigned long *user_pfn, int npage, > + int prot, unsigned long *phys_pfn) > +{ > + struct vfio_container *container; > + struct vfio_group *group; > + struct vfio_iommu_driver *driver; > + int ret; > + > + if (!dev || !user_pfn || !phys_pfn || !npage) > + return -EINVAL; > + > + if (npage > VFIO_PIN_PAGES_MAX_ENTRIES) > + return -E2BIG; > + > + group = vfio_group_get_from_dev(dev); > + if (IS_ERR(group)) > + return PTR_ERR(group); > + > + ret = vfio_group_add_container_user(group); > + if (ret) > + goto err_pin_pages; > + > + container = group->container; > + down_read(&container->group_lock); > + > + driver = container->iommu_driver; > + if (likely(driver && driver->ops->pin_pages)) > + ret = driver->ops->pin_pages(container->iommu_data, user_pfn, > + npage, prot, phys_pfn); > + else > + ret = -ENOTTY; > + > + up_read(&container->group_lock); > + vfio_group_try_dissolve_container(group); > + > +err_pin_pages: > + vfio_group_put(group); > + return ret; > +} > +EXPORT_SYMBOL(vfio_pin_pages); > + > +/* > + * Unpin set of host PFNs for local domain only. > + * @dev [in] : device > + * @user_pfn [in]: array of user/guest PFNs to be unpinned. Number of user/guest > + * PFNs should not be greater than VFIO_PIN_PAGES_MAX_ENTRIES. > + * @npage [in] :count of elements in array. This count should not be greater > + * than PAGE_SIZE. Same nits as above here. > + * Return error or number of pages unpinned. > + */ [...] > diff --git a/include/linux/vfio.h b/include/linux/vfio.h > index 0ecae0b1cd34..420cdc928786 100644 > --- a/include/linux/vfio.h > +++ b/include/linux/vfio.h > @@ -75,7 +75,11 @@ struct vfio_iommu_driver_ops { > struct iommu_group *group); > void (*detach_group)(void *iommu_data, > struct iommu_group *group); > - > + int (*pin_pages)(void *iommu_data, unsigned long *user_pfn, > + int npage, int prot, > + unsigned long *phys_pfn); > + int (*unpin_pages)(void *iommu_data, > + unsigned long *user_pfn, int npage); > }; > > extern int vfio_register_iommu_driver(const struct vfio_iommu_driver_ops *ops); > @@ -127,6 +131,14 @@ static inline long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group, > } > #endif /* CONFIG_EEH */ > > +#define VFIO_PIN_PAGES_MAX_ENTRIES (PAGE_SIZE/sizeof(unsigned long)) > + > +extern int vfio_pin_pages(struct device *dev, unsigned long *user_pfn, > + int npage, int prot, unsigned long *phys_pfn); > + > +extern int vfio_unpin_pages(struct device *dev, unsigned long *user_pfn, > + int npage); > + Move this hunk up to the "External user API" section? > /* > * IRQfd - generic > */ > -- > 2.7.0 > The code looks good to me. -- Dong Jia