From patchwork Tue Jan 26 13:12:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 60455 Delivered-To: patches@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp1949063lbb; Tue, 26 Jan 2016 05:13:33 -0800 (PST) X-Received: by 10.28.30.138 with SMTP id e132mr22784682wme.86.1453814013920; Tue, 26 Jan 2016 05:13:33 -0800 (PST) Return-Path: Received: from mail-wm0-x232.google.com (mail-wm0-x232.google.com. [2a00:1450:400c:c09::232]) by mx.google.com with ESMTPS id m132si5451399wmd.38.2016.01.26.05.13.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jan 2016 05:13:33 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::232 as permitted sender) client-ip=2a00:1450:400c:c09::232; Authentication-Results: mx.google.com; spf=pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::232 as permitted sender) smtp.mailfrom=eric.auger@linaro.org; dkim=pass header.i=@linaro.org Received: by mail-wm0-x232.google.com with SMTP id n5so129554595wmn.0 for ; Tue, 26 Jan 2016 05:13:33 -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=XubnHgwEvJGjJbCOjliHWbc59KSCGVuO/8ipApXkEJU=; b=kyqOh097p2VtSHdGnzUD88TrchXJdA/FOVa5DuPhNSXIqWOHi0//KOrMuTDnJemb3P 49Hf4LF4fgKle7WKBSNUJyEJGHP0xM0/k7L6KnTTlJ7zhCxRdOjTnTbTPDPppkogncSJ QNUH96NWrEvKxJtl637B+juui8wTSHfR/GcR0= 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=XubnHgwEvJGjJbCOjliHWbc59KSCGVuO/8ipApXkEJU=; b=HKE197rHPAYKvkRh2C2bPN6xfLVBbs5cenGmjjhN4296C5akwYBVk5eocnyN1aXG3n tOBZp5VPYcC8lKPBmOx/0xjlkyJBzQSBRCSFkNxxjXO18ZFO582FkNMz/19YjnVbGCOq Win+4e5nPxXoyBkoXiJq/0l971PzzLjmlpD1lhl4Ag9dgTpX8g0y0F0fJxlHYSDs0Icr pVPfut4qdXy1ho/FQUQqnF5OeocBuxnUK6equFvICm183cYQqKtr/5nJd5AOj7Y+9NSb cef2opOb0wDVwlXDanGjGOygfnEBAQ7+H9uLaIRY8MppGR/zP0eFtTF28NRWeLR/6hrk EkwA== X-Gm-Message-State: AG10YOTpTVONtXkwrgnnkAR6MiWDaHNfjh5y/yLmxziclcGef4KhevIns3hQ6X0lJE21yKu9lnU= X-Received: by 10.28.89.69 with SMTP id n66mr25492876wmb.63.1453814013728; Tue, 26 Jan 2016 05:13:33 -0800 (PST) Return-Path: Received: from localhost.localdomain (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id ct2sm1388885wjb.46.2016.01.26.05.13.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Jan 2016 05:13:32 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, alex.williamson@redhat.com, will.deacon@arm.com, christoffer.dall@linaro.org, marc.zyngier@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: Bharat.Bhushan@freescale.com, pranav.sawargaonkar@gmail.com, p.fedin@samsung.com, suravee.suthikulpanit@amd.com, linux-kernel@vger.kernel.org, patches@linaro.org, iommu@lists.linux-foundation.org Subject: [PATCH 05/10] vfio/type1: attach a reserved iova domain to vfio_domain Date: Tue, 26 Jan 2016 13:12:43 +0000 Message-Id: <1453813968-2024-6-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1453813968-2024-1-git-send-email-eric.auger@linaro.org> References: <1453813968-2024-1-git-send-email-eric.auger@linaro.org> This patch adds a reserved iova_domain to the vfio_domain struct. This iova domain will enable to allocate iova within the reserved iova region. alloc_reserved_iova_domain makes possible to allocate and initialize this iova domain. The user will be introduced in subsequent patches. Signed-off-by: Eric Auger --- drivers/vfio/vfio_iommu_type1.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) -- 1.9.1 diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 33a9ce4..33304c0 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 " @@ -77,6 +78,7 @@ struct vfio_domain { struct list_head group_list; /* rb tree indexed by PA, for reserved bindings only */ struct rb_root reserved_binding_list; + struct iova_domain *reserved_iova_domain; int prot; /* IOMMU_CACHE */ bool fgsp; /* Fine-grained super pages */ }; @@ -178,6 +180,41 @@ static struct vfio_dma *vfio_find_dma(struct vfio_iommu *iommu, return NULL; } +/* alloc_reserved_iova_domain: allocate an iova domain used to manage + * reserved iova + * @iova: base iova of the domain + * @size: size of the domain + * @order: iommu page size order + */ +static int alloc_reserved_iova_domain(struct vfio_domain *domain, + dma_addr_t iova, size_t size, + unsigned long order) +{ + unsigned long granule, mask; + int ret = 0; + + granule = 1UL << order; + mask = granule - 1; + if (iova & mask) + return -EINVAL; + if ((!size) || (size & mask)) + return -EINVAL; + + domain->reserved_iova_domain = + kzalloc(sizeof(struct iova_domain), GFP_KERNEL); + if (!domain->reserved_iova_domain) { + ret = -ENOMEM; + goto out_free; + } + init_iova_domain(domain->reserved_iova_domain, + granule, iova >> order, (iova + size - 1) >> order); + return ret; + +out_free: + kfree(domain->reserved_iova_domain); + return ret; +} + static void vfio_link_dma(struct vfio_iommu *iommu, struct vfio_dma *new) { struct rb_node **link = &iommu->dma_list.rb_node, *parent = NULL;