Skip to contentSkip to conversation

Revert "drm/amdgpu: Use dma_buf from GEM object instance"

PATCH In review Thomas Zimmermann 4 participants 5 messages Jul 15, 2025 – Aug 12, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Revert "drm/amdgpu: Use dma_buf from GEM object instance"

This reverts commit 515986100d176663d0a03219a3056e4252f729e6.

The dma_buf field in struct drm_gem_object is not stable over the object instance's lifetime. The field becomes NULL when user space releases the final GEM handle on the buffer object. This resulted in a NULL-pointer deref.

Workarounds in commit 5307dce878d4 ("drm/gem: Acquire references on GEM handles for framebuffers") and commit f6bfc9afc751 ("drm/framebuffer:
Acquire internal references on GEM handles") only solved the problem partially. They especially don't work for buffer objects without a DRM framebuffer associated.

Hence, this revert to going back to using .import_attach->dmabuf.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c     | 3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c      | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1 -1
index ff98c87b2e0b..5743ebb2f1b7 100644
@@ -514,7 +514,7 @@ bool amdgpu_dmabuf_is_xgmi_accessible(struct amdgpu_device *adev,
 		return false;
 
 	if (drm_gem_is_imported(obj)) {
-		struct dma_buf *dma_buf = obj->dma_buf;
+		struct dma_buf *dma_buf = obj->import_attach->dmabuf;
 
 		if (dma_buf->ops != &amdgpu_dmabuf_ops)
 			/* No XGMI with non AMD GPUs */
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index 6626a6e64ff5..d1ccbfcf21fa 100644
@@ -317,7 +317,8 @@ static int amdgpu_gem_object_open(struct drm_gem_object *obj,
 	 */
 	if (!vm->is_compute_context || !vm->process_info)
 		return 0;
-	if (!drm_gem_is_imported(obj) || !dma_buf_is_dynamic(obj->dma_buf))
+	if (!drm_gem_is_imported(obj) ||
+	    !dma_buf_is_dynamic(obj->import_attach->dmabuf))
 		return 0;
 	mutex_lock_nested(&vm->process_info->lock, 1);
 	if (!WARN_ON(!vm->process_info->eviction_fence)) {
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
index af0f655dfd5b..b9b4f7d9186e 100644
@@ -1272,7 +1272,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va,
 		struct drm_gem_object *obj = &bo->tbo.base;
 
 		if (drm_gem_is_imported(obj) && bo_va->is_xgmi) {
-			struct dma_buf *dma_buf = obj->dma_buf;
+			struct dma_buf *dma_buf = obj->import_attach->dmabuf;
 			struct drm_gem_object *gobj = dma_buf->priv;
 			struct amdgpu_bo *abo = gem_to_amdgpu_bo(gobj);
 
Signature · 1 line
2.50.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Thomas Zimmermann

This reverts commit 515986100d176663d0a03219a3056e4252f729e6.

The dma_buf field in struct drm_gem_object is not stable over the object instance's lifetime. The field becomes NULL when user space releases the final GEM handle on the buffer object. This resulted in a NULL-pointer deref.

Workarounds in commit 5307dce878d4 ("drm/gem: Acquire references on GEM handles for framebuffers") and commit f6bfc9afc751 ("drm/framebuffer:
Acquire internal references on GEM handles") only solved the problem partially. They especially don't work for buffer objects without a DRM framebuffer associated.

Quoted 3 lines

Hence, this revert to going back to using .import_attach->dmabuf.

Quoted 49 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c     | 3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c      | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1 -1
index ff98c87b2e0b..5743ebb2f1b7 100644
@@ -514,7 +514,7 @@ bool amdgpu_dmabuf_is_xgmi_accessible(struct amdgpu_device *adev,
 		return false;
 
 	if (drm_gem_is_imported(obj)) {
-		struct dma_buf *dma_buf = obj->dma_buf;
+		struct dma_buf *dma_buf = obj->import_attach->dmabuf;
 
 		if (dma_buf->ops != &amdgpu_dmabuf_ops)
 			/* No XGMI with non AMD GPUs */
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index 6626a6e64ff5..d1ccbfcf21fa 100644
@@ -317,7 +317,8 @@ static int amdgpu_gem_object_open(struct drm_gem_object *obj,
 	 */
 	if (!vm->is_compute_context || !vm->process_info)
 		return 0;
-	if (!drm_gem_is_imported(obj) || !dma_buf_is_dynamic(obj->dma_buf))
+	if (!drm_gem_is_imported(obj) ||
+	    !dma_buf_is_dynamic(obj->import_attach->dmabuf))
 		return 0;
 	mutex_lock_nested(&vm->process_info->lock, 1);
 	if (!WARN_ON(!vm->process_info->eviction_fence)) {
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
index af0f655dfd5b..b9b4f7d9186e 100644
@@ -1272,7 +1272,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va,
 		struct drm_gem_object *obj = &bo->tbo.base;
 
 		if (drm_gem_is_imported(obj) && bo_va->is_xgmi) {
-			struct dma_buf *dma_buf = obj->dma_buf;
+			struct dma_buf *dma_buf = obj->import_attach->dmabuf;
 			struct drm_gem_object *gobj = dma_buf->priv;
 			struct amdgpu_bo *abo = gem_to_amdgpu_bo(gobj);
 
Signature · 1 line
2.50.0
Signature · 3 lines
Simona Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Acked-by on v1 1/1
#2 lore raw
In reply to Thomas Zimmermann
Quoted 14 lines · Thomas Zimmermann

This reverts commit 515986100d176663d0a03219a3056e4252f729e6.

The dma_buf field in struct drm_gem_object is not stable over the object instance's lifetime. The field becomes NULL when user space releases the final GEM handle on the buffer object. This resulted in a NULL-pointer deref.

Workarounds in commit 5307dce878d4 ("drm/gem: Acquire references on GEM handles for framebuffers") and commit f6bfc9afc751 ("drm/framebuffer:
Acquire internal references on GEM handles") only solved the problem partially. They especially don't work for buffer objects without a DRM framebuffer associated.

Quoted 3 lines

Hence, this revert to going back to using .import_attach->dmabuf.

Quoted 49 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c     | 3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c      | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1 -1
index ff98c87b2e0b..5743ebb2f1b7 100644
@@ -514,7 +514,7 @@ bool amdgpu_dmabuf_is_xgmi_accessible(struct amdgpu_device *adev,
                return false;
 
        if (drm_gem_is_imported(obj)) {
-               struct dma_buf *dma_buf = obj->dma_buf;
+               struct dma_buf *dma_buf = obj->import_attach->dmabuf;
 
                if (dma_buf->ops != &amdgpu_dmabuf_ops)
                        /* No XGMI with non AMD GPUs */
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index 6626a6e64ff5..d1ccbfcf21fa 100644
@@ -317,7 +317,8 @@ static int amdgpu_gem_object_open(struct drm_gem_object *obj,
         */
        if (!vm->is_compute_context || !vm->process_info)
                return 0;
-       if (!drm_gem_is_imported(obj) || !dma_buf_is_dynamic(obj->dma_buf))
+       if (!drm_gem_is_imported(obj) ||
+           !dma_buf_is_dynamic(obj->import_attach->dmabuf))
                return 0;
        mutex_lock_nested(&vm->process_info->lock, 1);
        if (!WARN_ON(!vm->process_info->eviction_fence)) {
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -2
index af0f655dfd5b..b9b4f7d9186e 100644
@@ -1272,7 +1272,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va,
                struct drm_gem_object *obj = &bo->tbo.base;
 
                if (drm_gem_is_imported(obj) && bo_va->is_xgmi) {
-                       struct dma_buf *dma_buf = obj->dma_buf;
+                       struct dma_buf *dma_buf = obj->import_attach->dmabuf;
                        struct drm_gem_object *gobj = dma_buf->priv;
                        struct amdgpu_bo *abo = gem_to_amdgpu_bo(gobj);
 
--

2.50.0

#3 lore raw

Hi

Am 15.07.25 um 16:01 schrieb Alex Deucher:

Quoted 14 lines · Thomas Zimmermann
Quoted 13 lines

This reverts commit 515986100d176663d0a03219a3056e4252f729e6.

The dma_buf field in struct drm_gem_object is not stable over the object instance's lifetime. The field becomes NULL when user space releases the final GEM handle on the buffer object. This resulted in a NULL-pointer deref.

Workarounds in commit 5307dce878d4 ("drm/gem: Acquire references on GEM handles for framebuffers") and commit f6bfc9afc751 ("drm/framebuffer:
Acquire internal references on GEM handles") only solved the problem partially. They especially don't work for buffer objects without a DRM framebuffer associated.

Quoted 4 lines
Quoted 3 lines

Hence, this revert to going back to using .import_attach->dmabuf.

Can I take this patch into drm-misc-fixes?

Best regards
Thomas

Quoted 50 lines
Quoted 50 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c     | 3 ++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c      | 2 +-
  3 files changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1 -1
index ff98c87b2e0b..5743ebb2f1b7 100644
@@ -514,7 +514,7 @@ bool amdgpu_dmabuf_is_xgmi_accessible(struct amdgpu_device *adev,
                 return false;
 
         if (drm_gem_is_imported(obj)) {
-               struct dma_buf *dma_buf = obj->dma_buf;
+               struct dma_buf *dma_buf = obj->import_attach->dmabuf;
 
                 if (dma_buf->ops != &amdgpu_dmabuf_ops)
                         /* No XGMI with non AMD GPUs */
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index 6626a6e64ff5..d1ccbfcf21fa 100644
@@ -317,7 +317,8 @@ static int amdgpu_gem_object_open(struct drm_gem_object *obj,
          */
         if (!vm->is_compute_context || !vm->process_info)
                 return 0;
-       if (!drm_gem_is_imported(obj) || !dma_buf_is_dynamic(obj->dma_buf))
+       if (!drm_gem_is_imported(obj) ||
+           !dma_buf_is_dynamic(obj->import_attach->dmabuf))
                 return 0;
         mutex_lock_nested(&vm->process_info->lock, 1);
         if (!WARN_ON(!vm->process_info->eviction_fence)) {
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -2
index af0f655dfd5b..b9b4f7d9186e 100644
@@ -1272,7 +1272,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va,
                 struct drm_gem_object *obj = &bo->tbo.base;
 
                 if (drm_gem_is_imported(obj) && bo_va->is_xgmi) {
-                       struct dma_buf *dma_buf = obj->dma_buf;
+                       struct dma_buf *dma_buf = obj->import_attach->dmabuf;
                         struct drm_gem_object *gobj = dma_buf->priv;
                         struct amdgpu_bo *abo = gem_to_amdgpu_bo(gobj);
 
--

2.50.0

Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
maintainer
#4 lore raw
Quoted 17 lines · Thomas Zimmermann

Hi

Am 15.07.25 um 16:01 schrieb Alex Deucher:

Quoted 14 lines · Thomas Zimmermann
Quoted 13 lines

This reverts commit 515986100d176663d0a03219a3056e4252f729e6.

The dma_buf field in struct drm_gem_object is not stable over the object instance's lifetime. The field becomes NULL when user space releases the final GEM handle on the buffer object. This resulted in a NULL-pointer deref.

Workarounds in commit 5307dce878d4 ("drm/gem: Acquire references on GEM handles for framebuffers") and commit f6bfc9afc751 ("drm/framebuffer:
Acquire internal references on GEM handles") only solved the problem partially. They especially don't work for buffer objects without a DRM framebuffer associated.

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

Hence, this revert to going back to using .import_attach->dmabuf.

Can I take this patch into drm-misc-fixes?

Yeah, sure. Go ahead.

Thanks,
Christian.

Quoted 55 lines

Best regards
Thomas

Quoted 50 lines
Quoted 50 lines

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c     | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c      | 2 +-

  3 files changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1 -1
index ff98c87b2e0b..5743ebb2f1b7 100644
@@ -514,7 +514,7 @@ bool amdgpu_dmabuf_is_xgmi_accessible(struct amdgpu_device *adev,
                  return false;
 
          if (drm_gem_is_imported(obj)) {
-               struct dma_buf *dma_buf = obj->dma_buf;
+               struct dma_buf *dma_buf = obj->import_attach->dmabuf;
 
                  if (dma_buf->ops != &amdgpu_dmabuf_ops)
                          /* No XGMI with non AMD GPUs */
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index 6626a6e64ff5..d1ccbfcf21fa 100644
@@ -317,7 +317,8 @@ static int amdgpu_gem_object_open(struct drm_gem_object *obj,
           */
          if (!vm->is_compute_context || !vm->process_info)
                  return 0;
-       if (!drm_gem_is_imported(obj) || !dma_buf_is_dynamic(obj->dma_buf))
+       if (!drm_gem_is_imported(obj) ||
+           !dma_buf_is_dynamic(obj->import_attach->dmabuf))
                  return 0;
          mutex_lock_nested(&vm->process_info->lock, 1);
          if (!WARN_ON(!vm->process_info->eviction_fence)) {
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
index af0f655dfd5b..b9b4f7d9186e 100644
@@ -1272,7 +1272,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va,
                  struct drm_gem_object *obj = &bo->tbo.base;
 
                  if (drm_gem_is_imported(obj) && bo_va->is_xgmi) {
-                       struct dma_buf *dma_buf = obj->dma_buf;
+                       struct dma_buf *dma_buf = obj->import_attach->dmabuf;
                          struct drm_gem_object *gobj = dma_buf->priv;
                          struct amdgpu_bo *abo = gem_to_amdgpu_bo(gobj);
 
Signature · 1 line
2.50.0