Add memory page offlining support
Subsystems (4)
v13 cover Add memory page offlining support
This functionality represents a significant step in making the xe driver gracefully handle hardware memory degradation. By integrating with the DRM Buddy allocator, the driver can permanently "carve out" faulty memory so it isn't reused by subsequent allocations.
This series adds memory page offlining support with following:
1. Link VRAM object with gpu buddy
2. Link and track ttm BO's with physical addresses
3. Link LRC BO and its execution Queue
4. Extend BO purge to handle vram pages as well
5. Handle the generated physical address error by reserving addresses 4K page
6. Add buddy block allocation dump for debuggin buddy related issues
7. Add configfs for vram bad page reservation policy
8. Sysfs entry to provide statistics of bad gpu vram pages for user info
9. Expose ban reason in EXEC_QUEUE_GET_PROPERTY_BAN
10. Add soft/hard offline mode for VRAM page retirement
11. drm/xe: Add fault-inject based VRAM page offline injection
v13:
- Add fault inject and remove standlone debugfs
v12:
- Fix Sashiko review comments
v11:
- Add BAN reason for UMD to know about offlining
- Add support for soft offline mode
- Rebase and remove dummy lockdep annotation patch, as it merged from upstream v10:
- Remove RFC
v7:
- Improve debugfs warning messages
- Use scope_guard for locking(MattB)
- Adapt addition of queue member of LRC BO(MattB)
- Extend and use xe_ttm_bo_purge API for vram pages(MattB)
- Handle dma_buf_map requests for native and remote(MattB)
- Address if in never initialized block, set block to NULL
- Add lockdep in gpu buddy (MattB)
- Correct allocated_addr_to_block logic (MattA)
V6:
- Add more specific tests to noncritical bo sections
- Handle smooth exit of user created exec queues
- Break code and make purge specific static API
V5:
- Sysfs "max_pages" addition
- Reset block->private NULL post purge
- Remove wedge, return -EIO to system controller will initiate reset
- Add debugfs tests to trigger different test scenarios manually and via igt
- Rename addr_to_tbo to addr_to_block and move under gpu/buddy.c
V4: API reworks, add configfs for policy reservation and apply config everywhere
V3: use res_to_mem_region to avoid use of block->private (MattA)
V2:
- some fixes and clean up on errors
- Added xe_vram_addr_to_region helper to avoid other use of block->private (MattB)
IGT tests for testing this via injecting fault:
https://patchwork.freedesktop.org/patch/740601/
Tejas Upadhyay (11):
drm/xe: Link VRAM object with gpu buddy
drm/gpu: Add gpu_buddy_allocated_addr_to_block helper drm/xe: Link LRC BO and its execution Queue
drm/xe: Extend BO purge to handle vram pages as well drm/xe: Handle physical memory address error gpu/buddy: Add routine to dump allocated buddy blocks drm/xe/configfs: Add vram bad page reservation policy drm/xe/cri: Add sysfs interface for bad gpu vram pages drm/xe/uapi: Expose ban reason in EXEC_QUEUE_GET_PROPERTY_BAN drm/xe: Add soft/hard offline mode for VRAM page retirement drm/xe: Add fault-inject based VRAM page offline injection
drivers/gpu/buddy.c | 99 ++++ drivers/gpu/drm/xe/xe_bo.c | 16 +- drivers/gpu/drm/xe/xe_bo.h | 5 +- drivers/gpu/drm/xe/xe_bo_types.h | 3 + drivers/gpu/drm/xe/xe_configfs.c | 64 ++- drivers/gpu/drm/xe/xe_configfs.h | 2 + drivers/gpu/drm/xe/xe_debugfs.c | 40 ++ drivers/gpu/drm/xe/xe_device_sysfs.c | 7 + drivers/gpu/drm/xe/xe_dma_buf.c | 3 + drivers/gpu/drm/xe/xe_exec_queue.c | 13 +- drivers/gpu/drm/xe/xe_exec_queue_types.h | 7 +- drivers/gpu/drm/xe/xe_execlist.c | 4 +- drivers/gpu/drm/xe/xe_guc_submit.c | 30 +- drivers/gpu/drm/xe/xe_lrc.c | 1 + drivers/gpu/drm/xe/xe_pt.c | 3 +- drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 517 ++++++++++++++++++++- drivers/gpu/drm/xe/xe_ttm_vram_mgr.h | 3 + drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h | 42 ++ include/linux/gpu_buddy.h | 3 + include/uapi/drm/xe_drm.h | 12 +- 20 files changed, 829 insertions(+), 45 deletions(-)
Signature · 1 line
2.52.0
PATCH v13 1/11 drm/xe: Link VRAM object with gpu buddy
Setup to link TTM buffer object inside gpu buddy. This functionality is critical for supporting the memory page offline feature on CRI, where identified faulty pages must be traced back to their originating buffer for safe removal.
V2(MattB): Clear block->private in xe_ttm_vram_mgr_del as well
--- drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +6 -0
@@ -54,6 +54,7 @@ static int xe_ttm_vram_mgr_new(struct ttm_resource_manager *man,struct xe_ttm_vram_mgr *mgr =to_xe_ttm_vram_mgr (man);struct xe_ttm_vram_mgr_resource *vres;struct gpu_buddy *mm = &mgr->mm; +struct gpu_buddy_block *block;u64 size, min_page_size;unsigned long lpfn;int err;
@@ -138,6 +139,8 @@ static int xe_ttm_vram_mgr_new(struct ttm_resource_manager *man, } mgr->visible_avail -= vres->used_visible_size; +list_for_each_entry (block, &vres->blocks, link) + block->private = tbo;mutex_unlock (&mgr->lock); if (!(vres->base.placement & TTM_PL_FLAG_CONTIGUOUS) &&
@@ -176,8 +179,11 @@ static void xe_ttm_vram_mgr_del(struct ttm_resource_manager *man,to_xe_ttm_vram_mgr_resource (res);struct xe_ttm_vram_mgr *mgr =to_xe_ttm_vram_mgr (man);struct gpu_buddy *mm = &mgr->mm; +struct gpu_buddy_block *block;mutex_lock (&mgr->lock); +list_for_each_entry (block, &vres->blocks, link) + block->private =NULL ;gpu_buddy_free_list (mm, &vres->blocks,0 ); mgr->visible_avail += vres->used_visible_size;mutex_unlock (&mgr->lock);
Signature · 1 line
2.52.0
PATCH v13 2/11 drm/gpu: Add gpu_buddy_allocated_addr_to_block helper
In reply to Tejas UpadhyayAdd helper with primary purpose is to efficiently trace a specific physical memory address back to its corresponding TTM buffer object.
v3:
- use mm->chunk_size minimum allocation granularity (Arun) v2:
- %s/gpu_buddy_addr_to_block/gpu_buddy_allocated_addr_to_block(MattA)
- remove clear->avail and split nodes check(MattA)
- Adapt lockdep(MattB)
--- drivers/gpu/buddy.c | 53 +++++++++++++++++++++++++++++++++++++++ include/linux/gpu_buddy.h | 2 ++ 2 files changed, 55 insertions(+)
drivers/gpu/buddy.c +53 -0
@@ -594,6 +594,59 @@ void gpu_buddy_free_block(struct gpu_buddy *mm, }EXPORT_SYMBOL (gpu_buddy_free_block); +/** +* gpu_buddy_allocated_addr_to_block - given relative address find the allocated block +* +* @mm: GPU buddy manager +* @addr: Relative address +* +* Returns: +* gpu_buddy_block on success, NULL or error code on failure +*/ +struct gpu_buddy_block *gpu_buddy_allocated_addr_to_block (struct gpu_buddy *mm,u64 addr) +{ +struct gpu_buddy_block *block; +LIST_HEAD (dfs); +u64 end; +int i; + +gpu_buddy_driver_lock_held (mm); + + end = addr + mm->chunk_size -1 ; +for (i =0 ; i < mm->n_roots; ++i) +list_add_tail (&mm->roots[i]->tmp_link, &dfs); + +do { +u64 block_start; +u64 block_end; + + block =list_first_entry_or_null (&dfs, + struct gpu_buddy_block, + tmp_link); +if (!block) +break ; + +list_del (&block->tmp_link); + + block_start =gpu_buddy_block_offset (block); + block_end = block_start +gpu_buddy_block_size (mm, block) -1 ; + +if (!overlaps (addr, end, block_start, block_end)) +continue ; + +if (gpu_buddy_block_is_allocated (block)) +return block; +else if (gpu_buddy_block_is_free (block)) +return NULL ; + +list_add (&block->right->tmp_link, &dfs); +list_add (&block->left->tmp_link, &dfs); + }while (1 ); + +return ERR_PTR (-ENXIO ); +} +EXPORT_SYMBOL (gpu_buddy_allocated_addr_to_block); + static void __gpu_buddy_free_list(struct gpu_buddy *mm, struct list_head *objects, bool mark_clear,
include/linux/gpu_buddy.h +2 -0
@@ -272,6 +272,8 @@ void gpu_buddy_reset_clear(struct gpu_buddy *mm, bool is_clear);void gpu_buddy_free_block (struct gpu_buddy *mm,struct gpu_buddy_block *block); +struct gpu_buddy_block *gpu_buddy_allocated_addr_to_block (struct gpu_buddy *mm,u64 addr); +void gpu_buddy_free_list (struct gpu_buddy *mm,struct list_head *objects,unsigned int flags);
Signature · 1 line
2.52.0
PATCH v13 3/11 drm/xe: Link LRC BO and its execution Queue
In reply to Tejas UpadhyayTo establish a link between an LRC BO (Logical Ring Context Buffer Object) and its corresponding execution Queue in the drm/xe driver, you need to store a back-pointer to the queue within the BO's private data structure. This allows the driver to identify and take corrective action on the specific queue if the LRC BO encounters an error (e.g., memory corruption or eviction issues).
V3(Sashiko):
- Placeholder of 8 byte for non-lrc bo is acceptable
- Assign bo-q is safe just user READ_ONCE/WRITE_ONCE V2(MattB):
- Handle multiqueue
--- drivers/gpu/drm/xe/xe_bo_types.h | 3 +++ drivers/gpu/drm/xe/xe_exec_queue.c | 5 +++++ drivers/gpu/drm/xe/xe_lrc.c | 1 + 3 files changed, 9 insertions(+)
drivers/gpu/drm/xe/xe_bo_types.h +3 -0
@@ -20,6 +20,7 @@struct xe_device ;struct xe_mem_pool_node ;struct xe_vm ; +struct xe_exec_queue ;#define XE_BO_MAX_PLACEMENTS 3
@@ -42,6 +43,8 @@ struct xe_bo {u32 flags;/** @vm: VM this BO is attached to, for extobj this will be NULL */ struct xe_vm *vm; +/** @q: Queue this BO is attached to, mostly for LRC BO, NULL otherwise */ +struct xe_exec_queue *q;/** @tile: Tile this BO is attached to (kernel BO only) */ struct xe_tile *tile;/** @placements: valid placements for this BO */
drivers/gpu/drm/xe/xe_exec_queue.c +5 -0
@@ -390,6 +390,11 @@ static int __xe_exec_queue_init(struct xe_exec_queue *q, u32 exec_queue_flags) goto err_lrc; } +/* +* The queue ref counts the LRCs, thus it safe for the LRC BO to hold a +* pointer to queue without reference. +*/ + lrc->bo->q =xe_exec_queue_multi_queue_primary (q);xe_exec_queue_set_lrc (q, lrc, i);if (__lrc)
drivers/gpu/drm/xe/xe_lrc.c +1 -0
@@ -1066,6 +1066,7 @@ static void xe_lrc_set_ppgtt(struct xe_lrc *lrc, struct xe_vm *vm)static void xe_lrc_finish (struct xe_lrc *lrc) {xe_hw_fence_ctx_finish (&lrc->fence_ctx); +WRITE_ONCE (lrc->bo->q,NULL );xe_bo_unpin_map_no_vm (lrc->bo);xe_bo_unpin_map_no_vm (lrc->seqno_bo); }
Signature · 1 line
2.52.0
PATCH v13 4/11 drm/xe: Extend BO purge to handle vram pages as well
In reply to Tejas UpadhyayRecent driver update introduce support for purgeable buffer objects (BOs), extending the API to include VRAM pages to better manage memory pressure and enable memory offlining.
--- drivers/gpu/drm/xe/xe_bo.c | 5 +---- drivers/gpu/drm/xe/xe_bo.h | 1 + 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/xe/xe_bo.c +1 -4
@@ -909,7 +909,7 @@ void xe_bo_set_purgeable_state(struct xe_bo *bo,* * Return: 0 on success, negative error code on failure */ -static int xe_ttm_bo_purge (struct ttm_buffer_object *ttm_bo,struct ttm_operation_ctx *ctx) +int xe_ttm_bo_purge (struct ttm_buffer_object *ttm_bo,struct ttm_operation_ctx *ctx) {struct xe_bo *bo =ttm_to_xe_bo (ttm_bo);struct ttm_placement place = {};
@@ -917,9 +917,6 @@ static int xe_ttm_bo_purge(struct ttm_buffer_object *ttm_bo, struct ttm_operatioxe_bo_assert_held (bo); -if (!ttm_bo->ttm) -return 0 ; -if (!xe_bo_madv_is_dontneed (bo))return 0 ;
drivers/gpu/drm/xe/xe_bo.h +1 -0
@@ -585,6 +585,7 @@ struct xe_bo_shrink_flags {long xe_bo_shrink (struct ttm_operation_ctx *ctx,struct ttm_buffer_object *bo,const struct xe_bo_shrink_flags flags,unsigned long *scanned); +int xe_ttm_bo_purge (struct ttm_buffer_object *ttm_bo,struct ttm_operation_ctx *ctx);/** * xe_bo_is_mem_type - Whether the bo currently resides in the given
Signature · 1 line
2.52.0
PATCH v13 5/11 drm/xe: Handle physical memory address error
In reply to Tejas UpadhyayThis functionality represents a significant step in making the xe driver gracefully handle hardware memory degradation. By integrating with the DRM Buddy allocator, the driver can permanently "carve out" faulty memory so it isn't reused by subsequent allocations.
Buddy Block Reservation:
When a memory address is reported as faulty, the driver instructs the DRM Buddy allocator to reserve a block of the specific page size (typically 4KB). This marks the memory as "dirty/used" indefinitely.
Two-Stage Tracking:
Offlined Pages:
Pages that have been successfully isolated and removed from the available memory pool.
Queued Pages:
Addresses that have been flagged as faulty but are currently in use by a process. These are tracked until the associated buffer object (BO) is released or migrated, at which point they move to the "offlined" state.
v9(Sashiko):
- Move xe_exec_queue_put() outside bo lock to avoid sleeping under spinlock
- Check PURGED state before xe_bo_set_purgeable_state to avoid assertion if shrinker raced during unlocked window
- Add best-effort comment for flags check without resv lock
- Move xe_bo_put() (pbo_to_put) outside scoped_guard to avoid recursive deadlock
- Remove xe_ttm_vram_free_bad_pages from critical path (avoid UAF if another thread frees nentry while fault handler holds reference)
- Add comment documenting purge-to-reserve race window (self-corrects on next HW fault)
- In else branch, add nentry to queued_pages before buddy_alloc to prevent leak on allocation failure
- handle with Eexist for race case
v8(MattA):
- introduce helper for vram_buddy_alloc and free to avoid code dup
- Add WARN_ON for -ENXIO
v7:
- keep vm ref during vm kill and fix some typos
- FW communication code is moved in RAS, keep comment for same V6:
- Use scope_guard for locking(MattB)
- Adapt addition of queue member of LRC BO(MattB)
- Extend and use xe_ttm_bo_purge API for vram pages(MattB)
- Handle dma_buf_map requests for native and remote(MattB)
- Address if in never initialized block, set block to NULL V5:
- Categorise and handle BOs accordingly
- Fix crash found with new debugfs tests
V4:
- Set block->private NULL post bo purge
- Filter out gsm address early on
- Rebase
V3:
-rename api, remove tile dependency and add status of reservation V2:
- Fix mm->avail counter issue
- Remove unused code and handle clean up in case of error
--- drivers/gpu/drm/xe/xe_bo.c | 11 +- drivers/gpu/drm/xe/xe_bo.h | 4 +- drivers/gpu/drm/xe/xe_dma_buf.c | 3 + drivers/gpu/drm/xe/xe_exec_queue.c | 8 +- drivers/gpu/drm/xe/xe_pt.c | 3 +- drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 374 +++++++++++++++++++-- drivers/gpu/drm/xe/xe_ttm_vram_mgr.h | 1 + drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h | 28 ++ 8 files changed, 396 insertions(+), 36 deletions(-)
drivers/gpu/drm/xe/xe_bo.c +10 -1
@@ -158,7 +158,16 @@ bool xe_bo_is_vm_bound(struct xe_bo *bo)return !list_empty (&bo->ttm.base.gpuva.list); } -static bool xe_bo_is_user (struct xe_bo *bo) +/** +* xe_bo_is_user - check if BO is user created BO +* @bo: The BO +* +* Check if BO is user created BO. This requires the +* reservation lock for the BO to be held. +* +* Returns: boolean +*/ +bool xe_bo_is_user (struct xe_bo *bo) {return bo->flags &XE_BO_FLAG_USER ; }
drivers/gpu/drm/xe/xe_bo.h +3 -1
@@ -362,7 +362,8 @@ static inline void xe_bo_unpin_map_no_vm(struct xe_bo *bo) {if (likely (bo)) {xe_bo_lock (bo, false); -xe_bo_unpin (bo); +if (!xe_bo_is_purged (bo)) +xe_bo_unpin (bo);xe_bo_unlock (bo);xe_bo_put (bo);
@@ -586,6 +587,7 @@ long xe_bo_shrink(struct ttm_operation_ctx *ctx, struct ttm_buffer_object *bo,const struct xe_bo_shrink_flags flags, unsigned long *scanned);int xe_ttm_bo_purge (struct ttm_buffer_object *ttm_bo,struct ttm_operation_ctx *ctx); +bool xe_bo_is_user (struct xe_bo *bo);/** * xe_bo_is_mem_type - Whether the bo currently resides in the given
drivers/gpu/drm/xe/xe_dma_buf.c +3 -0
@@ -104,6 +104,9 @@ static struct sg_table *xe_dma_buf_map(struct dma_buf_attachment *attach,struct sg_table *sgt;int r =0 ; +if (xe_bo_is_purged (bo)) +return ERR_PTR (-ENOENT ); +if (!attach->peer2peer && !xe_bo_can_migrate (bo,XE_PL_TT ))return ERR_PTR (-EOPNOTSUPP );
drivers/gpu/drm/xe/xe_exec_queue.c +6 -2
@@ -1557,8 +1557,12 @@ void xe_exec_queue_update_run_ticks(struct xe_exec_queue *q)* errors. */ lrc = q->lrc[0 ]; - new_ts =xe_lrc_update_timestamp (lrc, &old_ts); - q->xef->run_ticks[q->class] += (new_ts - old_ts) * q->width; +xe_bo_lock (lrc->bo, false); +if (!xe_bo_is_purged (lrc->bo)) { + new_ts =xe_lrc_update_timestamp (lrc, &old_ts); + q->xef->run_ticks[q->class] += (new_ts - old_ts) * q->width; + } +xe_bo_unlock (lrc->bo);drm_dev_exit (idx); }
drivers/gpu/drm/xe/xe_pt.c +2 -1
@@ -212,7 +212,8 @@ void xe_pt_destroy(struct xe_pt *pt, u32 flags, struct llist_head *deferred)return ;XE_WARN_ON (!list_empty (&pt->bo->ttm.base.gpuva.list)); -xe_bo_unpin (pt->bo); +if (!xe_bo_is_purged (pt->bo)) +xe_bo_unpin (pt->bo);xe_bo_put_deferred (pt->bo, deferred);if (pt->level >0 && pt->num_live) {
drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +343 -31
436 lines not on this page · raw message
drivers/gpu/drm/xe/xe_ttm_vram_mgr.h +1 -0
@@ -31,6 +31,7 @@ u64 xe_ttm_vram_get_cpu_visible_size(struct ttm_resource_manager *man);void xe_ttm_vram_get_used (struct ttm_resource_manager *man,u64 *used,u64 *used_visible); +int xe_ttm_vram_handle_addr_fault (struct xe_device *xe,unsigned long addr);static inline struct xe_ttm_vram_mgr_resource *to_xe_ttm_vram_mgr_resource (struct ttm_resource *res) {
drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h +28 -0
@@ -19,6 +19,14 @@ struct xe_ttm_vram_mgr {struct ttm_resource_manager manager;/** @mm: DRM buddy allocator which manages the VRAM */ struct gpu_buddy mm; +/** @offlined_pages: List of offlined pages */ +struct list_head offlined_pages; +/** @n_offlined_pages: Number of offlined pages */ +u16 n_offlined_pages; +/** @queued_pages: List of queued pages */ +struct list_head queued_pages; +/** @n_queued_pages: Number of queued pages */ +u16 n_queued_pages;/** @visible_size: Proped size of the CPU visible portion */ u64 visible_size;/** @visible_avail: CPU visible portion still unallocated */
@@ -45,4 +53,24 @@ struct xe_ttm_vram_mgr_resource { unsigned long flags; }; +/** +* struct xe_ttm_vram_offline_resource - Xe TTM VRAM offline resource +*/ +struct xe_ttm_vram_offline_resource { +/** @offlined_link: Link to offlined pages */ +struct list_head offlined_link; +/** @queued_link: Link to queued pages */ +struct list_head queued_link; +/** @blocks: list of DRM buddy blocks */ +struct list_head blocks; +/** @used_visible_size: How many CPU visible bytes this resource is using */ +u64 used_visible_size; +/** @id: The id of an offline resource */ +u16 id; +/** @addr: Address of faulty memory location reported by HW */ +unsigned long addr; +/** @status: reservation status of resource */ +bool status; +}; +#endif
Signature · 1 line
2.52.0
PATCH v13 6/11 gpu/buddy: Add routine to dump allocated buddy blocks
In reply to Tejas UpadhyayTo implement the ability to see allocated blocks under a specific VRAM instance in the drm driver, new api is introduced. While existing structs often show the free block list, this addition provides a comprehensive view of all currently resident VRAM allocations.
Dump will look like,
[ +0.000003] 0x00000002f8000000-0x00000002f8800000: 8388608 [ +0.000005] 0x00000002f8800000-0x00000002f8840000: 262144 [ +0.000004] 0x00000002f8840000-0x00000002f8860000: 131072 [ +0.000004] 0x00000002f8860000-0x00000002f8870000: 65536 [ +0.000005] 0x00000002f9000000-0x00000002f9800000: 8388608 [ +0.000004] 0x00000002f9800000-0x00000002f9880000: 524288 [ +0.000005] 0x00000002f9880000-0x00000002f9884000: 16384 [ +0.000004] 0x00000002f9900000-0x00000002f9980000: 524288 [ +0.000005] 0x00000002f9980000-0x00000002f9988000: 32768 [ +0.000004] 0x00000002f9988000-0x00000002f998c000: 16384
v3(Sashiko):
- Add cond_resched() every 1024 blocks to yield CPU on large VRAM dumps v2(MattB):
- Add lockdep assert
--- drivers/gpu/buddy.c | 46 +++++++++++++++++++++++++++++++++++++++ include/linux/gpu_buddy.h | 1 + 2 files changed, 47 insertions(+)
drivers/gpu/buddy.c +46 -0
@@ -10,6 +10,7 @@#include <linux/sizes.h> #include <linux/gpu_buddy.h> +#include <drm/drm_print.h> /** * gpu_buddy_assert - assert a condition in the buddy allocator
@@ -1294,6 +1295,51 @@ int gpu_buddy_block_trim(struct gpu_buddy *mm, }EXPORT_SYMBOL (gpu_buddy_block_trim); +/** +* gpu_buddy_dump_allocated_blocks - print all allocated blocks in drm buddy +* +* @mm: DRM buddy manager to look into +* +* Looks into buddy manager for each block and their status and if allocated +* print allocated block range and size +* +* Returns: +* void +*/ +void gpu_buddy_dump_allocated_blocks (struct gpu_buddy *mm) +{ +struct gpu_buddy_block *block; +LIST_HEAD (dfs); +int i, count =0 ; + +gpu_buddy_driver_lock_held (mm); + +for (i =0 ; i < mm->n_roots; ++i) +list_add_tail (&mm->roots[i]->tmp_link, &dfs); + +do { + block =list_first_entry_or_null (&dfs, + struct gpu_buddy_block, + tmp_link); +if (!block) +break ; + +list_del (&block->tmp_link); + +if (gpu_buddy_block_is_allocated (block)) { +gpu_buddy_block_print (mm, block); +if (!(++count %1024 )) +cond_resched ();/* yield periodically */ + } + +if (gpu_buddy_block_is_split (block)) { +list_add (&block->right->tmp_link, &dfs); +list_add (&block->left->tmp_link, &dfs); + } + }while (1 ); +} +EXPORT_SYMBOL (gpu_buddy_dump_allocated_blocks); +static struct gpu_buddy_block * __gpu_buddy_alloc_blocks(struct gpu_buddy *mm, u64 start, u64 end,
include/linux/gpu_buddy.h +1 -0
@@ -267,6 +267,7 @@ int gpu_buddy_block_trim(struct gpu_buddy *mm,u64 *start, u64 new_size, struct list_head *blocks); +void gpu_buddy_dump_allocated_blocks (struct gpu_buddy *mm);void gpu_buddy_reset_clear (struct gpu_buddy *mm,bool is_clear);
Signature · 1 line
2.52.0
PATCH v13 7/11 drm/xe/configfs: Add vram bad page reservation policy
In reply to Tejas UpadhyayThe interface enables setting the policy for how bad pages are handled in VRAM. This is crucial for maintaining system stability in scenarios where VRAM degradation occurs.
By default policy will be "reserve", which can be changed to "logging" only.
v3:
- All FW communication moved under RAS
v2:
- Add CRI check and rebase
--- drivers/gpu/drm/xe/xe_configfs.c | 64 +++++++++++++++++++++++++++- drivers/gpu/drm/xe/xe_configfs.h | 2 + drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 10 +++++ 3 files changed, 75 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_configfs.c +63 -1
@@ -61,7 +61,8 @@* ├── survivability_mode * ├── gt_types_allowed * ├── engines_allowed -* └── enable_psmi +* ├── enable_psmi +* └── bad_page_reservation * * After configuring the attributes as per next section, the device can be * probed with::
@@ -159,6 +160,16 @@* * This attribute can only be set before binding to the device. * +* Bad pages reservation: +* --------------------- +* +* Disable vram bad pages reservation, instead just report it in dmesg. +* Example to disable it:: +* +* # echo 0 > /sys/kernel/config/xe/0000:03:00.0/bad_page_reservation +* +* This attribute can only be set before binding to the device. +* * Context restore BB * ------------------ *
@@ -275,6 +286,7 @@ struct xe_config_group_device {bool survivability_mode;bool enable_psmi;bool enable_multi_queue; +bool bad_page_reservation;struct {unsigned int max_vfs;bool admin_only_pf;
@@ -295,6 +307,7 @@ static const struct xe_config_device device_defaults = { .survivability_mode = false, .enable_psmi = false, .enable_multi_queue = true, + .bad_page_reservation = true, .sriov = { .max_vfs = XE_DEFAULT_MAX_VFS, .admin_only_pf = XE_DEFAULT_ADMIN_ONLY_PF,
@@ -616,6 +629,32 @@ static ssize_t enable_multi_queue_store(struct config_item *item, const char *pareturn len; } +static ssize_t bad_page_reservation_show (struct config_item *item,char *page) +{ +struct xe_config_device *dev =to_xe_config_device (item); + +return sprintf (page,"%d\n" , dev->bad_page_reservation); +} + +static ssize_t bad_page_reservation_store (struct config_item *item,const char *page,size_t len) +{ +struct xe_config_group_device *dev =to_xe_config_group_device (item); +bool val; +int ret; + + ret =kstrtobool (page, &val); +if (ret) +return ret; + +guard (mutex)(&dev->lock); +if (is_bound (dev)) +return -EBUSY ; + + dev->config.bad_page_reservation = val; + +return len; +} +static bool wa_bb_read_advance (bool dereference,char **p,const char *append,size_t len,size_t *max_size)
@@ -855,6 +894,7 @@ CONFIGFS_ATTR(, ctx_restore_mid_bb); CONFIGFS_ATTR(, ctx_restore_post_bb); CONFIGFS_ATTR(, enable_multi_queue); CONFIGFS_ATTR(, enable_psmi); +CONFIGFS_ATTR(, bad_page_reservation); CONFIGFS_ATTR(, engines_allowed); CONFIGFS_ATTR(, gt_types_allowed); CONFIGFS_ATTR(, survivability_mode);
@@ -864,6 +904,7 @@ static struct configfs_attribute *xe_config_device_attrs[] = { &attr_ctx_restore_post_bb, &attr_enable_multi_queue, &attr_enable_psmi, + &attr_bad_page_reservation, &attr_engines_allowed, &attr_gt_types_allowed, &attr_survivability_mode,
@@ -1142,6 +1183,7 @@ static void dump_custom_dev_config(struct pci_dev *pdev,PRI_CUSTOM_ATTR ("%llx" , engines_allowed);PRI_CUSTOM_ATTR ("%d" , enable_multi_queue);PRI_CUSTOM_ATTR ("%d" , enable_psmi); +PRI_CUSTOM_ATTR ("%d" , bad_page_reservation);PRI_CUSTOM_ATTR ("%d" , survivability_mode);PRI_CUSTOM_ATTR ("%u" , sriov.admin_only_pf);
@@ -1290,6 +1332,26 @@ bool xe_configfs_get_enable_multi_queue(struct pci_dev *pdev)return ret; } +/** +* xe_configfs_get_bad_page_reservation - get configfs bad_page_reservation setting +* @pdev: pci device +* +* Return: bad_page_reservation setting in configfs +*/ +bool xe_configfs_get_bad_page_reservation (struct pci_dev *pdev) +{ +struct xe_config_group_device *dev =find_xe_config_group_device (pdev); +bool ret; + +if (!dev) +return device_defaults.bad_page_reservation; + + ret = dev->config.bad_page_reservation; +config_group_put (&dev->group); + +return ret; +} +/** * xe_configfs_get_ctx_restore_mid_bb - get configfs ctx_restore_mid_bb setting * @pdev: pci device
drivers/gpu/drm/xe/xe_configfs.h +2 -0
@@ -24,6 +24,7 @@ bool xe_configfs_media_gt_allowed(struct pci_dev *pdev);u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev);bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev);bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev); +bool xe_configfs_get_bad_page_reservation (struct pci_dev *pdev);u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev,enum xe_engine_class class,const u32 **cs);
@@ -44,6 +45,7 @@ static inline bool xe_configfs_media_gt_allowed(struct pci_dev *pdev) { return tstatic inline u64 xe_configfs_get_engines_allowed (struct pci_dev *pdev) {return U64_MAX ; }static inline bool xe_configfs_get_psmi_enabled (struct pci_dev *pdev) {return false; }static inline bool xe_configfs_get_enable_multi_queue (struct pci_dev *pdev) {return true; } +static inline bool xe_configfs_get_bad_page_reservation (struct pci_dev *pdev) {return true; }static inline u32 xe_configfs_get_ctx_restore_mid_bb (struct pci_dev *pdev,enum xe_engine_class class,const u32 **cs) {return 0 ; }
drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +10 -0
@@ -12,6 +12,7 @@#include <drm/ttm/ttm_range_manager.h> #include "xe_bo.h" +#include "xe_configfs.h" #include "xe_device.h" #include "xe_exec_queue.h" #include "xe_lrc.h"
@@ -771,6 +772,7 @@ int xe_ttm_vram_handle_addr_fault(struct xe_device *xe, unsigned long addr)struct xe_ttm_vram_mgr *vram_mgr;struct xe_vram_region *vr;struct gpu_buddy *mm; +bool policy; vr =xe_ttm_vram_addr_to_region (xe, addr);if (!vr) {
@@ -782,6 +784,14 @@ int xe_ttm_vram_handle_addr_fault(struct xe_device *xe, unsigned long addr) vram_mgr = &vr->ttm; mm = &vram_mgr->mm; + policy =xe_configfs_get_bad_page_reservation (to_pci_dev (xe->drm.dev)); +if (!policy) { +drm_err (&xe->drm,"0x%lx is reported as corrupted address by HW\n" , + addr); +/* Let RAS report to FW to drop addr from SRAM queue */ +return -EOPNOTSUPP ; + } +/* Reserve page at address */ return xe_ttm_vram_reserve_page_at_addr (xe, addr, vram_mgr, mm); }
Signature · 1 line
2.52.0
PATCH v13 8/11 drm/xe/cri: Add sysfs interface for bad gpu vram pages
In reply to Tejas UpadhyayStarting CRI, Include a sysfs interface designed to expose information about bad VRAM pages—those identified as having hardware faults (e.g., ECC errors). This interface allows userspace tools and administrators to monitor the health of the GPU's local memory and track the status of page retirement.To get details on bad gpu vram pages can be found under /sys/bus/pci/devices/bdf/vram_bad_pages.
Where The format is, pfn : gpu page size : flags
flags:
R: reserved, this gpu page is reserved.
P: pending for reserve, this gpu page is marked as bad, will be reserved
in next window of page_reserve.
F: unable to reserve. this gpu page can't be reserved
due to some reasons.
For example if you read using cat /sys/bus/pci/devices/bdf/vram_bad_pages, max_pages : 100000x00000000 : 0x00001000 : R0x00001234 : 0x00001000 : P
v4:
- Use sysfs_emit_at() instead of scnprintf() to respect PAGE_SIZE
- Use list_first_entry_or_null() with continue to handle empty lists
- Use %016llx for full 64-bit address width
- Fix inverted P/F ternary (status ? F : P)
- Return err instead of 0 on device_create_file failure
- Remove redundant element_size/maxpage_size constants
v3:
- Move FW communication in RAS code
v2:
- Add max_pages info as per updated design doc
- Rebase
--- drivers/gpu/drm/xe/xe_device_sysfs.c | 7 ++ drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 85 ++++++++++++++++++++++ drivers/gpu/drm/xe/xe_ttm_vram_mgr.h | 1 + drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h | 2 + 4 files changed, 95 insertions(+)
drivers/gpu/drm/xe/xe_device_sysfs.c +7 -0
@@ -8,12 +8,14 @@#include <linux/pci.h> #include <linux/sysfs.h> +#include "xe_configfs.h" #include "xe_device.h" #include "xe_device_sysfs.h" #include "xe_mmio.h" #include "xe_pcode_api.h" #include "xe_pcode.h" #include "xe_pm.h" +#include "xe_ttm_vram_mgr.h" /** * DOC: Xe device sysfs
@@ -267,6 +269,7 @@ static const struct attribute_group auto_link_downgrade_attr_group = {int xe_device_sysfs_init (struct xe_device *xe) {struct device *dev = xe->drm.dev; +bool policy;int ret;if (xe->d3cold.capable) {
@@ -285,5 +288,9 @@ int xe_device_sysfs_init(struct xe_device *xe)return ret; } + policy =xe_configfs_get_bad_page_reservation (to_pci_dev (dev)); +if (xe->info.platform ==XE_CRESCENTISLAND && policy) +xe_ttm_vram_sysfs_init (xe); +return 0 ; }
drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +85 -0
88 lines not on this page · raw message
drivers/gpu/drm/xe/xe_ttm_vram_mgr.h +1 -0
@@ -32,6 +32,7 @@ void xe_ttm_vram_get_used(struct ttm_resource_manager *man, u64 *used, u64 *used_visible);int xe_ttm_vram_handle_addr_fault (struct xe_device *xe,unsigned long addr); +int xe_ttm_vram_sysfs_init (struct xe_device *xe);static inline struct xe_ttm_vram_mgr_resource *to_xe_ttm_vram_mgr_resource (struct ttm_resource *res) {
drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h +2 -0
@@ -37,6 +37,8 @@ struct xe_ttm_vram_mgr {struct mutex lock;/** @mem_type: The TTM memory type */ u32 mem_type; +/** @max_pages: max pages that can be in offline queue retrieved from FW */ +u16 max_pages; };/**
Signature · 1 line
2.52.0
PATCH v13 9/11 drm/xe/uapi: Expose ban reason in EXEC_QUEUE_GET_PROPERTY_BAN
In reply to Tejas UpadhyayExtend DRM_XE_EXEC_QUEUE_GET_PROPERTY_BAN to return a bitmask indicating the reason for the ban, rather than a simple boolean. This allows userspace to distinguish between different ban causes:
- DRM_XE_EXEC_QUEUE_BAN_REASON_GPU_HANG (bit 0): exec queue was banned due to a GPU hang or job timeout detected by the TDR.
- DRM_XE_EXEC_QUEUE_BAN_REASON_PAGE_OFFLINE (bit 1): exec queue was banned because a VRAM page backing its resources was taken offline.
The ban_reason field is added to struct xe_exec_queue and set at the point where the ban is triggered:
- In guc_exec_queue_timedout_job() for GPU hang.
- In xe_ttm_vram_purge_page() for memory page offline, before calling xe_exec_queue_kill() or xe_vm_kill().
The reset_status op is updated to return u64 with the reason bitmask. When a queue is banned but no explicit reason was recorded (e.g., from a generic CAT error), it defaults to GPU_HANG for backward compatibility. A value of 0 means the exec queue is not banned.
v2(Sashiko):
- Use atomic_t for ban_reason to fix concurrent updates from TDR and page-offline
- Guard GPU_HANG bit with !exec_queue_killed to avoid masking page-offline reason
- Clear ban_reason on queue recovery (clear_exec_queue_banned path)
- Use atomic_read in guc_exec_queue_reset_status for lockless read
--- drivers/gpu/drm/xe/xe_exec_queue_types.h | 7 ++++-- drivers/gpu/drm/xe/xe_execlist.c | 4 ++-- drivers/gpu/drm/xe/xe_guc_submit.c | 30 ++++++++++++++++++++---- drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 6 +++++ include/uapi/drm/xe_drm.h | 12 +++++++++- 5 files changed, 49 insertions(+), 10 deletions(-)
drivers/gpu/drm/xe/xe_exec_queue_types.h +5 -2
@@ -149,6 +149,9 @@ struct xe_exec_queue {*/ unsigned long flags; +/** @ban_reason: Bitmask of ban reasons (DRM_XE_EXEC_QUEUE_BAN_REASON_*) */ +atomic_t ban_reason; +union {/** @multi_gt_list: list head for VM bind engines if multi-GT */ struct list_head multi_gt_list;
@@ -343,8 +346,8 @@ struct xe_exec_queue_ops {* signalled when this function is called. */ void (*resume)(struct xe_exec_queue *q); -/** @reset_status: check exec queue reset status */ - bool (*reset_status)(struct xe_exec_queue *q); +/** @reset_status: check exec queue ban status, returns ban reason bitmask */ + u64 (*reset_status)(struct xe_exec_queue *q); };#endif
drivers/gpu/drm/xe/xe_execlist.c +2 -2
@@ -452,10 +452,10 @@ static void execlist_exec_queue_resume(struct xe_exec_queue *q)/* NIY */ } -static bool execlist_exec_queue_reset_status (struct xe_exec_queue *q) +static u64 execlist_exec_queue_reset_status (struct xe_exec_queue *q) {/* NIY */ -return false; +return 0 ; }static const struct xe_exec_queue_ops execlist_exec_queue_ops = {
drivers/gpu/drm/xe/xe_guc_submit.c +25 -5
@@ -6,6 +6,7 @@#include "xe_guc_submit.h" #include <linux/bitfield.h> +#include <uapi/drm/xe_drm.h> #include <linux/bitmap.h> #include <linux/circ_buf.h> #include <linux/dma-fence-array.h>
@@ -1573,6 +1574,12 @@ guc_exec_queue_timedout_job(struct drm_sched_job *drm_job)if (!exec_queue_killed (q)) wedged =guc_submit_hint_wedged (exec_queue_to_guc (q)); +/* +* Only tag as GPU hang if this is the original timeout, not a +* consequence of a prior kill (e.g., page-offline). +*/ +if (!exec_queue_killed (q)) +atomic_or (DRM_XE_EXEC_QUEUE_BAN_REASON_GPU_HANG , &q->ban_reason);set_exec_queue_banned (q);/* Kick job / queue off hardware */
@@ -1656,6 +1663,7 @@ guc_exec_queue_timedout_job(struct drm_sched_job *drm_job)if (timeout_needs_gt_reset (q, job, skip_timeout_check)) {if (!xe_sched_invalidate_job (job,2 )) {clear_exec_queue_banned (q); +atomic_set (&q->ban_reason,0 );xe_gt_reset_async (q->gt); goto rearm; }
@@ -2495,13 +2503,25 @@ static void guc_exec_queue_multi_queue_drop_suspend(struct xe_exec_queue *q) } } -static bool guc_exec_queue_reset_status (struct xe_exec_queue *q) +static u64 guc_exec_queue_reset_status (struct xe_exec_queue *q) { -if (xe_exec_queue_is_multi_queue_secondary (q) && -guc_exec_queue_reset_status (xe_exec_queue_multi_queue_primary (q))) -return true; +if (xe_exec_queue_is_multi_queue_secondary (q)) { +u64 status =guc_exec_queue_reset_status (xe_exec_queue_multi_queue_primary (q)); -return exec_queue_reset (q) ||exec_queue_killed_or_banned_or_wedged (q); +if (status) +return status; + } + +if (exec_queue_reset (q) ||exec_queue_killed_or_banned_or_wedged (q)) { +u64 reason =atomic_read (&q->ban_reason); + +/* If no specific reason was recorded, default to GPU hang */ +if (!reason) + reason =DRM_XE_EXEC_QUEUE_BAN_REASON_GPU_HANG ; +return reason; + } + +return 0 ; }/*
drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +6 -0
@@ -7,6 +7,7 @@#include <drm/drm_managed.h> #include <drm/drm_drv.h> #include <drm/drm_buddy.h> +#include <uapi/drm/xe_drm.h> #include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_range_manager.h>
@@ -538,7 +539,11 @@ static int xe_ttm_vram_purge_page(struct xe_device *xe, struct xe_bo *bo)xe_bo_unlock (bo);/* Ban VM if BO is PPGTT */ if (vm && (flags &XE_BO_FLAG_PAGETABLE )) { +struct xe_exec_queue *eq; +down_write (&vm->lock); +list_for_each_entry (eq, &vm->preempt.exec_queues, lr.link) +atomic_or (DRM_XE_EXEC_QUEUE_BAN_REASON_PAGE_OFFLINE , &eq->ban_reason);xe_vm_kill (vm, true);up_write (&vm->lock); }
@@ -549,6 +554,7 @@ static int xe_ttm_vram_purge_page(struct xe_device *xe, struct xe_bo *bo)/* Ban exec queue if BO is lrc */ if (bo->q &&xe_exec_queue_get_unless_zero (bo->q)) {/* ban queue */ +atomic_or (DRM_XE_EXEC_QUEUE_BAN_REASON_PAGE_OFFLINE , &bo->q->ban_reason);xe_exec_queue_kill (bo->q); q_to_put = bo->q; }
include/uapi/drm/xe_drm.h +11 -1
@@ -1503,7 +1503,17 @@ struct drm_xe_exec_queue_get_property {/** @property: property to get */ __u32 property; -/** @value: property value */ +/** +* @value: property value +* +* For %DRM_XE_EXEC_QUEUE_GET_PROPERTY_BAN, this is a bitmask of: +* - %DRM_XE_EXEC_QUEUE_BAN_REASON_GPU_HANG - banned due to GPU hang/timeout +* - %DRM_XE_EXEC_QUEUE_BAN_REASON_PAGE_OFFLINE - banned due to memory page offline +* +* Value of 0 means the exec queue is not banned. +*/ +#define DRM_XE_EXEC_QUEUE_BAN_REASON_GPU_HANG (1 << 0) +#define DRM_XE_EXEC_QUEUE_BAN_REASON_PAGE_OFFLINE (1 << 1)__u64 value;/** @reserved: Reserved */
Signature · 1 line
2.52.0
PATCH v13 10/11 drm/xe: Add soft/hard offline mode for VRAM page retirement
In reply to Tejas UpadhyayIntroduce a mode-based approach for VRAM page offlining to distinguish between soft (temporary) and hard (permanent) page retirement:
- Add enum xe_page_offline_mode with XE_PAGE_OFFLINE_SOFT and XE_PAGE_OFFLINE_HARD states.
- Add 'mode' field to struct xe_ttm_vram_offline_resource.
On first fault at an address:
- Reserve the block, add to offlined_pages with mode = SOFT.
- Page stays out of the allocator pool but is not permanently retired.
On second fault at the same address:
- xe_ttm_vram_page_already_processed() finds the entry and promotes mode from SOFT to HARD.
- Returns -EEXIST to the caller, which signals FW to permanently retire the page.
This avoids unnecessary permanent retirement on transient single-bit errors while ensuring persistent faults get hard-offlined.
v2(Sashiko):
- Add soft-to-hard mode promotion for queued_pages
--- drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 15 +++++++++++++-- drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h | 12 ++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-)
drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +13 -2
@@ -587,13 +587,23 @@ static bool xe_ttm_vram_page_already_processed(struct xe_ttm_vram_mgr *mgr,lockdep_assert_held (&mgr->lock);list_for_each_entry (pos, &mgr->offlined_pages, offlined_link) { -if (pos->addr == addr) +if (pos->addr == addr) { +/* +* Second fault at same addr: promote soft to hard. +* Caller returns -EEXIST to FW for permanent retirement. +*/ +if (pos->mode ==XE_PAGE_OFFLINE_SOFT ) + pos->mode =XE_PAGE_OFFLINE_HARD ;return true; + } }list_for_each_entry (pos, &mgr->queued_pages, queued_link) { -if (pos->addr == addr) +if (pos->addr == addr) { +if (pos->mode ==XE_PAGE_OFFLINE_SOFT ) + pos->mode =XE_PAGE_OFFLINE_HARD ;return true; + } }return false;
@@ -626,6 +636,7 @@ static int xe_ttm_vram_reserve_page_at_addr(struct xe_device *xe, unsigned longINIT_LIST_HEAD (&nentry->blocks); nentry->status = pending; nentry->addr = addr; + nentry->mode =XE_PAGE_OFFLINE_SOFT ;if (block) {struct xe_bo *pbo;
drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h +12 -0
@@ -55,6 +55,16 @@ struct xe_ttm_vram_mgr_resource {unsigned long flags; }; +/** +* enum xe_page_offline_mode - Mode of page offline +* @XE_PAGE_OFFLINE_SOFT: Page is soft-offlined (scrubbed, can be restored) +* @XE_PAGE_OFFLINE_HARD: Page is hard-offlined (permanently retired) +*/ +enum xe_page_offline_mode { +XE_PAGE_OFFLINE_SOFT =0 , +XE_PAGE_OFFLINE_HARD , +}; +/** * struct xe_ttm_vram_offline_resource - Xe TTM VRAM offline resource */
@@ -73,6 +83,8 @@ struct xe_ttm_vram_offline_resource {unsigned long addr;/** @status: reservation status of resource */ bool status; +/** @mode: offline mode (soft or hard) */ + enum xe_page_offline_mode mode; };#endif
Signature · 1 line
2.52.0
PATCH v13 11/11 drm/xe: Add fault-inject based VRAM page offline injection
In reply to Tejas UpadhyayAdd a fault-inject based debugfs interface for testing VRAM page offlining. This replaces the previous standalone debugfs approach with the standard kernel fault-inject infrastructure.
Two debugfs entries are created under the xe debugfs root for CRI platforms:
- inject_mempage_offline/: Standard fault-inject knobs (probability, times, interval, etc.) — only available with CONFIG_FAULT_INJECTION_DEBUG_FS
- inject_mempage_offline_trigger: Write a PFN value to inject a specific page, or write "0" to auto-pick the last unallocated VRAM page
The trigger accepts:
- "0" : auto-pick last unallocated page
- "0xPFN" : inject fault at a specific PFN address
On kernels with CONFIG_FAULT_INJECTION_DEBUG_FS, injection is gated by should_fail() (probability/times must be configured first). On kernels without it, the trigger always injects directly.
The injection reports the page as faulted via xe_ttm_vram_handle_addr_fault(), exercising the full page offlining path.
Usage (with CONFIG_FAULT_INJECTION_DEBUG_FS):
echo 100 > inject_mempage_offline/probability
echo 1 > inject_mempage_offline/times
echo 0 > inject_mempage_offline_trigger
Usage (without CONFIG_FAULT_INJECTION_DEBUG_FS):
echo 0 > inject_mempage_offline_trigger
--- drivers/gpu/drm/xe/xe_debugfs.c | 40 ++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 37 +++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_ttm_vram_mgr.h | 1 + 3 files changed, 78 insertions(+)
drivers/gpu/drm/xe/xe_debugfs.c +40 -0
@@ -30,6 +30,7 @@#include "xe_sriov_vf.h" #include "xe_step.h" #include "xe_tile_debugfs.h" +#include "xe_ttm_vram_mgr.h" #include "xe_vsec.h" #include "xe_wa.h"
@@ -41,6 +42,7 @@DECLARE_FAULT_ATTR (gt_reset_failure);DECLARE_FAULT_ATTR (inject_csc_hw_error); +DECLARE_FAULT_ATTR (inject_mempage_offline);static void read_residency_counter (struct xe_device *xe,struct xe_mmio *mmio,u32 offset,const char *name,struct drm_printer *p)
@@ -564,6 +566,37 @@ static const struct file_operations disable_late_binding_fops = { .write = disable_late_binding_set, }; +static ssize_t inject_mempage_offline_trigger (struct file *f, +const char __user *ubuf, +size_t size,loff_t *pos) +{ +struct xe_device *xe =file_inode (f)->i_private; +struct xe_tile *tile =xe_device_get_root_tile (xe); +struct xe_vram_region *vr = tile->mem.vram; +u64 pfn; +int ret; + +if (IS_ENABLED (CONFIG_FAULT_INJECTION_DEBUG_FS ) && + !should_fail (&inject_mempage_offline,1 )) +return size; + + ret =kstrtou64_from_user (ubuf, size,0 , &pfn); +if (ret) +return ret; + +if (pfn ==0 ) +return xe_ttm_vram_inject_fault (xe) ?: size; + +/* User provided PFN — convert to DPA and inject */ +return xe_ttm_vram_handle_addr_fault (xe, + (pfn <<PAGE_SHIFT ) + vr->dpa_base) ?: size; +} + +static const struct file_operations inject_mempage_offline_fops = { + .owner =THIS_MODULE , + .write = inject_mempage_offline_trigger, +}; +void xe_debugfs_register (struct xe_device *xe) {struct ttm_device *bdev = &xe->ttm;
@@ -632,6 +665,13 @@ void xe_debugfs_register(struct xe_device *xe)if (man)ttm_resource_manager_create_debugfs (man, root,"stolen_mm" ); +if (xe->info.platform ==XE_CRESCENTISLAND ) { +fault_create_debugfs_attr ("inject_mempage_offline" , root, + &inject_mempage_offline); +debugfs_create_file ("inject_mempage_offline_trigger" ,0200 , + root, xe, &inject_mempage_offline_fops); + } +for_each_tile (tile, xe, tile_id)xe_tile_debugfs_register (tile);
drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +37 -0
@@ -814,6 +814,43 @@ int xe_ttm_vram_handle_addr_fault(struct xe_device *xe, unsigned long addr) }EXPORT_SYMBOL (xe_ttm_vram_handle_addr_fault); +/** +* xe_ttm_vram_inject_fault - Inject a VRAM page fault for testing +* @xe: xe device instance +* +* Picks the last unallocated VRAM page and reports it as faulted +* via xe_ttm_vram_handle_addr_fault(). Used by the fault-inject +* debugfs interface for testing page offlining. +* +* Return: 0 on success, negative error code on failure. +*/ +int xe_ttm_vram_inject_fault (struct xe_device *xe) +{ +struct xe_tile *tile =xe_device_get_root_tile (xe); +struct xe_vram_region *vr = tile->mem.vram; +struct xe_ttm_vram_mgr *vram_mgr = &vr->ttm; +struct gpu_buddy *mm = &vram_mgr->mm; +struct gpu_buddy_block *block; +bool found = false; +u64 addr; + +/* Walk from end of VRAM to find last unallocated page */ +for (addr = vr->actual_physical_size -SZ_4K ; + addr < vr->actual_physical_size; addr -=SZ_4K ) { + scoped_guard(mutex, &vram_mgr->lock) { + block =gpu_buddy_allocated_addr_to_block (mm, addr); +if (!block) + found = true; + } +if (found) +return xe_ttm_vram_handle_addr_fault (xe, + addr + vr->dpa_base); + } + +return -ENOSPC ; +} +EXPORT_SYMBOL (xe_ttm_vram_inject_fault); +static int xe_ttm_vram_dump_bad_pages_info (char *buf,struct xe_ttm_vram_mgr *mgr) {struct xe_ttm_vram_offline_resource *pos;
drivers/gpu/drm/xe/xe_ttm_vram_mgr.h +1 -0
@@ -32,6 +32,7 @@ void xe_ttm_vram_get_used(struct ttm_resource_manager *man, u64 *used, u64 *used_visible);int xe_ttm_vram_handle_addr_fault (struct xe_device *xe,unsigned long addr); +int xe_ttm_vram_inject_fault (struct xe_device *xe);int xe_ttm_vram_sysfs_init (struct xe_device *xe);static inline struct xe_ttm_vram_mgr_resource *to_xe_ttm_vram_mgr_resource (struct ttm_resource *res)
Signature · 1 line
2.52.0
Please ignore this, end time landed rebase commit and pre-build on CI showing conflict, resending...
Tejas
Quoted 103 lines
-----Original Message-----
From: Upadhyay, Tejas <[email protected]>
Sent: 16 July 2026 15:51
To: [email protected]
Cc: Upadhyay, Tejas <[email protected]>
Subject: [PATCH V13 00/11] Add memory page offlining supportThis functionality represents a significant step in making the xe driver gracefully handle hardware memory degradation.
By integrating with the DRM Buddy allocator, the driver can permanently "carve out" faulty memory so it isn't reused by subsequent allocations.This series adds memory page offlining support with following:
1. Link VRAM object with gpu buddy
2. Link and track ttm BO's with physical addresses 3. Link LRC BO and its execution Queue 4. Extend BO purge to handle vram pages as well 5. Handle the generated physical address error by reserving addresses 4K page 6. Add buddy block allocation dump for debuggin buddy related issues 7. Add configfs for vram bad page reservation policy 8. Sysfs entry to provide statistics of bad gpu vram pages for user info 9. Expose ban reason inEXEC_QUEUE_GET_PROPERTY_BAN10. Add soft/hard offline mode for VRAM page retirement 11. drm/xe: Add fault-inject based VRAM page offline injectionv13:
- Add fault inject and remove standlone debugfs
v12:
- Fix Sashiko review comments
v11:
- Add BAN reason for UMD to know about offlining
- Add support for soft offline mode
- Rebase and remove dummy lockdep annotation patch, as it merged from upstream
v10:
- Remove RFC
v7:
- Improve debugfs warning messages
- Usescope_guardfor locking(MattB)
- Adapt addition of queue member of LRC BO(MattB)
- Extend and usexe_ttm_bo_purgeAPI for vram pages(MattB)
- Handledma_buf_maprequests for native and remote(MattB)
- Address if in never initialized block, set block to NULL
- Add lockdep in gpu buddy (MattB)
- Correctallocated_addr_to_blocklogic (MattA)
V6:
- Add more specific tests to noncritical bo sections
- Handle smooth exit of user created exec queues
- Break code and make purge specific static API
V5:
- Sysfs "max_pages" addition
- Resetblock->privateNULL post purge
- Remove wedge, return-EIOto system controller will initiate reset
- Add debugfs tests to trigger different test scenarios manually and via igt
- Renameaddr_to_tbotoaddr_to_blockand move undergpu/buddy.c
V4: API reworks, add configfs for policy reservation and apply config everywhere
V3: useres_to_mem_regionto avoid use ofblock->private(MattA) V2:
- some fixes and clean up on errors
- Addedxe_vram_addr_to_regionhelper to avoid other use ofblock->private(MattB)IGT tests for testing this via injecting fault:
https://patchwork.freedesktop.org/patch/740601/Tejas Upadhyay (11):
drm/xe: Link VRAM object with gpu buddy
drm/gpu: Addgpu_buddy_allocated_addr_to_blockhelper drm/xe: Link LRC BO and its execution Queue
drm/xe: Extend BO purge to handle vram pages as well drm/xe: Handle physical memory address error gpu/buddy: Add routine to dump allocated buddy blocks drm/xe/configfs: Add vram bad page reservation policy drm/xe/cri: Add sysfs interface for bad gpu vram pages drm/xe/uapi: Expose ban reason inEXEC_QUEUE_GET_PROPERTY_BANdrm/xe: Add soft/hard offline mode for VRAM page retirement drm/xe: Add fault-inject based VRAM page offline injectiondrivers/gpu/buddy.c | 99 ++++ drivers/gpu/drm/xe/xe_bo.c | 16 +- drivers/gpu/drm/xe/xe_bo.h | 5 +- drivers/gpu/drm/xe/xe_bo_types.h | 3 + drivers/gpu/drm/xe/xe_configfs.c | 64 ++- drivers/gpu/drm/xe/xe_configfs.h | 2 + drivers/gpu/drm/xe/xe_debugfs.c | 40 ++ drivers/gpu/drm/xe/xe_device_sysfs.c | 7 + drivers/gpu/drm/xe/xe_dma_buf.c | 3 + drivers/gpu/drm/xe/xe_exec_queue.c | 13 +- drivers/gpu/drm/xe/xe_exec_queue_types.h | 7 +- drivers/gpu/drm/xe/xe_execlist.c | 4 +- drivers/gpu/drm/xe/xe_guc_submit.c | 30 +- drivers/gpu/drm/xe/xe_lrc.c | 1 + drivers/gpu/drm/xe/xe_pt.c | 3 +- drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 517 ++++++++++++++++++++- drivers/gpu/drm/xe/xe_ttm_vram_mgr.h | 3 + drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h | 42 ++ include/linux/gpu_buddy.h | 3 + include/uapi/drm/xe_drm.h | 12 +- 20 files changed, 829 insertions(+), 45 deletions(-)--
2.52.0