All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Chen, Xiaogang" <xiaogang.chen@amd.com>
To: Felix Kuehling <Felix.Kuehling@amd.com>,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Cc: christian.koenig@amd.com
Subject: Re: [PATCH 6/6] drm/amdgpu: Do bo_va ref counting for KFD BOs
Date: Fri, 13 Jan 2023 16:58:06 -0600	[thread overview]
Message-ID: <513453ef-4632-9990-e5a6-bb97fffc4c11@amd.com> (raw)
In-Reply-To: <20230112013157.750568-7-Felix.Kuehling@amd.com>

Reviewed-by: Xiaogang Chen <Xiaoganng.Chen@amd.com>

Regards

Xiaogang

On 1/11/2023 7:31 PM, Felix Kuehling wrote:
> This is needed to correctly handle BOs imported into the GEM API, which
> would otherwise get added twice to the same VM.
>
> Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
> ---
>   .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 28 +++++++++++++++----
>   1 file changed, 22 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index df08e84f01d7..8b5ba2e04a79 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -370,9 +370,17 @@ static int amdgpu_amdkfd_bo_validate_and_fence(struct amdgpu_bo *bo,
>   		return ret;
>   
>   	ret = amdgpu_amdkfd_bo_validate(bo, domain, true);
> -	if (!ret)
> -		dma_resv_add_fence(bo->tbo.base.resv, fence,
> -				   DMA_RESV_USAGE_BOOKKEEP);
> +	if (ret)
> +		goto unreserve_out;
> +
> +	ret = dma_resv_reserve_fences(bo->tbo.base.resv, 1);
> +	if (ret)
> +		goto unreserve_out;
> +
> +	dma_resv_add_fence(bo->tbo.base.resv, fence,
> +			   DMA_RESV_USAGE_BOOKKEEP);
> +
> +unreserve_out:
>   	amdgpu_bo_unreserve(bo);
>   
>   	return ret;
> @@ -785,6 +793,7 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem,
>   	uint64_t va = mem->va;
>   	struct kfd_mem_attachment *attachment[2] = {NULL, NULL};
>   	struct amdgpu_bo *bo[2] = {NULL, NULL};
> +	struct amdgpu_bo_va *bo_va;
>   	bool same_hive = false;
>   	int i, ret;
>   
> @@ -871,7 +880,12 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem,
>   			pr_debug("Unable to reserve BO during memory attach");
>   			goto unwind;
>   		}
> -		attachment[i]->bo_va = amdgpu_vm_bo_add(adev, vm, bo[i]);
> +		bo_va = amdgpu_vm_bo_find(vm, bo[i]);
> +		if (!bo_va)
> +			bo_va = amdgpu_vm_bo_add(adev, vm, bo[i]);
> +		else
> +			++bo_va->ref_count;
> +		attachment[i]->bo_va = bo_va;
>   		amdgpu_bo_unreserve(bo[i]);
>   		if (unlikely(!attachment[i]->bo_va)) {
>   			ret = -ENOMEM;
> @@ -895,7 +909,8 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem,
>   			continue;
>   		if (attachment[i]->bo_va) {
>   			amdgpu_bo_reserve(bo[i], true);
> -			amdgpu_vm_bo_del(adev, attachment[i]->bo_va);
> +			if (--attachment[i]->bo_va->ref_count == 0)
> +				amdgpu_vm_bo_del(adev, attachment[i]->bo_va);
>   			amdgpu_bo_unreserve(bo[i]);
>   			list_del(&attachment[i]->list);
>   		}
> @@ -912,7 +927,8 @@ static void kfd_mem_detach(struct kfd_mem_attachment *attachment)
>   
>   	pr_debug("\t remove VA 0x%llx in entry %p\n",
>   			attachment->va, attachment);
> -	amdgpu_vm_bo_del(attachment->adev, attachment->bo_va);
> +	if (--attachment->bo_va->ref_count == 0)
> +		amdgpu_vm_bo_del(attachment->adev, attachment->bo_va);
>   	drm_gem_object_put(&bo->tbo.base);
>   	list_del(&attachment->list);
>   	kfree(attachment);

  reply	other threads:[~2023-01-13 22:58 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-12  1:31 [PATCH 0/6] Enable KFD to use render node BO mappings Felix Kuehling
2023-01-12  1:31 ` [PATCH 1/6] drm/amdgpu: Generalize KFD dmabuf import Felix Kuehling
2023-01-12 22:41   ` Chen, Xiaogang
2023-01-13 22:26     ` Felix Kuehling
2023-01-13 23:00       ` Chen, Xiaogang
2023-01-13 23:15         ` Felix Kuehling
2023-01-15 16:43           ` Christian König
2023-01-15 18:32             ` Felix Kuehling
2023-01-16 11:42               ` Christian König
2023-01-16 14:52                 ` Felix Kuehling
2023-01-16 15:11                   ` Christian König
2023-01-17  1:06                     ` Dmitry Osipenko
2023-02-16 12:22                       ` Daniel Vetter
2023-02-16 12:22                         ` Daniel Vetter
2023-01-16 22:04   ` Errabolu, Ramesh
2023-01-16 22:25     ` Felix Kuehling
2023-01-12  1:31 ` [PATCH 2/6] drm/amdkfd: Implement DMA buf fd export from KFD Felix Kuehling
2023-01-13  8:03   ` Chen, Xiaogang
2023-01-12  1:31 ` [PATCH 3/6] drm/amdkfd: Improve amdgpu_vm_handle_moved Felix Kuehling
2023-01-13  8:05   ` Chen, Xiaogang
2023-01-12  1:31 ` [PATCH 4/6] drm/amdgpu: Attach eviction fence on alloc Felix Kuehling
2023-01-13  8:12   ` Chen, Xiaogang
2023-01-16 22:11   ` Errabolu, Ramesh
2023-01-16 22:51     ` Felix Kuehling
2023-01-12  1:31 ` [PATCH 5/6] drm/amdgpu: update mappings not managed by KFD Felix Kuehling
2023-01-13 20:02   ` Chen, Xiaogang
2023-01-12  1:31 ` [PATCH 6/6] drm/amdgpu: Do bo_va ref counting for KFD BOs Felix Kuehling
2023-01-13 22:58   ` Chen, Xiaogang [this message]
2023-01-16 22:12     ` Errabolu, Ramesh
2023-01-16 22:58       ` Felix Kuehling
2023-01-12  7:18 ` [PATCH 0/6] Enable KFD to use render node BO mappings Christian König
  -- strict thread matches above, loose matches on Subject: below --
2022-11-18 23:44 Felix Kuehling
2022-11-18 23:44 ` [PATCH 6/6] drm/amdgpu: Do bo_va ref counting for KFD BOs Felix Kuehling

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=513453ef-4632-9990-e5a6-bb97fffc4c11@amd.com \
    --to=xiaogang.chen@amd.com \
    --cc=Felix.Kuehling@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    /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.