From patchwork Fri Sep 14 14:30:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 146707 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp780321ljw; Fri, 14 Sep 2018 07:30:46 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZNxhlnXq3Od0m4Ul+U6eoTyXuOxmYa/fsGiECFqncYVeJnDLhOPRalK1yS+RYassKA/WXA X-Received: by 2002:a17:902:4d45:: with SMTP id o5-v6mr12629273plh.78.1536935446613; Fri, 14 Sep 2018 07:30:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536935446; cv=none; d=google.com; s=arc-20160816; b=sMiKS6TCiy6LN26VjrxBJkrZCHJX43X4jfcOOeGIoGL9wX5iz7FyPATAE0vSPFFoUM 8YUh625BSpJrPP+2YCUf7RpsYoyajJF4GwRlRzQ46I0mRxVbNJs5oEtXo83X/je19Jnu eW1Oibt1rHikqpnZPfc3Mp5AO3Iih+bRsXlVAoRBsiDsCSmrJFdvVOPhz9F3Um5239L+ NkwH6Trd8MavBCot91h33MAG8ta/5fwaYmy+iNBcEwlGPgyF6QC8bYa6LmDYAJf5kDiG aHe9sVXxH/JU0Uu/JQeYVnDVnty66EakGrRkAjUafxmFZScD0+OKHPtwM1ZGgMDNCv9O +wZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+4Q4y4nXIVpXOHQZ8EUOiPgBXMMYeLBvHy0quzyKhu0=; b=Hb5yNNyzm5rEQaY/RYwhv3RFUBhdfqoWn7GN4JKk2y8TA8nmytgRXsvu8nT1qxVXlA iPAruiMa0HFP7TKmbdrn0XDOALfBnsYI93h3Ws7ETq263XnV0XgmVGdR5omarNehR1jw 9cjv1r9B1RNG7USB+m0z/kCmnNwIqRWCQA3c0rELTxa+TdmIYJHJi0I+wdNyVKt98KaH FGtLP811N5C1bMjzzmGrf04UAee5Q27V2y3oYIy6hpyWtnrYuJVbYCszQY1UFnbJfhXD CkorEAF0vYuCign/QkuBRzj9EZDgA+k7tzF64h74kHlJdaIXi4/rorguBctU5Yt63yYu 4EZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m10-v6si7711260pgc.105.2018.09.14.07.30.46; Fri, 14 Sep 2018 07:30:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728349AbeINTpa (ORCPT + 32 others); Fri, 14 Sep 2018 15:45:30 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:34248 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726902AbeINTp2 (ORCPT ); Fri, 14 Sep 2018 15:45:28 -0400 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 27DC01650; Fri, 14 Sep 2018 07:30:43 -0700 (PDT) Received: from e110467-lin.cambridge.arm.com (e110467-lin.emea.arm.com [10.4.12.131]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5DE173F575; Fri, 14 Sep 2018 07:30:41 -0700 (PDT) From: Robin Murphy To: joro@8bytes.org, will.deacon@arm.com, thunder.leizhen@huawei.com, iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: linuxarm@huawei.com, guohanjun@huawei.com, huawei.libin@huawei.com, john.garry@huawei.com Subject: [PATCH v7 5/6] iommu/arm-smmu-v3: Add support for non-strict mode Date: Fri, 14 Sep 2018 15:30:23 +0100 Message-Id: <4f9444c7224ea0e6e4cef8ddbf77bb5292a383e3.1536935328.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.19.0.dirty In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhen Lei Dynamically choose strict or non-strict mode for page table config based on the iommu domain type. Signed-off-by: Zhen Lei [rm: convert to domain attribute] Signed-off-by: Robin Murphy --- drivers/iommu/arm-smmu-v3.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) -- 2.19.0.dirty diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index f10c852479fc..7bbfa5f7ce8e 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -612,6 +612,7 @@ struct arm_smmu_domain { struct mutex init_mutex; /* Protects smmu pointer */ struct io_pgtable_ops *pgtbl_ops; + bool non_strict; enum arm_smmu_domain_stage stage; union { @@ -1633,6 +1634,9 @@ static int arm_smmu_domain_finalise(struct iommu_domain *domain) if (smmu->features & ARM_SMMU_FEAT_COHERENCY) pgtbl_cfg.quirks = IO_PGTABLE_QUIRK_NO_DMA; + if (smmu_domain->non_strict) + pgtbl_cfg.quirks |= IO_PGTABLE_QUIRK_NON_STRICT; + pgtbl_ops = alloc_io_pgtable_ops(fmt, &pgtbl_cfg, smmu_domain); if (!pgtbl_ops) return -ENOMEM; @@ -1934,13 +1938,17 @@ static int arm_smmu_domain_get_attr(struct iommu_domain *domain, { struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); - if (domain->type != IOMMU_DOMAIN_UNMANAGED) - return -EINVAL; - switch (attr) { case DOMAIN_ATTR_NESTING: + if (domain->type != IOMMU_DOMAIN_UNMANAGED) + return -EINVAL; *(int *)data = (smmu_domain->stage == ARM_SMMU_DOMAIN_NESTED); return 0; + case DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE: + if (domain->type != IOMMU_DOMAIN_DMA) + return -EINVAL; + *(int *)data = smmu_domain->non_strict; + return 0; default: return -ENODEV; } @@ -1952,13 +1960,15 @@ static int arm_smmu_domain_set_attr(struct iommu_domain *domain, int ret = 0; struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); - if (domain->type != IOMMU_DOMAIN_UNMANAGED) - return -EINVAL; - mutex_lock(&smmu_domain->init_mutex); switch (attr) { case DOMAIN_ATTR_NESTING: + if (domain->type != IOMMU_DOMAIN_UNMANAGED) { + ret = -EINVAL; + goto out_unlock; + } + if (smmu_domain->smmu) { ret = -EPERM; goto out_unlock; @@ -1969,6 +1979,14 @@ static int arm_smmu_domain_set_attr(struct iommu_domain *domain, else smmu_domain->stage = ARM_SMMU_DOMAIN_S1; + break; + case DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE: + if (domain->type != IOMMU_DOMAIN_DMA) { + ret = -EINVAL; + goto out_unlock; + } + + smmu_domain->non_strict = *(int *)data; break; default: ret = -ENODEV;