Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/ttm: Use fault-injection to test error paths

Use fault-injection to test partial TTM swapout and interrupted swapin.
Return -EINTR for swapin to test the callers ability to handle and
restart the swapin, and on swapout perform a partial swapout to test that
the swapin and release_shrunken functionality.

v8:
- Use the core fault-injection system.
v9:
- Fix compliation failure for !CONFIG_FAULT_INJECTION

Cc: Christian König <christian.koenig@amd.com>
Cc: Somalapuram Amaranath <Amaranath.Somalapuram@amd.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: <dri-devel@lists.freedesktop.org>
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Link: https://lore.kernel.org/intel-xe/20250305092220.123405-4-thomas.hellstrom@linux.intel.com

+24 -1
+24 -1
drivers/gpu/drm/ttm/ttm_pool.c
··· 48 48 49 49 #include "ttm_module.h" 50 50 51 + #ifdef CONFIG_FAULT_INJECTION 52 + #include <linux/fault-inject.h> 53 + static DECLARE_FAULT_ATTR(backup_fault_inject); 54 + #else 55 + #define should_fail(...) false 56 + #endif 57 + 51 58 /** 52 59 * struct ttm_pool_dma - Helper object for coherent DMA mappings 53 60 * ··· 520 513 p = first_page[i]; 521 514 if (ttm_backup_page_ptr_is_handle(p)) { 522 515 unsigned long handle = ttm_backup_page_ptr_to_handle(p); 516 + 517 + if (IS_ENABLED(CONFIG_FAULT_INJECTION) && ctx->interruptible && 518 + should_fail(&backup_fault_inject, 1)) { 519 + ret = -EINTR; 520 + break; 521 + } 523 522 524 523 if (handle == 0) { 525 524 restore->restored_pages++; ··· 1020 1007 1021 1008 alloc_gfp = GFP_KERNEL | __GFP_HIGH | __GFP_NOWARN | __GFP_RETRY_MAYFAIL; 1022 1009 1023 - for (i = 0; i < tt->num_pages; ++i) { 1010 + num_pages = tt->num_pages; 1011 + 1012 + /* Pretend doing fault injection by shrinking only half of the pages. */ 1013 + if (IS_ENABLED(CONFIG_FAULT_INJECTION) && should_fail(&backup_fault_inject, 1)) 1014 + num_pages = DIV_ROUND_UP(num_pages, 2); 1015 + 1016 + for (i = 0; i < num_pages; ++i) { 1024 1017 s64 shandle; 1025 1018 1026 1019 page = tt->pages[i]; ··· 1312 1293 &ttm_pool_debugfs_globals_fops); 1313 1294 debugfs_create_file("page_pool_shrink", 0400, ttm_debugfs_root, NULL, 1314 1295 &ttm_pool_debugfs_shrink_fops); 1296 + #ifdef CONFIG_FAULT_INJECTION 1297 + fault_create_debugfs_attr("backup_fault_inject", ttm_debugfs_root, 1298 + &backup_fault_inject); 1299 + #endif 1315 1300 #endif 1316 1301 1317 1302 mm_shrinker = shrinker_alloc(0, "drm-ttm_pool");