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

drm/vmwgfx: Don't refcount cotable lookups during command buffer validation

The typical pattern of these lookups are
-Lookup
-Put on validate list if not already there.
-Unreference
And since we are the exclusive user of the context during lookup time,
we can be sure that the resource will stay alive during the sequence.
So avoid taking a reference during lookup, and also avoid unreferencing
when done. There are two users outside of command buffer validation and
those are refcounted explicitly.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Sinclair Yeh <syeh@vmware.com>

+6 -10
+2 -3
drivers/gpu/drm/vmwgfx/vmwgfx_context.c
··· 861 861 if (cotable_type >= SVGA_COTABLE_DX10_MAX) 862 862 return ERR_PTR(-EINVAL); 863 863 864 - return vmw_resource_reference 865 - (container_of(ctx, struct vmw_user_context, res)-> 866 - cotables[cotable_type]); 864 + return container_of(ctx, struct vmw_user_context, res)-> 865 + cotables[cotable_type]; 867 866 } 868 867 869 868 /**
-5
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
··· 372 372 continue; 373 373 374 374 ret = vmw_resource_val_add(sw_context, res); 375 - vmw_resource_unreference(&res); 376 375 if (unlikely(ret != 0)) 377 376 return ret; 378 377 } ··· 1265 1266 1266 1267 cotable_res = vmw_context_cotable(ctx_node->ctx, SVGA_COTABLE_DXQUERY); 1267 1268 ret = vmw_cotable_notify(cotable_res, cmd->q.queryId); 1268 - vmw_resource_unreference(&cotable_res); 1269 1269 1270 1270 return ret; 1271 1271 } ··· 2576 2578 2577 2579 res = vmw_context_cotable(ctx_node->ctx, vmw_view_cotables[view_type]); 2578 2580 ret = vmw_cotable_notify(res, cmd->defined_id); 2579 - vmw_resource_unreference(&res); 2580 2581 if (unlikely(ret != 0)) 2581 2582 return ret; 2582 2583 ··· 2672 2675 res = vmw_context_cotable(ctx_node->ctx, vmw_so_cotables[so_type]); 2673 2676 cmd = container_of(header, typeof(*cmd), header); 2674 2677 ret = vmw_cotable_notify(res, cmd->defined_id); 2675 - vmw_resource_unreference(&res); 2676 2678 2677 2679 return ret; 2678 2680 } ··· 2802 2806 2803 2807 res = vmw_context_cotable(ctx_node->ctx, SVGA_COTABLE_DXSHADER); 2804 2808 ret = vmw_cotable_notify(res, cmd->body.shaderId); 2805 - vmw_resource_unreference(&res); 2806 2809 if (ret) 2807 2810 return ret; 2808 2811
+2 -1
drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
··· 636 636 637 637 res = &shader->res; 638 638 shader->ctx = ctx; 639 - shader->cotable = vmw_context_cotable(ctx, SVGA_COTABLE_DXSHADER); 639 + shader->cotable = vmw_resource_reference 640 + (vmw_context_cotable(ctx, SVGA_COTABLE_DXSHADER)); 640 641 shader->id = user_key; 641 642 shader->committed = false; 642 643 INIT_LIST_HEAD(&shader->cotable_head);
+2 -1
drivers/gpu/drm/vmwgfx/vmwgfx_so.c
··· 366 366 res = &view->res; 367 367 view->ctx = ctx; 368 368 view->srf = vmw_resource_reference(srf); 369 - view->cotable = vmw_context_cotable(ctx, vmw_view_cotables[view_type]); 369 + view->cotable = vmw_resource_reference 370 + (vmw_context_cotable(ctx, vmw_view_cotables[view_type])); 370 371 view->view_type = view_type; 371 372 view->view_id = user_key; 372 373 view->cmd_size = cmd_size;