From patchwork Thu Feb 6 18:14:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 13963602 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DEF7BC0219F for ; Thu, 6 Feb 2025 19:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ZCyiZrk1wZv+6lsBh4aT/JUbtqG9ImrmSJSb0HiDc9A=; b=zzrryRddPu3wQBhsy+I4sOk7ZX 2tOos80+BfKGGcoQhA94QCo9KEADa6quA7xGc2Uvuz0Dq64XtLjlFvxFQL4Qar4+H/KiqRe+G9W17 46lcdUQf3Wea9Gs8OXpuVtC9C54SbXsFWXnR/l3I/rL6lLmMGfKMzoS/GSLiBHKBpukL7xm3+1s/e xZJ7JgpaHB/8Y5ST47dI1+CG/No6Xu8pkilP3j7flB+V+0LBAw2eRqo5csFcZxgB+ne12ZqRf2Zzo rrJ07zYvn/TzZxPagLCHNEJEqpcFcTNWv0aq1CuenU1kvRNbmw5+lfDebG5kaPrZX6caj3UKPxjYM 5odmEWmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tg77n-00000007I08-1FjM; Thu, 06 Feb 2025 19:01:19 +0000 Received: from relay6-d.mail.gandi.net ([2001:4b98:dc4:8::226]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tg6PX-000000078Dr-346e for linux-arm-kernel@lists.infradead.org; Thu, 06 Feb 2025 18:15:37 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id AF2A8442BE; Thu, 6 Feb 2025 18:15:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1738865734; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZCyiZrk1wZv+6lsBh4aT/JUbtqG9ImrmSJSb0HiDc9A=; b=AREd3kQjJ5MTwvg4Dp7t6dvP4wFGZE9QXGJLQY+LDRgEiRXM1FTT8rIKcYUayo9OK1OPZW GXu667LdmHyFEYqs8ycBhfOZzN6QB96v/XKBV9zSNqqXDEHkztUyQsxt2NqALN6g6MU1MV 91LnmL9cUXLJ6tgH1r2zRWhZT7d+6g/xNVaEmC1sfOOpntSbrysfY3/42ZtJX6XqWz8INN vbgpmcFXbGf/ay46QDA7qKOLCRBJwe6WaItl7ZiIQnWWsP99GTO/KflixkdfD87igkqpXo 1UGorCaUmLK8li4s39xnfjtrsTcOjZ3iXly1Axlz9SvA5hnARHSC1CYDrSOyHg== From: Luca Ceresoli Date: Thu, 06 Feb 2025 19:14:36 +0100 Subject: [PATCH v6 21/26] drm/bridge: add list of removed refcounted bridges MIME-Version: 1.0 Message-Id: <20250206-hotplug-drm-bridge-v6-21-9d6f2c9c3058@bootlin.com> References: <20250206-hotplug-drm-bridge-v6-0-9d6f2c9c3058@bootlin.com> In-Reply-To: <20250206-hotplug-drm-bridge-v6-0-9d6f2c9c3058@bootlin.com> To: Simona Vetter , Inki Dae , Jagan Teki , Marek Szyprowski , Catalin Marinas , Will Deacon , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Daniel Thompson , Andrzej Hajda , Jonathan Corbet , Sam Ravnborg , Boris Brezillon , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Jessica Zhang Cc: Paul Kocialkowski , Maxime Ripard , Dmitry Baryshkov , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Thomas Zimmermann , David Airlie , =?utf-8?q?Herv=C3=A9_Codina?= , Thomas Petazzoni , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Paul Kocialkowski , Luca Ceresoli X-Mailer: b4 0.14.2 X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvjedtkecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpefnuhgtrgcuvegvrhgvshholhhiuceolhhutggrrdgtvghrvghsohhlihessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnhepieeiuedvffetgfeuudelheeutefggfejieettdetteekueeuueeukeevvedvueevnecukfhppedvrgdtvdemieejtdemvddtvddtmegvrgdtudemhegrgedtmedvughfieemrgdulegvmedutgejgeenucevlhhushhtvghrufhiiigvpedukeenucfrrghrrghmpehinhgvthepvdgrtddvmeeijedtmedvtddvtdemvggrtddumeehrgegtdemvdgufheimegrudelvgemudgtjeegpdhhvghloheplgduvdejrddtrddurddungdpmhgrihhlfhhrohhmpehluhgtrgdrtggvrhgvshholhhisegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopeefkedprhgtphhtthhopegtrghtrghlihhnrdhmrghrihhnrghssegrrhhmrdgtohhmpdhrtghpthhtohepshdrhhgruhgvrhesphgvnhhguhhtrhhonhhigidruggvpdhrtghpthhtoheprghlvgigrghnughrvgdrsggvlhhlohhnihessghoohhtlhhinhdrtghom hdprhgtphhtthhopegtlhgruhguihhurdgsvgiinhgvrgesthhugihonhdruggvvhdprhgtphhtthhopehmrdhsiiihphhrohifshhkihesshgrmhhsuhhnghdrtghomhdprhgtphhtthhopegtohhrsggvtheslhifnhdrnhgvthdprhgtphhtthhopehsihhmohhnrgesfhhffihllhdrtghhpdhrtghpthhtohepughrihdquggvvhgvlheslhhishhtshdrfhhrvggvuggvshhkthhophdrohhrgh X-GND-Sasl: luca.ceresoli@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250206_101535_917612_3C0A7F44 X-CRM114-Status: GOOD ( 19.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- 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)