Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Satyanarayana K V P" <satyanarayana.k.v.p@intel.com>,
	intel-xe@lists.freedesktop.org
Subject: Re: [RFC 11/11] drm/xe/guc: Process VF GuC error state captures
Date: Fri, 04 Dec 2026 18:41:29 +0000	[thread overview]
Message-ID: <sashiko-outbox-250442@kernel.org> (raw)
In-Reply-To: <20261204144712.3520695-24-satyanarayana.k.v.p@intel.com>

Thank you for your contribution! Sashiko AI review found 14 potential
issues to consider:
- [High] drm/xe: union type confusion in devcoredump_snapshot() on
  SR-IOV PF
- [High] drm/xe: xe_hw_engine_snapshot_capture() drops VF captures and
  leaks nodes
- [Medium] drm/xe: devcoredump_snapshot() stalls TDR on hung or stopped
  VF GuC
- [Medium] drm/xe/guc: NULL guc->ads.bo deref in
  guc_capture_process_output_vf()
- [Medium] drm/xe/guc: unvalidated VF header bounds in
  guc_capture_process_output_vf()
- [Medium] drm/xe/guc: guc_capture_process_output_vf() ignores
  wrap_offset and FULL flag
- [Medium] drm/xe/guc: unconditional VF node prealloc in
  xe_guc_capture_init()
- [Medium] drm/xe: unserialized xe_guc_mmio_send() from
  devcoredump_snapshot()
- [Low] drm/xe: vf_log_capture_lock dropped before log BO copy in
  devcoredump
- [Low] drm/xe: non-portable bitfields and struct version tag in
  guc_log_abi.h
- [Low] drm/xe/guc: swapped overflow and full args in
  guc_capture_process_output_vf()
- [Low] drm/xe/guc: non-portable bitfields and wrong DOC size in
  guc_log_abi.h
- [Low] drm/xe: unused uc variable and unreachable VF check in
  xe_guc_capture.c
- [Low] drm/xe: commit message omits VF GuC log request in
  devcoredump_snapshot()
--

commit 4aa56cd4efff155a6869d4a8e1711b02a0d8fd3a
Author: Satyanarayana K V P <satyanarayana.k.v.p@intel.com>

> drm/xe/guc: Process VF GuC error state captures
>
> Process the debug error state capture snapshot received from GuC for a VF.
> Initialize the capture preallocated nodes for VFs and allow coredump
> matching and engine snapshot collection to consume captures reported
> for VF queues.
>
> Signed-off-by: Satyanarayana K V P <satyanarayana.k.v.p@intel.com>

[Severity: Low]
Should the commit message mention the VF GuC event log snapshot request
added to devcoredump_snapshot()?  Calling xe_guc_log_vf_request_snapshot()
populates guc->log.bo before xe_guc_log_snapshot_capture() copies it,
which is separate from error state capture processing and may belong in
its own commit or be described here.

> diff --git a/drivers/gpu/drm/xe/abi/guc_log_abi.h b/drivers/gpu/drm/xe/abi/guc_log_abi.h
> index fbf212d59a40e..58706b0e80c4c 100644
> --- a/drivers/gpu/drm/xe/abi/guc_log_abi.h
> +++ b/drivers/gpu/drm/xe/abi/guc_log_abi.h
[ ... ]
> + *  +===============================+	      0000h
> + *  |    Crash dump state header    |		^
> + *  +-------------------------------+ 32B	|
> + *  |                               |		|
> + *  |            Reserved           |		4KB

[Severity: Low]
Are the header label and size in this diagram accurate?  This buffer holds
error state capture rather than a crash dump, and
struct guc_debug_snapshot_buffer_state_vf has nine u32 fields (36 bytes),
not 32B.

[ ... ]
> +struct guc_debug_snapshot_buffer_state_vf {
> +	/** @marker: buffer state start marker */
> +	u32 marker[2];
> +	/** @version: The version of the this structure */
> +	struct version {
> +		/** @version.minor: Minor version number  */
> +		u32 minor:8;
> +		/** @version.major: Major version number */
> +		u32 major:8;
> +		/** @version.reserved: Reserved for future use */
> +		u32 reserved:16;
> +	} __packed version;

[Severity: Low]
Should version be a plain u32 with GENMASK() definitions instead of a
named bitfield struct?  C bitfield ordering is endianness- and
compiler-dependent (unlike the rest of drivers/gpu/drm/xe/abi/), and
declaring a tagged struct version here exports that tag at file scope to
every includer of this header.

> diff --git a/drivers/gpu/drm/xe/xe_devcoredump.c b/drivers/gpu/drm/xe/xe_devcoredump.c
> index 7634246d77258..c9768842c6435 100644
> --- a/drivers/gpu/drm/xe/xe_devcoredump.c
> +++ b/drivers/gpu/drm/xe/xe_devcoredump.c
> @@ -678,6 +678,10 @@ static void devcoredump_snapshot(struct xe_devcoredump *coredump,
>  
>  	CLASS(xe_force_wake, fw_ref)(gt_to_fw(gt), XE_FORCEWAKE_ALL);
>  
> +	/* We need request GuC log and keep it ready in the buffer */
> +	if (xe_guc_log_vf_supported(&guc->log))
> +		xe_guc_log_vf_request_snapshot(&guc->log);
> +
>  	cookie = dma_fence_begin_signalling();

[Severity: High]
Can this trigger union type confusion and a NULL pointer dereference on an
SR-IOV PF?

devcoredump_snapshot() runs on native, PF, and VF devices, but
xe_guc_log_vf_supported() reads gt->sriov.vf.debug_log.guc_log_enabled
without checking IS_SRIOV_VF().  Because gt->sriov is a union of pf and
vf, on a PF this reads an aliased byte from live gt->sriov.pf data.

If that byte is non-zero, xe_guc_log_vf_request_snapshot() runs on the PF,
where xe_guc_log_init() never initialized log->vf_log_capture_lock or
log->vf_log_ready, hitting xe_gt_assert(gt, IS_SRIOV_VF(xe)) and crashing
in wait_for_completion_timeout().  Checking IS_SRIOV_VF(gt_to_xe(gt))
inside xe_guc_log_vf_supported() would prevent this.

[Severity: Medium]
Can calling xe_guc_log_vf_request_snapshot() here stall TDR and GT reset
recovery when the VF GuC is hung or stopped?

guc_exec_queue_timedout_job() calls xe_devcoredump() right before
xe_gt_reset_async(), including after a schedule-disable timeout or when
xe_guc_read_stopped(guc) is already set.  Without checking
xe_guc_read_stopped(guc), this blocks under coredump->lock for up to
GUC_LOG_VF_READY_TIMEOUT (5 seconds) waiting on CTB (or falls back to
blocking MMIO HXG requests when CT is stopped), while also ignoring the
return value.

[Severity: Medium]
Can the MMIO fallback in xe_guc_log_vf_request_snapshot() race with
xe_uc_suspend() on the shared per-GT MMIO mailbox?

CPU0 (PM suspend)                 CPU1 (gt->ordered_wq)
xe_uc_suspend()
  uc_reset_wait()  /* stopped=1 */
  xe_uc_stop()
    xe_guc_ct_stop()
                                  guc_exec_queue_timedout_job()
                                    xe_devcoredump()
                                      devcoredump_snapshot()
                                        xe_guc_log_vf_request_snapshot()
                                          /* !ct_enabled -> MMIO path */
  xe_guc_suspend()
    xe_guc_softreset()
      xe_guc_mmio_send()                  xe_guc_mmio_send()
                                            <-- concurrent VF_SW_FLAG use

drm_sched_wqueue_stop() does not cancel sched->work_tdr, and
xe_guc_mmio_send_recv() writes and polls VF_SW_FLAG / MED_VF_SW_FLAG
without mutual exclusion.  Overlapping requests can corrupt the mailbox
exchange and fail xe_guc_softreset(), aborting suspend.

[Severity: Low]
Can log->bo be overwritten by GuC while devcoredump_snapshot() is copying
it?

xe_guc_log_vf_request_snapshot() drops log->vf_log_capture_lock before
returning, while xe_guc_log_snapshot_capture() copies log->bo->vmap in
chunks later in devcoredump_snapshot().  A concurrent debugfs guc_log read
via xe_guc_log_vf_print() can request a new snapshot mid-copy, producing
a torn log dump.

> diff --git a/drivers/gpu/drm/xe/xe_guc_capture.c b/drivers/gpu/drm/xe/xe_guc_capture.c
> index 7e3b1bb234331..45bbc7cd48936 100644
> --- a/drivers/gpu/drm/xe/xe_guc_capture.c
> +++ b/drivers/gpu/drm/xe/xe_guc_capture.c
[ ... ]
> @@ -1581,6 +1583,60 @@ static void __guc_capture_process_output(struct xe_guc *guc)
>  	__guc_capture_flushlog_complete(guc);
>  }
>  
> +static void guc_capture_process_output_vf(struct xe_guc *guc)
> +{
> +	struct guc_debug_snapshot_buffer_state_vf log_buf_state_local;
> +	struct xe_uc *uc = container_of(guc, typeof(*uc), guc);

[Severity: Low]
Is uc unused here?  Also, now that xe_guc_capture_process() routes all VFs
to guc_capture_process_output_vf(), the IS_SRIOV_VF() early return inside
__guc_capture_process_output() is unreachable dead code and can be
removed.

[ ... ]
> +	xe_map_memcpy_from(guc_to_xe(guc), &log_buf_state_local, &guc->ads.bo->vmap,
> +			   log_buf_state_offset, sizeof(struct guc_debug_snapshot_buffer_state_vf));

[Severity: Medium]
Can guc->ads.bo be NULL here?

guc_init_vf() always allocates guc->capture before calling
xe_guc_ads_init(), which returns 0 early leaving ads->bo == NULL when
ads->capture_size is 0 (VF debug state capture disabled by the PF).  If an
unexpected capture G2H notification arrives, xe_guc_capture_process() only
checks !guc->capture and reaches &guc->ads.bo->vmap, causing a NULL
pointer dereference.

[ ... ]
> +	/* Overflow and full count are for the dump parser. */
> +	xe_gt_dbg(guc_to_gt(guc), "vf log-state: overflow = %lu full = %lu\n",
> +		  FIELD_GET(GUC_LOG_BUFFER_STATE_FULL, log_buf_state_local.flags),
> +		  FIELD_GET(GUC_LOG_BUFFER_STATE_OVERFLOW, log_buf_state_local.flags));

[Severity: Low]
Are the FIELD_GET() arguments swapped relative to the format string?
The format prints overflow first and full second, while the arguments pass
GUC_LOG_BUFFER_STATE_FULL then GUC_LOG_BUFFER_STATE_OVERFLOW.

> +
> +	buf.size = log_buf_state_local.size;
> +	buf.rd = log_buf_state_local.start_ptr;
> +	buf.wr = log_buf_state_local.end_ptr;
> +	buf.data_offset = src_data_offset;

[Severity: Medium]
Can malformed or uninitialized header fields in guc->ads.bo cause an
out-of-bounds read or buffer overflow in guc_capture_log_remove_bytes()?

Unlike __guc_capture_process_output(), this assigns size, start_ptr, and
end_ptr from firmware-writable memory without checking them against
xe_bo_size(guc->ads.bo) - src_data_offset (or INT_MAX), or verifying
rd <= size and wr <= size.  If start_ptr > size and start_ptr > end_ptr,
guc_capture_buf_cnt_to_end() returns a negative int that
guc_capture_log_remove_bytes() passes as copy_size to xe_map_memcpy_from(),
sign-extending it to size_t and overflowing the destination buffer.

> +
> +	if (!xe_guc_read_stopped(guc)) {
> +		do {
> +			ret = guc_capture_extract_reglists(guc, &buf);
> +			if (ret && ret != -ENODATA)
> +				xe_gt_dbg(guc_to_gt(guc), "Capture extraction failed:%d\n", ret);
> +		} while (ret >= 0);
> +	}
> +
> +	/* Make start_ptr same as end_ptr */
> +	xe_map_wr(guc_to_xe(guc), &guc->ads.bo->vmap,
> +		  log_buf_state_offset + offsetof(struct guc_debug_snapshot_buffer_state_vf,
> +						  start_ptr), u32, log_buf_state_local.end_ptr);
> +}

[Severity: Medium]
Does this drop full capture buffers and corrupt wrapped streams?

Per struct guc_debug_snapshot_buffer_state_vf, when start_ptr >= end_ptr
valid data is [start_ptr, wrap_offset) followed by [0, end_ptr), and
GUC_LOG_BUFFER_STATE_FULL distinguishes a full buffer from an empty one
when start_ptr == end_ptr.

Because wrap_offset is ignored, guc_capture_buf_cnt_to_end() reads stale
bytes in [wrap_offset, size) when wrap_offset < size, breaking header
parsing.  When GUC_LOG_BUFFER_STATE_FULL is set with start_ptr == end_ptr,
guc_capture_buf_cnt() returns 0 and silently discards the entire buffer,
and updating start_ptr without clearing GUC_LOG_BUFFER_STATE_FULL leaves
the header still marked full.

[ ... ]
> @@ -2024,9 +2087,6 @@ xe_guc_capture_get_matching_and_lock(struct xe_exec_queue *q)
>  	if (!xe_device_uc_enabled(xe))
>  		return NULL;
>  
> -	if (IS_SRIOV_VF(xe))
> -		return NULL;
> -
>  	ss = &xe->devcoredump.snapshot;
>  	if (ss->matched_node && ss->matched_node->source == XE_ENGINE_CAPTURE_SOURCE_GUC)
>  		return ss->matched_node;
> @@ -2079,9 +2139,6 @@ xe_engine_snapshot_capture_for_queue(struct xe_exec_queue *q)
>  	enum xe_hw_engine_id id;
>  	u32 adj_logical_mask = q->logical_mask;
>  
> -	if (IS_SRIOV_VF(xe))
> -		return;
> -
>  	for_each_hw_engine(hwe, q->gt, id) {
>  		if (hwe->class != q->hwe->class ||
>  		    !(BIT(hwe->logical_instance) & adj_logical_mask)) {

[Severity: High]
Does removing these IS_SRIOV_VF() guards without updating
xe_hw_engine_snapshot_capture() drop VF captures and leak preallocated
nodes?

xe_hw_engine_snapshot_capture() still returns early on VFs before
attaching the matched GuC capture node:

drivers/gpu/drm/xe/xe_hw_engine.c:xe_hw_engine_snapshot_capture() {
	...
	/* no more VF accessible data below this point */
	if (IS_SRIOV_VF(gt_to_xe(hwe->gt)))
		return snapshot;

	if (q) {
		/* If got guc capture, set source to GuC */
		node = xe_guc_capture_get_matching_and_lock(q);
	...
}

When GuC delivers a VF capture before TDR runs,
guc_exec_queue_timedout_job() calls xe_guc_capture_get_matching_and_lock(),
setting n->locked = 1 and skipping the early
xe_engine_snapshot_capture_for_queue() call.  Later, devcoredump_snapshot()
calls xe_hw_engine_snapshot_capture(), which returns early leaving
coredump->snapshot.matched_node NULL.

As a result, xe_engine_snapshot_print() omits the captured registers from
the devcoredump, and xe_guc_capture_put_matched_nodes() never unlocks or
returns n to cachelist, permanently leaking one node per hang until the
pool is exhausted.  Moving the VF check after the if (q) block (or relying
on the existing VF guard in xe_engine_manual_capture()) would fix both.

> @@ -2175,6 +2232,9 @@ int xe_guc_capture_init(struct xe_guc *guc)
>  	INIT_LIST_HEAD(&guc->capture->outlist);
>  	INIT_LIST_HEAD(&guc->capture->cachelist);
>  
> +	if (IS_SRIOV_VF(guc_to_xe(guc)))
> +		guc_capture_create_prealloc_nodes(guc);
> +
>  	return 0;
>  }

[Severity: Medium]
Should VF node preallocation be gated on VF debug state capture support?

guc_init_vf() calls xe_guc_capture_init() before xe_guc_ads_init() checks
whether the PF enabled VF debug state capture, so this unconditionally
allocates PREALLOC_NODES_MAX_COUNT (1,536) nodes via 6,144 drmm_kzalloc()
calls per GT (~5 MiB per GT) on every VF even when capture is disabled.
Deferring this until after xe_guc_ads_init() and checking
xe_guc_debug_capture_support(&guc->ads) would avoid that overhead.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204144712.3520695-13-satyanarayana.k.v.p@intel.com?part=11

  reply	other threads:[~2026-12-04 18:41 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 14:47 [RFC 00/11] Enable GuC log and debug error state capture for VF Satyanarayana K V P
2026-12-04 14:47 ` [RFC 01/11] drm/xe/pf: Allow VF access to GuC timestamp registers Satyanarayana K V P
2026-12-04 15:09   ` sashiko-bot
2026-12-04 14:47 ` [RFC 02/11] drm/xe/vf: Enable VF debug logging only on supported GUC versions Satyanarayana K V P
2026-12-04 15:22   ` sashiko-bot
2026-12-04 14:47 ` [RFC 03/11] drm/xe/guc: Add KLV definitions for GuC log and debug state capture Satyanarayana K V P
2026-12-04 15:34   ` sashiko-bot
2026-12-04 14:47 ` [RFC 04/11] drm/xe/pf: Enable VF debug logging only on supported GUC versions Satyanarayana K V P
2026-12-04 15:50   ` sashiko-bot
2026-12-04 14:47 ` [RFC 05/11] drm/xe/pf: Enable VF Guc log and debug state capture Satyanarayana K V P
2026-12-04 16:04   ` sashiko-bot
2026-12-04 14:47 ` [RFC 06/11] drm/xe/vf: Query and allocate VF GuC log and debug capture buffers Satyanarayana K V P
2026-12-04 16:31   ` sashiko-bot
2026-12-04 14:47 ` [RFC 07/11] drm/xe/vf: Register VF GuC log and debug state " Satyanarayana K V P
2026-12-04 17:04   ` sashiko-bot
2026-12-04 14:47 ` [RFC 08/11] drm/xe/vf: Initialize GuC logging buffers during GuC setup Satyanarayana K V P
2026-12-04 17:30   ` sashiko-bot
2026-12-04 14:47 ` [RFC 09/11] drm/xe/guc: Register VF-accessible registers for error capture Satyanarayana K V P
2026-12-04 17:52   ` sashiko-bot
2026-12-04 14:47 ` [RFC 10/11] drm/xe/guc: Handle GuC debug state capture notifications for VF Satyanarayana K V P
2026-12-04 18:13   ` sashiko-bot
2026-12-04 14:47 ` [RFC 11/11] drm/xe/guc: Process VF GuC error state captures Satyanarayana K V P
2026-12-04 18:41   ` sashiko-bot [this message]
2026-12-04 14:56 ` ✗ CI.checkpatch: warning for Enable GuC log and debug error state capture for VF Patchwork
2026-12-04 14:58 ` ✓ CI.KUnit: success " Patchwork
2026-12-04 15:34 ` ✗ Xe.CI.BAT: 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=sashiko-outbox-250442@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=satyanarayana.k.v.p@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