From: sashiko-bot@kernel.org
To: oushixiong1025@163.com
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2] drm/sched: Create a fake device for KUnit tests
Date: Thu, 03 Sep 2026 12:26:48 +0000 [thread overview]
Message-ID: <20260903122649.8FA441F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260903121558.782854-1-oushixiong1025@163.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Mock scheduler workqueues are leaked and cause Use-After-Free on KUnit assertion failures.
--
commit cd473696df99f11e05b48a9d612fa14552094751
Author: Shixiong Ou <oushixiong@kylinos.cn>
drm/sched: Create a fake device for KUnit tests
This commit addresses a NULL-pointer dereference in the drm_sched_job trace
event by registering a mock device using kunit_device_register() and
assigning it to the scheduler arguments during test initialization.
> diff --git a/drivers/gpu/drm/scheduler/tests/mock_scheduler.c b/drivers/gpu/drm/scheduler/tests/mock_scheduler.c
> index 8e9ae7d980eb2..12dc61f56192e 100644
> --- a/drivers/gpu/drm/scheduler/tests/mock_scheduler.c
> +++ b/drivers/gpu/drm/scheduler/tests/mock_scheduler.c
[ ... ]
> @@ -297,11 +300,19 @@ struct drm_mock_scheduler *drm_mock_sched_new(struct kunit *test, long timeout)
> .name = "drm-mock-scheduler",
> };
> struct drm_mock_scheduler *sched;
> + struct device *dev;
> + char name[64];
> int ret;
>
> sched = kunit_kzalloc(test, sizeof(*sched), GFP_KERNEL);
> KUNIT_ASSERT_NOT_NULL(test, sched);
>
> + snprintf(name, sizeof(name), "%s-%u", args.name, ++instance);
> + dev = kunit_device_register(test, name);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
> +
> + args.dev = dev;
> +
> ret = drm_sched_init(&sched->base, &args);
[Severity: High]
This is a pre-existing issue, but does this allocation structure leave the
scheduler's submit workqueue vulnerable to a use-after-free on test failures?
In drm_sched_init(), a new submit_wq workqueue is created since
args->submit_wq is NULL. This workqueue is not managed by KUnit. If a test
encounters an assertion failure later (for example, hitting
KUNIT_ASSERT_TRUE(test, done) in drm_sched_basic_submit()), the KUnit
test thread is immediately aborted, bypassing manual cleanup routines like
drm_mock_sched_fini().
Because sched and sched->dev are managed by KUnit (via kunit_kzalloc
and kunit_device_register), they will be automatically freed upon test
abort. However, the unmanaged submit_wq remains active, and any pending
work items will execute and access the freed sched and sched->dev
memory, potentially causing a kernel crash.
Could a KUnit-managed cleanup hook like kunit_add_action() be used
after drm_sched_init() to ensure the workqueue is safely destroyed even if
the test thread aborts?
> KUNIT_ASSERT_EQ(test, ret, 0);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260903121558.782854-1-oushixiong1025@163.com?part=1
next prev parent reply other threads:[~2026-09-03 12:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 12:15 [PATCH v2] drm/sched: Create a fake device for KUnit tests oushixiong1025
2026-09-03 12:26 ` sashiko-bot [this message]
2026-09-03 12:38 ` Maxime Ripard
2026-09-04 7:02 ` Philipp Stanner
2026-09-08 5:58 ` Shixiong Ou
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=20260903122649.8FA441F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=oushixiong1025@163.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 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.