Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] drm/msm/dcp: unsynchronized frame done state in dcp_crtc_hfi_frame_done_cb() - [Medium] drm/msm/dcp: missing payload validation in dcp_hfi_dispatch_frame_done() - [Medium] drm/msm/dcp: broken vblank count on HFI VSYNC in dcp_hfi_dispatch_event() --
commit 7a2a7eb3a151eeca0e80702b0d7a264c2c4003db Author: Jayant Shekhar <[email protected]> drm/msm/dcp: Route HFI display events This commit routes asynchronous HFI VSYNC and frame-scan completion events from DCP firmware to the corresponding DRM CRTC callbacks. > diff --git a/drivers/gpu/drm/msm/dcp/dcp_hfi_core.c > b/drivers/gpu/drm/msm/dcp/dcp_hfi_core.c > index 1a1addd33877c..3d0e15cae038f 100644 > --- a/drivers/gpu/drm/msm/dcp/dcp_hfi_core.c > +++ b/drivers/gpu/drm/msm/dcp/dcp_hfi_core.c [ ... ] > @@ -260,12 +261,41 @@ static void dcp_hfi_store_caps_payload(struct dcp_hfi > *hfi, > dev_dbg(hfi->dev, "%s: stored %u bytes\n", name, n); > } > > +static void dcp_hfi_dispatch_frame_done(struct dcp_hfi *hfi, > + const struct hfi_packet_info *pkt_info) > +{ > + const struct hfi_display_frame_event_data *frame = NULL; > + u32 sequence_id = 0; > + u64 timestamp_ns = 0; > + > + if (pkt_info->payload_ptr && > + pkt_info->payload_size >= sizeof(*frame)) { > + frame = pkt_info->payload_ptr; > + sequence_id = frame->bufferflip_index; > + timestamp_ns = ((u64)frame->timestamp_hi << 32) | > + frame->timestamp_lo; > + } > + dcp_crtc_hfi_frame_done_cb(hfi->drv, pkt_info->id & 0xFFFF, > + sequence_id, timestamp_ns); > +} [Severity: Medium] Should dcp_hfi_dispatch_frame_done() and the HFI_COMMAND_DISPLAY_EVENT_VSYNC handler below drop packets whose payload is missing or smaller than the expected event struct instead of still invoking the CRTC callback with zeroed fields? In dcp_crtc_hfi_frame_done_cb(), sequence_id is compared directly against dcp_crtc->pending_seq_id: drivers/gpu/drm/msm/dcp/dcp_crtc.c:dcp_crtc_hfi_frame_done_cb() { ... if (sequence_id != dcp_crtc->pending_seq_id) { drm_warn(crtc->dev, "CRTC%u: ignoring stale FRAME_SCAN_COMPLETE seq=%u expected=%u\n", dcp_crtc->display_id, sequence_id, dcp_crtc->pending_seq_id); return; } ... atomic_add_unless(&dcp_crtc->pending_kickoff_cnt, -1, 0); wake_up(&dcp_crtc->frame_done_wq); } When pending_seq_id is 0 (before the first commit or when commit_seq_id wraps around to 0), a truncated packet with sequence_id = 0 matches pending_seq_id and wakes frame_done_wq prematurely; otherwise it triggers an unratelimited drm_warn(). Similarly, passing timestamp_ns = 0 to dcp_crtc_hfi_vblank_cb() leaves dcp_crtc->hw_vblank_timestamp_ns at the previous frame's timestamp. [Severity: High] Does routing asynchronous FRAME_SCAN_COMPLETE events into dcp_crtc_hfi_frame_done_cb() race with dcp_crtc_atomic_flush() and dcp_crtc_commit_kickoff() over dcp_crtc->pending_seq_id and dcp_crtc->pending_kickoff_cnt? Because pending_seq_id and pending_kickoff_cnt are updated without locks across the commit path, several interleavings can occur: CPU0 (atomic commit) CPU1 (VirtIO resp callback) dcp_crtc_commit_kickoff() /* prior commit N timed out, * leaving pending_seq_id == N */ atomic_cmpxchg(&pending_kickoff_cnt, 0, 1) dcp_hfi_dispatch_frame_done() dcp_crtc_hfi_frame_done_cb() /* late seq N matches * pending_seq_id == N */ atomic_add_unless(&pending_kickoff_cnt, -1, 0) pending_seq_id = commit_seq_id; ... dcp_crtc_wait_for_commit_done() /* returns immediately without * waiting for commit N+1 */ In addition, dcp_crtc_atomic_flush() sends ++dcp_crtc->commit_seq_id to firmware via dcp_hfi_crtc_set_scan_sequence_id() and enables autorefresh before dcp_crtc_commit_kickoff() updates pending_seq_id, so a completion arriving in that window is dropped as stale and stalls the commit until the 500 ms frame timeout. And if dcp_hfi_display_commit() fails in dcp_crtc_commit_kickoff() after dcp_crtc_hfi_frame_done_cb() has already decremented pending_kickoff_cnt to 0, the error path's unconditional atomic_dec(&dcp_crtc->pending_kickoff_cnt) underflows pending_kickoff_cnt to -1, breaking subsequent commits. > /* Route asynchronous events and capability packets before flag handling. */ > static bool dcp_hfi_dispatch_event(struct dcp_hfi *hfi, > const struct hfi_packet_info *pkt_info) > { > switch (pkt_info->cmd) { > case HFI_COMMAND_DISPLAY_EVENT_VSYNC: { > + const struct hfi_display_vsync_data *vsync = NULL; > + u64 timestamp_ns = 0; > + > + if (pkt_info->payload_ptr && > + pkt_info->payload_size >= sizeof(*vsync)) { > + vsync = pkt_info->payload_ptr; > + timestamp_ns = ((u64)vsync->timestamp_hi << 32) | > + vsync->timestamp_lo; > + } > + dcp_crtc_hfi_vblank_cb(hfi->drv, pkt_info->id & 0xFFFF, > + timestamp_ns); > return true; > } [Severity: Medium] Should HFI_COMMAND_DISPLAY_EVENT_VSYNC also propagate vsync->vsync_index so the CRTC can report a hardware frame counter instead of returning drm_crtc_vblank_count(crtc) from dcp_crtc_get_vblank_counter()? drivers/gpu/drm/msm/dcp/dcp_crtc.c:dcp_crtc_get_vblank_counter() { return drm_crtc_vblank_count(crtc); } In drm_vblank.c, store_vblank() records vblank->last = cur_vblank before adding the increment to vblank->count. Because dcp_crtc_get_vblank_counter() returns the software vblank->count, subsequent non-IRQ calls to drm_update_vblank_count() see cur_vblank != vblank->last even when no frame has elapsed. With max_vblank_count = 0xffffffff and vblank_disable_immediate = true (set in commit "drm/msm/dcp: Register DCP display pipeline"), every vblank enable/disable transition spuriously increments vblank->count by 1 while losing frames that elapsed while vblank was disabled. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=12
