From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795956886; b=WsojpH2wTyHS9QQ8iAw2/Hx9N6Owh8knDtZn6VRxbJkz1TtSPoCENhfIpW9hKgXhFezl zA+X4VqPOwDVSU1dHtp8N77bdKjcVKgmiHTaxNWGbqS7QSLfMzSnAeMljefQxslCHxB0B bhmCqpyqAu2rMsiRXwr55AzHbsUMg59GAU/D+q8I88Ut2LMo0+bWKgXctMbvLhAieQUF4 oPYdGLyW9P9D4IlDvobt7iPbuqY1g4rhkfrRn9fxopodmIWCDmKE+1Bho4k+NKg5v5qE1 60diSZpZ7pyMQTnEF2+QSEzp0hMASkk20SsIp184ml73V5+OMtYOZXqJetup0mkEBiA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795956886; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=+2oY5YY2ES4hGYg5YoyOh89sbVerr3nr2KvMkDYvaIs=; b=vlxw11WX5E8WznXBPaFrge+I7RuyIzJEYQ5X/Dug7jGiH8Jlb+8NLN+REaVZaHNyyHXq zktCbPVKZUwya/dHsNaO4+JKhXVe6UpcEsGJ4nR7Eva0eRBHaonaoCZvhXS6UNj/lChj3 5nTFmfSAgdNcG7XG9zSiJ7jEwC+XqxW39NM56S5C3m44RNdp7TcP7nVSpXH1Zo3ICYD8I p2szp+aQn+7LSEoEn4nntBm1YUXLg29C9M6HJ8jVe9aFcSbCfvVr82sXhC+KgiE4NWS66 Iym985xbPg9mxPMv8lAGLsBePHaE1M1VUO24eOi5i0VJcrwoa0PY1dRTB7rosHlT8aQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RofLLTIK; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF2F3606A327; Sun, 29 Nov 2026 12:54:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RofLLTIK Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EF7D1F00897; Sun, 29 Nov 2026 12:54:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795956886; bh=+2oY5YY2ES4hGYg5YoyOh89sbVerr3nr2KvMkDYvaIs=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=RofLLTIK72bNicqxHE1uapQ8y3S8WraGLJAl56rRIf+CLWRnY8nSzUj2ACTho9Fcm 99PcdHfcS2oJeLEZpkth19Rk+IJV0v3vtnW6q2OMXop3slsv5PrflYsQy+h3kURmag PpTvDlFWWceijQkMsmJ9c8GtYi5HmEQ1SjJrxwbIeqTG0VJlJIY3/pRm6ngWPspOwP KI2xWQMUkNiuiV0Zz75CnNYMeV66R57K9vaGswUKfhOWFAJ7feDIZ9SDDl7FzyiEO1 clHjyNsteSLfYT9exBAhrlbFJqnF0peFGrTk0JRHG7dlcp7FaOef0Ik9bdFkffsFgt +je2M2NCS+6og== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 09/16] drm/spacemit: add Saturn DPU KMS pipeline Reply-To: sashiko-reviews@lists.linux.dev To: "Cody Kang" 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 In-Reply-To: <20261129-k3-display-v4-9-ce6cf7988202@gmail.com> References: <20261129-k3-display-v4-0-ce6cf7988202@gmail.com> <20261129-k3-display-v4-9-ce6cf7988202@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 29 Nov 2026 12:54:45 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] drm/spacemit: incomplete teardown in spacemit_drm_master_unbind() - [High] drm/spacemit: UAF of devm-allocated priv when drm_device outlives remove - [High] drm/spacemit: vblank init ordering in spacemit_drm_master_bind() and race - [High] drm/spacemit: premature event arming in spacemit_crtc_atomic_flush() and ISR -- commit e124be165ca1d42bc693534742294e9b826976ad Author: Cody Kang drm/spacemit: add Saturn DPU KMS pipeline This commit adds the atomic KMS CRTC and primary plane implementation, component master bind/unbind, and runtime PM callbacks for the SpacemiT Saturn DPU. > diff --git a/drivers/gpu/drm/spacemit/spacemit_crtc.c b/drivers/gpu/drm/s= pacemit/spacemit_crtc.c > new file mode 100644 > index 0000000000000..62b33f959f467 > --- /dev/null > +++ b/drivers/gpu/drm/spacemit/spacemit_crtc.c [ ... ] > +static void spacemit_crtc_atomic_flush(struct drm_crtc *crtc, > + struct drm_atomic_commit *state) > +{ > + struct drm_crtc_state *crtc_state =3D > + drm_atomic_get_new_crtc_state(state, crtc); > + struct spacemit_crtc *a_crtc =3D to_spacemit_crtc(crtc); > + struct spacemit_drm_private *priv =3D spacemit_drm_priv(crtc->dev); > + int idx; > + > + /* > + * The event releases the next commit, which rewrites the other > + * command list and points the engine at it. Hold the event until > + * CFG_RDY says the engine has taken this commit's lists; the > + * interrupt then arms it for the following vblank. > + */ > + spin_lock_irq(&crtc->dev->event_lock); > + if (crtc_state->event) { > + if (drm_crtc_vblank_get(crtc) =3D=3D 0) > + a_crtc->event =3D crtc_state->event; > + else > + drm_crtc_send_vblank_event(crtc, crtc_state->event); > + crtc_state->event =3D NULL; > + } > + spin_unlock_irq(&crtc->dev->event_lock); > + > + /* clocks_on is false here only after a failed power-up. */ > + if (priv->clocks_on && drm_dev_enter(crtc->dev, &idx)) { > + spacemit_dpu_run(crtc, state); > + drm_dev_exit(idx); > + } else { > + spacemit_dpu_complete_event(a_crtc); > + } > +} [Severity: High] Can spacemit_dpu_online_isr() arm and complete a_crtc->event before the DPU has taken and scanned out the new command lists? spacemit_crtc_atomic_flush() publishes a_crtc->event and drops event_lock before spacemit_dpu_run() clears stale INT_CFG_RDY status and raises both_cfg_rdy: drivers/gpu/drm/spacemit/dpu/dpu_saturn.c:spacemit_dpu_run() { ... saturn_hee_conf_dpuctrl(crtc, state); /* 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); ... saturn_hee_cfg_ready(a_crtc, hwdev); } Because spacemit_dpu_online_isr() reads unmasked status from DPU_ONLINE_IRQ_STS and handles INT_CFG_RDY before INT_VSYNC, an interrupt that fires with a leftover INT_CFG_RDY bit set (or at the frame boundary when INT_CFG_RDY and INT_VSYNC are both pending) arms a_crtc->event for vblank->count + 1 and immediately delivers it via drm_crtc_handle_vblank() in the same ISR call: drivers/gpu/drm/spacemit/dpu/dpu_saturn.c:spacemit_dpu_online_isr() { ... irq_bit =3D saturn_hee_get_irq_bit(INT_CFG_RDY); if (irq_raw & irq_bit) { ... if (a_crtc->event) { drm_crtc_arm_vblank_event(&a_crtc->crtc, a_crtc->event); a_crtc->event =3D NULL; } spin_unlock(&a_crtc->crtc.dev->event_lock); } irq_bit =3D 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 |=3D irq_bit; } ... } Completing the event early signals flip_done before the hardware finishes with the previous buffers, allowing the next commit to overwrite the in-use slot in the two-entry command-list ring and clean up the active framebuffer. [ ... ] > + ret =3D drm_mode_config_create_initial_state(drm); > + if (ret) { > + dev_err_probe(dev, ret, "failed to create the initial state\n"); > + goto err_unbind_all; > + } > + > + ret =3D drm_vblank_init(drm, drm->mode_config.num_crtc); > + if (ret) { > + dev_err_probe(dev, ret, "failed to initialize vblank\n"); > + goto err_unbind_all; > + } [Severity: High] Does calling drm_mode_config_create_initial_state() before drm_vblank_init() leave vblank enabled on the initially disabled CRTC and allow spacemit_crtc_enable_vblank() to race with runtime PM? drm_mode_config_create_initial_state() only calls drm_crtc_vblank_reset() when drm_dev_has_vblank(drm) is already true. Because drm_vblank_init() has not run yet, the disabled CRTC is left with vblank->inmodeset =3D=3D 0 instead of 1, so DRM_IOCTL_WAIT_VBLANK can invoke spacemit_crtc_enable_vblank() before drm_crtc_vblank_on() is called. Furthermore, spacemit_crtc_enable_vblank() only checks READ_ONCE(priv->clocks_on) without synchronization against spacemit_dpu_runtime_suspend() (which only waits on synchronize_irq(priv->irq_online)): CPU0 CPU1 spacemit_crtc_enable_vblank() spacemit_dpu_runtime_suspend() if (!READ_ONCE(priv->clocks_on)) WRITE_ONCE(priv->clocks_on, false= ); synchronize_irq(priv->irq_online); reset_control_bulk_assert(...); clk_bulk_disable_unprepare(...); saturn_hee_clr_int_sts(...) <-- MMIO write to clock-gated DPU stalls bus During spacemit_crtc_atomic_enable(), spacemit_dpu_runtime_resume() also sets priv->clocks_on =3D true before spacemit_dpu_init() and drm_crtc_vblank_on(), allowing a concurrent drm_vblank_get() to unmask INT_VSYNC before the timing generator is initialized. [ ... ] > +static void spacemit_drm_master_unbind(struct device *dev) > +{ > + struct spacemit_drm_private *priv =3D dev_get_drvdata(dev); > + struct drm_device *drm =3D priv->ddev; > + > + /* > + * A process may keep the card open past this point. Unplug, so that > + * its ioctls fail and the drm_dev_enter() sections keep off the > + * registers. The commits that follow still turn the outputs off: the > + * CRTC drops its runtime PM reference, and the suspend resets the DPU. > + * The interrupt stays alive until then, for a commit that was already > + * waiting on it. > + */ > + drm_dev_unplug(drm); > + /* An open file keeps the drm_device, and its poll worker, alive. */ > + drm_kms_helper_poll_fini(drm); > + drm_atomic_helper_shutdown(drm); > + > + disable_irq(priv->irq_online); > + /* > + * A shutdown commit that failed has not stopped the watchdog of a > + * commit still waiting for CFG_RDY, and the CRTC is freed once unbind > + * returns. > + */ > + timer_shutdown_sync(&priv->a_crtc->cfg_rdy_timer); > + > + component_unbind_all(dev, drm); > + > + /* .shutdown and a later re-bind must not touch the stale instance. */ > + priv->ddev =3D NULL; > + priv->a_crtc =3D NULL; > +} [Severity: High] What completes priv->a_crtc->event and stops DPU DMA when spacemit_drm_master_unbind() runs? If a commit is waiting for CFG_RDY when drm_atomic_helper_shutdown() fails, disable_irq() and timer_shutdown_sync() stop both paths that call spacemit_dpu_complete_event(), leaking priv->a_crtc->event and its vblank reference and leaving flip_done unsignaled (along with the CRTC's runtime PM reference). Even when drm_atomic_helper_shutdown() succeeds, calling drm_dev_unplug() first makes drm_dev_enter() in spacemit_crtc_atomic_disable() and spacemit_plane_atomic_disable() return false, skipping spacemit_dpu_uninit() and spacemit_plane_off(). Hardware shutdown then relies entirely on spacemit_dpu_runtime_suspend(), so if runtime suspend does not run (for example when power/control is set to "on" or shutdown failed), the DPU remains clocked and out of reset while component unbind releases the drm_device and frees the command-list rings via dma_free_coherent(). [ ... ] > +static int spacemit_dpu_probe(struct platform_device *pdev) > +{ > + struct device *dev =3D &pdev->dev; > + const struct spacemit_hw_device *hwdev_template; > + struct spacemit_drm_private *priv; > + int ret; > + > + /* A display MMU entry holds a 26-bit page frame number. */ > + ret =3D dma_set_mask_and_coherent(dev, DMA_BIT_MASK(38)); > + if (ret) > + return dev_err_probe(dev, ret, "failed to set DMA mask\n"); > + > + priv =3D devm_kzalloc_obj(dev, *priv); > + if (!priv) > + return -ENOMEM; > + priv->dev =3D dev; > + dev_set_drvdata(dev, priv); > + > + /* The match data is shared const; the MMIO mapping is per-instance. */ > + hwdev_template =3D device_get_match_data(dev); > + if (!hwdev_template) > + return -ENODEV; > + priv->hwdev =3D devm_kmemdup(dev, hwdev_template, > + sizeof(*hwdev_template), GFP_KERNEL); [Severity: High] Can sdrm->priv be dereferenced after it is freed if an open DRM file outlives spacemit_dpu_remove()? priv and priv->hwdev are allocated with devm on the platform device, so they are freed as soon as spacemit_dpu_remove() finishes, whereas sdrm->base (the drm_device) stays alive until the last open file descriptor is closed. KMS and vblank callbacks on that drm_device still dereference sdrm->priv via spacemit_drm_priv() before or without drm_dev_enter() =E2=80=94 for example in spacemit_crtc_atomic_flush() (priv->clocks_on), spacemit_plane_atomic_check() (priv->hwdev), and spacemit_crtc_disable_vblank() from the vblank disable timer =E2=80=94 caus= ing a use-after-free. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261129-k3-display= -v4-0-ce6cf7988202@gmail.com?part=3D9