From nobody Mon Feb 9 09:17:31 2026 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7821E2F6170 for ; Tue, 3 Feb 2026 17:26:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770139613; cv=none; b=d+/Qp4KIcGGLED6w+m0pvOYBpAwWnbLlUJE1Tm3CxrZHsApSg9l4U5CyQkRxzwjq0HcbF3sASZZHzzE/z07/YPaFAwuH50d0TqANFzoObg5wFu+J+EbUK4RMqvWzM8bQAzHsLwBCfZRKv83MYyAm8ToC25k9/qH5Y5Kd47x+NMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770139613; c=relaxed/simple; bh=eHeOc+eHIfgwQyPtYJklu2XEpZlaeyctfQC2N0cRT7M=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=AhAI7ahMtVdI+hyfGYvVPPDI3uhpD647YxbRxmJn30oAUbmwqPdVJDtM56Bfys5esRwrrourzvDal6IPX1MYycjIZeu3+6hrYqghvjLP4YIEwZ+JUh/fq4nYY9v+pcSjwbOOH/AgPGdnt4MFhERQd3IXKopChqf1pvLQUZpFAgc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=shenghaoyang.info; spf=pass smtp.mailfrom=shenghaoyang.info; dkim=pass (2048-bit key) header.d=shenghaoyang.info header.i=@shenghaoyang.info header.b=TJGhVFk3; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=shenghaoyang.info Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shenghaoyang.info Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=shenghaoyang.info header.i=@shenghaoyang.info header.b="TJGhVFk3" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2a78fff310dso2630095ad.2 for ; Tue, 03 Feb 2026 09:26:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shenghaoyang.info; s=google; t=1770139611; x=1770744411; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=c6xoUAJ4TqCwZ2nkBb+us8sMoTfJqBk6aFeos35tub8=; b=TJGhVFk3bBtRzqDW7MbVc6xEYHijQToXB/rejmbD5rmcNSalBBRYfhQMx+dO647MBU JdElzYLI2pJKRPtT3XXa0YGiV8CUUta/ce7NfYQzvxubpp0iiRNCJnGr+aLRhyZM841y QUX8o9tHkjXWLsYD33ZFssVghT8y1KGZd1ZFNejSL2NZvfLJxgXLBKFsJBlbGYweo5BY D/DX8K+PxFV7pNkgqxuWMKCtn0cufJNt+xadmS3LtoinbmxsIGW+11dtiS1AjpVBH3uh w8QpCtg1ipZ9cYAbi7OsmTaBlztRNBUjBLtJ9DXUDOiW6Pafz+xk6JMQak9pa5Ha5W7e 9cIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770139611; x=1770744411; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=c6xoUAJ4TqCwZ2nkBb+us8sMoTfJqBk6aFeos35tub8=; b=JCHe87LWSkyKYSBLDsHvtykFAlMtAqoYWbqgsGgsEZ/OhShiB1j9GS94p3CDdg0z8j oeuE131+3Rut/IxHVyp2dI416rCuNc7ySqhPmyZU1a71MCxDPPK3UAha+upGfzrfer6k bOeBozfkHRk1XAIcllf3Hf3bay+CtRfShxsuHPqVkyA9N0ArLy12vfo3dF04fWQ2sFTS t8Rx9H5lvpDGQFFe5EukDdr/SmIP1ILdfStVVSqgA5yiexeOjt3VNYJHIA93K+ZTOpbS goTzIOqDPpBqUqIRAY2mbC79xUilj7cwf9LCaDv1WL7NcNujFza+Cy2iu4bvq8LK7WGp bfqQ== X-Forwarded-Encrypted: i=1; AJvYcCX/4b8E7LlF/c0B9IviGd4lCDgb2A5jyxfVWP1X3hhW1xnhjRxwJF/MZ72Dq7vQCOhOE6gZpCXujzo4PGU=@vger.kernel.org X-Gm-Message-State: AOJu0Yy//cSUaSQl6/pfi0t9QADo5mNlzH0qK+tLQrdTnhg0B9Ty0Vgy v4ykv9gNy581DSnuRR8AIfj0FmX6ajA88oHtMPJ8Rd+NuLaf+WgJHRMcAj+lHMMOiIQ= X-Gm-Gg: AZuq6aLDOG5IpCpnZdFXTMYlAmzGG/8+kEbUbtTHqdpHKgQY+zpKYsLR+V2CC9P2iDT I+wN5gTXaAJhuun8pog/sHA6UKcBxSy6soDoN9+jJa4wVKhsJGKTyMBRouNY6TAeJHrWXO9OBYm 3cgnVsOV11BKGiVyEcJnl9KEh5LhwrxCOqCHQZw3rMWF1kjY1eg7sU00Jjb8LsAWGdl68WROmHr CAgKHei0h/9guKRzVRqlOe2Sj0Lo4Z3Ud/RFABUZoUZzgiJatIJtsHNxaikFxetT77CbPAF2SpV 2GJy5kbVBTKN9XxwALYhuYc5eakQnbfpvaL8M5TF4G90ZXVPBvv981H3SlsYKJjoGG/jzzNVb+d YUSHu4HOD2gHN1uYVwDswj/b1Rb1m9UyHtf7YXVUDrp8zYGa0SafL4VtkILFzcgZmx2WHOAzdXm yor6mtaw+u X-Received: by 2002:a17:903:4b0d:b0:2a7:84bb:158 with SMTP id d9443c01a7336-2a933ad0211mr533665ad.0.1770139610659; Tue, 03 Feb 2026 09:26:50 -0800 (PST) Received: from localhost ([132.147.84.99]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-2a933854fcbsm665445ad.18.2026.02.03.09.26.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 Feb 2026 09:26:50 -0800 (PST) From: Shenghao Yang To: Ruben Wauters , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Shenghao Yang , kernel test robot , Dan Carpenter Subject: [PATCH v3] drm/gud: fix NULL crtc dereference on display disable Date: Wed, 4 Feb 2026 01:26:30 +0800 Message-ID: <20260203172630.10077-1-me@shenghaoyang.info> X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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.vanill= a.gud.fc42.x86_64 #1 PREEMPT(lazy) RIP: 0010:gud_plane_atomic_update+0x148/0x470 [gud] 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/20251231055039.44266-1-me@shenghaoyang.info/ [2] https://github.com/notro/gud/wiki/GUD-Protocol#display-state Reported-by: kernel test robot Reported-by: Dan Carpenter Closes: https://lore.kernel.org/r/202601142159.0v8ilfVs-lkp@intel.com/ Fixes: 73cfd166e045 ("drm/gud: Replace simple display pipe with DRM atomic = helpers") Signed-off-by: Shenghao Yang --- v3: Dropped stable AUTOSEL opt out v2: Moved controller and display control commands to crtc enable / disable functions. [v2]: https://lore.kernel.org/lkml/20260201095956.21042-1-me@shenghaoyang.i= nfo/ [v1]: https://lore.kernel.org/lkml/20260118125044.54467-1-me@shenghaoyang.i= nfo/ drivers/gpu/drm/gud/gud_drv.c | 9 ++++- drivers/gpu/drm/gud/gud_internal.h | 4 ++ drivers/gpu/drm/gud/gud_pipe.c | 59 +++++++++++++++++++++--------- 3 files changed, 53 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/gud/gud_drv.c b/drivers/gpu/drm/gud/gud_drv.c index 42135a48d92e..a2000991ecbe 100644 --- a/drivers/gpu/drm/gud/gud_drv.c +++ b/drivers/gpu/drm/gud/gud_drv.c @@ -339,7 +339,9 @@ static int gud_stats_debugfs(struct seq_file *m, void *= data) } =20 static const struct drm_crtc_helper_funcs gud_crtc_helper_funcs =3D { - .atomic_check =3D drm_crtc_helper_atomic_check + .atomic_check =3D drm_crtc_helper_atomic_check, + .atomic_enable =3D gud_crtc_atomic_enable, + .atomic_disable =3D gud_crtc_atomic_disable, }; =20 static const struct drm_crtc_funcs gud_crtc_funcs =3D { @@ -364,6 +366,10 @@ static const struct drm_plane_funcs gud_plane_funcs = =3D { DRM_GEM_SHADOW_PLANE_FUNCS, }; =20 +static const struct drm_mode_config_helper_funcs gud_mode_config_helpers = =3D { + .atomic_commit_tail =3D drm_atomic_helper_commit_tail_rpm, +}; + static const struct drm_mode_config_funcs gud_mode_config_funcs =3D { .fb_create =3D drm_gem_fb_create_with_dirty, .atomic_check =3D 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 =3D le32_to_cpu(desc.min_height); drm->mode_config.max_height =3D le32_to_cpu(desc.max_height); drm->mode_config.funcs =3D &gud_mode_config_funcs; + drm->mode_config.helper_private =3D &gud_mode_config_helpers; =20 /* Format init */ formats_dev =3D devm_kmalloc(dev, GUD_FORMATS_MAX_NUM, GFP_KERNEL); diff --git a/drivers/gpu/drm/gud/gud_internal.h b/drivers/gpu/drm/gud/gud_i= nternal.h index d27c31648341..a5b7e53cf79c 100644 --- a/drivers/gpu/drm/gud/gud_internal.h +++ b/drivers/gpu/drm/gud/gud_internal.h @@ -62,6 +62,10 @@ int gud_usb_set_u8(struct gud_device *gdrm, u8 request, = u8 val); =20 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, diff --git a/drivers/gpu/drm/gud/gud_pipe.c b/drivers/gpu/drm/gud/gud_pipe.c index 4b77be94348d..46b47452b315 100644 --- a/drivers/gpu/drm/gud/gud_pipe.c +++ b/drivers/gpu/drm/gud/gud_pipe.c @@ -580,6 +580,44 @@ int gud_plane_atomic_check(struct drm_plane *plane, return ret; } =20 +void gud_crtc_atomic_enable(struct drm_crtc *crtc, + struct drm_atomic_state *state) +{ + struct drm_device *drm =3D crtc->dev; + struct gud_device *gdrm =3D to_gud_device(drm); + int idx; + + if (!drm_dev_enter(drm, &idx)) + return; + + if (crtc->state->mode_changed || crtc->state->connectors_changed) { + gud_usb_set_u8(gdrm, GUD_REQ_SET_CONTROLLER_ENABLE, 1); + gud_usb_set(gdrm, GUD_REQ_SET_STATE_COMMIT, 0, NULL, 0); + } + + gud_usb_set_u8(gdrm, GUD_REQ_SET_DISPLAY_ENABLE, crtc->state->active); + + drm_dev_exit(idx); +} + +void gud_crtc_atomic_disable(struct drm_crtc *crtc, + struct drm_atomic_state *state) +{ + struct drm_device *drm =3D crtc->dev; + struct gud_device *gdrm =3D to_gud_device(drm); + int idx; + + if (!drm_dev_enter(drm, &idx)) + return; + + gud_usb_set_u8(gdrm, GUD_REQ_SET_DISPLAY_ENABLE, 0); + + if (crtc->state->mode_changed || crtc->state->connectors_changed) + gud_usb_set_u8(gdrm, GUD_REQ_SET_CONTROLLER_ENABLE, 0); + + drm_dev_exit(idx); +} + void gud_plane_atomic_update(struct drm_plane *plane, struct drm_atomic_state *atomic_state) { @@ -607,24 +645,12 @@ void gud_plane_atomic_update(struct drm_plane *plane, mutex_unlock(&gdrm->damage_lock); } =20 - if (!drm_dev_enter(drm, &idx)) + if (!crtc || !drm_dev_enter(drm, &idx)) return; =20 - if (!old_state->fb) - gud_usb_set_u8(gdrm, GUD_REQ_SET_CONTROLLER_ENABLE, 1); - - if (fb && (crtc->state->mode_changed || crtc->state->connectors_changed)) - gud_usb_set(gdrm, GUD_REQ_SET_STATE_COMMIT, 0, NULL, 0); - - if (crtc->state->active_changed) - gud_usb_set_u8(gdrm, GUD_REQ_SET_DISPLAY_ENABLE, crtc->state->active); - - if (!fb) - goto ctrl_disable; - ret =3D drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE); if (ret) - goto ctrl_disable; + goto out; =20 drm_atomic_helper_damage_iter_init(&iter, old_state, new_state); drm_atomic_for_each_plane_damage(&iter, &damage) @@ -632,9 +658,6 @@ void gud_plane_atomic_update(struct drm_plane *plane, =20 drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE); =20 -ctrl_disable: - if (!crtc->state->enable) - gud_usb_set_u8(gdrm, GUD_REQ_SET_CONTROLLER_ENABLE, 0); - +out: drm_dev_exit(idx); } --=20 2.52.0