From: Matthew Auld <matthew.auld@intel.com>
To: intel-xe@lists.freedesktop.org
Subject: [CI] drm/xe/vram: Add early VRAM health check
Date: Wed, 26 Aug 2026 13:53:05 +0100 [thread overview]
Message-ID: <20260826125304.378173-2-matthew.auld@intel.com> (raw)
DO NOT REVIEW.
Use the last page as a canary for BAR sizing, CCS sizing, identity map
setup. If something is wrong the last page is where we will find it. Hit
it with everything we have. Test here should be non-destructive and fast.
Assisted-by: Gemini:gemini-3.1-pro-preview
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
---
drivers/gpu/drm/xe/xe_device.c | 6 ++
drivers/gpu/drm/xe/xe_migrate.c | 56 ++++++++++
drivers/gpu/drm/xe/xe_migrate.h | 4 +
drivers/gpu/drm/xe/xe_tile_types.h | 4 +
drivers/gpu/drm/xe/xe_vram.c | 162 ++++++++++++++++++++++++++++-
drivers/gpu/drm/xe/xe_vram.h | 8 ++
6 files changed, 239 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
index 74d566693dfd..7f4006b99a5f 100644
--- a/drivers/gpu/drm/xe/xe_device.c
+++ b/drivers/gpu/drm/xe/xe_device.c
@@ -1051,6 +1051,8 @@ int xe_device_probe(struct xe_device *xe)
if (err)
return err;
+ xe_vram_reserve_memtest_bo(xe);
+
for_each_tile(tile, xe, id) {
err = xe_tile_init(tile);
if (err)
@@ -1067,6 +1069,10 @@ int xe_device_probe(struct xe_device *xe)
return err;
}
+ err = xe_vram_memtest(xe);
+ if (err)
+ return err;
+
err = xe_pagefault_init(xe);
if (err)
return err;
diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
index 75b83687f1b5..f2151f222a17 100644
--- a/drivers/gpu/drm/xe/xe_migrate.c
+++ b/drivers/gpu/drm/xe/xe_migrate.c
@@ -2633,3 +2633,59 @@ void xe_migrate_job_lock_assert(struct xe_exec_queue *q)
#if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST)
#include "tests/xe_migrate.c"
#endif
+
+#if IS_ENABLED(CONFIG_DRM_XE_DEBUG_MEM)
+void xe_migrate_debug_ccs_overlap(struct xe_migrate *m, struct xe_bo *last_page_bo, struct xe_bo *scratch_bo)
+{
+ struct xe_device *xe = tile_to_xe(m->tile);
+ struct xe_gt *gt = m->tile->primary_gt;
+ struct dma_fence *fence;
+ struct xe_bb *bb;
+ struct xe_sched_job *job;
+ u64 first_page_dpa, clear_L0_ofs, scratch_dpa, scratch_L0_ofs;
+
+ if (!xe_device_has_flat_ccs(xe))
+ return;
+
+ first_page_dpa = xe_vram_region_dpa_base(m->tile->mem.vram);
+ clear_L0_ofs = xe_migrate_vram_ofs(xe, first_page_dpa, true);
+
+ scratch_dpa = xe_bo_addr(scratch_bo, 0, XE_PAGE_SIZE);
+ scratch_L0_ofs = xe_migrate_vram_ofs(xe, scratch_dpa, false);
+
+ for (int j = 0; j < 4; j++) {
+ bb = xe_bb_new(gt, 256, xe->info.has_usm);
+ if (IS_ERR(bb)) {
+ drm_warn(&xe->drm, "Failed to create bb for VRAM overlap check\n");
+ return;
+ }
+
+ for (int i = 0; i < 16; i++) {
+ int idx = (j * 16) + i;
+ /* 4MB payload = 16KB CCS metadata */
+ emit_copy_ccs(gt, bb, scratch_L0_ofs + (idx * 16384), false,
+ clear_L0_ofs + (idx * SZ_4M), true, SZ_4M);
+ }
+
+ bb->cs[bb->len++] = MI_BATCH_BUFFER_END;
+
+ job = xe_bb_create_migration_job(m->q, bb,
+ xe_migrate_batch_base(m, xe->info.has_usm),
+ bb->len);
+ if (!IS_ERR(job)) {
+ xe_sched_job_add_migrate_flush(job, MI_FLUSH_DW_CCS);
+ xe_sched_job_arm(job);
+
+ fence = dma_fence_get(&job->drm.s_fence->finished);
+ xe_sched_job_push(job);
+
+ dma_fence_wait(fence, false);
+ dma_fence_put(fence);
+ } else {
+ drm_warn(&xe->drm, "Failed to create job for VRAM overlap check\n");
+ }
+
+ xe_bb_free(bb, NULL);
+ }
+}
+#endif
diff --git a/drivers/gpu/drm/xe/xe_migrate.h b/drivers/gpu/drm/xe/xe_migrate.h
index c3a268b01768..17cec0855dad 100644
--- a/drivers/gpu/drm/xe/xe_migrate.h
+++ b/drivers/gpu/drm/xe/xe_migrate.h
@@ -182,4 +182,8 @@ static inline void xe_migrate_job_lock_assert(struct xe_exec_queue *q)
void xe_migrate_job_lock(struct xe_migrate *m, struct xe_exec_queue *q);
void xe_migrate_job_unlock(struct xe_migrate *m, struct xe_exec_queue *q);
+#if IS_ENABLED(CONFIG_DRM_XE_DEBUG_MEM)
+void xe_migrate_debug_ccs_overlap(struct xe_migrate *m, struct xe_bo *last_page_bo, struct xe_bo *scratch_bo);
+#endif
+
#endif
diff --git a/drivers/gpu/drm/xe/xe_tile_types.h b/drivers/gpu/drm/xe/xe_tile_types.h
index 0048100ccb72..75097e4d1c64 100644
--- a/drivers/gpu/drm/xe/xe_tile_types.h
+++ b/drivers/gpu/drm/xe/xe_tile_types.h
@@ -97,6 +97,10 @@ struct xe_tile {
* Only main GT has page reclaim list allocations.
*/
struct xe_sa_manager *reclaim_pool;
+#if IS_ENABLED(CONFIG_DRM_XE_DEBUG)
+ /** @mem.memtest_bo: VRAM overlap check BO */
+ struct xe_bo *memtest_bo;
+#endif
} mem;
/** @sriov: tile level virtualization data */
diff --git a/drivers/gpu/drm/xe/xe_vram.c b/drivers/gpu/drm/xe/xe_vram.c
index 23eb7edbdd57..eb3d7b42371c 100644
--- a/drivers/gpu/drm/xe/xe_vram.c
+++ b/drivers/gpu/drm/xe/xe_vram.c
@@ -17,8 +17,11 @@
#include "xe_device.h"
#include "xe_force_wake.h"
#include "xe_gt_mcr.h"
+#include "xe_map.h"
+#include "xe_migrate.h"
#include "xe_mmio.h"
#include "xe_sriov.h"
+#include "xe_tile.h"
#include "xe_tile_sriov_vf.h"
#include "xe_ttm_vram_mgr.h"
#include "xe_vram.h"
@@ -89,7 +92,7 @@ static int get_flat_ccs_offset(struct xe_gt *gt, u64 tile_size, u64 *poffset)
offset = offset_hi << 32; /* HW view bits 39:32 */
offset |= offset_lo << 6; /* HW view bits 31:6 */
offset *= num_enabled; /* convert to SW view */
- offset = round_up(offset, SZ_128K); /* SW must round up to nearest 128K */
+ offset = round_up(offset, SZ_128K); /* SW must round down to nearest 2M */
/* We don't expect any holes */
xe_assert_msg(xe, offset == (xe_mmio_read64_2x32(>_to_tile(gt)->mmio, GSMBASE) -
@@ -387,3 +390,160 @@ resource_size_t xe_vram_region_actual_physical_size(const struct xe_vram_region
return vram ? vram->actual_physical_size : 0;
}
EXPORT_SYMBOL_IF_KUNIT(xe_vram_region_actual_physical_size);
+
+#if IS_ENABLED(CONFIG_DRM_XE_DEBUG_MEM)
+void xe_vram_reserve_memtest_bo(struct xe_device *xe)
+{
+ struct xe_tile *tile;
+ u8 id;
+
+ for_each_tile(tile, xe, id) {
+ u64 vram_size;
+
+ if (!tile->mem.vram)
+ continue;
+
+ if (tile->mem.vram->io_size < tile->mem.vram->usable_size) {
+ drm_info(&xe->drm, "Tile %d: Small-BAR system detected, skipping VRAM memtest\n", id);
+ continue;
+ }
+
+ vram_size = tile->mem.vram->usable_size;
+
+ tile->mem.memtest_bo = xe_bo_create_pin_map_at_novm(xe, tile, SZ_64K,
+ vram_size - SZ_64K,
+ ttm_bo_type_kernel,
+ XE_BO_FLAG_VRAM_IF_DGFX(tile),
+ 0, false);
+ if (IS_ERR(tile->mem.memtest_bo)) {
+ drm_warn(&xe->drm, "Tile %d: Failed to reserve memtest BO\n", id);
+ tile->mem.memtest_bo = NULL;
+ continue;
+ }
+
+ drm_info(&xe->drm, "Tile %d: Reserved memtest BO at offset 0x%llx\n",
+ id, vram_size - SZ_64K);
+ }
+}
+
+int xe_vram_memtest(struct xe_device *xe)
+{
+ struct xe_tile *tile;
+ u8 id;
+ int err = 0;
+
+ for_each_tile(tile, xe, id) {
+ struct xe_bo *last_page_bo = tile->mem.memtest_bo;
+ struct dma_fence *fence;
+ bool overlap = false;
+ int i, consecutive = 0;
+ u8 val;
+
+ if (!last_page_bo || !tile->migrate)
+ continue;
+
+ drm_info(&xe->drm, "Tile %d: Running VRAM memtest...\n", id);
+
+ /* 1. CPU write and readback first and last byte of the last page */
+ xe_map_wr(xe, &last_page_bo->vmap, 0, u8, 0xA5);
+ xe_map_wr(xe, &last_page_bo->vmap, SZ_64K - 1, u8, 0x5A);
+
+ wmb();
+ rmb();
+
+ val = xe_map_rd(xe, &last_page_bo->vmap, 0, u8);
+ if (drm_WARN(&xe->drm, val != 0xA5,
+ "Tile %d: CPU memtest failed at offset 0 (expected 0xA5, got 0x%02x)\n",
+ id, val)) {
+ err = -EIO;
+ goto unpin;
+ }
+
+ val = xe_map_rd(xe, &last_page_bo->vmap, SZ_64K - 1, u8);
+ if (drm_WARN(&xe->drm, val != 0x5A,
+ "Tile %d: CPU memtest failed at offset 65535 (expected 0x5A, got 0x%02x)\n",
+ id, val)) {
+ err = -EIO;
+ goto unpin;
+ }
+
+ /* 2. Non-CCS access via GPU on the last page */
+ fence = xe_migrate_clear(tile->migrate, last_page_bo,
+ last_page_bo->ttm.resource,
+ XE_MIGRATE_CLEAR_FLAG_BO_DATA);
+ if (!IS_ERR(fence)) {
+ dma_fence_wait(fence, false);
+ dma_fence_put(fence);
+ }
+
+ rmb();
+
+ val = xe_map_rd(xe, &last_page_bo->vmap, 0, u8);
+ if (drm_WARN(&xe->drm, val != 0x00,
+ "Tile %d: GPU memtest clear failed at offset 0 (expected 0x00, got 0x%02x)\n",
+ id, val)) {
+ err = -EIO;
+ goto unpin;
+ }
+
+ if (xe_device_has_flat_ccs(xe)) {
+ struct xe_bo *scratch_bo;
+
+ scratch_bo = xe_bo_create_pin_map_novm(xe, tile, SZ_1M,
+ ttm_bo_type_kernel,
+ XE_BO_FLAG_VRAM_IF_DGFX(tile), false);
+ if (IS_ERR(scratch_bo)) {
+ err = PTR_ERR(scratch_bo);
+ goto unpin;
+ }
+
+ /* Fill the last page with a known pattern */
+ xe_map_memset(xe, &last_page_bo->vmap, 0, 0x79, SZ_64K);
+ xe_map_memset(xe, &scratch_bo->vmap, 0, 0x00, SZ_1M);
+ wmb();
+
+ /* Manually check CCS overlap */
+ xe_migrate_debug_ccs_overlap(tile->migrate, last_page_bo, scratch_bo);
+
+ rmb();
+
+ /*
+ * If the bounds are wrong, the CPU's write to last_page_bo
+ * physically overwrote the CCS metadata of PA 0.
+ * We search for a consecutive block of 0x79 to avoid false positives.
+ */
+ consecutive = 0;
+ for (i = 0; i < SZ_1M; i++) {
+ if (xe_map_rd(xe, &scratch_bo->vmap, i, u8) == 0x79) {
+ consecutive++;
+ if (consecutive >= 8) {
+ overlap = true;
+ break;
+ }
+ } else {
+ consecutive = 0;
+ }
+ }
+
+ xe_bo_unpin_map_no_vm(scratch_bo);
+
+ if (drm_WARN(&xe->drm, overlap,
+ "Tile %d: VRAM bounds overlap CCS region! VRAM sizing is incorrect.\n",
+ id)) {
+ err = -EINVAL;
+ goto unpin;
+ }
+ }
+
+ drm_info(&xe->drm, "Tile %d: VRAM memtest completed.\n", id);
+
+unpin:
+ xe_bo_unpin_map_no_vm(last_page_bo);
+ tile->mem.memtest_bo = NULL;
+ if (err)
+ return err;
+ }
+
+ return 0;
+}
+#endif
diff --git a/drivers/gpu/drm/xe/xe_vram.h b/drivers/gpu/drm/xe/xe_vram.h
index dd1c8bf17922..3fa1afc467aa 100644
--- a/drivers/gpu/drm/xe/xe_vram.h
+++ b/drivers/gpu/drm/xe/xe_vram.h
@@ -23,4 +23,12 @@ resource_size_t xe_vram_region_dpa_base(const struct xe_vram_region *vram);
resource_size_t xe_vram_region_usable_size(const struct xe_vram_region *vram);
resource_size_t xe_vram_region_actual_physical_size(const struct xe_vram_region *vram);
+#if IS_ENABLED(CONFIG_DRM_XE_DEBUG_MEM)
+void xe_vram_reserve_memtest_bo(struct xe_device *xe);
+int xe_vram_memtest(struct xe_device *xe);
+#else
+static inline void xe_vram_reserve_memtest_bo(struct xe_device *xe) {}
+static inline int xe_vram_memtest(struct xe_device *xe) { return 0; }
+#endif
+
#endif
--
2.55.0
next reply other threads:[~2026-08-26 12:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 12:53 Matthew Auld [this message]
2026-08-26 12:59 ` ✗ CI.checkpatch: warning for drm/xe/vram: Add early VRAM health check Patchwork
2026-08-26 13:01 ` ✓ CI.KUnit: success " Patchwork
2026-08-26 13:11 ` [CI] " sashiko-bot
2026-08-26 13:59 ` ✗ Xe.CI.BAT: failure for " Patchwork
2026-08-26 16:12 ` ✗ Xe.CI.FULL: " 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=20260826125304.378173-2-matthew.auld@intel.com \
--to=matthew.auld@intel.com \
--cc=intel-xe@lists.freedesktop.org \
/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