From patchwork Mon Dec 16 16:40:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 13910038 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 BCF9BE77183 for ; Mon, 16 Dec 2024 16:41:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E844210E611; Mon, 16 Dec 2024 16:41:11 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="cE4GTZU3"; dkim-atps=neutral Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by gabe.freedesktop.org (Postfix) with ESMTPS id CF51B8926F for ; Mon, 16 Dec 2024 16:41:10 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id AEA09E0005; Mon, 16 Dec 2024 16:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1734367269; 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=lEuh5s/boyvsj4t0oSTEvebQYcCGEo5tXwMo58H8NSk=; b=cE4GTZU3uqWFWv29TL9UYBSslHc1DczAnFW1lIsv4PL6n1dGO9LipTmMQp6T8BocMyeGjP WH/bbU0LhymdJymJ3j/7nshI3T+mk6+eUFN56UYgkBeM1RzB+w6kzCnWifVlVZgdKzCWhY 5K4sY3o7QljE0noo+qCsi/QCzPImVBnaTvzlfpvOLh6L5cONxx2z8Mtuzl6gXQnuNaT4tj L/ZeNooXLPgrXypfFrTCsu41IyOHaA9h8Qn3lqdgj8KPb+gtuz/lMd+z4BORdKv2/sB3vs sFOVAjOMgwp9/Y1pfpaB2NXpdRzrvsWE/WFqezg1hZKUE19KCt5FlaV7ATRbuQ== From: Luca Ceresoli Date: Mon, 16 Dec 2024 17:40:48 +0100 Subject: [PATCH RESEND v3 1/4] drm/drm_mode_object: fix typo in kerneldoc MIME-Version: 1.0 Message-Id: <20241216-drm-small-improvements-v3-1-78bbc95ac776@bootlin.com> References: <20241216-drm-small-improvements-v3-0-78bbc95ac776@bootlin.com> In-Reply-To: <20241216-drm-small-improvements-v3-0-78bbc95ac776@bootlin.com> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter Cc: Dmitry Baryshkov , Jani Nikula , Thomas Petazzoni , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Luca Ceresoli , Louis Chauvet X-Mailer: b4 0.14.2 X-GND-Sasl: luca.ceresoli@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Remove unintended extra word. Reviewed-by: Dmitry Baryshkov Signed-off-by: Luca Ceresoli Acked-by: Louis Chauvet --- include/drm/drm_mode_object.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/drm/drm_mode_object.h b/include/drm/drm_mode_object.h index 08d7a7f0188fea79e2d8ad5ee6cc5044300f1a26..c68edbd126d04d51221f50aa2b4166475543b59f 100644 --- a/include/drm/drm_mode_object.h +++ b/include/drm/drm_mode_object.h @@ -35,7 +35,7 @@ struct drm_file; * @id: userspace visible identifier * @type: type of the object, one of DRM_MODE_OBJECT\_\* * @properties: properties attached to this object, including values - * @refcount: reference count for objects which with dynamic lifetime + * @refcount: reference count for objects with dynamic lifetime * @free_cb: free function callback, only set for objects with dynamic lifetime * * Base structure for modeset objects visible to userspace. Objects can be From patchwork Mon Dec 16 16:40:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 13910039 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 7C1B7E77180 for ; Mon, 16 Dec 2024 16:41:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F041010E60F; Mon, 16 Dec 2024 16:41:15 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="bFHND2C2"; dkim-atps=neutral Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by gabe.freedesktop.org (Postfix) with ESMTPS id DEF3310E60F for ; Mon, 16 Dec 2024 16:41:11 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id B4AC9E000E; Mon, 16 Dec 2024 16:41:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1734367270; 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=Gr5nT2Jnw+/2OVk2gGwP/gOTe4r8NyAUC5u+F+sceZw=; b=bFHND2C2mCjVfFmvgtYTrE9l4QjIlqVzSC3EiYV3vZlKWQfkpURtHJXHOTt8iFvYDSwM9s T8tVET48Pp+6JWLGs7lzo5AwyYT5ylSf37dVX9rkQSPxRvruQzFxFV43KFzrdcwtgN4N4l vdrhgrh72oElFMmtukaD69YAMIUsmhaYq9jBOtF4IVpe+2MLwVteWAgyoRTmKI/c3uGDAT 4u479LHnpXjuvyG1bQtS1tKqZ7x4Mh4PgqfO0J2DMo4LtkltZzILNF/vetjVblQMpOWV8g umsyCPZyP9wgqmtj9Hb8FkrWwdVQaxifnSJHfPGOF44YmpYKsxyU0rx4jKdTYA== From: Luca Ceresoli Date: Mon, 16 Dec 2024 17:40:49 +0100 Subject: [PATCH RESEND v3 2/4] drm/atomic-helper: improve CRTC enabled/connectors mismatch logging message MIME-Version: 1.0 Message-Id: <20241216-drm-small-improvements-v3-2-78bbc95ac776@bootlin.com> References: <20241216-drm-small-improvements-v3-0-78bbc95ac776@bootlin.com> In-Reply-To: <20241216-drm-small-improvements-v3-0-78bbc95ac776@bootlin.com> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter Cc: Dmitry Baryshkov , Jani Nikula , Thomas Petazzoni , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Luca Ceresoli , Louis Chauvet X-Mailer: b4 0.14.2 X-GND-Sasl: luca.ceresoli@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This message reports a mismatch between new_crtc_state->enable and has_connectors, which should be either both true or both false. However it does not mention which one is true and which is false, which can be useful for debugging. Add the value of both avriables to the log message. Reviewed-by: Dmitry Baryshkov Signed-off-by: Luca Ceresoli Acked-by: Louis Chauvet --- drivers/gpu/drm/drm_atomic_helper.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index 43cdf39019a44537794cc5a519d139b0cb77073c..3c3bdef9bcf3c4ffcd861744f6607f317ab0c041 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -666,8 +666,9 @@ drm_atomic_helper_check_modeset(struct drm_device *dev, } if (new_crtc_state->enable != has_connectors) { - drm_dbg_atomic(dev, "[CRTC:%d:%s] enabled/connectors mismatch\n", - crtc->base.id, crtc->name); + drm_dbg_atomic(dev, "[CRTC:%d:%s] enabled/connectors mismatch (%d/%d)\n", + crtc->base.id, crtc->name, + new_crtc_state->enable, has_connectors); return -EINVAL; } From patchwork Mon Dec 16 16:40:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 13910040 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 868DAE7717F for ; Mon, 16 Dec 2024 16:41:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E510410E6F8; Mon, 16 Dec 2024 16:41:16 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="TfXKhGw1"; dkim-atps=neutral Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by gabe.freedesktop.org (Postfix) with ESMTPS id 537B610E60F for ; Mon, 16 Dec 2024 16:41:13 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id CB879E0003; Mon, 16 Dec 2024 16:41:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1734367271; 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=J90J1NyXaKoXccZe2X72ycchhXTtGFZ2PH6GpQkBJsQ=; b=TfXKhGw1Xu1kMTIPHWCUs8aLwUWzuTKGvJ4j91Qfd6r0hlmwy9jqbDGUa3nK9YjKpnJnwP cK53r5KYTSI9yx8tH/zjuFZhBWgUTpbaJX8x06dQO4fSlDokEEimr5TcZHmb5krbdJ60hL FMAd7Z8uS7G/ROKDCzU156r1kC6R8C231T1QzABHhYsQA1nX8PrulSaGWMogyY1wzibSjU bsqZCDq+mHrv4t5A5dfbxYfHsK4DAh9lOKJ4L7A9IPeve9fYNtC6WAmruHJSg/a8cPNZhk 8lp0QQaqPShbNAC1lTe4zRpFQxtsqtF9rE8Ajky47TvAs297yqgUvcnumi+Jgw== From: Luca Ceresoli Date: Mon, 16 Dec 2024 17:40:50 +0100 Subject: [PATCH RESEND v3 3/4] drm/mode_object: add drm_mode_object_read_refcount() MIME-Version: 1.0 Message-Id: <20241216-drm-small-improvements-v3-3-78bbc95ac776@bootlin.com> References: <20241216-drm-small-improvements-v3-0-78bbc95ac776@bootlin.com> In-Reply-To: <20241216-drm-small-improvements-v3-0-78bbc95ac776@bootlin.com> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter Cc: Dmitry Baryshkov , Jani Nikula , Thomas Petazzoni , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Luca Ceresoli , Louis Chauvet X-Mailer: b4 0.14.2 X-GND-Sasl: luca.ceresoli@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add a wrapper to kref_read() just like the ones already in place for kref_get() and kref_put(). This will be used for sanity checks on object lifetime. Signed-off-by: Luca Ceresoli Acked-by: Louis Chauvet --- Changed in v3: * use conventions for 'Returns' doc syntax * ditch DRM_DEBUG() and as a consequence rework and simplify the entire function * fix function name in kerneldoc --- drivers/gpu/drm/drm_mode_object.c | 17 +++++++++++++++++ include/drm/drm_mode_object.h | 1 + 2 files changed, 18 insertions(+) diff --git a/drivers/gpu/drm/drm_mode_object.c b/drivers/gpu/drm/drm_mode_object.c index df4cc0e8e263d5887a799cf1a61d998234be7158..b9a16aceb926782eb033434eb6967ce9fd2e94f7 100644 --- a/drivers/gpu/drm/drm_mode_object.c +++ b/drivers/gpu/drm/drm_mode_object.c @@ -217,6 +217,23 @@ void drm_mode_object_get(struct drm_mode_object *obj) } EXPORT_SYMBOL(drm_mode_object_get); +/** + * drm_mode_object_read_refcount - read the refcount for a mode object + * @obj: DRM mode object + * + * Returns: + * The current object refcount if it is a refcounted modeset object, or 0 + * for any other object. + */ +unsigned int drm_mode_object_read_refcount(struct drm_mode_object *obj) +{ + if (obj->free_cb) + return kref_read(&obj->refcount); + + return 0; +} +EXPORT_SYMBOL(drm_mode_object_read_refcount); + /** * drm_object_attach_property - attach a property to a modeset object * @obj: drm modeset object diff --git a/include/drm/drm_mode_object.h b/include/drm/drm_mode_object.h index c68edbd126d04d51221f50aa2b4166475543b59f..3d2c739e703888bf4520c61594d480f128d50e56 100644 --- a/include/drm/drm_mode_object.h +++ b/include/drm/drm_mode_object.h @@ -123,6 +123,7 @@ struct drm_mode_object *drm_mode_object_find(struct drm_device *dev, uint32_t id, uint32_t type); void drm_mode_object_get(struct drm_mode_object *obj); void drm_mode_object_put(struct drm_mode_object *obj); +unsigned int drm_mode_object_read_refcount(struct drm_mode_object *obj); int drm_object_property_set_value(struct drm_mode_object *obj, struct drm_property *property, From patchwork Mon Dec 16 16:40:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 13910041 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 94763E7717F for ; Mon, 16 Dec 2024 16:41:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2378D10E6F9; Mon, 16 Dec 2024 16:41:21 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="eyDGFgHV"; dkim-atps=neutral Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0A95510E60F for ; Mon, 16 Dec 2024 16:41:13 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id DC324E000F; Mon, 16 Dec 2024 16:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1734367272; 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=qW3wdr4EeYIZ0MLaRPPuH3cK65j246cHF8/ZPxNc2Bo=; b=eyDGFgHVeEDhExDDMXCSOSgsB8v/VSm2hPy3ubebFzBaHgkY9OCIVc9nnBg43U2bRdhdvW ss9r9o+GQbM6f1QKp6acKn032ygY1oWgbk519MEvab2avDyHYqC3LlfOiM2ClxaZiUdHXf tZhTbUkPSbyf80lmr4Jd9HImCi3J6kdtpv/tEfVEOHd1mCFH/9Hcu3K3axOY2bSceJ9ujy OBFut0yli1R9jA6DDRwLg76sQpgCE7fPL7Zclp3m83/ZQcvhntvDhXmrVxrsA7gkqD/B+Z jGkIKakyPXSRc80NEp8IcCix2arnsXdmcdn0p3jEPCRkGE9aJxtSdb6X+KkTjA== From: Luca Ceresoli Date: Mon, 16 Dec 2024 17:40:51 +0100 Subject: [PATCH RESEND v3 4/4] drm/connector: warn when cleaning up a refcounted connector MIME-Version: 1.0 Message-Id: <20241216-drm-small-improvements-v3-4-78bbc95ac776@bootlin.com> References: <20241216-drm-small-improvements-v3-0-78bbc95ac776@bootlin.com> In-Reply-To: <20241216-drm-small-improvements-v3-0-78bbc95ac776@bootlin.com> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter Cc: Dmitry Baryshkov , Jani Nikula , Thomas Petazzoni , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Luca Ceresoli , Louis Chauvet X-Mailer: b4 0.14.2 X-GND-Sasl: luca.ceresoli@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Calling drm_connector_cleanup() should only be done via the free_cb => .destroy path, which cleans up the struct drm_connector only when the refcount drops to zero. A cleanup done with a refcount higher than 0 can result from buggy code, e.g. by doing cleanup directly in the drivers teardown code. Serious trouble can happen if this happens, so warn about it. Reviewed-by: Dmitry Baryshkov Signed-off-by: Luca Ceresoli Acked-by: Louis Chauvet --- drivers/gpu/drm/drm_connector.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index fc35f47e2849ed6786d6223ac9c69e1c359fc648..e0bf9c490af43055de4caaee1580a4befbd608c5 100644 --- a/drivers/gpu/drm/drm_connector.c +++ b/drivers/gpu/drm/drm_connector.c @@ -624,6 +624,12 @@ void drm_connector_cleanup(struct drm_connector *connector) struct drm_device *dev = connector->dev; struct drm_display_mode *mode, *t; + /* + * Cleanup must happen when the last ref is put, via the + * drm_connector_free() callback. + */ + WARN_ON(drm_mode_object_read_refcount(&connector->base) != 0); + /* The connector should have been removed from userspace long before * it is finally destroyed. */