Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/msm/dcp: completion zeroing and unlocked caps_cache in
  dcp_hfi_kms.c
- [High] drm/msm/dcp: pipe count clobbering in
  dcp_hfi_parse_init_caps_kv()
- [Low] drm/msm/dcp: uninitialized stack buffer in
  dcp_hfi_log_pipe_ids()
--

commit 493628efb4ff9c95ef6c5374bcbb496f98a1b513
Author: Jayant Shekhar <[email protected]>

drm/msm/dcp: Add generic HFI display commands

This commit adds HFI display command helpers for CRTCs, planes, encoders,
device initialization, and capability parsing in the DCP driver.

> diff --git a/drivers/gpu/drm/msm/dcp/dcp_hfi_kms.c 
> b/drivers/gpu/drm/msm/dcp/dcp_hfi_kms.c
> new file mode 100644
> index 0000000000000..82a7fb420e650
> --- /dev/null
> +++ b/drivers/gpu/drm/msm/dcp/dcp_hfi_kms.c
> @@ -0,0 +1,325 @@

[ ... ]

> +static void dcp_hfi_caps_cache_init(struct dcp_hfi_caps_cache *cache)
> +{
> +     init_completion(&cache->device_done);
> +     init_completion(&cache->display_done);
> +}
> +
> +static void dcp_hfi_caps_cache_start(struct dcp_hfi *hfi)
> +{
> +     memset(&hfi->caps_cache, 0, sizeof(hfi->caps_cache));
> +     dcp_hfi_caps_cache_init(&hfi->caps_cache);
> +}
> +
> +static void dcp_hfi_caps_cache_stop(struct dcp_hfi *hfi)
> +{
> +     memset(&hfi->caps_cache, 0, sizeof(hfi->caps_cache));
> +}

[Severity: High]
Can dcp_hfi_caps_cache_stop() corrupt cache->device_done and
cache->display_done while capability events are still arriving on resp_vq?

memset() zeroes the whole struct dcp_hfi_caps_cache, including both struct
completion objects, setting their wait.task_list pointers to NULL and
zeroing wait.lock without holding hfi->caps_lock.  In
dcp_hfi_get_capabilities(), a timeout on cache->display_done only logs a
warning before jumping to out_free_cache and calling
dcp_hfi_caps_cache_stop() (and timeouts in dcp_hfi_send_device_init() or on
cache->device_done do the same):

CPU0                              CPU1 (resp_vq callback)
dcp_hfi_get_capabilities()
  wait_for_completion_timeout(
    &cache->display_done, ...)
    -> times out
  ...
  dcp_hfi_caps_cache_stop(hfi)
    memset(&hfi->caps_cache, 0, ...)
                                  dcp_hfi_dispatch_event()
                                    spin_lock_irqsave(&hfi->caps_lock)
                                    dcp_hfi_store_caps_payload(...,
                                      &hfi->caps_cache.display_done, ...)
                                      complete(&cache->display_done)
                                        swake_up_locked()
                                          <-- NULL pointer dereference

In swake_up_locked(), list_empty(&q->task_list) evaluates NULL ==
&q->task_list as false and dereferences NULL when waking the first entry.

In addition, dcp_hfi_dispatch_event() updates hfi->caps_cache under
hfi->caps_lock, whereas dcp_hfi_caps_cache_start(),
dcp_hfi_caps_cache_stop(), and dcp_hfi_get_capabilities() only hold
hfi->caps_cache_lock.  Because VIG_CAPS, DMA_CAPS, VIG_R1_CAPS, and
DMA_R1_CAPS do not signal a completion, dcp_hfi_get_capabilities() can read
and zero those buffers concurrently with dcp_hfi_store_caps_payload().

[ ... ]

> +static void dcp_hfi_parse_init_caps_kv(struct dcp_caps *caps,
> +                                    u32 prop_key,
> +                                    const u32 *payload,
> +                                    u32 max_words)
> +{
> +     u32 prop_id = HFI_PROP_ID(prop_key);
> +     u32 count, i;
> +
> +     if (!payload || !max_words)
> +             return;
> +
> +     switch (prop_id) {

[ ... ]

> +     case HFI_PROPERTY_DEVICE_INIT_VIG_INDICES:
> +             if (max_words < 1)
> +                     break;
> +             count = payload[0];
> +             if (count > max_words - 1)
> +                     count = max_words - 1;
> +             caps->num_vig_pipes = 0;
> +             caps->virt_vig_count = 0;
> +             for (i = 0; i < count; i++) {
> +                     u32 idx = payload[1 + i];
> +
> +                     if (DCP_REC_ID(idx) == 0) {
> +                             if (caps->num_vig_pipes < DCP_MAX_SSPP_COUNT)
> +                                     
> caps->vig_pipe_ids[caps->num_vig_pipes++] = idx;
> +                     } else {
> +                             if (caps->virt_vig_count < DCP_MAX_SSPP_COUNT)
> +                                     
> caps->vig_r1_indices[caps->virt_vig_count++] = idx;
> +                     }
> +             }
> +             break;
> +     case HFI_PROPERTY_DEVICE_INIT_DMA_INDICES:
> +             if (max_words < 1)
> +                     break;
> +             count = payload[0];
> +             if (count > max_words - 1)
> +                     count = max_words - 1;
> +             caps->num_dma_pipes = 0;
> +             caps->virt_dma_count = 0;
> +             for (i = 0; i < count; i++) {
> +                     u32 idx = payload[1 + i];
> +
> +                     if (DCP_REC_ID(idx) == 0) {
> +                             if (caps->num_dma_pipes < DCP_MAX_SSPP_COUNT)
> +                                     
> caps->dma_pipe_ids[caps->num_dma_pipes++] = idx;
> +                     } else {
> +                             if (caps->virt_dma_count < DCP_MAX_SSPP_COUNT)
> +                                     
> caps->dma_r1_indices[caps->virt_dma_count++] = idx;
> +                     }
> +             }
> +             break;

[Severity: High]
Does parsing cache->vig_r1_buf and cache->dma_r1_buf in
dcp_hfi_get_capabilities() wipe out caps->num_vig_pipes and
caps->num_dma_pipes?

Both primary (DCP_REC_ID(idx) == 0) and rect-1 (DCP_REC_ID(idx) != 0) pipe
lists use HFI_PROPERTY_DEVICE_INIT_VIG_INDICES and
HFI_PROPERTY_DEVICE_INIT_DMA_INDICES.  Because dcp_hfi_parse_init_caps_kv()
unconditionally zeroes both primary and virtual counts before looping,
parsing vig_r1_buf and dma_r1_buf after vig_buf and dma_buf resets
caps->num_vig_pipes and caps->num_dma_pipes to 0, causing caps->max_planes
to become 0 and dcp_hfi_get_capabilities() to fail with -EINVAL.

[ ... ]

> +static void dcp_hfi_log_pipe_ids(struct device *dev, const char *label,
> +                              const u32 *ids, u32 count)
> +{
> +     char buf[128];
> +     int pos = 0;
> +     u32 i;
> +
> +     for (i = 0; i < count && pos < (int)sizeof(buf) - 8; i++)
> +             pos += scnprintf(buf + pos, sizeof(buf) - pos,
> +                               "%s0x%x", i ? "," : "", ids[i]);
> +
> +     dev_dbg(dev, "%s: count=%u ids=[%s]\n", label, count, buf);
> +}

[Severity: Low]
If count is 0, the loop does not run and dev_dbg() prints buf uninitialized
from the stack.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=8

Reply via email to