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 07/21] drm/msm/dcp: Handle asynchronous HFI responses
Date: Thu, 26 Nov 2026 06:49:59 +0000	[thread overview]
Message-ID: <sashiko-outbox-234904@kernel.org> (raw)
In-Reply-To: <20261126-jshekhar-v3-dcp-v3-7-f1e9d7505039@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] drm/msm/dcp: uninitialized caps_cache completions in
  dcp_hfi_init() and deinit
- [High] drm/msm/dcp: race scheduling resource_vote_work after
  dcp_hfi_stop()
- [Medium] drm/msm/dcp: malformed RESOURCE_VOTE clobbers pending vote in
  dcp_hfi_dispatch_event()
- [Medium] drm/msm/dcp: unconsumed vote state in
  dcp_hfi_resource_vote_work()
- [Medium] drm/msm/dcp: missing power-control handling in
  dcp_hfi_dispatch_event()
--

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

drm/msm/dcp: Handle asynchronous HFI responses

This commit dispatches asynchronous HFI display events, caches capability
payloads, and defers resource-vote processing to a work item before
falling back to synchronous command completion handling.

> diff --git a/drivers/gpu/drm/msm/dcp/dcp_hfi_core.c b/drivers/gpu/drm/msm/dcp/dcp_hfi_core.c
> index 9c46a4560a0de..1a1addd33877c 100644
> --- a/drivers/gpu/drm/msm/dcp/dcp_hfi_core.c
> +++ b/drivers/gpu/drm/msm/dcp/dcp_hfi_core.c
[ ... ]
> @@ -228,6 +233,191 @@ void dcp_hfi_cmd_callback(struct virtqueue *vq)
>  	spin_unlock_irqrestore(&hfi->cmd_lock, flags);
>  }
>  
> +static void dcp_hfi_store_caps_payload(struct dcp_hfi *hfi,
> +				       struct completion *done,
> +				       u8 *dst, u32 *dst_len,
> +				       const struct hfi_packet_info *pkt_info,
> +				       const char *name)
> +{
> +	u32 n;
> +
> +	if (!pkt_info->payload_ptr || !pkt_info->payload_size) {
> +		dev_dbg(hfi->dev, "%s: empty payload\n", name);
> +		return;
> +	}
> +
> +	if (pkt_info->payload_size > DCP_HFI_CAPS_BUF_SIZE) {
> +		dev_warn(hfi->dev, "%s: payload too large: %u\n",
> +			 name, pkt_info->payload_size);
> +		return;
> +	}
> +
> +	n = pkt_info->payload_size;
> +	memcpy(dst, pkt_info->payload_ptr, n);
> +	*dst_len = n;
> +	if (done)
> +		complete(done);
> +	dev_dbg(hfi->dev, "%s: stored %u bytes\n", name, n);
> +}
> +
> +/* 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: {
> +		return true;
> +	}

[Severity: Medium]
Does dcp_hfi_dispatch_event() omit handling for display power-control
messages?

The commit message states that display power control produces asynchronous
responses and that this patch delivers power-control notifications, but
neither HFI_COMMAND_DISPLAY_POWER_CONTROL nor
HFI_COMMAND_DISPLAY_EVENT_POWER is handled here.  Any asynchronous
power-control response with HFI_RX_FLAGS_SUCCESS or
HFI_RX_FLAGS_INFORMATION will fall through in dcp_hfi_resp_callback() to
dcp_hfi_complete_pending().

[ ... ]

> +	case HFI_COMMAND_DEVICE_CALLBACK_RESOURCE_VOTE: {
> +		unsigned long vote_flags;
> +		u32 payload_size = pkt_info->payload_size;
> +		bool valid = pkt_info->payload_ptr && payload_size &&
> +			payload_size <= DCP_HFI_RESOURCE_VOTE_BUF_SIZE &&
> +			payload_size % sizeof(struct dcp_resource_vote_wire) == 0;
> +
> +		if (!valid) {
> +			dev_warn_ratelimited(hfi->dev,
> +					     "dropping malformed RESOURCE_VOTE payload size=%u max=%u\n",
> +					     payload_size, DCP_HFI_RESOURCE_VOTE_BUF_SIZE);
> +			payload_size = 0;
> +		}
> +
> +		spin_lock_irqsave(&hfi->resource_vote_lock, vote_flags);
> +		if (payload_size)
> +			memcpy(hfi->resource_vote_buf, pkt_info->payload_ptr,
> +			       payload_size);
> +		hfi->resource_vote_len = payload_size;
> +		hfi->resource_vote_generation++;
> +		spin_unlock_irqrestore(&hfi->resource_vote_lock, vote_flags);
> +
> +		if (payload_size)
> +			schedule_work(&hfi->resource_vote_work);
> +		return true;
> +	}

[Severity: Medium]
When a malformed HFI_COMMAND_DEVICE_CALLBACK_RESOURCE_VOTE packet arrives,
does setting payload_size = 0 and continuing discard a previously buffered
valid resource vote?

Instead of returning early on !valid, this overwrites
hfi->resource_vote_len = 0 and increments hfi->resource_vote_generation,
so dcp_hfi_resource_vote_work() sees len == 0 and returns without
delivering the earlier unconsumed vote.

[ ... ]

> @@ -642,6 +834,47 @@ int dcp_hfi_send_no_wait(struct dcp_hfi *hfi,
>  			payload_type, payload, payload_size, HFI_TX_FLAGS_NONE);
>  }
>  
> +static void dcp_hfi_resource_vote_work(struct work_struct *work)
> +{
> +	struct dcp_hfi *hfi = container_of(work, struct dcp_hfi,
> +					     resource_vote_work);
> +	u8 buf[DCP_HFI_RESOURCE_VOTE_BUF_SIZE];
> +	struct dcp_resource_vote_pair pairs[DCP_HFI_RESOURCE_VOTE_BUF_SIZE /
> +							 sizeof(struct dcp_resource_vote_wire)];
> +	const struct dcp_resource_vote_wire *wire;
> +	u32 len, generation, count, i;
> +	bool dirty;
> +	unsigned long flags;
> +
> +	do {
> +		spin_lock_irqsave(&hfi->resource_vote_lock, flags);
> +		len = hfi->resource_vote_len;
> +		generation = hfi->resource_vote_generation;
> +		if (len)
> +			memcpy(buf, hfi->resource_vote_buf, len);
> +		spin_unlock_irqrestore(&hfi->resource_vote_lock, flags);
> +
> +		if (!len || !hfi->resource_vote_cb)
> +			return;
> +		if (len % sizeof(struct dcp_resource_vote_wire)) {
> +			dev_warn_ratelimited(hfi->dev,
> +					     "dropping malformed RESOURCE_VOTE size=%u\n", len);
> +			return;
> +		}
> +		count = len / sizeof(struct dcp_resource_vote_wire);
> +		wire = (const struct dcp_resource_vote_wire *)buf;
> +		for (i = 0; i < count; i++) {
> +			pairs[i].key = le32_to_cpu(wire[i].key);
> +			pairs[i].value = get_unaligned_le64(&wire[i].value);
> +		}
> +
> +		hfi->resource_vote_cb(hfi->drv, pairs, count);
> +		spin_lock_irqsave(&hfi->resource_vote_lock, flags);
> +		dirty = generation != hfi->resource_vote_generation;
> +		spin_unlock_irqrestore(&hfi->resource_vote_lock, flags);
> +	} while (dirty);
> +}

[Severity: Medium]
Does dcp_hfi_resource_vote_work() invoke hfi->resource_vote_cb() twice
with the same vote when a new vote arrives while the worker is already
running?

Because the workqueue core clears WORK_STRUCT_PENDING_BIT before running
dcp_hfi_resource_vote_work(), an HFI_COMMAND_DEVICE_CALLBACK_RESOURCE_VOTE
event arriving while the worker is in hfi->resource_vote_cb() both causes
the do-while(dirty) loop to consume the new generation and causes
schedule_work(&hfi->resource_vote_work) to queue a second run.  Since
hfi->resource_vote_len is never cleared when snapshotting
hfi->resource_vote_buf, the queued second run sees the same non-zero
hfi->resource_vote_len and delivers the stale vote again.  Clearing
hfi->resource_vote_len = 0 under hfi->resource_vote_lock when copying
hfi->resource_vote_buf (and looping while hfi->resource_vote_len != 0)
would avoid duplicate callbacks.

[ ... ]

> @@ -807,6 +1047,7 @@ void dcp_hfi_stop(struct dcp_hfi *hfi)
>  	atomic_set(&hfi->shutdown_in_progress, 1);
>  	spin_unlock_irqrestore(&hfi->cmd_lock, flags);
>  
> +	cancel_work_sync(&hfi->resource_vote_work);
>  	cancel_delayed_work_sync(&hfi->resp_repost_work);
>  	dcp_hfi_cancel_pending(hfi, -ENODEV);
>  }

[Severity: High]
Can dcp_hfi_resp_callback() re-schedule hfi->resource_vote_work after
cancel_work_sync() in dcp_hfi_stop() returns?

dcp_hfi_resp_callback() checks hfi->shutdown_in_progress only once on
entry and drops hfi->resp_drain_lock while unpacking packets and calling
dcp_hfi_dispatch_event():

CPU0                                  CPU1
dcp_hfi_resp_callback()
  !atomic_read(&shutdown_in_progress)
  spin_unlock(&hfi->resp_drain_lock)
                                      dcp_hfi_stop()
                                        atomic_set(&shutdown_in_progress, 1)
                                        cancel_work_sync(&resource_vote_work)
  dcp_hfi_dispatch_event()
    schedule_work(&resource_vote_work)
                                      dcp_hfi_deinit()
                                      /* hfi / drv torn down */
                                      dcp_hfi_resource_vote_work()
                                        <-- runs after stop / use-after-free

Neither HFI_COMMAND_DEVICE_CALLBACK_RESOURCE_VOTE in
dcp_hfi_dispatch_event() nor dcp_hfi_resource_vote_work() checks
hfi->shutdown_in_progress, and resource_vote_work is not cancelled again
after virtqueue callbacks are synchronized.

> @@ -864,6 +1105,10 @@ int dcp_hfi_restore_queues(struct dcp_hfi *hfi, struct virtqueue *cmd_vq,
>  
>  void dcp_hfi_deinit(struct dcp_hfi *hfi)
>  {
> +	mutex_lock(&hfi->caps_cache_lock);
> +	memset(&hfi->caps_cache, 0, sizeof(hfi->caps_cache));
> +	mutex_unlock(&hfi->caps_cache_lock);
> +
>  	xa_destroy(&hfi->pending_xa);

[Severity: High]
Are hfi->caps_cache.device_done and hfi->caps_cache.display_done left
uninitialized in dcp_hfi_init() and wiped by memset() in dcp_hfi_deinit()?

dcp_hfi_init() allocates struct dcp_hfi with devm_kzalloc() and pre-posts
response buffers to resp_vq without calling init_completion() on
device_done or display_done, and dcp_hfi_deinit() zeroes the entire
caps_cache structure with memset() without holding hfi->caps_lock.  A
zeroed struct completion has wait.task_list.next == NULL, so when
HFI_COMMAND_DEVICE_INIT_DEVICE_CAPS or
HFI_COMMAND_DEVICE_INIT_DISPLAY_CAPS arrives and
dcp_hfi_store_caps_payload() calls complete(done), swake_up_locked() sees
!list_empty(&q->task_list) and dereferences a NULL pointer.

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

  reply	other threads:[~2026-11-26  6:50 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 [this message]
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
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-234904@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