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

drm/vmwgfx: Make the driver work without the dummy resources

In commit 180253782038 ("drm/ttm: stop allocating dummy resources during BO creation")
ttm stopped allocating dummy resources but vmwgfx was never ported to
handle it. Make the driver treat null resources as initial creation and
port code to handle null resources in general.

Fixes kernel oops'es on boot with vmwgfx.

Signed-off-by: Zack Rusin <zackr@vmware.com>
Fixes: 180253782038 ("drm/ttm: stop allocating dummy resources during BO creation")
Cc: Christian König <christian.koenig@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Nirmoy Das <nirmoy.das@intel.com>
Cc: Christian Koenig <christian.koenig@amd.com>
Cc: Huang Rui <ray.huang@amd.com>
Cc: dri-devel@lists.freedesktop.org
Reviewed-by: Christian König <christian.koenig@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230210023437.2214816-1-zack@kde.org

+16 -5
+2 -1
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
··· 837 837 mutex_lock(&dev_priv->binding_mutex); 838 838 839 839 /* If BO is being moved from MOB to system memory */ 840 - if (new_mem->mem_type == TTM_PL_SYSTEM && 840 + if (old_mem && 841 + new_mem->mem_type == TTM_PL_SYSTEM && 841 842 old_mem->mem_type == VMW_PL_MOB) { 842 843 struct vmw_fence_obj *fence; 843 844
+14 -4
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
··· 515 515 struct ttm_resource *new_mem, 516 516 struct ttm_place *hop) 517 517 { 518 - struct ttm_resource_manager *old_man = ttm_manager_type(bo->bdev, bo->resource->mem_type); 519 - struct ttm_resource_manager *new_man = ttm_manager_type(bo->bdev, new_mem->mem_type); 520 - int ret; 518 + struct ttm_resource_manager *new_man; 519 + struct ttm_resource_manager *old_man = NULL; 520 + int ret = 0; 521 + 522 + new_man = ttm_manager_type(bo->bdev, new_mem->mem_type); 523 + if (bo->resource) 524 + old_man = ttm_manager_type(bo->bdev, bo->resource->mem_type); 521 525 522 526 if (new_man->use_tt && !vmw_memtype_is_system(new_mem->mem_type)) { 523 527 ret = vmw_ttm_bind(bo->bdev, bo->ttm, new_mem); ··· 529 525 return ret; 530 526 } 531 527 528 + if (!bo->resource || (bo->resource->mem_type == TTM_PL_SYSTEM && 529 + bo->ttm == NULL)) { 530 + ttm_bo_move_null(bo, new_mem); 531 + return 0; 532 + } 533 + 532 534 vmw_move_notify(bo, bo->resource, new_mem); 533 535 534 - if (old_man->use_tt && new_man->use_tt) { 536 + if (old_man && old_man->use_tt && new_man->use_tt) { 535 537 if (vmw_memtype_is_system(bo->resource->mem_type)) { 536 538 ttm_bo_move_null(bo, new_mem); 537 539 return 0;