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: 8121681 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 967CE9F6DA for ; Tue, 26 Jan 2016 13:15:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AC8132024C for ; Tue, 26 Jan 2016 13:15:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BC3F72020F for ; Tue, 26 Jan 2016 13:15:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965915AbcAZNNi (ORCPT ); Tue, 26 Jan 2016 08:13:38 -0500 Received: from mail-wm0-f47.google.com ([74.125.82.47]:33606 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965895AbcAZNNe (ORCPT ); Tue, 26 Jan 2016 08:13:34 -0500 Received: by mail-wm0-f47.google.com with SMTP id 123so105334988wmz.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=VFuOUisMDuOLPOkzioJkSpF5EWIvKmx5jZbaiXdVQ/nYZmurjDh7W9+OZOog/OwMBE SHeU8AIlu+5uNG9pZaAzLm+zLXY8C4hLk7sLYoWp9T76+Ovw8wM6LpLIuDppdOEwaY6J Ymy1zFYk53dCQwc5fv2ZsjxRiT8ifg9XUyq4spJaJyzwq3anMsPCIZlg3xDDOwNRgTN2 Bme9UnWfjBJ6o29/l2FLDEBU8KRivkrit9mI6s/oe7B+QPPmL1MbJBRfIrsrQ62bpfX0 e4g8agXbEBbZY8fE3IYLI4R9qgISj5dzzX7jMIVASd760PPHeS84Xts77urYz3MKvdhy FYhQ== X-Gm-Message-State: AG10YOSuQ8olaK2Dsqs3RIue5jTyjN7+DW+Dp6FsR75rAIfxqivZUnxInxhmM/yNIdAJa4tZ 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 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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.8 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 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;