Hi

Am 15.04.25 um 09:15 schrieb Andy Yan:
Hi Thomas,

在 2025-04-15 14:54:21,"Thomas Zimmermann" <tzimmerm...@suse.de> 写道:
Hi

Am 15.04.25 um 06:00 schrieb Andy Yan:
Hi Thomas,

At 2025-04-14 21:48:12, "Thomas Zimmermann" <tzimmerm...@suse.de> wrote:
Instead of testing import_attach for imported GEM buffers, invoke
drm_gem_is_imported() to do the test. The helper tests the dma_buf
itself while import_attach is just an artifact of the import. Prepares
to make import_attach optional.

Signed-off-by: Thomas Zimmermann <tzimmerm...@suse.de>
Cc: Sandy Huang <h...@rock-chips.com>
Cc: "Heiko Stübner" <he...@sntech.de>
Cc: Andy Yan <andy....@rock-chips.com>
---
drivers/gpu/drm/rockchip/rockchip_drm_gem.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c 
b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c
index 6330b883efc3..e44396d46dc1 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c
@@ -332,7 +332,7 @@ void rockchip_gem_free_object(struct drm_gem_object *obj)
        struct rockchip_drm_private *private = drm->dev_private;
        struct rockchip_gem_object *rk_obj = to_rockchip_obj(obj);

-       if (obj->import_attach) {
+       if (drm_gem_is_imported(obj)) {
After applying this patch, when I tested glmark2-es2-wayland under Weston, the 
weston would freeze.
It seems it goto the else path.

   I'm still conducting further analysis to figure out the exact cause.
Thanks for testing. We test if obj->dma_buf is set and refers back to
obj. One of these fields has likely been cleared already to NULL during
the object cleanup. Other drivers also call drm_gem_is_imported() in
their object cleanup and I've not heard about any regressions.
 From my test, it seems that a dumb buffer may export then import:
and the obj->dma_buf will be cleared at 
drm_mode_destroy_dumb_ioctl-->drm_gem_handle_delete

then test with   obj->dma_buf && (obj->dma_buf->priv != obj) will be false.

Here's a patch for the problem. Could you please test and report back with the results? Thanks a lot.

Best regards
Thomas








[   12.028941] [drm] Initialized panthor 1.3.0 for fb000000.gpu on minor 1
[   14.606114] rockchip_gem_dumb_create weston obj: ffff00010149b000 handle: 1
[   14.606170] drm_gem_prime_handle_to_dmabuf weston obj: ffff00010149b000 
dma_buf: 0xffff000101454800 handle: 1
[   14.606217] drm_gem_prime_fd_to_handle weston obj: ffff0001023cdc00 dma_buf: 
0xffff000101454800 dma_buf->priv ffff00010149b000
[   14.685517] rockchip_gem_dumb_create weston obj: ffff00010149b400 handle: 2
[   14.685569] drm_gem_prime_handle_to_dmabuf weston obj: ffff00010149b400 
dma_buf: 0xffff000101454400 handle: 2
[   14.685691] drm_gem_prime_fd_to_handle weston obj: ffff0001023ce600 dma_buf: 
0xffff000101454400 dma_buf->priv ffff00010149b400
[   15.255277] rockchip_gem_dumb_create weston obj: ffff00010759f800 handle: 3
[   15.255298] drm_gem_prime_handle_to_dmabuf weston obj: ffff00010759f800 
dma_buf: 0xffff0001030cbc00 handle: 3
[   15.255317] drm_gem_prime_fd_to_handle weston obj: ffff0001037a3200 dma_buf: 
0xffff0001030cbc00 dma_buf->priv ffff00010759f800
[   15.316336] rockchip_gem_dumb_create weston obj: ffff00010759f000 handle: 4
[   15.316360] drm_gem_prime_handle_to_dmabuf weston obj: ffff00010759f000 
dma_buf: 0xffff0001030cba00 handle: 4
[   15.316404] drm_gem_prime_fd_to_handle weston obj: ffff0001037a1000 dma_buf: 
0xffff0001030cba00 dma_buf->priv ffff00010759f000
[   20.209006] rockchip_gem_dumb_create weston obj: ffff000106584000 handle: 1
[   20.209031] drm_gem_prime_handle_to_dmabuf weston obj: ffff000106584000 
dma_buf: 0xffff0001017a7600 handle: 1
[   20.209049] drm_gem_prime_fd_to_handle weston obj: ffff00010182fc00 dma_buf: 
0xffff0001017a7600 dma_buf->priv ffff000106584000
[   20.228008] rockchip_gem_dumb_create weston obj: ffff000106584c00 handle: 2
[   20.228029] drm_gem_prime_handle_to_dmabuf weston obj: ffff000106584c00 
dma_buf: 0xffff0001017a7a00 handle: 2
[   20.228081] drm_gem_prime_fd_to_handle weston obj: ffff000105eec000 dma_buf: 
0xffff0001017a7a00 dma_buf->priv ffff000106584c00

[   27.073265] drm_gem_prime_handle_to_dmabuf glmark2-es2-way obj: 
ffff0001035f0a00 dma_buf: 0xffff00010a24d500 handle: 10
[   27.073377] drm_gem_prime_fd_to_handle weston obj: ffff0001035f0a00 dma_buf: 
0xffff00010a24d500 dma_buf->priv ffff0001035f0a00
[   27.073718] drm_gem_prime_fd_to_handle weston obj: ffff00010759e000 dma_buf: 
0xffff00010a24d500 dma_buf->priv ffff0001035f0a00

[   27.075363] drm_gem_handle_delete glmark2-es2-way obj: ffff0001035f0a00 
handle: 10
[   27.075718] drm_gem_prime_handle_to_dmabuf glmark2-es2-way obj: 
ffff00012946e000 dma_buf: 0xffff00010a24d100 handle: 25
[   27.075799] drm_gem_prime_fd_to_handle weston obj: ffff00012946e000 dma_buf: 
0xffff00010a24d100 dma_buf->priv ffff00012946e000
[   27.076613] drm_gem_prime_fd_to_handle weston obj: ffff00010759dc00 dma_buf: 
0xffff00010a24d100 dma_buf->priv ffff00012946e000
[   27.079195] drm_gem_prime_handle_to_dmabuf glmark2-es2-way obj: 
ffff00012946e400 dma_buf: 0xffff00010a24d000 handle: 10
[   27.079262] drm_gem_handle_delete weston obj: ffff00010759e000 handle: 5
[   27.079271] CPU: 7 UID: 0 PID: 308 Comm: weston Not tainted 6.15.0-rc1+ #613 
PREEMPT
[   27.079276] Hardware name: Radxa ROCK 5B (DT)
[   27.079278] Call trace:
[   27.079280]  show_stack+0x18/0x24 (C)
[   27.079289]  dump_stack_lvl+0x74/0x8c
[   27.079296]  dump_stack+0x18/0x24
[   27.079301]  drm_gem_object_handle_put_unlocked+0x58/0x128
[   27.079309]  drm_gem_handle_delete+0xbc/0x110
[   27.079314]  drm_mode_destroy_dumb_ioctl+0x24/0x3c
[   27.079318]  drm_ioctl_kernel+0xc0/0x12c
[   27.079324]  drm_ioctl+0x25c/0x55c
[   27.079330]  __arm64_sys_ioctl+0xb4/0xe8
[   27.079335]  invoke_syscall+0x48/0x10c
[   27.079340]  el0_svc_common.constprop.0+0x40/0xe0
[   27.079346]  do_el0_svc+0x1c/0x28
[   27.079351]  el0_svc+0x30/0xcc
[   27.079355]  el0t_64_sync_handler+0x10c/0x138
[   27.079358]  el0t_64_sync+0x198/0x19c
[   27.079362] drm_gem_object_exported_dma_buf_free weston obj: ffff00010759e000 
dma_buf: 0xffff00010a24d500 dma_buf->priv: ffff0001035f0a00
[   27.085797] rockchip_gem_free_object weston obj: ffff00010759e000 import 
dma_buf: 0x0000000000000000 dma_buf->priv: 0000000000000000
[   27.086093] drm_gem_handle_delete weston obj: ffff0001035f0a00 handle: 35
[   27.086099] CPU: 7 UID: 0 PID: 308 Comm: weston Not tainted 6.15.0-rc1+ #613 
PREEMPT
[   27.086102] Hardware name: Radxa ROCK 5B (DT)
Best regards
Thomas

                if (private->domain) {
                        rockchip_gem_iommu_unmap(rk_obj);
                } else {
--
2.49.0
--
--
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)

--
--
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)
From 7c46e63274d3199ebedeac3f1eb540a2bb6b9cfb Mon Sep 17 00:00:00 2001
From: Thomas Zimmermann <tzimmerm...@suse.de>
Date: Tue, 15 Apr 2025 09:42:55 +0200
Subject: [PATCH] drm/gem: Internally test import_attach for imported objects
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Test struct drm_gem_object.import_attach to detect imported objects
during cleanup. At that point, the imported DMA buffer might have
already been released and the dma_buf field is NULL. The object's
free callback then does a cleanup as for native objects.

Happens for calls to drm_mode_destroy_dumb_ioctl() that eventually
clear the dma_buf field in drm_gem_object_exported_dma_buf_free().

Signed-off-by: Thomas Zimmermann <tzimmerm...@suse.de>
Fixes: b57aa47d39e9 ("drm/gem: Test for imported GEM buffers with helper")
Reported-by: Andy Yan <andys...@163.com>
Closes: https://lore.kernel.org/dri-devel/38d09d34.4354.196379aa560.coremail.andys...@163.com/
Cc: Thomas Zimmermann <tzimmerm...@suse.de>
Cc: Anusha Srivatsa <asriv...@redhat.com>
Cc: Christian König <christian.koe...@amd.com>
Cc: Maarten Lankhorst <maarten.lankho...@linux.intel.com>
Cc: Maxime Ripard <mrip...@kernel.org>
Cc: David Airlie <airl...@gmail.com>
Cc: Simona Vetter <sim...@ffwll.ch>
Cc: Sumit Semwal <sumit.sem...@linaro.org>
Cc: "Christian König" <christian.koe...@amd.com>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-me...@vger.kernel.org
Cc: linaro-mm-...@lists.linaro.org
---
 include/drm/drm_gem.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
index 9b71f7a9f3f8..f09b8afcf86d 100644
--- a/include/drm/drm_gem.h
+++ b/include/drm/drm_gem.h
@@ -589,7 +589,13 @@ static inline bool drm_gem_object_is_shared_for_memory_stats(struct drm_gem_obje
 static inline bool drm_gem_is_imported(const struct drm_gem_object *obj)
 {
 	/* The dma-buf's priv field points to the original GEM object. */
-	return obj->dma_buf && (obj->dma_buf->priv != obj);
+	return (obj->dma_buf && (obj->dma_buf->priv != obj)) ||
+	       /*
+		* TODO: During object release, the dma-buf might already
+		*       be gone. For now keep testing import_attach, but
+		*       this should be removed at some point.
+		*/
+	       obj->import_attach;
 }
 
 #ifdef CONFIG_LOCKDEP
-- 
2.49.0

Reply via email to