|
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 | *
|
@@ -514,6 +521,12 @@ static int ttm_pool_restore_commit(struct ttm_pool_tt_restore *restore,
|
514 | 521 | if (ttm_backup_page_ptr_is_handle(p)) {
|
515 | 522 | unsigned long handle = ttm_backup_page_ptr_to_handle(p);
|
516 | 523 |
|
| 524 | + if (IS_ENABLED(CONFIG_FAULT_INJECTION) && ctx->interruptible && |
| 525 | + should_fail(&backup_fault_inject, 1)) { |
| 526 | + ret = -EINTR; |
| 527 | + break; |
| 528 | + } |
| 529 | + |
517 | 530 | if (handle == 0) {
|
518 | 531 | restore->restored_pages++;
|
519 | 532 | continue;
|
@@ -1007,7 +1020,13 @@ long ttm_pool_backup(struct ttm_pool *pool, struct ttm_tt *tt,
|
1007 | 1020 |
|
1008 | 1021 | alloc_gfp = GFP_KERNEL | __GFP_HIGH | __GFP_NOWARN | __GFP_RETRY_MAYFAIL;
|
1009 | 1022 |
|
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) { |
1011 | 1030 | s64 shandle;
|
1012 | 1031 |
|
1013 | 1032 | page = tt->pages[i];
|
@@ -1293,6 +1312,10 @@ int ttm_pool_mgr_init(unsigned long num_pages)
|
1293 | 1312 | &ttm_pool_debugfs_globals_fops);
|
1294 | 1313 | debugfs_create_file("page_pool_shrink", 0400, ttm_debugfs_root, NULL,
|
1295 | 1314 | &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 |
1296 | 1319 | #endif
|
1297 | 1320 |
|
1298 | 1321 | mm_shrinker = shrinker_alloc(0, "drm-ttm_pool");
|
|
0 commit comments