From: Jonathan Cavitt <jonathan.cavitt@intel.com>
To: intel-gfx@lists.freedesktop.org
Cc: saurabhg.gupta@intel.com, alex.zuo@intel.com, jonathan.cavitt@intel.com
Subject: [PATCH] drm/i915/gt: Enforce some loop limits
Date: Tue, 3 Mar 2026 18:15:32 +0000 [thread overview]
Message-ID: <20260303181531.9953-2-jonathan.cavitt@intel.com> (raw)
The functions intel_guc_send_busy_loop and ct_send can theoretically
loop forever. In the former case, intel_guc_send_busy_loop can iterate
forever if intel_guc_send_nb repeatedly returns -EBUSY. In the latter
case, ct_send can loop forever if the guc-to-host or host-to-guc buffers
get stuck in a full state.
Rework the sleep_period_ms values here to count the number of loops that
have occurred and exit after 20. This lets both functions run for 10
minutes before escaping with -EBUSY (except in the former case if atomic
execution is enabled, but 20 consecutive failures in that case should
still be reported regardless).
This also technically solves a static analysis issue wherein
sleep_period_ms could overflow, but it would take over three weeks of
perpetual sleeping on these functions to ever hit that overflow, so it's
debatable whether this actually needed fixing or not. At any rate, it's
better to exit early in the error case.
Signed-off-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
---
drivers/gpu/drm/i915/gt/uc/intel_guc.h | 10 +++++++---
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 8 +++++---
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc.h b/drivers/gpu/drm/i915/gt/uc/intel_guc.h
index 053780f562c1..b4bf12193f75 100644
--- a/drivers/gpu/drm/i915/gt/uc/intel_guc.h
+++ b/drivers/gpu/drm/i915/gt/uc/intel_guc.h
@@ -361,7 +361,7 @@ static inline int intel_guc_send_busy_loop(struct intel_guc *guc,
bool loop)
{
int err;
- unsigned int sleep_period_ms = 1;
+ unsigned int loop_count = 0;
bool not_atomic = !in_atomic() && !irqs_disabled();
/*
@@ -377,13 +377,17 @@ static inline int intel_guc_send_busy_loop(struct intel_guc *guc,
retry:
err = intel_guc_send_nb(guc, action, len, g2h_len_dw);
if (unlikely(err == -EBUSY && loop)) {
+ if (loop_count >= 20)
+ return -EBUSY;
+
if (likely(not_atomic)) {
- if (msleep_interruptible(sleep_period_ms))
+ if (msleep_interruptible(1 << loop_count))
return -EINTR;
- sleep_period_ms = sleep_period_ms << 1;
} else {
cpu_relax();
}
+
+ loop_count++;
goto retry;
}
diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c
index 8c4da526d461..e4a5697622c8 100644
--- a/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c
+++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c
@@ -716,7 +716,7 @@ static int ct_send(struct intel_guc_ct *ct,
struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;
struct ct_request request;
unsigned long flags;
- unsigned int sleep_period_ms = 1;
+ unsigned int loop_count = 0;
bool send_again;
u32 fence;
int err;
@@ -747,9 +747,11 @@ static int ct_send(struct intel_guc_ct *ct,
if (unlikely(ct_deadlocked(ct)))
return -EPIPE;
- if (msleep_interruptible(sleep_period_ms))
+ if (loop_count >= 20)
+ return -EBUSY;
+
+ if (msleep_interruptible(1 << loop_count++))
return -EINTR;
- sleep_period_ms = sleep_period_ms << 1;
goto retry;
}
--
2.43.0
next reply other threads:[~2026-03-03 18:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-03 18:15 Jonathan Cavitt [this message]
2026-03-03 20:36 ` ✓ i915.CI.BAT: success for drm/i915/gt: Enforce some loop limits Patchwork
2026-03-04 8:09 ` ✗ 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=20260303181531.9953-2-jonathan.cavitt@intel.com \
--to=jonathan.cavitt@intel.com \
--cc=alex.zuo@intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=saurabhg.gupta@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.