From patchwork Thu Apr 28 08:28:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 66881 Delivered-To: patches@linaro.org Received: by 10.140.93.198 with SMTP id d64csp80486qge; Thu, 28 Apr 2016 01:29:17 -0700 (PDT) X-Received: by 10.28.4.194 with SMTP id 185mr28121153wme.11.1461832157785; Thu, 28 Apr 2016 01:29:17 -0700 (PDT) Return-Path: Received: from mail-wm0-x235.google.com (mail-wm0-x235.google.com. [2a00:1450:400c:c09::235]) by mx.google.com with ESMTPS id w189si14112444wmg.20.2016.04.28.01.29.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Apr 2016 01:29:17 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::235 as permitted sender) client-ip=2a00:1450:400c:c09::235; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::235 as permitted sender) smtp.mailfrom=eric.auger@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-wm0-x235.google.com with SMTP id e201so67275980wme.0 for ; Thu, 28 Apr 2016 01:29:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SAj8Jcp3tlU4brS18YfwyUVi6Q2z4AprKD0Npe/6u5g=; b=AK/o2xebqhABv3DKSdoOZ8cSx9jSDfb43EY3aIILN2HmzU0WgxFoOul1NT+rbkw/Tr gMtq6w9fAz6rt3j3eSdBTPoKTyh9fVy/AFRgCRINZhJLbP9j9XrHwuqw07H3h89Pk5zR r4+JbIPWS1e1H4Rhmt0hGejMOL9GmtClZfbUs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SAj8Jcp3tlU4brS18YfwyUVi6Q2z4AprKD0Npe/6u5g=; b=UFxPGkJ1NvmwQ2W598pyEjH3lq55bIDKJ2TI0CSGFRFiGhySVGzlMwhIBVAaTZo+eq WZqixr4YpGGuXXjhHco2uc/2bf6LwePwPkWVHwYn7p7yj5xTEXWlKW2YrN48/KK53VlQ JrTkb5wxnbQAudahT/62shQ/NWpqZLAoZtPka6Iuhfj5y/oVLYKuDthlfoFFYZGXEplY IoxB0UIp29+/6cgWHzZ/eu4hiRZDRBHDUGfIUg/k1UI+kDZmoVoeC0x68c4xBXNn8XrI MWPfTUaydduR9kxokDfa38IIch23hM7xq805mphTqI21bhz3OC7UgHuENpeb1tIBjLyT ZnIg== X-Gm-Message-State: AOPr4FVpYRZrZ3hLc6GtP8EKN9WXy1KwbMiW9XljHac1bGCbdapuyvFuDTWhj3Uy4vzBiHjfDiA= X-Received: by 10.28.210.10 with SMTP id j10mr28627769wmg.21.1461832157534; Thu, 28 Apr 2016 01:29:17 -0700 (PDT) Return-Path: Received: from new-host-46.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id j6sm8349121wjb.29.2016.04.28.01.29.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Apr 2016 01:29:16 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, robin.murphy@arm.com, alex.williamson@redhat.com, will.deacon@arm.com, joro@8bytes.org, tglx@linutronix.de, jason@lakedaemon.net, marc.zyngier@arm.com, christoffer.dall@linaro.org, linux-arm-kernel@lists.infradead.org Cc: patches@linaro.org, linux-kernel@vger.kernel.org, Bharat.Bhushan@freescale.com, pranav.sawargaonkar@gmail.com, p.fedin@samsung.com, iommu@lists.linux-foundation.org, Jean-Philippe.Brucker@arm.com, julien.grall@arm.com Subject: [PATCH v8 7/7] vfio/type1: return MSI mapping requirements with VFIO_IOMMU_GET_INFO Date: Thu, 28 Apr 2016 08:28:38 +0000 Message-Id: <1461832118-5668-8-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461832118-5668-1-git-send-email-eric.auger@linaro.org> References: <1461832118-5668-1-git-send-email-eric.auger@linaro.org> This patch allows the user-space to know whether MSI addresses need to be mapped in the IOMMU. The user-space uses VFIO_IOMMU_GET_INFO ioctl and IOMMU_INFO_REQUIRE_MSI_MAP gets set if they need to. The computation of the number of IOVA pages to be provided by the user space will be implemented in a separate patch using capability chains. Signed-off-by: Eric Auger --- v6 -> v7: - remove the computation of the number of IOVA pages to be provisionned. This number depends on the domain/group/device topology which can dynamically change. Let's rely instead rely on an arbitrary max depending on the system v4 -> v5: - move msi_info and ret declaration within the conditional code v3 -> v4: - replace former vfio_domains_require_msi_mapping by more complex computation of MSI mapping requirements, especially the number of pages to be provided by the user-space. - reword patch title RFC v1 -> v1: - derived from [RFC PATCH 3/6] vfio: Extend iommu-info to return MSIs automap state - renamed allow_msi_reconfig into require_msi_mapping - fixed VFIO_IOMMU_GET_INFO --- drivers/vfio/vfio_iommu_type1.c | 26 ++++++++++++++++++++++++++ include/uapi/linux/vfio.h | 4 ++++ 2 files changed, 30 insertions(+) -- 1.9.1 diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 2fc8197..86d97d9 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -310,6 +310,29 @@ static int vaddr_get_pfn(unsigned long vaddr, int prot, unsigned long *pfn) } /* + * vfio_domains_require_msi_mapping: return whether MSI doorbells must be + * iommu mapped + * + * returns true if msi mapping is requested + */ +static bool vfio_domains_require_msi_mapping(struct vfio_iommu *iommu) +{ + struct iommu_domain_msi_geometry msi_geometry; + struct vfio_domain *d; + bool flag; + + mutex_lock(&iommu->lock); + /* All domains have same require_msi_map property, pick first */ + d = list_first_entry(&iommu->domain_list, struct vfio_domain, next); + iommu_domain_get_attr(d->domain, DOMAIN_ATTR_MSI_GEOMETRY, + &msi_geometry); + flag = msi_geometry.programmable; + + mutex_unlock(&iommu->lock); + + return flag; +} +/* * Attempt to pin pages. We really don't want to track all the pfns and * the iommu can only map chunks of consecutive pfns anyway, so get the * first page and all consecutive pages with the same locking. @@ -1166,6 +1189,9 @@ static long vfio_iommu_type1_ioctl(void *iommu_data, info.flags = VFIO_IOMMU_INFO_PGSIZES; + if (vfio_domains_require_msi_mapping(iommu)) + info.flags |= VFIO_IOMMU_INFO_REQUIRE_MSI_MAP; + info.iova_pgsizes = vfio_pgsize_bitmap(iommu); return copy_to_user((void __user *)arg, &info, minsz) ? diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 4a9dbc2..3e27263 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -488,6 +488,7 @@ struct vfio_iommu_type1_info { __u32 argsz; __u32 flags; #define VFIO_IOMMU_INFO_PGSIZES (1 << 0) /* supported page sizes info */ +#define VFIO_IOMMU_INFO_REQUIRE_MSI_MAP (1 << 1)/* MSI must be mapped */ __u64 iova_pgsizes; /* Bitmap of supported page sizes */ }; @@ -503,6 +504,9 @@ struct vfio_iommu_type1_info { * IOVA region that will be used on some platforms to map the host MSI frames. * In that specific case, vaddr is ignored. Once registered, an MSI reserved * IOVA region stays until the container is closed. + * The requirement for provisioning such reserved IOVA range can be checked by + * calling VFIO_IOMMU_GET_INFO and testing the VFIO_IOMMU_INFO_REQUIRE_MSI_MAP + * flag. */ struct vfio_iommu_type1_dma_map { __u32 argsz;