From patchwork Mon Feb 27 19:54:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 9593873 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E08CC60471 for ; Mon, 27 Feb 2017 19:59:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D001C28491 for ; Mon, 27 Feb 2017 19:59:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4B072849E; Mon, 27 Feb 2017 19:59:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6CD3E28491 for ; Mon, 27 Feb 2017 19:59:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=tRACS499k3HfvqSu5biCumwSruap1Bh1vMG29YYZR9E=; b=PlYs7m4nfXKzyvlCBlJBljZ7jF 8udh9GOeY7sl2uUXzxF/IB1b6StntOGNFGy/0xCaC0TppGFAvgCItzRe9GaVBYW5iEE5HNr0JOrhk ZdlcsRmGsSNgxJSU6gwBV56AnjLTGV3WgYW/L6YwWkLNoZobNGReIQ6xdOk28MXvpqzAh8CWM79xj 37Py9MxtxwbWO8N4opzMSU6L/I2daNeXuSx+SfQqaC677jR97dO/AQyU6gUbyX7Vz9V94FCsqyiq8 zT/8Dip9BL0AskrjT53nrnme5iRiRGeoBpkUedKG3x+OVTa9xpcsS+cZ+iNLkpRf5Oj7aeKLSs2T3 KoVJFXSg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ciRSA-00009o-QW; Mon, 27 Feb 2017 19:59:26 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ciRR4-0007t7-4x for linux-arm-kernel@lists.infradead.org; Mon, 27 Feb 2017 19:58:22 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7853D687; Mon, 27 Feb 2017 11:58:01 -0800 (PST) Received: from e106794-lin.cambridge.arm.com (e106794-lin.cambridge.arm.com [10.1.210.60]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id CE2153F3E1; Mon, 27 Feb 2017 11:57:58 -0800 (PST) From: Jean-Philippe Brucker To: Subject: [RFC PATCH 02/30] iommu/arm-smmu-v3: Link groups and domains Date: Mon, 27 Feb 2017 19:54:13 +0000 Message-Id: <20170227195441.5170-3-jean-philippe.brucker@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170227195441.5170-1-jean-philippe.brucker@arm.com> References: <20170227195441.5170-1-jean-philippe.brucker@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170227_115818_350124_98044D8B X-CRM114-Status: GOOD ( 14.84 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lorenzo Pieralisi , Shanker Donthineni , kvm@vger.kernel.org, Catalin Marinas , Joerg Roedel , Sinan Kaya , Will Deacon , iommu@lists.linux-foundation.org, Harv Abdulhamid , Alex Williamson , linux-pci@vger.kernel.org, Bjorn Helgaas , Robin Murphy , David Woodhouse , linux-arm-kernel@lists.infradead.org, Nate Watterson MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP When removing a mapping from a domain, we need to send an invalidation to all of devices that might have stored it in their Address Translation Cache (ATC). This requires a lookup from smmu_domain to smmu_group. Add a list of groups in each domain. Although this domain-group link is already protected by iommu_group->mutex, the domain-to-group lookup will be done outside of the sections protected by that mutex. Add a spinlock for this case. Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/arm-smmu-v3.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index ce8b68fe254b..69d00416990d 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -651,9 +651,15 @@ struct arm_smmu_domain { }; struct iommu_domain domain; + + struct list_head groups; + spinlock_t groups_lock; }; struct arm_smmu_group { + struct arm_smmu_domain *domain; + struct list_head domain_head; + struct list_head devices; spinlock_t devices_lock; }; @@ -1408,6 +1414,9 @@ static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) mutex_init(&smmu_domain->init_mutex); spin_lock_init(&smmu_domain->pgtbl_lock); + INIT_LIST_HEAD(&smmu_domain->groups); + spin_lock_init(&smmu_domain->groups_lock); + return &smmu_domain->domain; } @@ -1641,6 +1650,7 @@ static void arm_smmu_detach_dev(struct device *dev) static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) { int ret = 0; + unsigned long flags; struct iommu_group *group; struct arm_smmu_device *smmu; struct arm_smmu_group *smmu_group; @@ -1666,9 +1676,31 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) return -ENOMEM; } - /* Already attached to a different domain? */ - if (!ste->bypass) + /* + * Already attached to a different domain? This happens when we're + * switching from default domain to unmanaged domain, and back. We + * assume here that, when switching from old domain to new domain, old + * domain doesn't have any live mapping anymore. This is an important + * requirement because here we remove the group-domain link when we + * re-attach the first device in a group. Other devices in that group + * might still be attached to the old domain, and will be reattached in + * a moment. + * + * We also take this path when attaching for the very first time, just + * after the STE is initialized. + */ + if (!ste->bypass) { + struct arm_smmu_domain *other_domain = smmu_group->domain; + + if (other_domain) { + spin_lock_irqsave(&other_domain->groups_lock, flags); + list_del(&smmu_group->domain_head); + spin_unlock_irqrestore(&other_domain->groups_lock, flags); + + smmu_group->domain = NULL; + } arm_smmu_detach_dev(dev); + } mutex_lock(&smmu_domain->init_mutex); @@ -1688,6 +1720,14 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) goto out_unlock; } + if (!smmu_group->domain) { + smmu_group->domain = smmu_domain; + + spin_lock_irqsave(&smmu_domain->groups_lock, flags); + list_add(&smmu_group->domain_head, &smmu_domain->groups); + spin_unlock_irqrestore(&smmu_domain->groups_lock, flags); + } + ste->bypass = false; ste->valid = true;