From: John Garry <john.garry@huawei.com> To: <joro@8bytes.org>, <will@kernel.org>, <robin.murphy@arm.com>, <baolu.lu@linux.intel.com> Cc: <iommu@lists.linux-foundation.org>, <linuxarm@huawei.com>, <thierry.reding@gmail.com>, <airlied@linux.ie>, <daniel@ffwll.ch>, <jonathanh@nvidia.com>, <sakari.ailus@linux.intel.com>, <bingbu.cao@intel.com>, <tian.shu.qiu@intel.com>, <mchehab@kernel.org>, <gregkh@linuxfoundation.org>, <digetx@gmail.com>, <mst@redhat.com>, <jasowang@redhat.com>, <linux-kernel@vger.kernel.org>, <chenxiang66@hisilicon.com>, John Garry <john.garry@huawei.com> Subject: [PATCH v4 2/6] iova: Allow rcache range upper limit to be flexible Date: Wed, 14 Jul 2021 18:36:39 +0800 [thread overview] Message-ID: <1626259003-201303-3-git-send-email-john.garry@huawei.com> (raw) In-Reply-To: <1626259003-201303-1-git-send-email-john.garry@huawei.com> 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 <john.garry@huawei.com> --- drivers/iommu/dma-iommu.c | 2 +- drivers/iommu/iova.c | 23 +++++++++++++++++------ include/linux/iova.h | 4 ++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 98ba927aee1a..4772278aa5da 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -434,7 +434,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 b6cf5f16123b..07ce73fdd8c1 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); @@ -881,7 +883,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; @@ -956,7 +965,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); @@ -1012,7 +1021,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); @@ -1028,7 +1037,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); @@ -1039,6 +1048,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); } /* @@ -1051,7 +1062,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); @@ -1070,7 +1081,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) -- 2.26.2
WARNING: multiple messages have this Message-ID (diff)
From: John Garry <john.garry@huawei.com> To: <joro@8bytes.org>, <will@kernel.org>, <robin.murphy@arm.com>, <baolu.lu@linux.intel.com> Cc: linux-kernel@vger.kernel.org, sakari.ailus@linux.intel.com, mst@redhat.com, airlied@linux.ie, gregkh@linuxfoundation.org, jasowang@redhat.com, linuxarm@huawei.com, jonathanh@nvidia.com, iommu@lists.linux-foundation.org, thierry.reding@gmail.com, daniel@ffwll.ch, bingbu.cao@intel.com, digetx@gmail.com, mchehab@kernel.org, tian.shu.qiu@intel.com Subject: [PATCH v4 2/6] iova: Allow rcache range upper limit to be flexible Date: Wed, 14 Jul 2021 18:36:39 +0800 [thread overview] Message-ID: <1626259003-201303-3-git-send-email-john.garry@huawei.com> (raw) In-Reply-To: <1626259003-201303-1-git-send-email-john.garry@huawei.com> 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 <john.garry@huawei.com> --- drivers/iommu/dma-iommu.c | 2 +- drivers/iommu/iova.c | 23 +++++++++++++++++------ include/linux/iova.h | 4 ++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 98ba927aee1a..4772278aa5da 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -434,7 +434,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 b6cf5f16123b..07ce73fdd8c1 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); @@ -881,7 +883,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; @@ -956,7 +965,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); @@ -1012,7 +1021,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); @@ -1028,7 +1037,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); @@ -1039,6 +1048,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); } /* @@ -1051,7 +1062,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); @@ -1070,7 +1081,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) -- 2.26.2 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2021-07-14 10:42 UTC|newest] Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-14 10:36 [PATCH v4 0/6] iommu: Allow IOVA rcache range be configured John Garry 2021-07-14 10:36 ` John Garry 2021-07-14 10:36 ` [PATCH v4 1/6] iommu: Refactor iommu_group_store_type() John Garry 2021-07-14 10:36 ` John Garry 2021-08-02 14:46 ` Will Deacon 2021-08-02 14:46 ` Will Deacon 2021-07-14 10:36 ` John Garry [this message] 2021-07-14 10:36 ` [PATCH v4 2/6] iova: Allow rcache range upper limit to be flexible John Garry 2021-08-02 15:01 ` Will Deacon 2021-08-02 15:01 ` Will Deacon 2021-08-02 15:23 ` John Garry 2021-08-02 15:23 ` John Garry 2021-08-02 16:09 ` Robin Murphy 2021-08-02 16:09 ` Robin Murphy 2021-07-14 10:36 ` [PATCH v4 3/6] iommu: Allow iommu_change_dev_def_domain() realloc default domain for same type John Garry 2021-07-14 10:36 ` John Garry 2021-07-14 10:36 ` [PATCH v4 4/6] iommu: Allow max opt DMA len be set for a group via sysfs John Garry 2021-07-14 10:36 ` John Garry 2021-07-14 10:36 ` [PATCH v4 5/6] iova: Add iova_len argument to init_iova_domain() John Garry 2021-07-14 10:36 ` John Garry 2021-08-02 15:06 ` Will Deacon 2021-08-02 15:06 ` Will Deacon 2021-08-02 16:06 ` John Garry 2021-08-02 16:06 ` John Garry 2021-08-02 16:16 ` Robin Murphy 2021-08-02 16:16 ` Robin Murphy 2021-08-02 16:40 ` John Garry 2021-08-02 16:40 ` John Garry 2021-08-02 17:18 ` John Garry 2021-08-02 17:18 ` John Garry 2021-09-21 8:48 ` John Garry 2021-09-21 8:48 ` John Garry 2021-07-14 10:36 ` [PATCH v4 6/6] dma-iommu: Pass iova len for IOVA domain init John Garry 2021-07-14 10:36 ` John Garry 2021-07-15 1:36 kernel test robot 2021-07-19 7:58 ` Dan Carpenter 2021-07-19 7:58 ` Dan Carpenter 2021-07-19 9:12 ` John Garry 2021-07-19 9:12 ` John Garry 2021-07-19 9:32 ` Robin Murphy 2021-07-19 9:32 ` Robin Murphy 2021-07-19 10:45 ` John Garry 2021-07-19 10:45 ` John Garry
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1626259003-201303-3-git-send-email-john.garry@huawei.com \ --to=john.garry@huawei.com \ --cc=airlied@linux.ie \ --cc=baolu.lu@linux.intel.com \ --cc=bingbu.cao@intel.com \ --cc=chenxiang66@hisilicon.com \ --cc=daniel@ffwll.ch \ --cc=digetx@gmail.com \ --cc=gregkh@linuxfoundation.org \ --cc=iommu@lists.linux-foundation.org \ --cc=jasowang@redhat.com \ --cc=jonathanh@nvidia.com \ --cc=joro@8bytes.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linuxarm@huawei.com \ --cc=mchehab@kernel.org \ --cc=mst@redhat.com \ --cc=robin.murphy@arm.com \ --cc=sakari.ailus@linux.intel.com \ --cc=thierry.reding@gmail.com \ --cc=tian.shu.qiu@intel.com \ --cc=will@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.