Skip to contentSkip to conversation

drm/amdgpu: allow variable BO struct creation

PATCH In review Nirmoy Das 4 participants 16 messages Mar 5, 2021 – Mar 8, 2021

Subsystems (3)
lore
Share & tools
lore

Nirmoy Das

author
#0 lore raw

PATCH 1/5 drm/amdgpu: allow variable BO struct creation

Allow allocating BO structures with different structure size than struct amdgpu_bo.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 +
 2 files changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -0
index 0bd22ed1dacf..745393472564 100644
@@ -551,6 +551,8 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
 
 	acc_size = ttm_bo_dma_acc_size(&adev->mman.bdev, size,
 				       sizeof(struct amdgpu_bo));
+	if (bp->bo_ptr_size < sizeof(struct amdgpu_bo))
+		bp->bo_ptr_size = sizeof(struct amdgpu_bo);
 
 	bo = kzalloc(sizeof(struct amdgpu_bo), GFP_KERNEL);
 	if (bo == NULL)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
index 8cd96c9330dd..848dc0a017dd 100644
@@ -40,6 +40,7 @@
 struct amdgpu_bo_param {
 	unsigned long			size;
 	int				byte_align;
+	u32				bo_ptr_size;
 	u32				domain;
 	u32				preferred_domain;
 	u64				flags;
Signature · 6 lines
2.30.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#1 lore raw

PATCH 2/5 drm/amdgpu: introduce struct amdgpu_bo_user

Implement a new struct amdgpu_bo_user as subclass of struct amdgpu_bo and a function to created amdgpu_bo_user bo with a flag to identify the owner.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 28 ++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 12 ++++++++++
 2 files changed, 40 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +28 -0
index 745393472564..355d01ebce51 100644
@@ -699,6 +699,34 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
 	return r;
 }
 
+/**
+ * amdgpu_bo_create_user - create an &amdgpu_bo_user buffer object
+ * @adev: amdgpu device object
+ * @bp: parameters to be used for the buffer object
+ * @ubo_ptr: pointer to the buffer object pointer
+ *
+ * Create a BO to be used by user application;
+ *
+ * Returns:
+ * 0 for success or a negative error code on failure.
+ */
+
+int amdgpu_bo_create_user(struct amdgpu_device *adev,
+		     struct amdgpu_bo_param *bp,
+		     struct amdgpu_bo_user **ubo_ptr)
+{
+	struct amdgpu_bo *bo_ptr;
+	int r;
+
+	bp->flags = bp->flags & ~AMDGPU_GEM_CREATE_SHADOW;
+	bp->bo_ptr_size = sizeof(struct amdgpu_bo_user);
+	r = amdgpu_bo_do_create(adev, bp, &bo_ptr);
+	if (r)
+		return r;
+
+	*ubo_ptr = (struct amdgpu_bo_user *)bo_ptr;
+	return r;
+}
 /**
  * amdgpu_bo_validate - validate an &amdgpu_bo buffer object
  * @bo: pointer to the buffer object
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +12 -0
index 848dc0a017dd..cbb881afe6da 100644
@@ -114,6 +114,15 @@ struct amdgpu_bo {
 	struct kgd_mem                  *kfd_bo;
 };
 
+struct amdgpu_bo_user {
+	struct amdgpu_bo		bo;
+	u64				tiling_flags;
+	u64				metadata_flags;
+	void				*metadata;
+	u32				metadata_size;
+
+};
+
 static inline struct amdgpu_bo *ttm_to_amdgpu_bo(struct ttm_buffer_object *tbo)
 {
 	return container_of(tbo, struct amdgpu_bo, tbo);
@@ -257,6 +266,9 @@ int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
 int amdgpu_bo_create_kernel_at(struct amdgpu_device *adev,
 			       uint64_t offset, uint64_t size, uint32_t domain,
 			       struct amdgpu_bo **bo_ptr, void **cpu_addr);
+int amdgpu_bo_create_user(struct amdgpu_device *adev,
+		     struct amdgpu_bo_param *bp,
+		     struct amdgpu_bo_user **ubo_ptr);
 void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr,
 			   void **cpu_addr);
 int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr);
Signature · 6 lines
2.30.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#2 lore raw

Re: [PATCH 2/5] drm/amdgpu: introduce struct amdgpu_bo_user

Am 05.03.21 um 15:35 schrieb Nirmoy Das:

Quoted 34 lines

Implement a new struct amdgpu_bo_user as subclass of struct amdgpu_bo and a function to created amdgpu_bo_user bo with a flag to identify the owner.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 28 ++++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 12 ++++++++++
  2 files changed, 40 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +16 -0
index 745393472564..355d01ebce51 100644
@@ -699,6 +699,34 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
  	return r;
  }
 
+/**
+ * amdgpu_bo_create_user - create an &amdgpu_bo_user buffer object
+ * @adev: amdgpu device object
+ * @bp: parameters to be used for the buffer object
+ * @ubo_ptr: pointer to the buffer object pointer
+ *
+ * Create a BO to be used by user application;
+ *
+ * Returns:
+ * 0 for success or a negative error code on failure.
+ */
+
+int amdgpu_bo_create_user(struct amdgpu_device *adev,
+		     struct amdgpu_bo_param *bp,
+		     struct amdgpu_bo_user **ubo_ptr)
+{

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create(struct amdgpu_device *adev, · line 727

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +10 -0
+	struct amdgpu_bo *bo_ptr;
+	int r;
+
+	bp->flags = bp->flags & ~AMDGPU_GEM_CREATE_SHADOW;
+	bp->bo_ptr_size = sizeof(struct amdgpu_bo_user);
+	r = amdgpu_bo_do_create(adev, bp, &bo_ptr);
+	if (r)
+		return r;
+
+	*ubo_ptr = (struct amdgpu_bo_user *)bo_ptr;

Maybe use container_of here instead. Even better would be a helper to upcast a amdgpu_bo pointer into a amdgpu_bo_user pointer.

Christian.

Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -0
+	return r;
+}
  /**
   * amdgpu_bo_validate - validate an &amdgpu_bo buffer object
   * @bo: pointer to the buffer object
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +9 -0
index 848dc0a017dd..cbb881afe6da 100644
@@ -114,6 +114,15 @@ struct amdgpu_bo {
  	struct kgd_mem                  *kfd_bo;
  };
 
+struct amdgpu_bo_user {
+	struct amdgpu_bo		bo;
+	u64				tiling_flags;
+	u64				metadata_flags;
+	void				*metadata;
+	u32				metadata_size;
+
+};
+
  static inline struct amdgpu_bo *ttm_to_amdgpu_bo(struct ttm_buffer_object *tbo)
  {
  	return container_of(tbo, struct amdgpu_bo, tbo);

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h int amdgpu_bo_create_kernel(struct amdgpu_device *adev, · line 274

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +3 -0
@@ -257,6 +266,9 @@ int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
  int amdgpu_bo_create_kernel_at(struct amdgpu_device *adev,
  			       uint64_t offset, uint64_t size, uint32_t domain,
  			       struct amdgpu_bo **bo_ptr, void **cpu_addr);
+int amdgpu_bo_create_user(struct amdgpu_device *adev,
+		     struct amdgpu_bo_param *bp,
+		     struct amdgpu_bo_user **ubo_ptr);
  void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr,
  			   void **cpu_addr);
  int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#3 lore raw

PATCH 3/5 drm/amdgpu: use amdgpu_bo_create_user() for gem object

In reply to Nirmoy Das

GEM objects encapsulate amdgpu_bo for userspace applications. Now that we have a new amdgpu_bo_user subclass for that purpose, let's use that instead.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +3 -1
index 8e9b8a6e6ef0..9d2b55eb31c2 100644
@@ -54,6 +54,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
 			     struct drm_gem_object **obj)
 {
 	struct amdgpu_bo *bo;
+	struct amdgpu_bo_user *ubo;
 	struct amdgpu_bo_param bp;
 	int r;
 
@@ -68,7 +69,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
 retry:
 	bp.flags = flags;
 	bp.domain = initial_domain;
-	r = amdgpu_bo_create(adev, &bp, &bo);
+	r = amdgpu_bo_create_user(adev, &bp, &ubo);
 	if (r) {
 		if (r != -ERESTARTSYS) {
 			if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {
@@ -85,6 +86,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
 		}
 		return r;
 	}
+	bo = &ubo->bo;
 	*obj = &bo->tbo.base;
 
 	return 0;
Signature · 6 lines
2.30.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#4 lore raw

Re: [PATCH 3/5] drm/amdgpu: use amdgpu_bo_create_user() for gem object

We might need to use this for the KFD as well.

Christian.

Am 05.03.21 um 15:35 schrieb Nirmoy Das:

Quoted 31 lines

GEM objects encapsulate amdgpu_bo for userspace applications. Now that we have a new amdgpu_bo_user subclass for that purpose, let's use that instead.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index 8e9b8a6e6ef0..9d2b55eb31c2 100644
@@ -54,6 +54,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
  			     struct drm_gem_object **obj)
  {
  	struct amdgpu_bo *bo;
+	struct amdgpu_bo_user *ubo;
  	struct amdgpu_bo_param bp;
  	int r;
 
@@ -68,7 +69,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
  retry:
  	bp.flags = flags;
  	bp.domain = initial_domain;
-	r = amdgpu_bo_create(adev, &bp, &bo);
+	r = amdgpu_bo_create_user(adev, &bp, &ubo);
  	if (r) {
  		if (r != -ERESTARTSYS) {
  			if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size, · line 92

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -0
@@ -85,6 +86,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
  		}
  		return r;
  	}
+	bo = &ubo->bo;
  	*obj = &bo->tbo.base;
 
  	return 0;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#5 lore raw

Re: [PATCH 3/5] drm/amdgpu: use amdgpu_bo_create_user() for gem object

Quoted 1 line · Christian König

We might need to use this for the KFD as well.

Do you mean for amdgpu_amdkfd_alloc_gws() ?

Regards,

Nirmoy

Quoted 34 lines

Christian.

Am 05.03.21 um 15:35 schrieb Nirmoy Das:

Quoted 30 lines

GEM objects encapsulate amdgpu_bo for userspace applications. Now that we have a new amdgpu_bo_user subclass for that purpose, let's use that instead.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 4 +++-

  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -0
index 8e9b8a6e6ef0..9d2b55eb31c2 100644
@@ -54,6 +54,7 @@ int amdgpu_gem_object_create(struct amdgpu_device 
 *adev, unsigned long size,
                    struct drm_gem_object **obj)
   {
       struct amdgpu_bo *bo;
+    struct amdgpu_bo_user *ubo;
       struct amdgpu_bo_param bp;
       int r;

  @@ -68,7 +69,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size, retry:
      bp.flags = flags;
      bp.domain = initial_domain;
-    r = amdgpu_bo_create(adev, &bp, &bo);
+    r = amdgpu_bo_create_user(adev, &bp, &ubo);
      if (r) {
          if (r != -ERESTARTSYS) {
              if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {

Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_object_create(struct amdgpu_device · line 92

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -0
@@ -85,6 +86,7 @@ int amdgpu_gem_object_create(struct amdgpu_device 
 *adev, unsigned long size,
           }
           return r;
       }
+    bo = &ubo->bo;
       *obj = &bo->tbo.base;
         return 0;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

maintainer
#6 lore raw

Re: [PATCH 3/5] drm/amdgpu: use amdgpu_bo_create_user() for gem object

Am 08.03.21 um 14:56 schrieb Nirmoy:

Quoted 5 lines · Christian König
Quoted 1 line

We might need to use this for the KFD as well.

Do you mean for amdgpu_amdkfd_alloc_gws() ?

For example, yes. Basically all places where KFD allocated an BO with the TTM type device/user.

Regards,
Christian.

Quoted 51 lines

Regards,

Nirmoy

Quoted 43 lines

Christian.

Am 05.03.21 um 15:35 schrieb Nirmoy Das:

Quoted 38 lines

GEM objects encapsulate amdgpu_bo for userspace applications. Now that we have a new amdgpu_bo_user subclass for that purpose, let's use that instead.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 4 +++-

  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -0
index 8e9b8a6e6ef0..9d2b55eb31c2 100644
@@ -54,6 +54,7 @@ int amdgpu_gem_object_create(struct amdgpu_device 
 *adev, unsigned long size,
                    struct drm_gem_object **obj)
   {
       struct amdgpu_bo *bo;
+    struct amdgpu_bo_user *ubo;
       struct amdgpu_bo_param bp;
       int r;

  @@ -68,7 +69,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size, retry:
      bp.flags = flags;
      bp.domain = initial_domain;
-    r = amdgpu_bo_create(adev, &bp, &bo);
+    r = amdgpu_bo_create_user(adev, &bp, &ubo);
      if (r) {
          if (r != -ERESTARTSYS) {
              if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -0
@@ -85,6 +86,7 @@ int amdgpu_gem_object_create(struct amdgpu_device 
 *adev, unsigned long size,
           }
           return r;
       }
+    bo = &ubo->bo;
       *obj = &bo->tbo.base;
         return 0;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#7 lore raw

Re: [PATCH 3/5] drm/amdgpu: use amdgpu_bo_create_user() for gem object

Quoted 10 lines · Christian König

Am 08.03.21 um 14:56 schrieb Nirmoy:

Quoted 5 lines · Christian König
Quoted 1 line

We might need to use this for the KFD as well.

Do you mean for amdgpu_amdkfd_alloc_gws() ?

For example, yes. Basically all places where KFD allocated an BO with the TTM type device/user.

Thanks Christian!

Quoted 56 lines

Regards,
Christian.

Quoted 51 lines

Regards,

Nirmoy

Quoted 43 lines

Christian.

Am 05.03.21 um 15:35 schrieb Nirmoy Das:

Quoted 38 lines

GEM objects encapsulate amdgpu_bo for userspace applications. Now that we have a new amdgpu_bo_user subclass for that purpose, let's use that instead.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 4 +++-

  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -0
index 8e9b8a6e6ef0..9d2b55eb31c2 100644
@@ -54,6 +54,7 @@ int amdgpu_gem_object_create(struct amdgpu_device 
 *adev, unsigned long size,
                    struct drm_gem_object **obj)
   {
       struct amdgpu_bo *bo;
+    struct amdgpu_bo_user *ubo;
       struct amdgpu_bo_param bp;
       int r;

  @@ -68,7 +69,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size, retry:
      bp.flags = flags;
      bp.domain = initial_domain;
-    r = amdgpu_bo_create(adev, &bp, &bo);
+    r = amdgpu_bo_create_user(adev, &bp, &ubo);
      if (r) {
          if (r != -ERESTARTSYS) {
              if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -0
@@ -85,6 +86,7 @@ int amdgpu_gem_object_create(struct amdgpu_device 
 *adev, unsigned long size,
           }
           return r;
       }
+    bo = &ubo->bo;
       *obj = &bo->tbo.base;
         return 0;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#8 lore raw

PATCH 4/5 drm/amdgpu: use tiling_flags of struct amdgpu_bo_user

In reply to Nirmoy Das

This flag is only needed for BOs created by amdgpu_gem_object_create(), so we can remove tiling_flags from the base class.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 19 +++++++++++++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  1 -
 2 files changed, 17 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +17 -2
index 355d01ebce51..2e5cf46251af 100644
@@ -1174,12 +1174,19 @@ int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo,
 int amdgpu_bo_set_tiling_flags(struct amdgpu_bo *bo, u64 tiling_flags)
 {
 	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+	struct amdgpu_bo_user *ubo;
+
+	if (bo->tbo.type != ttm_bo_type_device) {
+		DRM_ERROR("can not set tiling_flags for a non-amdgpu_bo_user type BO\n");
+		return -EINVAL;
+	}
 
 	if (adev->family <= AMDGPU_FAMILY_CZ &&
 	    AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT) > 6)
 		return -EINVAL;
 
-	bo->tiling_flags = tiling_flags;
+	ubo = container_of((bo), struct amdgpu_bo_user, bo);
+	ubo->tiling_flags = tiling_flags;
 	return 0;
 }
 
@@ -1193,10 +1200,18 @@ int amdgpu_bo_set_tiling_flags(struct amdgpu_bo *bo, u64 tiling_flags)
  */
 void amdgpu_bo_get_tiling_flags(struct amdgpu_bo *bo, u64 *tiling_flags)
 {
+	struct amdgpu_bo_user *ubo;
+
+	if (bo->tbo.type != ttm_bo_type_device) {
+		DRM_ERROR("can not get tiling_flags for a non-amdgpu_bo_user type BO\n");
+		return;
+	}
+
 	dma_resv_assert_held(bo->tbo.base.resv);
+	ubo = container_of((bo), struct amdgpu_bo_user, bo);
 
 	if (tiling_flags)
-		*tiling_flags = bo->tiling_flags;
+		*tiling_flags = ubo->tiling_flags;
 }
 
 /**
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -1
index cbb881afe6da..6cc38b71f7ca 100644
@@ -91,7 +91,6 @@ struct amdgpu_bo {
 	struct ttm_bo_kmap_obj		kmap;
 	u64				flags;
 	unsigned			pin_count;
-	u64				tiling_flags;
 	u64				metadata_flags;
 	void				*metadata;
 	u32				metadata_size;
Signature · 6 lines
2.30.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#9 lore raw

Re: [PATCH 4/5] drm/amdgpu: use tiling_flags of struct amdgpu_bo_user

Am 05.03.21 um 15:35 schrieb Nirmoy Das:

Quoted 14 lines

This flag is only needed for BOs created by amdgpu_gem_object_create(), so we can remove tiling_flags from the base class.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 19 +++++++++++++++++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  1 -
  2 files changed, 17 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index 355d01ebce51..2e5cf46251af 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo, · line 1182

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +6 -0
@@ -1174,12 +1174,19 @@ int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo,
  int amdgpu_bo_set_tiling_flags(struct amdgpu_bo *bo, u64 tiling_flags)
  {
  	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+	struct amdgpu_bo_user *ubo;
+
+	if (bo->tbo.type != ttm_bo_type_device) {
+		DRM_ERROR("can not set tiling_flags for a non-amdgpu_bo_user type BO\n");
+		return -EINVAL;
+	}

I would just replace this with a WARN_ON or even BUG_ON since we should never ever make kernel BOs accessible to users space.

But what could be is that this is used with an imported SG table BO, so you need to make this check bo->tbo.type == ttm_bo_type_kernel.

Christian.

Quoted 36 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +11 -2
  	if (adev->family <= AMDGPU_FAMILY_CZ &&
  	    AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT) > 6)
  		return -EINVAL;
 
-	bo->tiling_flags = tiling_flags;
+	ubo = container_of((bo), struct amdgpu_bo_user, bo);
+	ubo->tiling_flags = tiling_flags;
  	return 0;
  }
 
@@ -1193,10 +1200,18 @@ int amdgpu_bo_set_tiling_flags(struct amdgpu_bo *bo, u64 tiling_flags)
   */
  void amdgpu_bo_get_tiling_flags(struct amdgpu_bo *bo, u64 *tiling_flags)
  {
+	struct amdgpu_bo_user *ubo;
+
+	if (bo->tbo.type != ttm_bo_type_device) {
+		DRM_ERROR("can not get tiling_flags for a non-amdgpu_bo_user type BO\n");
+		return;
+	}
+
  	dma_resv_assert_held(bo->tbo.base.resv);
+	ubo = container_of((bo), struct amdgpu_bo_user, bo);
 
  	if (tiling_flags)
-		*tiling_flags = bo->tiling_flags;
+		*tiling_flags = ubo->tiling_flags;
  }
 
  /**
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -0
index cbb881afe6da..6cc38b71f7ca 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h struct amdgpu_bo { · line 96

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -1
@@ -91,7 +91,6 @@ struct amdgpu_bo {
  	struct ttm_bo_kmap_obj		kmap;
  	u64				flags;
  	unsigned			pin_count;
-	u64				tiling_flags;
  	u64				metadata_flags;
  	void				*metadata;
  	u32				metadata_size;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#10 lore raw

PATCH 5/5 drm/amdgpu: use metadata members of struct amdgpu_bo_user

In reply to Nirmoy Das

These memebers are only needed for BOs created by amdgpu_gem_object_create(), so we can remove these from the base class.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c |  2 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 48 +++++++++++++++-------
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  3 --
 3 files changed, 34 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0 -2
index c5343a5eecbe..f8c8cbd8ab59 100644
@@ -494,8 +494,6 @@ int amdgpu_amdkfd_get_dmabuf_info(struct kgd_dev *kgd, int dma_buf_fd,
 		*dma_buf_kgd = (struct kgd_dev *)adev;
 	if (bo_size)
 		*bo_size = amdgpu_bo_size(bo);
-	if (metadata_size)
-		*metadata_size = bo->metadata_size;
 	if (metadata_buffer)
 		r = amdgpu_bo_get_metadata(bo, metadata_buffer, buffer_size,
 					   metadata_size, &metadata_flags);
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +34 -14

91 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -3
index 6cc38b71f7ca..466081fa2083 100644
@@ -91,9 +91,6 @@ struct amdgpu_bo {
 	struct ttm_bo_kmap_obj		kmap;
 	u64				flags;
 	unsigned			pin_count;
-	u64				metadata_flags;
-	void				*metadata;
-	u32				metadata_size;
 	unsigned			prime_shared_count;
 	/* per VM structure for page tables and with virtual addresses */
 	struct amdgpu_vm_bo_base	*vm_bo;
Signature · 6 lines
2.30.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#11 lore raw

Re: [PATCH 5/5] drm/amdgpu: use metadata members of struct amdgpu_bo_user

Am 05.03.21 um 15:35 schrieb Nirmoy Das:

Quoted 2 lines

These memebers are only needed for BOs created by amdgpu_gem_object_create(), so we can remove these from the base class.

This patch must be squashed together with the previous one or we would have a broken driver in between.

Christian.

Quoted 127 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c |  2 -
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 48 +++++++++++++++-------
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  3 --
  3 files changed, 34 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0 -2
index c5343a5eecbe..f8c8cbd8ab59 100644
@@ -494,8 +494,6 @@ int amdgpu_amdkfd_get_dmabuf_info(struct kgd_dev *kgd, int dma_buf_fd,
  		*dma_buf_kgd = (struct kgd_dev *)adev;
  	if (bo_size)
  		*bo_size = amdgpu_bo_size(bo);
-	if (metadata_size)
-		*metadata_size = bo->metadata_size;
  	if (metadata_buffer)
  		r = amdgpu_bo_get_metadata(bo, metadata_buffer, buffer_size,
  					   metadata_size, &metadata_flags);
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +34 -14
index 2e5cf46251af..81b2cff42481 100644
@@ -77,6 +77,7 @@ static void amdgpu_bo_destroy(struct ttm_buffer_object *tbo)
  {
  	struct amdgpu_device *adev = amdgpu_ttm_adev(tbo->bdev);
  	struct amdgpu_bo *bo = ttm_to_amdgpu_bo(tbo);
+	struct amdgpu_bo_user *ubo;
 
  	if (bo->pin_count > 0)
  		amdgpu_bo_subtract_pin_size(bo);
@@ -94,7 +95,11 @@ static void amdgpu_bo_destroy(struct ttm_buffer_object *tbo)
  	}
  	amdgpu_bo_unref(&bo->parent);
 
-	kfree(bo->metadata);
+	if (bo->tbo.type == ttm_bo_type_device) {
+		ubo = container_of((bo), struct amdgpu_bo_user, bo);
+		kfree(ubo->metadata);
+	}
+
  	kfree(bo);
  }
 
@@ -1230,13 +1235,20 @@ void amdgpu_bo_get_tiling_flags(struct amdgpu_bo *bo, u64 *tiling_flags)
  int amdgpu_bo_set_metadata (struct amdgpu_bo *bo, void *metadata,
  			    uint32_t metadata_size, uint64_t flags)
  {
+	struct amdgpu_bo_user *ubo;
  	void *buffer;
 
+	if (bo->tbo.type != ttm_bo_type_device) {
+		DRM_ERROR("can not set metadata for a non-amdgpu_bo_user type BO\n");
+		return -EINVAL;
+	}
+
+	ubo = container_of((bo), struct amdgpu_bo_user, bo);
  	if (!metadata_size) {
-		if (bo->metadata_size) {
-			kfree(bo->metadata);
-			bo->metadata = NULL;
-			bo->metadata_size = 0;
+		if (ubo->metadata_size) {
+			kfree(ubo->metadata);
+			ubo->metadata = NULL;
+			ubo->metadata_size = 0;
  		}
  		return 0;
  	}
@@ -1248,10 +1260,10 @@ int amdgpu_bo_set_metadata (struct amdgpu_bo *bo, void *metadata,
  	if (buffer == NULL)
  		return -ENOMEM;
 
-	kfree(bo->metadata);
-	bo->metadata_flags = flags;
-	bo->metadata = buffer;
-	bo->metadata_size = metadata_size;
+	kfree(ubo->metadata);
+	ubo->metadata_flags = flags;
+	ubo->metadata = buffer;
+	ubo->metadata_size = metadata_size;
 
  	return 0;
  }
@@ -1275,21 +1287,29 @@ int amdgpu_bo_get_metadata(struct amdgpu_bo *bo, void *buffer,
  			   size_t buffer_size, uint32_t *metadata_size,
  			   uint64_t *flags)
  {
+	struct amdgpu_bo_user *ubo;
+
  	if (!buffer && !metadata_size)
  		return -EINVAL;
 
+	if (bo->tbo.type != ttm_bo_type_device) {
+		DRM_ERROR("can not get metadata for a non-amdgpu_bo_user type BO\n");
+		return -EINVAL;
+	}
+
+	ubo = container_of((bo), struct amdgpu_bo_user, bo);
  	if (buffer) {
-		if (buffer_size < bo->metadata_size)
+		if (buffer_size < ubo->metadata_size)
  			return -EINVAL;
 
-		if (bo->metadata_size)
-			memcpy(buffer, bo->metadata, bo->metadata_size);
+		if (ubo->metadata_size)
+			memcpy(buffer, ubo->metadata, ubo->metadata_size);
  	}
 
  	if (metadata_size)
-		*metadata_size = bo->metadata_size;
+		*metadata_size = ubo->metadata_size;
  	if (flags)
-		*flags = bo->metadata_flags;
+		*flags = ubo->metadata_flags;
 
  	return 0;
  }
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -0
index 6cc38b71f7ca..466081fa2083 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h struct amdgpu_bo { · line 96

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -3
@@ -91,9 +91,6 @@ struct amdgpu_bo {
  	struct ttm_bo_kmap_obj		kmap;
  	u64				flags;
  	unsigned			pin_count;
-	u64				metadata_flags;
-	void				*metadata;
-	u32				metadata_size;
  	unsigned			prime_shared_count;
  	/* per VM structure for page tables and with virtual addresses */
  	struct amdgpu_vm_bo_base	*vm_bo;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#12 lore raw
In reply to Nirmoy Das

Am 05.03.21 um 15:35 schrieb Nirmoy Das:

Quoted 14 lines

Allow allocating BO structures with different structure size than struct amdgpu_bo.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 ++
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 +
  2 files changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index 0bd22ed1dacf..745393472564 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c static int amdgpu_bo_do_create(struct amdgpu_device *adev, · line 555

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -0
@@ -551,6 +551,8 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
 
  	acc_size = ttm_bo_dma_acc_size(&adev->mman.bdev, size,
  				       sizeof(struct amdgpu_bo));
+	if (bp->bo_ptr_size < sizeof(struct amdgpu_bo))
+		bp->bo_ptr_size = sizeof(struct amdgpu_bo);

You should probably rather fix up all callers and make sure that the parameter structure is correctly filled in.

Christian.

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
  	bo = kzalloc(sizeof(struct amdgpu_bo), GFP_KERNEL);
  	if (bo == NULL)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -0
index 8cd96c9330dd..848dc0a017dd 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h line 46

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
@@ -40,6 +40,7 @@
  struct amdgpu_bo_param {
  	unsigned long			size;
  	int				byte_align;
+	u32				bo_ptr_size;
  	u32				domain;
  	u32				preferred_domain;
  	u64				flags;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#13 lore raw
Quoted 12 lines · Christian König

Am 05.03.21 um 15:35 schrieb Nirmoy Das:

Quoted 9 lines

Allow allocating BO structures with different structure size than struct amdgpu_bo.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 +

  2 files changed, 3 insertions(+)
Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c static int amdgpu_bo_do_create(struct · line 555

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -0
index 0bd22ed1dacf..745393472564 100644
@@ -551,6 +551,8 @@ static int amdgpu_bo_do_create(struct 
 amdgpu_device *adev,
         acc_size = ttm_bo_dma_acc_size(&adev->mman.bdev, size,
                          sizeof(struct amdgpu_bo));
+    if (bp->bo_ptr_size < sizeof(struct amdgpu_bo))
+        bp->bo_ptr_size = sizeof(struct amdgpu_bo);

You should probably rather fix up all callers and make sure that the parameter structure is correctly filled in.

Ok will resend with that change.

Thanks,

Nirmoy

Quoted 18 lines

Christian.

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
         bo = kzalloc(sizeof(struct amdgpu_bo), GFP_KERNEL);
       if (bo == NULL)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -0
index 8cd96c9330dd..848dc0a017dd 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h line 46

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
@@ -40,6 +40,7 @@
   struct amdgpu_bo_param {
       unsigned long            size;
       int                byte_align;
+    u32                bo_ptr_size;
       u32                domain;
       u32                preferred_domain;
       u64                flags;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

maintainer
#14 lore raw

Am 05.03.21 um 15:48 schrieb Nirmoy:

Quoted 28 lines · Christian König
Quoted 12 lines

Am 05.03.21 um 15:35 schrieb Nirmoy Das:

Quoted 9 lines

Allow allocating BO structures with different structure size than struct amdgpu_bo.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 +

  2 files changed, 3 insertions(+)
Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c static int amdgpu_bo_do_create(struct · line 555

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -0
index 0bd22ed1dacf..745393472564 100644
@@ -551,6 +551,8 @@ static int amdgpu_bo_do_create(struct 
 amdgpu_device *adev,
         acc_size = ttm_bo_dma_acc_size(&adev->mman.bdev, size,
                          sizeof(struct amdgpu_bo));
+    if (bp->bo_ptr_size < sizeof(struct amdgpu_bo))
+        bp->bo_ptr_size = sizeof(struct amdgpu_bo);

You should probably rather fix up all callers and make sure that the parameter structure is correctly filled in.

Quoted 1 line

Ok will resend with that change.

You are to fast, let me at least comment on all patches :)

Christian.

Quoted 25 lines

Thanks,

Nirmoy

Quoted 18 lines

Christian.

Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
         bo = kzalloc(sizeof(struct amdgpu_bo), GFP_KERNEL);
       if (bo == NULL)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
index 8cd96c9330dd..848dc0a017dd 100644
@@ -40,6 +40,7 @@
   struct amdgpu_bo_param {
       unsigned long            size;
       int                byte_align;
+    u32                bo_ptr_size;
       u32                domain;
       u32                preferred_domain;
       u64                flags;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#15 lore raw
Quoted 31 lines · Christian König

Am 05.03.21 um 15:48 schrieb Nirmoy:

Quoted 28 lines · Christian König
Quoted 24 lines

Am 05.03.21 um 15:35 schrieb Nirmoy Das:

Quoted 14 lines

Allow allocating BO structures with different structure size than struct amdgpu_bo.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 +

  2 files changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index 0bd22ed1dacf..745393472564 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c static int amdgpu_bo_do_create(struct · line 555

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -0
@@ -551,6 +551,8 @@ static int amdgpu_bo_do_create(struct 
 amdgpu_device *adev,
         acc_size = ttm_bo_dma_acc_size(&adev->mman.bdev, size,
                          sizeof(struct amdgpu_bo));
+    if (bp->bo_ptr_size < sizeof(struct amdgpu_bo))
+        bp->bo_ptr_size = sizeof(struct amdgpu_bo);

You should probably rather fix up all callers and make sure that the parameter structure is correctly filled in.

Quoted 3 lines
Quoted 1 line

Ok will resend with that change.

You are to fast, let me at least comment on all patches :)

Sorry about that :)

Nirmoy

Quoted 29 lines

Christian.

Quoted 25 lines

Thanks,

Nirmoy

Quoted 18 lines

Christian.

Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
         bo = kzalloc(sizeof(struct amdgpu_bo), GFP_KERNEL);
       if (bo == NULL)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
index 8cd96c9330dd..848dc0a017dd 100644
@@ -40,6 +40,7 @@
   struct amdgpu_bo_param {
       unsigned long            size;
       int                byte_align;
+    u32                bo_ptr_size;
       u32                domain;
       u32                preferred_domain;
       u64                flags;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx