From patchwork Fri Feb 12 08:13:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 8288311 Return-Path: X-Original-To: patchwork-kvm@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 7D2E4BEEE5 for ; Fri, 12 Feb 2016 08:19:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 908262035D for ; Fri, 12 Feb 2016 08:19:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A752D203C4 for ; Fri, 12 Feb 2016 08:19:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751785AbcBLITH (ORCPT ); Fri, 12 Feb 2016 03:19:07 -0500 Received: from mail-wm0-f47.google.com ([74.125.82.47]:36026 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751288AbcBLIOE (ORCPT ); Fri, 12 Feb 2016 03:14:04 -0500 Received: by mail-wm0-f47.google.com with SMTP id p63so9121533wmp.1 for ; Fri, 12 Feb 2016 00:14:04 -0800 (PST) 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=i3FW+63Ncuxln/JNpMSbbUZHEKCYUSS45T2f/pM/I/k=; b=TfcjkifV9vkGnbIjx4bPE0QeKGh9CyLWKqAwxHrU0LGGfNq3qA/r9Shfn6I4AEjrpT b2bU4VQnHX+arPfq1PYUNQLZmYSrOCxx2gJhvYCwXhvUNL8Nb8qCgZ1x2tEXcynTHGJ5 /qzNPtqV+A7fhOCTWK8Z/qALxzLq7N96gUMFk= 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=i3FW+63Ncuxln/JNpMSbbUZHEKCYUSS45T2f/pM/I/k=; b=GkgRNsqbeLehZ0BMDtDn33Wra5yTA2RMHQhmw+IROEK0FyFy/Wyc+QQKbEYZx+X7Pu eR0xYd9iAWpfZ+/gH4VhBlLxfxq/9NQwN4HR/E/BgYPvmkuHNChkG98Qw1rlrFZH1Juv Qr4rOCRJMqiR5XBxv6HQ4R2byRa+bF7vvp6ocSdGsGwHHk1ohFPLmqXW7a0Ih9u7IFI0 qczGpgX2O6lULj9ayQwxzDOb9TsV0x+sfTP+NRVy9+69qQ38xeu1LSAHoQ8bN/RpXrKw HMJGWtAcZJDR41HlPtO30TZhR87kCpYScGnu9fPwG4OWD89SOUCcaxgyPS/95imrpAnr GGDw== X-Gm-Message-State: AG10YOReo84HTiHBBebdx/cJy6yd41pMsczD4amboxYBC6MQvNlu10ySHzsmXMVdjXlJBrgk X-Received: by 10.194.9.42 with SMTP id w10mr191686wja.159.1455264843677; Fri, 12 Feb 2016 00:14:03 -0800 (PST) Received: from new-host-17.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id x66sm1243977wmb.20.2016.02.12.00.14.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Feb 2016 00:14:02 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, 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, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: suravee.suthikulpanit@amd.com, patches@linaro.org, linux-kernel@vger.kernel.org, Manish.Jaggi@caviumnetworks.com, Bharat.Bhushan@freescale.com, pranav.sawargaonkar@gmail.com, p.fedin@samsung.com, iommu@lists.linux-foundation.org, sherry.hurwitz@amd.com, brijesh.singh@amd.com, leo.duran@amd.com, Thomas.Lendacky@amd.com Subject: [RFC v3 02/15] vfio: expose MSI mapping requirement through VFIO_IOMMU_GET_INFO Date: Fri, 12 Feb 2016 08:13:04 +0000 Message-Id: <1455264797-2334-3-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455264797-2334-1-git-send-email-eric.auger@linaro.org> References: <1455264797-2334-1-git-send-email-eric.auger@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,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 retrieve whether msi write transaction addresses must be mapped. This is returned through the VFIO_IOMMU_GET_INFO API and its new flag: VFIO_IOMMU_INFO_REQUIRE_MSI_MAP. Signed-off-by: Bharat Bhushan Signed-off-by: Eric Auger Acked-by: Marc Zyngier --- 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 | 1 + 2 files changed, 27 insertions(+) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 6f1ea3d..c5b57e1 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -255,6 +255,29 @@ static int vaddr_get_pfn(unsigned long vaddr, int prot, unsigned long *pfn) } /* + * vfio_domains_require_msi_mapping: indicates whether MSI write transaction + * addresses must be mapped + * + * returns true if it does + */ +static bool vfio_domains_require_msi_mapping(struct vfio_iommu *iommu) +{ + struct vfio_domain *d; + bool ret; + + 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); + if (iommu_domain_get_attr(d->domain, DOMAIN_ATTR_MSI_MAPPING, NULL) < 0) + ret = false; + else + ret = true; + mutex_unlock(&iommu->lock); + + return ret; +} + +/* * 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. @@ -997,6 +1020,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 7d7a4c6..43e183b 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -400,6 +400,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 */ };