All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leonro@nvidia.com>
To: Matthew Brost <matthew.brost@intel.com>
Cc: <intel-xe@lists.freedesktop.org>,
	<dri-devel@lists.freedesktop.org>, <francois.dugast@intel.com>,
	<thomas.hellstrom@linux.intel.com>,
	<himal.prasad.ghimiray@intel.com>, <jgg@ziepe.ca>
Subject: Re: [RFC PATCH v3 02/11] drm/gpusvm: Use dma-map IOVA alloc, link, and sync API in GPU SVM
Date: Wed, 28 Jan 2026 16:04:22 +0200	[thread overview]
Message-ID: <20260128140422.GF40916@unreal> (raw)
In-Reply-To: <20260128004841.2436896-3-matthew.brost@intel.com>

On Tue, Jan 27, 2026 at 04:48:32PM -0800, Matthew Brost wrote:
> 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 the IOVA alloc, link, and sync APIs for GPU SVM, which create DMA
> mappings between the CPU and GPU.
> 
> v3:
>  - Always link IOVA in mixed mappings
>  - Sync IOVA

The same comment as before.

> 
> Signed-off-by: Matthew Brost <matthew.brost@intel.com>
> ---
>  drivers/gpu/drm/drm_gpusvm.c | 87 ++++++++++++++++++++++++++++--------
>  include/drm/drm_gpusvm.h     |  3 ++
>  2 files changed, 71 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c
> index 585d913d3d19..084e78fa0f32 100644
> --- a/drivers/gpu/drm/drm_gpusvm.c
> +++ b/drivers/gpu/drm/drm_gpusvm.c
> @@ -1139,19 +1139,26 @@ static void __drm_gpusvm_unmap_pages(struct drm_gpusvm *gpusvm,
>  		struct drm_gpusvm_pages_flags flags = {
>  			.__flags = svm_pages->flags.__flags,
>  		};
> +		struct dma_iova_state __state = {};

Why don't you use svm_pages->state directly?

>  
> -		for (i = 0, j = 0; i < npages; j++) {
> -			struct drm_pagemap_addr *addr = &svm_pages->dma_addr[j];
> -
> -			if (addr->proto == DRM_INTERCONNECT_SYSTEM)
> -				dma_unmap_page(dev,
> -					       addr->addr,
> -					       PAGE_SIZE << addr->order,
> -					       addr->dir);
> -			else if (dpagemap && dpagemap->ops->device_unmap)
> -				dpagemap->ops->device_unmap(dpagemap,
> -							    dev, *addr);
> -			i += 1 << addr->order;
> +		if (dma_use_iova(&svm_pages->state)) {
> +			dma_iova_destroy(dev, &svm_pages->state,
> +					 npages * PAGE_SIZE,
> +					 svm_pages->dma_addr[0].dir, 0);
> +		} else {
> +			for (i = 0, j = 0; i < npages; j++) {
> +				struct drm_pagemap_addr *addr = &svm_pages->dma_addr[j];
> +
> +				if (addr->proto == DRM_INTERCONNECT_SYSTEM)
> +					dma_unmap_page(dev,
> +						       addr->addr,
> +						       PAGE_SIZE << addr->order,
> +						       addr->dir);
> +				else if (dpagemap && dpagemap->ops->device_unmap)
> +					dpagemap->ops->device_unmap(dpagemap,
> +								    dev, *addr);
> +				i += 1 << addr->order;
> +			}
>  		}
>  
>  		/* WRITE_ONCE pairs with READ_ONCE for opportunistic checks */
> @@ -1161,6 +1168,7 @@ static void __drm_gpusvm_unmap_pages(struct drm_gpusvm *gpusvm,
>  
>  		drm_pagemap_put(svm_pages->dpagemap);
>  		svm_pages->dpagemap = NULL;
> +		svm_pages->state = __state;
>  	}
>  }
>  
> @@ -1402,12 +1410,14 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm,
>  	unsigned long num_dma_mapped;
>  	unsigned int order = 0;
>  	unsigned long *pfns;
> +	phys_addr_t last_phys;
>  	int err = 0;
>  	struct dev_pagemap *pagemap;
>  	struct drm_pagemap *dpagemap;
>  	struct drm_gpusvm_pages_flags flags;
>  	enum dma_data_direction dma_dir = ctx->read_only ? DMA_TO_DEVICE :
>  							   DMA_BIDIRECTIONAL;
> +	struct dma_iova_state *state = &svm_pages->state;
>  
>  retry:
>  	if (time_after(jiffies, timeout))
> @@ -1496,6 +1506,17 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm,
>  				err = -EOPNOTSUPP;
>  				goto err_unmap;
>  			}
> +
> +			if (dma_use_iova(state)) {
> +				err = dma_iova_link(gpusvm->drm->dev, state,
> +						    last_phys,
> +						    i * PAGE_SIZE,
> +						    PAGE_SIZE << order,
> +						    dma_dir, 0);
> +				if (err)
> +					goto err_unmap;
> +			}
> +
>  			zdd = __zdd;
>  			if (pagemap != page_pgmap(page)) {
>  				if (i > 0) {
> @@ -1539,13 +1560,34 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm,
>  				goto err_unmap;
>  			}
>  
> -			addr = dma_map_page(gpusvm->drm->dev,
> -					    page, 0,
> -					    PAGE_SIZE << order,
> -					    dma_dir);
> -			if (dma_mapping_error(gpusvm->drm->dev, addr)) {
> -				err = -EFAULT;
> -				goto err_unmap;
> +			if (!i)
> +				dma_iova_try_alloc(gpusvm->drm->dev, state,
> +						   npages * PAGE_SIZE >=
> +						   HPAGE_PMD_SIZE ?
> +						   HPAGE_PMD_SIZE : 0,
> +						   npages * PAGE_SIZE);
> +
> +			if (dma_use_iova(state)) {
> +				last_phys = page_to_phys(page);

hmm_pfn_to_phys().

> +
> +				err = dma_iova_link(gpusvm->drm->dev, state,
> +						    page_to_phys(page),

you have last_phys here.

> +						    i * PAGE_SIZE,
> +						    PAGE_SIZE << order,
> +						    dma_dir, 0);
> +				if (err)
> +					goto err_unmap;
> +

Thanks

  parent reply	other threads:[~2026-01-28 14:05 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=20260128140422.GF40916@unreal \
    --to=leonro@nvidia.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=francois.dugast@intel.com \
    --cc=himal.prasad.ghimiray@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jgg@ziepe.ca \
    --cc=matthew.brost@intel.com \
    --cc=thomas.hellstrom@linux.intel.com \
    /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: link
Be 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.