From patchwork Thu Feb 11 14:34:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 8281061 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B89FD9F3CD for ; Thu, 11 Feb 2016 14:39:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 40DED2035D for ; Thu, 11 Feb 2016 14:39:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 47B172009C for ; Thu, 11 Feb 2016 14:39:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751334AbcBKOjP (ORCPT ); Thu, 11 Feb 2016 09:39:15 -0500 Received: from mail-wm0-f42.google.com ([74.125.82.42]:38021 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752369AbcBKOfa (ORCPT ); Thu, 11 Feb 2016 09:35:30 -0500 Received: by mail-wm0-f42.google.com with SMTP id p63so71006413wmp.1 for ; Thu, 11 Feb 2016 06:35:29 -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=GKy2Q7yLU/X894uLREwVStp6QZwEY9qEUn7XgWS3ndYQ0BC5jAxy9HoYzcxzV7cOWv 3Jn54H/FtD9rg4ovMdBUcyL0tt4GccTIUNJEjsq1655TSTW6ady4JRiTW4mCX12v1M/6 Fw+ZDAvBkm/vhX2tB2UkoIY2ceYD2Nhk8e2Q8= 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=SqHe4VrKQcA9NbeJRPvNHas2Qw9pliq2jfT4/1RhFZWCAEYtbRkXkmEK/CxiYlE/Sv 1F+xa95XmCgIsztJr+muqIeCQCC6xCFJyHrEuC0zrQAtgbh5ihJdQHs4/HzAz4KfO4ct 84tF3Xk0dIKBj5J6YDRhGKsHZkmYYiRxueyODT3x/GKZ5Msb6h4ogvKEQxMQd7Kme3Tl gOY0qU6LCl2IRv6IFJfU84bUA/1Dsdx2uB9PoFM91soB93wHHd8CyldZm3FdtSV7LP7i js5VwVauGWBdMgW5taTyFG8nRgxjWyXf2HNLoRa7+krauwDA1b6CGoryPC+yX/fYyxoF 8CgQ== X-Gm-Message-State: AG10YOTlFMBsDM0S6o1QPDC1kd7G/OxnH4IOTZWVPcEoAgAhJa2sKz9G6oRnnkHNR3wSRRhP X-Received: by 10.28.9.67 with SMTP id 64mr18318249wmj.10.1455201329302; Thu, 11 Feb 2016 06:35:29 -0800 (PST) Received: from new-host-12.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id t205sm8290751wmt.23.2016.02.11.06.35.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Feb 2016 06:35:27 -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 Cc: suravee.suthikulpanit@amd.com, patches@linaro.org, linux-kernel@vger.kernel.org, Manish.Jaggi@caviumnetworks.com, Bharat.Bhushan@freescale.com, pranav.sawargaonkar@gmail.com, p.fedin@samsung.com, iommu@lists.linux-foundation.org, sherry.hurwitz@amd.com, brijesh.singh@amd.com, leo.duran@amd.com, Thomas.Lendacky@amd.com Subject: [RFC v2 09/15] iommu/arm-smmu: relinquish reserved resources on domain deletion Date: Thu, 11 Feb 2016 14:34:16 +0000 Message-Id: <1455201262-5259-10-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455201262-5259-1-git-send-email-eric.auger@linaro.org> References: <1455201262-5259-1-git-send-email-eric.auger@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,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,