All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Umesh Nerlige Ramappa" <umesh.nerlige.ramappa@intel.com>,
	intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH v3 1/2] drm/i915/guc: Use a delayed wakeref put in guc_engine_busyness()
Date: Thu, 03 Dec 2026 20:09:10 +0000	[thread overview]
Message-ID: <sashiko-outbox-248591@kernel.org> (raw)
In-Reply-To: <20261203194610.2030696-5-umesh.nerlige.ramappa@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/i915/gt: intel_gt_pm_put_delay() can wake kswapd under rq
  lock
- [Medium] drm/i915/gt: intel_gt_pm_put_delay() breaks scheduler safety
  on DEBUG_WAKEREF
--

commit 0ade1154ca3e2c5818eb07814d5eadbfbfdf75dd
Author: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>

drm/i915/guc: Use a delayed wakeref put in guc_engine_busyness()

This commit adds intel_gt_pm_put_delay() to defer releasing the final GT
wakeref on a timer, and switches guc_engine_busyness() to use it with a
1 jiffy delay to avoid waking a workqueue worker under a runqueue lock.

> diff --git a/drivers/gpu/drm/i915/gt/intel_gt_pm.h b/drivers/gpu/drm/i915/gt/intel_gt_pm.h
> index 6f25c747bc29b..24c8b014864d8 100644
> --- a/drivers/gpu/drm/i915/gt/intel_gt_pm.h
> +++ b/drivers/gpu/drm/i915/gt/intel_gt_pm.h
> @@ -72,6 +72,30 @@ static inline void intel_gt_pm_put_async(struct intel_gt *gt, intel_wakeref_t ha
>  	intel_gt_pm_put_async_untracked(gt);
>  }
>  
> +/**
> + * intel_gt_pm_put_delay - release the GT wakeref, deferred by a timer
> + *
> + * @gt: pointer to the gt
> + * @handle: the handle returned by the matching intel_gt_pm_get*()
> + * @delay: delay, in jiffies, before the release is processed
> + *
> + * As intel_gt_pm_put_async(), except that dropping the last reference arms a
> + * timer instead of queueing the release immediately.
> + *
> + * intel_gt_pm_put_async() ends up in mod_delayed_work() with a zero delay,
> + * which queues the work straight away and so wakes a workqueue worker through
> + * try_to_wake_up(). That deadlocks if the caller already holds a runqueue
> + * lock, since try_to_wake_up() then tries to take it again. Callers which can
> + * run from inside the scheduler must use this variant with a non-zero @delay,
> + * which takes the add_timer_on() path and never wakes a task.
> + */
> +static inline void intel_gt_pm_put_delay(struct intel_gt *gt, intel_wakeref_t handle,
> +					 unsigned long delay)
> +{
> +	intel_wakeref_untrack(&gt->wakeref, handle);
> +	intel_wakeref_put_delay(&gt->wakeref, delay);
> +}

[Severity: Medium]
Does intel_gt_pm_put_delay() violate raw spinlock nesting when
CONFIG_DRM_I915_DEBUG_WAKEREF is enabled?

When called from scheduler context with raw_spinlock_t rq->__lock held
(prepare_task_switch() -> perf_cgroup_switch() -> i915_pmu_event_del()),
intel_wakeref_untrack() calls ref_tracker_free(), which takes non-raw
dir->lock and calls kfree(), triggering CONFIG_PROVE_RAW_LOCK_NESTING.

ref_tracker_free() also calls stack_depot_save() with GFP_NOWAIT, which
can wake kswapd and self-deadlock on rq->__lock under memory pressure.
Commit "drm/i915/pmu: Use a delayed wakeref put in get_rc6()" reuses
intel_gt_pm_put_delay() with the same issue.

> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
> index 788e59cdfac9b..32d722c378e84 100644
> --- a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
> +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
> @@ -1361,7 +1361,12 @@ static ktime_t guc_engine_busyness(struct intel_engine_cs *engine, ktime_t *now)
>  		 */
>  		guc_update_engine_gt_clks(engine);
>  		guc_update_pm_timestamp(guc, now);
> -		intel_gt_pm_put_async(gt, wakeref);
> +		/*
> +		 * We are reached from the perf callbacks, which perf may invoke
> +		 * from the scheduler with the runqueue lock held. Defer the put
> +		 * on a timer so that it can never wake a task from here.
> +		 */
> +		intel_gt_pm_put_delay(gt, wakeref, 1);

[Severity: Medium]
Can the tracked wakeref pair here still wake kswapd and deadlock on
rq->__lock when CONFIG_DRM_I915_DEBUG_WAKEREF is enabled?

Both intel_gt_pm_get_if_awake() and intel_gt_pm_put_delay() invoke
ref_tracker with GFP_NOWAIT, which includes __GFP_KSWAPD_RECLAIM.
stack_depot_save_flags() preserves that flag via gfp_nested_mask() when
allocating a new depot pool.

Under memory pressure, alloc_pages() enters __alloc_pages_slowpath() ->
wakeup_kswapd() -> try_to_wake_up(), self-deadlocking on rq->__lock while
guc->timestamp.lock is held and stalling __guc_context_update_stats().
Untracked get_if_awake and put_delay helpers would avoid ref_tracker.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203194610.2030696-4-umesh.nerlige.ramappa@intel.com?part=1

  reply	other threads:[~2026-12-03 20:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 19:46 [PATCH v3 0/2] Fixup deadlock scenarios in the PMU path Umesh Nerlige Ramappa
2026-12-03 19:46 ` [PATCH v3 1/2] drm/i915/guc: Use a delayed wakeref put in guc_engine_busyness() Umesh Nerlige Ramappa
2026-12-03 20:09   ` sashiko-bot [this message]
2026-12-03 19:46 ` [PATCH v3 2/2] drm/i915/pmu: Use a delayed wakeref put in get_rc6() Umesh Nerlige Ramappa
2026-12-03 22:09 ` ✓ i915.CI.BAT: success for Fixup deadlock scenarios in the PMU path (rev3) Patchwork
2026-12-04 10:36 ` ✓ i915.CI.Full: " 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-248591@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=umesh.nerlige.ramappa@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.