Skip to content

Commit a5606b9

Browse files
mwajdeczjohnharr-intel
authored andcommitted
drm/i915/guc: Track all sent actions to GuC
For easier debug of any unexpected error responses from GuC that might be related to non-blocking fast requests, track action code (and stack if under DEBUG_GUC config) for every H2G request. Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com> Signed-off-by: John Harrison <John.C.Harrison@Intel.com> Reviewed-by: John Harrison <John.C.Harrison@Intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20230526235538.2230780-4-John.C.Harrison@Intel.com
1 parent d991102 commit a5606b9

3 files changed

Lines changed: 77 additions & 3 deletions

File tree

drivers/gpu/drm/i915/Kconfig.debug

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ config DRM_I915_SW_FENCE_CHECK_DAG
157157
config DRM_I915_DEBUG_GUC
158158
bool "Enable additional driver debugging for GuC"
159159
depends on DRM_I915
160+
select STACKDEPOT
160161
default n
161162
help
162163
Choose this option to turn on extra driver debugging that may affect

drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,24 @@ void intel_guc_ct_disable(struct intel_guc_ct *ct)
376376
}
377377
}
378378

379+
#if IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)
380+
static void ct_track_lost_and_found(struct intel_guc_ct *ct, u32 fence, u32 action)
381+
{
382+
unsigned int lost = fence % ARRAY_SIZE(ct->requests.lost_and_found);
383+
#if IS_ENABLED(CONFIG_DRM_I915_DEBUG_GUC)
384+
unsigned long entries[SZ_32];
385+
unsigned int n;
386+
387+
n = stack_trace_save(entries, ARRAY_SIZE(entries), 1);
388+
389+
/* May be called under spinlock, so avoid sleeping */
390+
ct->requests.lost_and_found[lost].stack = stack_depot_save(entries, n, GFP_NOWAIT);
391+
#endif
392+
ct->requests.lost_and_found[lost].fence = fence;
393+
ct->requests.lost_and_found[lost].action = action;
394+
}
395+
#endif
396+
379397
static u32 ct_get_next_fence(struct intel_guc_ct *ct)
380398
{
381399
/* For now it's trivial */
@@ -447,6 +465,11 @@ static int ct_write(struct intel_guc_ct *ct,
447465
}
448466
GEM_BUG_ON(tail > size);
449467

468+
#if IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)
469+
ct_track_lost_and_found(ct, fence,
470+
FIELD_GET(GUC_HXG_EVENT_MSG_0_ACTION, action[0]));
471+
#endif
472+
450473
/*
451474
* make sure H2G buffer update and LRC tail update (if this triggering a
452475
* submission) are visible before updating the descriptor tail
@@ -953,6 +976,43 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)
953976
return -EPIPE;
954977
}
955978

979+
#if IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)
980+
static bool ct_check_lost_and_found(struct intel_guc_ct *ct, u32 fence)
981+
{
982+
unsigned int n;
983+
char *buf = NULL;
984+
bool found = false;
985+
986+
lockdep_assert_held(&ct->requests.lock);
987+
988+
for (n = 0; n < ARRAY_SIZE(ct->requests.lost_and_found); n++) {
989+
if (ct->requests.lost_and_found[n].fence != fence)
990+
continue;
991+
found = true;
992+
993+
#if IS_ENABLED(CONFIG_DRM_I915_DEBUG_GUC)
994+
buf = kmalloc(SZ_4K, GFP_NOWAIT);
995+
if (buf && stack_depot_snprint(ct->requests.lost_and_found[n].stack,
996+
buf, SZ_4K, 0)) {
997+
CT_ERROR(ct, "Fence %u was used by action %#04x sent at\n%s",
998+
fence, ct->requests.lost_and_found[n].action, buf);
999+
break;
1000+
}
1001+
#endif
1002+
CT_ERROR(ct, "Fence %u was used by action %#04x\n",
1003+
fence, ct->requests.lost_and_found[n].action);
1004+
break;
1005+
}
1006+
kfree(buf);
1007+
return found;
1008+
}
1009+
#else
1010+
static bool ct_check_lost_and_found(struct intel_guc_ct *ct, u32 fence)
1011+
{
1012+
return false;
1013+
}
1014+
#endif
1015+
9561016
static int ct_handle_response(struct intel_guc_ct *ct, struct ct_incoming_msg *response)
9571017
{
9581018
u32 len = FIELD_GET(GUC_CTB_MSG_0_NUM_DWORDS, response->msg[0]);
@@ -996,9 +1056,11 @@ static int ct_handle_response(struct intel_guc_ct *ct, struct ct_incoming_msg *r
9961056
if (!found) {
9971057
CT_ERROR(ct, "Unsolicited response message: len %u, data %#x (fence %u, last %u)\n",
9981058
len, hxg[0], fence, ct->requests.last_fence);
999-
list_for_each_entry(req, &ct->requests.pending, link)
1000-
CT_ERROR(ct, "request %u awaits response\n",
1001-
req->fence);
1059+
if (!ct_check_lost_and_found(ct, fence)) {
1060+
list_for_each_entry(req, &ct->requests.pending, link)
1061+
CT_ERROR(ct, "request %u awaits response\n",
1062+
req->fence);
1063+
}
10021064
err = -ENOKEY;
10031065
}
10041066
spin_unlock_irqrestore(&ct->requests.lock, flags);

drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <linux/interrupt.h>
1010
#include <linux/spinlock.h>
11+
#include <linux/stackdepot.h>
1112
#include <linux/workqueue.h>
1213
#include <linux/ktime.h>
1314
#include <linux/wait.h>
@@ -81,6 +82,16 @@ struct intel_guc_ct {
8182

8283
struct list_head incoming; /* incoming requests */
8384
struct work_struct worker; /* handler for incoming requests */
85+
86+
#if IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)
87+
struct {
88+
u16 fence;
89+
u16 action;
90+
#if IS_ENABLED(CONFIG_DRM_I915_DEBUG_GUC)
91+
depot_stack_handle_t stack;
92+
#endif
93+
} lost_and_found[SZ_16];
94+
#endif
8495
} requests;
8596

8697
/** @stall_time: time of first time a CTB submission is stalled */

0 commit comments

Comments
 (0)