From patchwork Mon May 10 14:17:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 433155 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp2896399jao; Mon, 10 May 2021 07:27:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+pFSS4B5sd8GPjTGnYbpgZ53C2pI8KLbuycR1/he40W2iHGiGEXOphoV7HO//vxP6SfF/ X-Received: by 2002:a05:6e02:548:: with SMTP id i8mr20374476ils.69.1620656832503; Mon, 10 May 2021 07:27:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620656832; cv=none; d=google.com; s=arc-20160816; b=zdLHYdtAD2BOpu7JxKaWOyBZwo36qJ/MUG+RuInDin1TItnwoW5A8EiG6R3FmGtIbm bK2dCwoS+ujjblXuufqa3WHKPjFaEa1FHEdRAMYoYIdBOodLgrdDeuykzvQT9k2mQvM7 Sv3zrJZhZWY/FZfKXao/kBh3Ly39qDSJIAZcs0Ss7qA7C/7RWmyUhSgryaLHl1A1T8Ko VU7Ikui9+3AP1pk5EgOmoTplrmtFtkZ+jMqCH9wXKXoKNESGM4Rht/XEK5Svwj5IxRDo QOrixGnUVQFg/T5iCcP97gR8U2ORbaaxCHmx+0tySjCDI+5Fb3242Q7xfHb6QK9KtzLn ZkIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=6a6I1aR8lcbxRI0GUxbhXgr6xgSFHTraT73BRldZrG8=; b=lqNu3otaKfxyXNYNBBEeCjP69Kg4ry602ChgWhf5BEgrCA/iSQV6nMYks5qHDu9q3h qysn9Nryr8U9onIf2k1EVa0qo+NGEJgfwERwhgas85BzGuupysS0nQS0mAXocutuB2vW P4XuvFq7yiPNIxXs4DDjVCbLaT9ZaZdmVey8+WRlQFmNcMvGQKh5oB/MRE8plMUI6BEl 0SKp68xn/mGmXUOZfuCaX0I/mPP0Mq8FYXf1h3EfUyVKQmq/6StHN0rs0KRVUCa8f9WW 6AMet9XXv5FlssdaVvcFBJwiEKLQrIID49VweDOGMsSHAoDkHy2NYhhoCreqhNWSdj6/ LDfw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si13610863ilr.121.2021.05.10.07.27.12 for ; Mon, 10 May 2021 07:27:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237520AbhEJO2N (ORCPT ); Mon, 10 May 2021 10:28:13 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2759 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238904AbhEJOZr (ORCPT ); Mon, 10 May 2021 10:25:47 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Ff38H3gGRzqTrb; Mon, 10 May 2021 22:19:11 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Mon, 10 May 2021 22:22:24 +0800 From: John Garry To: , , , , CC: , , , , , , John Garry Subject: [PATCH v2 01/15] iommu: Reactor iommu_group_store_type() Date: Mon, 10 May 2021 22:17:15 +0800 Message-ID: <1620656249-68890-2-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1620656249-68890-1-git-send-email-john.garry@huawei.com> References: <1620656249-68890-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Function iommu_group_store_type() supports changing the default domain of an IOMMU group. Many conditions need to be satisfied and steps taken for this action to be successful. Satisfying these conditions and steps will be required for setting other IOMMU group attributes, so factor into a common part and a part specific to update the IOMMU group attribute. No functional change intended. Some code comments are tidied up also. Signed-off-by: John Garry --- drivers/iommu/iommu.c | 73 +++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 27 deletions(-) -- 2.26.2 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 808ab70d5df5..4d12b607918c 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3169,20 +3169,23 @@ static int iommu_change_dev_def_domain(struct iommu_group *group, } /* - * Changing the default domain through sysfs requires the users to ubind the - * drivers from the devices in the iommu group. Return failure if this doesn't - * meet. + * Changing the default domain or any other IOMMU group attribute through sysfs + * requires the users to unbind the drivers from the devices in the IOMMU group. + * Return failure if this precondition is not met. * * We need to consider the race between this and the device release path. * device_lock(dev) is used here to guarantee that the device release path * will not be entered at the same time. */ -static ssize_t iommu_group_store_type(struct iommu_group *group, - const char *buf, size_t count) +static ssize_t iommu_group_store_common(struct iommu_group *group, + const char *buf, size_t count, + int (*cb)(const char *buf, + struct iommu_group *group, + struct device *dev)) { struct group_device *grp_dev; struct device *dev; - int ret, req_type; + int ret; if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) return -EACCES; @@ -3190,25 +3193,16 @@ static ssize_t iommu_group_store_type(struct iommu_group *group, if (WARN_ON(!group)) return -EINVAL; - if (sysfs_streq(buf, "identity")) - req_type = IOMMU_DOMAIN_IDENTITY; - else if (sysfs_streq(buf, "DMA")) - req_type = IOMMU_DOMAIN_DMA; - else if (sysfs_streq(buf, "auto")) - req_type = 0; - else - return -EINVAL; - /* * Lock/Unlock the group mutex here before device lock to - * 1. Make sure that the iommu group has only one device (this is a + * 1. Make sure that the IOMMU group has only one device (this is a * prerequisite for step 2) * 2. Get struct *dev which is needed to lock device */ mutex_lock(&group->mutex); if (iommu_group_device_count(group) != 1) { mutex_unlock(&group->mutex); - pr_err_ratelimited("Cannot change default domain: Group has more than one device\n"); + pr_err_ratelimited("Cannot change IOMMU group default domain attribute: Group has more than one device\n"); return -EINVAL; } @@ -3220,16 +3214,16 @@ static ssize_t iommu_group_store_type(struct iommu_group *group, /* * Don't hold the group mutex because taking group mutex first and then * the device lock could potentially cause a deadlock as below. Assume - * two threads T1 and T2. T1 is trying to change default domain of an - * iommu group and T2 is trying to hot unplug a device or release [1] VF - * of a PCIe device which is in the same iommu group. T1 takes group - * mutex and before it could take device lock assume T2 has taken device - * lock and is yet to take group mutex. Now, both the threads will be - * waiting for the other thread to release lock. Below, lock order was - * suggested. + * two threads, T1 and T2. T1 is trying to change default domain + * attribute of an IOMMU group and T2 is trying to hot unplug a device + * or release [1] VF of a PCIe device which is in the same IOMMU group. + * T1 takes the group mutex and before it could take device lock T2 may + * have taken device lock and is yet to take group mutex. Now, both the + * threads will be waiting for the other thread to release lock. Below, + * lock order was suggested. * device_lock(dev); * mutex_lock(&group->mutex); - * iommu_change_dev_def_domain(); + * cb->iommu_change_dev_def_domain(); [example cb] * mutex_unlock(&group->mutex); * device_unlock(dev); * @@ -3243,7 +3237,7 @@ static ssize_t iommu_group_store_type(struct iommu_group *group, */ mutex_unlock(&group->mutex); - /* Check if the device in the group still has a driver bound to it */ + /* Check if the only device in the group still has a driver bound */ device_lock(dev); if (device_is_bound(dev)) { pr_err_ratelimited("Device is still bound to driver\n"); @@ -3251,7 +3245,7 @@ static ssize_t iommu_group_store_type(struct iommu_group *group, goto out; } - ret = iommu_change_dev_def_domain(group, dev, req_type); + ret = (cb)(buf, group, dev); ret = ret ?: count; out: @@ -3260,3 +3254,28 @@ static ssize_t iommu_group_store_type(struct iommu_group *group, return ret; } + +static int iommu_group_store_type_cb(const char *buf, + struct iommu_group *group, + struct device *dev) +{ + int type; + + if (sysfs_streq(buf, "identity")) + type = IOMMU_DOMAIN_IDENTITY; + else if (sysfs_streq(buf, "DMA")) + type = IOMMU_DOMAIN_DMA; + else if (sysfs_streq(buf, "auto")) + type = 0; + else + return -EINVAL; + + return iommu_change_dev_def_domain(group, dev, type); +} + +static ssize_t iommu_group_store_type(struct iommu_group *group, + const char *buf, size_t count) +{ + return iommu_group_store_common(group, buf, count, + iommu_group_store_type_cb); +} From patchwork Mon May 10 14:17:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 433150 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp2895848jao; Mon, 10 May 2021 07:26:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxyNayur2ZoR1YD5bIwMCSrrHmaIKamzkmi6MFb93lvfocumZEPFu+t9f5JPpYCEu3FeLS X-Received: by 2002:a05:6e02:218a:: with SMTP id j10mr3851582ila.279.1620656787316; Mon, 10 May 2021 07:26:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620656787; cv=none; d=google.com; s=arc-20160816; b=zMfMRFbimWTeYnDOitDmXZpn7qW8SaDsUXQDsAggF3ouX+z9mukBDIG/jMmlfvNTup ZZtYNmiRMrSIlbYSVOv/sQCZBXaAPamyDE+7fx/F5F8jISMFNCs044ZsITcqimAINhv9 wNwhyC9qiTO/eF/iK/YgOBCB5z5o1KQ+t8CcQHEpCglrLwFD4gs49tG5mPk//1lq1EAY Z6NQGBgiBxGkOpbWZfL8jHeqvH6PSIDAgpgdxSMlCpQ4A/XOk4Ilm56FNRDA22As7/Wv XKbnL0UfcBZo+nP53Mhz67LxpVW/e0CIZEnHMJwi0uAYXYt/562Y8vmemVKe/KcB+SqD Sv+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=tRa9OT4rjiKwVt067L+S8Ar56X9w3FzmXKxh5URW9AI=; b=jmnNddz/k4ZR3kNG3bjIrS9IL2QSHscXufZ5cHrTXyYpeEmo9fSYtHK1WllmVLg0FR Zzpqm/Xe6Hpybq75jmSqvQA2jV3rrU0Q3esif9BYphnvRnzcOaWNK9dJ4Ls10LHvUclr cEjUDtB6E0HfiOYnqaWRUCMhZUO+5kdE5dGUk81NnnL19rCQTqCbT+/awnRL2oQQPwvD J8F8usOXgVgIA2g3dT8+XYeClTlEAW/f9zD2swqPiFwRAKZnwBdq/4aVd4ROfdKOptOG /WAMDU3PBcv+ha20siqd1ryd5TeL1wfXle0tVVD6CxWURPb3EVhjFbh+/tTCqmJaNldr HKtA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si13610863ilr.121.2021.05.10.07.26.27 for ; Mon, 10 May 2021 07:26:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236497AbhEJO1A (ORCPT ); Mon, 10 May 2021 10:27:00 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2755 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235153AbhEJOXq (ORCPT ); Mon, 10 May 2021 10:23:46 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Ff38H430SzqTrc; Mon, 10 May 2021 22:19:11 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Mon, 10 May 2021 22:22:25 +0800 From: John Garry To: , , , , CC: , , , , , , John Garry Subject: [PATCH v2 02/15] iova: Allow rcache range upper limit to be flexible Date: Mon, 10 May 2021 22:17:16 +0800 Message-ID: <1620656249-68890-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1620656249-68890-1-git-send-email-john.garry@huawei.com> References: <1620656249-68890-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Some LLDs may request DMA mappings whose IOVA length exceeds that of the current rcache upper limit. This means that allocations for those IOVAs will never be cached, and always must be allocated and freed from the RB tree per DMA mapping cycle. This has a significant effect on performance, more so since commit 4e89dce72521 ("iommu/iova: Retry from last rb tree node if iova search fails"), as discussed at [0]. As a first step towards allowing the rcache range upper limit be configured, hold this value in the IOVA rcache structure, and allocate the rcaches separately. [0] https://lore.kernel.org/linux-iommu/20210129092120.1482-1-thunder.leizhen@huawei.com/ Signed-off-by: John Garry --- drivers/iommu/dma-iommu.c | 2 +- drivers/iommu/iova.c | 23 +++++++++++++++++------ include/linux/iova.h | 4 ++-- 3 files changed, 20 insertions(+), 9 deletions(-) -- 2.26.2 diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 7bcdd1205535..f6d3302bb829 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -432,7 +432,7 @@ static dma_addr_t iommu_dma_alloc_iova(struct iommu_domain *domain, * rounding up anything cacheable to make sure that can't happen. The * order of the unadjusted size will still match upon freeing. */ - if (iova_len < (1 << (IOVA_RANGE_CACHE_MAX_SIZE - 1))) + if (iova_len < (1 << (iovad->rcache_max_size - 1))) iova_len = roundup_pow_of_two(iova_len); dma_limit = min_not_zero(dma_limit, dev->bus_dma_limit); diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index b7ecd5b08039..0e4c0e55178a 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -15,6 +15,8 @@ /* The anchor node sits above the top of the usable address space */ #define IOVA_ANCHOR ~0UL +#define IOVA_RANGE_CACHE_MAX_SIZE 6 /* log of max cached IOVA range size (in pages) */ + static bool iova_rcache_insert(struct iova_domain *iovad, unsigned long pfn, unsigned long size); @@ -877,7 +879,14 @@ static void init_iova_rcaches(struct iova_domain *iovad) unsigned int cpu; int i; - for (i = 0; i < IOVA_RANGE_CACHE_MAX_SIZE; ++i) { + iovad->rcache_max_size = IOVA_RANGE_CACHE_MAX_SIZE; + + iovad->rcaches = kcalloc(iovad->rcache_max_size, + sizeof(*iovad->rcaches), GFP_KERNEL); + if (!iovad->rcaches) + return; + + for (i = 0; i < iovad->rcache_max_size; ++i) { rcache = &iovad->rcaches[i]; spin_lock_init(&rcache->lock); rcache->depot_size = 0; @@ -952,7 +961,7 @@ static bool iova_rcache_insert(struct iova_domain *iovad, unsigned long pfn, { unsigned int log_size = order_base_2(size); - if (log_size >= IOVA_RANGE_CACHE_MAX_SIZE) + if (log_size >= iovad->rcache_max_size) return false; return __iova_rcache_insert(iovad, &iovad->rcaches[log_size], pfn); @@ -1008,7 +1017,7 @@ static unsigned long iova_rcache_get(struct iova_domain *iovad, { unsigned int log_size = order_base_2(size); - if (log_size >= IOVA_RANGE_CACHE_MAX_SIZE) + if (log_size >= iovad->rcache_max_size) return 0; return __iova_rcache_get(&iovad->rcaches[log_size], limit_pfn - size); @@ -1024,7 +1033,7 @@ static void free_iova_rcaches(struct iova_domain *iovad) unsigned int cpu; int i, j; - for (i = 0; i < IOVA_RANGE_CACHE_MAX_SIZE; ++i) { + for (i = 0; i < iovad->rcache_max_size; ++i) { rcache = &iovad->rcaches[i]; for_each_possible_cpu(cpu) { cpu_rcache = per_cpu_ptr(rcache->cpu_rcaches, cpu); @@ -1035,6 +1044,8 @@ static void free_iova_rcaches(struct iova_domain *iovad) for (j = 0; j < rcache->depot_size; ++j) iova_magazine_free(rcache->depot[j]); } + + kfree(iovad->rcaches); } /* @@ -1047,7 +1058,7 @@ static void free_cpu_cached_iovas(unsigned int cpu, struct iova_domain *iovad) unsigned long flags; int i; - for (i = 0; i < IOVA_RANGE_CACHE_MAX_SIZE; ++i) { + for (i = 0; i < iovad->rcache_max_size; ++i) { rcache = &iovad->rcaches[i]; cpu_rcache = per_cpu_ptr(rcache->cpu_rcaches, cpu); spin_lock_irqsave(&cpu_rcache->lock, flags); @@ -1066,7 +1077,7 @@ static void free_global_cached_iovas(struct iova_domain *iovad) unsigned long flags; int i, j; - for (i = 0; i < IOVA_RANGE_CACHE_MAX_SIZE; ++i) { + for (i = 0; i < iovad->rcache_max_size; ++i) { rcache = &iovad->rcaches[i]; spin_lock_irqsave(&rcache->lock, flags); for (j = 0; j < rcache->depot_size; ++j) { diff --git a/include/linux/iova.h b/include/linux/iova.h index 71d8a2de6635..9974e1d3e2bc 100644 --- a/include/linux/iova.h +++ b/include/linux/iova.h @@ -25,7 +25,6 @@ struct iova { struct iova_magazine; struct iova_cpu_rcache; -#define IOVA_RANGE_CACHE_MAX_SIZE 6 /* log of max cached IOVA range size (in pages) */ #define MAX_GLOBAL_MAGS 32 /* magazines per bin */ struct iova_rcache { @@ -74,6 +73,7 @@ struct iova_domain { unsigned long start_pfn; /* Lower limit for this domain */ unsigned long dma_32bit_pfn; unsigned long max32_alloc_size; /* Size of last failed allocation */ + unsigned long rcache_max_size; /* Upper limit of cached IOVA RANGE */ struct iova_fq __percpu *fq; /* Flush Queue */ atomic64_t fq_flush_start_cnt; /* Number of TLB flushes that @@ -83,7 +83,6 @@ struct iova_domain { have been finished */ struct iova anchor; /* rbtree lookup anchor */ - struct iova_rcache rcaches[IOVA_RANGE_CACHE_MAX_SIZE]; /* IOVA range caches */ iova_flush_cb flush_cb; /* Call-Back function to flush IOMMU TLBs */ @@ -96,6 +95,7 @@ struct iova_domain { atomic_t fq_timer_on; /* 1 when timer is active, 0 when not */ struct hlist_node cpuhp_dead; + struct iova_rcache *rcaches; /* IOVA range caches */ }; static inline unsigned long iova_size(struct iova *iova) From patchwork Mon May 10 14:17:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 433152 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp2895859jao; Mon, 10 May 2021 07:26:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJ98fiAZpEf5vfXmkXqo6PFLSocid2eNVyA57CmM90l/ICzX9FNDyaT8s4EAdlVnO0L4K7 X-Received: by 2002:a02:c98a:: with SMTP id b10mr21987436jap.103.1620656787658; Mon, 10 May 2021 07:26:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620656787; cv=none; d=google.com; s=arc-20160816; b=SL/KT7RhsRk/sUovwwkBlmjb8oSan0eK3US/mPBlOHm99KEUTteJSaEDbSrjIJ2drN BlgjTT3audeIzoQTqraQ9w/jYLWHLl3PSmK2Z/WGMGvh18EyR9X5tXUkjrFmq9zQ9u6G uQowKJ7JXwLCJDdjbpxGJTKHPFDdMdu3/OOOetLmbN2V4+nuWjh8I0dtOfjNoWACm/T2 xJd02zMGhmun6u7kxczKb0OsjsnqQfxMejcHZT6YxLAKEzmDCazIGxdVcM6TnPceT/m3 WLimXZapalmnHQL5cZ+hQUQzESNgY0u1LBNE7yfZWakItxmuhO7QC5T4peFgyaFV9NAP BnVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=YtVsHa0yfZheRmVM3+/Q2d3OzhUuveI8U36N59XcsF8=; b=RWhArXEYghQhVzSFbKbRozcTXDqu1WBFkftJirEBKfYgTEBCU0J0tFs0JtTsN5XO3z DOXKHmokLDKiAvEGNNGrF3MRVXdwQ7JB8Iblp4uyrOZzVdAfVk5VDfJaNsm7vKgngWkF V7A5rvitPSB8Lla1i08R6vxYI/yMOuXe4ESdHiU/Iye+rbwYlgh2tvFr2q5ea6oUe8rI XHYUUPoNKf9GRDEnDulAOPuahQyRNt658xnvscYed0hnJH0vCX1QOu1UuEVxt4eiVabu mo0kG4kwmveYIB7oPTWvg9S1eBCuI9XM7sREkX17BDbeqPmNaTx0ioNfYaCAuInjwPxj xwSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si13610863ilr.121.2021.05.10.07.26.27 for ; Mon, 10 May 2021 07:26:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237680AbhEJO1H (ORCPT ); Mon, 10 May 2021 10:27:07 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2757 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235166AbhEJOXq (ORCPT ); Mon, 10 May 2021 10:23:46 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Ff38H6LJkzqTs0; Mon, 10 May 2021 22:19:11 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Mon, 10 May 2021 22:22:25 +0800 From: John Garry To: , , , , CC: , , , , , , John Garry Subject: [PATCH v2 03/15] iommu: Allow max opt DMA len be set for a group via sysfs Date: Mon, 10 May 2021 22:17:17 +0800 Message-ID: <1620656249-68890-4-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1620656249-68890-1-git-send-email-john.garry@huawei.com> References: <1620656249-68890-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add support to allow the maximum optimised DMA len be set for an IOMMU group via sysfs. This much the same with the method to change the default domain type for a group. However, unlike changing the default domain type, the new domains will be allocated on a member device reprobe path. Signed-off-by: John Garry --- drivers/iommu/iommu.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) -- 2.26.2 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 4d12b607918c..63cdfb11ebed 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -45,6 +45,7 @@ struct iommu_group { struct iommu_domain *default_domain; struct iommu_domain *domain; struct list_head entry; + size_t max_opt_dma_size; }; struct group_device { @@ -86,6 +87,9 @@ static int iommu_create_device_direct_mappings(struct iommu_group *group, static struct iommu_group *iommu_group_get_for_dev(struct device *dev); static ssize_t iommu_group_store_type(struct iommu_group *group, const char *buf, size_t count); +static ssize_t iommu_group_store_max_opt_dma_size(struct iommu_group *group, + const char *buf, + size_t count); #define IOMMU_GROUP_ATTR(_name, _mode, _show, _store) \ struct iommu_group_attribute iommu_group_attr_##_name = \ @@ -554,6 +558,12 @@ static ssize_t iommu_group_show_type(struct iommu_group *group, return strlen(type); } +static ssize_t iommu_group_show_max_opt_dma_size(struct iommu_group *group, + char *buf) +{ + return sprintf(buf, "%zu\n", group->max_opt_dma_size); +} + static IOMMU_GROUP_ATTR(name, S_IRUGO, iommu_group_show_name, NULL); static IOMMU_GROUP_ATTR(reserved_regions, 0444, @@ -562,6 +572,9 @@ static IOMMU_GROUP_ATTR(reserved_regions, 0444, static IOMMU_GROUP_ATTR(type, 0644, iommu_group_show_type, iommu_group_store_type); +static IOMMU_GROUP_ATTR(max_opt_dma_size, 0644, iommu_group_show_max_opt_dma_size, + iommu_group_store_max_opt_dma_size); + static void iommu_group_release(struct kobject *kobj) { struct iommu_group *group = to_iommu_group(kobj); @@ -648,6 +661,10 @@ struct iommu_group *iommu_group_alloc(void) if (ret) return ERR_PTR(ret); + ret = iommu_group_create_file(group, &iommu_group_attr_max_opt_dma_size); + if (ret) + return ERR_PTR(ret); + pr_debug("Allocated group %d\n", group->id); return group; @@ -3279,3 +3296,29 @@ static ssize_t iommu_group_store_type(struct iommu_group *group, return iommu_group_store_common(group, buf, count, iommu_group_store_type_cb); } + +static int iommu_group_store_max_opt_dma_size_cb(const char *buf, + struct iommu_group *group, + struct device *dev) +{ + unsigned long val; + char *endp; + + val = simple_strtoul(buf, &endp, 0); + if (endp == buf) + return -EINVAL; + + mutex_lock(&group->mutex); + group->max_opt_dma_size = val; + mutex_unlock(&group->mutex); + + return 0; +} + +static ssize_t iommu_group_store_max_opt_dma_size(struct iommu_group *group, + const char *buf, + size_t count) +{ + return iommu_group_store_common(group, buf, count, + iommu_group_store_max_opt_dma_size_cb); +} From patchwork Mon May 10 14:17:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 433144 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp2895204jao; Mon, 10 May 2021 07:25:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxE4dCr7CLK+6CDQJyruK1no1RrV0va2dDHsQOjGrJSsyLx9V/zN68+0rKBTVL+EOSjiW8W X-Received: by 2002:a92:c8c6:: with SMTP id c6mr22483618ilq.109.1620656745076; Mon, 10 May 2021 07:25:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620656745; cv=none; d=google.com; s=arc-20160816; b=xlSYWQl9ByBNPO7fJcuup5BT5ZETupw4nEZRxWUc2AyFR1irjgtv52MLlixupQiSgq ZwXi63/0rd/lUo2ftmtjgDMUPNUMz9o6Ep/W6RD2M8cIOSeSin1g1swXUvg5pawlA/J6 jOPZCWN/Oy/jhi+Hsad2IaTKdJLNg05rgXb7XjtKz/g1QgbKTYbuZG81/t7Vl8AhRjqi 3uXVgvJsKvlIe0HVOk6HXx2K4ru6r6ZeCCYD2vv9Re9wVsM5oO2iqZ3zEz7icAMfRc1u p2lvWj9adekT0ubcP1GG3gHhxozDRaCaWfTNP8QimcsWSdPOpSZ9CMB4tDdMPRlezK1/ /dNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=SBE+paazxh0MQ/q+C0ZEfZA0pyppjs4z3+gh9TFRPm4=; b=NY7p5eyMfZozl7346SYWLOgAAD6+VQCSbpWzw8w6ZzBQqIiNV9YDFWw8m1y4aM832A uivmBRTBv6XEdXrQbT40FfOzQCw8pIht/1WV+DaT46A35YLrFAkBCuueNnXGyWkSDJcB mmXeDHva+MqotXikzsQV6NC/zQupoitcQNJuB064MGfiGRMxECR795qjk7J8QKpVUze2 swX79dzg0U+DPAYJG68eJfJn+dugXW6nusAtgbD3b6aOVV8pEhPzhulAimXzXQjsbeEd 2dH2TCTOnYd92R8zZ//LD77dJpriD/75N4ILpQv5yes0FpQsbFUPzi4XoYwuILYsLTtb lCwA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k8si18487873jav.68.2021.05.10.07.25.45 for ; Mon, 10 May 2021 07:25:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232846AbhEJO0q (ORCPT ); Mon, 10 May 2021 10:26:46 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2756 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235161AbhEJOXq (ORCPT ); Mon, 10 May 2021 10:23:46 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Ff38H6410zqTrx; Mon, 10 May 2021 22:19:11 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Mon, 10 May 2021 22:22:25 +0800 From: John Garry To: , , , , CC: , , , , , , John Garry Subject: [PATCH v2 04/15] iommu: Add iommu_group_get_max_opt_dma_size() Date: Mon, 10 May 2021 22:17:18 +0800 Message-ID: <1620656249-68890-5-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1620656249-68890-1-git-send-email-john.garry@huawei.com> References: <1620656249-68890-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add a function to return the max optimised DMA size for an IOMMU group. Signed-off-by: John Garry --- drivers/iommu/iommu.c | 5 +++++ include/linux/iommu.h | 6 ++++++ 2 files changed, 11 insertions(+) -- 2.26.2 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 63cdfb11ebed..62e4491f32e0 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2296,6 +2296,11 @@ struct iommu_domain *iommu_get_dma_domain(struct device *dev) return dev->iommu_group->default_domain; } +size_t iommu_group_get_max_opt_dma_size(struct iommu_group *group) +{ + return group->max_opt_dma_size; +} + /* * IOMMU groups are really the natural working unit of the IOMMU, but * the IOMMU API works on domains and devices. Bridge that gap by diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 32d448050bf7..e26abda94792 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -405,6 +405,7 @@ extern int iommu_sva_unbind_gpasid(struct iommu_domain *domain, struct device *dev, ioasid_t pasid); extern struct iommu_domain *iommu_get_domain_for_dev(struct device *dev); extern struct iommu_domain *iommu_get_dma_domain(struct device *dev); +extern size_t iommu_group_get_max_opt_dma_size(struct iommu_group *group); extern int iommu_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t size, int prot); extern int iommu_map_atomic(struct iommu_domain *domain, unsigned long iova, @@ -653,6 +654,11 @@ static inline struct iommu_domain *iommu_get_domain_for_dev(struct device *dev) return NULL; } +static inline size_t iommu_group_get_max_opt_dma_size(struct iommu_group *group) +{ + return 0; +} + static inline int iommu_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t size, int prot) { From patchwork Mon May 10 14:17:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 433158 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp2896508jao; Mon, 10 May 2021 07:27:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQrF/SUcvitQJZrFmjUiH8+t8ABu956o3rPyhAHBgF4F/aDO3h/ngc6Kqn+Gt8mjo8rMuf X-Received: by 2002:a92:d9c2:: with SMTP id n2mr21646418ilq.284.1620656839836; Mon, 10 May 2021 07:27:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620656839; cv=none; d=google.com; s=arc-20160816; b=cuW9Q3bNQnRA7qkw5ea1qWAYdomusXggOk8IC3usUYPQIN0qi2Nvd/D20nlQltx109 L2fjSa2mCJ0zevvu/wacwNL1y67SYYYQbnURnJ2VK79sHmhiyLbuzpCltbpFC1FyxMMs Uv6Jlk8uu+yzURgJo1vSC/CXw4rxwbZloyoC/ekvUfj/6PO/4TZJuWvkglXMW7OS4cLK C7JFSzIp/fRK95x7vtYjWLIRFwXCnKMATdph6Tz/GUdwo7zppIUKHA+lX0T/VrEV5NlL uAPpgNZxKk34pXnxJWLa1z4lfHZ/NvUo256vCZ/c52dYdAg+JMsS5QfW10vxFskePtTB DDHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=SYz+gKiL94rtRZuO7lRzPwE8cgMG3n2nJaKJiAl4qn4=; b=HJWcnYsQDAX21K1jyeLuc88HKNE1UQaZNkwIz43nneTKGKRHVeZAqyt5NuCkHe43GB Nxs/bzURoyA4F4U8o7jW5Hcblv2i56qgS345Qz5p3ssPGoNdZz4NXKoobIQtJLIGoexz xgPIJf7KNgvx7tMi47TLRK8U7kVMPXMpdaR9IQ0rW142DJLYAkAji/e/POWMgNfY35/c jmqKgsRdNuOOc3ahKN0HLDvNRmQzqoa4AeSfGIDnsppD+zKIcwd7G1/toiW43Yq/ssTa RKro8sEyWDRPo/j/1uv6ldpNQeI+C+oTzvgkAmKVPuaVWSRxLcMS1is7+NfHWtHmbWBF zSYA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si13610863ilr.121.2021.05.10.07.27.19 for ; Mon, 10 May 2021 07:27:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241872AbhEJO2T (ORCPT ); Mon, 10 May 2021 10:28:19 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2760 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238905AbhEJOZr (ORCPT ); Mon, 10 May 2021 10:25:47 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Ff38H3LXdzqTrV; Mon, 10 May 2021 22:19:11 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Mon, 10 May 2021 22:22:26 +0800 From: John Garry To: , , , , CC: , , , , , , John Garry Subject: [PATCH v2 05/15] iova: Add iova_domain_len_is_cached() Date: Mon, 10 May 2021 22:17:19 +0800 Message-ID: <1620656249-68890-6-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1620656249-68890-1-git-send-email-john.garry@huawei.com> References: <1620656249-68890-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add a function to check whether an IOVA domain currently caches a given upper IOVA len exactly. Signed-off-by: John Garry --- drivers/iommu/iova.c | 11 +++++++++++ include/linux/iova.h | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) -- 2.26.2 diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index 0e4c0e55178a..95892a0433cc 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -872,6 +872,17 @@ static void iova_magazine_push(struct iova_magazine *mag, unsigned long pfn) mag->pfns[mag->size++] = pfn; } +static unsigned long iova_len_to_rcache_max(unsigned long iova_len) +{ + return order_base_2(iova_len) + 1; +} + +/* Test if iova_len range cached upper limit matches that of IOVA domain */ +bool iova_domain_len_is_cached(struct iova_domain *iovad, unsigned long iova_len) +{ + return iova_len_to_rcache_max(iova_len) == iovad->rcache_max_size; +} + static void init_iova_rcaches(struct iova_domain *iovad) { struct iova_cpu_rcache *cpu_rcache; diff --git a/include/linux/iova.h b/include/linux/iova.h index 9974e1d3e2bc..04cc8eb6de38 100644 --- a/include/linux/iova.h +++ b/include/linux/iova.h @@ -136,7 +136,8 @@ static inline unsigned long iova_pfn(struct iova_domain *iovad, dma_addr_t iova) #if IS_ENABLED(CONFIG_IOMMU_IOVA) int iova_cache_get(void); void iova_cache_put(void); - +bool iova_domain_len_is_cached(struct iova_domain *iovad, + unsigned long iova_len); void free_iova(struct iova_domain *iovad, unsigned long pfn); void __free_iova(struct iova_domain *iovad, struct iova *iova); struct iova *alloc_iova(struct iova_domain *iovad, unsigned long size, @@ -158,6 +159,11 @@ int init_iova_flush_queue(struct iova_domain *iovad, struct iova *find_iova(struct iova_domain *iovad, unsigned long pfn); void put_iova_domain(struct iova_domain *iovad); #else +static inline bool iova_domain_len_is_cached(struct iova_domain *iovad, + unsigned long iova_len) +{ + return false; +} static inline int iova_cache_get(void) { return -ENOTSUPP; From patchwork Mon May 10 14:17:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 433147 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp2895351jao; Mon, 10 May 2021 07:25:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcBv1xkdyVLQLObWVdbErzCHpgasMnJckSEP17FdYj5rBJkFOYB3hSANdw+cckJDtAD6VE X-Received: by 2002:a05:6e02:527:: with SMTP id h7mr20482535ils.293.1620656752745; Mon, 10 May 2021 07:25:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620656752; cv=none; d=google.com; s=arc-20160816; b=i5kq6XnkuQMeHVtfnmUhVepJxjpU1qPIL4wBW0emlACnEwpln8FJdvjq7TWC5GCEX/ dEM8g+QcKqTUYgiR931nfcoS4KlXI83jBWmbEpFX0WsrOswZqvgfGX5daQ3vJ4wc9QkG q3C6azNX7NOOgBbJSgEmfdyih8+KLh8RtZ2CEl7Tu6eDs6xvwtFe65VBrt9TybOHWtK5 AgOVusLTSCHsOuhvXpjiuHYG0v/Uh5m72MC+Ameh0oRSuh71be2yVH0UbfIjPLu1cyRN aMWY+hooDVSU13cXaOGhl+hMR5niz1VuqzXfcQChzNFRxtZwds7lA5wRHBXJ3KHsaPHd 3DCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=hfLFINyeWMlChJXjiJey+tFDP5zA0+KVvEEzk5hf1CA=; b=bsjPMZhQ16D7HPIoJyiwC3JBplCp9a9fg7WypYAtH34Uj+huDVMXdZHBVwp1uCYlMW O0M6WA4O67p8b15o9EQztf9kEbzENVsGCCwNjw5qG6N0uAl3fL++wqssM2TIzZWCrYAO 7CKv30X+0qeSfnn/+oB9K7KTXr1rzjNK5IwCQZ64wWrsIHqJQ2f6UvmdGVvk90OwBpFe HNRWAN636EZ8jfX9QytmuOO1wwpNn7SLTFhiwXN5amxKZFsClsMupVy2GrWHLSdHQPfw cUiCQ3Xmd9Gn0C9gMq+8A9nDyqL6DidSkJCQb+A35ma48xe3dxOdyXrEGvQcQJ8PbbXM Ya5Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g19si19729924jat.91.2021.05.10.07.25.52 for ; Mon, 10 May 2021 07:25:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231341AbhEJO0x (ORCPT ); Mon, 10 May 2021 10:26:53 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2758 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235168AbhEJOXq (ORCPT ); Mon, 10 May 2021 10:23:46 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Ff38H4mTnzqTrf; Mon, 10 May 2021 22:19:11 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Mon, 10 May 2021 22:22:26 +0800 From: John Garry To: , , , , CC: , , , , , , John Garry Subject: [PATCH v2 06/15] iommu: Allow iommu_change_dev_def_domain() realloc default domain for same type Date: Mon, 10 May 2021 22:17:20 +0800 Message-ID: <1620656249-68890-7-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1620656249-68890-1-git-send-email-john.garry@huawei.com> References: <1620656249-68890-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Allow iommu_change_dev_def_domain() to create a new default domain, keeping the same as current in case type argument is not set. Also remove comment about function purpose, which will become stale. Signed-off-by: John Garry --- drivers/iommu/iommu.c | 53 ++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 26 deletions(-) -- 2.26.2 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 62e4491f32e0..f7253a973ab9 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3065,16 +3065,13 @@ EXPORT_SYMBOL_GPL(iommu_sva_get_pasid); * @prev_dev: The device in the group (this is used to make sure that the device * hasn't changed after the caller has called this function) * @type: The type of the new default domain that gets associated with the group + * @new: Allocate new default domain, keeping same type when no type passed * * Returns 0 on success and error code on failure * - * Note: - * 1. Presently, this function is called only when user requests to change the - * group's default domain type through /sys/kernel/iommu_groups//type - * Please take a closer look if intended to use for other purposes. */ static int iommu_change_dev_def_domain(struct iommu_group *group, - struct device *prev_dev, int type) + struct device *prev_dev, int type, bool new) { struct iommu_domain *prev_dom; struct group_device *grp_dev; @@ -3127,28 +3124,32 @@ static int iommu_change_dev_def_domain(struct iommu_group *group, goto out; } - dev_def_dom = iommu_get_def_domain_type(dev); - if (!type) { + if (new && !type) { + type = prev_dom->type; + } else { + dev_def_dom = iommu_get_def_domain_type(dev); + if (!type) { + /* + * If the user hasn't requested any specific type of domain and + * if the device supports both the domains, then default to the + * domain the device was booted with + */ + type = dev_def_dom ? : iommu_def_domain_type; + } else if (dev_def_dom && type != dev_def_dom) { + dev_err_ratelimited(prev_dev, "Device cannot be in %s domain\n", + iommu_domain_type_str(type)); + ret = -EINVAL; + goto out; + } + /* - * If the user hasn't requested any specific type of domain and - * if the device supports both the domains, then default to the - * domain the device was booted with + * Switch to a new domain only if the requested domain type is different + * from the existing default domain type */ - type = dev_def_dom ? : iommu_def_domain_type; - } else if (dev_def_dom && type != dev_def_dom) { - dev_err_ratelimited(prev_dev, "Device cannot be in %s domain\n", - iommu_domain_type_str(type)); - ret = -EINVAL; - goto out; - } - - /* - * Switch to a new domain only if the requested domain type is different - * from the existing default domain type - */ - if (prev_dom->type == type) { - ret = 0; - goto out; + if (prev_dom->type == type) { + ret = 0; + goto out; + } } /* Sets group->default_domain to the newly allocated domain */ @@ -3292,7 +3293,7 @@ static int iommu_group_store_type_cb(const char *buf, else return -EINVAL; - return iommu_change_dev_def_domain(group, dev, type); + return iommu_change_dev_def_domain(group, dev, type, false); } static ssize_t iommu_group_store_type(struct iommu_group *group, From patchwork Mon May 10 14:17:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 433146 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp2895346jao; Mon, 10 May 2021 07:25:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsg0iQbQIuLdDTP9kAgWduuILDT9MjGFnKWSRUScPbnhysm5edTaQ6drVA7OlQpuijOPZt X-Received: by 2002:a6b:dc06:: with SMTP id s6mr18649045ioc.130.1620656752536; Mon, 10 May 2021 07:25:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620656752; cv=none; d=google.com; s=arc-20160816; b=tmYcpcV4rwPlBxfGBcP7JNDzw8WqjO5s7XOWiVgWTFX6rp7HhZ6mPyxFfZMOakSl9v XTIytY/4Clq8H9LWqCymoa5FikBB8rne32RJ/xURxSvBJiz1HDkfyNYJcBQOwTbtpDPd sHbFxvfj4Ak4M7OOFLXTyF3ctjJNffYnuG8SlmP6UE5iYSHmOTfIInunf0BJUTsM45/v CVLHjHHDtUAx/ZJHl0Z+vi7NeCnEgMLYxPZJyAG67mWbAn5qhqnnWQivaxTlqIhCNKXy 5W0UDmmM7PRIoHgibdtSDJbgcU9YahxVBe7kNI8nC33yvYymJdEkyTA3s99vWNM98mkl 3RKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=0lVFVstcQT500R1DyMTnIY1sv7V5pgeYjvvC2I1feIY=; b=d6R6LP7Ri2tt/pUN1oMN2Pv3rACDLilsIS92yXoHc/iMjOLIJ284dENogRl6EPRaw7 3mUEQSlFxeIwbvgh41NuemKNrZftoUIngPMoC4AsJsaFuj2mqhhmF+bysO2B5wnVk8H+ jX7bhLGPD2cgALUc8azCKB+vqzkwvlGOtoGUc+W49P9Ebm3OruwEL1Yy0hTbIW9KLCaB rbH3Tlm5icgnlPJwHu4hZJ/DEto4i9C3AFXKMi4G+DVO/xNjmnwVa7vCdf4I7o6bKrbG vcn9wLSjP/Ce26WQSmJ9nUdatKajPk52zC+s5jk4nf63aQHoQzItC3Ml38CUBNqTsLuK IC+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g19si19729924jat.91.2021.05.10.07.25.52 for ; Mon, 10 May 2021 07:25:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233719AbhEJO0v (ORCPT ); Mon, 10 May 2021 10:26:51 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2676 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235354AbhEJOXq (ORCPT ); Mon, 10 May 2021 10:23:46 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Ff39B4WTgz1BKvs; Mon, 10 May 2021 22:19:58 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Mon, 10 May 2021 22:22:26 +0800 From: John Garry To: , , , , CC: , , , , , , John Garry Subject: [PATCH v2 07/15] iommu: Add iommu_realloc_dev_group() Date: Mon, 10 May 2021 22:17:21 +0800 Message-ID: <1620656249-68890-8-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1620656249-68890-1-git-send-email-john.garry@huawei.com> References: <1620656249-68890-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add a function to re-alloc IOMMU group default domain. Signed-off-by: John Garry --- drivers/iommu/iommu.c | 12 ++++++++++++ include/linux/iommu.h | 6 ++++++ 2 files changed, 18 insertions(+) -- 2.26.2 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index f7253a973ab9..bdb9aa47dfca 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3191,6 +3191,18 @@ static int iommu_change_dev_def_domain(struct iommu_group *group, return ret; } +int iommu_realloc_dev_group(struct device *dev) +{ + struct iommu_group *group; + int ret; + + group = iommu_group_get(dev); + ret = iommu_change_dev_def_domain(group, dev, 0, true); + iommu_group_put(group); + + return ret; +} + /* * Changing the default domain or any other IOMMU group attribute through sysfs * requires the users to unbind the drivers from the devices in the IOMMU group. diff --git a/include/linux/iommu.h b/include/linux/iommu.h index e26abda94792..6e187746af0f 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -482,6 +482,7 @@ bool iommu_get_dma_strict(struct iommu_domain *domain); extern int report_iommu_fault(struct iommu_domain *domain, struct device *dev, unsigned long iova, int flags); +extern int iommu_realloc_dev_group(struct device *dev); static inline void iommu_flush_iotlb_all(struct iommu_domain *domain) { @@ -699,6 +700,11 @@ static inline size_t iommu_map_sg_atomic(struct iommu_domain *domain, return 0; } +static inline int iommu_realloc_dev_group(struct device *dev) +{ + return -ENODEV; +} + static inline void iommu_flush_iotlb_all(struct iommu_domain *domain) { } From patchwork Mon May 10 14:17:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 433159 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp2896599jao; Mon, 10 May 2021 07:27:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzw7wlQzh1+dqlSa0IgdR2KXUfSXYElCUmtYVEmr9hKR+Mxr21kybdJELLkmjKhD0xUofkV X-Received: by 2002:a92:d9c2:: with SMTP id n2mr21646920ilq.284.1620656847662; Mon, 10 May 2021 07:27:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620656847; cv=none; d=google.com; s=arc-20160816; b=fGXkTIDu92swbZ3ciHgoKsdlj8cOsIu6a4Ycj/HeohWfItYFxXj4kSPz1ipAPSCdzq nyAWqQnbxkth31MpNXVE6NdWW/9qk+fZSairQ/VNgq9y/g00mgxRqqU45KUIoDbr9gKy lqTrJgT3zU1ZsV48NCnLIG+bJlAKGYIz69Y9+cj+ejzyjf1ywvXo1LDiCBpvNTLzDGSC CRbliGKl+p6lF4FsLJnmfKnR1S9g274e2/ColNLlyp+HiIW7W565GoJl9pMDWIUjUH8l vdR/CjEa7l9gXSo8cp37k1jOaQiTlftt8Cf4ibLv32CaDPtM0XsfoTLdpgw9+hANgTqr L/RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=U9BuamBJyLXyQjVveS+7+Phb3KtFTqoN5v75BJsWxqA=; b=N+y/iSBZZadCFKt3sskycfbnbdsi2kV14cLirBMgQOdbz8eTT9JM8viDpjcKAUX885 clFJBcY0buUiu/WH+TUb+SFu58plKyWpsLqP/sGYqH5KL+S26QLoL28rBOePy7LYSH9t VA4c+9ktRb3jwRNhuAsSyauYBCFv1NAbApGp2wXlklQBu8cIyyQi1mfvYf3wRmUjlLv7 3q1svNIVQP6zCWsjse+yeF3xupUpMjnNQKUcrHjTl+UWujAIc+a/muIrthAtRjJxpQUZ GuWFf6Lob15RNQoBLuDpE4wX0I9DNW6xjXZrdhzRcUSaCOJR0+DRsveT3u06f2bA0e9a dxaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si13610863ilr.121.2021.05.10.07.27.27 for ; Mon, 10 May 2021 07:27:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242223AbhEJO2Y (ORCPT ); Mon, 10 May 2021 10:28:24 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2679 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238909AbhEJOZr (ORCPT ); Mon, 10 May 2021 10:25:47 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Ff39B5ghvz1BKw7; Mon, 10 May 2021 22:19:58 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Mon, 10 May 2021 22:22:26 +0800 From: John Garry To: , , , , CC: , , , , , , John Garry Subject: [PATCH v2 08/15] dma-iommu: Add iommu_reconfig_dev_group_dma() Date: Mon, 10 May 2021 22:17:22 +0800 Message-ID: <1620656249-68890-9-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1620656249-68890-1-git-send-email-john.garry@huawei.com> References: <1620656249-68890-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add a function to reconfigure the IOMMU group for a device, if necessary. IOVAs are cached in power-of-2 granules, so there is no point in allocating a new IOMMU domain if the current range is suitable. Signed-off-by: John Garry --- drivers/iommu/dma-iommu.c | 25 +++++++++++++++++++++++++ include/linux/dma-iommu.h | 4 ++++ 2 files changed, 29 insertions(+) -- 2.26.2 diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index f6d3302bb829..4fb82c554ede 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -315,6 +315,31 @@ static bool dev_is_untrusted(struct device *dev) return dev_is_pci(dev) && to_pci_dev(dev)->untrusted; } +void iommu_reconfig_dev_group_dma(struct device *dev) +{ + struct iommu_domain *domain = iommu_get_domain_for_dev(dev); + struct iommu_dma_cookie *cookie = domain->iova_cookie; + unsigned long shift, iova_len; + struct iova_domain *iovad; + size_t max_opt_dma_size; + + if (!cookie || cookie->type != IOMMU_DMA_IOVA_COOKIE) + return; + + max_opt_dma_size = iommu_group_get_max_opt_dma_size(dev->iommu_group); + if (!max_opt_dma_size) + return; + + iovad = &cookie->iovad; + shift = iova_shift(iovad); + iova_len = max_opt_dma_size >> shift; + + if (iova_domain_len_is_cached(iovad, iova_len)) + return; + + iommu_realloc_dev_group(dev); +} + /** * iommu_dma_init_domain - Initialise a DMA mapping domain * @domain: IOMMU domain previously prepared by iommu_get_dma_cookie() diff --git a/include/linux/dma-iommu.h b/include/linux/dma-iommu.h index 6e75a2d689b4..097398b76dcc 100644 --- a/include/linux/dma-iommu.h +++ b/include/linux/dma-iommu.h @@ -20,6 +20,7 @@ void iommu_put_dma_cookie(struct iommu_domain *domain); /* Setup call for arch DMA mapping code */ void iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 size); +void iommu_reconfig_dev_group_dma(struct device *dev); /* The DMA API isn't _quite_ the whole story, though... */ /* @@ -53,6 +54,9 @@ static inline void iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 size) { } +static inline void iommu_reconfig_dev_group_dma(struct device *dev) +{ +} static inline int iommu_get_dma_cookie(struct iommu_domain *domain) { From patchwork Mon May 10 14:17:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 433149 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp2895404jao; Mon, 10 May 2021 07:25:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFr+yJnIPBrEtJfOqEKsh2EbFKO/Pec/lvHC3BGmqUDqNTHGvsjqjb8cU0aESvMBi4ob0/ X-Received: by 2002:a05:6602:181:: with SMTP id m1mr19034394ioo.153.1620656755851; Mon, 10 May 2021 07:25:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620656755; cv=none; d=google.com; s=arc-20160816; b=HetK99OKFkyJfaNw3YpBqdGGXFRL9ZYGXkSeLgbsiCOzit0RbXFgiQm4YumzL+WLE1 bIGt2GvTUhE4G9Bi3V1MXLIQrlIDvyfztAzKsbApFzvSSTr7nX6KqVTOZetG05Jig9Jf OIdCBWIAhQ8sVOH1IAG46gf/wMwJ2hYjMY4sR+JYq5pl/xfjrI/y5M9kFONvJbX/leIv 2vSaC1y7TbgYYhhucpvn6rC3V+ugZqxvA8RlvKQFtVqL8mWtPxUUm39P28cF4fqz/MFY 42TmTjW3BNDVU8L/KvCqzru5yCDg2QcrDgNsSuWD54sdZ0VOKqRK0fv1e5ZrRh5pml6/ /+GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=brR+MYHF8iTRFkbwgRyb5TbgRqRu13/U0EQtDUfyyz4=; b=rll14L6RVYjQ3I76FObe7iDZ4rLsjng5WqnbLKN2wS4XE0vpVr3G9Dv+wtZxoX+mM2 i8UIJhS+KmL8FxGV9/j3SOCo9St8dJpd8AO7SuIATFcznRzEBayEi2k8+hbcvV+rRmwq RSUK12QzPTp9FBPstJ15d379kqFQS7XuYRl8rRqMtsT9D93OC2ILkHFLFqYorZNOKVL6 UMqYihl8PoN4piEkK2qB4e2YsPQL8/eIU26Az0N4TYoy1yML7ZjRpT1AXVPNbx7PFeOt uqRFmJwyyUs1+K+fAa6RAi3ds0gGQErYxgySJH+7zFSNg4BX38mkGOZp29S7eVqpqUom gyAA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g19si19729924jat.91.2021.05.10.07.25.55 for ; Mon, 10 May 2021 07:25:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235670AbhEJO06 (ORCPT ); Mon, 10 May 2021 10:26:58 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2675 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235453AbhEJOXq (ORCPT ); Mon, 10 May 2021 10:23:46 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Ff39B2nMzz1BKvg; Mon, 10 May 2021 22:19:58 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Mon, 10 May 2021 22:22:27 +0800 From: John Garry To: , , , , CC: , , , , , , John Garry Subject: [PATCH v2 09/15] iova: Add init_iova_domain_ext() Date: Mon, 10 May 2021 22:17:23 +0800 Message-ID: <1620656249-68890-10-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1620656249-68890-1-git-send-email-john.garry@huawei.com> References: <1620656249-68890-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add extended version of init_iova_domain() which accepts an max opt iova length argument, and use it to set the rcaches range. Signed-off-by: John Garry --- drivers/iommu/iova.c | 29 +++++++++++++++++++++++------ include/linux/iova.h | 9 +++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) -- 2.26.2 Reported-by: kernel test robot diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index 95892a0433cc..273a689006c3 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -23,7 +23,7 @@ static bool iova_rcache_insert(struct iova_domain *iovad, static unsigned long iova_rcache_get(struct iova_domain *iovad, unsigned long size, unsigned long limit_pfn); -static void init_iova_rcaches(struct iova_domain *iovad); +static void init_iova_rcaches(struct iova_domain *iovad, unsigned long iova_len); static void free_cpu_cached_iovas(unsigned int cpu, struct iova_domain *iovad); static void free_iova_rcaches(struct iova_domain *iovad); static void fq_destroy_all_entries(struct iova_domain *iovad); @@ -47,8 +47,8 @@ static struct iova *to_iova(struct rb_node *node) } void -init_iova_domain(struct iova_domain *iovad, unsigned long granule, - unsigned long start_pfn) +__init_iova_domain(struct iova_domain *iovad, unsigned long granule, + unsigned long start_pfn, unsigned long iova_len) { /* * IOVA granularity will normally be equal to the smallest @@ -71,7 +71,21 @@ init_iova_domain(struct iova_domain *iovad, unsigned long granule, rb_link_node(&iovad->anchor.node, NULL, &iovad->rbroot.rb_node); rb_insert_color(&iovad->anchor.node, &iovad->rbroot); cpuhp_state_add_instance_nocalls(CPUHP_IOMMU_IOVA_DEAD, &iovad->cpuhp_dead); - init_iova_rcaches(iovad); + init_iova_rcaches(iovad, iova_len); +} + +void +init_iova_domain_ext(struct iova_domain *iovad, unsigned long granule, + unsigned long start_pfn, unsigned long iova_len) +{ + __init_iova_domain(iovad, granule, start_pfn, iova_len); +} + +void +init_iova_domain(struct iova_domain *iovad, unsigned long granule, + unsigned long start_pfn) +{ + __init_iova_domain(iovad, granule, start_pfn, 0); } EXPORT_SYMBOL_GPL(init_iova_domain); @@ -883,14 +897,17 @@ bool iova_domain_len_is_cached(struct iova_domain *iovad, unsigned long iova_len return iova_len_to_rcache_max(iova_len) == iovad->rcache_max_size; } -static void init_iova_rcaches(struct iova_domain *iovad) +static void init_iova_rcaches(struct iova_domain *iovad, unsigned long iova_len) { struct iova_cpu_rcache *cpu_rcache; struct iova_rcache *rcache; unsigned int cpu; int i; - iovad->rcache_max_size = IOVA_RANGE_CACHE_MAX_SIZE; + if (iova_len) + iovad->rcache_max_size = iova_len_to_rcache_max(iova_len); + else + iovad->rcache_max_size = IOVA_RANGE_CACHE_MAX_SIZE; iovad->rcaches = kcalloc(iovad->rcache_max_size, sizeof(*iovad->rcaches), GFP_KERNEL); diff --git a/include/linux/iova.h b/include/linux/iova.h index 04cc8eb6de38..cfe416b6a8c7 100644 --- a/include/linux/iova.h +++ b/include/linux/iova.h @@ -154,6 +154,8 @@ struct iova *reserve_iova(struct iova_domain *iovad, unsigned long pfn_lo, unsigned long pfn_hi); void init_iova_domain(struct iova_domain *iovad, unsigned long granule, unsigned long start_pfn); +void init_iova_domain_ext(struct iova_domain *iovad, unsigned long granule, + unsigned long start_pfn, unsigned long iova_len); int init_iova_flush_queue(struct iova_domain *iovad, iova_flush_cb flush_cb, iova_entry_dtor entry_dtor); struct iova *find_iova(struct iova_domain *iovad, unsigned long pfn); @@ -222,6 +224,13 @@ static inline void init_iova_domain(struct iova_domain *iovad, { } +static inline void init_iova_domain_ext(struct iova_domain *iovad, + unsigned long granule, + unsigned long start_pfn, + unsigned long iova_len) +{ +} + static inline int init_iova_flush_queue(struct iova_domain *iovad, iova_flush_cb flush_cb, iova_entry_dtor entry_dtor) From patchwork Mon May 10 14:17:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 433157 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp2896434jao; Mon, 10 May 2021 07:27:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKzD/s+oxJ81bvH6NinPzQ6kgmiA0IpCpDnxKoj+/LJtvCIYNFFrv+4vAwWB9gp1w0pkYZ X-Received: by 2002:a02:7110:: with SMTP id n16mr21719032jac.69.1620656834572; Mon, 10 May 2021 07:27:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620656834; cv=none; d=google.com; s=arc-20160816; b=GIWjNUX7e/aj3I73+CExW2lKWZzFQcRhtI5ocYEL8JFanHH0n+1IYl4rkZf+Nv86il ae3q98z6H7Ga94SpTcNwqDjEvO8PF7EtvUFCXVDlVOrCVl8Fv2KPrAqaESET18Mqltd2 PLrof2x2HdEXip3krC4w67ccbQlH19xW9EqiT+BKekHYjWtrwMs0dR3TFby//di5Yn4X wew/OIcF0m6frorDwhS9XNyPHPiEF+Pwr2H8d2381pdXC0wHfjo5dY9xEgFjeMEYi3Wp wIxm1PP9k5ZwesCSVRhS3LypBxjzDFbRD3/zQXiXAB9rA2Laf8Tx/e13QuLdnRDNbS+4 IugA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=/32nLBDRL8jKTEMjozf/nnNTt9LaEOB0GtMFOdJwa68=; b=ZzfoDKuxgq1CvbJaFSzAfbZoFLv5fDNBWjo/HtgxyApl8TlSSQtpD2NWAR0baokoxk yudnAxV9L1XMbcPvuGkT54Dp3U7EcbJVFNUf/PtLP6HQg1G+efYhiIgwxp8x9pkfijdf Rzc0GgFBscQ0SGYim+njcHhNKpFK3a8qGw0Pt+6lcZxTqoHNrS2x5O3NcQoHOkxR4LiX 5RC+fLLfNuB7fMV6bTXW0hO9xBXhi198NdqTkEyQPCqBSm7LvOknb0IoVHDo7AoIAwda JrAYU758Xjd4wW/MCBESmDEeSed6ubQ+x5uk1s6sbW9+quK4ojNDMVHrryD5g54mb5YD T91A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si13610863ilr.121.2021.05.10.07.27.14 for ; Mon, 10 May 2021 07:27:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238232AbhEJO2R (ORCPT ); Mon, 10 May 2021 10:28:17 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2680 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238906AbhEJOZr (ORCPT ); Mon, 10 May 2021 10:25:47 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Ff39B5PH8z1BKwK; Mon, 10 May 2021 22:19:58 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Mon, 10 May 2021 22:22:27 +0800 From: John Garry To: , , , , CC: , , , , , , John Garry Subject: [PATCH v2 10/15] dma-iommu: Use init_iova_domain_ext() for IOVA domain init Date: Mon, 10 May 2021 22:17:24 +0800 Message-ID: <1620656249-68890-11-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1620656249-68890-1-git-send-email-john.garry@huawei.com> References: <1620656249-68890-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Pass the max opt iova len to init the IOVA domain, if set. Signed-off-by: John Garry --- drivers/iommu/dma-iommu.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) -- 2.26.2 diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 4fb82c554ede..574d7a901fd2 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -358,6 +358,8 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base, struct iommu_dma_cookie *cookie = domain->iova_cookie; unsigned long order, base_pfn; struct iova_domain *iovad; + size_t max_opt_dma_size; + unsigned long iova_len; if (!cookie || cookie->type != IOMMU_DMA_IOVA_COOKIE) return -EINVAL; @@ -391,7 +393,18 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base, return 0; } - init_iova_domain(iovad, 1UL << order, base_pfn); + max_opt_dma_size = iommu_group_get_max_opt_dma_size(dev->iommu_group); + + if (max_opt_dma_size) { + unsigned long shift = __ffs(1UL << order); + + iova_len = max_opt_dma_size >> shift; + iova_len = roundup_pow_of_two(iova_len); + } else { + iova_len = 0; + } + + init_iova_domain_ext(iovad, 1UL << order, base_pfn, iova_len); if (!cookie->fq_domain && (!dev || !dev_is_untrusted(dev)) && domain->ops->flush_iotlb_all && !iommu_get_dma_strict(domain)) { From patchwork Mon May 10 14:17:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 433156 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp2896425jao; Mon, 10 May 2021 07:27:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDbsPZY0M0DxSgIpKphOJMkIKpeWz9NBvpB/zNjPBjUrcjciW9Vd6mUVAMCXnnk8XfEgse X-Received: by 2002:a05:6e02:102:: with SMTP id t2mr23229599ilm.182.1620656833716; Mon, 10 May 2021 07:27:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620656833; cv=none; d=google.com; s=arc-20160816; b=VszkeUboggd7y0JvjNbjJXK4KKra3EMEJ/P3FEaZ3mRmFfqVZraxJo2+e3RjWn9KkK dM8w8u6FR7pSavBSkMssBuxrkcayPqVzAj8jppmrwbiIkpqwg78VAmCGBV2jznm8awJM 0dT8ertFK4vT4oIUKlcn1eaoHt7iWRD22NobsQ99P6EyfgoP2WT6dn53e69r8L2n9/oZ tljFIPu0oCTUviXzFsMKyYw2or5mh4jWT/k3HmwkhhiaFtgr1Db9Q507XlCBZzS9yBGF bAcaos5Y2qd58fn8IorfKPyhTIyYMMWv3c9xo2kvDPcsHhL0zVX5Aa73E9C2DhSv2H7z Qc6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=SzCYQZ/VBH1JsO6cMEhAmAAnS29aBCeeOLJ6f21e8GQ=; b=A8Pi5lfGypJLpSjbtD7f4+AHv2dDm8HVxMAt+t4/fq3flA7dBt+yuE1xdiYEphDhA6 N+oL9QgNDbmLbXtcOqPhbhy9GzBNyz5Z2mex1D5fLrDLrdBjsnrUXBBocN2+e6XR1t7E EhMyhlGAYF8BQxDSCQ02k/7LUPs+Nah595Or9gyx/oAwINw5nuB0j0zqR0A/OQWrthS5 u3hFwjjbS+Jfj5769foIvRYOk8bqEQySs/7gAthcWtfBQWggkOyiOOylf557dpKltypt OnSVBFUkzQJxYc9EKH7I8NW/3as1fPv1p6A0X5Bx6xVr/YA0MC5CN1dbGUuVa8X7dpTQ Lxbg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si13610863ilr.121.2021.05.10.07.27.13 for ; Mon, 10 May 2021 07:27:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241702AbhEJO2Q (ORCPT ); Mon, 10 May 2021 10:28:16 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2682 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238913AbhEJOZs (ORCPT ); Mon, 10 May 2021 10:25:48 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Ff39B6D7Yz1BKw3; Mon, 10 May 2021 22:19:58 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Mon, 10 May 2021 22:22:27 +0800 From: John Garry To: , , , , CC: , , , , , , John Garry Subject: [PATCH v2 11/15] dma-iommu: Reconfig group domain Date: Mon, 10 May 2021 22:17:25 +0800 Message-ID: <1620656249-68890-12-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1620656249-68890-1-git-send-email-john.garry@huawei.com> References: <1620656249-68890-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Call iommu_reconfig_dev_group_dma() from iommu_setup_dma_ops() to reconfig the group domain, if necessary. Signed-off-by: John Garry --- drivers/iommu/dma-iommu.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.26.2 diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 574d7a901fd2..1d58c7a2d85d 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -1358,6 +1358,9 @@ void iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 size) * underlying IOMMU driver needs to support via the dma-iommu layer. */ if (domain->type == IOMMU_DOMAIN_DMA) { + iommu_reconfig_dev_group_dma(dev); + /* domain may be stale ... */ + domain = iommu_get_domain_for_dev(dev); if (iommu_dma_init_domain(domain, dma_base, size, dev)) goto out_err; dev->dma_ops = &iommu_dma_ops; From patchwork Mon May 10 14:17:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 433148 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp2895365jao; Mon, 10 May 2021 07:25:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtUDl0MJRgI8Mgx+XWA5ZHmfob2taeviXshLU8DfaMeaI6HhZPdH+gp2jnf5GUgqdULZJY X-Received: by 2002:a05:6e02:1a49:: with SMTP id u9mr23475861ilv.306.1620656753703; Mon, 10 May 2021 07:25:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620656753; cv=none; d=google.com; s=arc-20160816; b=o7h8P5hRmFsgUpWBh//VNXioxUd4Dzigdq5FL9Aa0tjVD42AzRIjMJWpGcpv8ES+H0 L9enHh+SFHutX7gvZ99om1+QrEC8yHAVRi0LpR3u+jphdJWYET6AF7RCl35Trw21yCBL phazVybqFeK3ju3SGS2avqitx682vR2rFEqVlK9wuDkGvmRlKHO40Ra5HLOzg55Tso4X Z+tw3z9AijqODMoXfRD6tOfGu3H8MZg30WtIR4qGQ/Xb0QvVhEvn7rTO1Kl5X9txNa11 TyX0ubNAu/3+lvntcimU3fjNPGmSr12lwDkTlEHaUem2uHuYVlF4+nHW+VQveIKLryNT cNBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=JPJ83FhwamrjcZOdepavjxeI4Bkw8WDG5Uy4q7hEA5Y=; b=Exj7oXT8VCDwaD6+Yp0zS+cz+C9tTIJ/Kv17u42/iY+hwgjupLEj2R6lXoccVcEFGb 2quxdHH9NVOWi19H5CPrtEAHgm4HEmd99EDPmQ9gLNVPaLXsWDfNw0lAiRaIYiTawgG0 Rteh4cCxg4R3Nq++eFaA2tm+6v613k5c1xYwRmdiUccDtFn0nxcWFFD0mzr8VB/XBc5M LouB+Do5tA5OONZkYa4qm3CighYZEeoeBd5ckFh2XCGqV00ehXmg8MXP/awVPTUeJE8Q vgDtNzd4jpItdKbAYiTVQTrvpHEj4nTQalyoYeBfmybeMevl8Uu6IuzgsLfa+p9Jd7g+ E6+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g19si19729924jat.91.2021.05.10.07.25.53 for ; Mon, 10 May 2021 07:25:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235100AbhEJO04 (ORCPT ); Mon, 10 May 2021 10:26:56 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2677 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235260AbhEJOXq (ORCPT ); Mon, 10 May 2021 10:23:46 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Ff39B4pCWz1BKvy; Mon, 10 May 2021 22:19:58 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Mon, 10 May 2021 22:22:28 +0800 From: John Garry To: , , , , CC: , , , , , , John Garry Subject: [PATCH v2 12/15] iommu: Add iommu_set_dev_dma_opt_size() Date: Mon, 10 May 2021 22:17:26 +0800 Message-ID: <1620656249-68890-13-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1620656249-68890-1-git-send-email-john.garry@huawei.com> References: <1620656249-68890-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add a function which allows the max optimised IOMMU DMA size to be set. When set successfully, return -EPROBE_DEFER to inform the caller that the device driver needs to be reprobed to take effect. Signed-off-by: John Garry --- drivers/iommu/iommu.c | 47 +++++++++++++++++++++++++++++++++++++++++++ include/linux/iommu.h | 7 +++++++ 2 files changed, 54 insertions(+) -- 2.26.2 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index bdb9aa47dfca..263d78e26c48 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3058,6 +3058,53 @@ u32 iommu_sva_get_pasid(struct iommu_sva *handle) } EXPORT_SYMBOL_GPL(iommu_sva_get_pasid); +int iommu_set_dev_dma_opt_size(struct device *dev, size_t size) +{ + struct iommu_group *group = iommu_group_get(dev); + struct group_device *grp_dev; + struct device *_dev; + int ret, group_count; + + if (!group) + return 0; + + mutex_lock(&group->mutex); + + /* + * If already set, then ignore. We may have been set via sysfs, so + * honour that. + */ + if (group->max_opt_dma_size) { + ret = 0; + goto out; + } + + group_count = iommu_group_device_count(group); + if (group_count != 1) { + dev_err_ratelimited(dev, "Cannot change DMA opt size: Group has more than one device group_count=%d\n", + group_count); + ret = -EINVAL; + goto out; + } + + /* Since group has only one device */ + grp_dev = list_first_entry(&group->devices, struct group_device, list); + _dev = grp_dev->dev; + + if (_dev != dev) { + dev_err_ratelimited(dev, "Cannot set DMA max opt size - device has changed\n"); + ret = -EBUSY; + goto out; + } + + group->max_opt_dma_size = size; + ret = -EPROBE_DEFER; +out: + mutex_unlock(&group->mutex); + iommu_group_put(group); + return ret; +} + /* * Changes the default domain of an iommu group that has *only* one device * diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 6e187746af0f..36871e8ae636 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -428,6 +428,7 @@ extern void iommu_get_resv_regions(struct device *dev, struct list_head *list); extern void iommu_put_resv_regions(struct device *dev, struct list_head *list); extern void generic_iommu_put_resv_regions(struct device *dev, struct list_head *list); +extern int iommu_set_dev_dma_opt_size(struct device *dev, size_t size); extern void iommu_set_default_passthrough(bool cmd_line); extern void iommu_set_default_translated(bool cmd_line); extern bool iommu_default_passthrough(void); @@ -740,6 +741,12 @@ static inline int iommu_get_group_resv_regions(struct iommu_group *group, return -ENODEV; } +static inline int iommu_set_dev_dma_opt_size(struct device *dev, + size_t size) +{ + return -ENODEV; +} + static inline void iommu_set_default_passthrough(bool cmd_line) { } From patchwork Mon May 10 14:17:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 433145 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp2895213jao; Mon, 10 May 2021 07:25:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxoM3W6fAfV1KyrskhNtvNEg9YaqbF9/TkWzqorbiIGpiLFWmizyHtftuERnxUzRVEGWT+ X-Received: by 2002:a92:2a12:: with SMTP id r18mr21413006ile.170.1620656745456; Mon, 10 May 2021 07:25:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620656745; cv=none; d=google.com; s=arc-20160816; b=kTi1EUz23fQOjCuYzlnFt2usbK0X7FCCbGcv4SlNqLBIjN6zFaQPcv2sFtWkU+sJQb YtlvF46s4mzTays428legngn9Rx4oDFX3olUG9BsNRXA5/tNvWydQrD93iszUSkxIuLw /myjZhG5ZfhllQAY0qAwkpkd7a4/SFm4K/hCfWbNslb3Uj2NqMwwxORDEPK2MeuXKcVE LBkaYEHV/qnpTaLJd4G/bQ+XLP+QqUgOyBujgRcm4/YJYr/ABHhoMZ3NuiL2jN9330bV Wx/Ev7c2L8ghiGi4ZIJWVq7KfGNC+Z/iR5uRrhtv5x4Vwmz/ixZRIMyevSoGa0L+if+d EXZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=So/e+f3iqa0YCU0ukfuZrV7EnxP1XudXwqwF5ltFSOA=; b=VLzVrR6q2L1LpwQW+CHH6r1ztYRSuQLI7tk5T8pJnNPMxE2ntqjksDga8YQZWb6csN 36JqHX+54zgeH4NbATyuGJ1LOvzhnCQ1Vg+mVIt434Nrs0Mc+NQ6VMclzpHMrp+sJyyT 0AX0Z2bu4FLHLkeIWAjKBLC9yzvqArzgZT44M+Ifj+iY6fF8dx7YytojpIMzrHSrZBzj NjY4K/RX42Z8vbpfqFGc/juXcvA/k4Ni1lAwsbOgbYj1mxGKn8EEe73zzcER2LiptcoU mLffOmC8XFk9ZgvO3kFjzY3f6pXLPRRX1KPQzscQfvyNVog8k8zBSYFbveV3jMS7aqSF Ze+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k8si18487873jav.68.2021.05.10.07.25.45 for ; Mon, 10 May 2021 07:25:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232976AbhEJO0s (ORCPT ); Mon, 10 May 2021 10:26:48 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2678 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235417AbhEJOXq (ORCPT ); Mon, 10 May 2021 10:23:46 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Ff39B55RDz1BKvf; Mon, 10 May 2021 22:19:58 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Mon, 10 May 2021 22:22:28 +0800 From: John Garry To: , , , , CC: , , , , , , John Garry Subject: [PATCH v2 13/15] dma-mapping: Add dma_set_max_opt_size() Date: Mon, 10 May 2021 22:17:27 +0800 Message-ID: <1620656249-68890-14-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1620656249-68890-1-git-send-email-john.garry@huawei.com> References: <1620656249-68890-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add a function to allow the max size which we want to optimise DMA mappings for. Signed-off-by: John Garry --- include/linux/dma-map-ops.h | 1 + include/linux/dma-mapping.h | 8 ++++++++ kernel/dma/mapping.c | 11 +++++++++++ 3 files changed, 20 insertions(+) -- 2.26.2 diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h index 0d53a96a3d64..7f9857da87d8 100644 --- a/include/linux/dma-map-ops.h +++ b/include/linux/dma-map-ops.h @@ -69,6 +69,7 @@ struct dma_map_ops { u64 (*get_required_mask)(struct device *dev); size_t (*max_mapping_size)(struct device *dev); unsigned long (*get_merge_boundary)(struct device *dev); + int (*set_max_opt_size)(struct device *dev, size_t size); }; #ifdef CONFIG_DMA_OPS diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 183e7103a66d..41681db93580 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -153,6 +153,7 @@ void *dma_vmap_noncontiguous(struct device *dev, size_t size, void dma_vunmap_noncontiguous(struct device *dev, void *vaddr); int dma_mmap_noncontiguous(struct device *dev, struct vm_area_struct *vma, size_t size, struct sg_table *sgt); +int dma_set_max_opt_size(struct device *dev, size_t size); #else /* CONFIG_HAS_DMA */ static inline dma_addr_t dma_map_page_attrs(struct device *dev, struct page *page, size_t offset, size_t size, @@ -266,6 +267,7 @@ static inline unsigned long dma_get_merge_boundary(struct device *dev) { return 0; } + static inline struct sg_table *dma_alloc_noncontiguous(struct device *dev, size_t size, enum dma_data_direction dir, gfp_t gfp, unsigned long attrs) @@ -289,6 +291,12 @@ static inline int dma_mmap_noncontiguous(struct device *dev, { return -EINVAL; } + +static inline int dma_set_max_opt_size(struct device *dev, size_t size) +{ + return -EINVAL; +} + #endif /* CONFIG_HAS_DMA */ struct page *dma_alloc_pages(struct device *dev, size_t size, diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index 2b06a809d0b9..1e4820b08f7e 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -736,3 +736,14 @@ unsigned long dma_get_merge_boundary(struct device *dev) return ops->get_merge_boundary(dev); } EXPORT_SYMBOL_GPL(dma_get_merge_boundary); + +int dma_set_max_opt_size(struct device *dev, size_t size) +{ + const struct dma_map_ops *ops = get_dma_ops(dev); + + if (!ops || !ops->set_max_opt_size) + return 0; + + return ops->set_max_opt_size(dev, size); +} +EXPORT_SYMBOL_GPL(dma_set_max_opt_size); From patchwork Mon May 10 14:17:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 433154 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp2896362jao; Mon, 10 May 2021 07:27:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsUqDEtAd0MlpRYVCT2neSw9E+BA1cRgX7LvAwN29mNFPKrEf16s3Mxwys46FPGQSPZwmR X-Received: by 2002:a6b:c889:: with SMTP id y131mr18329478iof.196.1620656829551; Mon, 10 May 2021 07:27:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620656829; cv=none; d=google.com; s=arc-20160816; b=RY8C88VmVsrFAP2iMCAD950fEaMN3H9caqa7gFhudS29SaMm21P2sgeMPhgc14gcYG bEfikeqPYKHaEjmAPMwoglIuFBlTgcqU5X2Gqa3uqLJqi4D6F2UmeRXYnMjt/1PwS5GF mXe4CYpWBHgiahb+1JN98/pkmSCO0bGuUS0UWuN2uOfHiU60H/Phbr2V5SjZiKXPNdkv rhHXzdvfLPDxCHJaUbrwmKn5HbI0UNzdxjf7Fxtaih6gstXzE2FVL7+MtqP8U9fnE8ES tOcx5rYwpRjhMR0DdwWXkYkRPyslHF3FXUjvlmf0ptJNnXxTGSTNj8Yyiprb5EIKn+ya gd9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=5FO8BU/SJLLPHrlQDlrkMRWeR8rPI98kI3+U2DnClxM=; b=WtuTLVHZPTszX7j7a5zSWDdB9ir00evXHILiJy3jDaPA5Y3B7F1SSp6chqlyENxDfO 367diSkkPzHh41ZhlyFQoUAG9YdbXEEnlJ5sJzizEFWmkQrJ/TL/jYdCVTjl2MGA/fte zhqoRTJKJ3EsM7jjQ3XV8FgOGkMplEbXqwS+b8bVL+2i73iAZsJMdKT+tCAhSkNjpvnq KwDL2QKxoIh7UUD13H/bFT0hwKji2AonGjCjdGDrlsMuq0SFzfYPv4CYbGCXcaK4BHSM ifdhsqSqcD/e0N1vEx7ZIGA30qdPxkIxys5ni7P9SgazMXvqDKtQglbVIPwAAO2f4gJV oX+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si13610863ilr.121.2021.05.10.07.27.09 for ; Mon, 10 May 2021 07:27:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231623AbhEJO2I (ORCPT ); Mon, 10 May 2021 10:28:08 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2681 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238914AbhEJOZs (ORCPT ); Mon, 10 May 2021 10:25:48 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Ff39B5yJgz1BKwN; Mon, 10 May 2021 22:19:58 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Mon, 10 May 2021 22:22:28 +0800 From: John Garry To: , , , , CC: , , , , , , John Garry Subject: [PATCH v2 14/15] dma-iommu: Add iommu_dma_set_opt_size() Date: Mon, 10 May 2021 22:17:28 +0800 Message-ID: <1620656249-68890-15-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1620656249-68890-1-git-send-email-john.garry@huawei.com> References: <1620656249-68890-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add iommu_dma_set_opt_size(), which is a frontend for iommu_set_dev_dma_opt_size(). Signed-off-by: John Garry --- drivers/iommu/dma-iommu.c | 6 ++++++ 1 file changed, 6 insertions(+) -- 2.26.2 diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 1d58c7a2d85d..fd62afe7c7d0 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -490,6 +490,11 @@ static dma_addr_t iommu_dma_alloc_iova(struct iommu_domain *domain, return (dma_addr_t)iova << shift; } +static int iommu_dma_set_opt_size(struct device *dev, size_t size) +{ + return iommu_set_dev_dma_opt_size(dev, size); +} + static void iommu_dma_free_iova(struct iommu_dma_cookie *cookie, dma_addr_t iova, size_t size, struct page *freelist) { @@ -1340,6 +1345,7 @@ static const struct dma_map_ops iommu_dma_ops = { .map_resource = iommu_dma_map_resource, .unmap_resource = iommu_dma_unmap_resource, .get_merge_boundary = iommu_dma_get_merge_boundary, + .set_max_opt_size = iommu_dma_set_opt_size, }; /* From patchwork Mon May 10 14:17:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 433151 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp2895853jao; Mon, 10 May 2021 07:26:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlh2Uo5SwjerFX5aESU6RRy+Xdc0Bt6iZxSu+HbATm+M2GUQ4njbHRyms8M5VnkD4kwK+I X-Received: by 2002:a05:6602:280d:: with SMTP id d13mr11290557ioe.90.1620656787481; Mon, 10 May 2021 07:26:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620656787; cv=none; d=google.com; s=arc-20160816; b=sUsYouHu4impY8MZEO8mReujlmC6ptNeefEIKVs1nDwYhW5xTzeGZ0QFM9hDPTzarj ZFEouEEEly906FZ9XZmcsX6r2Y3ba+MBVw9ZzWV8yTUbwpcphoePwjmBCKSyeIobWH3K rcUg3hhP2l/6+frd2ATXLA6IrocA1UVRPt1U1cb0wtHibb7ajDO+NcXt59oCzi5+v8rS iMINOAhGvTm7QB/QiV88fGw9HzFHYq/FLnCQXQ76UAgzABuPc2wBcfq68PjsEH1ygDOr 39K4mLVA9DKdG76Vxrz8H8O635x8N3nnL+Yl79Jp31ed8mLgQSXIGoUU0ANosnEnfppk B2ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=1XDm/gOGP5lgju4tzG89B+PyEXUN/jGKmIQbMYBaucg=; b=tCJsoMH5uFrK8KtTtQejxn+4cYwqxA3NY40w9mj4aY5O2Pv/sEB4ZazKtPr+52nX6T t62eOE3Ob4RfnlLYT1iHBuPae7LxSWywf5paSlWYcHZzgyTj/KcfZ+bRw05QSH7RWjFT vurCH36TUrWt2InVHM4DhadhZ68r2LHLBJ4Krfscev8aN6ZUyq6EFcDLlzUehxFQCPXk OomIyuBjNDGsypIyqT+EyTAe/b878l+yyHMN/IVJrRIwYFpp17shUXXkzwapHdvrIOGy nAUF0/QbUlJXHpVW9VejMFrXPgBH0VlpgE6a6uyTBqq6RnpyIyKJFQjh64m3I5kODUhm 25cQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si13610863ilr.121.2021.05.10.07.26.27 for ; Mon, 10 May 2021 07:26:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236682AbhEJO1B (ORCPT ); Mon, 10 May 2021 10:27:01 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2674 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235418AbhEJOXq (ORCPT ); Mon, 10 May 2021 10:23:46 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Ff39B2V5Hz1BKmS; Mon, 10 May 2021 22:19:58 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Mon, 10 May 2021 22:22:29 +0800 From: John Garry To: , , , , CC: , , , , , , John Garry Subject: [PATCH v2 15/15] scsi: hisi_sas: Set max optimal DMA size for v3 hw Date: Mon, 10 May 2021 22:17:29 +0800 Message-ID: <1620656249-68890-16-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1620656249-68890-1-git-send-email-john.garry@huawei.com> References: <1620656249-68890-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org For IOMMU strict mode, gives a big performance boost in some scenarios. Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.26.2 diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c index 499c770d405c..365fc9de4be2 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c @@ -4675,6 +4675,11 @@ hisi_sas_v3_probe(struct pci_dev *pdev, const struct pci_device_id *id) struct sas_ha_struct *sha; int rc, phy_nr, port_nr, i; + rc = dma_set_max_opt_size(dev, PAGE_SIZE * HISI_SAS_SGE_PAGE_CNT); + /* We can live with other errors */ + if (rc == -EPROBE_DEFER) + return rc; + rc = pci_enable_device(pdev); if (rc) goto err_out;