Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jayant Shekhar" <jayant.shekhar@oss.qualcomm.com>
Cc: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org, media-ci@linuxtv.org
Subject: Re: [PATCH v3 10/21] drm/msm/dcp: Add DCP CRTCs
Date: Thu, 26 Nov 2026 06:58:35 +0000	[thread overview]
Message-ID: <sashiko-outbox-234918@kernel.org> (raw)
In-Reply-To: <20261126-jshekhar-v3-dcp-v3-10-f1e9d7505039@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 9 potential
issues to consider:
- [High] drm/msm/dcp: software vblank count returned in
  dcp_crtc_get_vblank_counter()
- [Medium] drm/msm/dcp: stale timestamp returned in
  dcp_crtc_get_vblank_timestamp()
- [Medium] drm/msm/dcp: skipped drm_crtc_vblank_on() in
  dcp_crtc_atomic_enable()
- [Medium] drm/msm/dcp: pending_seq_id race and underflow in
  dcp_crtc_commit_kickoff()
- [Medium] drm/msm/dcp: missing height and inactive-CRTC checks in
  dcp_crtc_atomic_check()
- [Medium] drm/msm/dcp: stale bandwidth vote when planes hide in
  dcp_crtc_atomic_begin()
- [Medium] drm/msm/dcp: per-frame sync autorefresh stall and redundant
  ROI HFI commands
- [Medium] drm/msm/dcp: async workqueue deferral and session race in
  dcp_crtc_vblank()
- [Low] drm/msm/dcp: unused fields and inaccurate lock comment in struct
  dcp_crtc
--

commit 2a044a474b64e69e569183925ccbd150a8cf4b9c
Author: Jayant Shekhar <jayant.shekhar@oss.qualcomm.com>

drm/msm/dcp: Add DCP CRTCs

This commit adds DRM CRTC objects for firmware-owned DCP displays, including
session tracking, display topology ROI setup, atomic commit handling, and
HFI vblank callbacks.

> diff --git a/drivers/gpu/drm/msm/dcp/dcp_crtc.c b/drivers/gpu/drm/msm/dcp/dcp_crtc.c
> new file mode 100644
> index 0000000000000..512da8c4ddbcb
> --- /dev/null
> +++ b/drivers/gpu/drm/msm/dcp/dcp_crtc.c
> @@ -0,0 +1,665 @@

[ ... ]

> +	if (cstate->core_clk > 0 || cstate->dram_ib > 0) {
> +		ret = dcp_hfi_crtc_set_bw(dcp_kms->hfi, session_id,
> +					  cstate->dram_ib,  cstate->dram_ab,
> +					  cstate->llcc_ib,  cstate->llcc_ab,
> +					  cstate->core_clk);
> +		if (ret) {
> +			cstate->hfi_error = ret;
> +			return;
> +		}
> +	}

[Severity: Medium]
Does this leave the previous bandwidth and clock votes active in firmware
when all planes on an active CRTC are disabled or clipped off-screen?
When the aggregated cstate->core_clk and cstate->dram_ib drop to 0 while
the CRTC remains active, dcp_hfi_crtc_set_bw() is skipped and the zero vote
is never sent.

> +
> +	mixer_count = cstate->topology_mixer_count;
> +	if (mixer_count < 1 || mixer_count > DCP_MAX_MIXERS) {
> +		cstate->hfi_error = -EINVAL;
> +		return;
> +	}
> +	for (i = 0; i < mixer_count; i++) {
> +		struct drm_rect *roi = &cstate->mixer_roi[i];
> +
> +		if (drm_rect_width(roi) <= 0 || drm_rect_height(roi) <= 0) {
> +			drm_err(crtc->dev, "CRTC%u: invalid zero-sized LM%u ROI\n",
> +				dcp_crtc->display_id, i);
> +			cstate->hfi_error = -EINVAL;
> +			return;
> +		}
> +
> +		ret = dcp_hfi_crtc_set_resource(dcp_kms->hfi, session_id,
> +						i, drm_rect_width(roi),
> +						drm_rect_height(roi),
> +						roi->x1, roi->y1);
> +		if (ret) {
> +			cstate->hfi_error = ret;
> +			return;
> +		}
> +	}
> +
> +	ret = dcp_hfi_crtc_set_dest_roi(dcp_kms->hfi, session_id, 0, 0,
> +					crtc->state->adjusted_mode.hdisplay,
> +					crtc->state->adjusted_mode.vdisplay);
> +	if (ret) {
> +		cstate->hfi_error = ret;
> +		return;
> +	}
> +}
> +
> +static void dcp_crtc_atomic_flush(struct drm_crtc *crtc,
> +				  struct drm_atomic_commit *state)
> +{
> +	struct dcp_crtc *dcp_crtc = to_dcp_crtc(crtc);
> +	struct dcp_crtc_state *cstate = to_dcp_crtc_state(crtc->state);
> +	struct dcp_dpu_kms *dcp_kms = dcp_crtc_get_kms(crtc);
> +	unsigned long flags;
> +	u32 session_id;
> +	int ret;
> +
> +	/* Inactive CRTCs may carry an event but must not receive HFI updates. */
> +	if (!crtc->state->enable || !crtc->state->active)
> +		goto flush_done;
> +	drm_dbg_driver(crtc->dev, "DCP_FLUSH CRTC%u mask=0x%x err=%d\n",
> +		       dcp_crtc->display_id, crtc->state->plane_mask,
> +		       cstate->hfi_error);
> +
> +	if (!dcp_crtc_get_session(crtc, &session_id)) {
> +		drm_dbg_driver(crtc->dev,
> +			       "CRTC%u: atomic flush without HFI session\n",
> +			       dcp_crtc->display_id);
> +		goto flush_done;
> +	}
> +
> +	if (cstate->hfi_error)
> +		goto flush_done;
> +
> +	ret = dcp_hfi_crtc_set_scan_sequence_id(dcp_kms->hfi, session_id,
> +						++dcp_crtc->commit_seq_id);
> +	if (ret)
> +		goto flush_error;
> +
> +	ret = dcp_hfi_crtc_set_autorefresh(dcp_kms->hfi,
> +					   session_id, true, 1);

[Severity: Medium]
Does calling dcp_hfi_crtc_set_autorefresh() on every frame stall every
page flip and async cursor update on a synchronous VirtIO round-trip?

Unlike the asynchronous HFI commands on the commit path,
dcp_hfi_crtc_set_autorefresh() calls dcp_hfi_send_sync() with
HFI_TX_FLAGS_RESPONSE_REQUIRED and blocks in wait_for_completion_timeout()
before kickoff can proceed.  In addition, dcp_crtc_atomic_begin()
unconditionally sends mixer_count dcp_hfi_crtc_set_resource() packets and
one dcp_hfi_crtc_set_dest_roi() packet on every frame even when the mode
and mixer ROIs have not changed.

[ ... ]

> +	/* MSM serializes commits, so only one frame completion may be pending. */
> +	if (atomic_cmpxchg(&dcp_crtc->pending_kickoff_cnt, 0, 1)) {
> +		drm_err(crtc->dev,
> +			"CRTC%u: frame completion already pending (dropped commit_seq_id=%u, in-flight pending_seq_id=%u)\n",
> +			dcp_crtc->display_id, dcp_crtc->commit_seq_id,
> +			dcp_crtc->pending_seq_id);
> +		cstate->hfi_error = -EBUSY;
> +		return;
> +	}
> +	dcp_crtc->pending_seq_id = dcp_crtc->commit_seq_id;
> +
> +	ret = dcp_hfi_display_commit(dcp_kms->hfi, session_id);
> +	if (ret) {
> +		drm_err(crtc->dev,
> +			"HFI commit failed for CRTC%u (session=%u): %d\n",
> +			dcp_crtc->display_id, session_id, ret);
> +		atomic_dec(&dcp_crtc->pending_kickoff_cnt);
> +		wake_up(&dcp_crtc->frame_done_wq);
> +	}
> +}

[Severity: Medium]
Can dcp_crtc_commit_kickoff() race with dcp_crtc_hfi_frame_done_cb() on
pending_seq_id and pending_kickoff_cnt?

CPU0                                  CPU1 (VirtIO response)
dcp_crtc_atomic_flush()
  ++dcp_crtc->commit_seq_id
  dcp_hfi_crtc_set_scan_sequence_id()
  dcp_hfi_crtc_set_autorefresh()
dcp_crtc_commit_kickoff()
  atomic_cmpxchg(&pending_kickoff_cnt,
                 0, 1)
                                      dcp_crtc_hfi_frame_done_cb()
                                        if (sequence_id != pending_seq_id)
                                          return;  <-- drops new seq_id
  pending_seq_id = commit_seq_id

Because commit_seq_id and autorefresh are already programmed in
dcp_crtc_atomic_flush(), or if a late completion for the previous frame
arrives before pending_seq_id is updated, dcp_crtc_hfi_frame_done_cb()
reads the stale pending_seq_id without locking: a callback for the new
sequence ID is dropped (stalling dcp_crtc_wait_for_commit_done() for
500ms), while a late callback for the old sequence ID matches and clears
the new commit's pending_kickoff_cnt early.

Also, if dcp_hfi_display_commit() fails after a racing callback already
decremented pending_kickoff_cnt to 0, the unconditional atomic_dec()
underflows pending_kickoff_cnt to -1 (and omits setting cstate->hfi_error =
ret), causing dcp_crtc_wait_for_commit_done() to time out.

[ ... ]

> +static int dcp_crtc_atomic_check(struct drm_crtc *crtc,
> +				 struct drm_atomic_commit *state)
> +{
> +	struct dcp_dpu_kms *dcp_kms = dcp_crtc_get_kms(crtc);
> +	struct drm_crtc_state *crtc_state =
> +		drm_atomic_get_new_crtc_state(state, crtc);
> +	struct dcp_crtc_state *cstate = to_dcp_crtc_state(crtc_state);
> +	u32 mixer_count;
> +	int ret;
> +
> +	drm_dbg_atomic(crtc->dev, "CRTC%u: atomic_check enable=%d active=%d mode=%s\n",
> +		       crtc->base.id, crtc_state->enable, crtc_state->active,
> +		       crtc_state->mode.name[0] ? crtc_state->mode.name : "none");
> +
> +	if (!crtc_state->enable || !crtc_state->active)
> +		return 0;
> +
> +	mixer_count = cstate->topology_mixer_count;
> +	if (mixer_count < 1 || mixer_count > DCP_MAX_MIXERS) {
> +		drm_dbg_atomic(crtc->dev,
> +			       "CRTC%u: invalid mixer count %u (limit 1..%u)\n",
> +				crtc->base.id, mixer_count, DCP_MAX_MIXERS);
> +		return -EINVAL;
> +	}
> +
> +	ret = dcp_crtc_setup_mixer_rois(crtc, crtc_state, cstate);
> +	if (ret)
> +		return ret;
> +
> +	if (crtc_state->adjusted_mode.hdisplay > dcp_kms->caps->max_width) {
> +		drm_dbg_atomic(crtc->dev,
> +			       "CRTC%u: mode width %d exceeds DCP max width %u\n",
> +			       crtc->base.id,
> +			       crtc_state->adjusted_mode.hdisplay,
> +			       dcp_kms->caps->max_width);
> +		return -E2BIG;
> +	}
> +
> +	return 0;
> +}

[Severity: Medium]
Should dcp_crtc_mode_valid() and dcp_crtc_atomic_check() also validate
vdisplay against dcp_kms->caps->max_height, and run when crtc_state->enable
is true even if crtc_state->active is false?

Neither function checks vdisplay against caps->max_height (and
dcp_crtc_setup_mixer_rois() does not reject vdisplay == 0, leaving
zero-height ROI detection to dcp_crtc_atomic_begin()).  Returning early in
dcp_crtc_atomic_check() when !crtc_state->active also skips mixer ROI setup
and mode validation on an enabled but DPMS-off CRTC, which can allow an
invalid configuration to succeed until a later DPMS-on commit.

> +
> +static u32 dcp_crtc_get_vblank_counter(struct drm_crtc *crtc)
> +{
> +	return drm_crtc_vblank_count(crtc);
> +}

[Severity: High]
Does returning drm_crtc_vblank_count(crtc) from
drm_crtc_funcs.get_vblank_counter corrupt DRM vblank accounting and trigger
a warning in drm_update_vblank_count()?

get_vblank_counter is meant to return a raw hardware frame counter (or be
left NULL when the driver has none), whereas drm_crtc_vblank_count() reads
the cooked software counter vblank->count.  After store_vblank() sets
vblank->last = cur_vblank and increments vblank->count, the next non-IRQ
call to drm_update_vblank_count() sees cur_vblank != vblank->last: with
max_vblank_count == 0 this hits drm_WARN_ON_ONCE(dev, cur_vblank !=
vblank->last), and with max_vblank_count == 0xffffffff it computes diff = 1
and spuriously advances the vblank counter on every vblank enable and
disable.

> +
> +static bool dcp_crtc_get_vblank_timestamp(struct drm_crtc *crtc, int *max_error,
> +					  ktime_t *vblank_time, bool in_vblank_irq)
> +{
> +	struct dcp_crtc *dcp_crtc = to_dcp_crtc(crtc);
> +	u64 timestamp_ns = READ_ONCE(dcp_crtc->hw_vblank_timestamp_ns);
> +
> +	if (!timestamp_ns)
> +		return false;
> +
> +	*vblank_time = ns_to_ktime(timestamp_ns);
> +	return true;
> +}

[Severity: Medium]
Does returning the cached hw_vblank_timestamp_ns when in_vblank_irq is
false expose stale timestamps to DRM vblank and async commit scheduling?

hw_vblank_timestamp_ns is only updated when an HFI VSYNC event arrives and
is never cleared in dcp_crtc_atomic_disable().  When callers query
get_vblank_timestamp() outside vblank IRQ context (such as
drm_crtc_next_vblank_start() in msm_atomic_commit_tail() or
drm_reset_vblank_timestamp() during drm_crtc_vblank_on()), they receive the
timestamp from the last VSYNC before vblanks or the CRTC were disabled,
causing async commit timers to expire immediately and timestamp-based
vblank diffing in drm_update_vblank_count() to jump the vblank counter.

> +
> +static void dcp_crtc_atomic_enable(struct drm_crtc *crtc,
> +				   struct drm_atomic_commit *state)
> +{
> +	struct dcp_dpu_kms *dcp_kms = dcp_crtc_get_kms(crtc);
> +	struct dcp_crtc_state *cstate = to_dcp_crtc_state(crtc->state);
> +	u32 session_id;
> +	int ret;
> +
> +	if (!dcp_crtc_get_session(crtc, &session_id))
> +		return;
> +
> +	ret = dcp_hfi_crtc_set_power_mode(dcp_kms->hfi, session_id,
> +					  HFI_MODE_DPMS_ON);
> +	if (ret) {
> +		drm_err(crtc->dev, "CRTC%u: DPMS ON failed: %d\n",
> +			to_dcp_crtc(crtc)->display_id, ret);
> +		cstate->hfi_error = ret;
> +	}
> +
> +	drm_crtc_vblank_on(crtc);
> +}

[Severity: Medium]
If dcp_crtc_get_session() returns false here, does skipping
drm_crtc_vblank_on(crtc) underflow vblank->refcount later in the commit?

Because crtc->state->active is true, msm_atomic_commit_tail() still runs
vblank_get() followed by vblank_put() on this CRTC.  With vblank->inmodeset
still set, drm_crtc_vblank_get() fails with -EINVAL without incrementing
vblank->refcount, and the unconditional drm_crtc_vblank_put() in
vblank_put() drops the inmodeset reference to 0.

[ ... ]

> +static const struct drm_crtc_funcs dcp_crtc_funcs = {
> +	.set_config             = drm_atomic_helper_set_config,
> +	.page_flip              = drm_atomic_helper_page_flip,
> +	.atomic_create_state    = dcp_crtc_atomic_create_state,
> +	.atomic_duplicate_state = dcp_crtc_atomic_duplicate_state,
> +	.atomic_destroy_state   = dcp_crtc_atomic_destroy_state,
> +	.enable_vblank          = msm_crtc_enable_vblank,
> +	.disable_vblank         = msm_crtc_disable_vblank,

[Severity: Medium]
Can deferring enable_vblank and disable_vblank through
msm_crtc_enable_vblank() and msm_crtc_disable_vblank() race with HFI
session teardown or frame kickoff?

dcp_crtc_vblank() already uses the atomic-safe
dcp_hfi_display_event_register_async() and
dcp_hfi_display_event_deregister_async() helpers.  Routing it through
priv->kms->wq allocates a GFP_ATOMIC work item on every vblank toggle,
discards errors from dcp_crtc_vblank(), allows flush_commit() to trigger a
frame before the worker registers HFI_EVENT_VSYNC, and lets a disable work
item queued by drm_crtc_vblank_off() in dcp_crtc_atomic_disable() run
after the session has been cleared or replaced.

[ ... ]

> diff --git a/drivers/gpu/drm/msm/dcp/dcp_crtc.h b/drivers/gpu/drm/msm/dcp/dcp_crtc.h
> new file mode 100644
> index 0000000000000..b6a435a686c53
> --- /dev/null
> +++ b/drivers/gpu/drm/msm/dcp/dcp_crtc.h
> @@ -0,0 +1,85 @@

[ ... ]

> +	/* Protects CRTC-local vblank and commit state. */
> +	spinlock_t        spin_lock;
> +	u32     vblank_cb_count;
> +	ktime_t vblank_cb_time;
> +	/* Latest firmware-reported VSYNC timestamp; 0 until the first HFI VSYNC. */
> +	u64     hw_vblank_timestamp_ns;
> +	bool    enabled;

[Severity: Low]
This isn't a bug, but enabled is unused, vblank_cb_count and
vblank_cb_time are only ever written in dcp_crtc_vblank_callback() and
never read, and spin_lock only protects session_id and session_valid rather
than vblank or commit state.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-jshekhar-v3-dcp-v3-0-f1e9d7505039@oss.qualcomm.com?part=10

  reply	other threads:[~2026-11-26  6:58 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  6:29 [PATCH v3 00/21] drm/msm/dcp: Add Qualcomm DCP display support Jayant Shekhar
2026-11-26  6:29 ` [PATCH v3 01/21] dt-bindings: display: msm: Add Qualcomm DCP Jayant Shekhar
2026-11-26  6:44   ` sashiko-bot
2026-11-26  6:29 ` [PATCH v3 02/21] drm/msm/dcp: Add HFI packet helpers Jayant Shekhar
2026-11-26  6:52   ` sashiko-bot
2026-11-26  6:29 ` [PATCH v3 03/21] drm/msm/dcp: Add HFI device definitions Jayant Shekhar
2026-11-26  6:29 ` [PATCH v3 04/21] drm/msm/dcp: Add HFI display definitions Jayant Shekhar
2026-11-26  6:29 ` [PATCH v3 05/21] drm/msm/dcp: Add HFI panel definitions Jayant Shekhar
2026-11-26  6:40   ` sashiko-bot
2026-11-26  6:29 ` [PATCH v3 06/21] drm/msm/dcp: Add HFI VirtIO transport Jayant Shekhar
2026-11-26  6:51   ` sashiko-bot
2026-11-26  6:29 ` [PATCH v3 07/21] drm/msm/dcp: Handle asynchronous HFI responses Jayant Shekhar
2026-11-26  6:49   ` sashiko-bot
2026-11-26  6:29 ` [PATCH v3 08/21] drm/msm/dcp: Add generic HFI display commands Jayant Shekhar
2026-11-26  6:45   ` sashiko-bot
2026-11-26  6:29 ` [PATCH v3 09/21] drm/msm/dcp: Add HFI DSI and panel commands Jayant Shekhar
2026-11-26  6:54   ` sashiko-bot
2026-11-26  6:29 ` [PATCH v3 10/21] drm/msm/dcp: Add DCP CRTCs Jayant Shekhar
2026-11-26  6:58   ` sashiko-bot [this message]
2026-11-26  6:29 ` [PATCH v3 11/21] drm/msm/dcp: Add DCP planes Jayant Shekhar
2026-11-26  7:02   ` sashiko-bot
2026-11-26  6:29 ` [PATCH v3 12/21] drm/msm/dcp: Route HFI display events Jayant Shekhar
2026-11-26  6:50   ` sashiko-bot
2026-11-26  6:29 ` [PATCH v3 13/21] drm/msm/dcp: Add DCP encoder Jayant Shekhar
2026-11-26  6:42   ` sashiko-bot
2026-11-26  6:29 ` [PATCH v3 14/21] drm/msm/dcp: Add DCP DSI host and panel support Jayant Shekhar
2026-11-26  7:06   ` sashiko-bot
2026-11-26  6:29 ` [PATCH v3 15/21] drm/msm/dcp: Integrate the DSI bridge with KMS Jayant Shekhar
2026-11-26  6:53   ` sashiko-bot
2026-11-26  6:29 ` [PATCH v3 16/21] drm/msm/dcp: Register DCP display pipeline Jayant Shekhar
2026-11-26  7:03   ` sashiko-bot
2026-11-26  6:29 ` [PATCH v3 17/21] drm/msm: Export GPU component matching helper Jayant Shekhar
2026-11-26  6:29 ` [PATCH v3 18/21] drm/msm/dcp: Add DCP VirtIO driver Jayant Shekhar
2026-11-26  7:07   ` sashiko-bot
2026-11-26  6:29 ` [PATCH v3 19/21] drm/msm: Support KMS backends without a display IRQ Jayant Shekhar
2026-11-26  6:29 ` [PATCH v3 20/21] drm/msm: Register the DCP backend Jayant Shekhar
2026-11-26  7:00   ` sashiko-bot
2026-11-26  6:29 ` [PATCH v3 21/21] arm64: dts: qcom: hawi: Add DCP support Jayant Shekhar
2026-11-26  7:10   ` sashiko-bot

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-234918@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jayant.shekhar@oss.qualcomm.com \
    --cc=media-ci@linuxtv.org \
    --cc=robh@kernel.org \
    --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