From: sashiko-bot@kernel.org
To: "Tomasz Lis" <tomasz.lis@intel.com>, intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v5 2/2] drm/xe: After VF migration, repeat BO mapping in progress
Date: Thu, 19 Nov 2026 14:52:25 +0000 [thread overview]
Message-ID: <sashiko-outbox-223323@kernel.org> (raw)
In-Reply-To: <20261119141741.1720650-3-tomasz.lis@intel.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/xe: UAF and double free of ggtt_node in
__xe_ggtt_insert_bo_at()
- [Medium] drm/xe: race in __xe_ggtt_insert_bo_at() on VF migration
recovery abort
--
commit ffaea991a62518238992d72726824a9a18cd6e5d
Author: Tomasz Lis <tomasz.lis@intel.com>
drm/xe: After VF migration, repeat BO mapping in progress
This commit moves the post-migration retry loop from LRC creation to GGTT
BO insertion so that any GGTT PTE writes racing with VF migration are
redone once recovery updates the GGTT range.
> diff --git a/drivers/gpu/drm/xe/xe_ggtt.c b/drivers/gpu/drm/xe/xe_ggtt.c
> index 44480fad27679..2a7b4322c7a5f 100644
> --- a/drivers/gpu/drm/xe/xe_ggtt.c
> +++ b/drivers/gpu/drm/xe/xe_ggtt.c
[ ... ]
> @@ -1080,6 +1086,41 @@ static int __xe_ggtt_insert_bo_at(struct xe_ggtt *ggtt, struct xe_bo *bo,
> }
> mutex_unlock(&ggtt->lock);
>
> + if (!err) {
> + /*
> + * If VF migration happens during BO mapping, some PTE value writes may
> + * be ignored by HW. This can happen in case GGTT range changed; already
> + * set PTEs are moved by the VF restore, but xe_ggtt_map_bo() within VM
> + * may still loop at old position. To be sure, redo all PTE writes.
> + * Make this a loop as another VF migration could start immediately.
> + */
> + while (marker != xe_vf_migration_fixups_complete_count(ggtt->tile->primary_gt)) {
> + u16 cache_mode = bo->flags & XE_BO_FLAG_NEEDS_UC ?
> + XE_CACHE_NONE : XE_CACHE_WB;
> + u16 pat_index = xe_cache_pat_idx(tile_to_xe(ggtt->tile), cache_mode);
> + u64 pte = ggtt->pt_ops->pte_encode_flags(bo, pat_index);
> +
> + marker = xe_gt_sriov_vf_wait_valid_ggtt(ggtt->tile->primary_gt);
> + /*
> + * Only abort fixing the PTEs if we're wedged; if the wait timeouts,
> + * the cause may be that VF migration recovery was just repeated or
> + * prolonged, so do not treat that as bailout condition.
> + * If the VF migration was detected, we can be sure that recovery
> + * will start or already has started. The recovery worker assures
> + * on finish that this loop will exit - either by marker or by wedge.
> + */
> + if (xe_wedged(tile_to_xe(ggtt->tile))) {
> + xe_ggtt_remove_bo(ggtt, bo);
> + err = -ECANCELED;
> + break;
> + }
[Severity: High]
Does this leave a dangling pointer in bo->ggtt_node[tile_id] after
xe_ggtt_remove_bo() frees the node?
Unlike the earlier error paths in __xe_ggtt_insert_bo_at(),
xe_ggtt_remove_bo() frees bo->ggtt_node[tile_id] via
xe_ggtt_node_remove() without clearing the pointer to NULL. When
__xe_bo_create_locked() sees -ECANCELED and drops the BO with
xe_bo_put(), xe_ttm_bo_destroy() finds bo->ggtt_node[id] still non-NULL
and calls xe_ggtt_remove_bo() a second time, causing a use-after-free and
double free of the GGTT node.
> +
> + mutex_lock(&ggtt->lock);
> + xe_ggtt_map_bo(ggtt, bo->ggtt_node[tile_id], bo, pte);
> + mutex_unlock(&ggtt->lock);
> + }
> + }
[Severity: Medium]
Can this loop exit with err == 0 if VF migration recovery fails and
aborts before fixups_complete_count is incremented?
In vf_post_migration_recovery(), the failure path calls
vf_post_migration_abort() before xe_wedge_declare():
drivers/gpu/drm/xe/xe_gt_sriov_vf.c:vf_post_migration_recovery() {
...
fail:
vf_post_migration_abort(gt);
xe_gt_sriov_err(gt, "migration recovery failed (%pe)\n", ERR_PTR(err));
xe_wedge_declare(xe, DRM_WEDGE_RECOVERY_REBIND | DRM_WEDGE_RECOVERY_BUS_RESET);
return;
}
vf_post_migration_abort() clears ggtt_need_fixes and wakes migration.wq
without incrementing fixups_complete_count:
CPU0 CPU1 (recovery worker)
__xe_ggtt_insert_bo_at()
marker = N
...
xe_gt_sriov_vf_wait_valid_ggtt()
vf_post_migration_recovery()
vf_post_migration_abort()
ggtt_need_fixes = false
wake_up_all(&migration.wq)
returns N
if (xe_wedged(xe)) (false)
xe_ggtt_map_bo()
while (marker !=
xe_vf_migration_fixups_complete_count())
(N != N is false, exits with err = 0)
xe_wedge_declare(xe, ...)
If CPU0 reaches the while condition after vf_post_migration_abort()
clears ggtt_need_fixes, xe_vf_migration_fixups_complete_count() also
returns the unchanged count N, so the retry loop and its xe_wedged()
check are bypassed altogether and __xe_ggtt_insert_bo_at() succeeds with
PTEs written to the unfixed GGTT range.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119141741.1720650-1-tomasz.lis@intel.com?part=2
next prev parent reply other threads:[~2026-11-19 14:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 14:17 [PATCH v5 0/2] drm/xe/vf: New approach for post-migration LRC fixups Tomasz Lis
2026-11-19 14:17 ` [PATCH v5 1/2] drm/xe/vf: Late fixups of LRCs after VF migration Tomasz Lis
2026-11-19 14:17 ` [PATCH v5 2/2] drm/xe: After VF migration, repeat BO mapping in progress Tomasz Lis
2026-11-19 14:52 ` sashiko-bot [this message]
2026-11-19 14:58 ` ✓ CI.KUnit: success for drm/xe/vf: New approach for post-migration LRC fixups (rev5) Patchwork
2026-11-19 15:42 ` ✓ Xe.CI.BAT: " 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-223323@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tomasz.lis@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