From patchwork Tue Apr 19 17:24: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: 66133 Delivered-To: patches@linaro.org Received: by 10.140.93.198 with SMTP id d64csp1983662qge; Tue, 19 Apr 2016 10:25:05 -0700 (PDT) X-Received: by 10.194.78.178 with SMTP id c18mr4906875wjx.114.1461086700644; Tue, 19 Apr 2016 10:25:00 -0700 (PDT) Return-Path: Received: from mail-wm0-x22b.google.com (mail-wm0-x22b.google.com. [2a00:1450:400c:c09::22b]) by mx.google.com with ESMTPS id 204si5290511wmy.68.2016.04.19.10.25.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Apr 2016 10:25:00 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22b as permitted sender) client-ip=2a00:1450:400c:c09::22b; 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::22b as permitted sender) smtp.mailfrom=eric.auger@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-wm0-x22b.google.com with SMTP id v188so171473394wme.1 for ; Tue, 19 Apr 2016 10:25:00 -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=MR4tc1AXztWYmwi41urbGNjQg+9Hu93f7mLQruGrfFU=; b=frS5ZZSws/P8sMIoU0yw6Oua7ot1zcTNcMh19cC2OYZTusF/35pqyV9v7HL3Eg8vVw u0GadbIdG5DC+oktHsmtKQgAICDJHOOqFeGMbk414PcMeiIV2OIsFBnG/6sM7Orut3wc TP9Gz8B9XxbBFcHi1gKMv73NoND1VfmZ36ZHY= 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=MR4tc1AXztWYmwi41urbGNjQg+9Hu93f7mLQruGrfFU=; b=BDSjlHPz4un6TzwcrNSwpPP3+1egoBk8fPQSKwLoqz5fmQQ0oLk/Cbed0EHhXkU/2H iu/uCrjyQ2vISGOSf27WRP5NncBCvANGf5lgyTJbZoLkSEPhlxXvADKOyCi3UMPeJSOa tNwbql4J9SY5AaqCXypDdQPWPoQX3S5mXKTxmZhlu/awKmmjJjKPEVTda+uD8BRdlUG/ k87G8hr4AgIEtJu0qdtpAWvXyJV8bI/GZ1lVF0B94BMHN/Pqhl0/MVcMwVl313SNvcvH T6snJ/2CnUG7v1A86O89NHwM5KHKB5xKJhacSFCC8NXLOGAIpYVgyWPCDJTO+1X/aCx6 0qFQ== X-Gm-Message-State: AOPr4FXiWh/2tYLfgQ6idysJSC9D4zfQ0sZes7WlhNduRsgs/9K2r2XAUisheJe22ikH4rJ8r2I= X-Received: by 10.28.19.21 with SMTP id 21mr25032353wmt.74.1461086700383; Tue, 19 Apr 2016 10:25:00 -0700 (PDT) Return-Path: Received: from new-host-34.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id w202sm5330220wmw.18.2016.04.19.10.24.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Apr 2016 10:24:59 -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 v7 3/7] vfio/type1: specialize remove_dma and replay according to type Date: Tue, 19 Apr 2016 17:24:43 +0000 Message-Id: <1461086687-2658-4-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461086687-2658-1-git-send-email-eric.auger@linaro.org> References: <1461086687-2658-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, the physical pages bound to reserved IOVA do not need to be pinned/unpinned. Also we currently handle a single reserved iova domain. Any attempt to remove the single reserved dma slot ends up deleting the underlying iova domain for each iommu domain. Signed-off-by: Eric Auger --- drivers/vfio/vfio_iommu_type1.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) -- 1.9.1 diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 2d769d4..93c17d9 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 " @@ -445,9 +446,20 @@ static void vfio_unmap_unpin(struct vfio_iommu *iommu, struct vfio_dma *dma) vfio_lock_acct(-unlocked); } +static void vfio_destroy_reserved(struct vfio_iommu *iommu) +{ + struct vfio_domain *d; + + list_for_each_entry(d, &iommu->domain_list, next) + iommu_free_reserved_iova_domain(d->domain); +} + static void vfio_remove_dma(struct vfio_iommu *iommu, struct vfio_dma *dma) { - vfio_unmap_unpin(iommu, dma); + if (likely(dma->type == VFIO_IOVA_USER)) + vfio_unmap_unpin(iommu, dma); + else + vfio_destroy_reserved(iommu); vfio_unlink_dma(iommu, dma); kfree(dma); } @@ -727,6 +739,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;