From: "Christian König" <christian.koenig@amd.com>
To: Sunil Khatri <sunil.khatri@amd.com>,
Alex Deucher <alexander.deucher@amd.com>
Cc: amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH v2 1/2] drm/amdgpu/userq: use drm_exec in amdgpu_userq_fence_read_wptr
Date: Mon, 11 May 2026 15:22:32 +0200 [thread overview]
Message-ID: <7922720c-4036-474d-805e-04bca3e9cd7a@amd.com> (raw)
In-Reply-To: <20260508103910.2442183-1-sunil.khatri@amd.com>
On 5/8/26 12:39, Sunil Khatri wrote:
> To access the bo from vm mapping first lock the root bo and
> then the object bo of the mapping to make sure both locks
> are taken safely.
>
> Signed-off-by: Sunil Khatri <sunil.khatri@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
> ---
> .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 55 +++++++++----------
> 1 file changed, 26 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
> index 369914cab555..008330a0d852 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
> @@ -370,51 +370,48 @@ static int amdgpu_userq_fence_read_wptr(struct amdgpu_device *adev,
> {
> struct amdgpu_bo_va_mapping *mapping;
> struct amdgpu_bo *bo;
> + struct drm_exec exec;
> u64 addr, *ptr;
> - int r;
> -
> - r = amdgpu_bo_reserve(queue->vm->root.bo, false);
> - if (r)
> - return r;
> + int ret;
>
> addr = queue->userq_prop->wptr_gpu_addr;
> addr &= AMDGPU_GMC_HOLE_MASK;
>
> - mapping = amdgpu_vm_bo_lookup_mapping(queue->vm, addr >> PAGE_SHIFT);
> - if (!mapping) {
> - amdgpu_bo_unreserve(queue->vm->root.bo);
> - DRM_ERROR("Failed to lookup amdgpu_bo_va_mapping\n");
> - return -EINVAL;
> - }
> + drm_exec_init(&exec, DRM_EXEC_IGNORE_DUPLICATES, 2);
> + drm_exec_until_all_locked(&exec) {
> + ret = amdgpu_vm_lock_pd(queue->vm, &exec, 1);
> + drm_exec_retry_on_contention(&exec);
> + if (unlikely(ret))
> + goto lock_error;
>
> - bo = amdgpu_bo_ref(mapping->bo_va->base.bo);
> - amdgpu_bo_unreserve(queue->vm->root.bo);
> - r = amdgpu_bo_reserve(bo, true);
> - if (r) {
> - amdgpu_bo_unref(&bo);
> - DRM_ERROR("Failed to reserve userqueue wptr bo");
> - return r;
> + mapping = amdgpu_vm_bo_lookup_mapping(queue->vm, addr >> PAGE_SHIFT);
> + if (!mapping) {
> + ret = -EINVAL;
> + goto lock_error;
> + }
> +
> + ret = drm_exec_lock_obj(&exec, &mapping->bo_va->base.bo->tbo.base);
> + drm_exec_retry_on_contention(&exec);
> + if (unlikely(ret))
> + goto lock_error;
> }
>
> - r = amdgpu_bo_kmap(bo, (void **)&ptr);
> - if (r) {
> + bo = mapping->bo_va->base.bo;
> + ret = amdgpu_bo_kmap(bo, (void **)&ptr);
> + if (ret) {
> DRM_ERROR("Failed mapping the userqueue wptr bo");
> - goto map_error;
> + goto lock_error;
> }
>
> *wptr = le64_to_cpu(*ptr);
>
> amdgpu_bo_kunmap(bo);
> - amdgpu_bo_unreserve(bo);
> - amdgpu_bo_unref(&bo);
> -
> + drm_exec_fini(&exec);
> return 0;
>
> -map_error:
> - amdgpu_bo_unreserve(bo);
> - amdgpu_bo_unref(&bo);
> -
> - return r;
> +lock_error:
> + drm_exec_fini(&exec);
> + return ret;
> }
>
> static void
prev parent reply other threads:[~2026-05-11 13:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 10:39 [PATCH v2 1/2] drm/amdgpu/userq: use drm_exec in amdgpu_userq_fence_read_wptr Sunil Khatri
2026-05-08 10:39 ` [PATCH v2 2/2] drm/amdgpu/userq: pin mqd and fw object bo to avoid eviction Sunil Khatri
2026-05-11 13:27 ` Christian König
2026-05-11 13:29 ` Khatri, Sunil
2026-05-11 12:29 ` [PATCH v2 1/2] drm/amdgpu/userq: use drm_exec in amdgpu_userq_fence_read_wptr Christian König
2026-05-11 13:22 ` 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=7922720c-4036-474d-805e-04bca3e9cd7a@amd.com \
--to=christian.koenig@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=sunil.khatri@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox