From: sashiko-bot@kernel.org
To: "Piórkowski, Piotr" <piotr.piorkowski@intel.com>
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v2 2/4] drm/xe/kunit: Extend GuC ID manager split-pool coverage
Date: Mon, 17 Aug 2026 09:23:59 +0000 [thread overview]
Message-ID: <20260817092400.07EA41F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260817091013.280173-3-piotr.piorkowski@intel.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Out-of-bounds memory write via `bitmap_clear()` if a resource allocation fails during KUnit tests.
--
--- Patch [2]: [PATCH v2 2/4] drm/xe/kunit: Extend GuC ID manager split-pool coverage ---
commit de07034d7b51f00db6617697a552f2ac15c74f32
Author: Piotr Piórkowski <piotr.piorkowski@intel.com>
drm/xe/kunit: Extend GuC ID manager split-pool coverage
Expand the GuC ID manager KUnit coverage to exercise the new
usable/shareable pool model.
> diff --git a/drivers/gpu/drm/xe/tests/xe_guc_id_mgr_test.c b/drivers/gpu/drm/xe/tests/xe_guc_id_mgr_test.c
> index 103ea82d278e3..295c17dbc21fb 100644
> --- a/drivers/gpu/drm/xe/tests/xe_guc_id_mgr_test.c
> +++ b/drivers/gpu/drm/xe/tests/xe_guc_id_mgr_test.c
[ ... ]
> +static void check_used_usable(struct kunit *test)
> +{
> + struct xe_guc_id_mgr *idm = test->priv;
> + int id;
> +
> + KUNIT_ASSERT_EQ(test, 0, idm_init(idm, 8, 8));
> +
> + mutex_lock(idm_mutex(idm));
> +
> + KUNIT_EXPECT_EQ(test, idm_used_usable(idm), 0);
> + KUNIT_EXPECT_EQ(test, idm_used_shareable(idm), 0);
> +
> + id = xe_guc_id_mgr_reserve_usable_locked(idm, 2);
> + KUNIT_EXPECT_GE(test, id, 0);
[Severity: High]
The commit message notes that KUNIT_EXPECT is used instead of KUNIT_ASSERT to
avoid leaking the mutex on failure. However, if the reservation fails and
returns a negative error code, KUNIT_EXPECT_GE() will allow execution to
continue.
Since idm_release_chunk_locked() takes an unsigned int for the start position,
will passing a negative id result in an implicit cast to a huge unsigned
integer, causing an out-of-bounds write in bitmap_clear() when the chunk is
released below?
Would it be better to use a conditional check to handle the error and unlock
the mutex before returning, rather than letting the test continue with a
negative id?
> +
> + KUNIT_EXPECT_EQ(test, idm_used_usable(idm), 2);
> + KUNIT_EXPECT_EQ(test, idm_used_shareable(idm), 0);
> + KUNIT_EXPECT_EQ(test, idm_used_total(idm), 2);
> +
> + idm_release_chunk_locked(idm, id, 2);
> + KUNIT_EXPECT_EQ(test, idm_used_total(idm), 0);
> +
> + mutex_unlock(idm_mutex(idm));
> +}
> +
> +static void check_used_shareable(struct kunit *test)
> +{
> + struct xe_guc_id_mgr *idm = test->priv;
> + unsigned int shareable_start;
> + int id;
> +
> + KUNIT_ASSERT_EQ(test, 0, idm_init(idm, 8, 8));
> +
> + mutex_lock(idm_mutex(idm));
> + shareable_start = idm_shareable_start(idm);
> +
> + KUNIT_EXPECT_EQ(test, idm_used_usable(idm), 0);
> + KUNIT_EXPECT_EQ(test, idm_used_shareable(idm), 0);
> +
> + id = xe_guc_id_mgr_reserve_shareable_locked(idm, 3, 0);
> + KUNIT_EXPECT_EQ(test, id, shareable_start);
[Severity: High]
Could the same out-of-bounds write happen here if id is a negative error
code? KUNIT_EXPECT_EQ() does not abort the test, so idm_release_chunk_locked()
would process a negative id.
> +
> + KUNIT_EXPECT_EQ(test, idm_used_usable(idm), 0);
> + KUNIT_EXPECT_EQ(test, idm_used_shareable(idm), 3);
> + KUNIT_EXPECT_EQ(test, idm_used_total(idm), 3);
> +
> + idm_release_chunk_locked(idm, id, 3);
> + KUNIT_EXPECT_EQ(test, idm_used_total(idm), 0);
> +
> + mutex_unlock(idm_mutex(idm));
> +}
[ ... ]
> +static void check_shareable_spare(struct kunit *test)
> +{
> + struct xe_guc_id_mgr *idm = test->priv;
> + unsigned int pools_size = (GUC_ID_MAX / 3) * 2;
> + unsigned int shareable_start;
> + unsigned int overlap_size;
> + unsigned int shared_tail;
> + int id_tail, id_overlap;
> +
> + KUNIT_ASSERT_EQ(test, 0, idm_init(idm, pools_size, pools_size));
> +
> + mutex_lock(idm_mutex(idm));
> + shareable_start = idm_shareable_start(idm);
> + overlap_size = idm->usable - shareable_start;
> + shared_tail = idm_total(idm) - idm->usable;
> +
> + KUNIT_EXPECT_GT(test, overlap_size, 0);
> + KUNIT_EXPECT_GT(test, shared_tail, 0);
> +
> + id_tail = xe_guc_id_mgr_reserve_shareable_locked(idm, shared_tail, 1);
> + KUNIT_EXPECT_EQ(test, id_tail, idm->usable);
[Severity: High]
Similar to the above, if id_tail is assigned a negative error code upon failure,
it will eventually be passed to idm_release_chunk_locked() since KUNIT_EXPECT_EQ()
does not halt execution.
> + KUNIT_EXPECT_EQ(test, idm_used_shareable(idm), shared_tail);
> +
> + id_overlap = xe_guc_id_mgr_reserve_shareable_locked(idm, overlap_size - 1, 1);
> + KUNIT_EXPECT_EQ(test, id_overlap, shareable_start + 1);
[Severity: High]
If id_overlap is negative, will this also result in an out-of-bounds write
when calling idm_release_chunk_locked() later in the function?
> + KUNIT_EXPECT_EQ(test, idm_used_shareable(idm), idm->shareable - 1);
> +
> + KUNIT_EXPECT_EQ(test, xe_guc_id_mgr_reserve_shareable_locked(idm, 1, 1), -EDQUOT);
> + KUNIT_EXPECT_EQ(test, idm_used_shareable(idm), idm->shareable - 1);
> +
> + idm_release_chunk_locked(idm, id_tail, shared_tail);
> + idm_release_chunk_locked(idm, id_overlap, overlap_size - 1);
> + KUNIT_EXPECT_EQ(test, idm_used_shareable(idm), 0);
> +
> + mutex_unlock(idm_mutex(idm));
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260817091013.280173-1-piotr.piorkowski@intel.com?part=2
next prev parent reply other threads:[~2026-08-17 9:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 9:10 [PATCH v2 0/4] Split GuC ID space into usable and shareable pools Piórkowski, Piotr
2026-08-17 9:10 ` [PATCH v2 1/4] drm/xe/guc: Split GuC ID manager " Piórkowski, Piotr
2026-08-17 9:24 ` sashiko-bot
2026-08-17 9:10 ` [PATCH v2 2/4] drm/xe/kunit: Extend GuC ID manager split-pool coverage Piórkowski, Piotr
2026-08-17 9:23 ` sashiko-bot [this message]
2026-08-17 9:10 ` [PATCH v2 3/4] drm/xe/guc: Start use explicitly usable GuC IDs for for submission Piórkowski, Piotr
2026-08-17 9:10 ` [PATCH v2 4/4] drm/xe/pf: Explicitly use shareable GuC IDs for VFs provisioning Piórkowski, Piotr
2026-08-17 9:24 ` sashiko-bot
2026-08-17 13:01 ` ✗ CI.checkpatch: warning for Split GuC ID space into usable and shareable pools (rev2) Patchwork
2026-08-17 13:03 ` ✓ CI.KUnit: success " Patchwork
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=20260817092400.07EA41F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=piotr.piorkowski@intel.com \
--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