lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250206-hotplug-drm-bridge-v6-21-9d6f2c9c3058@bootlin.com>
Date: Thu, 06 Feb 2025 19:14:36 +0100
From: Luca Ceresoli <luca.ceresoli@...tlin.com>
To: Simona Vetter <simona@...ll.ch>, Inki Dae <inki.dae@...sung.com>, 
 Jagan Teki <jagan@...rulasolutions.com>, 
 Marek Szyprowski <m.szyprowski@...sung.com>, 
 Catalin Marinas <catalin.marinas@....com>, Will Deacon <will@...nel.org>, 
 Shawn Guo <shawnguo@...nel.org>, Sascha Hauer <s.hauer@...gutronix.de>, 
 Pengutronix Kernel Team <kernel@...gutronix.de>, 
 Fabio Estevam <festevam@...il.com>, Daniel Thompson <danielt@...nel.org>, 
 Andrzej Hajda <andrzej.hajda@...el.com>, Jonathan Corbet <corbet@....net>, 
 Sam Ravnborg <sam@...nborg.org>, Boris Brezillon <bbrezillon@...nel.org>, 
 Nicolas Ferre <nicolas.ferre@...rochip.com>, 
 Alexandre Belloni <alexandre.belloni@...tlin.com>, 
 Claudiu Beznea <claudiu.beznea@...on.dev>, 
 Jessica Zhang <quic_jesszhan@...cinc.com>
Cc: Paul Kocialkowski <contact@...lk.fr>, 
 Maxime Ripard <mripard@...nel.org>, 
 Dmitry Baryshkov <dmitry.baryshkov@...aro.org>, 
 Neil Armstrong <neil.armstrong@...aro.org>, Robert Foss <rfoss@...nel.org>, 
 Laurent Pinchart <Laurent.pinchart@...asonboard.com>, 
 Jonas Karlman <jonas@...boo.se>, Jernej Skrabec <jernej.skrabec@...il.com>, 
 Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>, 
 Thomas Zimmermann <tzimmermann@...e.de>, David Airlie <airlied@...il.com>, 
 Hervé Codina <herve.codina@...tlin.com>, 
 Thomas Petazzoni <thomas.petazzoni@...tlin.com>, 
 linux-kernel@...r.kernel.org, dri-devel@...ts.freedesktop.org, 
 linux-doc@...r.kernel.org, linux-arm-kernel@...ts.infradead.org, 
 Paul Kocialkowski <paul.kocialkowski@...tlin.com>, 
 Luca Ceresoli <luca.ceresoli@...tlin.com>
Subject: [PATCH v6 21/26] drm/bridge: add list of removed refcounted
 bridges

Between drm_bridge_add() and drm_bridge_remove() bridges "published" to the
DRM core via the global bridge_list and visible in
/sys/kernel/debug/dri/bridges. However between drm_bridge_remove() and the
last drm_bridge_put(), a refcounted bridge memory is still allocated even
though the bridge is not "published", i.e. not in bridges_list, so it is
invisible in debugfs. This prevents debugging refcounted bridges lifetime,
especially leaks doe to any missing drm_bridge_put().

In order to allow debugfs to also show the removed refcounted bridges, move
such bridges into a new ad-hoc list until they are freed.

Note this requires adding INIT_LIST_HEAD(&bridge->list) in the bridge
initialization code: the lack of such init was not exposing any bug so far,
but it would with the new code.

Document the new behaviour of drm_bridge_remove() and update the
drm_bridge_add() documentation to stay consistent.

Signed-off-by: Luca Ceresoli <luca.ceresoli@...tlin.com>

---

This patch was added in v6.
---
 drivers/gpu/drm/drm_bridge.c   | 23 ++++++++++++++++++++---
 drivers/gpu/drm/drm_internal.h |  1 +
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index fc44a5d227a89a12b5c3299a29776cfddb36ce27..b315c7c4e32cc27723c69c795efe4f3313134204 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -315,9 +315,10 @@
  * driver.
  */
 
-/* Protect bridge_list */
+/* Protect bridge_list and bridge_removed_list */
 DEFINE_MUTEX(bridge_lock);
 LIST_HEAD(bridge_list);
+LIST_HEAD(bridge_removed_list);
 
 /* Internal function (for refcounted bridges) */
 void __drm_bridge_free(struct kref *kref)
@@ -327,6 +328,10 @@ void __drm_bridge_free(struct kref *kref)
 
 	DRM_DEBUG("bridge=%p, container=%p FREE\n", bridge, container);
 
+	mutex_lock(&bridge_lock);
+	list_del(&bridge->list);
+	mutex_unlock(&bridge_lock);
+
 	kfree(container);
 }
 EXPORT_SYMBOL(__drm_bridge_free);
@@ -355,6 +360,8 @@ void *__devm_drm_bridge_alloc(struct device *dev, size_t size, size_t offset,
 		return ERR_PTR(-ENOMEM);
 
 	bridge = container + offset;
+
+	INIT_LIST_HEAD(&bridge->list);
 	bridge->container_offset = offset;
 	bridge->funcs = funcs;
 	kref_init(&bridge->refcount);
@@ -371,7 +378,10 @@ void *__devm_drm_bridge_alloc(struct device *dev, size_t size, size_t offset,
 EXPORT_SYMBOL(__devm_drm_bridge_alloc);
 
 /**
- * drm_bridge_add - add the given bridge to the global bridge list
+ * drm_bridge_add - add to published bridges
+ *
+ * Adds the given bridge to the global bridge list, so it can be found by
+ * of_drm_find_bridge().
  *
  * @bridge: bridge control structure
  */
@@ -423,7 +433,12 @@ int devm_drm_bridge_add(struct device *dev, struct drm_bridge *bridge)
 EXPORT_SYMBOL(devm_drm_bridge_add);
 
 /**
- * drm_bridge_remove - remove the given bridge from the global bridge list
+ * drm_bridge_remove - remove from published bridges
+ *
+ * Remove the given bridge from the global bridge list, so it won't be
+ * found by of_drm_find_bridge(). If the bridge is refcounted it also adds
+ * it to the removed bridge list, to keep track of removed bridges until
+ * their allocated memory is finally freed.
  *
  * @bridge: bridge control structure
  */
@@ -435,6 +450,8 @@ void drm_bridge_remove(struct drm_bridge *bridge)
 
 	mutex_lock(&bridge_lock);
 	list_del_init(&bridge->list);
+	if (drm_bridge_is_refcounted(bridge))
+		list_add_tail(&bridge->list, &bridge_removed_list);
 	mutex_unlock(&bridge_lock);
 
 	list_for_each_entry_safe(br, tmp, &bridge_list, list)
diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h
index b6e875d4b25faae6bb0bb952c3c12bd4819698ec..bbfc938b21c13bc69c36d3833f6cb6d5d22d1c54 100644
--- a/drivers/gpu/drm/drm_internal.h
+++ b/drivers/gpu/drm/drm_internal.h
@@ -51,6 +51,7 @@ struct drm_vblank_crtc;
 // for drm_debugfs.c
 extern struct mutex bridge_lock;
 extern struct list_head bridge_list;
+extern struct list_head bridge_removed_list;
 
 /* drm_client_event.c */
 #if defined(CONFIG_DRM_CLIENT)

-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ