From patchwork Thu Apr 28 08:28:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 66877 Delivered-To: patches@linaro.org Received: by 10.140.93.198 with SMTP id d64csp80430qge; Thu, 28 Apr 2016 01:29:06 -0700 (PDT) X-Received: by 10.194.123.102 with SMTP id lz6mr14794873wjb.2.1461832146509; Thu, 28 Apr 2016 01:29:06 -0700 (PDT) Return-Path: Received: from mail-wm0-x229.google.com (mail-wm0-x229.google.com. [2a00:1450:400c:c09::229]) by mx.google.com with ESMTPS id n10si9349230wjy.217.2016.04.28.01.29.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Apr 2016 01:29:06 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::229 as permitted sender) client-ip=2a00:1450:400c:c09::229; 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::229 as permitted sender) smtp.mailfrom=eric.auger@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-wm0-x229.google.com with SMTP id e201so67269937wme.0 for ; Thu, 28 Apr 2016 01:29:06 -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=EIEh9nB6I6YVNaN79B7its9mlKpoND1Zl43AndJ+49pk5PzXXqgW+8rRV/A3NQszpR qnmkkvX0kHLSBPlrAhJsuNgxYuvb96TK1SQCnnaKuTAm+zv+hz5Jb/KChtNH3xojdzFu pvCzcF26clI/oTmRfzZVypDU+0EWPLBJE4dI4= 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=GrAA0UrtVmAs/PXfmyj5JtMh7RLvB4k4ilwS2ZSYR9Za6jQEhoHRAjSC4mN+jgrsK8 NcWmHMAAw6grXz+g8VFmpd0eT9dPfGLarBMhbhTVoPOzD8VJBvyfGGIBIpHZATurXav9 xwV+vPasT/BXVozs+H/avDFIKRrE1KmAdtpjV6flY57RJCiVac1ACynCJUlaKgqGI3Iz r40wz+NfYx9FGMB4/cMhgkESmZJUiQSPM19193DB9lFpRDUSvhWVjzfbndT3byTEXQC/ zwYb8MKB+IbJMbbY1dihBgXv/apYQWcBEXcuhfFnrDePhKG1GYL6BOWYImtaV8lf/fRn CxaA== X-Gm-Message-State: AOPr4FUxOWcobAUqOmEiHU4qgO72eHfMYFHwzujzlQncyOZbCp0dv5H04hlV8/7QYeKgu8A5MEo= X-Received: by 10.195.20.66 with SMTP id ha2mr13578115wjd.76.1461832146265; Thu, 28 Apr 2016 01:29:06 -0700 (PDT) Return-Path: Received: from new-host-46.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id j6sm8349121wjb.29.2016.04.28.01.29.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Apr 2016 01:29:04 -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 Subject: [PATCH v8 3/7] vfio/type1: bypass unmap/unpin and replay for VFIO_IOVA_RESERVED slots Date: Thu, 28 Apr 2016 08:28:34 +0000 Message-Id: <1461832118-5668-4-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461832118-5668-1-git-send-email-eric.auger@linaro.org> References: <1461832118-5668-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;