From: "Maíra Canal" <mcanal@igalia.com>
To: Henry Zhang <henryzhang62@gmail.com>,
mripard@kernel.org, dave.stevenson@raspberrypi.com
Cc: kernel-list@raspberrypi.com, maarten.lankhorst@linux.intel.com,
tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm/vc4: dsi: Allocate the encoder per DRM device
Date: Wed, 18 Nov 2026 11:00:43 -0300 [thread overview]
Message-ID: <bd7812ad-3eb6-49a1-bd22-b4252c09ac00@igalia.com> (raw)
In-Reply-To: <20261117205902.1293962-1-henryzhang62@gmail.com>
Hi Henry,
On 17/11/26 17:59, Henry Zhang wrote:
> The DSI encoder is embedded in struct vc4_dsi, which lives as long as
> the DSI platform device, but it is initialised with drmm_encoder_init()
> and so is only cleaned up when the DRM device is released. The DRM
> device can outlive the unbind of the vc4 components: unloading the DSI
> panel driver detaches from the DSI host, which deletes the DSI component
> and unbinds the whole vc4 DRM device, but a compositor that keeps the
> DRM device open keeps it alive.
>
> If the panel driver is loaded again before that, the new DRM device
> binds the DSI component and calls drmm_encoder_init() on the encoder
> that is still on the old DRM device's encoder list. The old device's
> release later cleans it up from under the new one. On a Raspberry Pi 4
> with a 6.18-based kernel, closing the old DRM device then gave:
>
> WARNING: drivers/gpu/drm/drm_encoder.c:214 at drmm_encoder_alloc_release+0x30/0x40 [drm]
> Call trace: drmm_encoder_alloc_release <- drm_dev_put <- drm_gem_dmabuf_release <- __fput
> Unable to handle kernel NULL pointer dereference at virtual address 0000000000000008
> pc : drm_mode_config_cleanup+0x5c/0x2f0 [drm]
> Call trace: drm_mode_config_cleanup <- drm_managed_release <- drm_dev_put
Could you reproduce this issue on top of drm-misc-next? The downstream
kernel differs from upstream in several ways. If you are able to
reproduce it, could you please provide the full call trace?
Best regards,
- Maíra
>
> Allocate the encoder in bind with drmm_encoder_alloc(), so each DRM
> device has its own and releases only its own. The DSI bridge is still
> shared: while the old DRM device holds it, drm_bridge_attach() in the
> new bind fails with -EBUSY, so binding again before the old DRM device
> is released now fails cleanly instead of corrupting both devices.
>
> The analysis, this change and this description were prepared with the
> help of an AI coding assistant (Claude Code).
>
> Fixes: 6f0ca506c30e ("drm/vc4: dsi: Switch to DRM-managed encoder initialization")
> Signed-off-by: Henry Zhang <henryzhang62@gmail.com>
> ---
> Testing:
>
> - On this base (drm-misc-next 467ac0b56aeb): compile-tested only,
> arm64 defconfig with DRM_VC4=m, W=1, no new warnings.
>
> - A backport to a downstream Raspberry Pi 6.18.34 kernel, on a
> Raspberry Pi 4 with an out-of-tree modular DSI panel driver: with the
> compositor stopped and a process holding /dev/dri/card1 open, unload
> the panel driver and load it again. The bind now fails cleanly:
>
> vc4-drm gpu: failed to bind fe700000.dsi (ops vc4_dsi_ops [vc4]): -16
> vc4-drm gpu: adev bind failed: -16
>
> the panel probe fails with -16, and there is no warning or oops,
> also when the holder then closes the old DRM device. Unloading and
> loading the panel driver again after that brings back the display
> and the compositor. Without the change, the same kernel gave the
> warning and oops above. The backport differs from this patch in two
> ways: that kernel still gets the panel bridge with
> drmm_of_get_bridge(), which has a use-after-free of its own in this
> sequence, so the test kernel used devm_drm_of_get_bridge() instead
> (not needed here, where the panel bridge is refcounted); and a
> downstream DSI restart worker that used the embedded encoder now
> follows a pointer to the current one.
>
> The -EBUSY is final: the panel probe is not retried when the old DRM
> device goes away, so the panel driver has to be loaded again. Would you
> prefer the DSI host to wait for the old DRM device to be released
> before adding its component again, or a bridge allocated per bind?
>
> Not addressed: a connector probe that is already running when the
> panel is removed can still call into the panel driver.
>
> This applies to drm-misc-next on its own. It also applies on top of my
> "drm/vc4: dsi: Serialize register writes through the DMA workaround",
> and it does not touch the code changed by my vc4 DSI series
> <20261028164539.3471833-1-henryzhang62@gmail.com>.
>
> Tools: Claude Code (an AI coding assistant) analysed the crash logs and
> the vc4/DRM lifetimes, located the introducing commit, wrote the change
> and this description, built and checkpatch-checked it, and ran the
> backport test on the board, at my request.
>
> drivers/gpu/drm/vc4/vc4_dsi.c | 35 +++++++++++++++++++++++------------
> 1 file changed, 23 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c
> index ec008f766..5bd8f579b 100644
> --- a/drivers/gpu/drm/vc4/vc4_dsi.c
> +++ b/drivers/gpu/drm/vc4/vc4_dsi.c
> @@ -546,9 +546,18 @@ struct vc4_dsi_variant {
>
> };
>
> +/*
> + * The encoder of one DRM device. The DRM device can outlive the unbind of
> + * this component, so a later bind must not reuse the encoder of an earlier
> + * one: allocate one per bind, managed by the DRM device.
> + */
> +struct vc4_dsi_encoder {
> + struct vc4_encoder base;
> + struct vc4_dsi *dsi;
> +};
> +
> /* General DSI hardware state. */
> struct vc4_dsi {
> - struct vc4_encoder encoder;
> struct mipi_dsi_host dsi_host;
>
> struct platform_device *pdev;
> @@ -601,7 +610,7 @@ struct vc4_dsi {
> container_of_const(host, struct vc4_dsi, dsi_host)
>
> #define to_vc4_dsi(_encoder) \
> - container_of_const(_encoder, struct vc4_dsi, encoder.base)
> + (container_of_const(_encoder, struct vc4_dsi_encoder, base.base)->dsi)
>
> #define bridge_to_vc4_dsi(_bridge) \
> container_of_const(_bridge, struct vc4_dsi, bridge)
> @@ -1626,7 +1635,8 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)
> struct platform_device *pdev = to_platform_device(dev);
> struct drm_device *drm = dev_get_drvdata(master);
> struct vc4_dsi *dsi = dev_get_drvdata(dev);
> - struct drm_encoder *encoder = &dsi->encoder.base;
> + struct vc4_dsi_encoder *dsi_encoder;
> + struct drm_encoder *encoder;
> int ret;
>
> drm_bridge_get(&dsi->bridge);
> @@ -1637,9 +1647,6 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)
>
> dsi->variant = of_device_get_match_data(dev);
>
> - dsi->encoder.type = dsi->variant->port ?
> - VC4_ENCODER_TYPE_DSI1 : VC4_ENCODER_TYPE_DSI0;
> -
> dsi->regs = vc4_ioremap_regs(pdev, 0);
> if (IS_ERR(dsi->regs))
> return PTR_ERR(dsi->regs);
> @@ -1758,12 +1765,16 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)
> if (ret)
> return ret;
>
> - ret = drmm_encoder_init(drm, encoder,
> - &vc4_dsi_encoder_funcs,
> - DRM_MODE_ENCODER_DSI,
> - NULL);
> - if (ret)
> - return ret;
> + dsi_encoder = drmm_encoder_alloc(drm, struct vc4_dsi_encoder, base.base,
> + &vc4_dsi_encoder_funcs,
> + DRM_MODE_ENCODER_DSI, NULL);
> + if (IS_ERR(dsi_encoder))
> + return PTR_ERR(dsi_encoder);
> +
> + dsi_encoder->dsi = dsi;
> + dsi_encoder->base.type = dsi->variant->port ?
> + VC4_ENCODER_TYPE_DSI1 : VC4_ENCODER_TYPE_DSI0;
> + encoder = &dsi_encoder->base.base;
>
> ret = devm_pm_runtime_enable(dev);
> if (ret)
>
> base-commit: 467ac0b56aebc804360f276feffbc9032c265a6e
prev parent reply other threads:[~2026-11-18 14:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 20:59 Henry Zhang
2026-11-18 10:09 ` Maxime Ripard
2026-11-18 14:00 ` Maíra Canal [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bd7812ad-3eb6-49a1-bd22-b4252c09ac00@igalia.com \
--to=mcanal@igalia.com \
--cc=airlied@gmail.com \
--cc=dave.stevenson@raspberrypi.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=henryzhang62@gmail.com \
--cc=kernel-list@raspberrypi.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®