All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felix Kuehling <felix.kuehling@amd.com>
To: Shahyan Soltani <shahyan.soltani@amd.com>, amd-gfx@lists.freedesktop.org
Cc: christian.koenig@amd.com, alexander.deucher@amd.com, yangp@amd.com
Subject: Re: [PATCH v3] drm/amdgpu: clear root PT after setting vm->is_npa = true
Date: Fri, 20 Nov 2026 17:01:53 -0500	[thread overview]
Message-ID: <ecac4e13-0da7-428a-a1cb-db75990cd20b@amd.com> (raw)
In-Reply-To: <20261119184620.1090706-1-shahyan.soltani@amd.com>

On 2026-11-19 13:46, Shahyan Soltani wrote:
> Previously, the root PT was never cleared after setting vm->is_npa =
> true within amdgpu_vm_make_npa(). This resulted in the flag
> adev->gmc.no_retry_flags to never be applied for the NPA VMs.
>
> Call amdgpu_vm_pt_clear() after vm->is_npa = true is set and the bo has
> been pinned/validated. This allows the root PT of the NPA VM to be
> cleared with the correct value.
>
> If the pinning or reservation of the bo failed, the vm->is_npa flag will
> no longer remain as true. This is to avoid conditionals outside of
> amdgpu_vm_make_npa() that depend on the vm->is_npa flag to determine if
> the VM is a correctly initialized NPA VM.
>
> Warn if the VM already has mappings, since clearing the root PT will
> break existing mappings.
>
> Remove the redundant second setting of vm->is_npa = true.
>
> v2:
> - Add the WARN_ON sanity check regarding an empty VM (Felix)
> - Change the return handling to only set vm->is_npa = true upon a
>    successful pin (Felix)
> - Add the heavy weight TLB flush after the root PT clear (Philip)
>
> v3:
> - Remove TLB flush (Felix)
> - Move WARN_ON sanity check to start to return early (Christian)
> - Reserve fence slots for amdgpu_vm_pt_clear() and amdgpu_bo_pin()
>    by replacing amdgpu_bo_reserve with amdgpu_vm_lock_pd()
>    (Christian)
> - Use goto error handling rather than calling return when applicable
>
> Suggested-by: Christian König <christian.koenig@amd.com>
> Signed-off-by: Shahyan Soltani <shahyan.soltani@amd.com>

Reviewed-by: Felix Kuehling <felix.kuehling@amd.com>


> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 36 ++++++++++++++++++++------
>   1 file changed, 28 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 94b1cfe05e3e..d9e3916feea6 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -2820,23 +2820,43 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm)
>    */
>   int amdgpu_vm_make_npa(struct amdgpu_device *adev, struct amdgpu_vm *vm)
>   {
> -	int r = amdgpu_vm_make_compute(adev, vm);
> +	struct drm_exec exec;
> +	int r;
>   
> +	/* Check if VM mappings are empty, clearing would break existing mapping */
> +	if (WARN_ON(!RB_EMPTY_ROOT(&vm->va.rb_root)))
> +		return -EINVAL;
> +
> +	r = amdgpu_vm_make_compute(adev, vm);
>   	if (r)
> -		return r;
> -	vm->is_npa = true;
> -	r = amdgpu_bo_reserve(vm->root.bo, false);
> -	if (r)
> -		return r;
> +		goto error;
> +
> +	drm_exec_init(&exec, 0, 0);
> +	drm_exec_until_all_locked(&exec) {
> +		r = amdgpu_vm_lock_pd(vm, &exec, 0);
> +		drm_exec_retry_on_contention(&exec);
> +		if (unlikely(r))
> +			goto error_unlock;
> +	}
> +
>   	r = amdgpu_bo_pin(vm->root.bo, AMDGPU_GEM_DOMAIN_VRAM);
> -	amdgpu_bo_unreserve(vm->root.bo);
>   	if (r)
> -		return r;
> +		goto error_unlock;
>   
>   	vm->is_npa = true;
> +	r = amdgpu_vm_pt_clear(adev, vm, to_amdgpu_bo_vm(vm->root.bo), false);
> +	if (r)
> +		goto error_unlock;
> +
> +	drm_exec_fini(&exec);
>   	vm->need_tlb_fence = false;
>   
>   	return 0;
> +
> +error_unlock:
> +	drm_exec_fini(&exec);
> +error:
> +	return r;
>   }
>   
>   static int amdgpu_vm_stats_is_zero(struct amdgpu_vm *vm)

      parent reply	other threads:[~2026-11-20 22:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 18:46 [PATCH v3] drm/amdgpu: clear root PT after setting vm->is_npa = true Shahyan Soltani
2026-11-19 18:55 ` sashiko-bot
2026-11-20 22:01 ` Felix Kuehling [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=ecac4e13-0da7-428a-a1cb-db75990cd20b@amd.com \
    --to=felix.kuehling@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=shahyan.soltani@amd.com \
    --cc=yangp@amd.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.