Skip to contentSkip to conversation

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

PATCH In review Zack Rusin 2 participants 2 messages Feb 10, 2023

Subsystems (3)
lore
Share & tools
lore

Zack Rusin

author
#0 lore raw

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

From: Zack Rusin <[email protected]>

In change 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.

Fixes 180253782038 ("drm/ttm: stop allocating dummy resources during BO creation")
Cc Christian König <[email protected]>
Cc Matthew Auld <[email protected]>
Cc Nirmoy Das <[email protected]>
Cc Christian Koenig <[email protected]>
Cc Huang Rui <[email protected]>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_resource.c   |  3 ++-
 drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 18 ++++++++++++++----
 2 files changed, 16 insertions(+), 5 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +2 -1
index 54e942df3b8e..71eeabf001c8 100644
@@ -837,7 +837,8 @@ void vmw_query_move_notify(struct ttm_buffer_object *bo,
 	mutex_lock(&dev_priv->binding_mutex);
 
 	/* If BO is being moved from MOB to system memory */
-	if (new_mem->mem_type == TTM_PL_SYSTEM &&
+	if (old_mem &&
+	    new_mem->mem_type == TTM_PL_SYSTEM &&
 	    old_mem->mem_type == VMW_PL_MOB) {
 		struct vmw_fence_obj *fence;
 
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c +14 -4
index 4daebc5b9eb4..af8562c95cc3 100644
@@ -515,9 +515,13 @@ static int vmw_move(struct ttm_buffer_object *bo,
 		    struct ttm_resource *new_mem,
 		    struct ttm_place *hop)
 {
-	struct ttm_resource_manager *old_man = ttm_manager_type(bo->bdev, bo->resource->mem_type);
-	struct ttm_resource_manager *new_man = ttm_manager_type(bo->bdev, new_mem->mem_type);
-	int ret;
+	struct ttm_resource_manager *new_man;
+	struct ttm_resource_manager *old_man = NULL;
+	int ret = 0;
+
+	new_man = ttm_manager_type(bo->bdev, new_mem->mem_type);
+	if (bo->resource)
+		old_man = ttm_manager_type(bo->bdev, bo->resource->mem_type);
 
 	if (new_man->use_tt && !vmw_memtype_is_system(new_mem->mem_type)) {
 		ret = vmw_ttm_bind(bo->bdev, bo->ttm, new_mem);
@@ -525,9 +529,15 @@ static int vmw_move(struct ttm_buffer_object *bo,
 			return ret;
 	}
 
+	if (!bo->resource || (bo->resource->mem_type == TTM_PL_SYSTEM &&
+			      bo->ttm == NULL)) {
+		ttm_bo_move_null(bo, new_mem);
+		return 0;
+	}
+
 	vmw_move_notify(bo, bo->resource, new_mem);
 
-	if (old_man->use_tt && new_man->use_tt) {
+	if (old_man && old_man->use_tt && new_man->use_tt) {
 		if (vmw_memtype_is_system(bo->resource->mem_type)) {
 			ttm_bo_move_null(bo, new_mem);
 			return 0;
Signature · 1 line
2.38.1
Reviewed-by on v1 1/1
#1 lore raw

Am 10.02.23 um 03:34 schrieb Zack Rusin:

Quoted 9 lines

From: Zack Rusin <[email protected]>

In change 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.

Quoted 8 lines
Fixes 180253782038 ("drm/ttm: stop allocating dummy resources during BO creation")
Cc Christian König <[email protected]>
Cc Matthew Auld <[email protected]>
Cc Nirmoy Das <[email protected]>
Cc Christian Koenig <[email protected]>
Cc Huang Rui <[email protected]>

Sorry for the noise.

Quoted 57 lines
---
  drivers/gpu/drm/vmwgfx/vmwgfx_resource.c   |  3 ++-
  drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 18 ++++++++++++++----
  2 files changed, 16 insertions(+), 5 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +2 -1
index 54e942df3b8e..71eeabf001c8 100644
@@ -837,7 +837,8 @@ void vmw_query_move_notify(struct ttm_buffer_object *bo,
  	mutex_lock(&dev_priv->binding_mutex);
 
  	/* If BO is being moved from MOB to system memory */
-	if (new_mem->mem_type == TTM_PL_SYSTEM &&
+	if (old_mem &&
+	    new_mem->mem_type == TTM_PL_SYSTEM &&
  	    old_mem->mem_type == VMW_PL_MOB) {
  		struct vmw_fence_obj *fence;
 
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c +14 -4
index 4daebc5b9eb4..af8562c95cc3 100644
@@ -515,9 +515,13 @@ static int vmw_move(struct ttm_buffer_object *bo,
  		    struct ttm_resource *new_mem,
  		    struct ttm_place *hop)
  {
-	struct ttm_resource_manager *old_man = ttm_manager_type(bo->bdev, bo->resource->mem_type);
-	struct ttm_resource_manager *new_man = ttm_manager_type(bo->bdev, new_mem->mem_type);
-	int ret;
+	struct ttm_resource_manager *new_man;
+	struct ttm_resource_manager *old_man = NULL;
+	int ret = 0;
+
+	new_man = ttm_manager_type(bo->bdev, new_mem->mem_type);
+	if (bo->resource)
+		old_man = ttm_manager_type(bo->bdev, bo->resource->mem_type);
 
  	if (new_man->use_tt && !vmw_memtype_is_system(new_mem->mem_type)) {
  		ret = vmw_ttm_bind(bo->bdev, bo->ttm, new_mem);
@@ -525,9 +529,15 @@ static int vmw_move(struct ttm_buffer_object *bo,
  			return ret;
  	}
 
+	if (!bo->resource || (bo->resource->mem_type == TTM_PL_SYSTEM &&
+			      bo->ttm == NULL)) {
+		ttm_bo_move_null(bo, new_mem);
+		return 0;
+	}
+
  	vmw_move_notify(bo, bo->resource, new_mem);
 
-	if (old_man->use_tt && new_man->use_tt) {
+	if (old_man && old_man->use_tt && new_man->use_tt) {
  		if (vmw_memtype_is_system(bo->resource->mem_type)) {
  			ttm_bo_move_null(bo, new_mem);
  			return 0;