AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Amir Shetaia" <amir.shetaia@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amdgpu: wait for PT updates in amdgpu_vm_make_compute
Date: Fri, 04 Dec 2026 20:39:43 +0000	[thread overview]
Message-ID: <sashiko-outbox-250633@kernel.org> (raw)
In-Reply-To: <20261204201649.375581-1-amir.shetaia@amd.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/amdgpu: BOOKKEEP wait in amdgpu_vm_make_compute() evicts
  KGD userqs
- [Low] drm/amdgpu: Fixes tag cites 4247084057cf instead of 926c79ad6ecd
--

commit f7d48a981689f9a016015e4327294adae6c1d421
Author: Amir Shetaia <amir.shetaia@amd.com>

> drm/amdgpu: wait for PT updates in amdgpu_vm_make_compute
>
> amdgpu_vm_make_compute() switches a VM to CPU page table updates when
> compute VMs use the CPU path (vm_update_mode, the default when all of
> VRAM is CPU visible). Before switching it waits for the last SDMA
> update/clear of the root PD with amdgpu_bo_sync_wait().
>
> That helper goes through amdgpu_sync_resv(), which only iterates
> DMA_RESV_USAGE_READ fences. Since commit 4247084057cf
> ("drm/amdgpu: use DMA_RESV_USAGE_BOOKKEEP v2") page table updates add
> their fence to the root reservation with DMA_RESV_USAGE_BOOKKEEP, so the
> wait no longer covers the clear of the root PD issued at VM creation.
>
> A process that maps memory right after AMDKFD_IOC_ACQUIRE_VM can then
> write a root PDE with the CPU before the pending SDMA clear of the root
> PD has executed, and the clear wipes the entry. The GPU later takes a
> not-present fault on the mapped address. We hit this as a CPC fault on a
> user queue's write pointer page; walking the VM with UMR while the fault
> was pending showed the root entry as 0x8000000000000000. Adding a short
> delay after ACQUIRE_VM made the fault go away.
>
> Wait for all fences on the root reservation, including BOOKKEEP, before
> switching to CPU updates. The dma_resv_wait_timeout() result is kept in
> a long, since MAX_SCHEDULE_TIMEOUT does not fit in an int.
>
> Tested on gfx1201 with a v7.0 based kernel and a reproducer that
> acquires a VM, maps buffers and creates an SDMA queue right away:
> 8 of 8 runs faulted without this patch, 0 of 8 with it.
>
> Fixes: 4247084057cf ("drm/amdgpu: use DMA_RESV_USAGE_BOOKKEEP v2")
> Signed-off-by: Amir Shetaia <amir.shetaia@amd.com>

[Severity: Low]
Should the Fixes tag (and commit message) cite 926c79ad6ecd ("drm/amdgpu:
promote the implicit sync to the dependent read fences") instead of
4247084057cf ("drm/amdgpu: use DMA_RESV_USAGE_BOOKKEEP v2")?

amdgpu_sync_resv() still iterated DMA_RESV_USAGE_BOOKKEEP fences until
the 2025 commit changed it to DMA_RESV_USAGE_READ, so
amdgpu_bo_sync_wait() kept waiting on PT updates prior to that.  Citing
the earlier commit can cause stable backport tooling to flag unaffected
LTS kernels.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index a3758c654dd42..130dbcbf3c85c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

[ ... ]

> @@ -2721,11 +2722,16 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm)
>  		  "CPU update of VM recommended only for large BAR system\n");
>  
>  	if (vm->use_cpu_for_update) {
> -		/* Sync with last SDMA update/clear before switching to CPU */
> -		r = amdgpu_bo_sync_wait(vm->root.bo,
> -					AMDGPU_FENCE_OWNER_UNDEFINED, true);
> -		if (r)
> +		/* Sync with last SDMA update/clear before switching to CPU.
> +		 * PT updates are BOOKKEEP fences, amdgpu_bo_sync_wait() skips them.
> +		 */
> +		wait = dma_resv_wait_timeout(vm->root.bo->tbo.base.resv,
> +					     DMA_RESV_USAGE_BOOKKEEP, true,
> +					     MAX_SCHEDULE_TIMEOUT);
> +		if (wait < 0) {
> +			r = wait;
>  			goto unreserve_bo;
> +		}

[Severity: Medium]
Can waiting on all DMA_RESV_USAGE_BOOKKEEP fences here trigger an
unintended eviction of active KGD user queues?

If a process creates a KGD user queue on a DRM render fd before calling
AMDKFD_IOC_ACQUIRE_VM on it, amdgpu_evf_mgr_attach_fence() attaches an
unsignaled amdgpu_eviction_fence to vm->root.bo with
DMA_RESV_USAGE_BOOKKEEP.

Waiting on that fence enables signaling and schedules suspend_work ->
amdgpu_userq_evict(), draining every active user queue's last_fence
uninterruptibly and unmapping all user queues via MES while vm->root.bo
is reserved, stalling AMDKFD_IOC_ACQUIRE_VM until they are evicted and
later remapped.

Switching to amdgpu_vm_cpu_funcs only needs to wait for kernel/move
fences and pending SDMA PT updates (AMDGPU_FENCE_OWNER_VM), and can skip
waiting for SDMA updates when vm->update_funcs is already
&amdgpu_vm_cpu_funcs.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204201649.375581-1-amir.shetaia@amd.com?part=1

      reply	other threads:[~2026-12-04 20:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 20:16 [PATCH] drm/amdgpu: wait for PT updates in amdgpu_vm_make_compute Amir Shetaia
2026-12-04 20:39 ` 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-250633@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=amir.shetaia@amd.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