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

drm/ttm: make TT creation purely optional v3

We only need the page array when the BO is about to be accessed.

So not only populate, but also create it on demand.

v2: move NULL check into ttm_tt_create()
v3: fix the occurrence in ttm_bo_kmap_ttm as well

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Michael J. Ruhl <michael.j.ruhl@intel.com>
Link: https://patchwork.freedesktop.org/patch/373182/

+22 -31
+9 -28
drivers/gpu/drm/ttm/ttm_bo.c
··· 292 292 */ 293 293 294 294 if (!(new_man->flags & TTM_MEMTYPE_FLAG_FIXED)) { 295 - if (bo->ttm == NULL) { 296 - bool zero = !(old_man->flags & TTM_MEMTYPE_FLAG_FIXED); 297 - ret = ttm_tt_create(bo, zero); 298 - if (ret) 299 - goto out_err; 300 - } 295 + bool zero = !(old_man->flags & TTM_MEMTYPE_FLAG_FIXED); 296 + 297 + ret = ttm_tt_create(bo, zero); 298 + if (ret) 299 + goto out_err; 301 300 302 301 ret = ttm_tt_set_placement_caching(bo->ttm, mem->placement); 303 302 if (ret) ··· 659 660 placement.num_busy_placement = 0; 660 661 bdev->driver->evict_flags(bo, &placement); 661 662 662 - if (!placement.num_placement && !placement.num_busy_placement) { 663 - ret = ttm_bo_pipeline_gutting(bo); 664 - if (ret) 665 - return ret; 666 - 667 - return ttm_tt_create(bo, false); 668 - } 663 + if (!placement.num_placement && !placement.num_busy_placement) 664 + return ttm_bo_pipeline_gutting(bo); 669 665 670 666 evict_mem = bo->mem; 671 667 evict_mem.mm_node = NULL; ··· 1189 1195 /* 1190 1196 * Remove the backing store if no placement is given. 1191 1197 */ 1192 - if (!placement->num_placement && !placement->num_busy_placement) { 1193 - ret = ttm_bo_pipeline_gutting(bo); 1194 - if (ret) 1195 - return ret; 1196 - 1197 - return ttm_tt_create(bo, false); 1198 - } 1198 + if (!placement->num_placement && !placement->num_busy_placement) 1199 + return ttm_bo_pipeline_gutting(bo); 1199 1200 1200 1201 /* 1201 1202 * Check whether we need to move buffer. ··· 1206 1217 */ 1207 1218 ttm_flag_masked(&bo->mem.placement, new_flags, 1208 1219 ~TTM_PL_MASK_MEMTYPE); 1209 - } 1210 - /* 1211 - * We might need to add a TTM. 1212 - */ 1213 - if (bo->mem.mem_type == TTM_PL_SYSTEM && bo->ttm == NULL) { 1214 - ret = ttm_tt_create(bo, true); 1215 - if (ret) 1216 - return ret; 1217 1220 } 1218 1221 return 0; 1219 1222 }
+5 -2
drivers/gpu/drm/ttm/ttm_bo_util.c
··· 532 532 .interruptible = false, 533 533 .no_wait_gpu = false 534 534 }; 535 - struct ttm_tt *ttm = bo->ttm; 535 + struct ttm_tt *ttm; 536 536 pgprot_t prot; 537 537 int ret; 538 538 539 - BUG_ON(!ttm); 539 + ret = ttm_tt_create(bo, true); 540 + if (ret) 541 + return ret; 540 542 543 + ttm = bo->ttm; 541 544 ret = ttm_tt_populate(ttm, &ctx); 542 545 if (ret) 543 546 return ret;
+5
drivers/gpu/drm/ttm/ttm_bo_vm.c
··· 349 349 350 350 }; 351 351 352 + if (ttm_tt_create(bo, true)) { 353 + ret = VM_FAULT_OOM; 354 + goto out_io_unlock; 355 + } 356 + 352 357 ttm = bo->ttm; 353 358 if (ttm_tt_populate(bo->ttm, &ctx)) { 354 359 ret = VM_FAULT_OOM;
+3 -1
drivers/gpu/drm/ttm/ttm_tt.c
··· 50 50 51 51 dma_resv_assert_held(bo->base.resv); 52 52 53 + if (bo->ttm) 54 + return 0; 55 + 53 56 if (bdev->need_dma32) 54 57 page_flags |= TTM_PAGE_FLAG_DMA32; 55 58 ··· 70 67 page_flags |= TTM_PAGE_FLAG_SG; 71 68 break; 72 69 default: 73 - bo->ttm = NULL; 74 70 pr_err("Illegal buffer object type\n"); 75 71 return -EINVAL; 76 72 }