From: sashiko-bot@kernel.org
To: "Màxim Pedraza Padilla" <maximpedraza@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [RFC PATCH v2 1/2] drm/tilcdc: Implement state readout support
Date: Tue, 24 Nov 2026 14:49:59 +0000 [thread overview]
Message-ID: <sashiko-outbox-231373@kernel.org> (raw)
In-Reply-To: <20261124141908.443764-2-maximpedraza@gmail.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] drm/tilcdc: atomic commit failure on readout fb without custom
prepare_fb
- [High] drm/tilcdc: tilcdc_encoder_get_current_crtc() returns CRTC when
raster is off
- [High] drm/tilcdc: missing DRM atomic state readout headers and
symbols
- [Medium] drm/tilcdc: uninitialized stack mode and stale crtc_hskew in
readout
- [Medium] drm/tilcdc: probe error after tilcdc_crtc_install_state()
accesses unmapped MMIO
--
commit 971a5ab17852dfc54b7fed700c69635bf4fd3c19
Author: Màxim Pedraza Padilla <maximpedraza@gmail.com>
drm/tilcdc: Implement state readout support
This commit implements DRM atomic state readout for tilcdc to reconstruct
the initial KMS mode, CRTC state, and primary plane framebuffer from the
LCDC raster registers when the bootloader leaves the display active.
> diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
> index f619b7a6e70d9..7040172b1a0db 100644
> --- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
> +++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
[ ... ]
> @@ -711,10 +716,204 @@ static void tilcdc_crtc_hw_reset(struct drm_crtc *crtc)
[ ... ]
> +static int tilcdc_crtc_readout_state(struct drm_crtc *crtc,
> + struct drm_atomic_sro_state *state,
> + struct drm_crtc_state *crtc_state)
> +{
> + struct drm_device *dev = crtc->dev;
> + struct drm_display_mode adjusted = {}, mode;
> + int ret;
> +
> + pm_runtime_get_sync(dev->dev);
> +
> + /* Nothing to adopt unless the bootloader left the raster running. */
> + if (!(tilcdc_read(dev, LCDC_RASTER_CTRL_REG) & LCDC_RASTER_ENABLE))
> + goto out;
> +
> + ret = tilcdc_crtc_readout_mode(crtc, &adjusted);
> + if (ret)
> + goto err;
> +
> + /* Undo tilcdc_crtc_mode_fixup(). */
> + drm_mode_copy(&mode, &adjusted);
> + mode.hskew = 0;
> + mode.flags &= ~(DRM_MODE_FLAG_HSKEW | DRM_MODE_FLAG_NHSYNC |
> + DRM_MODE_FLAG_PHSYNC);
> + if (adjusted.flags & DRM_MODE_FLAG_PHSYNC)
> + mode.flags |= DRM_MODE_FLAG_NHSYNC;
> +
> + ret = drm_atomic_set_mode_for_crtc(crtc_state, &mode);
[Severity: Medium]
Does drm_mode_copy(&mode, &adjusted) leave mode.head uninitialized on the
stack?
drm_mode_copy() saves and restores dst->head, which is later read by
memcmp(&state->mode, mode, sizeof(*mode)) in drm_atomic_set_mode_for_crtc().
Using drm_mode_init(&mode, &adjusted) would zero mode.head for the
on-stack mode.
Also, tilcdc_crtc_readout_mode() calls drm_mode_set_crtcinfo(&adjusted, 0)
while hskew is hsw, so clearing mode.hskew = 0 afterwards leaves
mode.crtc_hskew set to hsw unless mode.crtc_hskew is cleared or
drm_mode_set_crtcinfo(&mode, 0) is called again.
[ ... ]
> +static void tilcdc_crtc_install_state(struct drm_crtc *crtc,
> + struct drm_crtc_state *crtc_state)
> +{
> + struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc);
> + struct drm_device *dev = crtc->dev;
> + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev);
> +
> + if (!crtc_state->active)
> + return;
> +
> + /*
> + * The display is already scanning out the bootloader's image. Do what
> + * tilcdc_crtc_enable() and tilcdc_crtc_set_mode() would have done,
> + * without touching the raster: keep the controller powered, enable its
> + * interrupts and fill in the software state derived from the mode. A
> + * commit that doesn't change the mode relies on it, since no modeset
> + * will update it: set_scanout() uses crtc->mode for the DMA ceiling.
> + */
> + pm_runtime_get_sync(dev->dev);
> +
> + mutex_lock(&tilcdc_crtc->enable_lock);
> +
> + drm_mode_copy(&crtc->mode, &crtc_state->mode);
> + drm_mode_copy(&crtc->hwmode, &crtc_state->adjusted_mode);
> + crtc->enabled = true;
> + tilcdc_crtc->hvtotal_us = tilcdc_mode_hvtotal(&crtc->hwmode);
> + tilcdc_crtc->lcd_fck_rate = clk_get_rate(priv->clk);
> + tilcdc_crtc->last_vblank = ktime_get();
> +
> + tilcdc_crtc_enable_irqs(dev);
> +
> + drm_calc_timestamping_constants(crtc, &crtc->hwmode);
> + drm_crtc_vblank_on(crtc);
> +
> + tilcdc_crtc->enabled = true;
> + mutex_unlock(&tilcdc_crtc->enable_lock);
> +}
[Severity: Medium]
What happens if drm_dev_register() fails in tilcdc_pdev_probe() after
tilcdc_crtc_install_state() has marked the CRTC enabled and taken a
runtime PM reference?
Before this change, drm_mode_config_reset() stopped the raster and left
tilcdc_crtc->enabled false during probe. With state readout adopting an
active CRTC during drm_mode_config_reset(), a failure in drm_dev_register()
jumps to stop_poll, which uninstalls the IRQ, disables runtime PM while
the CRTC's runtime PM reference is still held, and destroys priv->wq.
When devres then cleans up in reverse order, priv->mmio is unmapped before
the drmm action tilcdc_crtc_destroy() calls tilcdc_crtc_shutdown() ->
tilcdc_crtc_off(), accessing unmapped MMIO registers and flushing the
destroyed workqueue.
> diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c
> index 1d6c9a423a410..53658fc8b1b2e 100644
> --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c
> +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c
> @@ -12,6 +12,8 @@
>
> #include <drm/clients/drm_client_setup.h>
> #include <drm/drm_atomic_helper.h>
> +#include <drm/drm_atomic_state_readout.h>
> +#include <drm/drm_atomic_state_readout_helper.h>
> #include <drm/drm_debugfs.h>
> #include <drm/drm_drv.h>
> #include <drm/drm_fbdev_dma.h>
> @@ -75,6 +77,13 @@ static const struct drm_mode_config_funcs mode_config_funcs = {
> .fb_create = drm_gem_fb_create,
> .atomic_check = tilcdc_atomic_check,
> .atomic_commit = drm_atomic_helper_commit,
> + .atomic_sro_readout_state = drm_atomic_helper_sro_readout_state,
> + .hw_reset = drm_mode_config_helper_hw_reset,
> +};
> +
> +static const struct drm_mode_config_helper_funcs mode_config_helper_funcs = {
> + .atomic_sro_build_state = drm_atomic_helper_sro_build_state,
> + .atomic_sro_install_state = drm_atomic_helper_sro_install_state,
> };
[Severity: High]
Does this depend on an unmerged DRM atomic state readout series?
Neither drm/drm_atomic_state_readout.h nor
drm/drm_atomic_state_readout_helper.h exists in the tree, and the
atomic_sro_* callbacks, types, and helpers used across tilcdc_drv.c,
tilcdc_crtc.c, tilcdc_encoder.c, and tilcdc_plane.c are undeclared, so
CONFIG_DRM_TILCDC fails to build.
> diff --git a/drivers/gpu/drm/tilcdc/tilcdc_encoder.c b/drivers/gpu/drm/tilcdc/tilcdc_encoder.c
> index ac4b5beb2dd58..b3fe18f69f174 100644
> --- a/drivers/gpu/drm/tilcdc/tilcdc_encoder.c
> +++ b/drivers/gpu/drm/tilcdc/tilcdc_encoder.c
[ ... ]
> +/*
> + * State readout needs to know which CRTC drives this encoder so the connector
> + * can be tied back to it. tilcdc has a single CRTC, so return the one the
> + * encoder was made possible for.
> + */
> +static struct drm_crtc *
> +tilcdc_encoder_get_current_crtc(struct drm_encoder *encoder)
> +{
> + struct drm_crtc *crtc;
> +
> + drm_for_each_crtc(crtc, encoder->dev)
> + if (encoder->possible_crtcs == drm_crtc_mask(crtc))
> + return crtc;
> +
> + return NULL;
> +}
[Severity: High]
Should tilcdc_encoder_get_current_crtc() return NULL when LCDC_RASTER_ENABLE
is not set?
When the raster is disabled at boot or after a commit disables the CRTC,
tilcdc_crtc_readout_state() and tilcdc_plane_atomic_readout_state() read
out the CRTC and plane as disabled, while tilcdc_encoder_get_current_crtc()
still returns the CRTC. That links the connector and encoder to a CRTC
whose crtc_state->enable is false, producing an invalid atomic state and
failing post-commit state readout comparisons when the CRTC is disabled.
> diff --git a/drivers/gpu/drm/tilcdc/tilcdc_plane.c b/drivers/gpu/drm/tilcdc/tilcdc_plane.c
> index eb0a5562421fd..f710310cece20 100644
> --- a/drivers/gpu/drm/tilcdc/tilcdc_plane.c
> +++ b/drivers/gpu/drm/tilcdc/tilcdc_plane.c
[ ... ]
> + rfb = kzalloc_obj(*rfb);
> + if (!rfb) {
> + ret = -ENOMEM;
> + goto err;
> + }
> + rfb->dma_addr = tilcdc_read(dev, LCDC_DMA_FB_BASE_ADDR_0_REG);
> + fb = &rfb->base;
> + fb->dev = dev;
> + fb->format = info;
> + fb->width = w;
> + fb->height = h;
> + fb->pitches[0] = w * (drm_format_info_bpp(info, 0) / 8);
> + fb->offsets[0] = 0;
> +
> + ret = drm_framebuffer_init(dev, fb, &tilcdc_plane_readout_fb_funcs);
> + if (ret) {
> + kfree(rfb);
> + goto err;
> + }
[Severity: High]
Will atomic commits that keep the readout framebuffer fail in
drm_atomic_helper_prepare_planes()?
Because rfb has no backing GEM object, fb->obj[0] is NULL. tilcdc sets
DRIVER_GEM and leaves plane_helper_funcs.prepare_fb NULL, so any commit
that includes the primary plane without replacing rfb (such as disabling
and re-enabling the CRTC, or system suspend/resume) calls
drm_gem_plane_helper_prepare_fb() -> drm_gem_fb_get_obj(), which triggers
drm_WARN_ON_ONCE(dev, !fb->obj[plane]) and fails the commit with -EINVAL
before set_scanout() is reached.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124141908.443764-1-maximpedraza@gmail.com?part=1
next prev parent reply other threads:[~2026-11-24 14:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 14:19 [RFC PATCH v2 0/2] drm/tilcdc: Implement state readout Màxim Pedraza Padilla
2026-11-24 14:19 ` [RFC PATCH v2 1/2] drm/tilcdc: Implement state readout support Màxim Pedraza Padilla
2026-11-24 14:49 ` sashiko-bot [this message]
2026-11-24 14:19 ` [RFC PATCH v2 2/2] drm/panel: simple: Keep the enable GPIO as left by the bootloader Màxim Pedraza Padilla
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=sashiko-outbox-231373@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=maximpedraza@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/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