From: "Christian König" <christian.koenig@amd.com>
To: "Wang, Beyond" <Wang.Beyond@amd.com>,
"Deucher, Alexander" <Alexander.Deucher@amd.com>
Cc: "amd-gfx@lists.freedesktop.org" <amd-gfx@lists.freedesktop.org>,
"Jin, Jason(Yong)" <JasonYong.Jin@amd.com>,
"Alnasser, Mais" <Mais.Alnasser@amd.com>
Subject: Re: [PATCH] drm/amdgpu: add fast-path for userptr BO validation
Date: Tue, 31 Mar 2026 10:39:44 +0200 [thread overview]
Message-ID: <6c32fbb1-669f-4656-9d03-e70f9b515a88@amd.com> (raw)
In-Reply-To: <SJ0PR12MB69030113B9A8023E3132F8F7F753A@SJ0PR12MB6903.namprd12.prod.outlook.com>
On 3/31/26 10:33, Wang, Beyond wrote:
> [Public]
>
> This change is based on Linux 6.19-rc7
>
>
> Skip the expensive per-BO hmm_range_fault page table walk if no MMU
> invalidation occurred since last successful submit. Here it's a single
> seq counter compare vs the full HMM walk
>
> On first submit the slow path runs and caches notifier_seq into
> bo->last_valid_notifier_seq. Subsequent submits check with the cached seq
> for the fast-path. If an MMU notifier fires, the seq changes accordingly
> and the slow path runs again on affected BOs.
Well absolutely clear NAK on that, we have intentionally removed that before because it leads to security issues.
Regards,
Christian.
>
> Signed-off-by: Wang, Beyond <Wang.Beyond@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 25 +++++++++++++++++++++-
> drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 8 +++++++
> 2 files changed, 32 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> index ecdfe6cb36cc..140346e9cb92 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> @@ -891,6 +891,17 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
> bool userpage_invalidated = false;
> struct amdgpu_bo *bo = e->bo;
>
> + /*
> + * Skip the expensive HMM page table walk if no MMU invalidation occurred
> + * since last successful submit
> + */
> + if (bo->last_valid_notifier_seq &&
> + !mmu_interval_read_retry(&bo->notifier, bo->last_valid_notifier_seq)) {
> + e->range = NULL;
> + e->user_invalidated = false;
> + continue;
> + }
> +
> e->range = amdgpu_hmm_range_alloc(NULL);
> if (unlikely(!e->range))
> return -ENOMEM;
> @@ -1326,7 +1337,19 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
> */
> r = 0;
> amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
> - r |= !amdgpu_hmm_range_valid(e->range);
> + struct amdgpu_bo *bo = e->bo;
> +
> + if (!e->range) {
> + if (mmu_interval_read_retry(&bo->notifier, bo->last_valid_notifier_seq))
> + r = 1;
> + continue;
> + }
> +
> + if (!amdgpu_hmm_range_valid(e->range))
> + r = 1;
> + else
> + bo->last_valid_notifier_seq = e->range->hmm_range.notifier_seq;
> +
> amdgpu_hmm_range_free(e->range);
> e->range = NULL;
> }
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> index 52c2d1731aab..89dc9ee1176e 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> @@ -115,6 +115,14 @@ struct amdgpu_bo {
>
> #ifdef CONFIG_MMU_NOTIFIER
> struct mmu_interval_notifier notifier;
> +
> + /*
> + * Cached notifier_seq from last successful CS submit.
> + * Used to skip the expensive HMM page table walk when
> + * no MMU invalidation has occurred since last validation.
> + * Zero means never validated (always takes the slow path).
> + */
> + unsigned long last_valid_notifier_seq;
> #endif
> struct kgd_mem *kfd_bo;
>
> --
> 2.43.0
>
>
>
> Thanks,
> Beyond
prev parent reply other threads:[~2026-03-31 8:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 8:33 [PATCH] drm/amdgpu: add fast-path for userptr BO validation Wang, Beyond
2026-03-31 8:39 ` Christian König [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=6c32fbb1-669f-4656-9d03-e70f9b515a88@amd.com \
--to=christian.koenig@amd.com \
--cc=Alexander.Deucher@amd.com \
--cc=JasonYong.Jin@amd.com \
--cc=Mais.Alnasser@amd.com \
--cc=Wang.Beyond@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
/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