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: Eric Auger X-Patchwork-Id: 8882241 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 DE185BF29F for ; Tue, 19 Apr 2016 17:27:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F31712026F for ; Tue, 19 Apr 2016 17:27:09 +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 32EEE20251 for ; Tue, 19 Apr 2016 17:27:09 +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 1asZPD-00086g-Sx; Tue, 19 Apr 2016 17:25:43 +0000 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1asZOr-0006gu-QW for linux-arm-kernel@lists.infradead.org; Tue, 19 Apr 2016 17:25:22 +0000 Received: by mail-wm0-x231.google.com with SMTP id 127so6344463wmz.0 for ; Tue, 19 Apr 2016 10:25:01 -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=XXaxZEc6md1gYE0R3nz6b8NQP2sFe8Itasvu+2K5/Lf4lp/AuYW+1ODSV5UkuHM2C1 OKBU/VorEWFQfRgMSCCf43LNCsw4AbzXXboEE8qg+H6LOKoNxmwee1Sgu0dHfiR4c1fU efj1CrgBa934zNeKIoDq0A88inH8ouaJkOZiVh04L5eEH59DJpexBAPX5tuQT1jXelNm R8eAvRU+7/zWb/Vdo+Lg4auv2HsQ+E+t9Gf4VwKlxW7p9RyJvLA+BpsFFUPhF7l8brWP iNDDNJklcsIQGpaN0aXiuF705lhgX94D4BDIFgbSp9GR+knqLEiyXc50WQLFBfCdaNat Jvhg== X-Gm-Message-State: AOPr4FWz9gaGupmKNA7JRb++GvD8hr5KRAeosCUgewfy6ALV/jZmEkBrKeX1uPFarzNLPhh0 X-Received: by 10.28.19.21 with SMTP id 21mr25032353wmt.74.1461086700383; Tue, 19 Apr 2016 10:25:00 -0700 (PDT) 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160419_102522_038026_856EA284 X-CRM114-Status: GOOD ( 13.88 ) 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: julien.grall@arm.com, patches@linaro.org, Jean-Philippe.Brucker@arm.com, p.fedin@samsung.com, linux-kernel@vger.kernel.org, Bharat.Bhushan@freescale.com, iommu@lists.linux-foundation.org, pranav.sawargaonkar@gmail.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=-5.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 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(-) 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;