From patchwork Tue Apr 19 16:56:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 8881891 Return-Path: X-Original-To: patchwork-linux-arm@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 7A7279F1C1 for ; Tue, 19 Apr 2016 16:59:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A5D8820172 for ; Tue, 19 Apr 2016 16:59: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 BD03D2024D for ; Tue, 19 Apr 2016 16:59: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 1asYyl-0002Pr-GM; Tue, 19 Apr 2016 16:58:23 +0000 Received: from mail-wm0-x230.google.com ([2a00:1450:400c:c09::230]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1asYxi-00013V-Jg for linux-arm-kernel@lists.infradead.org; Tue, 19 Apr 2016 16:57:19 +0000 Received: by mail-wm0-x230.google.com with SMTP id e201so21405012wme.0 for ; Tue, 19 Apr 2016 09:56:58 -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=4rmBE8uLq+X0uhfIDiam23+7AqqSkQdmo9koIVa3EPg=; b=WZY06JL8bUQhpRbv4WePDIXwhez1O6R3C/9l6RilOL/RjFvyls9duaP7tqFDja/+2Z cwkcoCaa6EDuCC+U1cYtaLPal5m4cndH6yewZKn4KT62VM857L464bZ7QyPiQm+y6jjd KSze4mNtDXXJyyvMsBxYDjBLfjP2HsvLXihXs= 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=4rmBE8uLq+X0uhfIDiam23+7AqqSkQdmo9koIVa3EPg=; b=nGZnYBhXwGAuaSZmUAoqvA5TQscnky4+bqNZVsn6d3NPjpW0oxBJEFLIaVi/O20mMj iddzZllVMoCVqNxtZ9SU2FWQpebt9ceSMNWIOlRxpA9xOL6Gvc02iZ8ECR9jI22dmdAy zznWoyy7l0OiWNXzCTRyCWrJRrH2wiTI2WBlDkhP94u93z5hUYhaYbHM0pa+/vuDRZXM jKoadvB8Cq89mc5r9VNnooruy2NZ0QlrHScADKgjNhFmK/WRmhU1AJth4lcvqblBw6Zg Zy7YqYYjH6IsMqnb0hXF0xKHs61AH6tvc1lqASlTe/oB6F14usQkFhZywPKjEmgou+fZ uafQ== X-Gm-Message-State: AOPr4FXXUa4j3IiJSWNbQdRJWeKqJ+Dyy2TGBG8Nf/bTbkDJ1b+PazwshEKguj/YmmMlJVIe X-Received: by 10.194.95.40 with SMTP id dh8mr4506743wjb.146.1461085016984; Tue, 19 Apr 2016 09:56:56 -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 x2sm1169329wjr.33.2016.04.19.09.56.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Apr 2016 09:56:55 -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 07/10] iommu/dma-reserved-iommu: delete bindings in iommu_free_reserved_iova_domain Date: Tue, 19 Apr 2016 16:56:31 +0000 Message-Id: <1461084994-2355-8-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461084994-2355-1-git-send-email-eric.auger@linaro.org> References: <1461084994-2355-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_095718_850303_48FBFB9F X-CRM114-Status: GOOD ( 13.17 ) 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 Now reserved bindings can exist, destroy them when destroying the reserved iova domain. iommu_map is not supposed to be atomic, hence the extra complexity in the locking. Signed-off-by: Eric Auger --- v6 -> v7: - remove [PATCH v6 7/7] dma-reserved-iommu: iommu_unmap_reserved and destroy the bindings in iommu_free_reserved_iova_domain v5 -> v6: - use spin_lock instead of mutex v3 -> v4: - previously "iommu/arm-smmu: relinquish reserved resources on domain deletion" --- drivers/iommu/dma-reserved-iommu.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/dma-reserved-iommu.c b/drivers/iommu/dma-reserved-iommu.c index 426d339..2522235 100644 --- a/drivers/iommu/dma-reserved-iommu.c +++ b/drivers/iommu/dma-reserved-iommu.c @@ -157,14 +157,36 @@ void iommu_free_reserved_iova_domain(struct iommu_domain *domain) unsigned long flags; int ret = 0; - spin_lock_irqsave(&domain->reserved_lock, flags); - - rid = (struct reserved_iova_domain *)domain->reserved_iova_cookie; - if (!rid) { - ret = -EINVAL; - goto unlock; + while (1) { + struct iommu_reserved_binding *b; + struct rb_node *node; + dma_addr_t iova; + size_t size; + + spin_lock_irqsave(&domain->reserved_lock, flags); + + rid = (struct reserved_iova_domain *) + domain->reserved_iova_cookie; + if (!rid) { + ret = -EINVAL; + goto unlock; + } + + node = rb_first(&domain->reserved_binding_list); + if (!node) + break; + b = rb_entry(node, struct iommu_reserved_binding, node); + + iova = b->iova; + size = b->size; + + while (!kref_put(&b->kref, reserved_binding_release)) + ; + spin_unlock_irqrestore(&domain->reserved_lock, flags); + iommu_unmap(domain, iova, size); } + domain->reserved_binding_list = RB_ROOT; domain->reserved_iova_cookie = NULL; unlock: spin_unlock_irqrestore(&domain->reserved_lock, flags);