All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/6] iommu: Allow IOVA rcache range be configured
@ 2021-07-14 10:36 ` John Garry
  0 siblings, 0 replies; 43+ messages in thread
From: John Garry @ 2021-07-14 10:36 UTC (permalink / raw)
  To: joro, will, robin.murphy, baolu.lu
  Cc: iommu, linuxarm, thierry.reding, airlied, daniel, jonathanh,
	sakari.ailus, bingbu.cao, tian.shu.qiu, mchehab, gregkh, digetx,
	mst, jasowang, linux-kernel, chenxiang66, John Garry

For streaming DMA mappings involving an IOMMU and whose IOVA len regularly
exceeds the IOVA rcache upper limit (meaning that they are not cached),
performance can be reduced. 

This may be much more pronounced from commit 4e89dce72521 ("iommu/iova:
Retry from last rb tree node if iova search fails"), as discussed at [0].

IOVAs which cannot be cached are highly involved in the IOVA ageing issue,
as discussed at [1].

This series allows the IOVA rcache range be configured, so that we may
cache all IOVAs per domain, thus improving performance.

A new IOMMU group sysfs file is added - max_opt_dma_size - which is used
indirectly to configure the IOVA rcache range:
/sys/kernel/iommu_groups/X/max_opt_dma_size

This file is updated same as how the IOMMU group default domain type is
updated, i.e. must unbind the only device in the group first.

The inspiration here comes from block layer request queue sysfs
"optimal_io_size" file, in /sys/block/sdX/queue/optimal_io_size

Some figures for storage scenario (when increasing IOVA rcache range to
cover all DMA mapping sizes from the LLD):
v5.13-rc1 baseline:			1200K IOPS
With series:				1800K IOPS

All above are for IOMMU strict mode. Non-strict mode gives ~1800K IOPS in
all scenarios.

[0] https://lore.kernel.org/linux-iommu/20210129092120.1482-1-thunder.leizhen@huawei.com/
[1] https://lore.kernel.org/linux-iommu/1607538189-237944-1-git-send-email-john.garry@huawei.com/

Note that I cc'ed maintainers/reviewers only for the changes associated
with patch #5 since it just touches their code in only a minor way.

John Garry (6):
  iommu: Refactor iommu_group_store_type()
  iova: Allow rcache range upper limit to be flexible
  iommu: Allow iommu_change_dev_def_domain() realloc default domain for
    same type
  iommu: Allow max opt DMA len be set for a group via sysfs
  iova: Add iova_len argument to init_iova_domain()
  dma-iommu: Pass iova len for IOVA domain init

 .../ABI/testing/sysfs-kernel-iommu_groups     |  16 ++
 drivers/gpu/drm/tegra/drm.c                   |   2 +-
 drivers/gpu/host1x/dev.c                      |   2 +-
 drivers/iommu/dma-iommu.c                     |  15 +-
 drivers/iommu/iommu.c                         | 172 ++++++++++++------
 drivers/iommu/iova.c                          |  39 +++-
 drivers/staging/media/ipu3/ipu3-dmamap.c      |   2 +-
 drivers/staging/media/tegra-vde/iommu.c       |   2 +-
 drivers/vdpa/vdpa_sim/vdpa_sim.c              |   2 +-
 include/linux/iommu.h                         |   6 +
 include/linux/iova.h                          |   9 +-
 11 files changed, 194 insertions(+), 73 deletions(-)

-- 
2.26.2


^ permalink raw reply	[flat|nested] 43+ messages in thread
* Re: [PATCH v4 6/6] dma-iommu: Pass iova len for IOVA domain init
  2021-07-14 10:36   ` John Garry
  (?)
@ 2021-07-19  7:58 ` Dan Carpenter
  -1 siblings, 0 replies; 43+ messages in thread
From: kernel test robot @ 2021-07-15  1:36 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 8704 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <1626259003-201303-7-git-send-email-john.garry@huawei.com>
References: <1626259003-201303-7-git-send-email-john.garry@huawei.com>
TO: John Garry <john.garry@huawei.com>
TO: joro(a)8bytes.org
TO: will(a)kernel.org
TO: robin.murphy(a)arm.com
TO: baolu.lu(a)linux.intel.com
CC: iommu(a)lists.linux-foundation.org
CC: linuxarm(a)huawei.com
CC: thierry.reding(a)gmail.com
CC: airlied(a)linux.ie
CC: daniel(a)ffwll.ch
CC: jonathanh(a)nvidia.com

Hi John,

I love your patch! Perhaps something to improve:

[auto build test WARNING on iommu/next]
[also build test WARNING on linuxtv-media/master tegra/for-next tegra-drm/drm/tegra/for-next linus/master v5.14-rc1 next-20210714]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/John-Garry/iommu-Allow-IOVA-rcache-range-be-configured/20210714-184328
base:   https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next
:::::: branch date: 15 hours ago
:::::: commit date: 15 hours ago
config: ia64-randconfig-m031-20210714 (attached as .config)
compiler: ia64-linux-gcc (GCC) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/iommu/dma-iommu.c:384 iommu_dma_init_domain() warn: variable dereferenced before check 'dev' (see line 374)

vim +/dev +384 drivers/iommu/dma-iommu.c

82c3cefb9f1652 Lu Baolu              2021-02-25  319  
0db2e5d18f76a6 Robin Murphy          2015-10-01  320  /**
0db2e5d18f76a6 Robin Murphy          2015-10-01  321   * iommu_dma_init_domain - Initialise a DMA mapping domain
0db2e5d18f76a6 Robin Murphy          2015-10-01  322   * @domain: IOMMU domain previously prepared by iommu_get_dma_cookie()
0db2e5d18f76a6 Robin Murphy          2015-10-01  323   * @base: IOVA at which the mappable address space starts
ac6d704679d343 Jean-Philippe Brucker 2021-06-18  324   * @limit: Last address of the IOVA space
fade1ec055dc6b Robin Murphy          2016-09-12  325   * @dev: Device the domain is being initialised for
0db2e5d18f76a6 Robin Murphy          2015-10-01  326   *
ac6d704679d343 Jean-Philippe Brucker 2021-06-18  327   * @base and @limit + 1 should be exact multiples of IOMMU page granularity to
0db2e5d18f76a6 Robin Murphy          2015-10-01  328   * avoid rounding surprises. If necessary, we reserve the page at address 0
0db2e5d18f76a6 Robin Murphy          2015-10-01  329   * to ensure it is an invalid IOVA. It is safe to reinitialise a domain, but
0db2e5d18f76a6 Robin Murphy          2015-10-01  330   * any change which could make prior IOVAs invalid will fail.
0db2e5d18f76a6 Robin Murphy          2015-10-01  331   */
06d60728ff5c01 Christoph Hellwig     2019-05-20  332  static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base,
ac6d704679d343 Jean-Philippe Brucker 2021-06-18  333  				 dma_addr_t limit, struct device *dev)
0db2e5d18f76a6 Robin Murphy          2015-10-01  334  {
fdbe574eb69312 Robin Murphy          2017-01-19  335  	struct iommu_dma_cookie *cookie = domain->iova_cookie;
c61a4633a56aaa Shaokun Zhang         2019-01-24  336  	unsigned long order, base_pfn;
6b0c54e7f27159 Yunsheng Lin          2019-08-24  337  	struct iova_domain *iovad;
de4ba360c3e4ed John Garry            2021-07-14  338  	size_t max_opt_dma_size;
de4ba360c3e4ed John Garry            2021-07-14  339  	unsigned long iova_len = 0;
0db2e5d18f76a6 Robin Murphy          2015-10-01  340  
fdbe574eb69312 Robin Murphy          2017-01-19  341  	if (!cookie || cookie->type != IOMMU_DMA_IOVA_COOKIE)
fdbe574eb69312 Robin Murphy          2017-01-19  342  		return -EINVAL;
0db2e5d18f76a6 Robin Murphy          2015-10-01  343  
6b0c54e7f27159 Yunsheng Lin          2019-08-24  344  	iovad = &cookie->iovad;
6b0c54e7f27159 Yunsheng Lin          2019-08-24  345  
0db2e5d18f76a6 Robin Murphy          2015-10-01  346  	/* Use the smallest supported page size for IOVA granularity */
d16e0faab911cc Robin Murphy          2016-04-07  347  	order = __ffs(domain->pgsize_bitmap);
0db2e5d18f76a6 Robin Murphy          2015-10-01  348  	base_pfn = max_t(unsigned long, 1, base >> order);
0db2e5d18f76a6 Robin Murphy          2015-10-01  349  
0db2e5d18f76a6 Robin Murphy          2015-10-01  350  	/* Check the domain allows at least some access to the device... */
0db2e5d18f76a6 Robin Murphy          2015-10-01  351  	if (domain->geometry.force_aperture) {
0db2e5d18f76a6 Robin Murphy          2015-10-01  352  		if (base > domain->geometry.aperture_end ||
ac6d704679d343 Jean-Philippe Brucker 2021-06-18  353  		    limit < domain->geometry.aperture_start) {
0db2e5d18f76a6 Robin Murphy          2015-10-01  354  			pr_warn("specified DMA range outside IOMMU capability\n");
0db2e5d18f76a6 Robin Murphy          2015-10-01  355  			return -EFAULT;
0db2e5d18f76a6 Robin Murphy          2015-10-01  356  		}
0db2e5d18f76a6 Robin Murphy          2015-10-01  357  		/* ...then finally give it a kicking to make sure it fits */
0db2e5d18f76a6 Robin Murphy          2015-10-01  358  		base_pfn = max_t(unsigned long, base_pfn,
0db2e5d18f76a6 Robin Murphy          2015-10-01  359  				domain->geometry.aperture_start >> order);
0db2e5d18f76a6 Robin Murphy          2015-10-01  360  	}
0db2e5d18f76a6 Robin Murphy          2015-10-01  361  
f51d7bb79c1124 Robin Murphy          2017-01-16  362  	/* start_pfn is always nonzero for an already-initialised domain */
0db2e5d18f76a6 Robin Murphy          2015-10-01  363  	if (iovad->start_pfn) {
0db2e5d18f76a6 Robin Murphy          2015-10-01  364  		if (1UL << order != iovad->granule ||
f51d7bb79c1124 Robin Murphy          2017-01-16  365  		    base_pfn != iovad->start_pfn) {
0db2e5d18f76a6 Robin Murphy          2015-10-01  366  			pr_warn("Incompatible range for DMA domain\n");
0db2e5d18f76a6 Robin Murphy          2015-10-01  367  			return -EFAULT;
0db2e5d18f76a6 Robin Murphy          2015-10-01  368  		}
7c1b058c8b5a31 Robin Murphy          2017-03-16  369  
7c1b058c8b5a31 Robin Murphy          2017-03-16  370  		return 0;
0db2e5d18f76a6 Robin Murphy          2015-10-01  371  	}
7c1b058c8b5a31 Robin Murphy          2017-03-16  372  
de4ba360c3e4ed John Garry            2021-07-14  373  
de4ba360c3e4ed John Garry            2021-07-14 @374  	max_opt_dma_size = iommu_group_get_max_opt_dma_size(dev->iommu_group);
de4ba360c3e4ed John Garry            2021-07-14  375  	if (max_opt_dma_size) {
de4ba360c3e4ed John Garry            2021-07-14  376  		unsigned long shift = __ffs(1UL << order);
de4ba360c3e4ed John Garry            2021-07-14  377  
de4ba360c3e4ed John Garry            2021-07-14  378  		iova_len = max_opt_dma_size >> shift;
de4ba360c3e4ed John Garry            2021-07-14  379  		iova_len = roundup_pow_of_two(iova_len);
de4ba360c3e4ed John Garry            2021-07-14  380  	}
de4ba360c3e4ed John Garry            2021-07-14  381  
de4ba360c3e4ed John Garry            2021-07-14  382  	init_iova_domain(iovad, 1UL << order, base_pfn, iova_len);
2da274cdf998a1 Zhen Lei              2018-09-20  383  
82c3cefb9f1652 Lu Baolu              2021-02-25 @384  	if (!cookie->fq_domain && (!dev || !dev_is_untrusted(dev)) &&
a250c23f15c21c Robin Murphy          2021-04-01  385  	    domain->ops->flush_iotlb_all && !iommu_get_dma_strict(domain)) {
b34e9b0de3c411 Tom Murphy            2020-09-10  386  		if (init_iova_flush_queue(iovad, iommu_dma_flush_iotlb_all,
2a2b8eaa5b2566 Tom Murphy            2020-11-24  387  					  iommu_dma_entry_dtor))
b34e9b0de3c411 Tom Murphy            2020-09-10  388  			pr_warn("iova flush queue initialization failed\n");
b34e9b0de3c411 Tom Murphy            2020-09-10  389  		else
2da274cdf998a1 Zhen Lei              2018-09-20  390  			cookie->fq_domain = domain;
2da274cdf998a1 Zhen Lei              2018-09-20  391  	}
2da274cdf998a1 Zhen Lei              2018-09-20  392  
7c1b058c8b5a31 Robin Murphy          2017-03-16  393  	if (!dev)
0db2e5d18f76a6 Robin Murphy          2015-10-01  394  		return 0;
7c1b058c8b5a31 Robin Murphy          2017-03-16  395  
7c1b058c8b5a31 Robin Murphy          2017-03-16  396  	return iova_reserve_iommu_regions(dev, domain);
0db2e5d18f76a6 Robin Murphy          2015-10-01  397  }
0db2e5d18f76a6 Robin Murphy          2015-10-01  398  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 36406 bytes --]

^ permalink raw reply	[flat|nested] 43+ messages in thread

end of thread, other threads:[~2021-09-21  8:45 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH v4 2/6] iova: Allow rcache range upper limit to be flexible John Garry
2021-07-14 10:36   ` 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

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.