From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>,
amd-gfx@lists.freedesktop.org
Cc: christian.koenig@amd.com, alexander.deucher@amd.com
Subject: Re: [PATCH v2 08/08] drm/amdgpu: add vm root BO lock before accessing the vm
Date: Thu, 26 Sep 2024 14:32:47 +0200 [thread overview]
Message-ID: <64119b68-12d0-4bc3-890e-edf809cb68df@gmail.com> (raw)
In-Reply-To: <20240925195928.142001-8-Arunpravin.PaneerSelvam@amd.com>
Am 25.09.24 um 21:59 schrieb Arunpravin Paneer Selvam:
> Add a vm root BO lock before accessing the userqueue VM.
>
> Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
> ---
> .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 19 +++++++++++--------
> 1 file changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
> index 43429661f62d..52722b738316 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
> @@ -320,7 +320,6 @@ static const struct dma_fence_ops amdgpu_userq_fence_ops = {
> /**
> * amdgpu_userq_fence_read_wptr - Read the userq wptr value
> *
> - * @filp: drm file private data structure
> * @queue: user mode queue structure pointer
> * @wptr: write pointer value
> *
> @@ -330,23 +329,27 @@ static const struct dma_fence_ops amdgpu_userq_fence_ops = {
> *
> * Returns wptr value on success, error on failure.
> */
> -static int amdgpu_userq_fence_read_wptr(struct drm_file *filp,
> - struct amdgpu_usermode_queue *queue,
> +static int amdgpu_userq_fence_read_wptr(struct amdgpu_usermode_queue *queue,
> u64 *wptr)
> {
> - struct amdgpu_fpriv *fpriv = filp->driver_priv;
> struct amdgpu_bo_va_mapping *mapping;
> - struct amdgpu_vm *vm = &fpriv->vm;
> struct amdgpu_bo *bo;
> u64 addr, *ptr;
> int r;
>
> + r = amdgpu_bo_reserve(queue->vm->root.bo, false);
> + if (r)
> + return r;
> +
> addr = queue->userq_prop->wptr_gpu_addr;
> addr &= AMDGPU_GMC_HOLE_MASK;
>
> - mapping = amdgpu_vm_bo_lookup_mapping(vm, addr >> PAGE_SHIFT);
> - if (!mapping)
> + mapping = amdgpu_vm_bo_lookup_mapping(queue->vm, addr >> PAGE_SHIFT);
> + amdgpu_bo_unreserve(queue->vm->root.bo);
You need to keep the VM locked until you are done with the mapping.
Otherwise the mapping could be released at any time.
Regards,
Christian.
> + if (!mapping) {
> + DRM_ERROR("Failed to lookup amdgpu_bo_va_mapping\n");
> return -EINVAL;
> + }
>
> bo = mapping->bo_va->base.bo;
If you only need the BO then grab a temporary BO reference here, drop
the VM lock and acquire the BO.
When you are done with everything just drop the BO lock and then the
temporary BO reference.
Regards,
Christian.
> r = amdgpu_bo_reserve(bo, true);
> @@ -448,7 +451,7 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,
> goto exec_fini;
> }
>
> - r = amdgpu_userq_fence_read_wptr(filp, queue, &wptr);
> + r = amdgpu_userq_fence_read_wptr(queue, &wptr);
> if (r)
> goto exec_fini;
>
next prev parent reply other threads:[~2024-09-26 12:32 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-25 19:59 [PATCH v2 01/08] drm/amdgpu: Implement userqueue signal/wait IOCTL Arunpravin Paneer Selvam
2024-09-25 19:59 ` [PATCH v2 02/08] drm/amdgpu: screen freeze and userq driver crash Arunpravin Paneer Selvam
2024-09-26 11:38 ` Christian König
2024-09-25 19:59 ` [PATCH v2 03/08] drm/amdgpu: Add wait IOCTL timeline syncobj support Arunpravin Paneer Selvam
2024-09-26 11:49 ` Christian König
2024-09-25 19:59 ` [PATCH v2 04/08] drm/amdgpu: Enable userq fence interrupt support Arunpravin Paneer Selvam
2024-09-25 19:59 ` [PATCH v2 05/08] drm/amdgpu: Remove the MES self test Arunpravin Paneer Selvam
2024-09-25 19:59 ` [PATCH v2 06/08] drm/amdgpu: Add few optimizations to userq fence driver Arunpravin Paneer Selvam
2024-09-26 12:28 ` Christian König
2024-09-25 19:59 ` [PATCH v2 07/08] drm/amdgpu: Add the missing error handling for xa_store() call Arunpravin Paneer Selvam
2024-09-26 12:29 ` Christian König
2024-09-25 19:59 ` [PATCH v2 08/08] drm/amdgpu: add vm root BO lock before accessing the vm Arunpravin Paneer Selvam
2024-09-26 12:32 ` Christian König [this message]
2024-09-26 9:27 ` [PATCH v2 01/08] drm/amdgpu: Implement userqueue signal/wait IOCTL Christian König
2024-09-26 9:31 ` Paneer Selvam, Arunpravin
2024-09-26 9:34 ` Christian König
2024-09-26 10:26 ` Paneer Selvam, Arunpravin
2024-09-26 11:16 ` Christian König
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=64119b68-12d0-4bc3-890e-edf809cb68df@gmail.com \
--to=ckoenig.leichtzumerken@gmail.com \
--cc=Arunpravin.PaneerSelvam@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@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