From: Matthew Brost <matthew.brost@intel.com>
To: Honglei Huang <honghuan@amd.com>
Cc: <sima@ffwll.ch>, <rodrigo.vivi@intel.com>,
<thomas.hellstrom@linux.intel.com>,
<himal.prasad.ghimiray@intel.com>, <dakr@kernel.org>,
<intel-xe@lists.freedesktop.org>, <aliceryhl@google.com>,
<Alexander.Deucher@amd.com>, <Felix.Kuehling@amd.com>,
<Christian.Koenig@amd.com>, <Ray.Huang@amd.com>,
<Junhua.Shen@amd.com>, <amd-gfx@lists.freedesktop.org>,
<dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH v2 4/4] drm/gpusvm: make the DMA mapping step in get_pages() optional
Date: Tue, 1 Sep 2026 13:02:51 -0700 [thread overview]
Message-ID: <apcva2LimMW3QSQ8@gsse-cloud1.jf.intel.com> (raw)
In-Reply-To: <20260901090100.2024933-5-honghuan@amd.com>
On Tue, Sep 01, 2026 at 05:01:00PM +0800, Honglei Huang wrote:
> Some drivers (e.g. AMDXDNA) only need the CPU pages faulted in and tracked
> by the notifier, no need DMA mapping.
>
> Add a drm_gpusvm_ctx::no_dma_map flag. When set, get_pages() does the
> shared HMM fault and records notifier_seq, but skips svm_pages->drm
> validation, the dma_addr allocation and drm_gpusvm_dma_map_pages().
> With no mapping state to check, the fault is redone on every call. The
> default (no_dma_map == 0) is unchanged.
>
> Suggested-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
> Signed-off-by: Honglei Huang <honghuan@amd.com>
> ---
> drivers/gpu/drm/drm_gpusvm.c | 44 ++++++++++++++++++++++++++----------
> include/drm/drm_gpusvm.h | 9 ++++++++
> 2 files changed, 41 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c
> index 810f801a9f7..0156ee82d7c 100644
> --- a/drivers/gpu/drm/drm_gpusvm.c
> +++ b/drivers/gpu/drm/drm_gpusvm.c
> @@ -1663,6 +1663,12 @@ static int drm_gpusvm_dma_map_pages(struct drm_gpusvm *gpusvm,
> * On error the instances mapped before the failing one stay mapped, so the
> * caller must unmap and free every instance regardless of the return value.
> *
> + * With &drm_gpusvm_ctx.no_dma_map no mapping state is recorded, so
> + * drm_gpusvm_pages_valid() never returns true and success is only a snapshot:
> + * the caller must recheck mmu_interval_read_retry() against the recorded
> + * &drm_gpusvm_pages.notifier_seq under the notifier lock, and hold it until
> + * its work is visible to invalidation.
> + *
> * Return: 0 on success, negative error code on failure.
> */
> int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm,
> @@ -1689,11 +1695,18 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm,
> int err = 0;
> enum dma_data_direction dma_dir = ctx->read_only ? DMA_TO_DEVICE :
> DMA_BIDIRECTIONAL;
> + const bool map_dma = !ctx->no_dma_map;
> unsigned int p;
>
> - for (p = 0; p < num_pages; ++p)
> - if (!svm_pages[p].drm)
> - return -EINVAL;
> + if (ctx->no_dma_map && ctx->devmem_only)
> + return -EINVAL;
> +
> + if (map_dma) {
> + for (p = 0; p < num_pages; ++p) {
> + if (!svm_pages[p].drm)
> + return -EINVAL;
> + }
> + }
>
> retry:
> remaining = timeout - jiffies;
> @@ -1703,7 +1716,8 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm,
>
> hmm_range.notifier_seq = mmu_interval_read_begin(notifier);
>
> - if (drm_gpusvm_pages_valid_unlocked(gpusvm, svm_pages, num_pages))
> + if (map_dma &&
> + drm_gpusvm_pages_valid_unlocked(gpusvm, svm_pages, num_pages))
> goto set_seqno;
>
> pfns = kvmalloc_array(npages, sizeof(*pfns), GFP_KERNEL);
> @@ -1721,14 +1735,16 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm,
> if (err)
> goto err_free;
>
> - for (p = 0; p < num_pages; ++p) {
> - if (svm_pages[p].dma_addr)
> - continue;
> - svm_pages[p].dma_addr =
> - kvzalloc_objs(*svm_pages[p].dma_addr, npages);
> - if (!svm_pages[p].dma_addr) {
> - err = -ENOMEM;
> - goto err_free;
> + if (map_dma) {
> + for (p = 0; p < num_pages; ++p) {
> + if (svm_pages[p].dma_addr)
> + continue;
> + svm_pages[p].dma_addr =
> + kvzalloc_objs(*svm_pages[p].dma_addr, npages);
> + if (!svm_pages[p].dma_addr) {
> + err = -ENOMEM;
> + goto err_free;
> + }
> }
> }
>
> @@ -1753,6 +1769,9 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm,
> goto retry;
> }
>
> + if (!map_dma)
> + goto done_mapping;
> +
> for (p = 0; p < num_pages; ++p) {
> if (drm_gpusvm_pages_valid(gpusvm, &svm_pages[p]))
> continue;
> @@ -1771,6 +1790,7 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm,
> }
> }
>
> +done_mapping:
> drm_gpusvm_notifier_unlock(gpusvm);
> kvfree(pfns);
> set_seqno:
> diff --git a/include/drm/drm_gpusvm.h b/include/drm/drm_gpusvm.h
> index d2b6f3d2b84..ec7b81957b1 100644
> --- a/include/drm/drm_gpusvm.h
> +++ b/include/drm/drm_gpusvm.h
> @@ -254,6 +254,14 @@ struct drm_gpusvm {
> * @allow_mixed: Allow mixed mappings in get pages. Mixing between system and
> * single dpagemap is supported, mixing between multiple dpagemap
> * is unsupported.
> + * @no_dma_map: Only fault the CPU pages for the range; skip the device DMA
> + * mapping step. Used by drivers that consume the faulted pages
> + * without needing a DMA mapping. In this mode @drm on the
> + * drm_gpusvm_pages is not required, no mapping state is recorded
> + * and drm_gpusvm_pages_valid() therefore never reports these
> + * pages as valid; the caller revalidates the snapshot itself, see
> + * drm_gpusvm_get_pages(). @devmem_only is rejected and no page
> + * type check is performed, so @allow_mixed has no effect.
> *
> * Context that is DRM GPUSVM is operating in (i.e. user arguments).
> */
> @@ -266,6 +274,7 @@ struct drm_gpusvm_ctx {
> unsigned int devmem_possible :1;
> unsigned int devmem_only :1;
> unsigned int allow_mixed :1;
> + unsigned int no_dma_map :1;
> };
>
> int drm_gpusvm_init(struct drm_gpusvm *gpusvm,
> --
> 2.34.1
>
prev parent reply other threads:[~2026-09-01 20:03 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-01 9:00 [PATCH v2 0/4] drm/gpusvm: share one HMM fault across per-device DMA mappings Honglei Huang
2026-09-01 9:00 ` [PATCH v2 1/4] drm/gpusvm: move dma_addr allocation before the notifier lock Honglei Huang
2026-09-01 19:39 ` Matthew Brost
2026-09-02 6:21 ` Huang, Honglei
2026-09-01 9:00 ` [PATCH v2 2/4] drm/gpusvm: extract drm_gpusvm_dma_map_pages() helper Honglei Huang
2026-09-01 19:43 ` Matthew Brost
2026-09-02 6:22 ` Huang, Honglei
2026-09-01 9:00 ` [PATCH v2 3/4] drm/gpusvm: let drm_gpusvm_get_pages() map an array of pages Honglei Huang
2026-09-01 19:57 ` Matthew Brost
2026-09-02 6:39 ` Huang, Honglei
2026-09-01 9:01 ` [PATCH v2 4/4] drm/gpusvm: make the DMA mapping step in get_pages() optional Honglei Huang
2026-09-01 20:02 ` Matthew Brost [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=apcva2LimMW3QSQ8@gsse-cloud1.jf.intel.com \
--to=matthew.brost@intel.com \
--cc=Alexander.Deucher@amd.com \
--cc=Christian.Koenig@amd.com \
--cc=Felix.Kuehling@amd.com \
--cc=Junhua.Shen@amd.com \
--cc=Ray.Huang@amd.com \
--cc=aliceryhl@google.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=himal.prasad.ghimiray@intel.com \
--cc=honghuan@amd.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=rodrigo.vivi@intel.com \
--cc=sima@ffwll.ch \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox