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: Auger Eric X-Patchwork-Id: 66118 Delivered-To: patches@linaro.org Received: by 10.140.93.198 with SMTP id d64csp1968797qge; Tue, 19 Apr 2016 09:57:04 -0700 (PDT) X-Received: by 10.28.30.86 with SMTP id e83mr4511081wme.18.1461085017306; Tue, 19 Apr 2016 09:56:57 -0700 (PDT) Return-Path: Received: from mail-wm0-x229.google.com (mail-wm0-x229.google.com. [2a00:1450:400c:c09::229]) by mx.google.com with ESMTPS id bz1si1180199wjb.84.2016.04.19.09.56.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Apr 2016 09:56:57 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::229 as permitted sender) client-ip=2a00:1450:400c:c09::229; 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::229 as permitted sender) smtp.mailfrom=eric.auger@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-wm0-x229.google.com with SMTP id l6so29577656wml.1 for ; Tue, 19 Apr 2016 09:56:57 -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=Vh4bWkXH7SlFg1pfjNYPJ4nrHX1XamExa6lvDmO68ky9j2RseQWxSVvo00d9dPH8pu 3ZhTHNtF2dUKjorAErhgJYs1+5E4pvC/kZWqtu8Yg/MIK7lQwBdypxta+OoE7Kn9hyDe rDizFS7eXC5S5HE7pOLhvj6uzQNywIsnb3J6uM+GeUWbNajqzJJcNczcqNmqkHrz7Rpq LokZug3Bnueh9IetC62I6tb6ElEpeR/tCqn7b3Wu+H1Syl2R9ZvOxfN3NNqHnsxigbve ZJ7qNngTMdQmGcOhnR7L6jjYy+GMby/FiRW/PDtSMyG6fgqD9C3+NagrP8u33M1qhmQ4 SmiQ== X-Gm-Message-State: AOPr4FXPhCSDVQDZOue11ywQlAh924VTWs0W89OpMopCheYKU5BwwC0/kCyycDUKYhwxG6tm2IY= X-Received: by 10.194.95.40 with SMTP id dh8mr4506743wjb.146.1461085016984; Tue, 19 Apr 2016 09:56:56 -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 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 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 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> 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(-) -- 1.9.1 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);