Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Matthew Brost" <matthew.brost@intel.com>,
	intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v3 1/2] drm/gpusvm: Add a DMA-mapping accounting callback
Date: Fri, 13 Nov 2026 19:19:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-213540@kernel.org> (raw)
In-Reply-To: <20261113190128.2118723-1-matthew.brost@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] drm/gpusvm: incomplete full-SVM ops check and doc in
  drm_gpusvm_init()
- [Low] drm/gpusvm: document locking context for
  drm_gpusvm_ops.dma_map_account
--

commit 8cdf85308b0a5f01cbf31357b5001cfa11f7973f
Author: Thomas Hellström <thomas.hellstrom@linux.intel.com>

drm/gpusvm: Add a DMA-mapping accounting callback

This commit adds an optional dma_map_account callback to struct
drm_gpusvm_ops for symmetric DMA-mapping accounting and allows a restricted
ops table with page-level hooks when initializing drm_gpusvm without an mm.

> diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c
> index 45169eb6de619..18b51be7d6df3 100644
> --- a/drivers/gpu/drm/drm_gpusvm.c
> +++ b/drivers/gpu/drm/drm_gpusvm.c
> @@ -503,8 +503,16 @@ int drm_gpusvm_init(struct drm_gpusvm *gpusvm,
>  			return -EINVAL;
>  		mmgrab(mm);
>  	} else {
> -		/* No full SVM mode, only core drm_gpusvm_pages API. */
> -		if (ops || num_chunks || mm_range || notifier_size)
> +		/*
> +		 * No full SVM mode, only core drm_gpusvm_pages API. A
> +		 * restricted @ops that only implements the page-level hooks
> +		 * (e.g. @dma_map_account) is allowed; the full-SVM hooks must
> +		 * not be set.
> +		 */
> +		if (num_chunks || mm_range || notifier_size)
> +			return -EINVAL;
> +		if (ops && (ops->invalidate || ops->range_alloc ||
> +			    ops->range_free))
>  			return -EINVAL;
>  	}

[Severity: Low]
Should this check also reject ops->notifier_alloc and ops->notifier_free
when mm is NULL, as those are full-SVM hooks on struct drm_gpusvm_ops as
well?

Also, the kernel-doc above drm_gpusvm_init() still says that only @gpusvm
and @name are expected when using the simple drm_gpusvm_pages API.

[ ... ]

> diff --git a/include/drm/drm_gpusvm.h b/include/drm/drm_gpusvm.h
> index 4d31c6bba7455..637c19f7169f1 100644
> --- a/include/drm/drm_gpusvm.h
> +++ b/include/drm/drm_gpusvm.h
> @@ -75,6 +75,25 @@ struct drm_gpusvm_ops {
>  	void (*invalidate)(struct drm_gpusvm *gpusvm,
>  			   struct drm_gpusvm_notifier *notifier,
>  			   const struct mmu_notifier_range *mmu_range);
> +
> +	/**
> +	 * @dma_map_account: Account a DMA-mapping change (optional)
> +	 * @gpusvm: Pointer to the GPU SVM
> +	 * @addr: The address descriptor of the chunk being (un)mapped
> +	 * @sign: +1 when @addr has just been DMA-mapped, -1 when it is being
> +	 *        unmapped
> +	 *
> +	 * Called once per &drm_pagemap_addr entry, when the entry is
> +	 * DMA-mapped by drm_gpusvm_get_pages() (@sign == +1) and when it is
> +	 * unmapped (@sign == -1), so the driver can keep symmetric accounting
> +	 * of the pages it has mapped for GPU access. The @addr->proto field
> +	 * can be used to distinguish system-memory mappings from device
> +	 * interconnect mappings. May be provided in both full SVM mode and the
> +	 * core drm_gpusvm_pages-only mode.
> +	 */
> +	void (*dma_map_account)(struct drm_gpusvm *gpusvm,
> +				const struct drm_pagemap_addr *addr,
> +				int sign);
>  };

[Severity: Low]
Could the kernel-doc for @dma_map_account document its locking and
execution context, similar to @invalidate and @devmem_fn?

It is called under gpusvm->notifier_lock in read mode during
drm_gpusvm_dma_map_pages() and non-notifier unmaps (allowing concurrent
calls), and in write mode from MMU notifier invalidation context when
ctx->in_notifier is set in drm_gpusvm_unmap_pages().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261113190128.2118723-1-matthew.brost@intel.com?part=1

      parent reply	other threads:[~2026-11-13 19:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 19:01 [PATCH v3 1/2] drm/gpusvm: Add a DMA-mapping accounting callback Matthew Brost
2026-11-13 19:01 ` [PATCH v3 2/2] drm/xe: Add debugfs stats for DMA-mapped pages per order Matthew Brost
2026-11-13 19:08 ` ✗ CI.checkpatch: warning for series starting with [v3,1/2] drm/gpusvm: Add a DMA-mapping accounting callback Patchwork
2026-11-13 19:10 ` ✓ CI.KUnit: success " Patchwork
2026-11-13 19:19 ` sashiko-bot [this message]

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=sashiko-outbox-213540@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.brost@intel.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox