From: "Ghimiray, Himal Prasad" <himal.prasad.ghimiray@intel.com>
To: Tejas Upadhyay <tejas.upadhyay@intel.com>,
<intel-xe@lists.freedesktop.org>
Cc: <matthew.brost@intel.com>
Subject: Re: [PATCH 2/4] drm/xe: Re-validate external pin under resv lock before VRAM purge
Date: Mon, 5 Oct 2026 12:28:30 +0530 [thread overview]
Message-ID: <22c921f8-8cd2-4abe-b13b-253f781f085b@intel.com> (raw)
In-Reply-To: <20261001094518.1493651-8-tejas.upadhyay@intel.com>
On 01-10-2026 15:15, Tejas Upadhyay wrote:
> xe_ttm_vram_reserve_page_at_addr() checks xe_bo_is_user() &&
> xe_bo_is_pinned() while holding only mgr->lock, not the BO's
> reservation lock, since it must run before the owning BO is
> even known to be purgeable. A user BO can become pinned
> after that check passes but before xe_ttm_vram_purge_page()
> runs.
>
> xe_ttm_vram_purge_page() takes the reservation lock but only
> rechecks xe_bo_is_pinned(), not xe_bo_is_user(). If the race
> is hit, it calls xe_bo_unpin() (the kernel-BO unpin path,
> not xe_bo_unpin_external())on an externally pinned BO and
> then purges its backing store while userspace/hardware still
> expects it to be resident.
>
> Recheck xe_bo_is_user() && xe_bo_is_pinned() under the
> reservation lock and reject the purge, requesting SBR with
> -EIO the same way the caller's own critical-BO check
> already does.
>
> Fixes: 7737f819e9f1 ("drm/xe/vram: Add VRAM page offline fault handler")
> Signed-off-by: Tejas Upadhyay <tejas.upadhyay@intel.com>
> ---
> drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
> index 4c5837cdb996..ed79e4c6ba1a 100644
> --- a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
> +++ b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
> @@ -687,6 +687,19 @@ static int xe_ttm_vram_purge_page(struct xe_device *xe, struct xe_bo *bo)
> goto out;
> }
>
> + /*
> + * The caller's user+pinned check was lockless (mgr->lock only), so an
> + * external pin can race in before we get here. Re-validate now that
> + * we hold the reservation lock and reject the purge instead of
> + * unpinning a BO userspace still expects to be resident. Request SBR
> + * the same way the caller's own critical-BO check does.
> + */
> + if (xe_bo_is_user(bo) && xe_bo_is_pinned(bo)) {
> + xe_bo_unlock(bo);
> + ret = -EIO;
> + goto out;
> + }
> +
> xe_bo_set_purgeable_
Patch looks correct.
Reviewed-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
state(bo, XE_MADV_PURGEABLE_DONTNEED);
> ttm_bo_unmap_virtual(&bo->ttm); /* nuke CPU mmap + VRAM IO mappings */
> if (xe_bo_is_pinned(bo))
> @@ -851,6 +864,13 @@ static int xe_ttm_vram_reserve_page_at_addr(struct xe_device *xe, u64 addr,
> */
> ret = xe_ttm_vram_purge_page(xe, pbo);
> xe_bo_put(pbo);
> + if (ret == -EIO) {
> + /* Raced into an external pin after the lockless check above */
> + drm_err(&xe->drm,
> + "%s: addr: 0x%llx became externally pinned, requesting SBR\n",
> + __func__, addr);
> + return ret;
> + }
> if (ret)
> drm_warn(&xe->drm, "Purge failed at addr:0x%llx, ret:%d\n", addr, ret);
> }
next prev parent reply other threads:[~2026-10-05 6:58 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 9:45 [PATCH 0/4] Followup fixes for memory page offline Tejas Upadhyay
2026-10-01 9:45 ` [PATCH 1/4] drm/xe: Clean up kernel-doc typos in VRAM manager Tejas Upadhyay
2026-10-01 10:25 ` Ghimiray, Himal Prasad
2026-10-01 9:45 ` [PATCH 2/4] drm/xe: Re-validate external pin under resv lock before VRAM purge Tejas Upadhyay
2026-10-05 6:58 ` Ghimiray, Himal Prasad [this message]
2026-10-01 9:45 ` [PATCH 3/4] drm/xe: Drop RCU list handling for VRAM bad-page tracking, use mgr->lock Tejas Upadhyay
2026-10-01 10:26 ` Ghimiray, Himal Prasad
2026-10-01 9:45 ` [PATCH 4/4] drm/xe: Keep VRAM fault injection within the usable range Tejas Upadhyay
2026-10-01 10:01 ` sashiko-bot
2026-10-05 6:13 ` Upadhyay, Tejas
2026-10-01 10:27 ` Ghimiray, Himal Prasad
2026-10-01 9:53 ` ✓ CI.KUnit: success for Followup fixes for memory page offline Patchwork
2026-10-01 13:19 ` ✓ Xe.CI.BAT: " Patchwork
2026-10-01 17:19 ` ✗ Xe.CI.FULL: 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=22c921f8-8cd2-4abe-b13b-253f781f085b@intel.com \
--to=himal.prasad.ghimiray@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.brost@intel.com \
--cc=tejas.upadhyay@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