From patchwork Thu May 31 07:42:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 137336 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp6278344lji; Thu, 31 May 2018 00:44:16 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJbh0fN1663YLRV4ZDBcouKwVb/aLqdavOjgArmrC80r3kRx0c9acYd5KxUok27OL5UAzpe X-Received: by 2002:a62:f5da:: with SMTP id b87-v6mr2025316pfm.113.1527752655994; Thu, 31 May 2018 00:44:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527752655; cv=none; d=google.com; s=arc-20160816; b=KkKhDs+O2B7Fh/6gr0xqBowDaCoC6ZytrtXteDL4BFZEVfZeGIHzKbJXYzWisSg+QC KCcNrvlGfB7migJ0dIHzJpn3IyD5KvMpbXxHW4ytAd3HQxhdVEjwQIGxtqWngeTRko0R 35krwivIKVrBsUlzh5Y2KVJa4BVq6I0ByJ7M8KxzOF6c4d3FYyrsSxRF+hcLowFHNb8y I/bnZpCh3sHg9JUNvdjrV3ie7It5GfNWyZehBvrYfnNh9GUqCtdyI9CZJC0mBfHxdTP0 nvPWOoctdazgR6PuC713ARkhakWqDGZBp3hIgxxQPh6JpcDMi1oOpWUlem4pC2o390Nb 4YBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=Tm0ss8UIDBPWxeADwEuvJz1008Q0BI4rUIiYniD1Ylg=; b=xj/316aEiYFSP+jATfhjjmcM7fj+NlDM+ePvNNCe5p1QEtD9m1rS/KAEuV/Od1bkIA gYyMyZ1A2qiVOh2FXBGLSVYDSGx0XPS7k3Ftdle4sMyyDhjYk05kmv18lS0EHhdgw+Q1 1J4jyeu2kCn5PC+tvvGqZDTZtXJlAL6Sgn/rTZ6U5TVFUTjbtLnwOnVLa1SHDeDu3U3z 1+QgHK/Jr4FM8Al9+kKXa0SUjOYFlkjz/fzqVfkq44+Q/YwjPXEbZyKGxVC4uJcErvRP FMs+JOdHFv4mkAr7gdJUGn0sUeA9G5gVhjWcUK5WjlOEresDPOdNtPMcLqkaCV57NUW0 Xy5Q== 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 8-v6si37259303plc.444.2018.05.31.00.44.15; Thu, 31 May 2018 00:44:15 -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 S1754154AbeEaHoO (ORCPT + 30 others); Thu, 31 May 2018 03:44:14 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:8213 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754126AbeEaHn7 (ORCPT ); Thu, 31 May 2018 03:43:59 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id E533B396C8E89; Thu, 31 May 2018 15:43:44 +0800 (CST) Received: from localhost (10.177.23.164) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.382.0; Thu, 31 May 2018 15:43:36 +0800 From: Zhen Lei To: Robin Murphy , Will Deacon , Matthias Brugger , Rob Clark , Joerg Roedel , linux-mediatek , linux-arm-msm , linux-arm-kernel , iommu , linux-kernel CC: Zhen Lei , Hanjun Guo , Libin , Guozhu Li , "Xinwei Hu" Subject: [PATCH 6/7] iommu/io-pgtable-arm: add support for non-strict mode Date: Thu, 31 May 2018 15:42:48 +0800 Message-ID: <1527752569-18020-7-git-send-email-thunder.leizhen@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1527752569-18020-1-git-send-email-thunder.leizhen@huawei.com> References: <1527752569-18020-1-git-send-email-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.23.164] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To support the non-strict mode, now we only tlbi and sync for the strict mode. But for the non-leaf case, always follow strict mode. Signed-off-by: Zhen Lei --- drivers/iommu/io-pgtable-arm.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) -- 1.8.3 diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index e0f52db..1a65b7b 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -287,7 +287,7 @@ static void __arm_lpae_set_pte(arm_lpae_iopte *ptep, arm_lpae_iopte pte, static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data, unsigned long iova, size_t size, int lvl, - arm_lpae_iopte *ptep); + arm_lpae_iopte *ptep, int strict); static void __arm_lpae_init_pte(struct arm_lpae_io_pgtable *data, phys_addr_t paddr, arm_lpae_iopte prot, @@ -329,7 +329,7 @@ static int arm_lpae_init_pte(struct arm_lpae_io_pgtable *data, size_t sz = ARM_LPAE_BLOCK_SIZE(lvl, data); tblp = ptep - ARM_LPAE_LVL_IDX(iova, lvl, data); - if (WARN_ON(__arm_lpae_unmap(data, iova, sz, lvl, tblp) != sz)) + if (WARN_ON(__arm_lpae_unmap(data, iova, sz, lvl, tblp, IOMMU_STRICT) != sz)) return -EINVAL; } @@ -526,7 +526,7 @@ static void arm_lpae_free_pgtable(struct io_pgtable *iop) static size_t arm_lpae_split_blk_unmap(struct arm_lpae_io_pgtable *data, unsigned long iova, size_t size, arm_lpae_iopte blk_pte, int lvl, - arm_lpae_iopte *ptep) + arm_lpae_iopte *ptep, int strict) { struct io_pgtable_cfg *cfg = &data->iop.cfg; arm_lpae_iopte pte, *tablep; @@ -571,15 +571,17 @@ static size_t arm_lpae_split_blk_unmap(struct arm_lpae_io_pgtable *data, } if (unmap_idx < 0) - return __arm_lpae_unmap(data, iova, size, lvl, tablep); + return __arm_lpae_unmap(data, iova, size, lvl, tablep, strict); + + if (strict) + io_pgtable_tlb_add_flush(&data->iop, iova, size, size, true); - io_pgtable_tlb_add_flush(&data->iop, iova, size, size, true); return size; } static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data, unsigned long iova, size_t size, int lvl, - arm_lpae_iopte *ptep) + arm_lpae_iopte *ptep, int strict) { arm_lpae_iopte pte; struct io_pgtable *iop = &data->iop; @@ -604,7 +606,7 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data, io_pgtable_tlb_sync(iop); ptep = iopte_deref(pte, data); __arm_lpae_free_pgtable(data, lvl + 1, ptep); - } else { + } else if (strict) { io_pgtable_tlb_add_flush(iop, iova, size, size, true); } @@ -615,12 +617,12 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data, * minus the part we want to unmap */ return arm_lpae_split_blk_unmap(data, iova, size, pte, - lvl + 1, ptep); + lvl + 1, ptep, strict); } /* Keep on walkin' */ ptep = iopte_deref(pte, data); - return __arm_lpae_unmap(data, iova, size, lvl + 1, ptep); + return __arm_lpae_unmap(data, iova, size, lvl + 1, ptep, strict); } static size_t arm_lpae_unmap(struct io_pgtable_ops *ops, unsigned long iova, @@ -633,7 +635,7 @@ static size_t arm_lpae_unmap(struct io_pgtable_ops *ops, unsigned long iova, if (WARN_ON(iova >= (1ULL << data->iop.cfg.ias))) return 0; - return __arm_lpae_unmap(data, iova, size, lvl, ptep); + return __arm_lpae_unmap(data, iova, size, lvl, ptep, strict); } static phys_addr_t arm_lpae_iova_to_phys(struct io_pgtable_ops *ops, From patchwork Thu May 31 07:42:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 137335 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp6278128lji; Thu, 31 May 2018 00:44:02 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLQXy1FG13QTBx2h5CT5rZ65Z1RtiNNWS/7YJzRux3/j0S5PrZnU7MSsrnAVICeolbvyC/P X-Received: by 2002:a62:aa18:: with SMTP id e24-v6mr5733627pff.107.1527752641965; Thu, 31 May 2018 00:44:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527752641; cv=none; d=google.com; s=arc-20160816; b=gTWrljcn2nSWw93uKWNQVZXHsjIwf6EOVx3S+7eSTe2VV4FeN3ukmA7ALgAgeqUOom w3pkxhMXTy+5nkaY2yxaD80wgHGXqyg9zPttXh403MrVDz9SHqvfEbF8KgIAJC1EvJcI WE80aLrTpni7g395IbvPuEOKfLeoJ7rVd3r8p29r5lVdiTYC18m33HnlwljK+zGdIVsb DK1UKU5PVmOrOdN4B7mlZzO96VRSxDyb6waNIzI+E1Jpn7jF3pUjfPRhiTHfyXgYW44s 7iRTbYgLDHTCIp55Nu/qWI/2IBgn3jTScgluMAAgD8tbbhhbC4542E3YyRTCk3ASTq3b 8dVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=BZVIf6Mn+4Tswr/KHTsmOTpFMVpQb/Ax57Q7oMvGtmg=; b=VGpSe+7A6UhXdxRJZ6WkF7oIqNxBIOke7ALHNn2ierxSimm2e9hQ7dM77L4DUY6mZF 9+U+yf/JjnwHykhkoMdx1q7ekO9F7jgZpLGiukUoHDqVdD4hrHBNh9/yzOxIkvdpTt18 cfZKKyrV9oxgqVFIxcKsYBtxm8/Dbu6+eMHRz+ZRpumU+onDik8Ie2UMh7THjtO/PNwj YBoWoCf5GLZI5YoiC9sLalt/ip47+3JXB5aj0JQqcg97LoKcVdeKS8rUTOvDes4KZTn5 aeTc7j3xWkraCVFg8zAQuNKdeXH3nzbA9w0eaLndlKt39STd2TZ81FDsHRH1OvCvYwYe Noxg== 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 r11-v6si28682529pgp.235.2018.05.31.00.44.01; Thu, 31 May 2018 00:44:01 -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 S1754141AbeEaHoA (ORCPT + 30 others); Thu, 31 May 2018 03:44:00 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:8212 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754076AbeEaHn5 (ORCPT ); Thu, 31 May 2018 03:43:57 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 0844FEA061686; Thu, 31 May 2018 15:43:43 +0800 (CST) Received: from localhost (10.177.23.164) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.382.0; Thu, 31 May 2018 15:43:37 +0800 From: Zhen Lei To: Robin Murphy , Will Deacon , Matthias Brugger , Rob Clark , Joerg Roedel , linux-mediatek , linux-arm-msm , linux-arm-kernel , iommu , linux-kernel CC: Zhen Lei , Hanjun Guo , Libin , Guozhu Li , "Xinwei Hu" Subject: [PATCH 7/7] iommu/arm-smmu-v3: add support for non-strict mode Date: Thu, 31 May 2018 15:42:49 +0800 Message-ID: <1527752569-18020-8-git-send-email-thunder.leizhen@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1527752569-18020-1-git-send-email-thunder.leizhen@huawei.com> References: <1527752569-18020-1-git-send-email-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.23.164] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 1. Add IOMMU_CAP_NON_STRICT capability. 2. Dynamic choose strict or non-strict mode base on the iommu domain type. Signed-off-by: Zhen Lei --- drivers/iommu/arm-smmu-v3.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) -- 1.8.3 diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index 59b3387..25bccbd 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -1440,6 +1440,8 @@ static bool arm_smmu_capable(enum iommu_cap cap) return true; case IOMMU_CAP_NOEXEC: return true; + case IOMMU_CAP_NON_STRICT: + return true; default: return false; } @@ -1767,7 +1769,7 @@ static int arm_smmu_map(struct iommu_domain *domain, unsigned long iova, if (!ops) return 0; - return ops->unmap(ops, iova, size, IOMMU_STRICT); + return ops->unmap(ops, iova, size, IOMMU_DOMAIN_IS_STRICT(domain)); } static void arm_smmu_flush_iotlb_all(struct iommu_domain *domain) @@ -1782,7 +1784,7 @@ static void arm_smmu_iotlb_sync(struct iommu_domain *domain) { struct arm_smmu_device *smmu = to_smmu_domain(domain)->smmu; - if (smmu) + if (smmu && IOMMU_DOMAIN_IS_STRICT(domain)) __arm_smmu_tlb_sync(smmu); }