[PATCH 05/11] drm/rockchip: Test for imported buffers with drm_gem_is_imported()

Thomas Zimmermann tzimmermann at suse.de
Tue Apr 15 07:51:31 UTC 2025


Hi

Am 15.04.25 um 09:15 schrieb Andy Yan:
> Hi Thomas,
>
> 在 2025-04-15 14:54:21,"Thomas Zimmermann" <tzimmermann at suse.de> 写道:
>> Hi
>>
>> Am 15.04.25 um 06:00 schrieb Andy Yan:
>>> Hi Thomas,
>>>
>>> At 2025-04-14 21:48:12, "Thomas Zimmermann" <tzimmermann at 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 <tzimmermann at suse.de>
>>>> Cc: Sandy Huang <hjc at rock-chips.com>
>>>> Cc: "Heiko Stübner" <heiko at sntech.de>
>>>> Cc: Andy Yan <andy.yan at 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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-drm-gem-Internally-test-import_attach-for-imported-o.patch
Type: text/x-patch
Size: 2341 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/dri-devel/attachments/20250415/e55e7ece/attachment.bin>


More information about the dri-devel mailing list