FAILED: patch "[PATCH] drm/gud: fix NULL crtc dereference on display disable" failed to apply to 6.18-stable tree
Subsystems (4)
[email protected]
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x 7149be786da012afc6bae293d38f8c1fff1fb90d
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026031703-footpad-unpaved-0a7a@gregkh' --subject-prefix 'PATCH 6.18.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 7149be786da012afc6bae293d38f8c1fff1fb90d Mon Sep 17 00:00:00 2001
From: Shenghao Yang <[email protected]>
Date: Sun, 22 Feb 2026 13:45:51 +0800
Subject: [PATCH] drm/gud: fix NULL crtc dereference on display disable
gud_plane_atomic_update() currently handles both crtc state and framebuffer updates - the complexity has led to a few accidental NULL pointer dereferences.
Commit dc2d5ddb193e ("drm/gud: fix NULL fb and crtc dereferences on USB disconnect") [1] fixed an earlier dereference but planes can also be disabled in non-hotplug paths (e.g. display disables via the desktop environment). The drm_dev_enter() call would not cause an early return in those and subsequently oops on dereferencing crtc:
BUG: kernel NULL pointer dereference, address: 00000000000005c8 CPU: 6 UID: 1000 PID: 3473 Comm: kwin_wayland Not tainted 6.18.2-200.vanilla.gud.fc42.x86_64 #1 PREEMPT(lazy) RIP: 0010:gud_plane_atomic_update+0x148/0x470 [gud] <TASK> drm_atomic_helper_commit_planes+0x28e/0x310 drm_atomic_helper_commit_tail+0x2a/0x70 commit_tail+0xf1/0x150 drm_atomic_helper_commit+0x13c/0x180 drm_atomic_commit+0xb1/0xe0 info ? __pfx___drm_printfn_info+0x10/0x10 drm_mode_atomic_ioctl+0x70f/0x7c0 ? __pfx_drm_mode_atomic_ioctl+0x10/0x10 drm_ioctl_kernel+0xae/0x100 drm_ioctl+0x2a8/0x550 ? __pfx_drm_mode_atomic_ioctl+0x10/0x10 __x64_sys_ioctl+0x97/0xe0 do_syscall_64+0x7e/0x7f0 ? __ct_user_enter+0x56/0xd0 ? do_syscall_64+0x158/0x7f0 ? __ct_user_enter+0x56/0xd0 ? do_syscall_64+0x158/0x7f0 entry_SYSCALL_64_after_hwframe+0x76/0x7e
Split out crtc handling from gud_plane_atomic_update() into atomic_enable() and atomic_disable() functions to delegate crtc state transitioning work to the DRM helpers.
To preserve the gud state commit sequence [2], switch to the runtime PM version of drm_atomic_helper_commit_tail() which ensures that crtcs are enabled (hence sending the GUD_REQ_SET_CONTROLLER_ENABLE and GUD_REQ_SET_DISPLAY_ENABLE requests) before a framebuffer update is sent.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://github.com/notro/gud/wiki/GUD-Protocol#display-state
drivers/gpu/drm/gud/gud_drv.c +8 -1
@@ -339,7 +339,9 @@ static int gud_stats_debugfs(struct seq_file *m, void *data) }static const struct drm_crtc_helper_funcs gud_crtc_helper_funcs = { - .atomic_check = drm_crtc_helper_atomic_check + .atomic_check = drm_crtc_helper_atomic_check, + .atomic_enable = gud_crtc_atomic_enable, + .atomic_disable = gud_crtc_atomic_disable, };static const struct drm_crtc_funcs gud_crtc_funcs = {
@@ -364,6 +366,10 @@ static const struct drm_plane_funcs gud_plane_funcs = { DRM_GEM_SHADOW_PLANE_FUNCS, }; +static const struct drm_mode_config_helper_funcs gud_mode_config_helpers = { + .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm, +}; +static const struct drm_mode_config_funcs gud_mode_config_funcs = { .fb_create = drm_gem_fb_create_with_dirty, .atomic_check = drm_atomic_helper_check,
@@ -499,6 +505,7 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id) drm->mode_config.min_height =le32_to_cpu (desc.min_height); drm->mode_config.max_height =le32_to_cpu (desc.max_height); drm->mode_config.funcs = &gud_mode_config_funcs; + drm->mode_config.helper_private = &gud_mode_config_helpers;/* Format init */ formats_dev =devm_kmalloc (dev,GUD_FORMATS_MAX_NUM ,GFP_KERNEL );
drivers/gpu/drm/gud/gud_internal.h +4 -0
@@ -62,6 +62,10 @@ int gud_usb_set_u8(struct gud_device *gdrm, u8 request, u8 val);void gud_clear_damage (struct gud_device *gdrm);void gud_flush_work (struct work_struct *work); +void gud_crtc_atomic_enable (struct drm_crtc *crtc, +struct drm_atomic_state *state); +void gud_crtc_atomic_disable (struct drm_crtc *crtc, +struct drm_atomic_state *state);int gud_plane_atomic_check (struct drm_plane *plane,struct drm_atomic_state *state); void gud_plane_atomic_update(struct drm_plane *plane,
drivers/gpu/drm/gud/gud_pipe.c +36 -18
75 lines not on this page · raw message
Sasha Levin
maintainerPATCH 1/2 drm/gud: rearrange gud_probe() to prepare for function splitting
From: Ruben Wauters <[email protected]>
[ Upstream commit b9e5e9d2c187b849e050d59823e8c834f78475ab ]
gud_probe() is currently very large and does many things, including pipeline setup and feature detection, as well as having USB functions.
This patch re-orders the code in gud_probe() to make it more organised and easier to split apart in the future.
Stable-dep-of: 7149be786da0 ("drm/gud: fix NULL crtc dereference on display disable")
--- drivers/gpu/drm/gud/gud_drv.c | 45 +++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 21 deletions(-)
drivers/gpu/drm/gud/gud_drv.c +24 -21
@@ -249,7 +249,7 @@ int gud_usb_set_u8(struct gud_device *gdrm, u8 request, u8 val)return gud_usb_set (gdrm, request,0 , &val,sizeof (val)); } -static int gud_get_properties (struct gud_device *gdrm) +static int gud_plane_add_properties (struct gud_device *gdrm) {struct gud_property_req *properties;unsigned int i, num_properties;
@@ -463,10 +463,6 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)return PTR_ERR (gdrm); drm = &gdrm->drm; - drm->mode_config.funcs = &gud_mode_config_funcs; - ret =drmm_mode_config_init (drm); -if (ret) -return ret; gdrm->flags =le32_to_cpu (desc.flags); gdrm->compression = desc.compression &GUD_COMPRESSION_LZ4 ;
@@ -483,11 +479,28 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)if (ret)return ret; +usb_set_intfdata (intf, gdrm); + + dma_dev =usb_intf_get_dma_device (intf); +if (dma_dev) { +drm_dev_set_dma_dev (drm, dma_dev); +put_device (dma_dev); + }else { +dev_warn (dev,"buffer sharing not supported" );/* not an error */ + } + +/* Mode config init */ + ret =drmm_mode_config_init (drm); +if (ret) +return ret; + drm->mode_config.min_width =le32_to_cpu (desc.min_width); drm->mode_config.max_width =le32_to_cpu (desc.max_width); drm->mode_config.min_height =le32_to_cpu (desc.min_height); drm->mode_config.max_height =le32_to_cpu (desc.max_height); + drm->mode_config.funcs = &gud_mode_config_funcs; +/* Format init */ formats_dev =devm_kmalloc (dev,GUD_FORMATS_MAX_NUM ,GFP_KERNEL );/* Add room for emulated XRGB8888 */ formats =devm_kmalloc_array (dev,GUD_FORMATS_MAX_NUM +1 ,sizeof (*formats),GFP_KERNEL );
@@ -587,6 +600,7 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)return -ENOMEM ; } +/* Pipeline init */ ret = drm_universal_plane_init(drm, &gdrm->plane, 0, &gud_plane_funcs, formats, num_formats,
@@ -598,12 +612,9 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)drm_plane_helper_add (&gdrm->plane, &gud_plane_helper_funcs);drm_plane_enable_fb_damage_clips (&gdrm->plane); -devm_kfree (dev, formats); -devm_kfree (dev, formats_dev); - - ret =gud_get_properties (gdrm); + ret =gud_plane_add_properties (gdrm);if (ret) { -dev_err (dev,"Failed to get properties (error=%d)\n" , ret); +dev_err (dev,"Failed to add properties (error=%d)\n" , ret);return ret; }
@@ -621,16 +632,7 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id) }drm_mode_config_reset (drm); - -usb_set_intfdata (intf, gdrm); - - dma_dev =usb_intf_get_dma_device (intf); -if (dma_dev) { -drm_dev_set_dma_dev (drm, dma_dev); -put_device (dma_dev); - }else { -dev_warn (dev,"buffer sharing not supported" );/* not an error */ - } +drm_kms_helper_poll_init (drm);drm_debugfs_add_file (drm,"stats" , gud_stats_debugfs,NULL );
@@ -638,7 +640,8 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)if (ret)return ret; -drm_kms_helper_poll_init (drm); +devm_kfree (dev, formats); +devm_kfree (dev, formats_dev);drm_client_setup (drm,NULL );
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 2/2 drm/gud: fix NULL crtc dereference on display disable
From: Shenghao Yang <[email protected]>
[ Upstream commit 7149be786da012afc6bae293d38f8c1fff1fb90d ]
gud_plane_atomic_update() currently handles both crtc state and framebuffer updates - the complexity has led to a few accidental NULL pointer dereferences.
Commit dc2d5ddb193e ("drm/gud: fix NULL fb and crtc dereferences on USB disconnect") [1] fixed an earlier dereference but planes can also be disabled in non-hotplug paths (e.g. display disables via the desktop environment). The drm_dev_enter() call would not cause an early return in those and subsequently oops on dereferencing crtc:
BUG: kernel NULL pointer dereference, address: 00000000000005c8 CPU: 6 UID: 1000 PID: 3473 Comm: kwin_wayland Not tainted 6.18.2-200.vanilla.gud.fc42.x86_64 #1 PREEMPT(lazy) RIP: 0010:gud_plane_atomic_update+0x148/0x470 [gud] <TASK> drm_atomic_helper_commit_planes+0x28e/0x310 drm_atomic_helper_commit_tail+0x2a/0x70 commit_tail+0xf1/0x150 drm_atomic_helper_commit+0x13c/0x180 drm_atomic_commit+0xb1/0xe0 info ? __pfx___drm_printfn_info+0x10/0x10 drm_mode_atomic_ioctl+0x70f/0x7c0 ? __pfx_drm_mode_atomic_ioctl+0x10/0x10 drm_ioctl_kernel+0xae/0x100 drm_ioctl+0x2a8/0x550 ? __pfx_drm_mode_atomic_ioctl+0x10/0x10 __x64_sys_ioctl+0x97/0xe0 do_syscall_64+0x7e/0x7f0 ? __ct_user_enter+0x56/0xd0 ? do_syscall_64+0x158/0x7f0 ? __ct_user_enter+0x56/0xd0 ? do_syscall_64+0x158/0x7f0 entry_SYSCALL_64_after_hwframe+0x76/0x7e
Split out crtc handling from gud_plane_atomic_update() into atomic_enable() and atomic_disable() functions to delegate crtc state transitioning work to the DRM helpers.
To preserve the gud state commit sequence [2], switch to the runtime PM version of drm_atomic_helper_commit_tail() which ensures that crtcs are enabled (hence sending the GUD_REQ_SET_CONTROLLER_ENABLE and GUD_REQ_SET_DISPLAY_ENABLE requests) before a framebuffer update is sent.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://github.com/notro/gud/wiki/GUD-Protocol#display-state
--- drivers/gpu/drm/gud/gud_drv.c | 9 ++++- drivers/gpu/drm/gud/gud_internal.h | 4 +++ drivers/gpu/drm/gud/gud_pipe.c | 54 ++++++++++++++++++++---------- 3 files changed, 48 insertions(+), 19 deletions(-)
drivers/gpu/drm/gud/gud_drv.c +8 -1
@@ -339,7 +339,9 @@ static int gud_stats_debugfs(struct seq_file *m, void *data) }static const struct drm_crtc_helper_funcs gud_crtc_helper_funcs = { - .atomic_check = drm_crtc_helper_atomic_check + .atomic_check = drm_crtc_helper_atomic_check, + .atomic_enable = gud_crtc_atomic_enable, + .atomic_disable = gud_crtc_atomic_disable, };static const struct drm_crtc_funcs gud_crtc_funcs = {
@@ -364,6 +366,10 @@ static const struct drm_plane_funcs gud_plane_funcs = { DRM_GEM_SHADOW_PLANE_FUNCS, }; +static const struct drm_mode_config_helper_funcs gud_mode_config_helpers = { + .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm, +}; +static const struct drm_mode_config_funcs gud_mode_config_funcs = { .fb_create = drm_gem_fb_create_with_dirty, .atomic_check = drm_atomic_helper_check,
@@ -499,6 +505,7 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id) drm->mode_config.min_height =le32_to_cpu (desc.min_height); drm->mode_config.max_height =le32_to_cpu (desc.max_height); drm->mode_config.funcs = &gud_mode_config_funcs; + drm->mode_config.helper_private = &gud_mode_config_helpers;/* Format init */ formats_dev =devm_kmalloc (dev,GUD_FORMATS_MAX_NUM ,GFP_KERNEL );
drivers/gpu/drm/gud/gud_internal.h +4 -0
@@ -62,6 +62,10 @@ int gud_usb_set_u8(struct gud_device *gdrm, u8 request, u8 val);void gud_clear_damage (struct gud_device *gdrm);void gud_flush_work (struct work_struct *work); +void gud_crtc_atomic_enable (struct drm_crtc *crtc, +struct drm_atomic_state *state); +void gud_crtc_atomic_disable (struct drm_crtc *crtc, +struct drm_atomic_state *state);int gud_plane_atomic_check (struct drm_plane *plane,struct drm_atomic_state *state); void gud_plane_atomic_update(struct drm_plane *plane,
drivers/gpu/drm/gud/gud_pipe.c +36 -18
75 lines not on this page · raw message
Signature · 1 line
2.51.0