All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: Nirmoy Das <nirmoy.das@amd.com>,
	Christian.Koenig@amd.com, Felix.Kuehling@amd.com
Cc: amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH v2 2/3] drm/amdgpu: introduce kfd user flag for amdgpu_bo
Date: Wed, 3 Mar 2021 13:01:11 +0100	[thread overview]
Message-ID: <eb637494-e025-8231-94c4-46929bc76644@gmail.com> (raw)
In-Reply-To: <20210303092550.110816-2-nirmoy.das@amd.com>

Am 03.03.21 um 10:25 schrieb Nirmoy Das:
> Introduce a new flag for amdgpu_bo->flags to identify if
> a BO is created by KFD.
>
> v2: rename AMDGPU_GEM_USER_KFD -> AMDGPU_GEM_CREATE_KFD
>
> Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
> ---
>   .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  |  2 +-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       |  3 +-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c    | 48 ++++++++++++++++++-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.h    |  3 ++
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c       |  2 +-
>   include/uapi/drm/amdgpu_drm.h                 |  5 ++
>   6 files changed, 59 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index 89d0e4f7c6a8..57798707cd5f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -1227,7 +1227,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
>   	bp.flags = alloc_flags;
>   	bp.type = bo_type;
>   	bp.resv = NULL;
> -	ret = amdgpu_bo_create(adev, &bp, &bo);
> +	ret = amdgpu_kfd_bo_create(adev, &bp, &bo);
>   	if (ret) {
>   		pr_debug("Failed to create BO on domain %s. ret %d\n",
>   				domain_string(alloc_domain), ret);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> index 8e9b8a6e6ef0..e0ceeb32642c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> @@ -234,7 +234,8 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
>   		      AMDGPU_GEM_CREATE_VRAM_CLEARED |
>   		      AMDGPU_GEM_CREATE_VM_ALWAYS_VALID |
>   		      AMDGPU_GEM_CREATE_EXPLICIT_SYNC |
> -		      AMDGPU_GEM_CREATE_ENCRYPTED))
> +		      AMDGPU_GEM_CREATE_ENCRYPTED |
> +		      AMDGPU_GEM_CREATE_KFD))
>
>   		return -EINVAL;
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index 0bd22ed1dacf..1b41b4870c99 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -697,6 +697,52 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
>   	return r;
>   }
>
> +/**
> + * amdgpu_kfd_bo_create - create an &amdgpu_bo buffer object with kfd user flag
> + * @adev: amdgpu device object
> + * @bp: parameters to be used for the buffer object
> + * @bo_ptr: pointer to the buffer object pointer
> + *
> + * Creates an &amdgpu_bo buffer object; and if requested, also creates a
> + * shadow object.
> + * Shadow object is used to backup the original buffer object, and is always
> + * in GTT.
> + *
> + * Returns:
> + * 0 for success or a negative error code on failure.
> + */
> +
> +int amdgpu_kfd_bo_create(struct amdgpu_device *adev,

Please name this amdgpu_bo_create_kfd instead.

> +			 struct amdgpu_bo_param *bp,
> +			 struct amdgpu_bo **bo_ptr)
> +{
> +	u64 flags = bp->flags;
> +	int r;
> +
> +	bp->flags = bp->flags & ~AMDGPU_GEM_CREATE_SHADOW;
> +	bp->flags = bp->flags | AMDGPU_GEM_CREATE_KFD;
> +	r = amdgpu_bo_do_create(adev, bp, bo_ptr);
> +	if (r)
> +		return r;
> +
> +	if ((flags & AMDGPU_GEM_CREATE_SHADOW) && !(adev->flags & AMD_IS_APU)) {
> +		if (!bp->resv)
> +			WARN_ON(dma_resv_lock((*bo_ptr)->tbo.base.resv,
> +							NULL));
> +
> +		r = amdgpu_bo_create_shadow(adev, bp->size, *bo_ptr);
> +
> +		if (!bp->resv)
> +			dma_resv_unlock((*bo_ptr)->tbo.base.resv);
> +
> +		if (r)
> +			amdgpu_bo_unref(bo_ptr);
> +	}

I don't think the KFD should ever have a reason to use the shadow buffer 
functionality.

> +
> +	return r;
> +}
> +
> +
>   /**
>    * amdgpu_bo_validate - validate an &amdgpu_bo buffer object
>    * @bo: pointer to the buffer object
> @@ -1309,7 +1355,7 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo)
>
>   	abo = ttm_to_amdgpu_bo(bo);
>
> -	if (abo->kfd_bo)
> +	if (abo->flags & AMDGPU_GEM_CREATE_KFD)
>   		amdgpu_amdkfd_unreserve_memory_limit(abo);
>
>   	/* We only remove the fence if the resv has individualized. */
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> index 8cd96c9330dd..665ee0015f06 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> @@ -245,6 +245,9 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain);
>   int amdgpu_bo_create(struct amdgpu_device *adev,
>   		     struct amdgpu_bo_param *bp,
>   		     struct amdgpu_bo **bo_ptr);
> +int amdgpu_kfd_bo_create(struct amdgpu_device *adev,
> +			 struct amdgpu_bo_param *bp,
> +			 struct amdgpu_bo **bo_ptr);
>   int amdgpu_bo_create_reserved(struct amdgpu_device *adev,
>   			      unsigned long size, int align,
>   			      u32 domain, struct amdgpu_bo **bo_ptr,
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index 7b2db779f313..030bec382f54 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -164,7 +164,7 @@ static int amdgpu_verify_access(struct ttm_buffer_object *bo, struct file *filp)
>   	 * Don't verify access for KFD BOs. They don't have a GEM
>   	 * object associated with them.
>   	 */
> -	if (abo->kfd_bo)
> +	if (abo->flags & AMDGPU_GEM_CREATE_KFD)
>   		return 0;
>
>   	if (amdgpu_ttm_tt_get_usermm(bo->ttm))
> diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
> index 8b832f7458f2..f510e8302228 100644
> --- a/include/uapi/drm/amdgpu_drm.h
> +++ b/include/uapi/drm/amdgpu_drm.h
> @@ -142,6 +142,11 @@ extern "C" {
>    */
>   #define AMDGPU_GEM_CREATE_ENCRYPTED		(1 << 10)
>
> +/* Flag that the allocating BO's user is KFD. It should never be used by
> + * user space applications
> + */
> +#define AMDGPU_GEM_CREATE_KFD			(1 << 20)

Why 20? 11 is the next one here.

Christian.

> +
>   struct drm_amdgpu_gem_create_in  {
>   	/** the requested memory size */
>   	__u64 bo_size;
> --
> 2.30.1
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  reply	other threads:[~2021-03-03 12:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-03  9:25 [PATCH 1/3] drm/amdgpu: drm/amdkfd: split amdgpu_mn_register Nirmoy Das
2021-03-03  9:25 ` [PATCH v2 2/3] drm/amdgpu: introduce kfd user flag for amdgpu_bo Nirmoy Das
2021-03-03 12:01   ` Christian König [this message]
2021-03-03 12:41     ` Nirmoy
2021-03-03 12:46       ` Christian König
2021-03-03  9:25 ` [PATCH v2 3/3] drm/amdgpu: drm/amdkfd: add amdgpu_kfd_bo struct Nirmoy Das
2021-03-03 12:04   ` Christian König
2021-03-03 13:06     ` Nirmoy
2021-03-05  0:37     ` Felix Kuehling
2021-03-05  9:13       ` Nirmoy

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=eb637494-e025-8231-94c4-46929bc76644@gmail.com \
    --to=ckoenig.leichtzumerken@gmail.com \
    --cc=Christian.Koenig@amd.com \
    --cc=Felix.Kuehling@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=nirmoy.das@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 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.