From mboxrd@z Thu Jan 1 00:00:00 1970 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 68DB6106ACCD for ; Thu, 12 Mar 2026 17:30:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BF0B010EA7C; Thu, 12 Mar 2026 17:30:31 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="eOcN8kbq"; dkim-atps=neutral Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7954110EA7C for ; Thu, 12 Mar 2026 17:30:30 +0000 (UTC) Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id EDC981A2E0C; Thu, 12 Mar 2026 17:30:28 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id BEEA16001B; Thu, 12 Mar 2026 17:30:28 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 8B63F103686EE; Thu, 12 Mar 2026 18:30:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1773336628; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=ojA5kgEFX5C9rF7JLxEzCUAGdAQqEGLeKAjjT9Y7YhE=; b=eOcN8kbqOLqamC+20v9ynFsBO1M/Ja3dkiV5DndS47knCL5qs5Z7mjR+4cNQSWcPgAdFqs FRaLIXoDcJQIpGiHXJyYL6Ak1Al/JWYKC8fCMPNRMDyXcy0CozCSov6mVN0EImqLGrS8d2 oKXhMS7oRQDnI9r6ZmcbAimRl4C2tiXnRlulQe7V90XT1oSvkas3SsOcSiRVuOEKZaYoFA Xe3+PDe6qny8BzWr8RV1BVzM79dUDJaNPezA3Fa9xEaPbb/ilfO5XtkbZkHqO/fun+TGXq /lwB+B84HbEHPu4QX5xtgzWIwWvW3B6wXnxbn+XyUoXqOvdumhZwCnB5QJ5IBw== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 12 Mar 2026 18:30:22 +0100 Message-Id: Cc: "Marco Felsch" , , To: "Liu Ying" , "Andrzej Hajda" , "Neil Armstrong" , "Robert Foss" , "Laurent Pinchart" , "Jonas Karlman" , "Jernej Skrabec" , "Maarten Lankhorst" , "Maxime Ripard" , "Thomas Zimmermann" , "David Airlie" , "Simona Vetter" From: "Luca Ceresoli" Subject: Re: [PATCH] drm/bridge: Fix refcount shown via debugfs for encoder_bridges_show() X-Mailer: aerc 0.20.1 References: <20260312-drm-misc-next-2026-03-05-fix-encoder-bridges-refcount-v1-1-b9ba3d844732@nxp.com> In-Reply-To: <20260312-drm-misc-next-2026-03-05-fix-encoder-bridges-refcount-v1-1-b9ba3d844732@nxp.com> X-Last-TLS-Session-Version: TLSv1.3 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" Hello Liu, Maxime, On Thu Mar 12, 2026 at 7:05 AM CET, Liu Ying wrote: > A typical bridge refcount value is 3 after a bridge chain is formed: > - devm_drm_bridge_alloc() initializes the refcount value to be 1. > - drm_bridge_add() gets an additional reference hence 2. > - drm_bridge_attach() gets the third reference hence 3. > > This typical refcount value aligns with allbridges_show()'s behaviour. > However, since encoder_bridges_show() uses > drm_for_each_bridge_in_chain_scoped() to automatically get/put the > bridge reference while iterating, a bogus reference is accidentally > got when showing the wrong typical refcount value as 4 to users via > debugfs. Fix this by caching the refcount value returned from > kref_read() while iterating and explicitly decreasing the cached > refcount value by 1 before showing it to users. Good point, indeed the refcount shown by /dri//encoder-0/bridges is by one unit higher than the one shown in /dri/bridges. I understand it's puzzling from a debugfs user point of view. As you noticed, this is because the _scoped loop holds an extra ref on the current bridge. For other reasons I proposed a mutex for stronger protection around the bridge chain [v2]. With the mutex the extra ref is redundant, so in [v2] the extra ref is removed, thus making your patch unneeded. However Maxime asked to keep the extra ref, and so my latest iteration [v4] still has the extra ref. That series is still on the mailing list, we are still in time to rediscuss it. @Maxime: based on the issue Liu is trying to work around, do you think it would make sense to go back to the initial approach for that series? I.e. drm_for_each_bridge_in_chain_scoped() grabs the chain lock, which is a superset of the per-bridge refcount, and thus the refcount can be dropped? This would remove the debugfs issue, slightly simplify drm_for_each_bridge_in_chain_scoped(), and introduce no new issues AFAIK. [v2] https://lore.kernel.org/all/20251003-drm-bridge-alloc-encoder-chain-mu= tex-v2-4-78bf61580a06@bootlin.com/ [v4] https://lore.kernel.org/all/20260113-drm-bridge-alloc-encoder-chain-mu= tex-v4-4-60f3135adc45@bootlin.com/ Luca -- Luca Ceresoli, Bootlin Embedded Linux and Kernel engineering https://bootlin.com