All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: Initialise drm_gem_object_funcs for imported BOs
@ 2020-12-08 17:10 ` Andrey Grodzovsky
  0 siblings, 0 replies; 22+ messages in thread
From: Andrey Grodzovsky @ 2020-12-08 17:10 UTC (permalink / raw)
  To: dri-devel; +Cc: Alexander.Deucher, ckoenig.leichtzumerken, tzimmermann, amd-gfx

For BOs imported from outside of amdgpu, setting of amdgpu_gem_object_funcs
was missing in amdgpu_dma_buf_create_obj. Fix by refactoring BO creation
and amdgpu_gem_object_funcs setting into single function called
from both code paths.

This fixes null ptr regression casued by commit
d693def drm: Remove obsolete GEM and PRIME callbacks from struct drm_driver

Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 13 ++++++-------
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c     | 22 +++++++++++++++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h     |  5 +++++
 3 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
index e5919ef..da4d0ab 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
@@ -405,6 +405,7 @@ struct dma_buf *amdgpu_gem_prime_export(struct drm_gem_object *gobj,
 	return buf;
 }
 
+
 /**
  * amdgpu_dma_buf_create_obj - create BO for DMA-buf import
  *
@@ -424,7 +425,7 @@ amdgpu_dma_buf_create_obj(struct drm_device *dev, struct dma_buf *dma_buf)
 	struct amdgpu_device *adev = drm_to_adev(dev);
 	struct amdgpu_bo *bo;
 	struct amdgpu_bo_param bp;
-	int ret;
+	struct drm_gem_object *obj;
 
 	memset(&bp, 0, sizeof(bp));
 	bp.size = dma_buf->size;
@@ -434,21 +435,19 @@ amdgpu_dma_buf_create_obj(struct drm_device *dev, struct dma_buf *dma_buf)
 	bp.type = ttm_bo_type_sg;
 	bp.resv = resv;
 	dma_resv_lock(resv, NULL);
-	ret = amdgpu_bo_create(adev, &bp, &bo);
-	if (ret)
+	obj = amdgpu_gem_object_create_raw(adev, &bp);
+	if (IS_ERR(obj))
 		goto error;
 
+	bo = gem_to_amdgpu_bo(obj);
 	bo->allowed_domains = AMDGPU_GEM_DOMAIN_GTT;
 	bo->preferred_domains = AMDGPU_GEM_DOMAIN_GTT;
 	if (dma_buf->ops != &amdgpu_dmabuf_ops)
 		bo->prime_shared_count = 1;
 
-	dma_resv_unlock(resv);
-	return &bo->tbo.base;
-
 error:
 	dma_resv_unlock(resv);
-	return ERR_PTR(ret);
+	return obj;
 }
 
 /**
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index c9f94fb..5f22ce6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -52,13 +52,26 @@ static void amdgpu_gem_object_free(struct drm_gem_object *gobj)
 	}
 }
 
+struct drm_gem_object *amdgpu_gem_object_create_raw(struct amdgpu_device *adev,
+						    struct amdgpu_bo_param *bp)
+{
+	struct amdgpu_bo *bo;
+	int r;
+
+	r = amdgpu_bo_create(adev, bp, &bo);
+	if (r)
+		return ERR_PTR(r);
+
+	bo->tbo.base.funcs = &amdgpu_gem_object_funcs;
+	return &bo->tbo.base;
+}
+
 int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
 			     int alignment, u32 initial_domain,
 			     u64 flags, enum ttm_bo_type type,
 			     struct dma_resv *resv,
 			     struct drm_gem_object **obj)
 {
-	struct amdgpu_bo *bo;
 	struct amdgpu_bo_param bp;
 	int r;
 
@@ -73,8 +86,9 @@ 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);
-	if (r) {
+	*obj = amdgpu_gem_object_create_raw(adev, &bp);
+	if (IS_ERR(*obj)) {
+		r = PTR_ERR(*obj);
 		if (r != -ERESTARTSYS) {
 			if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {
 				flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
@@ -90,8 +104,6 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
 		}
 		return r;
 	}
-	*obj = &bo->tbo.base;
-	(*obj)->funcs = &amdgpu_gem_object_funcs;
 
 	return 0;
 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h
index 637bf51..a6b90d3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h
@@ -38,12 +38,17 @@ unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
 /*
  * GEM objects.
  */
+
+struct amdgpu_bo_param;
+
 void amdgpu_gem_force_release(struct amdgpu_device *adev);
 int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
 			     int alignment, u32 initial_domain,
 			     u64 flags, enum ttm_bo_type type,
 			     struct dma_resv *resv,
 			     struct drm_gem_object **obj);
+struct drm_gem_object *amdgpu_gem_object_create_raw(struct amdgpu_device *adev,
+						    struct amdgpu_bo_param *bp);
 
 int amdgpu_mode_dumb_create(struct drm_file *file_priv,
 			    struct drm_device *dev,
-- 
2.7.4

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2020-12-08 19:16 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-08 17:10 [PATCH] drm/amdgpu: Initialise drm_gem_object_funcs for imported BOs Andrey Grodzovsky
2020-12-08 17:10 ` Andrey Grodzovsky
2020-12-08 17:23 ` Alex Deucher
2020-12-08 17:23   ` Alex Deucher
2020-12-08 17:36 ` Christian König
2020-12-08 17:36   ` Christian König
2020-12-08 18:26   ` Andrey Grodzovsky
2020-12-08 18:26     ` Andrey Grodzovsky
2020-12-08 18:29     ` Christian König
2020-12-08 18:29       ` Christian König
2020-12-08 18:44       ` Andrey Grodzovsky
2020-12-08 18:44         ` Andrey Grodzovsky
2020-12-08 18:47         ` Christian König
2020-12-08 18:47           ` Christian König
2020-12-08 18:52           ` Andrey Grodzovsky
2020-12-08 18:52             ` Andrey Grodzovsky
2020-12-08 19:01             ` Christian König
2020-12-08 19:01               ` Christian König
2020-12-08 19:11               ` Andrey Grodzovsky
2020-12-08 19:11                 ` Andrey Grodzovsky
2020-12-08 19:16                 ` Christian König
2020-12-08 19:16                   ` Christian König

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.