[PATCH 1/8] drm/amdgpu: use GEM references instead of TTMs
Daniel Vetter
daniel.vetter at ffwll.ch
Thu Jul 25 12:01:36 UTC 2024
On Tue, Jul 23, 2024 at 02:17:43PM +0200, Christian König wrote:
> Instead of a TTM reference grab a GEM reference whenever necessary.
>
> Signed-off-by: Christian König <christian.koenig at amd.com>
> Cc: Alex Deucher <alexander.deucher at amd.com>
> Cc: Felix Kuehling <felix.kuehling at amd.com>
> Cc: amd-gfx at lists.freedesktop.org
I was worried that changing the refcounting for the mmu_interval_notifier
that this patch does could result in a use-after-free, but the mmu
notifier code already does the required amount of mmgrab/mmdrop, so we're
good.
Reviewed-by: Daniel Vetter <daniel.vetter at ffwll.ch>
Cheers, Sima
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 8 ++++----
> drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 7 ++-----
> 2 files changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> index 67c234bcf89f..6be3d7cd1c51 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> @@ -87,11 +87,11 @@ static const struct vm_operations_struct amdgpu_gem_vm_ops = {
>
> static void amdgpu_gem_object_free(struct drm_gem_object *gobj)
> {
> - struct amdgpu_bo *robj = gem_to_amdgpu_bo(gobj);
> + struct amdgpu_bo *aobj = gem_to_amdgpu_bo(gobj);
>
> - if (robj) {
> - amdgpu_hmm_unregister(robj);
> - amdgpu_bo_unref(&robj);
> + if (aobj) {
> + amdgpu_hmm_unregister(aobj);
> + ttm_bo_put(&aobj->tbo);
> }
> }
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index 8d8c39be6129..6c187e310034 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -853,7 +853,7 @@ struct amdgpu_bo *amdgpu_bo_ref(struct amdgpu_bo *bo)
> if (bo == NULL)
> return NULL;
>
> - ttm_bo_get(&bo->tbo);
> + drm_gem_object_get(&bo->tbo.base);
> return bo;
> }
>
> @@ -865,13 +865,10 @@ struct amdgpu_bo *amdgpu_bo_ref(struct amdgpu_bo *bo)
> */
> void amdgpu_bo_unref(struct amdgpu_bo **bo)
> {
> - struct ttm_buffer_object *tbo;
> -
> if ((*bo) == NULL)
> return;
>
> - tbo = &((*bo)->tbo);
> - ttm_bo_put(tbo);
> + drm_gem_object_get(&(*bo)->tbo.base);
> *bo = NULL;
> }
>
> --
> 2.34.1
>
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
More information about the dri-devel
mailing list