NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
kern/61126: amdgpu: overreleasing kref panic on modeset
>Number: 61126
>Category: kern
>Synopsis: amdgpu: overreleasing kref panic on modeset
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: kern-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Dec 04 13:15:00 +0000 2026
>Originator: Robert Bagdan
>Release: NetBSD-11
>Organization:
>Environment:
NetBSD inara 11.0_STABLE NetBSD 11.0_STABLE (GENERIC) #0: Fri Oct 30 19:02:53 UTC 2026 mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
I have an AMD Radeon RX550, with a HDMI monitor. On Xorg with modesetting driver, after change mode with xrandr I got crash:
[ 3452,192251] panic: kernel diagnostic assertion "(count <= old)" failed: file "/usr/src/sys/external/bsd/drm2/include/linux/kref.h", line 87 overreleasing kref: 0 - 1
[ 3452,192251] cpu5: Begin traceback...
[ 3452,192251] vpanic() at netbsd:vpanic+0x171
[ 3452,192251] kern_assert() at netbsd:kern_assert+0x4b
[ 3452,202253] dc_stream_release() at amdgpu:dc_stream_release+0xa4
[ 3452,202253] dc_resource_state_destruct() at amdgpu:dc_resource_state_destruct+0x4f
[ 3452,202253] dc_release_state() at amdgpu:dc_release_state+0xdb
[ 3452,202253] dm_atomic_destroy_state() at amdgpu:dm_atomic_destroy_state+0x1f
[ 3452,202253] drm_atomic_state_default_clear() at netbsd:drm_atomic_state_default_clear+0x253
[ 3452,202253] __drm_atomic_state_free() at netbsd:__drm_atomic_state_free+0x5c
[ 3452,202253] drm_atomic_helper_set_config() at netbsd:drm_atomic_helper_set_config+0xaa
[ 3452,202253] drm_mode_setcrtc() at netbsd:drm_mode_setcrtc+0x561
[ 3452,202253] drm_ioctl() at netbsd:drm_ioctl+0x3fb
[ 3452,202253] drm_ioctl_shim() at netbsd:drm_ioctl_shim+0x35
[ 3452,202253] sys_ioctl() at netbsd:sys_ioctl+0x4ca
[ 3452,202253] syscall() at netbsd:syscall+0x9a
[ 3452,202253] --- syscall (number 54) ---
[ 3452,202253] netbsd:syscall+0x9a:
[ 3452,202253] cpu5: End traceback...
[ 3452,202253] dumping to dev 168,2 (offset=8, size=16668651):
[ 3452,202253] dump
In dm_update_crtc_state() (amdgpu_dm/amdgpu_dm.c), the skip_modeset
path releases the extra reference on new_stream but leaves the
pointer set:
skip_modeset:
/* Release extra reference */
if (new_stream)
dc_stream_release(new_stream);
If amdgpu_dm_update_crtc_color_mgmt() fails afterwards, the fail path
calls dc_stream_release(new_stream) again. That drops the reference
owned by dm_new_crtc_state->stream, and the later state teardown
underflows the kref.
>How-To-Repeat:
xrandr --output HDMI-1 --mode 1280x720
or with 2 monitor:
xrandr --output HDMI-1 --auto --output DVI-D-1 --auto --left-of HDMI-1
triggers the same panic.
>Fix:
Found this commit in linux:
https://github.com/torvalds/linux/commit/99f3af19073b3ddbfd96e789124cce12c4277b28:
>From 99f3af19073b3ddbfd96e789124cce12c4277b28 Mon Sep 17 00:00:00 2001
From: WenTao Liang <vulab%iscas.ac.cn@localhost>
Date: Sun, 28 Jun 2026 15:27:40 +0800
Subject: [PATCH] drm/amd/display: set new_stream to NULL after release
In dm_update_crtc_state(), the skip_modeset path releases new_stream
via dc_stream_release() but does not set the pointer to NULL.
If a later error (e.g., color management failure) triggers the fail
label, the error path calls dc_stream_release() again on the same
dangling pointer, causing a double release and potential use-after-free.
Fix this by setting new_stream to NULL after the initial release.
Fixes: 9b690ef3c704 ("drm/amd/display: Avoid full modeset when not required")
Signed-off-by: WenTao Liang <vulab%iscas.ac.cn@localhost>
Reviewed-by: George Zhang <george.zhang%amd.com@localhost>
Signed-off-by: Alex Deucher <alexander.deucher%amd.com@localhost>
---
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 0e76a3799b8502..e7080880b2211e 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -6046,6 +6046,7 @@ static int dm_update_crtc_state(struct amdgpu_display_manager *dm,
/* Release extra reference */
if (new_stream)
dc_stream_release(new_stream);
+ new_stream = NULL;
/*
* We want to do dc stream updates that do not require a
After applied this change in NetBSD, this crash gone for me.
Home |
Main Index |
Thread Index |
Old Index