All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Linmao Li" <lilinmao@kylinos.cn>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH RESEND] drm/i915/guc: Return NULL for missing multi-lrc parent
Date: Mon, 06 Jul 2026 11:31:43 +0000	[thread overview]
Message-ID: <20260706113144.25F851F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260706111954.619602-1-lilinmao@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Uninitialized stack memory dereference in `logical_sort()` leading to kernel panic.
- [High] Memory corruption in `logical_sort()` due to incorrect pointer dereference in `memcpy()`.
--

commit c072d35be05423277bc1711d69cd5ba9043c2466
Author: Linmao Li <lilinmao@kylinos.cn>

drm/i915/guc: Return NULL for missing multi-lrc parent

multi_lrc_create_parent() returns ERR_PTR(0) when there are not enough engines.
This commit changes it to explicitly return NULL to make the non-error path
clear, as the caller already handles NULL.

> diff --git a/drivers/gpu/drm/i915/gt/uc/selftest_guc_multi_lrc.c b/drivers/gpu/drm/i915/gt/uc/selftest_guc_multi_lrc.c
> index 28e8a092f4e7d..18077801b2e60 100644
> --- a/drivers/gpu/drm/i915/gt/uc/selftest_guc_multi_lrc.c
> +++ b/drivers/gpu/drm/i915/gt/uc/selftest_guc_multi_lrc.c
> @@ -44,7 +44,7 @@ multi_lrc_create_parent(struct intel_gt *gt, u8 class,
>  	}
>  
>  	if (i <= 1)
> -		return ERR_PTR(0);
> +		return NULL;
>  
>  	logical_sort(siblings, i);

[Severity: High]
This is a pre-existing issue, but does logical_sort() dereference
uninitialized stack memory here?

In multi_lrc_create_parent(), the siblings array is allocated on the stack
and partially populated before being passed in:

    struct intel_engine_cs *siblings[MAX_ENGINE_INSTANCE + 1];
    // ... populated with i elements ...
    logical_sort(siblings, i);

However, the inner loop in logical_sort() unconditionally iterates past the
initialized num_engines:

selftest_guc_multi_lrc.c:logical_sort() {
    ...
    for (i = 0; i < num_engines; ++i)
        for (j = 0; j < MAX_ENGINE_INSTANCE + 1; ++j) {
            if (engines[j]->logical_mask & BIT(i)) {
    ...
}

If the mask condition is not met by the initialized elements, won't this
loop continue reading beyond num_engines, dereferencing uninitialized stack
memory as a struct intel_engine_cs pointer?

[Severity: High]
This is also a pre-existing issue, but can this call corrupt memory when
copying the sorted array?

At the end of logical_sort(), memcpy() is called with dereferenced array
pointers:

selftest_guc_multi_lrc.c:logical_sort() {
    ...
    memcpy(*engines, *sorted,
           sizeof(struct intel_engine_cs *) * num_engines);
}

Since engines is a double pointer (struct intel_engine_cs **), *engines
evaluates to the first engine object pointer rather than the array itself.

Will this cause memcpy() to overwrite the struct intel_engine_cs hardware
configuration memory directly, instead of updating the array of pointers?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260706111954.619602-1-lilinmao@kylinos.cn?part=1

      reply	other threads:[~2026-07-06 11:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-06 11:19 [PATCH RESEND] drm/i915/guc: Return NULL for missing multi-lrc parent Linmao Li
2026-07-06 11:31 ` sashiko-bot [this message]

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=20260706113144.25F851F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=lilinmao@kylinos.cn \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.