dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Maarten Lankhorst" <dev@lankhorst.se>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 01/10] drm/vblank_work: Add methods to schedule vblank_work in 2 stages
Date: Thu, 02 Jul 2026 07:32:17 +0000	[thread overview]
Message-ID: <20260702073218.413D61F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260702072154.171324-2-dev@lankhorst.se>

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

New issues:
- [High] Missing read memory barrier (`smp_rmb` or `smp_load_acquire`) when reading `work->armed` in `drm_handle_vblank_works` breaks transitive ordering.
- [Medium] `drm_vblank_work_schedule` early return logic fails to arm a disabled work if the target vblank count is identical.

Pre-existing issues:
- [High] Use-after-free risk due to calling `list_del_init(&work->node)` after `kthread_queue_work()`.
--

commit 2d70bdfd10b5fd90f1bf2ecac514ae3f86ae65ba
Author: Maarten Lankhorst <dev@lankhorst.se>

drm/vblank_work: Add methods to schedule vblank_work in 2 stages

In case of vblank evasion in intel/display, it's necessary to
perform some work in advance, so the critical section will always run in
constant time on PREEMPT_RT.

> diff --git a/drivers/gpu/drm/drm_vblank_work.c b/drivers/gpu/drm/drm_vblank_work.c
> index 70f0199251ea0..ed62c189fe041 100644
> --- a/drivers/gpu/drm/drm_vblank_work.c
> +++ b/drivers/gpu/drm/drm_vblank_work.c
> @@ -54,7 +54,8 @@ void drm_handle_vblank_works(struct drm_vblank_crtc *vblank)
>  	assert_spin_locked(&vblank->dev->event_lock);
>  
>  	list_for_each_entry_safe(work, next, &vblank->pending_work, node) {
> -		if (!drm_vblank_passed(count, work->count))
> +		/* READ_ONCE pairs with WRITE_ONCE in drm_vblank_work_enable() */
> +		if (!READ_ONCE(work->armed) || !drm_vblank_passed(count, work->count))
>  			continue;

[Severity: High]
Does this READ_ONCE() need a corresponding read memory barrier like
smp_rmb() or smp_load_acquire() to establish transitive ordering?

Since drm_vblank_work_enable() uses an smp_wmb() before writing to
work->armed, if the reader just uses READ_ONCE() here without an acquire
barrier before transferring the work via kthread_queue_work(), the memory
model doesn't guarantee the writer's data updates will be transitively
visible to the worker thread.

Could the kthread end up reading stale driver state as a result?

[ ... ]

> @@ -139,6 +118,7 @@ int drm_vblank_work_schedule(struct drm_vblank_work *work,
>  		rescheduling = true;
>  	}
>  
> +	work->armed = armed;
>  	work->count = count;

[Severity: Medium]
Does the early return logic in __drm_vblank_work_schedule() break if a work
item is first scheduled disabled, and then re-scheduled to be armed with the
exact same target count?

Earlier in __drm_vblank_work_schedule(), if work->count == count, the function
takes an early return:

	} else if (work->count == count) {
		/* Already scheduled w/ same vbl count */
		goto out;
	} else {

If a driver uses drm_vblank_work_schedule_disabled() to schedule the work,
and later calls drm_vblank_work_schedule() with the exact same count to arm it,
doesn't the early return bypass this new work->armed = armed assignment?

Could this leave the work permanently disabled and never executed?

[ ... ]

> @@ -147,7 +127,7 @@ int drm_vblank_work_schedule(struct drm_vblank_work *work,
>  			     "crtc %d vblank %llu already passed (current %llu)\n",
>  			     vblank->pipe, count, cur_vbl);
>  
> -	if (!nextonmiss && passed) {
> +	if (!nextonmiss && passed && armed) {
>  		drm_vblank_put(dev, vblank->pipe);
>  		ret = kthread_queue_work(vblank->worker, &work->base);
>  

[Severity: High]
This is a pre-existing issue, but is there a use-after-free risk here when
rescheduling a work item that has already passed?

If rescheduling is true, the code right below this in
__drm_vblank_work_schedule() does:

		ret = kthread_queue_work(vblank->worker, &work->base);

		if (rescheduling) {
			list_del_init(&work->node);
			wake = true;
		}

Since kthread_queue_work() immediately places the work on the worker's queue,
could the worker thread run concurrently and execute the work before
list_del_init() is called on the current CPU?

If the work is freed by the executing kthread, the list_del_init() call
would then access freed memory.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260702072154.171324-1-dev@lankhorst.se?part=1

  reply	other threads:[~2026-07-02  7:32 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-02  7:21 [PATCH 00/10] drm/intel/display: Changes required to make vblank evasion PREEMPT_RT safe Maarten Lankhorst
2026-07-02  7:21 ` [PATCH 01/10] drm/vblank_work: Add methods to schedule vblank_work in 2 stages Maarten Lankhorst
2026-07-02  7:32   ` sashiko-bot [this message]
2026-07-02  7:21 ` [PATCH 02/10] drm/vblank: Add a 2-stage version of drm_crtc_arm_vblank_event Maarten Lankhorst
2026-07-02  7:35   ` sashiko-bot
2026-07-02  7:21 ` [PATCH 03/10] drm/intel/display: Make intel_crtc_arm_vblank_event static Maarten Lankhorst
2026-07-10 14:20   ` Ville Syrjälä
2026-07-02  7:21 ` [PATCH 04/10] drm/intel/display: Convert vblank event handling to 2-stage arming Maarten Lankhorst
2026-07-02  7:37   ` sashiko-bot
2026-07-02  7:21 ` [PATCH 05/10] drm/i915/display: Move vblank put until after critical section Maarten Lankhorst
2026-07-02  7:34   ` sashiko-bot
2026-07-02  7:21 ` [PATCH 06/10] drm/i915/display: Remove locking from intel_vblank_evade " Maarten Lankhorst
2026-07-02  7:36   ` sashiko-bot
2026-07-02  7:21 ` [PATCH 07/10] drm/i915/display: Handle vlv dsi workaround in scanline_in_safe_range too Maarten Lankhorst
2026-07-02  7:30   ` sashiko-bot
2026-07-02  7:21 ` [PATCH 08/10] drm/i915: Use preempt_disable/enable_rt() where recommended Maarten Lankhorst
2026-07-02  7:36   ` sashiko-bot
2026-07-02  7:21 ` [PATCH 09/10] drm/i915/display: Make get_vblank_counter use intel_de_read_fw() Maarten Lankhorst
2026-07-02  7:43   ` sashiko-bot
2026-07-10 14:34   ` Ville Syrjälä
2026-07-02  7:21 ` [PATCH 10/10] drm/i915/display: Do not take uncore lock in i915_get_vblank_counter Maarten Lankhorst
2026-07-10 14:19   ` Ville Syrjälä
2026-07-10 14:43 ` [PATCH 00/10] drm/intel/display: Changes required to make vblank evasion PREEMPT_RT safe Ville Syrjälä

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=20260702073218.413D61F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dev@lankhorst.se \
    --cc=dri-devel@lists.freedesktop.org \
    --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