From patchwork Thu Sep 4 16:50:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 36744 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f69.google.com (mail-yh0-f69.google.com [209.85.213.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 299DD20CC4 for ; Thu, 4 Sep 2014 17:09:55 +0000 (UTC) Received: by mail-yh0-f69.google.com with SMTP id v1sf35832565yhn.8 for ; Thu, 04 Sep 2014 10:09:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=mgOJcoFP2aB4GGUB29Dxp8HKcB8d9uMNceTnbNHsQ/w=; b=mW/Vpd9wY/kB2N55xHjMOl59tJKagTdZtfG9J7WZB9ex9Hx3kaIqqxopZyoNJ0RBN8 8EFJWlKNryZ1FmpUdDrCeOAQ4YdN+UIoUpPzeqB6dSw5edxwueahaSUjr/KCN4dGtVWX 3cqBPFU721sQru6oT2U38U5DINbI2BbdZgz4FSzdRSPIXhrBBhl6Po4Knurn0fAVnF7E TBOZIFE8wo53CHluQul79k1B3QjcAQdCydnUbArqlxCqxaycLw8rK6oPZ41n+TmkRLsE EMxB3jpBXjZkZoB23ZqdPS3XxgstaiEqvgQNrDlJCLFHY2vMQVlS7jYQobrq/VOyeQZW M3QA== X-Gm-Message-State: ALoCoQlz9X3n9QXJuTdRxTxpH+i/QxJgYljCesc3k2qKrlddUa0vPf5tPek1Rv/Sg8uEhUTwxJgV X-Received: by 10.52.190.163 with SMTP id gr3mr3176292vdc.3.1409850594907; Thu, 04 Sep 2014 10:09:54 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.20.41 with SMTP id 38ls409132qgi.26.gmail; Thu, 04 Sep 2014 10:09:54 -0700 (PDT) X-Received: by 10.52.170.180 with SMTP id an20mr2324933vdc.89.1409850594705; Thu, 04 Sep 2014 10:09:54 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id yw7si3440912vdb.63.2014.09.04.10.09.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 04 Sep 2014 10:09:54 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.169 as permitted sender) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id hq11so11189457vcb.28 for ; Thu, 04 Sep 2014 10:09:54 -0700 (PDT) X-Received: by 10.52.94.108 with SMTP id db12mr4672948vdb.8.1409850594521; Thu, 04 Sep 2014 10:09:54 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp870517vcb; Thu, 4 Sep 2014 10:09:54 -0700 (PDT) X-Received: by 10.70.49.2 with SMTP id q2mr11060125pdn.28.1409850593951; Thu, 04 Sep 2014 10:09:53 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id h2si4673209pdk.176.2014.09.04.10.09.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Sep 2014 10:09:52 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; 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 1XPaTP-0001Zo-5d; Thu, 04 Sep 2014 17:05:27 +0000 Received: from cam-admin0.cambridge.arm.com ([217.140.96.50]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XPaEh-0002bW-AD for linux-arm-kernel@lists.infradead.org; Thu, 04 Sep 2014 16:50:16 +0000 Received: from edgewater-inn.cambridge.arm.com (edgewater-inn.cambridge.arm.com [10.1.203.34]) by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id s84Gniwo014712; Thu, 4 Sep 2014 17:49:44 +0100 (BST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id C24161AE07F0; Thu, 4 Sep 2014 17:50:08 +0100 (BST) From: Will Deacon To: iommu@lists.linuxfoundation.org Subject: [PATCH 3/7] iommu/arm-smmu: put iommu_domain pointer in dev->archdata.iommu Date: Thu, 4 Sep 2014 17:50:01 +0100 Message-Id: <1409849405-17347-4-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1409849405-17347-1-git-send-email-will.deacon@arm.com> References: <1409849405-17347-1-git-send-email-will.deacon@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140904_095015_750446_8BA0EF8B X-CRM114-Status: GOOD ( 12.49 ) X-Spam-Score: -6.7 (------) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-6.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [217.140.96.50 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.6 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: Will Deacon , tchalamarla@cavium.com, robin.murphy@arm.com, joro@8bytes.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: will.deacon@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.169 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 In preparation for nested translation support, stick a pointer to the iommu_domain in dev->archdata.iommu. This makes it much easier to grab hold of the physical group configuration (e.g. cbndx) when dealing with vSMMU accesses from a guest. Signed-off-by: Will Deacon --- drivers/iommu/arm-smmu.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index ef6623dbba9a..7ab3cc4ffbb3 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -1206,6 +1206,11 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) return -ENXIO; } + if (dev->archdata.iommu) { + dev_err(dev, "already attached to IOMMU domain\n"); + return -EEXIST; + } + /* * Sanity check the domain. We don't support domains across * different SMMUs. @@ -1232,7 +1237,10 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) if (!cfg) return -ENODEV; - return arm_smmu_domain_add_master(smmu_domain, cfg); + ret = arm_smmu_domain_add_master(smmu_domain, cfg); + if (!ret) + dev->archdata.iommu = domain; + return ret; } static void arm_smmu_detach_dev(struct iommu_domain *domain, struct device *dev) @@ -1241,8 +1249,11 @@ static void arm_smmu_detach_dev(struct iommu_domain *domain, struct device *dev) struct arm_smmu_master_cfg *cfg; cfg = find_smmu_master_cfg(dev); - if (cfg) - arm_smmu_domain_remove_master(smmu_domain, cfg); + if (!cfg) + return; + + dev->archdata.iommu = NULL; + arm_smmu_domain_remove_master(smmu_domain, cfg); } static bool arm_smmu_pte_is_contiguous_range(unsigned long addr,