From patchwork Fri Feb 12 08:13:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 8288361 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 6ED0EBEEE5 for ; Fri, 12 Feb 2016 08:21:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8168B2035D for ; Fri, 12 Feb 2016 08:21:39 +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 AE923202EC for ; Fri, 12 Feb 2016 08:21:38 +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 1aU8xA-0002FR-At; Fri, 12 Feb 2016 08:19:48 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aU8sE-0004n8-WF for linux-arm-kernel@lists.infradead.org; Fri, 12 Feb 2016 08:14:46 +0000 Received: by mail-wm0-x234.google.com with SMTP id g62so8947323wme.0 for ; Fri, 12 Feb 2016 00:14:23 -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=UKFmbaNKDyfPSdKuCT8gpiApo3OxYgDoZJ670XyxPAk=; b=iccTFqrCRGbyZxVBpSkea5oY19z7rTf2dzBE25wIjFyH0T+QJXxy542PhLeLw7MgCF umyQexMLS3yKDdDnBLEIeF0WXQP7ZRTg+scneKILThsCSHkDZV6Z08H73Aax7f3DH0rq o9CFqNr6y1sOu4oOTBHPdw1S/Dbw5c5j6hm9Q= 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=UKFmbaNKDyfPSdKuCT8gpiApo3OxYgDoZJ670XyxPAk=; b=IPeAh1C566n1GEjDMlJeIZeJ2eMhWS2ZwEECcizbXLdnbxE0Dk8Yg7lYjff6DB8dP5 gifZCcDN3uIAhV4YVOGwqoDJjRix0bwJMUteNYAmePw1G/bVU7Z6O15lXRgjo2O5Qexc hrFhE1Lr+GcUw4BmYI6kSPw/ShxCbLycz1iebZp1STjg7AjHXvjvMr18LoY5QOwPbXlU Kavi4GGfyBtGF4LDwoPxSwNaVgDnakP68qfKUI0sup8iJljYm5go7QF01/EfY7Zf3oBB L6qj6Jj03HOneSI/yIPMFV4yhm4tJxzsIsdAOngiWLXohKXTbgSAP1VlOw2FDGb1FfJD tJiQ== X-Gm-Message-State: AG10YOQXpMYp8EC7o2PIFdA/BIVf163/jRoe7BbKflNcsIM5UFL8LBQWZ+lW8ecYbUOErn82 X-Received: by 10.194.87.161 with SMTP id az1mr194637wjb.163.1455264861945; Fri, 12 Feb 2016 00:14:21 -0800 (PST) Received: from new-host-17.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id x66sm1243977wmb.20.2016.02.12.00.14.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Feb 2016 00:14:20 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, 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, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Subject: [RFC v3 09/15] iommu/arm-smmu: relinquish reserved resources on domain deletion Date: Fri, 12 Feb 2016 08:13:11 +0000 Message-Id: <1455264797-2334-10-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455264797-2334-1-git-send-email-eric.auger@linaro.org> References: <1455264797-2334-1-git-send-email-eric.auger@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160212_001443_525629_AE588C0C X-CRM114-Status: GOOD ( 12.06 ) 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: Thomas.Lendacky@amd.com, brijesh.singh@amd.com, patches@linaro.org, Manish.Jaggi@caviumnetworks.com, p.fedin@samsung.com, linux-kernel@vger.kernel.org, Bharat.Bhushan@freescale.com, iommu@lists.linux-foundation.org, pranav.sawargaonkar@gmail.com, leo.duran@amd.com, suravee.suthikulpanit@amd.com, sherry.hurwitz@amd.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=-4.2 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 arm_smmu_unmap_reserved releases all reserved binding resources: destroy all bindings, free iova, free iova_domain. This happens on domain deletion. Signed-off-by: Eric Auger --- drivers/iommu/arm-smmu.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index 9961bfd..ae8a97d 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -363,6 +363,7 @@ struct arm_smmu_reserved_binding { dma_addr_t iova; size_t size; }; +static void arm_smmu_unmap_reserved(struct iommu_domain *domain); static struct iommu_ops arm_smmu_ops; @@ -1057,6 +1058,7 @@ static void arm_smmu_domain_free(struct iommu_domain *domain) * already been detached. */ arm_smmu_destroy_domain_context(domain); + arm_smmu_unmap_reserved(domain); kfree(smmu_domain); } @@ -1547,19 +1549,23 @@ unlock: return ret; } -static void arm_smmu_free_reserved_iova_domain(struct iommu_domain *domain) +static void __arm_smmu_free_reserved_iova_domain(struct arm_smmu_domain *sd) { - struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); - struct iova_domain *iovad = smmu_domain->reserved_iova_domain; + struct iova_domain *iovad = sd->reserved_iova_domain; if (!iovad) return; - mutex_lock(&smmu_domain->reserved_mutex); - put_iova_domain(iovad); kfree(iovad); +} +static void arm_smmu_free_reserved_iova_domain(struct iommu_domain *domain) +{ + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); + + mutex_lock(&smmu_domain->reserved_mutex); + __arm_smmu_free_reserved_iova_domain(smmu_domain); mutex_unlock(&smmu_domain->reserved_mutex); } @@ -1675,6 +1681,24 @@ unlock: mutex_unlock(&smmu_domain->reserved_mutex); } +static void arm_smmu_unmap_reserved(struct iommu_domain *domain) +{ + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); + struct rb_node *node; + + mutex_lock(&smmu_domain->reserved_mutex); + while ((node = rb_first(&smmu_domain->reserved_binding_list))) { + struct arm_smmu_reserved_binding *b = + rb_entry(node, struct arm_smmu_reserved_binding, node); + + while (!kref_put(&b->kref, reserved_binding_release)) + ; + } + smmu_domain->reserved_binding_list = RB_ROOT; + __arm_smmu_free_reserved_iova_domain(smmu_domain); + mutex_unlock(&smmu_domain->reserved_mutex); +} + static struct iommu_ops arm_smmu_ops = { .capable = arm_smmu_capable, .domain_alloc = arm_smmu_domain_alloc,