Skip to content

Commit 8ae875f

Browse files
author
Thomas Hellström
committed
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 <[email protected]> Cc: Somalapuram Amaranath <[email protected]> Cc: Matthew Brost <[email protected]> Cc: <[email protected]> Signed-off-by: Thomas Hellström <[email protected]> Reviewed-by: Matthew Brost <[email protected]> Reviewed-by: Christian König <[email protected]> Link: https://lore.kernel.org/intel-xe/[email protected]
1 parent b63d715 commit 8ae875f

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

drivers/gpu/drm/ttm/ttm_pool.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@
4848

4949
#include "ttm_module.h"
5050

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+
5158
/**
5259
* struct ttm_pool_dma - Helper object for coherent DMA mappings
5360
*
@@ -514,6 +521,12 @@ static int ttm_pool_restore_commit(struct ttm_pool_tt_restore *restore,
514521
if (ttm_backup_page_ptr_is_handle(p)) {
515522
unsigned long handle = ttm_backup_page_ptr_to_handle(p);
516523

524+
if (IS_ENABLED(CONFIG_FAULT_INJECTION) && ctx->interruptible &&
525+
should_fail(&backup_fault_inject, 1)) {
526+
ret = -EINTR;
527+
break;
528+
}
529+
517530
if (handle == 0) {
518531
restore->restored_pages++;
519532
continue;
@@ -1007,7 +1020,13 @@ long ttm_pool_backup(struct ttm_pool *pool, struct ttm_tt *tt,
10071020

10081021
alloc_gfp = GFP_KERNEL | __GFP_HIGH | __GFP_NOWARN | __GFP_RETRY_MAYFAIL;
10091022

1010-
for (i = 0; i < tt->num_pages; ++i) {
1023+
num_pages = tt->num_pages;
1024+
1025+
/* Pretend doing fault injection by shrinking only half of the pages. */
1026+
if (IS_ENABLED(CONFIG_FAULT_INJECTION) && should_fail(&backup_fault_inject, 1))
1027+
num_pages = DIV_ROUND_UP(num_pages, 2);
1028+
1029+
for (i = 0; i < num_pages; ++i) {
10111030
s64 shandle;
10121031

10131032
page = tt->pages[i];
@@ -1293,6 +1312,10 @@ int ttm_pool_mgr_init(unsigned long num_pages)
12931312
&ttm_pool_debugfs_globals_fops);
12941313
debugfs_create_file("page_pool_shrink", 0400, ttm_debugfs_root, NULL,
12951314
&ttm_pool_debugfs_shrink_fops);
1315+
#ifdef CONFIG_FAULT_INJECTION
1316+
fault_create_debugfs_attr("backup_fault_inject", ttm_debugfs_root,
1317+
&backup_fault_inject);
1318+
#endif
12961319
#endif
12971320

12981321
mm_shrinker = shrinker_alloc(0, "drm-ttm_pool");

0 commit comments

Comments
 (0)