All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v3 00/11] Use new dma-map IOVA alloc, link, and sync API in GPU SVM and DRM pagemap
@ 2026-01-28  0:48 Matthew Brost
  2026-01-28  0:48 ` [RFC PATCH v3 01/11] drm/pagemap: Add helper to access zone_device_data Matthew Brost
                   ` (13 more replies)
  0 siblings, 14 replies; 37+ messages in thread
From: Matthew Brost @ 2026-01-28  0:48 UTC (permalink / raw)
  To: intel-xe, dri-devel
  Cc: leonro, francois.dugast, thomas.hellstrom, himal.prasad.ghimiray,
	jgg

The dma-map IOVA alloc, link, and sync APIs perform significantly better
than dma-map / dma-unmap, as they avoid costly IOMMU synchronizations.
This difference is especially noticeable when mapping a 2MB region in
4KB pages.

Use dma-map IOVA alloc, link, and sync APIs for GPU SVM and DRM page,
which mappings between the CPU and GPU.

Initial results are promising.

Baseline CPU time during 2M / 64K fault with a migration:
Average migrate 2M cpu time (us, percentage): 552.36049107142857142857, .71943789893868318799
Average migrate 64K cpu time (us, percentage): 24.97767857142857142857, .34789908128526791960

After patch 4 in this series CPU time during 2M / 64K fault with a migration:
Average migrate 2M cpu time (us, percentage): 224.81808035714285714286, .51412827364772602557
Average migrate 64K cpu time (us, percentage): 14.65625000000000000000, .25659463050529524405

After patch 5 in this series CPU time during 2M / 64K fault with a migration:
Average migrate 2M cpu time (us, percentage): 158.52901785714285714286, .42740093699505625280
Average migrate 64K cpu time (us, percentage): 14.00000000000000000000, .23276613905846987437

- Patches 2-4 implement dma-map IOVA API for system pages

- Patch 5 optimizes this a bit but questionable if we need if this
  needed if 2M pages are enabled

- Patches 6-11 implement a IOVA API for multi-GPU PoC. I'm told drivers
  shouldn't call dma-map IOVA API for multi-device but including it as
  reference for a design we'd like to get to with high-speed fabrics in
  mind.

Still an RFC as patches 6-11 may not be able to merged in there current
form, the series can be split if needed to merge eariler patches.

Matt

v2:
 - Include missing basline patch for CI
v3:
 - Fix memory corruption
 - PoC IOVA alloc for multi-GPU

Francois Dugast (1):
  drm/pagemap: Add helper to access zone_device_data

Matthew Brost (10):
  drm/gpusvm: Use dma-map IOVA alloc, link, and sync API in GPU SVM
  drm/pagemap: Split drm_pagemap_migrate_map_pages into device / system
  drm/pagemap: Use dma-map IOVA alloc, link, and sync API for DRM
    pagemap
  drm/pagemap: Reduce number of IOVA link calls
  drm/pagemap: Add IOVA interface to DRM pagemap
  drm/xe: Stub out DRM pagemap IOVA alloc implementation
  drm/pagemap: Use device-to-device IOVA alloc, link, and sync API for
    DRM pagemap
  drm/xe: Drop BO dma-resv lock during SVM migrate-to-device
  drm/xe: Implement DRM pagemap IOVA vfuncs
  drm/gpusvm: Use device-to-device IOVA alloc, link, and sync API in GPU
    SVM

 drivers/gpu/drm/drm_gpusvm.c  | 196 ++++++++++++++++---
 drivers/gpu/drm/drm_pagemap.c | 351 +++++++++++++++++++++++++++-------
 drivers/gpu/drm/xe/xe_svm.c   | 143 +++++++++++++-
 include/drm/drm_gpusvm.h      |   5 +
 include/drm/drm_pagemap.h     | 101 ++++++++++
 5 files changed, 693 insertions(+), 103 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 37+ messages in thread
* Re: [RFC PATCH v3 02/11] drm/gpusvm: Use dma-map IOVA alloc, link, and sync API in GPU SVM
@ 2026-01-28 21:01 kernel test robot
  0 siblings, 0 replies; 37+ messages in thread
From: kernel test robot @ 2026-01-28 21:01 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp

:::::: 
:::::: Manual check reason: "__compiletime_assert_NNN"
:::::: 

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20260128004841.2436896-3-matthew.brost@intel.com>
References: <20260128004841.2436896-3-matthew.brost@intel.com>
TO: Matthew Brost <matthew.brost@intel.com>

Hi Matthew,

[This is a private test report for your RFC patch.]
kernel test robot noticed the following build errors:

[auto build test ERROR on drm-xe/drm-xe-next]
[also build test ERROR on drm/drm-next drm-tip/drm-tip next-20260128]
[cannot apply to drm-misc/drm-misc-next daeinki-drm-exynos/exynos-drm-next drm-i915/for-linux-next drm-i915/for-linux-next-fixes linus/master v6.19-rc7]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Matthew-Brost/drm-pagemap-Add-helper-to-access-zone_device_data/20260128-085843
base:   https://gitlab.freedesktop.org/drm/xe/kernel.git drm-xe-next
patch link:    https://lore.kernel.org/r/20260128004841.2436896-3-matthew.brost%40intel.com
patch subject: [RFC PATCH v3 02/11] drm/gpusvm: Use dma-map IOVA alloc, link, and sync API in GPU SVM
:::::: branch date: 20 hours ago
:::::: commit date: 20 hours ago
config: sparc64-randconfig-r052-20260128 (https://download.01.org/0day-ci/archive/20260129/202601290502.B5smBHPk-lkp@intel.com/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 9b8addffa70cee5b2acc5454712d9cf78ce45710)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260129/202601290502.B5smBHPk-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/r/202601290502.B5smBHPk-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/gpu/drm/drm_gpusvm.c:1566:10: error: call to '__compiletime_assert_340' declared with 'error' attribute: BUILD_BUG failed
    1566 |                                                    HPAGE_PMD_SIZE ?
         |                                                    ^
   include/linux/huge_mm.h:120:34: note: expanded from macro 'HPAGE_PMD_SIZE'
     120 | #define HPAGE_PMD_SIZE  ((1UL) << HPAGE_PMD_SHIFT)
         |                                   ^
   include/linux/huge_mm.h:113:28: note: expanded from macro 'HPAGE_PMD_SHIFT'
     113 | #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
         |                            ^
   include/linux/build_bug.h:59:21: note: expanded from macro 'BUILD_BUG'
      59 | #define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed")
         |                     ^
   note: (skipping 2 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler_types.h:619:2: note: expanded from macro '_compiletime_assert'
     619 |         __compiletime_assert(condition, msg, prefix, suffix)
         |         ^
   include/linux/compiler_types.h:612:4: note: expanded from macro '__compiletime_assert'
     612 |                         prefix ## suffix();                             \
         |                         ^
   <scratch space>:117:1: note: expanded from here
     117 | __compiletime_assert_340
         | ^
   1 error generated.


vim +1566 drivers/gpu/drm/drm_gpusvm.c

99624bdff867079 Matthew Brost         2025-03-05  1374  
99624bdff867079 Matthew Brost         2025-03-05  1375  /**
6364afd532bcabf Matthew Auld          2025-08-28  1376   * drm_gpusvm_get_pages() - Get pages and populate GPU SVM pages struct
99624bdff867079 Matthew Brost         2025-03-05  1377   * @gpusvm: Pointer to the GPU SVM structure
6364afd532bcabf Matthew Auld          2025-08-28  1378   * @svm_pages: The SVM pages to populate. This will contain the dma-addresses
6364afd532bcabf Matthew Auld          2025-08-28  1379   * @mm: The mm corresponding to the CPU range
6364afd532bcabf Matthew Auld          2025-08-28  1380   * @notifier: The corresponding notifier for the given CPU range
6364afd532bcabf Matthew Auld          2025-08-28  1381   * @pages_start: Start CPU address for the pages
6364afd532bcabf Matthew Auld          2025-08-28  1382   * @pages_end: End CPU address for the pages (exclusive)
99624bdff867079 Matthew Brost         2025-03-05  1383   * @ctx: GPU SVM context
99624bdff867079 Matthew Brost         2025-03-05  1384   *
6364afd532bcabf Matthew Auld          2025-08-28  1385   * This function gets and maps pages for CPU range and ensures they are
6364afd532bcabf Matthew Auld          2025-08-28  1386   * mapped for DMA access.
99624bdff867079 Matthew Brost         2025-03-05  1387   *
99624bdff867079 Matthew Brost         2025-03-05  1388   * Return: 0 on success, negative error code on failure.
99624bdff867079 Matthew Brost         2025-03-05  1389   */
83f706ecbde1dfd Matthew Auld          2025-08-28  1390  int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm,
6364afd532bcabf Matthew Auld          2025-08-28  1391  			 struct drm_gpusvm_pages *svm_pages,
6364afd532bcabf Matthew Auld          2025-08-28  1392  			 struct mm_struct *mm,
6364afd532bcabf Matthew Auld          2025-08-28  1393  			 struct mmu_interval_notifier *notifier,
83f706ecbde1dfd Matthew Auld          2025-08-28  1394  			 unsigned long pages_start, unsigned long pages_end,
99624bdff867079 Matthew Brost         2025-03-05  1395  			 const struct drm_gpusvm_ctx *ctx)
99624bdff867079 Matthew Brost         2025-03-05  1396  {
99624bdff867079 Matthew Brost         2025-03-05  1397  	struct hmm_range hmm_range = {
99624bdff867079 Matthew Brost         2025-03-05  1398  		.default_flags = HMM_PFN_REQ_FAULT | (ctx->read_only ? 0 :
99624bdff867079 Matthew Brost         2025-03-05  1399  			HMM_PFN_REQ_WRITE),
99624bdff867079 Matthew Brost         2025-03-05  1400  		.notifier = notifier,
6364afd532bcabf Matthew Auld          2025-08-28  1401  		.start = pages_start,
6364afd532bcabf Matthew Auld          2025-08-28  1402  		.end = pages_end,
ad298d9ec957414 Thomas Hellström      2025-09-30  1403  		.dev_private_owner = ctx->device_private_page_owner,
99624bdff867079 Matthew Brost         2025-03-05  1404  	};
f86ad0ed620cb3c Matthew Brost         2025-06-19  1405  	void *zdd;
99624bdff867079 Matthew Brost         2025-03-05  1406  	unsigned long timeout =
99624bdff867079 Matthew Brost         2025-03-05  1407  		jiffies + msecs_to_jiffies(HMM_RANGE_DEFAULT_TIMEOUT);
99624bdff867079 Matthew Brost         2025-03-05  1408  	unsigned long i, j;
6364afd532bcabf Matthew Auld          2025-08-28  1409  	unsigned long npages = npages_in_range(pages_start, pages_end);
99624bdff867079 Matthew Brost         2025-03-05  1410  	unsigned long num_dma_mapped;
99624bdff867079 Matthew Brost         2025-03-05  1411  	unsigned int order = 0;
99624bdff867079 Matthew Brost         2025-03-05  1412  	unsigned long *pfns;
70ea69ceed7db91 Matthew Brost         2026-01-27  1413  	phys_addr_t last_phys;
99624bdff867079 Matthew Brost         2025-03-05  1414  	int err = 0;
99624bdff867079 Matthew Brost         2025-03-05  1415  	struct dev_pagemap *pagemap;
99624bdff867079 Matthew Brost         2025-03-05  1416  	struct drm_pagemap *dpagemap;
f70da6f99d4f40c Matthew Auld          2025-08-28  1417  	struct drm_gpusvm_pages_flags flags;
ad70e289ed4b1f8 Matthew Auld          2025-08-28  1418  	enum dma_data_direction dma_dir = ctx->read_only ? DMA_TO_DEVICE :
ad70e289ed4b1f8 Matthew Auld          2025-08-28  1419  							   DMA_BIDIRECTIONAL;
70ea69ceed7db91 Matthew Brost         2026-01-27  1420  	struct dma_iova_state *state = &svm_pages->state;
99624bdff867079 Matthew Brost         2025-03-05  1421  
99624bdff867079 Matthew Brost         2025-03-05  1422  retry:
9fb1f1256e419fc Matthew Brost         2025-11-21  1423  	if (time_after(jiffies, timeout))
9fb1f1256e419fc Matthew Brost         2025-11-21  1424  		return -EBUSY;
9fb1f1256e419fc Matthew Brost         2025-11-21  1425  
99624bdff867079 Matthew Brost         2025-03-05  1426  	hmm_range.notifier_seq = mmu_interval_read_begin(notifier);
6364afd532bcabf Matthew Auld          2025-08-28  1427  	if (drm_gpusvm_pages_valid_unlocked(gpusvm, svm_pages))
99624bdff867079 Matthew Brost         2025-03-05  1428  		goto set_seqno;
99624bdff867079 Matthew Brost         2025-03-05  1429  
99624bdff867079 Matthew Brost         2025-03-05  1430  	pfns = kvmalloc_array(npages, sizeof(*pfns), GFP_KERNEL);
99624bdff867079 Matthew Brost         2025-03-05  1431  	if (!pfns)
99624bdff867079 Matthew Brost         2025-03-05  1432  		return -ENOMEM;
99624bdff867079 Matthew Brost         2025-03-05  1433  
99624bdff867079 Matthew Brost         2025-03-05  1434  	if (!mmget_not_zero(mm)) {
99624bdff867079 Matthew Brost         2025-03-05  1435  		err = -EFAULT;
99624bdff867079 Matthew Brost         2025-03-05  1436  		goto err_free;
99624bdff867079 Matthew Brost         2025-03-05  1437  	}
99624bdff867079 Matthew Brost         2025-03-05  1438  
99624bdff867079 Matthew Brost         2025-03-05  1439  	hmm_range.hmm_pfns = pfns;
99624bdff867079 Matthew Brost         2025-03-05  1440  	while (true) {
99624bdff867079 Matthew Brost         2025-03-05  1441  		mmap_read_lock(mm);
99624bdff867079 Matthew Brost         2025-03-05  1442  		err = hmm_range_fault(&hmm_range);
99624bdff867079 Matthew Brost         2025-03-05  1443  		mmap_read_unlock(mm);
99624bdff867079 Matthew Brost         2025-03-05  1444  
99624bdff867079 Matthew Brost         2025-03-05  1445  		if (err == -EBUSY) {
99624bdff867079 Matthew Brost         2025-03-05  1446  			if (time_after(jiffies, timeout))
99624bdff867079 Matthew Brost         2025-03-05  1447  				break;
99624bdff867079 Matthew Brost         2025-03-05  1448  
99624bdff867079 Matthew Brost         2025-03-05  1449  			hmm_range.notifier_seq =
99624bdff867079 Matthew Brost         2025-03-05  1450  				mmu_interval_read_begin(notifier);
99624bdff867079 Matthew Brost         2025-03-05  1451  			continue;
99624bdff867079 Matthew Brost         2025-03-05  1452  		}
99624bdff867079 Matthew Brost         2025-03-05  1453  		break;
99624bdff867079 Matthew Brost         2025-03-05  1454  	}
99624bdff867079 Matthew Brost         2025-03-05  1455  	mmput(mm);
99624bdff867079 Matthew Brost         2025-03-05  1456  	if (err)
99624bdff867079 Matthew Brost         2025-03-05  1457  		goto err_free;
99624bdff867079 Matthew Brost         2025-03-05  1458  
99624bdff867079 Matthew Brost         2025-03-05  1459  map_pages:
99624bdff867079 Matthew Brost         2025-03-05  1460  	/*
99624bdff867079 Matthew Brost         2025-03-05  1461  	 * Perform all dma mappings under the notifier lock to not
99624bdff867079 Matthew Brost         2025-03-05  1462  	 * access freed pages. A notifier will either block on
99624bdff867079 Matthew Brost         2025-03-05  1463  	 * the notifier lock or unmap dma.
99624bdff867079 Matthew Brost         2025-03-05  1464  	 */
99624bdff867079 Matthew Brost         2025-03-05  1465  	drm_gpusvm_notifier_lock(gpusvm);
99624bdff867079 Matthew Brost         2025-03-05  1466  
f70da6f99d4f40c Matthew Auld          2025-08-28  1467  	flags.__flags = svm_pages->flags.__flags;
a9ac0fa455b050d Matthew Brost         2025-05-12  1468  	if (flags.unmapped) {
99624bdff867079 Matthew Brost         2025-03-05  1469  		drm_gpusvm_notifier_unlock(gpusvm);
99624bdff867079 Matthew Brost         2025-03-05  1470  		err = -EFAULT;
99624bdff867079 Matthew Brost         2025-03-05  1471  		goto err_free;
99624bdff867079 Matthew Brost         2025-03-05  1472  	}
99624bdff867079 Matthew Brost         2025-03-05  1473  
99624bdff867079 Matthew Brost         2025-03-05  1474  	if (mmu_interval_read_retry(notifier, hmm_range.notifier_seq)) {
99624bdff867079 Matthew Brost         2025-03-05  1475  		drm_gpusvm_notifier_unlock(gpusvm);
99624bdff867079 Matthew Brost         2025-03-05  1476  		kvfree(pfns);
99624bdff867079 Matthew Brost         2025-03-05  1477  		goto retry;
99624bdff867079 Matthew Brost         2025-03-05  1478  	}
99624bdff867079 Matthew Brost         2025-03-05  1479  
f70da6f99d4f40c Matthew Auld          2025-08-28  1480  	if (!svm_pages->dma_addr) {
99624bdff867079 Matthew Brost         2025-03-05  1481  		/* Unlock and restart mapping to allocate memory. */
99624bdff867079 Matthew Brost         2025-03-05  1482  		drm_gpusvm_notifier_unlock(gpusvm);
f70da6f99d4f40c Matthew Auld          2025-08-28  1483  		svm_pages->dma_addr =
f70da6f99d4f40c Matthew Auld          2025-08-28  1484  			kvmalloc_array(npages, sizeof(*svm_pages->dma_addr), GFP_KERNEL);
f70da6f99d4f40c Matthew Auld          2025-08-28  1485  		if (!svm_pages->dma_addr) {
99624bdff867079 Matthew Brost         2025-03-05  1486  			err = -ENOMEM;
99624bdff867079 Matthew Brost         2025-03-05  1487  			goto err_free;
99624bdff867079 Matthew Brost         2025-03-05  1488  		}
99624bdff867079 Matthew Brost         2025-03-05  1489  		goto map_pages;
99624bdff867079 Matthew Brost         2025-03-05  1490  	}
99624bdff867079 Matthew Brost         2025-03-05  1491  
99624bdff867079 Matthew Brost         2025-03-05  1492  	zdd = NULL;
f86ad0ed620cb3c Matthew Brost         2025-06-19  1493  	pagemap = NULL;
99624bdff867079 Matthew Brost         2025-03-05  1494  	num_dma_mapped = 0;
99624bdff867079 Matthew Brost         2025-03-05  1495  	for (i = 0, j = 0; i < npages; ++j) {
99624bdff867079 Matthew Brost         2025-03-05  1496  		struct page *page = hmm_pfn_to_page(pfns[i]);
99624bdff867079 Matthew Brost         2025-03-05  1497  
c50729c68aaf936 Matthew Auld          2025-08-28  1498  		order = drm_gpusvm_hmm_pfn_to_order(pfns[i], i, npages);
99624bdff867079 Matthew Brost         2025-03-05  1499  		if (is_device_private_page(page) ||
99624bdff867079 Matthew Brost         2025-03-05  1500  		    is_device_coherent_page(page)) {
cfc101ad69846fc Francois Dugast       2026-01-27  1501  			struct drm_pagemap_zdd *__zdd =
cfc101ad69846fc Francois Dugast       2026-01-27  1502  				drm_pagemap_page_zone_device_data(page);
cfc101ad69846fc Francois Dugast       2026-01-27  1503  
bce13d6ecd6c0e6 Matthew Brost         2025-10-15  1504  			if (!ctx->allow_mixed &&
cfc101ad69846fc Francois Dugast       2026-01-27  1505  			    zdd != __zdd && i > 0) {
99624bdff867079 Matthew Brost         2025-03-05  1506  				err = -EOPNOTSUPP;
99624bdff867079 Matthew Brost         2025-03-05  1507  				goto err_unmap;
99624bdff867079 Matthew Brost         2025-03-05  1508  			}
70ea69ceed7db91 Matthew Brost         2026-01-27  1509  
70ea69ceed7db91 Matthew Brost         2026-01-27  1510  			if (dma_use_iova(state)) {
70ea69ceed7db91 Matthew Brost         2026-01-27  1511  				err = dma_iova_link(gpusvm->drm->dev, state,
70ea69ceed7db91 Matthew Brost         2026-01-27  1512  						    last_phys,
70ea69ceed7db91 Matthew Brost         2026-01-27  1513  						    i * PAGE_SIZE,
70ea69ceed7db91 Matthew Brost         2026-01-27  1514  						    PAGE_SIZE << order,
70ea69ceed7db91 Matthew Brost         2026-01-27  1515  						    dma_dir, 0);
70ea69ceed7db91 Matthew Brost         2026-01-27  1516  				if (err)
70ea69ceed7db91 Matthew Brost         2026-01-27  1517  					goto err_unmap;
70ea69ceed7db91 Matthew Brost         2026-01-27  1518  			}
70ea69ceed7db91 Matthew Brost         2026-01-27  1519  
cfc101ad69846fc Francois Dugast       2026-01-27  1520  			zdd = __zdd;
eb0ece16027f822 Linus Torvalds        2025-04-01  1521  			if (pagemap != page_pgmap(page)) {
99624bdff867079 Matthew Brost         2025-03-05  1522  				if (i > 0) {
99624bdff867079 Matthew Brost         2025-03-05  1523  					err = -EOPNOTSUPP;
99624bdff867079 Matthew Brost         2025-03-05  1524  					goto err_unmap;
99624bdff867079 Matthew Brost         2025-03-05  1525  				}
99624bdff867079 Matthew Brost         2025-03-05  1526  
eb0ece16027f822 Linus Torvalds        2025-04-01  1527  				pagemap = page_pgmap(page);
f86ad0ed620cb3c Matthew Brost         2025-06-19  1528  				dpagemap = drm_pagemap_page_to_dpagemap(page);
99624bdff867079 Matthew Brost         2025-03-05  1529  				if (drm_WARN_ON(gpusvm->drm, !dpagemap)) {
99624bdff867079 Matthew Brost         2025-03-05  1530  					/*
99624bdff867079 Matthew Brost         2025-03-05  1531  					 * Raced. This is not supposed to happen
99624bdff867079 Matthew Brost         2025-03-05  1532  					 * since hmm_range_fault() should've migrated
99624bdff867079 Matthew Brost         2025-03-05  1533  					 * this page to system.
99624bdff867079 Matthew Brost         2025-03-05  1534  					 */
99624bdff867079 Matthew Brost         2025-03-05  1535  					err = -EAGAIN;
99624bdff867079 Matthew Brost         2025-03-05  1536  					goto err_unmap;
99624bdff867079 Matthew Brost         2025-03-05  1537  				}
99624bdff867079 Matthew Brost         2025-03-05  1538  			}
f70da6f99d4f40c Matthew Auld          2025-08-28  1539  			svm_pages->dma_addr[j] =
99624bdff867079 Matthew Brost         2025-03-05  1540  				dpagemap->ops->device_map(dpagemap,
99624bdff867079 Matthew Brost         2025-03-05  1541  							  gpusvm->drm->dev,
99624bdff867079 Matthew Brost         2025-03-05  1542  							  page, order,
ad70e289ed4b1f8 Matthew Auld          2025-08-28  1543  							  dma_dir);
99624bdff867079 Matthew Brost         2025-03-05  1544  			if (dma_mapping_error(gpusvm->drm->dev,
f70da6f99d4f40c Matthew Auld          2025-08-28  1545  					      svm_pages->dma_addr[j].addr)) {
99624bdff867079 Matthew Brost         2025-03-05  1546  				err = -EFAULT;
99624bdff867079 Matthew Brost         2025-03-05  1547  				goto err_unmap;
99624bdff867079 Matthew Brost         2025-03-05  1548  			}
99624bdff867079 Matthew Brost         2025-03-05  1549  		} else {
99624bdff867079 Matthew Brost         2025-03-05  1550  			dma_addr_t addr;
99624bdff867079 Matthew Brost         2025-03-05  1551  
bce13d6ecd6c0e6 Matthew Brost         2025-10-15  1552  			if (is_zone_device_page(page) ||
bce13d6ecd6c0e6 Matthew Brost         2025-10-15  1553  			    (pagemap && !ctx->allow_mixed)) {
99624bdff867079 Matthew Brost         2025-03-05  1554  				err = -EOPNOTSUPP;
99624bdff867079 Matthew Brost         2025-03-05  1555  				goto err_unmap;
99624bdff867079 Matthew Brost         2025-03-05  1556  			}
99624bdff867079 Matthew Brost         2025-03-05  1557  
8a9b978ebd47df9 Himal Prasad Ghimiray 2025-05-12  1558  			if (ctx->devmem_only) {
8a9b978ebd47df9 Himal Prasad Ghimiray 2025-05-12  1559  				err = -EFAULT;
8a9b978ebd47df9 Himal Prasad Ghimiray 2025-05-12  1560  				goto err_unmap;
8a9b978ebd47df9 Himal Prasad Ghimiray 2025-05-12  1561  			}
8a9b978ebd47df9 Himal Prasad Ghimiray 2025-05-12  1562  
70ea69ceed7db91 Matthew Brost         2026-01-27  1563  			if (!i)
70ea69ceed7db91 Matthew Brost         2026-01-27  1564  				dma_iova_try_alloc(gpusvm->drm->dev, state,
70ea69ceed7db91 Matthew Brost         2026-01-27  1565  						   npages * PAGE_SIZE >=
70ea69ceed7db91 Matthew Brost         2026-01-27 @1566  						   HPAGE_PMD_SIZE ?
70ea69ceed7db91 Matthew Brost         2026-01-27  1567  						   HPAGE_PMD_SIZE : 0,
70ea69ceed7db91 Matthew Brost         2026-01-27  1568  						   npages * PAGE_SIZE);
70ea69ceed7db91 Matthew Brost         2026-01-27  1569  
70ea69ceed7db91 Matthew Brost         2026-01-27  1570  			if (dma_use_iova(state)) {
70ea69ceed7db91 Matthew Brost         2026-01-27  1571  				last_phys = page_to_phys(page);
70ea69ceed7db91 Matthew Brost         2026-01-27  1572  
70ea69ceed7db91 Matthew Brost         2026-01-27  1573  				err = dma_iova_link(gpusvm->drm->dev, state,
70ea69ceed7db91 Matthew Brost         2026-01-27  1574  						    page_to_phys(page),
70ea69ceed7db91 Matthew Brost         2026-01-27  1575  						    i * PAGE_SIZE,
70ea69ceed7db91 Matthew Brost         2026-01-27  1576  						    PAGE_SIZE << order,
70ea69ceed7db91 Matthew Brost         2026-01-27  1577  						    dma_dir, 0);
70ea69ceed7db91 Matthew Brost         2026-01-27  1578  				if (err)
70ea69ceed7db91 Matthew Brost         2026-01-27  1579  					goto err_unmap;
70ea69ceed7db91 Matthew Brost         2026-01-27  1580  
70ea69ceed7db91 Matthew Brost         2026-01-27  1581  				addr = state->addr + i * PAGE_SIZE;
70ea69ceed7db91 Matthew Brost         2026-01-27  1582  			} else {
99624bdff867079 Matthew Brost         2025-03-05  1583  				addr = dma_map_page(gpusvm->drm->dev,
99624bdff867079 Matthew Brost         2025-03-05  1584  						    page, 0,
99624bdff867079 Matthew Brost         2025-03-05  1585  						    PAGE_SIZE << order,
ad70e289ed4b1f8 Matthew Auld          2025-08-28  1586  						    dma_dir);
99624bdff867079 Matthew Brost         2025-03-05  1587  				if (dma_mapping_error(gpusvm->drm->dev, addr)) {
99624bdff867079 Matthew Brost         2025-03-05  1588  					err = -EFAULT;
99624bdff867079 Matthew Brost         2025-03-05  1589  					goto err_unmap;
99624bdff867079 Matthew Brost         2025-03-05  1590  				}
70ea69ceed7db91 Matthew Brost         2026-01-27  1591  			}
99624bdff867079 Matthew Brost         2025-03-05  1592  
f70da6f99d4f40c Matthew Auld          2025-08-28  1593  			svm_pages->dma_addr[j] = drm_pagemap_addr_encode
99624bdff867079 Matthew Brost         2025-03-05  1594  				(addr, DRM_INTERCONNECT_SYSTEM, order,
ad70e289ed4b1f8 Matthew Auld          2025-08-28  1595  				 dma_dir);
99624bdff867079 Matthew Brost         2025-03-05  1596  		}
99624bdff867079 Matthew Brost         2025-03-05  1597  		i += 1 << order;
99624bdff867079 Matthew Brost         2025-03-05  1598  		num_dma_mapped = i;
a9ac0fa455b050d Matthew Brost         2025-05-12  1599  		flags.has_dma_mapping = true;
99624bdff867079 Matthew Brost         2025-03-05  1600  	}
99624bdff867079 Matthew Brost         2025-03-05  1601  
70ea69ceed7db91 Matthew Brost         2026-01-27  1602  	if (dma_use_iova(state)) {
70ea69ceed7db91 Matthew Brost         2026-01-27  1603  		err = dma_iova_sync(gpusvm->drm->dev, state, 0,
70ea69ceed7db91 Matthew Brost         2026-01-27  1604  				    npages * PAGE_SIZE);
70ea69ceed7db91 Matthew Brost         2026-01-27  1605  		if (err)
70ea69ceed7db91 Matthew Brost         2026-01-27  1606  			goto err_unmap;
70ea69ceed7db91 Matthew Brost         2026-01-27  1607  	}
70ea69ceed7db91 Matthew Brost         2026-01-27  1608  
f86ad0ed620cb3c Matthew Brost         2025-06-19  1609  	if (pagemap) {
a9ac0fa455b050d Matthew Brost         2025-05-12  1610  		flags.has_devmem_pages = true;
a599b98607decdc Thomas Hellström      2025-12-19  1611  		drm_pagemap_get(dpagemap);
a599b98607decdc Thomas Hellström      2025-12-19  1612  		drm_pagemap_put(svm_pages->dpagemap);
f70da6f99d4f40c Matthew Auld          2025-08-28  1613  		svm_pages->dpagemap = dpagemap;
99624bdff867079 Matthew Brost         2025-03-05  1614  	}
99624bdff867079 Matthew Brost         2025-03-05  1615  
a9ac0fa455b050d Matthew Brost         2025-05-12  1616  	/* WRITE_ONCE pairs with READ_ONCE for opportunistic checks */
f70da6f99d4f40c Matthew Auld          2025-08-28  1617  	WRITE_ONCE(svm_pages->flags.__flags, flags.__flags);
a9ac0fa455b050d Matthew Brost         2025-05-12  1618  
99624bdff867079 Matthew Brost         2025-03-05  1619  	drm_gpusvm_notifier_unlock(gpusvm);
99624bdff867079 Matthew Brost         2025-03-05  1620  	kvfree(pfns);
99624bdff867079 Matthew Brost         2025-03-05  1621  set_seqno:
f70da6f99d4f40c Matthew Auld          2025-08-28  1622  	svm_pages->notifier_seq = hmm_range.notifier_seq;
99624bdff867079 Matthew Brost         2025-03-05  1623  
99624bdff867079 Matthew Brost         2025-03-05  1624  	return 0;
99624bdff867079 Matthew Brost         2025-03-05  1625  
99624bdff867079 Matthew Brost         2025-03-05  1626  err_unmap:
6364afd532bcabf Matthew Auld          2025-08-28  1627  	__drm_gpusvm_unmap_pages(gpusvm, svm_pages, num_dma_mapped);
99624bdff867079 Matthew Brost         2025-03-05  1628  	drm_gpusvm_notifier_unlock(gpusvm);
99624bdff867079 Matthew Brost         2025-03-05  1629  err_free:
99624bdff867079 Matthew Brost         2025-03-05  1630  	kvfree(pfns);
99624bdff867079 Matthew Brost         2025-03-05  1631  	if (err == -EAGAIN)
99624bdff867079 Matthew Brost         2025-03-05  1632  		goto retry;
99624bdff867079 Matthew Brost         2025-03-05  1633  	return err;
99624bdff867079 Matthew Brost         2025-03-05  1634  }
83f706ecbde1dfd Matthew Auld          2025-08-28  1635  EXPORT_SYMBOL_GPL(drm_gpusvm_get_pages);
6364afd532bcabf Matthew Auld          2025-08-28  1636  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

end of thread, other threads:[~2026-01-29 19:33 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-28  0:48 [RFC PATCH v3 00/11] Use new dma-map IOVA alloc, link, and sync API in GPU SVM and DRM pagemap Matthew Brost
2026-01-28  0:48 ` [RFC PATCH v3 01/11] drm/pagemap: Add helper to access zone_device_data Matthew Brost
2026-01-28 13:53   ` Leon Romanovsky
2026-01-28  0:48 ` [RFC PATCH v3 02/11] drm/gpusvm: Use dma-map IOVA alloc, link, and sync API in GPU SVM Matthew Brost
2026-01-28 11:24   ` kernel test robot
2026-01-28 14:04   ` Leon Romanovsky
2026-01-28  0:48 ` [RFC PATCH v3 03/11] drm/pagemap: Split drm_pagemap_migrate_map_pages into device / system Matthew Brost
2026-01-28  0:48 ` [RFC PATCH v3 04/11] drm/pagemap: Use dma-map IOVA alloc, link, and sync API for DRM pagemap Matthew Brost
2026-01-28 14:28   ` Leon Romanovsky
2026-01-28 17:46     ` Matthew Brost
2026-01-28 17:55       ` Jason Gunthorpe
2026-01-28 19:29         ` Matthew Brost
2026-01-28 19:38           ` Jason Gunthorpe
2026-01-28 19:45           ` Leon Romanovsky
2026-01-28 21:04             ` Matthew Brost
2026-01-29 10:14               ` Leon Romanovsky
2026-01-29 18:22                 ` Matthew Brost
2026-01-28  0:48 ` [RFC PATCH v3 05/11] drm/pagemap: Reduce number of IOVA link calls Matthew Brost
2026-01-28  0:48 ` [RFC PATCH v3 06/11] drm/pagemap: Add IOVA interface to DRM pagemap Matthew Brost
2026-01-28 15:14   ` Jason Gunthorpe
2026-01-28 18:42     ` Matthew Brost
2026-01-28 19:35       ` Jason Gunthorpe
2026-01-28 20:24         ` Matthew Brost
2026-01-29 18:57           ` Jason Gunthorpe
2026-01-29 19:28             ` Matthew Brost
2026-01-29 19:32               ` Jason Gunthorpe
2026-01-28 19:41       ` Matthew Brost
2026-01-28  0:48 ` [RFC PATCH v3 07/11] drm/xe: Stub out DRM pagemap IOVA alloc implementation Matthew Brost
2026-01-28  0:48 ` [RFC PATCH v3 08/11] drm/pagemap: Use device-to-device IOVA alloc, link, and sync API for DRM pagemap Matthew Brost
2026-01-28  0:48 ` [RFC PATCH v3 09/11] drm/xe: Drop BO dma-resv lock during SVM migrate-to-device Matthew Brost
2026-01-28 11:46   ` kernel test robot
2026-01-28  0:48 ` [RFC PATCH v3 10/11] drm/xe: Implement DRM pagemap IOVA vfuncs Matthew Brost
2026-01-28  0:48 ` [RFC PATCH v3 11/11] drm/gpusvm: Use device-to-device IOVA alloc, link, and sync API in GPU SVM Matthew Brost
2026-01-28  0:59 ` ✗ CI.checkpatch: warning for Use new dma-map IOVA alloc, link, and sync API in GPU SVM and DRM pagemap (rev3) Patchwork
2026-01-28  1:01 ` ✓ CI.KUnit: success " Patchwork
2026-01-28  1:42 ` ✓ Xe.CI.BAT: " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2026-01-28 21:01 [RFC PATCH v3 02/11] drm/gpusvm: Use dma-map IOVA alloc, link, and sync API in GPU SVM kernel test robot

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.