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: Eric Auger X-Patchwork-Id: 8121791 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 D7CD2BEEE5 for ; Tue, 26 Jan 2016 13:17:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 084D72020F for ; Tue, 26 Jan 2016 13:17:18 +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 31900201F2 for ; Tue, 26 Jan 2016 13:17:17 +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 1aO3T9-0002a9-6f; Tue, 26 Jan 2016 13:15:39 +0000 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aO3RT-000074-FI for linux-arm-kernel@lists.infradead.org; Tue, 26 Jan 2016 13:13:56 +0000 Received: by mail-wm0-x22a.google.com with SMTP id n5so129554599wmn.0 for ; Tue, 26 Jan 2016 05:13:34 -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=QGucvYaxbcAXa7dAqKfAp00dtMlcxh1L1UNntrTwTK5MRiQmazduNxqvhLvI5wZj3+ cUdydZ1eBVEbdFiEvkyd9R4YUiVyayybwdSIC9FvBx3vm2kPhSYIOAbDFTxEPHEmOrL/ DmT/2ewlZ7nLyqBJdynHyciM5MuCEnsqpgwYV9hM9nwKvEY669oizGsGmhsDW/kvd7W9 QU1D9kUtdO3YPZ0QxS6B8cDhHOqRj1Y1q7xI1IAVBLUBoONLN0rdm0n7zL0Wkn0vFQUA kOV5QP2KTp0b6n3wBOhoVBU7coKo8pQJR7xVum37fB2sl6blxN8nRlCqH5k85khoGeVP rWtg== X-Gm-Message-State: AG10YOSRwAy46YN/NJVBBWFdfSPtXiPgG/etQdLciBo8cXQyEMyAyNbx4FYxRGw0uRYBng7t X-Received: by 10.28.89.69 with SMTP id n66mr25492876wmb.63.1453814013728; Tue, 26 Jan 2016 05:13:33 -0800 (PST) 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160126_051355_762387_CD066F30 X-CRM114-Status: GOOD ( 17.78 ) 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: patches@linaro.org, p.fedin@samsung.com, linux-kernel@vger.kernel.org, Bharat.Bhushan@freescale.com, iommu@lists.linux-foundation.org, pranav.sawargaonkar@gmail.com, suravee.suthikulpanit@amd.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=-4.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 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(+) 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;