From: sashiko-bot@kernel.org
To: "Ville Syrjala" <ville.syrjala@linux.intel.com>,
dri-devel@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org
Subject: Re: [PATCH 6/6] drm/tests: Test limiting the run-ahead of fake commit only commits
Date: Tue, 17 Nov 2026 20:23:35 +0000 [thread overview]
Message-ID: <sashiko-outbox-219593@kernel.org> (raw)
In-Reply-To: <20261117200253.27078-7-ville.syrjala@linux.intel.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/tests: race on inflight counter in
drm_test_flood_commit_work()
- [Medium] drm/tests: premature inflight dec in
drm_test_flood_commit_work() causes UAF
--
commit 6c86373dc620a9330ac1f7518a644a35a7fe6819
Author: Ville Syrjälä <ville.syrjala@linux.intel.com>
drm/tests: Test limiting the run-ahead of fake commit only commits
This commit adds a KUnit test that floods nonblocking commits touching only
an unbound plane with swap_state(stall=false) to verify that in-flight
commits stay bounded and do not time out waiting for hw_done.
> diff --git a/drivers/gpu/drm/tests/drm_atomic_commit_test.c b/drivers/gpu/drm/tests/drm_atomic_commit_test.c
> index 593e1842fada2..247b5a916b585 100644
> --- a/drivers/gpu/drm/tests/drm_atomic_commit_test.c
> +++ b/drivers/gpu/drm/tests/drm_atomic_commit_test.c
[ ... ]
> @@ -495,6 +496,88 @@ static void drm_test_fake_commit_not_busy(struct kunit *test)
> drm_modeset_acquire_fini(&ctx);
> }
>
> +static atomic_t drm_test_flood_inflight, drm_test_flood_max, drm_test_flood_timeouts;
> +
> +static void drm_test_flood_commit_work(struct work_struct *work)
> +{
> + struct drm_atomic_commit *state =
> + container_of(work, struct drm_atomic_commit, commit_work);
> + struct drm_plane *plane;
> + struct drm_plane_state *old_plane_state;
> + int i;
> +
> + for_each_old_plane_in_state(state, plane, old_plane_state, i)
> + if (drm_crtc_commit_wait(old_plane_state->commit))
> + atomic_inc(&drm_test_flood_timeouts);
> +
> + /* Pretend to do some work */
> + msleep(2);
> +
> + drm_atomic_helper_commit_hw_done(state);
> + drm_atomic_helper_commit_cleanup_done(state);
> + atomic_dec(&drm_test_flood_inflight);
> + drm_atomic_commit_put(state);
> +}
[Severity: Medium]
Can decrementing drm_test_flood_inflight before drm_atomic_commit_put(state)
cause a use-after-free on dev->driver during test teardown?
CPU0 (kunit) CPU1 (kworker)
drm_test_fake_commit_flood() drm_test_flood_commit_work()
/* sees inflight == 0 */ atomic_dec(&drm_test_flood_inflight)
kunit_cleanup()
...
devres_release_all(dev)
/* frees dev->driver */
drm_atomic_commit_put(state)
__drm_atomic_commit_free()
drm_dev_put(dev)
drm_dev_release()
dev->driver->release
<-- use-after-free
__drm_kunit_helper_alloc_drm_device() allocates struct drm_driver with
devm_kzalloc_obj(dev, *driver), while each drm_atomic_commit holds a
drm_device reference via drm_dev_get() until __drm_atomic_commit_free().
Because drm_test_fake_commit_flood() only waits for drm_test_flood_inflight
to reach 0 without flushing the work items, KUnit cleanup can unregister the
mock device and free dev->driver before the final worker finishes
drm_atomic_commit_put(state).
> +
> +/*
> + * Test that a flood of nonblocking commits that only touch an unbound plane
> + * can not queue up an unbounded number of commits, even if the driver does not
> + * ask swap_state() to stall. Otherwise the work items would all wait for the
> + * hw_done of their predecessor, and the waits would add up.
> + */
> +static void drm_test_fake_commit_flood(struct kunit *test)
> +{
[ ... ]
> + INIT_WORK(&state->commit_work, drm_test_flood_commit_work);
> + queue_work(system_dfl_wq, &state->commit_work);
> +
> + drm_modeset_drop_locks(&ctx);
> + drm_modeset_acquire_fini(&ctx);
> + }
> +
> + while (atomic_read(&drm_test_flood_inflight))
> + msleep(10);
> +
> + /*
> + * The previous commit may still be doing its cleanup when the next
> + * one is submitted, hence 2 rather than 1.
> + */
> + KUNIT_EXPECT_LE(test, atomic_read(&drm_test_flood_max), 2);
[Severity: Medium]
Can drm_test_flood_max exceed 2 when workers on system_dfl_wq are preempted
between drm_atomic_helper_commit_hw_done() and
atomic_dec(&drm_test_flood_inflight)?
drm_atomic_helper_commit_hw_done(state) completes state->fake_commit->hw_done,
which immediately unblocks stall_for_fake_commit() in
drm_atomic_helper_setup_commit() for the next commit on the test thread.
Neither stall_for_fake_commit() nor drm_crtc_commit_wait() waits for
cleanup_done or work completion, and system_dfl_wq is an unbound workqueue
that can run multiple workers concurrently. If more than one worker is
preempted after signaling hw_done before reaching
atomic_dec(&drm_test_flood_inflight), drm_test_flood_max will be greater than
2 and fail the expectation. In addition, exiting the wait loop as soon as
drm_test_flood_inflight reaches 0 without flushing the work items allows test
teardown to race with the final drm_atomic_commit_put(state).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117200253.27078-1-ville.syrjala@linux.intel.com?part=6
next prev parent reply other threads:[~2026-11-17 20:23 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 20:02 [PATCH 0/6] drm/atomic-helper: Eliminate the fake_commit spurious -EBUSYs Ville Syrjala
2026-11-17 20:02 ` [PATCH 1/6] drm/atomic-helper: Limit run-ahead of fake commit only commits Ville Syrjala
2026-11-17 20:02 ` [PATCH 2/6] drm/atomic-helper: Complete fake_commit->flip_done in setup_commit Ville Syrjala
2026-11-17 20:02 ` [PATCH 3/6] drm/tests: Test fake_commit->flip_done completion Ville Syrjala
2026-11-17 20:02 ` [PATCH 4/6] drm/atomic: Store the device in drm_crtc_commit Ville Syrjala
2026-11-17 20:14 ` sashiko-bot
2026-11-17 20:02 ` [PATCH 5/6] drm/tests: Test the device stored " Ville Syrjala
2026-11-17 20:02 ` [PATCH 6/6] drm/tests: Test limiting the run-ahead of fake commit only commits Ville Syrjala
2026-11-17 20:23 ` sashiko-bot [this message]
2026-11-17 20:16 ` ✗ CI.checkpatch: warning for drm/atomic-helper: Eliminate the fake_commit spurious -EBUSYs Patchwork
2026-11-17 20:18 ` ✓ CI.KUnit: success " Patchwork
2026-11-17 20:57 ` ✓ Xe.CI.BAT: " Patchwork
2026-11-17 21:04 ` ✓ i915.CI.BAT: " Patchwork
2026-11-18 0:36 ` ✗ i915.CI.Full: failure " 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=sashiko-outbox-219593@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=ville.syrjala@linux.intel.com \
/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.