From patchwork Tue Apr 19 17:24:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 8882281 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 72F93BF29F for ; Tue, 19 Apr 2016 17:27:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 80491202C8 for ; Tue, 19 Apr 2016 17:27:49 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9FD562026F for ; Tue, 19 Apr 2016 17:27:48 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1asZPr-0000M2-GQ; Tue, 19 Apr 2016 17:26:23 +0000 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1asZOz-0007s1-QM for linux-arm-kernel@lists.infradead.org; Tue, 19 Apr 2016 17:25:30 +0000 Received: by mail-wm0-x22b.google.com with SMTP id n3so41796195wmn.0 for ; Tue, 19 Apr 2016 10:25:09 -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=BD5kMnLbXFzOVhTs+7nai2bsM8zOyk7Yz/d4GLgWSmE=; b=NSj3h73h8hEXgFBm+PTBqK7u9mlWXR9ZRsupOAjbhfaPXI4M/9TQl+FzxMnzcFeq1i 0BupdHthyC/3iXSjyX8k00zjUMSKuOt3TBGwfpPstxBhJr/tUVUsO08HGLdUsEBSBB09 xALfD2GnNjef+2bNDK4T8Kwz33CsJozIBgWY8= 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=BD5kMnLbXFzOVhTs+7nai2bsM8zOyk7Yz/d4GLgWSmE=; b=SljZYD+HIeUpGdjiiea1GpEs7O8llTL+2CSlzncayWAOC4xkeP4GmHbFOFDx4WBNiR F0/WoqP9IItbrvhLBQewmXxu4LbmMlUZr9DCmP02GL3XbyCH51DGi71NN71P62/YZroF WtNkln0UQ16iDDv52hmFqzP/Fer7V3CMhYsB2bRHsSdgvjUJ/XSKOUPZK+rVrPFPb2Ja K4ECl0nkysHyzYYjDWkC9E1sm3M7u+ZlimHlC9NWrSh118/BGRvxXsEAP8yGrdDE/PxK 1zE9Iy3K8sJuHUebuxwuCOdJ6FES+jO88nxlsF+Rzv/CXQMqjXFvCmHp5SySgFRnpWDh ILfw== X-Gm-Message-State: AOPr4FXj6woPx4+ORe3yOYFywgZHLZRopgiDtRYJbACajAAhKSGBcepjT/FxNos0ddaEDBEw X-Received: by 10.28.157.142 with SMTP id g136mr4807408wme.29.1461086708347; Tue, 19 Apr 2016 10:25:08 -0700 (PDT) Received: from new-host-34.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id w202sm5330220wmw.18.2016.04.19.10.25.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Apr 2016 10:25:07 -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 Subject: [PATCH v7 7/7] vfio/type1: return MSI mapping requirements with VFIO_IOMMU_GET_INFO Date: Tue, 19 Apr 2016 17:24:47 +0000 Message-Id: <1461086687-2658-8-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461086687-2658-1-git-send-email-eric.auger@linaro.org> References: <1461086687-2658-1-git-send-email-eric.auger@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160419_102530_038990_0941A3A8 X-CRM114-Status: GOOD ( 19.91 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: julien.grall@arm.com, patches@linaro.org, Jean-Philippe.Brucker@arm.com, p.fedin@samsung.com, linux-kernel@vger.kernel.org, Bharat.Bhushan@freescale.com, iommu@lists.linux-foundation.org, pranav.sawargaonkar@gmail.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 | 24 ++++++++++++++++++++++++ include/uapi/linux/vfio.h | 5 ++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 51b1f15..a63ce6f 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -310,6 +310,27 @@ 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 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); + flag = (!(iommu_domain_get_attr(d->domain, + DOMAIN_ATTR_MSI_MAPPING, NULL))); + + 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. @@ -1231,6 +1252,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 0637f35..4d9c97d 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 */ }; @@ -501,7 +502,9 @@ struct vfio_iommu_type1_info { * * In case RESERVED_MSI_IOVA flag is set, the API only aims at registering an * IOVA region that will be used on some platforms to map the host MSI frames. - * In that specific case, vaddr is ignored. + * In that specific case, vaddr is ignored. 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;