Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755201AbcKONKQ (ORCPT ); Tue, 15 Nov 2016 08:10:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52382 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754982AbcKONKL (ORCPT ); Tue, 15 Nov 2016 08:10:11 -0500 From: Eric Auger To: eric.auger@redhat.com, eric.auger.pro@gmail.com, christoffer.dall@linaro.org, marc.zyngier@arm.com, robin.murphy@arm.com, alex.williamson@redhat.com, will.deacon@arm.com, joro@8bytes.org, tglx@linutronix.de, jason@lakedaemon.net, linux-arm-kernel@lists.infradead.org Cc: kvm@vger.kernel.org, drjones@redhat.com, linux-kernel@vger.kernel.org, pranav.sawargaonkar@gmail.com, iommu@lists.linux-foundation.org, punit.agrawal@arm.com, diana.craciun@nxp.com Subject: [RFC v3 10/10] vfio/type1: Get MSI cookie Date: Tue, 15 Nov 2016 13:09:23 +0000 Message-Id: <1479215363-2898-11-git-send-email-eric.auger@redhat.com> In-Reply-To: <1479215363-2898-1-git-send-email-eric.auger@redhat.com> References: <1479215363-2898-1-git-send-email-eric.auger@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 15 Nov 2016 13:10:10 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2003 Lines: 64 When attaching a group to the container, handle the group's reserved regions and particularly the IOMMU_RESV_MSI region which requires an IOVA allocator to be initialized through the iommu_get_msi_cookie API. This will allow the MSI IOVAs to be transparently allocated on MSI controller's compose(). Signed-off-by: Eric Auger --- drivers/vfio/vfio_iommu_type1.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 2ba1942..701d8a8 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -36,6 +36,7 @@ #include #include #include +#include #define DRIVER_VERSION "0.2" #define DRIVER_AUTHOR "Alex Williamson " @@ -734,6 +735,27 @@ static void vfio_test_domain_fgsp(struct vfio_domain *domain) __free_pages(pages, order); } +static int vfio_iommu_handle_resv_regions(struct iommu_domain *domain, + struct iommu_group *group) +{ + struct list_head group_resv_regions; + struct iommu_resv_region *region, *next; + int ret = 0; + + INIT_LIST_HEAD(&group_resv_regions); + iommu_get_group_resv_regions(group, &group_resv_regions); + list_for_each_entry(region, &group_resv_regions, list) { + if (region->prot & IOMMU_RESV_MSI) { + ret = iommu_get_msi_cookie(domain, region->start); + if (ret) + break; + } + } + list_for_each_entry_safe(region, next, &group_resv_regions, list) + kfree(region); + return ret; +} + static int vfio_iommu_type1_attach_group(void *iommu_data, struct iommu_group *iommu_group) { @@ -834,6 +856,10 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, if (ret) goto out_detach; + ret = vfio_iommu_handle_resv_regions(domain->domain, iommu_group); + if (ret) + goto out_detach; + list_add(&domain->next, &iommu->domain_list); mutex_unlock(&iommu->lock); -- 1.9.1