Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Cody Kang" <codykang.hk@gmail.com>
Cc: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,
	linux-phy@lists.infradead.org, linux-clk@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org, vkoul@kernel.org,
	neil.armstrong@linaro.org, olteanv@gmail.com
Subject: Re: [PATCH v4 08/16] drm/spacemit: add Saturn DPU hardware backend
Date: Sun, 29 Nov 2026 12:49:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-239607@kernel.org> (raw)
In-Reply-To: <20261129-k3-display-v4-8-ce6cf7988202@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/spacemit: unmasked IRQ dispatch and early flip event in
  spacemit_dpu_online_isr()
- [Medium] drm/spacemit: stale underrun IRQ and ur_mask_armed race in
  saturn_hee_cfg_ready()
- [Medium] drm/spacemit: race on cfg_rdy_timer and INT_CFG_RDY in
  spacemit_dpu_run()
--

commit 6da7eab6a7dc744a64994fe44a0926021ae9c800
Author: Cody Kang <codykang@vsit.ai>

drm/spacemit: add Saturn DPU hardware backend

This commit adds register-level programming for the SpacemiT Saturn DPU
hardware backend, covering clock setup, timing generator and composer
programming, RDMA line-buffer sizing, and interrupt handling.

> diff --git a/drivers/gpu/drm/spacemit/dpu/dpu_saturn.c b/drivers/gpu/drm/spacemit/dpu/dpu_saturn.c
> new file mode 100644
> index 0000000000000..927082c49bfd1
> --- /dev/null
> +++ b/drivers/gpu/drm/spacemit/dpu/dpu_saturn.c
[ ... ]
> +void spacemit_cfg_rdy_timer_handler(struct timer_list *t)
> +{
> +	struct spacemit_crtc *a_crtc = timer_container_of(a_crtc, t,
> +							  cfg_rdy_timer);
> +
> +	drm_err_ratelimited(a_crtc->crtc.dev, "CFG_RDY handshake timeout\n");
> +	/* A CFG_RDY that still comes belongs to no commit any more. */
> +	saturn_hee_enable_irq(a_crtc, INT_CFG_RDY, false);
> +	spacemit_dpu_complete_event(a_crtc);
> +}
[ ... ]
> +/* Returns false when none of the pending status bits was this CRTC's. */
> +bool spacemit_dpu_online_isr(struct spacemit_crtc *a_crtc)
> +{
> +	u32 irq_raw, irq_bit, irq_ur_bit, handled;
> +	struct spacemit_drm_private *priv = spacemit_drm_priv(a_crtc->crtc.dev);
> +	struct spacemit_hw_device *hwdev = priv->hwdev;
> +
> +	irq_raw = saturn_hee_get_int_sts(hwdev);
> +	irq_bit = saturn_hee_get_irq_bit(INT_UNDERRUN);
> +	irq_ur_bit = irq_raw & irq_bit;
> +	handled = irq_ur_bit;
> +	if (irq_ur_bit && !a_crtc->ur_reported) {
> +		saturn_hee_clr_int_sts(a_crtc, irq_ur_bit);
> +		drm_err_ratelimited(a_crtc->crtc.dev, "underrun\n");
> +		a_crtc->ur_reported = true;
> +	}
> +	irq_bit = saturn_hee_get_irq_bit(INT_CFG_RDY);
> +	if (irq_raw & irq_bit) {
> +		saturn_hee_clr_int_sts(a_crtc, irq_bit);
> +		timer_delete(&a_crtc->cfg_rdy_timer);
> +		a_crtc->ur_reported = false;
> +		saturn_hee_enable_irq(a_crtc, INT_CFG_RDY, false);
> +		handled |= irq_bit;
> +
> +		/* The lists are taken: the next vblank completes the commit. */
> +		spin_lock(&a_crtc->crtc.dev->event_lock);
> +		if (a_crtc->event) {
> +			drm_crtc_arm_vblank_event(&a_crtc->crtc, a_crtc->event);
> +			a_crtc->event = NULL;
> +		}
> +		spin_unlock(&a_crtc->crtc.dev->event_lock);
> +	}
> +	irq_bit = saturn_hee_get_irq_bit(INT_VSYNC);
> +	if (irq_raw & irq_bit) {
> +		saturn_hee_clr_int_sts(a_crtc, irq_bit);
> +		drm_crtc_handle_vblank(&a_crtc->crtc);
> +		handled |= irq_bit;
> +	}

[Severity: High]
Can spacemit_dpu_online_isr() complete a_crtc->event one frame early and
dispatch masked interrupts?

saturn_hee_get_int_sts() reads raw DPU_ONLINE_IRQ_STS bits without masking
against DPU_ONLINE_IRQ_MSK, even though status bits latch while masked.
Because INT_CFG_RDY is handled before INT_VSYNC in the same ISR pass, when
both bits are set in irq_raw, the INT_CFG_RDY branch calls
drm_crtc_arm_vblank_event() for current_vblank + 1 and the INT_VSYNC
branch immediately calls drm_crtc_handle_vblank(), firing the flip event
on the same interrupt instead of the next vblank.  This unblocks
drm_atomic_helper_wait_for_flip_done() early, allowing the next commit to
overwrite the active command-list slot and unmap the old framebuffer while
it is still scanning out.

> +	irq_bit = saturn_hee_get_irq_bit(INT_REST) | irq_ur_bit;
> +	if (irq_raw & irq_bit) {
> +		saturn_hee_clr_int_sts(a_crtc, irq_bit);
> +		handled |= irq_raw & irq_bit;
> +	}
> +
> +	return handled;
> +}
> +
> +void spacemit_dpu_run(struct drm_crtc *crtc, struct drm_atomic_commit *state)
> +{
> +	struct drm_crtc_state *crtc_state =
> +			drm_atomic_get_new_crtc_state(state, crtc);
> +	struct spacemit_crtc *a_crtc = to_spacemit_crtc(crtc);
> +	struct spacemit_drm_private *priv = spacemit_drm_priv(a_crtc->crtc.dev);
> +	struct spacemit_hw_device *hwdev = priv->hwdev;
> +
> +	saturn_hee_conf_dpuctrl(crtc, state);
> +
> +	/* flush all config register writes before CFG_RDY is raised */
> +	mb();
> +
> +	/* Ack first: one left by a commit that timed out is not this one's. */
> +	saturn_hee_clr_int_sts(a_crtc, saturn_hee_get_irq_bit(INT_CFG_RDY));
> +	saturn_hee_enable_irq(a_crtc, INT_CFG_RDY, true);
> +
> +	mod_timer(&a_crtc->cfg_rdy_timer,
> +		  jiffies + msecs_to_jiffies(SATURN_CFG_RDY_TIMEOUT_MS));
> +	saturn_hee_cfg_ready(a_crtc, hwdev);

[Severity: Medium]
Can an in-flight spacemit_cfg_rdy_timer_handler() or a late INT_CFG_RDY
from a timed-out commit race with spacemit_dpu_run()?

CPU0 (<softirq>)                  CPU1
spacemit_cfg_rdy_timer_handler()
  drm_err_ratelimited(...)
                                  <hardirq>
                                  spacemit_dpu_online_isr()
                                    timer_delete(&a_crtc->cfg_rdy_timer)
                                    drm_crtc_arm_vblank_event(...)
                                    drm_crtc_handle_vblank(...)
                                  spacemit_crtc_atomic_flush()
                                    a_crtc->event = ...
                                    spacemit_dpu_run()
                                      saturn_hee_enable_irq(..., true)
  saturn_hee_enable_irq(..., false)
  spacemit_dpu_complete_event(a_crtc)  <-- completes new commit's event

timer_delete() in spacemit_dpu_online_isr() does not wait for a running
timer callback, so spacemit_cfg_rdy_timer_handler() can mask the next
commit's INT_CFG_RDY and complete its a_crtc->event before hardware
consumes its command lists.  In addition, spacemit_dpu_run() unmasks
INT_CFG_RDY before mod_timer() and saturn_hee_cfg_ready(), so a late
CFG_RDY from a prior timed-out commit firing in that window deletes the
timer before it is armed, masks INT_CFG_RDY, and leaves cfg_rdy_timer
running with INT_CFG_RDY disabled.

> diff --git a/drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c b/drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c
> new file mode 100644
> index 0000000000000..209845f635c93
> --- /dev/null
> +++ b/drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c
[ ... ]
> +void saturn_hee_cfg_ready(struct spacemit_crtc *a_crtc,
> +			  struct spacemit_hw_device *hwdev)
> +{
> +	u32 base = DPU_SCENE_CTL_ADDR(COMPOSER1);
> +
> +	saturn_hee_enable_irq(a_crtc, INT_UNDERRUN, true);
> +	a_crtc->ur_mask_armed = true;
> +	dpu_write(hwdev, DPU_CTL_REG, base, both_cfg_rdy, 1);
> +}

[Severity: Medium]
Does saturn_hee_cfg_ready() immediately fire on a stale underrun bit and
race on a_crtc->ur_mask_armed?

After an underrun is logged and INT_UNDERRUN is masked by
saturn_hee_clr_int_sts(), further underrunning scanlines re-latch
DPU_INT_FRM_TIMING_UNFLOW in DPU_ONLINE_IRQ_STS.  On the next commit,
saturn_hee_cfg_ready() unmasks INT_UNDERRUN without clearing
DPU_ONLINE_IRQ_STS first and before setting a_crtc->ur_mask_armed = true
(as does saturn_hee_irq_enable()):

saturn_hee_cfg_ready()
  saturn_hee_enable_irq(a_crtc, INT_UNDERRUN, true)
  <hardirq>
    spacemit_dpu_online_isr()
      saturn_hee_clr_int_sts(..., irq_ur_bit)
        if (... && a_crtc->ur_mask_armed)  <-- still false; stays unmasked
  a_crtc->ur_mask_armed = true

Even if a_crtc->ur_mask_armed = true is written before the interrupt is
taken, a_crtc->ur_reported is still true until INT_CFG_RDY fires, so the
stale underrun triggers spacemit_dpu_online_isr(), skips logging, and is
cleared at the end of the ISR via saturn_hee_clr_int_sts(), which masks
INT_UNDERRUN and disarms ur_mask_armed before the new commit takes effect.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129-k3-display-v4-0-ce6cf7988202@gmail.com?part=8

  reply	other threads:[~2026-11-29 12:49 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 12:32 [PATCH v4 00/16] drm/spacemit: add SpacemiT K3 display support Cody Kang via B4 Relay
2026-11-29 12:32 ` [PATCH v4 01/16] dt-bindings: display: spacemit: add K3 Saturn DPU controller Cody Kang via B4 Relay
2026-11-29 12:36   ` sashiko-bot
2026-11-29 12:32 ` [PATCH v4 02/16] dt-bindings: phy: add SpacemiT K3 Innosilicon DP PHY Cody Kang via B4 Relay
2026-11-29 12:32 ` [PATCH v4 03/16] dt-bindings: display: spacemit: add K3 Innosilicon DP/eDP controller Cody Kang via B4 Relay
2026-11-29 12:38   ` sashiko-bot
2026-11-29 12:32 ` [PATCH v4 04/16] dt-bindings: soc: spacemit: allow eDP/DP PHY PLL pixel clocks on K3 APMU Cody Kang via B4 Relay
2026-11-29 12:32 ` [PATCH v4 05/16] phy: spacemit: add Innosilicon DP TX PHY driver Cody Kang via B4 Relay
2026-11-29 12:48   ` sashiko-bot
2026-11-29 12:32 ` [PATCH v4 06/16] drm/spacemit: add Saturn DPU register model Cody Kang via B4 Relay
2026-11-29 12:32 ` [PATCH v4 07/16] drm/spacemit: add Saturn DPU core types, cmdlist and display MMU Cody Kang via B4 Relay
2026-11-29 12:32 ` [PATCH v4 08/16] drm/spacemit: add Saturn DPU hardware backend Cody Kang via B4 Relay
2026-11-29 12:49   ` sashiko-bot [this message]
2026-11-29 12:32 ` [PATCH v4 09/16] drm/spacemit: add Saturn DPU KMS pipeline Cody Kang via B4 Relay
2026-11-29 12:54   ` sashiko-bot
2026-11-29 12:32 ` [PATCH v4 10/16] drm/spacemit: add Saturn DPU DRM device driver Cody Kang via B4 Relay
2026-11-29 12:32 ` [PATCH v4 11/16] drm/spacemit: add Innosilicon DP/eDP controller bridge driver Cody Kang via B4 Relay
2026-11-29 13:01   ` sashiko-bot
2026-11-29 12:32 ` [PATCH v4 12/16] MAINTAINERS: add SpacemiT K3 display driver entry Cody Kang via B4 Relay
2026-11-29 12:32 ` [PATCH v4 13/16] riscv: dts: spacemit: k3: add display nodes Cody Kang via B4 Relay
2026-11-29 12:48   ` sashiko-bot
2026-11-29 12:32 ` [PATCH v4 14/16] riscv: dts: spacemit: k3-pico-itx: enable the DisplayPort output Cody Kang via B4 Relay
2026-11-29 12:32 ` [PATCH v4 15/16] riscv: dts: spacemit: k3-com260-ifx: " Cody Kang via B4 Relay
2026-11-29 12:32 ` [PATCH v4 16/16] riscv: defconfig: spacemit: k3: enable display driver Cody Kang via B4 Relay

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-239607@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=codykang.hk@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=neil.armstrong@linaro.org \
    --cc=olteanv@gmail.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    /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