From patchwork Wed May 4 11:54:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 67124 Delivered-To: patches@linaro.org Received: by 10.140.92.199 with SMTP id b65csp135383qge; Wed, 4 May 2016 04:54:38 -0700 (PDT) X-Received: by 10.194.95.198 with SMTP id dm6mr8551797wjb.136.1462362878811; Wed, 04 May 2016 04:54:38 -0700 (PDT) Return-Path: Received: from mail-wm0-x22d.google.com (mail-wm0-x22d.google.com. [2a00:1450:400c:c09::22d]) by mx.google.com with ESMTPS id d88si4667995wmh.21.2016.05.04.04.54.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 May 2016 04:54:38 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22d as permitted sender) client-ip=2a00:1450:400c:c09::22d; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22d as permitted sender) smtp.mailfrom=eric.auger@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-wm0-x22d.google.com with SMTP id a17so89581272wme.0 for ; Wed, 04 May 2016 04:54:38 -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=4zWw3QwHuG+y7qVbiTQkH/Fx76jdUZaunVlfhJvpT0o=; b=eGCik/jRjSDsUW2XXnewtMkuzGYR0cL52Uq61u15/Z0AW3FeIr+RvJwK8OXRB6p4mG Rxv4tJF3LF5Ly5ftOCJjO4wk4z2XALh8A+gU0vcQUhe6MikCCwfpixSSgitfsTyr2PHZ yInv9RqZ81tdfFr4Hqm8VCSkmYP/wIAQ0oqxc= 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=4zWw3QwHuG+y7qVbiTQkH/Fx76jdUZaunVlfhJvpT0o=; b=YIEB65UyBydHgev0cD15RJs14VOs72q7RBXHIUT8aildsboMoOAJiRn+MJuRP9NlfU sRAtDqVy612sLiVGwN9xCJj0fioveiLkpco79UjZxvM2bYdwvWM1tVge0MbBOfNKQIkc YBllPHAHNY3ZiHmwEO70Mu44PCRiOnbxVk4F2TfzFpwphvZ9+5G0+ZGVf2CKgc7l4Rzl 36km996kPnFffST6GTLk9dnS1nnA1j0EeoOa80gSBrIxzzjgLfIvnI426zRvwyYn3zCH YJ8/2ksYZmrBZXSL0vZ91jOnRdcs/m/KRkn1RVvuSr3M1Rhr9KzyJRW0+PzZFy0p41KW VWJQ== X-Gm-Message-State: AOPr4FVULuuoJ8SFQrc21z7xqEGp/BPyMp1vp45S/zln3u9tWW58rRZU6INwgT7P79f06+KlpUY= X-Received: by 10.28.175.143 with SMTP id y137mr16057740wme.21.1462362878476; Wed, 04 May 2016 04:54:38 -0700 (PDT) Return-Path: Received: from new-host-61.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id ck9sm3816623wjc.22.2016.05.04.04.54.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 May 2016 04:54:36 -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 Cc: patches@linaro.org, linux-kernel@vger.kernel.org, Bharat.Bhushan@freescale.com, pranav.sawargaonkar@gmail.com, p.fedin@samsung.com, iommu@lists.linux-foundation.org, Jean-Philippe.Brucker@arm.com, julien.grall@arm.com, yehuday@marvell.com Subject: [PATCH v9 3/7] vfio/type1: bypass unmap/unpin and replay for VFIO_IOVA_RESERVED slots Date: Wed, 4 May 2016 11:54:14 +0000 Message-Id: <1462362858-2925-4-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1462362858-2925-1-git-send-email-eric.auger@linaro.org> References: <1462362858-2925-1-git-send-email-eric.auger@linaro.org> Before allowing the end-user to create VFIO_IOVA_RESERVED dma slots, let's implement the expected behavior for removal and replay. As opposed to user dma slots, IOVAs are not systematically bound to PAs and PAs are not pinned. VFIO just initializes the IOVA "aperture". IOVAs are allocated outside of the VFIO framework, typically the MSI layer which is responsible to free and unmap them. The MSI mapping resources are freeed by the IOMMU driver on domain destruction. Signed-off-by: Eric Auger --- v7 -> v8: - do no destroy anything anymore, just bypass unmap/unpin and iommu_map on replay --- drivers/vfio/vfio_iommu_type1.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) -- 1.9.1 diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 2d769d4..94a9916 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -391,7 +391,7 @@ static void vfio_unmap_unpin(struct vfio_iommu *iommu, struct vfio_dma *dma) struct vfio_domain *domain, *d; long unlocked = 0; - if (!dma->size) + if (!dma->size || dma->type != VFIO_IOVA_USER) return; /* * We use the IOMMU to track the physical addresses, otherwise we'd @@ -727,6 +727,9 @@ static int vfio_iommu_replay(struct vfio_iommu *iommu, dma = rb_entry(n, struct vfio_dma, node); iova = dma->iova; + if (dma->type == VFIO_IOVA_RESERVED) + continue; + while (iova < dma->iova + dma->size) { phys_addr_t phys = iommu_iova_to_phys(d->domain, iova); size_t size;