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 07/11] drm/xe/vf: Register VF GuC log and debug state capture buffers
Date: Fri, 04 Dec 2026 17:04:10 +0000	[thread overview]
Message-ID: <sashiko-outbox-250257@kernel.org> (raw)
In-Reply-To: <20261204144712.3520695-20-satyanarayana.k.v.p@intel.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] drm/xe/vf: unzeroed, over-allocated ads->bo in
  xe_guc_ads_init()
- [Medium] drm/xe/vf: xe_guc_ads_capture_init_vf() registers unzeroed
  oversized ads->bo
- [Medium] drm/xe: 32-bit PAGE_ALIGN() overflow in
  guc_ads_capture_size() on VF
- [Medium] drm/xe: vf_uc_load_hw() treats optional VF debug buffer
  failures as fatal
- [Medium] drm/xe: unlocked GuC MMIO and GGTT reads race in
  vf_uc_load_hw()
--

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

drm/xe/vf: Register VF GuC log and debug state capture buffers

This commit adds VF helpers to register the GuC log and debug state capture
buffers with GuC via self-configuration KLVs and invokes them from
vf_uc_load_hw().

[ ... ]

> diff --git a/drivers/gpu/drm/xe/xe_guc_ads.c b/drivers/gpu/drm/xe/xe_guc_ads.c
> index 1cce54cc711d4..e6d7833ea8b91 100644
> --- a/drivers/gpu/drm/xe/xe_guc_ads.c
> +++ b/drivers/gpu/drm/xe/xe_guc_ads.c
> @@ -1206,3 +1206,23 @@ int xe_guc_ads_scheduler_policy_toggle_reset(struct xe_guc_ads *ads,
>  
>  	return guc_ads_action_update_policies(ads, xe_guc_buf_flush(buf));
>  }
> +
> +/**
> + * xe_guc_ads_capture_init_vf() - Initialize the GuC debug state capture buffer for a VF.
> + * @ads: Additional data structures object
> + *
> + * Return: 0 on success, or a negative error code on failure.
> + */
> +int xe_guc_ads_capture_init_vf(struct xe_guc_ads *ads)
> +{
> +	struct xe_device *xe = ads_to_xe(ads);
> +	struct xe_gt *gt = ads_to_gt(ads);
> +	struct xe_bo *bo = ads->bo;
> +
> +	xe_gt_assert(gt, IS_SRIOV_VF(xe));
> +
> +	if (!xe_guc_debug_capture_support(ads))
> +		return 0;
> +
> +	return xe_gt_sriov_vf_register_debug_state_capt_buff(gt, xe_bo_ggtt_addr(bo));
> +}

[Severity: Medium]
Does xe_guc_ads_capture_init_vf() register an unzeroed and over-allocated
ads->bo with GuC?

xe_guc_ads_init() allocates ads->bo with xe_managed_bo_create_pin_map()
(a ttm_bo_type_kernel BO, which does not set TTM_TT_FLAG_ZERO_ALLOC) and
returns early on VF without calling xe_map_memset().  Since neither
xe_guc_ads_populate() nor xe_guc_ads_populate_minimal() runs on VF, stale
kernel pages are exposed to GuC and later capture readers.  It also
allocates guc_ads_size(ads) + MAX_GOLDEN_LRC_SIZE, wasting over 256 KiB of
pinned system memory and GGTT space per GT on native ADS sections that VFs
do not use.

[Severity: Medium]
Should the VF debug state capture output buffer be separated from
guc->ads.bo and cleared on load and reset?

Overloading guc->ads.bo breaks the invariant that ads->bo is NULL on VFs,
ties the allocation to PF-only ADS headers, regsets, WAKLV, and
MAX_GOLDEN_LRC_SIZE (over 264 KiB of wasted pinned RAM and PF-partitioned
VF GGTT per GT), and leaves struct guc_debug_snapshot_buffer_state_vf at
offset 0 uninitialized on first load or stale across GT resets and resumes
when vf_uc_load_hw() re-registers the buffer.  Keeping a dedicated BO in
xe_guc_capture sized to PAGE_ALIGN(size) and zeroed on init and reset would
avoid both issues.

[Severity: Medium]
Can guc_ads_capture_size() overflow in 32-bit arithmetic and cause
xe_guc_ads_capture_init_vf() to register an undersized BO with GuC?

guc_capture_size() stores the GuC-reported capture buffer size directly
into u32 ads->capture_size without an upper-bound check.  In
guc_ads_capture_size(), PAGE_ALIGN(ads->capture_size) is evaluated in
32-bit arithmetic, so any value above 0xfffff000 wraps to 0 while
if (!ads->capture_size) in xe_guc_ads_init() still passes.  Registering
the resulting undersized ads->bo risks out-of-bounds GGTT DMA writes from
GuC into adjacent VF kernel buffers.

[ ... ]

> diff --git a/drivers/gpu/drm/xe/xe_uc.c b/drivers/gpu/drm/xe/xe_uc.c
> index ff13f6e6ccb66..d2e863d457b7f 100644
> --- a/drivers/gpu/drm/xe/xe_uc.c
> +++ b/drivers/gpu/drm/xe/xe_uc.c
[ ... ]
> @@ -298,6 +300,14 @@ static int vf_uc_load_hw(struct xe_uc *uc)
>  	if (err)
>  		return err;
>  
> +	err = xe_guc_log_init_vf(&uc->guc.log);
> +	if (err)
> +		return err;
> +
> +	err = xe_guc_ads_capture_init_vf(&uc->guc.ads);
> +	if (err)
> +		return err;
> +
>  	return 0;
>  }

[Severity: Medium]
Should failures from xe_guc_log_init_vf() and xe_guc_ads_capture_init_vf()
be fatal to vf_uc_load_hw()?

vf_uc_load_hw() is called during VF probe, system resume, and GT reset
recovery (gt_reset_worker() -> vf_gt_restart()), where any non-zero error
permanently wedges the device via xe_wedge_declare().  Because
guc_log_enabled and debug_state_capture_enabled are cached once at probe
and never re-queried, a PF reset or VF migration to a PF without VF debug
logging enabled can cause GuC to reject the HOST2GUC_SELF_CFG registration
with an error such as -ENOKEY or -ENXIO.

Logging the failure and clearing the corresponding VF debug flag instead of
returning the error would match how guc_log_size() and guc_capture_size()
already treat optional VF debug buffer errors.  Also, since these helpers
re-register buffers on every reset and resume rather than doing one-time SW
init, a register/enable-oriented name would be clearer.

[Severity: Medium]
Can xe_guc_log_init_vf() and xe_guc_ads_capture_init_vf() race with
vf_post_migration_recovery() or gt_reset_worker() on the unlocked GuC MMIO
scratch registers and GGTT addresses?

Both helpers run after xe_guc_enable_communication() has enabled memirq and
CT, while xe_gt_init() and xe_gt_resume() execute outside gt->ordered_wq:

CPU0 (xe_gt_init / xe_gt_resume)  CPU1 (gt->ordered_wq)
vf_uc_load_hw()
  xe_guc_enable_communication()
  ...
  xe_guc_log_init_vf()
    addr = xe_bo_ggtt_addr(bo)
                                  vf_post_migration_recovery()
                                    vf_post_migration_resfix_start()
                                      xe_guc_mmio_send_recv()
    xe_guc_self_cfg64(..., addr)
      xe_guc_mmio_send_recv()     <-- races on VF_SW_FLAG(0..3)
                                    vf_post_migration_fixups()
                                      xe_ggtt_shift_nodes()

xe_guc_mmio_send_recv() writes and polls VF_SW_FLAG(0..3) or
MED_VF_SW_FLAG(0..3) without locking, so concurrent MMIO requests from
vf_post_migration_recovery() (or from gt_reset_worker() triggered by a G2H
fault during xe_gt_init()) can corrupt HxG requests and replies.  In
addition, sampling xe_bo_ggtt_addr(bo) without synchronizing against
xe_ggtt_shift_nodes() can register a stale pre-migration GGTT address with
the post-migration GuC.

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

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