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 <[email protected]> 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/[email protected]?part=8
