From: Andi Shyti <andi.shyti@kernel.org>
To: Sebastian Brzezinka <sebastian.brzezinka@intel.com>
Cc: intel-gfx@lists.freedesktop.org, andi.shyti@linux.intel.com,
krzysztof.karas@intel.com
Subject: Re: [PATCH] drm/i915/gt: fix refcount underflow in intel_engine_park_heartbeat
Date: Wed, 1 Apr 2026 23:26:07 +0200 [thread overview]
Message-ID: <ac2KBMAJHRkV4d7s@zenone.zhora.eu> (raw)
In-Reply-To: <d4c1c14255688dd07cc8044973c4f032a8d1559e.1775038106.git.sebastian.brzezinka@intel.com>
Hi Sebastian,
...
> Fix this by replacing the non-atomic pointer read + separate clear with
> xchg() in both racing paths. xchg() is a single indivisible hardware
> instruction that atomically reads the old pointer and writes NULL. This
> guarantees only one of the two concurrent callers obtains the non-NULL
> pointer and performs the put, the other gets NULL and skips it.
>
> Closes: https://gitlab.freedesktop.org/drm/i915/kernel/-/work_items/15880
> Fixes: 058179e72e09 ("drm/i915/gt: Replace hangcheck by heartbeats")
Cc: <stable@vger.kernel.org> # v5.5+
> Signed-off-by: Sebastian Brzezinka <sebastian.brzezinka@intel.com>
> ---
> .../gpu/drm/i915/gt/intel_engine_heartbeat.c | 26 +++++++++++++------
> 1 file changed, 18 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c b/drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c
> index b279878dca29..a3830627ef81 100644
> --- a/drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c
> +++ b/drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c
> @@ -148,10 +148,12 @@ static void heartbeat(struct work_struct *wrk)
> /* Just in case everything has gone horribly wrong, give it a kick */
> intel_engine_flush_submission(engine);
>
> - rq = engine->heartbeat.systole;
> - if (rq && i915_request_completed(rq)) {
> - i915_request_put(rq);
> - engine->heartbeat.systole = NULL;
> + rq = xchg(&engine->heartbeat.systole, NULL);
> + if (rq) {
> + if (i915_request_completed(rq))
> + i915_request_put(rq);
> + else
> + engine->heartbeat.systole = rq;
Well spotted, Sebastian!
> }
>
> if (!intel_engine_pm_get_if_awake(engine))
> @@ -232,8 +234,11 @@ static void heartbeat(struct work_struct *wrk)
> unlock:
> mutex_unlock(&ce->timeline->mutex);
> out:
> - if (!engine->i915->params.enable_hangcheck || !next_heartbeat(engine))
> - i915_request_put(fetch_and_zero(&engine->heartbeat.systole));
> + if (!engine->i915->params.enable_hangcheck || !next_heartbeat(engine)) {
> + rq = xchg(&engine->heartbeat.systole, NULL);
> + if (rq)
> + i915_request_put(rq);
> + }
> intel_engine_pm_put(engine);
> }
>
> @@ -247,8 +252,13 @@ void intel_engine_unpark_heartbeat(struct intel_engine_cs *engine)
>
> void intel_engine_park_heartbeat(struct intel_engine_cs *engine)
> {
> - if (cancel_delayed_work(&engine->heartbeat.work))
> - i915_request_put(fetch_and_zero(&engine->heartbeat.systole));
> + struct i915_request *rq;
nit: this should go inside the if statement.
Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
Nice patch, Sebastian. Two very little nitpicks that I can take
care of before merging.
Thank you,
Andi
> + if (cancel_delayed_work(&engine->heartbeat.work)) {
> + rq = xchg(&engine->heartbeat.systole, NULL);
> + if (rq)
> + i915_request_put(rq);
> + }
> }
>
> void intel_gt_unpark_heartbeats(struct intel_gt *gt)
> --
> 2.52.0
>
next prev parent reply other threads:[~2026-04-01 21:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-01 10:10 [PATCH] drm/i915/gt: fix refcount underflow in intel_engine_park_heartbeat Sebastian Brzezinka
2026-04-01 13:07 ` ✓ i915.CI.BAT: success for " Patchwork
2026-04-01 21:26 ` Andi Shyti [this message]
2026-04-02 6:10 ` ✗ i915.CI.Full: failure " Patchwork
2026-04-02 12:40 ` ✓ i915.CI.BAT: success for drm/i915/gt: fix refcount underflow in intel_engine_park_heartbeat (rev2) Patchwork
2026-04-03 9:06 ` [PATCH] drm/i915/gt: fix refcount underflow in intel_engine_park_heartbeat Krzysztof Karas
2026-04-03 10:05 ` ✗ i915.CI.Full: failure for drm/i915/gt: fix refcount underflow in intel_engine_park_heartbeat (rev2) Patchwork
2026-04-07 10:06 ` ✓ i915.CI.BAT: success for drm/i915/gt: fix refcount underflow in intel_engine_park_heartbeat (rev3) Patchwork
2026-04-07 12:28 ` ✗ i915.CI.Full: failure " Patchwork
2026-04-07 16:06 ` [PATCH] drm/i915/gt: fix refcount underflow in intel_engine_park_heartbeat Andi Shyti
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=ac2KBMAJHRkV4d7s@zenone.zhora.eu \
--to=andi.shyti@kernel.org \
--cc=andi.shyti@linux.intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=krzysztof.karas@intel.com \
--cc=sebastian.brzezinka@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox