From patchwork Sun Jun 10 11:07:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 138188 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2892910lji; Sun, 10 Jun 2018 04:09:02 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKdQuWykiz6HzZi21Uz0+usF3sM5BzE6jxi3deYbScp+0VH1DuHTScTkLvovWyjybNnZ8pJ X-Received: by 2002:a17:902:9309:: with SMTP id bc9-v6mr14159057plb.189.1528628942174; Sun, 10 Jun 2018 04:09:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528628942; cv=none; d=google.com; s=arc-20160816; b=BUGFmhRJPGfZIoxoSim2jwd2b5Th6YDY9IDXsxzFtfbcNYxA4xjVDMNWOW1hVROAH6 0CfjZQ1twEseojqB8HwW3QNWkpooEmc0RVWs5/3hUpEN3hFWV8owlyyww+jM8sCgKBxR xRDlE3cTn4SyLC5MijcEv5HQSaetFxVuEc9GgNTD3XrQX2qpQfX6aap6VjqVUJzQM1Kp Wff0xJDUvBQPSS1Izh8asK/e8K37JkyOo7J+g9U/TMZTQTIg9uE3+ad7xveXhaYLdwlf 1q3QJL7SsgZoL7LbVS/4GHm38g8/aRLe8ubKJQCa6zxQlzIO/tbbpcnrdc9xE7iQJa5p zSbA== 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=I/2axhcNhjsdRlubO+OmbKAV1yFMjMZQpt9UX5MkvFk=; b=XWHJekgXKTwomeroRHwFoHrvrARwCiLtcyiQXCQWZDhnOChu1GrF4Hq85OwSPsCI90 xBtpt4w9yJFgO1mrPC4AZZdQ89icN91wBC3adGnAcEeKkdJQM6/TFVvDved8ZwVOCJ/k KL5zxFJqtRZnX2AZlbGse+IO46lX5e5JWcjr/w8rAU7H7eZKBbSfF3eopCL58zcCYwHD TjM0JnB9yWKai5/7W8wLFMDKKemBk3bt1qilX8cYKjsxy6qqp6v0tc9Q0OszP0dc7KHD oOtwUCY3EKSkiiOLr8ZJtlwK/MfJb7Gz63k/Ar7zyjjd1zeHbv54Dy8YitB0D/rM9miq WbqA== 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 q1-v6si26580971pgs.441.2018.06.10.04.09.01; Sun, 10 Jun 2018 04:09:02 -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 S1753962AbeFJLI6 (ORCPT + 30 others); Sun, 10 Jun 2018 07:08:58 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:8656 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753944AbeFJLI4 (ORCPT ); Sun, 10 Jun 2018 07:08:56 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 98F985C7C3BC4; Sun, 10 Jun 2018 19:08:31 +0800 (CST) Received: from localhost (10.177.23.164) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.382.0; Sun, 10 Jun 2018 19:08:23 +0800 From: Zhen Lei To: Robin Murphy , Will Deacon , Joerg Roedel , iommu , linux-kernel CC: Zhen Lei , Hanjun Guo , Libin , Guozhu Li , "Xinwei Hu" Subject: [PATCH v2 1/5] iommu/arm-smmu-v3: fix the implementation of flush_iotlb_all hook Date: Sun, 10 Jun 2018 19:07:19 +0800 Message-ID: <1528628843-10280-2-git-send-email-thunder.leizhen@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1528628843-10280-1-git-send-email-thunder.leizhen@huawei.com> References: <1528628843-10280-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 .flush_iotlb_all can not just wait for previous tlbi operations to be completed, but should also invalid all TLBs of the related domain. Signed-off-by: Zhen Lei --- drivers/iommu/arm-smmu-v3.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) -- 1.8.3 diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index 1d64710..4402187 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -1770,6 +1770,14 @@ static int arm_smmu_map(struct iommu_domain *domain, unsigned long iova, return ops->unmap(ops, iova, size); } +static void arm_smmu_flush_iotlb_all(struct iommu_domain *domain) +{ + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); + + if (smmu_domain->smmu) + arm_smmu_tlb_inv_context(smmu_domain); +} + static void arm_smmu_iotlb_sync(struct iommu_domain *domain) { struct arm_smmu_device *smmu = to_smmu_domain(domain)->smmu; @@ -1998,7 +2006,7 @@ static void arm_smmu_put_resv_regions(struct device *dev, .map = arm_smmu_map, .unmap = arm_smmu_unmap, .map_sg = default_iommu_map_sg, - .flush_iotlb_all = arm_smmu_iotlb_sync, + .flush_iotlb_all = arm_smmu_flush_iotlb_all, .iotlb_sync = arm_smmu_iotlb_sync, .iova_to_phys = arm_smmu_iova_to_phys, .add_device = arm_smmu_add_device, From patchwork Sun Jun 10 11:07:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 138190 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2893638lji; Sun, 10 Jun 2018 04:09:56 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIZ+CKuU+hxnF23jJzU6pMcUgjYXuk9Pt+FkIX32KtGdItmRrJi2HUVtWhfYRvsFo6mx2QW X-Received: by 2002:a63:2bc4:: with SMTP id r187-v6mr11267406pgr.231.1528628996499; Sun, 10 Jun 2018 04:09:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528628996; cv=none; d=google.com; s=arc-20160816; b=mWWPuMVN2vA4vJXh6qd0+uUh34UH3sTGah6NN/Ev0dd0mU21RyHpRozDhr0rNnDJVB /pv+HEyhrTtF6ypBi1yuQk5HYU91JBNV0K0gu88loLS9VTImjvJkAv/ppZK24b0PWCJN EJ+YfLOtsVUX0HgmSpiGi2rWlwfg/yyoteArhuuZrWlqc7VUbhARn3cs5NICvXfzPon1 pyWxFibeACc1CZ4Ig8jWLJ+uQbd2BJU+G5Jgo+9Tm28HYtqYgZfxoHWcNiO0SOT6Hhn/ EL9klC9YxNzgM2orgDglDb24lmo4T2YyuGmxr2wFUTU2BskEyOk9nJ6kxzm/DLJp+2W+ egGA== 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=SQEPjNAL1wrnxESpn8g8Uz57dtH825joF34k+kCA8UA=; b=gFvppNWkEUyCaBYtHXMzVjMUf/eiCGeYQI/w/ywSIJ/gXobk/TQrT/jfhbhcbgsECJ dyc96UOH49k6Sz6mBdeQcmy1NoMEYkairuUWsYEcgSICG5u/EW+8YCklr2HUuubyW3Eu gNsDr/JYSd9ZNHzXzobCOg/7jTHBu2Mxoi7wkytnW+7KhqXwHUdX9GTXeoTTwfPJl7aB 5cnN8PaGbFQgtCztkYLeof4f6mPuZNrsvciZZOg140fksz50B3zZ9a5iF+1ZRGytBEtO obUQYm6WhPcOY5CKm9CHmSMlD4nUGOCVni4HHzx5SHAw9sv4TEsl/Uf51RRcZpRexhvd Kfbg== 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 p25-v6si35534729pfi.345.2018.06.10.04.09.56; Sun, 10 Jun 2018 04:09:56 -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 S1754000AbeFJLJx (ORCPT + 30 others); Sun, 10 Jun 2018 07:09:53 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:35222 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753877AbeFJLIg (ORCPT ); Sun, 10 Jun 2018 07:08:36 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 15ADC5C677746; Sun, 10 Jun 2018 19:08:33 +0800 (CST) Received: from localhost (10.177.23.164) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.382.0; Sun, 10 Jun 2018 19:08:23 +0800 From: Zhen Lei To: Robin Murphy , Will Deacon , Joerg Roedel , iommu , linux-kernel CC: Zhen Lei , Hanjun Guo , Libin , Guozhu Li , "Xinwei Hu" Subject: [PATCH v2 2/5] iommu/dma: add support for non-strict mode Date: Sun, 10 Jun 2018 19:07:20 +0800 Message-ID: <1528628843-10280-3-git-send-email-thunder.leizhen@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1528628843-10280-1-git-send-email-thunder.leizhen@huawei.com> References: <1528628843-10280-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. Save the related domain pointer in struct iommu_dma_cookie, make iovad capable call domain->ops->flush_iotlb_all to flush TLB. 2. Add a new iommu capability: IOMMU_CAP_NON_STRICT, which used to indicate that the iommu domain support non-strict mode. 3. During the iommu domain initialization phase, call capable() to check whether it support non-strcit mode. If so, call init_iova_flush_queue to register iovad->flush_cb callback. 4. All unmap(contains iova-free) APIs will finally invoke __iommu_dma_unmap -->iommu_dma_free_iova. If the domain is non-strict, call queue_iova to put off iova freeing. Signed-off-by: Zhen Lei --- drivers/iommu/dma-iommu.c | 25 +++++++++++++++++++++++++ include/linux/iommu.h | 7 +++++++ 2 files changed, 32 insertions(+) -- 1.8.3 diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index ddcbbdb..9f0c77a 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -55,6 +55,7 @@ struct iommu_dma_cookie { }; struct list_head msi_page_list; spinlock_t msi_lock; + struct iommu_domain *domain_non_strict; }; static inline size_t cookie_msi_granule(struct iommu_dma_cookie *cookie) @@ -257,6 +258,17 @@ static int iova_reserve_iommu_regions(struct device *dev, return ret; } +static void iommu_dma_flush_iotlb_all(struct iova_domain *iovad) +{ + struct iommu_dma_cookie *cookie; + struct iommu_domain *domain; + + cookie = container_of(iovad, struct iommu_dma_cookie, iovad); + domain = cookie->domain_non_strict; + + domain->ops->flush_iotlb_all(domain); +} + /** * iommu_dma_init_domain - Initialise a DMA mapping domain * @domain: IOMMU domain previously prepared by iommu_get_dma_cookie() @@ -272,6 +284,7 @@ static int iova_reserve_iommu_regions(struct device *dev, int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base, u64 size, struct device *dev) { + const struct iommu_ops *ops = domain->ops; struct iommu_dma_cookie *cookie = domain->iova_cookie; struct iova_domain *iovad = &cookie->iovad; unsigned long order, base_pfn, end_pfn; @@ -308,6 +321,15 @@ int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base, } init_iova_domain(iovad, 1UL << order, base_pfn); + + if ((ops->capable && ops->capable(IOMMU_CAP_NON_STRICT)) && + (IOMMU_DOMAIN_STRICT_MODE(domain) == IOMMU_NON_STRICT)) { + BUG_ON(!ops->flush_iotlb_all); + + cookie->domain_non_strict = domain; + init_iova_flush_queue(iovad, iommu_dma_flush_iotlb_all, NULL); + } + if (!dev) return 0; @@ -390,6 +412,9 @@ static void iommu_dma_free_iova(struct iommu_dma_cookie *cookie, /* The MSI case is only ever cleaning up its most recent allocation */ if (cookie->type == IOMMU_DMA_MSI_COOKIE) cookie->msi_iova -= size; + else if (cookie->domain_non_strict) + queue_iova(iovad, iova_pfn(iovad, iova), + size >> iova_shift(iovad), 0); else free_iova_fast(iovad, iova_pfn(iovad, iova), size >> iova_shift(iovad)); diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 19938ee..82ed979 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -86,6 +86,12 @@ struct iommu_domain_geometry { #define IOMMU_DOMAIN_DMA (__IOMMU_DOMAIN_PAGING | \ __IOMMU_DOMAIN_DMA_API) +#define IOMMU_STRICT 0 +#define IOMMU_NON_STRICT 1 +#define IOMMU_STRICT_MODE_MASK 1UL +#define IOMMU_DOMAIN_STRICT_MODE(domain) \ + (domain->type != IOMMU_DOMAIN_UNMANAGED) + struct iommu_domain { unsigned type; const struct iommu_ops *ops; @@ -101,6 +107,7 @@ enum iommu_cap { transactions */ IOMMU_CAP_INTR_REMAP, /* IOMMU supports interrupt isolation */ IOMMU_CAP_NOEXEC, /* IOMMU_NOEXEC flag */ + IOMMU_CAP_NON_STRICT, /* IOMMU supports non-strict mode */ }; /* From patchwork Sun Jun 10 11:07:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 138186 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2892773lji; Sun, 10 Jun 2018 04:08:52 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI+KxY2AWI+5aYy8NBCMMw/nPz0+B3cfS3pN14d+Q+0CRyo3zgvYVn/3JdNfvrTqmvN5K98 X-Received: by 2002:a17:902:5a4c:: with SMTP id f12-v6mr14164556plm.85.1528628932192; Sun, 10 Jun 2018 04:08:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528628932; cv=none; d=google.com; s=arc-20160816; b=fFInIbjplUZm+akONxWqhBcLJycUMuNxN3u9vG6tJq2+FqjKpCs/B9ceDgtlmjWnzH dNgr6ylINZqw+KY6Tw6f0YFfOk4ucfx7ikjpi0/GryENxERWiRfniYX+fgw6CSTBiOx/ BB2AkbMQBOj74rfmUQRsrofF/d1bb/DeY1WC3NMtQQ/FxYdFzd0ih5gR3HAjllDqXyfQ k4ylx7wJxJ5TP4Nf19tFMqyu9u7vYriPLKpNCuq+bMIrupQ3ATL/Hbw2i/1aZ4KKAChZ U+3CbmlwxJZmqk/tbIklhI0fid8w+NU3NaEQW8XshBVjGoEscYQrDScesu1DIixzvuTz GvmQ== 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=Dqiu3WLCv4ZERoYgplhtT/SOIpAtuOlrStEp27w5kyc=; b=Md5oEcWLqSulPPHVrNQJEIYfwOTwI9jDZ9Gh8DYHcdb//S30C41ylZDaMMNPTVLcBK ATxjyc1pT/5chmIvpv8r1BbXUc9ZcrKJthTWb4jB3GJgb+U5Ux5oL19lBMCPK4pjhnUW Ic0HlukVuMqHutfOHYLsIfDfrjBafTEiSzl7a0DAPe0kgjqgHOHh22TJP8XzOo1p9Hm5 qrp82OHoSNH2ITPrOnAgt374h/9HmykHN8aGWA4eqZegNhorxOQ5dEiDX+fP9SMpFu6x Xcg9gvM/WxZSRZWku5QxGtPcPrmJ9rq+7BnnqU+g0mFgBsxIIQDjYHRvE/1UtcvMjtVp gSiw== 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 t187-v6si12235159pgc.163.2018.06.10.04.08.51; Sun, 10 Jun 2018 04:08:52 -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 S1753943AbeFJLIn (ORCPT + 30 others); Sun, 10 Jun 2018 07:08:43 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:35230 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753878AbeFJLIh (ORCPT ); Sun, 10 Jun 2018 07:08:37 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 44ACD150A446A; Sun, 10 Jun 2018 19:08:33 +0800 (CST) Received: from localhost (10.177.23.164) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.382.0; Sun, 10 Jun 2018 19:08:24 +0800 From: Zhen Lei To: Robin Murphy , Will Deacon , Joerg Roedel , iommu , linux-kernel CC: Zhen Lei , Hanjun Guo , Libin , Guozhu Li , "Xinwei Hu" Subject: [PATCH v2 3/5] iommu/amd: use default branch to deal with all non-supported capabilities Date: Sun, 10 Jun 2018 19:07:21 +0800 Message-ID: <1528628843-10280-4-git-send-email-thunder.leizhen@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1528628843-10280-1-git-send-email-thunder.leizhen@huawei.com> References: <1528628843-10280-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 Avoid below warning when new capabilities added: drivers/iommu/amd_iommu.c: In function 'amd_iommu_capable': drivers/iommu/amd_iommu.c:3053:2: warning: enumeration value 'IOMMU_CAP_NON_STRICT' not handled in switch [-Wswitch] switch (cap) { Signed-off-by: Zhen Lei --- drivers/iommu/amd_iommu.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) -- 1.8.3 diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 1912e91..8b0ba6d 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -3059,11 +3059,9 @@ static bool amd_iommu_capable(enum iommu_cap cap) return true; case IOMMU_CAP_INTR_REMAP: return (irq_remapping_enabled == 1); - case IOMMU_CAP_NOEXEC: + default: return false; } - - return false; } static void amd_iommu_get_resv_regions(struct device *dev, From patchwork Sun Jun 10 11:07:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 138187 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2892871lji; Sun, 10 Jun 2018 04:08:59 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJZ2qMtRKyn/hbtDuYwYKxSC0lJG5fJiq9eISTebu59G4UM3Qk6eRJSVJMx/m2Eza35ksMq X-Received: by 2002:a62:c9ce:: with SMTP id l75-v6mr13190122pfk.179.1528628939741; Sun, 10 Jun 2018 04:08:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528628939; cv=none; d=google.com; s=arc-20160816; b=b8TxqgjqUzPuuUlSsHN4UYNIsImb/+JxQhEzM1AsDRv6vC+cAfBeDr0XKRZC/h30P/ Q66bOQfBsbyICMYOwgizsxlPy864wo+N6OoOKZAZhd0Np2fkpx1m+LcdScEh9ULvRSQP aSGc6nd7Ij6KGnPIKbQN6dN04d6tJMKt/HB7d5JIpfORzpVBZhp1PzbguYK7dLUCHvdV TsguXA289W2iQ2t4F9ZPBKaha0XILtw8CBAmUqeN8zp5nXc2NQ7y7R7zCNSYFJkZWD+R asglsWCNjtQooDzcpTXBL5IYKbMlT+eqSsItWxdlcDRSLFIqF1EIFFq5OuurPAhMXFhE OYzw== 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=EgczgummaNhPjXxM1mizWwsgShTS8qOJqqRBLaV5ZZI=; b=RcnSgSea7p8OsSfKvqGJSfOHuuycfjtjcHXwyGpykHwBqnqhWVDqoDSREBwXBf32c+ SjsFFWCBr7/gMuWlNe39X/kq1QYHe2Mdcx+jb98sdFhQ/yixN8Jf48I653+ZCjEVLXh7 G88sGaQrG2X6S7L96eUrxbz+Sr6vheL1ctOiPQuw7Sw+nCidjHruhM2O+dxmxbGHhKPE W0Q2OI6bAqcf8Em3z7dE68qRXEiom/u7LsbHo99iRQ4R1fcbn6Mx9Dm01zlcOqnK9Img XEHwwnk8Z46lN/kaC6ug93NNCJsVXEXGJEQmS9RFQXbjlMVsIpuyq3D66YK4W1xdEK7D RpyQ== 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 t7-v6si17595855pgv.668.2018.06.10.04.08.59; Sun, 10 Jun 2018 04:08:59 -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 S1753927AbeFJLIm (ORCPT + 30 others); Sun, 10 Jun 2018 07:08:42 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:35191 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753874AbeFJLIh (ORCPT ); Sun, 10 Jun 2018 07:08:37 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 111E44A3AAC54; Sun, 10 Jun 2018 19:08:31 +0800 (CST) Received: from localhost (10.177.23.164) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.382.0; Sun, 10 Jun 2018 19:08:25 +0800 From: Zhen Lei To: Robin Murphy , Will Deacon , Joerg Roedel , iommu , linux-kernel CC: Zhen Lei , Hanjun Guo , Libin , Guozhu Li , "Xinwei Hu" Subject: [PATCH v2 4/5] iommu/io-pgtable-arm: add support for non-strict mode Date: Sun, 10 Jun 2018 19:07:22 +0800 Message-ID: <1528628843-10280-5-git-send-email-thunder.leizhen@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1528628843-10280-1-git-send-email-thunder.leizhen@huawei.com> References: <1528628843-10280-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. Use the lowest bit of the iova parameter to pass the strict mode: 0, IOMMU_STRICT; 1, IOMMU_NON_STRICT; Treat 0 as IOMMU_STRICT, so that the unmap operation can compatible with other IOMMUs which still use strict mode. Signed-off-by: Zhen Lei --- drivers/iommu/io-pgtable-arm.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) -- 1.8.3 diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index 010a254..9234db3 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -292,7 +292,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, @@ -334,7 +334,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; } @@ -531,7 +531,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; @@ -576,15 +576,18 @@ 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); io_pgtable_tlb_add_flush(&data->iop, iova, size, size, true); + if (!strict) + io_pgtable_tlb_sync(&data->iop); + 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; @@ -609,7 +612,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); } @@ -620,25 +623,27 @@ 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, size_t size) { + int strict = ((iova & IOMMU_STRICT_MODE_MASK) == IOMMU_STRICT); struct arm_lpae_io_pgtable *data = io_pgtable_ops_to_data(ops); arm_lpae_iopte *ptep = data->pgd; int lvl = ARM_LPAE_START_LVL(data); + iova &= ~IOMMU_STRICT_MODE_MASK; 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 Sun Jun 10 11:07:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 138185 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2892687lji; Sun, 10 Jun 2018 04:08:45 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLdCKGcvf0yiDiQ6xebDN6+rZVv0WyIm/Xn2T3J9cUoB8raQb8pwnR/SlUR1xGdT+nfmYsq X-Received: by 2002:a63:7211:: with SMTP id n17-v6mr10818680pgc.94.1528628925355; Sun, 10 Jun 2018 04:08:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528628925; cv=none; d=google.com; s=arc-20160816; b=NQd7UcXSTJeCKnn29/k169einIwqom/ezS4Gts8WpEWORcePHa5TlH02zp6CjhoCAk E5W7b4Pc+tQalcfM6dOONWOdx+Vay+SLZppDuctipn6yxEMOpjBg1zMIol/6wt6UQ1F4 +oWFZi+NN6qgJg+2BI09XijOv1Y9hV2sHQDDflnlHzO4rIYpbmGL0GVuk5z/AIxC3h95 pgLIF0WPEm5xbhhpkjQxSBfi8RZ04gRqWHzn4ge1LqBzc56z9rK2HtNBQGcnQaO66Yhe ePn2tzSIEcVt0s58FbY+DTGcaeu7+T+mTTiEeKrfJjj1rJeJ6nL+y6hzMhZjMCkb4uXn cPaA== 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=Y2+p1O9jEqtldX4F8u9tfk07x9I2K98fNte2KfG2HT0=; b=y/WHq49AZE3WA3QK2RUieyhd5h3AhBt1ZuO7Y0kdGO8lplQUipT1ULMaVskYCpXTRI CgQmGRoFF7nmyUms/z5730sJh3qN52wrLxwWlAJZUfZYskk+G2OdhLRG3sxNz7MIM8M3 og3+Orby5/dbYTHsFSI+soX96k9nR3HM43Y16QcF5zlnJUgfkhfA1KgCGOCWXtoSAB7T voV3lG1C/DexaWYcn6OEojHGKh2J7aaPr4HA+SlDBUhfhqZZxB3L7UCUO4lQVK+NHoJq Y/ghbCh3UIsRLlpmDV9GwTiiNTm4iYxNZloAGWYfF+eMpkNmMsDRgbpDWADnRiaPNCbe U32Q== 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 v11-v6si60401056plp.25.2018.06.10.04.08.43; Sun, 10 Jun 2018 04:08:45 -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 S1753897AbeFJLIh (ORCPT + 30 others); Sun, 10 Jun 2018 07:08:37 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:35206 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753869AbeFJLIg (ORCPT ); Sun, 10 Jun 2018 07:08:36 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 72320B2132917; Sun, 10 Jun 2018 19:08:32 +0800 (CST) Received: from localhost (10.177.23.164) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.382.0; Sun, 10 Jun 2018 19:08:26 +0800 From: Zhen Lei To: Robin Murphy , Will Deacon , Joerg Roedel , iommu , linux-kernel CC: Zhen Lei , Hanjun Guo , Libin , Guozhu Li , "Xinwei Hu" Subject: [PATCH v2 5/5] iommu/arm-smmu-v3: add support for non-strict mode Date: Sun, 10 Jun 2018 19:07:23 +0800 Message-ID: <1528628843-10280-6-git-send-email-thunder.leizhen@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1528628843-10280-1-git-send-email-thunder.leizhen@huawei.com> References: <1528628843-10280-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 4402187..4a198a0 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); + return ops->unmap(ops, iova | IOMMU_DOMAIN_STRICT_MODE(domain), size); } 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_STRICT_MODE(domain) == IOMMU_STRICT)) __arm_smmu_tlb_sync(smmu); }