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 06/11] drm/xe/vf: Query and allocate VF GuC log and debug capture buffers
Date: Fri, 04 Dec 2026 16:31:50 +0000	[thread overview]
Message-ID: <sashiko-outbox-250196@kernel.org> (raw)
In-Reply-To: <20261204144712.3520695-19-satyanarayana.k.v.p@intel.com>

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] drm/xe: unguarded gt->sriov.vf union read in VF debug/log
  helpers
- [High] drm/xe: unaligned VF GuC log size triggers BUG_ON in
  xe_guc_log_init()
- [Medium] drm/xe: VF capture BO over-allocated and unzeroed in
  xe_guc_ads_init()
- [Medium] drm/xe: uninitialized VF ads->bo mapped to GGTT in
  xe_guc_ads_init()
- [Medium] drm/xe: 32-bit overflow in PAGE_ALIGN() in
  guc_ads_capture_size()
- [Medium] drm/xe: signed int overflow in xe_guc_log_snapshot_capture()
--

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

drm/xe/vf: Query and allocate VF GuC log and debug capture buffers

This commit adds VF helpers to query the GuC log and debug state capture
buffer sizes from the PF and uses them to allocate the corresponding
buffers in xe_guc_log_init() and xe_guc_ads_init().

> diff --git a/drivers/gpu/drm/xe/xe_guc_ads.c b/drivers/gpu/drm/xe/xe_guc_ads.c
> index 4b7d423e715ca..1cce54cc711d4 100644
> --- a/drivers/gpu/drm/xe/xe_guc_ads.c
> +++ b/drivers/gpu/drm/xe/xe_guc_ads.c
> @@ -446,6 +446,49 @@ static int calculate_waklv_size(struct xe_guc_ads *ads)
>  	return SZ_4K;
>  }
>  
> +/**
> + * xe_guc_debug_capture_support() - Check if VF GuC debug state capture is
> + * supported
> + * @ads: the &ads
> + *
> + * Returns: true if VF GuC debug state capture is enabled, false otherwise.
> + */
> +bool xe_guc_debug_capture_support(struct xe_guc_ads *ads)
> +{
> +	struct xe_gt *gt = ads_to_gt(ads);
> +
> +	return gt->sriov.vf.debug_log.debug_state_capture_enabled;
> +}

[Severity: High]
Can xe_guc_debug_capture_support() and xe_guc_log_vf_supported() read
aliased PF state when called on a non-VF device?

gt->sriov is a union of pf and vf, so reading gt->sriov.vf.debug_log
without checking IS_SRIOV_VF(gt_to_xe(gt)) performs an unlocked read of
live PF fields on a PF and can return true.  Later in this series,
devcoredump_snapshot() calls xe_guc_log_vf_supported() unconditionally on
PF devices, which can then run xe_guc_log_vf_request_snapshot() on a PF
and lock the uninitialized vf_log_capture_lock mutex.

Returning false when !IS_SRIOV_VF(gt_to_xe(gt)) in both helpers (and
reflecting VF-only scope in xe_guc_debug_capture_support()'s name) would
avoid the union aliasing.

> +
> +static u32 guc_capture_size(struct xe_guc_ads *ads)
> +{
> +	u32 size = xe_guc_capture_ads_input_worst_size(ads_to_guc(ads));
> +	struct xe_gt *gt = ads_to_gt(ads);
> +	int err;
> +
> +	if (!IS_SRIOV_VF(gt_to_xe(gt)))
> +		return size;
> +
> +	gt->sriov.vf.debug_log.debug_state_capture_enabled = false;
> +	err = xe_gt_sriov_vf_guc_debug_state_capture_buff_size(gt, &size);
> +	if (err) {
> +		xe_gt_err(gt, "Failed to query debug state capture size!\n");
> +		size = 0;
> +		goto out;
> +	}
> +
> +	if (!size) {
> +		xe_gt_notice(gt, "VF debug state capture is not enabled by PF\n");
> +		goto out;
> +	}
> +
> +	gt->sriov.vf.debug_log.debug_state_capture_enabled = true;
> +	xe_gt_notice(gt, "VF GuC debug state capture buffer size: %u bytes\n", size);
> +
> +out:
> +	return size;
> +}

[Severity: Medium]
Can an unchecked capture buffer size from GuC overflow PAGE_ALIGN() in
guc_ads_capture_size()?

drivers/gpu/drm/xe/xe_guc_ads.c:guc_ads_capture_size() {
	return PAGE_ALIGN(ads->capture_size);
}

Because ads->capture_size is a u32, PAGE_ALIGN() evaluates in 32-bit
arithmetic and wraps values above U32_MAX - (PAGE_SIZE - 1) to 0.
xe_guc_ads_init() then allocates ads->bo with 0 bytes for capture while
leaving ads->capture_size near 4 GiB and debug_state_capture_enabled set.

Validating an upper bound on size in guc_capture_size() would prevent
this wrap.

[ ... ]

> @@ -456,10 +499,13 @@ int xe_guc_ads_init(struct xe_guc_ads *ads)
>  	struct xe_bo *bo;
>  
>  	ads->golden_lrc_size = calculate_golden_lrc_size(ads);
> -	ads->capture_size = xe_guc_capture_ads_input_worst_size(ads_to_guc(ads));
> +	ads->capture_size = guc_capture_size(ads);
>  	ads->regset_size = calculate_regset_size(gt);
>  	ads->ads_waklv_size = calculate_waklv_size(ads);
>  
> +	if (!ads->capture_size)
> +		return 0;
> +
>  	bo = xe_managed_bo_create_pin_map(xe, tile, guc_ads_size(ads) + MAX_GOLDEN_LRC_SIZE,
>  					  XE_BO_FLAG_SYSTEM |
>  					  XE_BO_FLAG_GGTT |

[Severity: Medium]
Does reusing xe_guc_ads_init() over-allocate VF GGTT and pinned RAM for
the VF debug state capture buffer?

On a VF, guc_ads_size(ads) + MAX_GOLDEN_LRC_SIZE adds at least 256 KiB
plus unused PF ADS headers, golden LRC, regset, and WA KLV space per GT,
which can exhaust tight PF-provisioned VF GGTT budgets and makes
xe_bo_size(ads->bo) disagree with ads->capture_size.

Also, gating BO allocation on !ads->capture_size unconditionally skips
ads->bo on native and PF devices where xe_guc_ads_populate_minimal()
expects it to be non-NULL.  Restricting the zero-size skip to
IS_SRIOV_VF(xe) and allocating only the validated capture size for VFs
would avoid both issues.

[ ... ]

> @@ -471,6 +517,9 @@ int xe_guc_ads_init(struct xe_guc_ads *ads)
>  
>  	ads->bo = bo;
>  
> +	if (IS_SRIOV_VF(xe))
> +		return 0;
> +

[Severity: Medium]
Is ads->bo left uninitialized when mapped into the GGTT on a VF?

ttm_tt_create() does not zero-allocate ttm_bo_type_kernel BOs, and VFs
never call xe_guc_ads_populate*().  Without an xe_map_memset() here like
xe_guc_log_init() does, stale guest memory is exposed to the GPU/GuC/PF
and remains in unwritten parts of the capture buffer and its header.

[ ... ]

> diff --git a/drivers/gpu/drm/xe/xe_guc_log.c b/drivers/gpu/drm/xe/xe_guc_log.c
> index 80d80393b05db..7625e07026a7d 100644
> --- a/drivers/gpu/drm/xe/xe_guc_log.c
> +++ b/drivers/gpu/drm/xe/xe_guc_log.c

[ ... ]

> +static size_t guc_log_size(struct xe_gt *gt)
> +{
> +	u32 size = GUC_LOG_SIZE;
> +	int err;
> +
> +	if (!IS_SRIOV_VF(gt_to_xe(gt)))
> +		return size;
> +
> +	gt->sriov.vf.debug_log.guc_log_enabled = false;
> +	err = xe_gt_sriov_vf_guc_log_buff_size(gt, &size);
> +	if (err) {
> +		xe_gt_err(gt, "Failed to query Guc log size!\n");
> +		size = 0;
> +		goto out;
> +	}
> +
> +	if (!size) {
> +		xe_gt_notice(gt, "VF GuC log not enabled by PF\n");
> +		goto out;
> +	}
> +
> +	gt->sriov.vf.debug_log.guc_log_enabled = true;
> +	xe_gt_notice(gt, "VF Guc log size is %u\n", size);
> +out:
> +	return size;
> +}

[Severity: Medium]
Can an unbounded VF GuC log size trigger a signed int overflow in
xe_guc_log_snapshot_capture()?

drivers/gpu/drm/xe/xe_guc_log.c:xe_guc_log_snapshot_capture() {
    ...
	for (i = 0; i < snapshot->num_chunks; i++) {
		size_t size = min(GUC_LOG_CHUNK_SIZE, remain);

		xe_map_memcpy_from(xe, snapshot->copy[i], &log->bo->vmap,
				   i * GUC_LOG_CHUNK_SIZE, size);
    ...
}

Both i and GUC_LOG_CHUNK_SIZE (SZ_2M) are signed 32-bit ints.  If GuC
reports a log size above 2 GiB, i * GUC_LOG_CHUNK_SIZE overflows at
i == 1024 and sign-extends to a huge size_t offset in
xe_map_memcpy_from(), causing an out-of-bounds read.

Enforcing an upper bound in guc_log_size() and using size_t for the
offset calculation would prevent this.

> +
>  int xe_guc_log_init(struct xe_guc_log *log)
>  {
>  	struct xe_device *xe = log_to_xe(log);
>  	struct xe_gt *gt = log_to_gt(log);
>  	struct xe_tile *tile = gt_to_tile(gt);
> +	size_t size = guc_log_size(gt);
>  	struct xe_bo *bo;
>  
> -	bo = xe_managed_bo_create_pin_map(xe, tile, GUC_LOG_SIZE,
> +	if (!size)
> +		return 0;
> +
> +	bo = xe_managed_bo_create_pin_map(xe, tile, size,
>  					  XE_BO_FLAG_SYSTEM |

[Severity: High]
Can an unaligned VF GuC log size panic the kernel in
drm_gem_private_object_init()?

xe_guc_log_init() passes the raw KLV byte count directly to
xe_managed_bo_create_pin_map().  For ttm_bo_type_kernel system BOs,
xe_bo_init_locked() passes size unchanged to
drm_gem_private_object_init(), which runs:

drivers/gpu/drm/drm_gem.c:drm_gem_private_object_init() {
    ...
	BUG_ON((size & (PAGE_SIZE - 1)) != 0);
    ...
}

On 16 KiB or 64 KiB page kernels (or if GuC reports any size not aligned
to PAGE_SIZE), this panics during VF probe.  Checking alignment or
safely aligning size in size_t before allocation would avoid the crash.

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

  reply	other threads:[~2026-12-04 16:32 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 [this message]
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
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-250196@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