| Message ID | 20260510124111.1226584-22-jonas@kwiboo.se (mailing list archive) |
|---|---|
| State | New |
| Headers |
Return-Path: <linux-sunxi+bounces-23230-sunxi=pue.re@lists.linux.dev> X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id BE52A1C06E9 for <noreply@patchwork.local>; Sun, 10 May 2026 14:51:48 +0200 (CEST) Authentication-Results: mxe881; dkim=pass header.d=kwiboo.se; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-23230-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-23230-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by tor.lore.kernel.org (Postfix) with ESMTP id E1FAC3088290 for <noreply@patchwork.local>; Sun, 10 May 2026 12:44:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 31D90385535; Sun, 10 May 2026 12:43:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kwiboo.se header.i=@kwiboo.se header.b="t1X/0ept" X-Original-To: linux-sunxi@lists.linux.dev Received: from smtp.forwardemail.net (smtp.forwardemail.net [121.127.44.73]) (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 DDE59385516 for <linux-sunxi@lists.linux.dev>; Sun, 10 May 2026 12:43:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=121.127.44.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778416983; cv=none; b=XM1fFwmzMYB1WLI0XTrGps9cKFsmQX7bKeNi3LAdWNEyLPGVkRBTDrYRKw9d/gMAoPcmrD4dJ3mxuXmcY78gp44rddIXjTL7ldLhTavNTQcMHkj7P0IjbxN4SqIv1vgWSFjUDxdbqG6J1jKtFTtbRiNRebdLrYDpH107CCthI7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778416983; c=relaxed/simple; bh=ofWvltFFN75SKEi4UQY+nolo8ycoGrWIU6z7m0c5RZ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aLviBuaFp9ao4TR4p4vm2Jb+GO40w2KGV33D/lcYvWdfDErOzpJUvJ1D9l23X0gW9vdVj+fW8G++pipixLthGGgkjV/pjvDUuLTCgPPWoLEl5w6+6lvo4BrqbpabysEN0Kyx87w3+zbLdNh+4Sc5/s1T4uV+L99kaYTQJ9TIav4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=kwiboo.se; spf=pass smtp.mailfrom=fe-bounces.kwiboo.se; dkim=pass (2048-bit key) header.d=kwiboo.se header.i=@kwiboo.se header.b=t1X/0ept; arc=none smtp.client-ip=121.127.44.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=kwiboo.se Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fe-bounces.kwiboo.se DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kwiboo.se; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-ID: Date: Subject: Cc: To: From; q=dns/txt; s=fe-e1b5cab7be; t=1778416980; bh=UqGGh3H1sUTh9W3shIilOvORsLiwtCTjl7edRaUY1bI=; b=t1X/0eptX489v7MlvSlu8LKNRdk9t7GtR6H5bFgf1vhOyztpiD1oYk7KdY+7oFdMHf09K1Dnn fgPdJvybXhW18G99VmX/9anXanPtHTaIKJB2Whry65Hkwim690O2tXOThPUMUeLrghJC3G2YHTM DGPbizJanPNUhKs/fCL6AYFRYKeAyl524+PwwBX2GJjNpOAiuJzXAZYf7nuYUEbEkdM1S/EpHfV 8BWur4XWzatEhiGN5L7FnwVVUag11cXz3WgcWFhttajmgZGPsf3ovVbzMyablvfliD+RwYUGPkQ mYlq1ZI11J8b5bPAr9BzVUNrk/hVfEaknN6iypL40Y6A== X-Forward-Email-ID: 6a007d4f0d91f03a31a0bd8d X-Forward-Email-Sender: rfc822; jonas@kwiboo.se, smtp.forwardemail.net, 121.127.44.73 X-Forward-Email-Version: 2.8.0 X-Forward-Email-Website: https://forwardemail.net X-Complaints-To: abuse@forwardemail.net X-Report-Abuse: abuse@forwardemail.net X-Report-Abuse-To: abuse@forwardemail.net From: Jonas Karlman <jonas@kwiboo.se> To: Andrzej Hajda <andrzej.hajda@intel.com>, Neil Armstrong <neil.armstrong@linaro.org>, Robert Foss <rfoss@kernel.org>, Heiko Stuebner <heiko@sntech.de>, Laurent Pinchart <Laurent.pinchart@ideasonboard.com>, Jonas Karlman <jonas@kwiboo.se>, Jernej Skrabec <jernej.skrabec@gmail.com>, Luca Ceresoli <luca.ceresoli@bootlin.com>, Maarten Lankhorst <maarten.lankhorst@linux.intel.com>, Maxime Ripard <mripard@kernel.org>, Thomas Zimmermann <tzimmermann@suse.de>, David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch> Cc: Liu Ying <victor.liu@nxp.com>, Sandy Huang <hjc@rock-chips.com>, Andy Yan <andy.yan@rock-chips.com>, Chen-Yu Tsai <wens@kernel.org>, Christian Hewitt <christianshewitt@gmail.com>, Diederik de Haas <diederik@cknow-tech.com>, Nicolas Frattaroli <nicolas.frattaroli@collabora.com>, Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-amlogic@lists.infradead.org, linux-sunxi@lists.linux.dev, imx@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v5 21/21] drm: bridge: dw_hdmi: Drop call to drm_bridge_hpd_notify() Date: Sun, 10 May 2026 12:41:05 +0000 Message-ID: <20260510124111.1226584-22-jonas@kwiboo.se> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260510124111.1226584-1-jonas@kwiboo.se> References: <20260510124111.1226584-1-jonas@kwiboo.se> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: <linux-sunxi.lists.linux.dev> List-Subscribe: <mailto:linux-sunxi+subscribe@lists.linux.dev> List-Unsubscribe: <mailto:linux-sunxi+unsubscribe@lists.linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= |
| Series |
drm: bridge: dw_hdmi: Misc enable/disable, CEC and EDID cleanup
|
|
Commit Message
Jonas Karlman
May 10, 2026, 12:41 p.m. UTC
The use of calls to both drm_helper_hpd_irq_event() and
drm_bridge_hpd_notify() in HPD delayed_work may cause multiple hotplug
uevents and modesets when the bridge connector is used.
Use of drm_helper_hpd_irq_event() cause the internal DRM function
check_connector_changed() to be called, which in turn calls the
connector detect()/force() funcs to detect any connection status or
epoch changes, and when changed trigger a hotplug uevent. For dw-hdmi
connector this also help ensure that EDID and CEC phys addr is updated.
If only a call drm_bridge_hpd_notify() would be used, a custom connector
status/EDID change detection logic needs to be implemented, to fully
match what check_connector_changed() already provides. Update of EDID
and CEC phys addr typically is delayed until userspace trigger a modeset
and fill_modes()/get_modes() ops is called.
The bridge connector detect() func also ensures that any hpd_notify()
funcs are called for all bridges in the chain, so there is not really
any need to have a call to drm_bridge_hpd_notify() here.
With both calls there is two hotplug uevents, two modesets and a total
of four .hpd_notify() calls (using a bridge connector):
dw_hdmi_hardirq(): EVENT=plugout
dw_hdmi_hpd_work()
drm_helper_hpd_irq_event():
dw_hdmi_bridge_hpd_notify(status=2)
[drm:check_connector_changed] [CONNECTOR:46:HDMI-A-1] status updated from connected to disconnected
[drm:check_connector_changed] [CONNECTOR:46:HDMI-A-1] Changed epoch counter 1 => 2
[drm:drm_sysfs_connector_hotplug_event] [CONNECTOR:46:HDMI-A-1] generating connector hotplug event
drm_client_hotplug():
[drm:drm_fb_helper_hotplug_event]
[drm:drm_client_modeset_probe]
[drm:drm_helper_probe_single_connector_modes] [CONNECTOR:46:HDMI-A-1]
dw_hdmi_bridge_hpd_notify(status=2)
[drm:drm_helper_probe_single_connector_modes] [CONNECTOR:46:HDMI-A-1] disconnected
[drm:drm_edid_connector_update] [CONNECTOR:46:HDMI-A-1] EDID changed, epoch counter 3
[drm:drm_client_modeset_probe] No connectors reported connected with modes
[drm:drm_client_modeset_probe] [CONNECTOR:46:HDMI-A-1] enabled? no
[drm:drm_client_firmware_config.isra.0] Not using firmware configuration
[drm:drm_client_modeset_probe] picking CRTCs for 3840x2160 config
[drm:drm_client_hotplug] fbdev: ret=0
drm_bridge_hpd_notify():
dw_hdmi_bridge_hpd_notify(status=2)
[drm:drm_sysfs_connector_hotplug_event] [CONNECTOR:46:HDMI-A-1] generating connector hotplug event
drm_client_hotplug():
[drm:drm_fb_helper_hotplug_event]
[drm:drm_client_modeset_probe]
[drm:drm_helper_probe_single_connector_modes] [CONNECTOR:46:HDMI-A-1]
dw_hdmi_bridge_hpd_notify(status=2)
[drm:drm_helper_probe_single_connector_modes] [CONNECTOR:46:HDMI-A-1] disconnected
[drm:drm_client_modeset_probe] No connectors reported connected with modes
[drm:drm_client_modeset_probe] [CONNECTOR:46:HDMI-A-1] enabled? no
[drm:drm_client_firmware_config.isra.0] Not using firmware configuration
[drm:drm_client_modeset_probe] picking CRTCs for 3840x2160 config
[drm:drm_client_hotplug] fbdev: ret=0
Change to only call drm_helper_hpd_irq_event() in HPD delayed_work to
ensure there is only one hotplug uevent and that EDID and CEC phys addr
is updated in a timely manner, independent from userspace having to
react the hotplug uevent.
With only a call the drm_helper_hpd_irq_event() there is only a single
hotplug uevent and only two .hpd_notify() calls:
dw_hdmi_hardirq(): EVENT=plugout
dw_hdmi_hpd_work()
drm_helper_hpd_irq_event():
dw_hdmi_bridge_hpd_notify(status=2)
[drm:check_connector_changed] [CONNECTOR:46:HDMI-A-1] status updated from connected to disconnected
[drm:check_connector_changed] [CONNECTOR:46:HDMI-A-1] Changed epoch counter 1 => 2
[drm:drm_sysfs_connector_hotplug_event] [CONNECTOR:46:HDMI-A-1] generating connector hotplug event
drm_client_hotplug():
[drm:drm_fb_helper_hotplug_event]
[drm:drm_client_modeset_probe]
[drm:drm_helper_probe_single_connector_modes] [CONNECTOR:46:HDMI-A-1]
dw_hdmi_bridge_hpd_notify(status=2)
[drm:drm_helper_probe_single_connector_modes] [CONNECTOR:46:HDMI-A-1] disconnected
[drm:drm_edid_connector_update] [CONNECTOR:46:HDMI-A-1] EDID changed, epoch counter 3
[drm:drm_client_modeset_probe] No connectors reported connected with modes
[drm:drm_client_modeset_probe] [CONNECTOR:46:HDMI-A-1] enabled? no
[drm:drm_client_firmware_config.isra.0] Not using firmware configuration
[drm:drm_client_modeset_probe] picking CRTCs for 3840x2160 config
[drm:drm_client_hotplug] fbdev: ret=0
Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
---
v5: New patch
---
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
Comments
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Removing `drm_bridge_hpd_notify()` violates the DRM bridge API contract, breaks hotplug for non-polling setups, and causes inefficient global polling. - [High] Teardown asymmetry allows the interrupt handler to re-arm canceled delayed work, leading to a Use-After-Free. - [High] TOCTOU race condition in asynchronous workqueue leads to Use-After-Free on DRM device teardown. -- commit ad165e8e6d6f42026d4a0bad754838b6429517bd Author: Jonas Karlman <jonas@kwiboo.se> drm: bridge: dw_hdmi: Drop call to drm_bridge_hpd_notify() This commit drops the call to drm_bridge_hpd_notify() in the HDMI hotplug delayed work to prevent duplicate hotplug uevents and modesets, relying solely on drm_helper_hpd_irq_event(). > diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c > index 2ea8ce5eca367..d9c9d03f8eff2 100644 > --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c > +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c > @@ -3019,14 +3019,28 @@ static irqreturn_t dw_hdmi_hardirq(int irq, void *dev_id) > static void dw_hdmi_hpd_work(struct work_struct *work) > { > struct dw_hdmi *hdmi = container_of(work, struct dw_hdmi, hpd_work.work); This is an existing issue not introduced by this patch, but does the delayed work lifecycle have a use-after-free vulnerability during teardown? If cancel_delayed_work_sync(&hdmi->hpd_work) is called in dw_hdmi_remove() before hardware interrupts are muted, can dw_hdmi_hardirq() silently re-arm the workqueue? If the hdmi structure is then freed by devres, execution of this work function later would cause a use-after-free. > - enum drm_connector_status status; > > if (WARN_ON(!hdmi->bridge.dev)) This is another pre-existing issue, but is there a time-of-check to time-of-use race condition here? Since dw_hdmi is an external bridge, its lifetime is independent of the master DRM device. If the master DRM driver unbinds concurrently, it could set hdmi->bridge.dev to NULL and free the DRM device. Could this workqueue evaluate hdmi->bridge.dev as non-NULL, get interrupted, and then pass a freed DRM device pointer to drm_helper_hpd_irq_event() below? > return; [ ... ] > drm_helper_hpd_irq_event(hdmi->bridge.dev); > - status = dw_hdmi_phy_read_hpd(hdmi, hdmi->phy.data); > - drm_bridge_hpd_notify(&hdmi->bridge, status); > } Does removing drm_bridge_hpd_notify() violate the DRM_BRIDGE_OP_HPD contract and break hotplug functionality for non-polling setups? Looking at drm_helper_hpd_irq_event(), it immediately returns false if dev->mode_config.poll_enabled is false. For setups relying strictly on interrupt-driven bridge hotplug notifications without enabling polling, would this leave hotplug completely broken? Additionally, instead of handling just the HDMI port, will drm_helper_hpd_irq_event() force a synchronous detect() cycle on all connectors on the DRM device that have the DRM_CONNECTOR_POLL_HPD flag set, causing an inefficient system-wide poll?
diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c index 2ea8ce5eca36..d9c9d03f8eff 100644 --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c @@ -3019,14 +3019,28 @@ static irqreturn_t dw_hdmi_hardirq(int irq, void *dev_id) static void dw_hdmi_hpd_work(struct work_struct *work) { struct dw_hdmi *hdmi = container_of(work, struct dw_hdmi, hpd_work.work); - enum drm_connector_status status; if (WARN_ON(!hdmi->bridge.dev)) return; + /* + * Notify the DRM core of the HPD event using drm_helper_hpd_irq_event() + * instead of drm_bridge_hpd_notify(). This will cause the DRM function + * check_connector_changed() to be called, which in turn calls the + * connector detect()/force() funcs to detect any connection status or + * epoch changes. Something that also triggers EDID and CEC phys address + * updates. + * + * If we were to instead call drm_bridge_hpd_notify() here, we would + * have to implement a very similar change detection logic or fully + * relay on userspace to react on a hotplug uevent to ensure EDID and + * CEC phys address are updated. + * + * The bridge connector detect() func also ensures that hpd_notify() + * funcs are called for all bridges in the chain. + */ + drm_helper_hpd_irq_event(hdmi->bridge.dev); - status = dw_hdmi_phy_read_hpd(hdmi, hdmi->phy.data); - drm_bridge_hpd_notify(&hdmi->bridge, status); } static const struct dw_hdmi_phy_data dw_hdmi_phys[] = {