drm/vmwgfx: Add a validation module v2
Subsystems (4)
PATCH 1/18 drm/vmwgfx: Add a validation module v2
Isolate the functionality needed for reservation, validation and fencing of vmwgfx buffer objects and resources and publish an API for this.
--- drivers/gpu/drm/vmwgfx/Makefile | 3 +- drivers/gpu/drm/vmwgfx/vmwgfx_validation.c | 659 +++++++++++++++++++++++++++++ drivers/gpu/drm/vmwgfx/vmwgfx_validation.h | 202 +++++++++ 3 files changed, 863 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/vmwgfx/vmwgfx_validation.c create mode 100644 drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
drivers/gpu/drm/vmwgfx/Makefile +2 -1
@@ -7,6 +7,7 @@ vmwgfx-y := vmwgfx_execbuf.o vmwgfx_gmr.o vmwgfx_kms.o vmwgfx_drv.o \ vmwgfx_surface.o vmwgfx_prime.o vmwgfx_mob.o vmwgfx_shader.o \ vmwgfx_cmdbuf_res.o vmwgfx_cmdbuf.o vmwgfx_stdu.o \ vmwgfx_cotable.o vmwgfx_so.o vmwgfx_binding.o vmwgfx_msg.o \ - vmwgfx_simple_resource.o vmwgfx_va.o vmwgfx_blit.o + vmwgfx_simple_resource.o vmwgfx_va.o vmwgfx_blit.o \ + vmwgfx_validation.o obj-$(CONFIG_DRM_VMWGFX) := vmwgfx.o
drivers/gpu/drm/vmwgfx/vmwgfx_validation.c new file +659 -0
659 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_validation.h new file +202 -0
202 lines not on this page · raw message
Signature · 6 lines
2.14.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/18 drm/vmwgfx: Modify the resource validation interface
Allow selecting interruptible or uninterruptible waits to match expectations of callers.
--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 13 ++++++++----- drivers/gpu/drm/vmwgfx/vmwgfx_validation.c | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +1 -1
@@ -628,7 +628,7 @@ extern void vmw_resource_unreference(struct vmw_resource **p_res);extern struct vmw_resource *vmw_resource_reference (struct vmw_resource *res);extern struct vmw_resource *vmw_resource_reference_unless_doomed (struct vmw_resource *res); -extern int vmw_resource_validate (struct vmw_resource *res); +extern int vmw_resource_validate (struct vmw_resource *res,bool intr);extern int vmw_resource_reserve (struct vmw_resource *res,bool interruptible,bool no_backup);extern bool vmw_resource_needs_backup (const struct vmw_resource *res);
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +1 -1
@@ -659,7 +659,7 @@ static int vmw_resources_validate(struct vmw_sw_context *sw_context)struct vmw_resource *res = val->res;struct vmw_buffer_object *backup = res->backup; - ret =vmw_resource_validate (res); + ret =vmw_resource_validate (res, true);if (unlikely (ret !=0 )) {if (ret != -ERESTARTSYS )DRM_ERROR ("Failed to validate resource.\n" );
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +1 -1
@@ -2713,7 +2713,7 @@ int vmw_kms_helper_resource_prepare(struct vmw_resource *res, ctx->buf =vmw_bo_reference (res->backup); } - ret =vmw_resource_validate (res); + ret =vmw_resource_validate (res, interruptible);if (ret) goto out_revert;return 0 ;
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +8 -5
@@ -587,15 +587,18 @@ static int vmw_resource_do_evict(struct ww_acquire_ctx *ticket,/** * vmw_resource_validate - Make a resource up-to-date and visible * to the device. -* -* @res: The resource to make visible to the device. +* @res: The resource to make visible to the device. +* @intr: Perform waits interruptible if possible. * * On succesful return, any backup DMA buffer pointed to by @res->backup will * be reserved and validated. * On hardware resource shortage, this function will repeatedly evict * resources of the same type until the validation succeeds. +* +* Return: Zero on success, -ERESTARTSYS if interrupted, negative error code +* on failure. */ -int vmw_resource_validate (struct vmw_resource *res) +int vmw_resource_validate (struct vmw_resource *res,bool intr) {int ret;struct vmw_resource *evict_res;
@@ -633,7 +636,7 @@ int vmw_resource_validate(struct vmw_resource *res)write_unlock (&dev_priv->resource_lock);/* Trylock backup buffers with a NULL ticket. */ - ret =vmw_resource_do_evict (NULL , evict_res, true); + ret =vmw_resource_do_evict (NULL , evict_res, intr);if (unlikely (ret !=0 )) {write_lock (&dev_priv->resource_lock);list_add_tail (&evict_res->lru_head, lru_list);
@@ -914,7 +917,7 @@ int vmw_resource_pin(struct vmw_resource *res, bool interruptible)/* Do we really need to pin the MOB as well? */ vmw_bo_pin_reserved (vbo, true); } - ret =vmw_resource_validate (res); + ret =vmw_resource_validate (res, interruptible);if (vbo)ttm_bo_unreserve (&vbo->base);if (ret)
drivers/gpu/drm/vmwgfx/vmwgfx_validation.c +1 -1
@@ -479,7 +479,7 @@ int vmw_validation_res_validate(struct vmw_validation_context *ctx, bool intr)struct vmw_resource *res = val->res;struct vmw_buffer_object *backup = res->backup; - ret =vmw_resource_validate (res); + ret =vmw_resource_validate (res, intr);if (ret) {if (ret != -ERESTARTSYS )DRM_ERROR ("Failed to validate resource.\n" );
Signature · 6 lines
2.14.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 3/18 drm/vmwgfx: Adapt execbuf to the new validation api
In reply to Thomas HellstromStrip the old execbuf validation functionality and use the new API instead. Also use the new API for a now removed execbuf function that was called from the kms code.
--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 65 ++- drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 885 +++++++++++--------------------- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 4 +- 3 files changed, 360 insertions(+), 594 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +48 -17
@@ -28,6 +28,7 @@#ifndef _VMWGFX_DRV_H_#define _VMWGFX_DRV_H_ +#include "vmwgfx_validation.h" #include "vmwgfx_reg.h" #include <drm/drmP.h> #include <drm/vmwgfx_drm.h>
@@ -207,26 +208,27 @@ struct vmw_fifo_state {struct vmw_relocation {SVGAMobId *mob_loc;SVGAGuestPtr *location; -uint32_t index; +struct vmw_buffer_object *vbo; };/** * struct vmw_res_cache_entry - resource information cache entry -* +* @handle: User-space handle of a resource. +* @res: Non-ref-counted pointer to the resource. +* @valid_handle: Whether the @handle member is valid. * @valid: Whether the entry is valid, which also implies that the execbuf * code holds a reference to the resource, and it's placed on the * validation list. -* @handle: User-space handle of a resource. -* @res: Non-ref-counted pointer to the resource. * * Used to avoid frequent repeated user-space handle lookups of the * same resource. */ struct vmw_res_cache_entry { -bool valid;uint32_t handle;struct vmw_resource *res; -struct vmw_resource_val_node *node; +void *private; +unsigned short valid_handle; +unsigned short valid; };/**
@@ -291,21 +293,52 @@ enum vmw_display_unit_type {vmw_du_screen_target }; +struct vmw_validation_context ; +struct vmw_ctx_validation_info ; +/** +* struct vmw_sw_context - Command submission context +* @res_ht: Pointer hash table used to find validation duplicates +* @kernel: Whether the command buffer originates from kernel code rather +* than from user-space +* @fp: If @kernel is false, points to the file of the client. Otherwise +* NULL +* @relocs: Array of buffer object relocations +* @cur_reloc: Cursor pointing to the current relocation +* @cmd_bounce: Command bounce buffer used for command validation before +* copying to fifo space +* @cmd_bounce_size: Current command bounce buffer size +* @cur_query_bo: Current buffer object used as query result buffer +* @res_relocations: List of resource relocations +* @buf_start: Pointer to start of memory where command validation takes +* place +* @res_cache: Cache of recently looked up resources +* @last_query_ctx: Last context that submitted a query +* @needs_post_query_barrier: Whether a query barrier is needed after +* command submission +* @error_resource: Pointer to hold a reference to the resource causing +* an error +* @staged_bindings: Cached per-context binding tracker +* @staged_bindings_inuse: Whether the cached per-context binding tracker +* is in use +* @staged_cmd_res: List of staged command buffer managed resources in this +* command buffer +* @ctx_list: List of context resources referenced in this command buffer +* @dx_ctx_node: Validation metadata of the current DX context +* @dx_query_mob: The MOB used for DX queries +* @dx_query_ctx: The DX context used for the last DX query +* @man: Pointer to the command buffer managed resource manager +* @ctx: The validation context +*/ struct vmw_sw_context {struct drm_open_hash res_ht;bool res_ht_initialized; -bool kernel;/**< is the called made from the kernel */ +bool kernel;struct vmw_fpriv *fp; -struct list_head validate_nodes;struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS ];uint32_t cur_reloc; -struct vmw_validate_buffer val_bufs[VMWGFX_MAX_VALIDATIONS ]; -uint32_t cur_val_buf;uint32_t *cmd_bounce;uint32_t cmd_bounce_size; -struct list_head resource_list; -struct list_head ctx_resource_list;/* For contexts and cotables */ struct vmw_buffer_object *cur_query_bo;struct list_head res_relocations;uint32_t *buf_start;
@@ -316,10 +349,12 @@ struct vmw_sw_context{struct vmw_ctx_binding_state *staged_bindings;bool staged_bindings_inuse;struct list_head staged_cmd_res; -struct vmw_resource_val_node *dx_ctx_node; +struct list_head ctx_list; +struct vmw_ctx_validation_info *dx_ctx_node;struct vmw_buffer_object *dx_query_mob;struct vmw_resource *dx_query_ctx;struct vmw_cmdbuf_res_manager *man; +struct vmw_validation_context *ctx; };struct vmw_legacy_display ;
@@ -864,10 +899,6 @@ extern void vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,uint32_t fence_handle, int32_t out_fence_fd, struct sync_file *sync_file); -extern int vmw_validate_single_buffer (struct vmw_private *dev_priv, -struct ttm_buffer_object *bo, -bool interruptible, -bool validate_as_mob);bool vmw_cmd_describe (const void *buf,u32 *size,char const **cmd);/**
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +310 -575
1,662 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +2 -2
@@ -2586,8 +2586,8 @@ int vmw_kms_helper_buffer_prepare(struct vmw_private *dev_priv,if (for_cpu_blit) ret =ttm_bo_validate (bo, &vmw_nonfixed_placement, &ctx);else - ret =vmw_validate_single_buffer (dev_priv, bo, interruptible, - validate_as_mob); + ret =vmw_validation_bo_validate_single (bo, interruptible, + validate_as_mob);if (ret)ttm_bo_unreserve (bo);
Signature · 6 lines
2.14.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 4/18 drm/vmwgfx: Use new validation interface for the modesetting code v2
In reply to Thomas HellstromStrip the old KMS helpers and use the new validation interface also in the modesetting code.
--- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 199 ++++------------------------------- drivers/gpu/drm/vmwgfx/vmwgfx_kms.h | 24 ++--- drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c | 48 ++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c | 31 ++++-- 4 files changed, 86 insertions(+), 216 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +21 -178
@@ -2557,88 +2557,31 @@ int vmw_kms_helper_dirty(struct vmw_private *dev_priv, }/** -* vmw_kms_helper_buffer_prepare - Reserve and validate a buffer object before -* command submission. -* -* @dev_priv. Pointer to a device private structure. -* @buf: The buffer object -* @interruptible: Whether to perform waits as interruptible. -* @validate_as_mob: Whether the buffer should be validated as a MOB. If false, -* The buffer will be validated as a GMR. Already pinned buffers will not be -* validated. -* -* Returns 0 on success, negative error code on failure, -ERESTARTSYS if -* interrupted by a signal. +* vmw_kms_helper_validation_finish - Helper for post KMS command submission +* cleanup and fencing +* @dev_priv: Pointer to the device-private struct +* @file_priv: Pointer identifying the client when user-space fencing is used +* @ctx: Pointer to the validation context +* @out_fence: If non-NULL, returned refcounted fence-pointer +* @user_fence_rep: If non-NULL, pointer to user-space address area +* in which to copy user-space fence info */ -int vmw_kms_helper_buffer_prepare (struct vmw_private *dev_priv, -struct vmw_buffer_object *buf, -bool interruptible, -bool validate_as_mob, -bool for_cpu_blit) -{ -struct ttm_operation_ctx ctx = { - .interruptible = interruptible, - .no_wait_gpu = false}; -struct ttm_buffer_object *bo = &buf->base; -int ret; - -ttm_bo_reserve (bo, false, false,NULL ); -if (for_cpu_blit) - ret =ttm_bo_validate (bo, &vmw_nonfixed_placement, &ctx); -else - ret =vmw_validation_bo_validate_single (bo, interruptible, - validate_as_mob); -if (ret) -ttm_bo_unreserve (bo); - -return ret; -} - -/** -* vmw_kms_helper_buffer_revert - Undo the actions of -* vmw_kms_helper_buffer_prepare. -* -* @res: Pointer to the buffer object. -* -* Helper to be used if an error forces the caller to undo the actions of -* vmw_kms_helper_buffer_prepare. -*/ -void vmw_kms_helper_buffer_revert (struct vmw_buffer_object *buf) -{ -if (buf) -ttm_bo_unreserve (&buf->base); -} - -/** -* vmw_kms_helper_buffer_finish - Unreserve and fence a buffer object after -* kms command submission. -* -* @dev_priv: Pointer to a device private structure. -* @file_priv: Pointer to a struct drm_file representing the caller's -* connection. Must be set to NULL if @user_fence_rep is NULL, and conversely -* if non-NULL, @user_fence_rep must be non-NULL. -* @buf: The buffer object. -* @out_fence: Optional pointer to a fence pointer. If non-NULL, a -* ref-counted fence pointer is returned here. -* @user_fence_rep: Optional pointer to a user-space provided struct -* drm_vmw_fence_rep. If provided, @file_priv must also be provided and the -* function copies fence data to user-space in a fail-safe manner. -*/ -void vmw_kms_helper_buffer_finish (struct vmw_private *dev_priv, -struct drm_file *file_priv, -struct vmw_buffer_object *buf, -struct vmw_fence_obj **out_fence, -struct drm_vmw_fence_rep __user * - user_fence_rep) -{ -struct vmw_fence_obj *fence; +void vmw_kms_helper_validation_finish (struct vmw_private *dev_priv, +struct drm_file *file_priv, +struct vmw_validation_context *ctx, +struct vmw_fence_obj **out_fence, +struct drm_vmw_fence_rep __user * + user_fence_rep) +{ +struct vmw_fence_obj *fence =NULL ;uint32_t handle;int ret; - ret =vmw_execbuf_fence_commands (file_priv, dev_priv, &fence, - file_priv ? &handle :NULL ); -if (buf) -vmw_bo_fence_single (&buf->base, fence); +if (file_priv || user_fence_rep ||vmw_validation_has_bos (ctx) || + out_fence) + ret =vmw_execbuf_fence_commands (file_priv, dev_priv, &fence, + file_priv ? &handle :NULL ); +vmw_validation_done (ctx, fence);if (file_priv) vmw_execbuf_copy_fence_user(dev_priv, vmw_fpriv(file_priv), ret, user_fence_rep, fence,
@@ -2647,106 +2590,6 @@ void vmw_kms_helper_buffer_finish(struct vmw_private *dev_priv, *out_fence = fence; else vmw_fence_obj_unreference(&fence); - -vmw_kms_helper_buffer_revert (buf); -} - - -/** -* vmw_kms_helper_resource_revert - Undo the actions of -* vmw_kms_helper_resource_prepare. -* -* @res: Pointer to the resource. Typically a surface. -* -* Helper to be used if an error forces the caller to undo the actions of -* vmw_kms_helper_resource_prepare. -*/ -void vmw_kms_helper_resource_revert (struct vmw_validation_ctx *ctx) -{ -struct vmw_resource *res = ctx->res; - -vmw_kms_helper_buffer_revert (ctx->buf); -vmw_bo_unreference (&ctx->buf); -vmw_resource_unreserve (res, false,NULL ,0 ); -mutex_unlock (&res->dev_priv->cmdbuf_mutex); -} - -/** -* vmw_kms_helper_resource_prepare - Reserve and validate a resource before -* command submission. -* -* @res: Pointer to the resource. Typically a surface. -* @interruptible: Whether to perform waits as interruptible. -* -* Reserves and validates also the backup buffer if a guest-backed resource. -* Returns 0 on success, negative error code on failure. -ERESTARTSYS if -* interrupted by a signal. -*/ -int vmw_kms_helper_resource_prepare (struct vmw_resource *res, -bool interruptible, -struct vmw_validation_ctx *ctx) -{ -int ret =0 ; - - ctx->buf =NULL ; - ctx->res = res; - -if (interruptible) - ret =mutex_lock_interruptible (&res->dev_priv->cmdbuf_mutex); -else -mutex_lock (&res->dev_priv->cmdbuf_mutex); - -if (unlikely (ret !=0 )) -return -ERESTARTSYS ; - - ret =vmw_resource_reserve (res, interruptible, false); -if (ret) - goto out_unlock; - -if (res->backup) { - ret =vmw_kms_helper_buffer_prepare (res->dev_priv, res->backup, - interruptible, - res->dev_priv->has_mob, - false); -if (ret) - goto out_unreserve; - - ctx->buf =vmw_bo_reference (res->backup); - } - ret =vmw_resource_validate (res, interruptible); -if (ret) - goto out_revert; -return 0 ; - -out_revert: -vmw_kms_helper_buffer_revert (ctx->buf); -out_unreserve: -vmw_resource_unreserve (res, false,NULL ,0 ); -out_unlock: -mutex_unlock (&res->dev_priv->cmdbuf_mutex); -return ret; -} - -/** -* vmw_kms_helper_resource_finish - Unreserve and fence a resource after -* kms command submission. -* -* @res: Pointer to the resource. Typically a surface. -* @out_fence: Optional pointer to a fence pointer. If non-NULL, a -* ref-counted fence pointer is returned here. -*/ -void vmw_kms_helper_resource_finish (struct vmw_validation_ctx *ctx, -struct vmw_fence_obj **out_fence) -{ -struct vmw_resource *res = ctx->res; - -if (ctx->buf || out_fence) -vmw_kms_helper_buffer_finish (res->dev_priv,NULL , ctx->buf, - out_fence,NULL ); - -vmw_bo_unreference (&ctx->buf); -vmw_resource_unreserve (res, false,NULL ,0 ); -mutex_unlock (&res->dev_priv->cmdbuf_mutex); }/**
drivers/gpu/drm/vmwgfx/vmwgfx_kms.h +6 -18
@@ -308,24 +308,12 @@ int vmw_kms_helper_dirty(struct vmw_private *dev_priv,int increment, struct vmw_kms_dirty *dirty); -int vmw_kms_helper_buffer_prepare (struct vmw_private *dev_priv, -struct vmw_buffer_object *buf, -bool interruptible, -bool validate_as_mob, -bool for_cpu_blit); -void vmw_kms_helper_buffer_revert (struct vmw_buffer_object *buf); -void vmw_kms_helper_buffer_finish (struct vmw_private *dev_priv, -struct drm_file *file_priv, -struct vmw_buffer_object *buf, -struct vmw_fence_obj **out_fence, -struct drm_vmw_fence_rep __user * - user_fence_rep); -int vmw_kms_helper_resource_prepare (struct vmw_resource *res, -bool interruptible, -struct vmw_validation_ctx *ctx); -void vmw_kms_helper_resource_revert (struct vmw_validation_ctx *ctx); -void vmw_kms_helper_resource_finish (struct vmw_validation_ctx *ctx, -struct vmw_fence_obj **out_fence); +void vmw_kms_helper_validation_finish (struct vmw_private *dev_priv, +struct drm_file *file_priv, +struct vmw_validation_context *ctx, +struct vmw_fence_obj **out_fence, +struct drm_vmw_fence_rep __user * + user_fence_rep); int vmw_kms_readback(struct vmw_private *dev_priv, struct drm_file *file_priv, struct vmw_framebuffer *vfb,
drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c +35 -13
111 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c +24 -7
@@ -759,17 +759,21 @@ int vmw_kms_stdu_dma(struct vmw_private *dev_priv,struct vmw_stdu_dirty ddirty;int ret;bool cpu_blit = !(dev_priv->capabilities &SVGA_CAP_3D ); +DECLARE_VAL_CONTEXT (val_ctx,NULL ,0 );/* * VMs without 3D support don't have the surface DMA command and * we'll be using a CPU blit, and the framebuffer should be moved out * of VRAM. */ - ret =vmw_kms_helper_buffer_prepare (dev_priv, buf, interruptible, - false, cpu_blit); + ret =vmw_validation_add_bo (&val_ctx, buf, false, cpu_blit);if (ret)return ret; + ret =vmw_validation_prepare (&val_ctx,NULL , interruptible); +if (ret) + goto out_unref; + ddirty.transfer = (to_surface) ?SVGA3D_WRITE_HOST_VRAM :SVGA3D_READ_HOST_VRAM ; ddirty.left = ddirty.top =S32_MAX ;
@@ -796,9 +800,13 @@ int vmw_kms_stdu_dma(struct vmw_private *dev_priv, ret =vmw_kms_helper_dirty (dev_priv, vfb, clips, vclips,0 ,0 , num_clips, increment, &ddirty.base); -vmw_kms_helper_buffer_finish (dev_priv, file_priv, buf,NULL , - user_fence_rep); +vmw_kms_helper_validation_finish (dev_priv, file_priv, &val_ctx,NULL , + user_fence_rep); +return ret; + +out_unref: +vmw_validation_unref_lists (&val_ctx);return ret; }
@@ -924,16 +932,20 @@ int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv,struct vmw_framebuffer_surface *vfbs =container_of (framebuffer,typeof (*vfbs), base);struct vmw_stdu_dirty sdirty; -struct vmw_validation_ctx ctx; +DECLARE_VAL_CONTEXT (val_ctx,NULL ,0 );int ret;if (!srf) srf = &vfbs->surface->res; - ret =vmw_kms_helper_resource_prepare (srf, true, &ctx); + ret =vmw_validation_add_resource (&val_ctx, srf,0 ,NULL ,NULL );if (ret)return ret; + ret =vmw_validation_prepare (&val_ctx, &dev_priv->cmdbuf_mutex, true); +if (ret) + goto out_unref; +if (vfbs->is_bo_proxy) { ret =vmw_kms_update_proxy (srf, clips, num_clips, inc);if (ret)
@@ -954,8 +966,13 @@ int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv, dest_x, dest_y, num_clips, inc, &sdirty.base); out_finish: -vmw_kms_helper_resource_finish (&ctx, out_fence); +vmw_kms_helper_validation_finish (dev_priv,NULL , &val_ctx, out_fence, +NULL ); + +return ret; +out_unref: +vmw_validation_unref_lists (&val_ctx);return ret; }
Signature · 6 lines
2.14.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 5/18 drm/vmwgfx: Use a validation context allocator for relocations and validations
In reply to Thomas HellstromA common trait of these objects are that they are allocated during the command validation phase and freed after command submission. Furthermore they are accessed by a single thread only. So provide a simple unprotected stack-like allocator from which these objects can be allocated. Their memory is freed with the validation context when the command submission is done.
Note that the mm subsystem maintains a per-cpu cache of single pages to make single page allocation and freeing efficient.
--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 12 +--- drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 80 ++++++++++++++------------ drivers/gpu/drm/vmwgfx/vmwgfx_validation.c | 92 ++++++++++++++++++++++++------ drivers/gpu/drm/vmwgfx/vmwgfx_validation.h | 12 +++- 4 files changed, 132 insertions(+), 64 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +2 -10
@@ -205,12 +205,6 @@ struct vmw_fifo_state {bool dx; }; -struct vmw_relocation { -SVGAMobId *mob_loc; -SVGAGuestPtr *location; -struct vmw_buffer_object *vbo; -}; -/** * struct vmw_res_cache_entry - resource information cache entry * @handle: User-space handle of a resource.
@@ -303,12 +297,11 @@ struct vmw_ctx_validation_info;* than from user-space * @fp: If @kernel is false, points to the file of the client. Otherwise * NULL -* @relocs: Array of buffer object relocations -* @cur_reloc: Cursor pointing to the current relocation * @cmd_bounce: Command bounce buffer used for command validation before * copying to fifo space * @cmd_bounce_size: Current command bounce buffer size * @cur_query_bo: Current buffer object used as query result buffer +* @bo_relocations: List of buffer object relocations * @res_relocations: List of resource relocations * @buf_start: Pointer to start of memory where command validation takes * place
@@ -335,11 +328,10 @@ struct vmw_sw_context{bool res_ht_initialized;bool kernel;struct vmw_fpriv *fp; -struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS ]; -uint32_t cur_reloc;uint32_t *cmd_bounce;uint32_t cmd_bounce_size;struct vmw_buffer_object *cur_query_bo; +struct list_head bo_relocations;struct list_head res_relocations;uint32_t *buf_start;struct vmw_res_cache_entry res_cache[vmw_res_max];
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +44 -36
210 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_validation.c +75 -17
140 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_validation.h +11 -1
@@ -40,19 +40,25 @@* @resource_ctx_list: List head for resource validation metadata for * resources that need to be validated before those in @resource_list * @bo_list: List head for buffer objects +* @page_list: List of pages used by the memory allocator * @ticket: Ticked used for ww mutex locking * @res_mutex: Pointer to mutex used for resource reserving * @merge_dups: Whether to merge metadata for duplicate resources or * buffer objects +* @mem_size_left: Free memory left in the last page in @page_list +* @page_address: Kernel virtual address of the last page in @page_list */ struct vmw_validation_context {struct drm_open_hash *ht;struct list_head resource_list;struct list_head resource_ctx_list;struct list_head bo_list; +struct list_head page_list;struct ww_acquire_ctx ticket;struct mutex *res_mutex;unsigned int merge_dups; +unsigned int mem_size_left; +u8 *page_address; };struct vmw_buffer_object ;
@@ -76,8 +82,10 @@ struct vmw_fence_obj; .resource_list = LIST_HEAD_INIT((_name).resource_list), \ .resource_ctx_list = LIST_HEAD_INIT((_name).resource_ctx_list), \ .bo_list = LIST_HEAD_INIT((_name).bo_list), \ + .page_list = LIST_HEAD_INIT((_name).page_list), \ + .res_mutex = NULL, \ .merge_dups = _merge_dups, \ - .res_mutex = NULL \ + .mem_size_left = 0, \ }/**
@@ -199,4 +207,6 @@ void vmw_validation_revert(struct vmw_validation_context *ctx);void vmw_validation_done (struct vmw_validation_context *ctx,struct vmw_fence_obj *fence); +void *vmw_validation_mem_alloc (struct vmw_validation_context *ctx,size_t size); +#endif
Signature · 6 lines
2.14.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 6/18 drm/vmwgfx: Reduce the size of buffer object relocations
In reply to Thomas HellstromWith the new allocator this leads to less consumed memory for each user-space command submission
--- drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +5 -4
@@ -39,15 +39,17 @@* struct vmw_relocation - Buffer object relocation * * @head: List head for the command submission context's relocation list +* @vbo: Non ref-counted pointer to buffer object * @mob_loc: Pointer to location for mob id to be modified * @location: Pointer to location for guest pointer to be modified -* @vbo: Non ref-counted pointer to buffer object */ struct vmw_relocation {struct list_head head; -SVGAMobId *mob_loc; -SVGAGuestPtr *location;struct vmw_buffer_object *vbo; +union { +SVGAMobId *mob_loc; +SVGAGuestPtr *location; + }; };/**
@@ -1167,7 +1169,6 @@ static int vmw_translate_mob_ptr(struct vmw_private *dev_priv, goto out_no_reloc; reloc->mob_loc = id; - reloc->location =NULL ; reloc->vbo = vmw_bo; ret =vmw_validation_add_bo (sw_context->ctx, vmw_bo, true, false);
Signature · 6 lines
2.14.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 7/18 drm/vmwgfx: Replace unconditional mutex unlocked warnings with lockdep counterpart
In reply to Thomas HellstromReplace instances of WARN_ON[_ONCE](!mutex_is_held()) with lockdep_assert_held(). This makes sure the checking process actually holds the mutex and also removes the checks from release builds
--- drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c | 4 ++-- drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_so.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c +2 -2
@@ -660,7 +660,7 @@ static void __vmw_cmdbuf_cur_flush(struct vmw_cmdbuf_man *man) {struct vmw_cmdbuf_header *cur = man->cur; -WARN_ON (!mutex_is_locked (&man->cur_mutex)); +lockdep_assert_held_once (&man->cur_mutex);if (!cur)return ;
@@ -1045,7 +1045,7 @@ static void vmw_cmdbuf_commit_cur(struct vmw_cmdbuf_man *man, {struct vmw_cmdbuf_header *cur = man->cur; -WARN_ON (!mutex_is_locked (&man->cur_mutex)); +lockdep_assert_held_once (&man->cur_mutex);WARN_ON (size > cur->reserved); man->cur_pos += size;
drivers/gpu/drm/vmwgfx/vmwgfx_shader.c +1 -1
@@ -562,7 +562,7 @@ void vmw_dx_shader_cotable_list_scrub(struct vmw_private *dev_priv, {struct vmw_dx_shader *entry, *next; -WARN_ON_ONCE (!mutex_is_locked (&dev_priv->binding_mutex)); +lockdep_assert_held_once (&dev_priv->binding_mutex);list_for_each_entry_safe (entry, next, list, cotable_head) {WARN_ON (vmw_dx_shader_scrub (&entry->res));
drivers/gpu/drm/vmwgfx/vmwgfx_so.c +3 -3
@@ -208,7 +208,7 @@ static int vmw_view_destroy(struct vmw_resource *res)union vmw_view_destroy body; } *cmd; -WARN_ON_ONCE (!mutex_is_locked (&dev_priv->binding_mutex)); +lockdep_assert_held_once (&dev_priv->binding_mutex);vmw_binding_res_list_scrub (&res->binding_head);if (!view->committed || res->id ==-1 )
@@ -439,7 +439,7 @@ void vmw_view_cotable_list_destroy(struct vmw_private *dev_priv, {struct vmw_view *entry, *next; -WARN_ON_ONCE (!mutex_is_locked (&dev_priv->binding_mutex)); +lockdep_assert_held_once (&dev_priv->binding_mutex);list_for_each_entry_safe (entry, next, list, cotable_head)WARN_ON (vmw_view_destroy (&entry->res));
@@ -459,7 +459,7 @@ void vmw_view_surface_list_destroy(struct vmw_private *dev_priv, {struct vmw_view *entry, *next; -WARN_ON_ONCE (!mutex_is_locked (&dev_priv->binding_mutex)); +lockdep_assert_held_once (&dev_priv->binding_mutex);list_for_each_entry_safe (entry, next, list, srf_head)WARN_ON (vmw_view_destroy (&entry->res));
Signature · 6 lines
2.14.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 8/18 drm/vmwgfx: Remove the resource avail field
In reply to Thomas HellstromThis field was previously used to prevent a lookup of a resource before its constructor had run to its end. This was mainly intended for an interface that is now removed that allowed looking up a resource by its device id.
Currently all affected resources are added to the lookup mechanism (its TTM prime object is initialized) late in the constructor where it's OK to look up the resource.
This means we can change the device resource_lock to an ordinary spinlock instead of an rwlock and remove a locking sequence during lookup.
--- drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 6 +- drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 44 ++++++++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 75 ++++++++----------------- drivers/gpu/drm/vmwgfx/vmwgfx_resource_priv.h | 2 - drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 4 +- drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_so.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 2 +- 10 files changed, 68 insertions(+), 73 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_context.c +2 -4
@@ -217,9 +217,7 @@ static int vmw_gb_context_init(struct vmw_private *dev_priv, } } - - -vmw_resource_activate (res, vmw_hw_context_destroy); + res->hw_destroy = vmw_hw_context_destroy;return 0 ; out_cotables:
@@ -274,7 +272,7 @@ static int vmw_context_init(struct vmw_private *dev_priv,vmw_fifo_commit (dev_priv,sizeof (*cmd));vmw_fifo_resource_inc (dev_priv); -vmw_resource_activate (res, vmw_hw_context_destroy); + res->hw_destroy = vmw_hw_context_destroy;return 0 ; out_early:
drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c +1 -1
@@ -615,7 +615,7 @@ struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv, vcotbl->type = type; vcotbl->ctx = ctx; -vmw_resource_activate (&vcotbl->res, vmw_hw_cotable_destroy); + vcotbl->res.hw_destroy = vmw_hw_cotable_destroy;return &vcotbl->res;
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +1 -1
@@ -667,8 +667,8 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)mutex_init (&dev_priv->binding_mutex);mutex_init (&dev_priv->requested_layout_mutex);mutex_init (&dev_priv->global_kms_state_mutex); -rwlock_init (&dev_priv->resource_lock);ttm_lock_init (&dev_priv->reservation_sem); +spin_lock_init (&dev_priv->resource_lock);spin_lock_init (&dev_priv->hw_lock);spin_lock_init (&dev_priv->waiter_lock);spin_lock_init (&dev_priv->cap_lock);
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +36 -8
64 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +23 -52
190 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_resource_priv.h +0 -2
@@ -120,8 +120,6 @@ int vmw_resource_init(struct vmw_private *dev_priv, struct vmw_resource *res,bool delay_id, void (*res_free) (struct vmw_resource *res), const struct vmw_res_func *func); -void vmw_resource_activate (struct vmw_resource *res, -void (*hw_destroy) (struct vmw_resource *)); int vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data,
drivers/gpu/drm/vmwgfx/vmwgfx_shader.c +2 -2
@@ -186,7 +186,7 @@ static int vmw_gb_shader_init(struct vmw_private *dev_priv, shader->num_input_sig = num_input_sig; shader->num_output_sig = num_output_sig; -vmw_resource_activate (res, vmw_hw_shader_destroy); + res->hw_destroy = vmw_hw_shader_destroy;return 0 ; }
@@ -656,7 +656,7 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man, goto out_resource_init; res->id = shader->id; -vmw_resource_activate (res, vmw_hw_shader_destroy); + res->hw_destroy = vmw_hw_shader_destroy; out_resource_init:vmw_resource_unreference (&res);
drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c +1 -1
@@ -81,7 +81,7 @@ static int vmw_simple_resource_init(struct vmw_private *dev_priv,return ret; } -vmw_resource_activate (&simple->res, simple->func->hw_destroy); + simple->res.hw_destroy = simple->func->hw_destroy;return 0 ; }
drivers/gpu/drm/vmwgfx/vmwgfx_so.c +1 -1
@@ -386,7 +386,7 @@ int vmw_view_add(struct vmw_cmdbuf_res_manager *man, goto out_resource_init; res->id = view->view_id; -vmw_resource_activate (res, vmw_hw_view_destroy); + res->hw_destroy = vmw_hw_view_destroy; out_resource_init:vmw_resource_unreference (&res);
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +1 -1
@@ -614,7 +614,7 @@ static int vmw_surface_init(struct vmw_private *dev_priv,*/ INIT_LIST_HEAD (&srf->view_list); -vmw_resource_activate (res, vmw_hw_surface_destroy); + res->hw_destroy = vmw_hw_surface_destroy;return ret; }
Signature · 6 lines
2.14.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 9/18 drm/vmwgfx: Remove the user resource destructor check
In reply to Thomas HellstromWe were checking that the resource destructor matched that of the intended object type, to make sure the looked up resource was of the right type.
But we already have an object type check in place which makes sure the resource is of the right type.
--- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 3 --- 1 file changed, 3 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +0 -3
@@ -219,9 +219,6 @@ int vmw_user_resource_lookup_handle(struct vmw_private *dev_priv, goto out_bad_resource; res = converter->base_obj_to_res (base); -if (res->res_free != converter->res_free) - goto out_bad_resource; -kref_get (&res->kref); *p_res = res;
Signature · 6 lines
2.14.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 10/18 drm/ttm: Make the object handles idr-generated
In reply to Thomas HellstromInstead of generating user-space object handles based on a, possibly processed, hash of the kernel address of the object, use idr to generate and lookup those handles. This might improve somewhat on security since we loose all connections to the object's kernel address. Also idr is designed to do just this.
As a todo-item, since user-space handles are now generated in sequence, we can probably use a much simpler hash function to hash them.
--- drivers/gpu/drm/ttm/ttm_lock.c | 2 +- drivers/gpu/drm/ttm/ttm_object.c | 42 ++++++++++++------------- drivers/gpu/drm/vmwgfx/vmwgfx_bo.c | 7 +++-- drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 12 +++---- drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 7 +++-- drivers/gpu/drm/vmwgfx/vmwgfx_resource_priv.h | 5 +++ drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 16 +++------- drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c | 5 +-- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 18 +++++------ include/drm/ttm/ttm_object.h | 13 ++++++-- 10 files changed, 65 insertions(+), 62 deletions(-)
drivers/gpu/drm/ttm/ttm_lock.c +1 -1
@@ -267,7 +267,7 @@ EXPORT_SYMBOL(ttm_vt_lock);int ttm_vt_unlock (struct ttm_lock *lock) {return ttm_ref_object_base_unref (lock->vt_holder, - lock->base.hash.key,TTM_REF_USAGE ); + lock->base.handle,TTM_REF_USAGE ); }EXPORT_SYMBOL (ttm_vt_unlock);
drivers/gpu/drm/ttm/ttm_object.c +20 -22
115 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +4 -3
@@ -441,7 +441,8 @@ static size_t vmw_bo_acc_size(struct vmw_private *dev_priv, size_t size, struct_size = backend_size +ttm_round_pot (sizeof (struct vmw_buffer_object )); user_struct_size = backend_size + -ttm_round_pot (sizeof (struct vmw_user_buffer_object )); +ttm_round_pot (sizeof (struct vmw_user_buffer_object )) + +TTM_OBJ_EXTRA_SIZE ; }if (dev_priv->map_mode == vmw_dma_alloc_coherent)
@@ -631,7 +632,7 @@ int vmw_user_bo_alloc(struct vmw_private *dev_priv, *p_base = &user_bo->prime.base;kref_get (&(*p_base)->refcount); } - *handle = user_bo->prime.base.hash.key; + *handle = user_bo->prime.base.handle; out_no_base_object:return ret;
@@ -940,7 +941,7 @@ int vmw_user_bo_reference(struct ttm_object_file *tfile, user_bo = container_of(vbo, struct vmw_user_buffer_object, vbo); - *handle = user_bo->prime.base.hash.key; + *handle = user_bo->prime.base.handle;return ttm_ref_object_add (tfile, &user_bo->prime.base,TTM_REF_USAGE ,NULL , false); }
drivers/gpu/drm/vmwgfx/vmwgfx_context.c +4 -8
@@ -755,14 +755,10 @@ static int vmw_context_define(struct drm_device *dev, void *data,return -EINVAL ; } -/* -* Approximate idr memory usage with 128 bytes. It will be limited -* by maximum number_of contexts anyway. -*/ -if (unlikely (vmw_user_context_size ==0 )) - vmw_user_context_size =ttm_round_pot (sizeof (*ctx)) +128 + - ((dev_priv->has_mob) ?vmw_cmdbuf_res_man_size () :0 ); + vmw_user_context_size =ttm_round_pot (sizeof (*ctx)) + + ((dev_priv->has_mob) ?vmw_cmdbuf_res_man_size () :0 ) + + +VMW_IDA_ACC_SIZE +TTM_OBJ_EXTRA_SIZE ; ret =ttm_read_lock (&dev_priv->reservation_sem, true);if (unlikely (ret !=0 ))
@@ -807,7 +803,7 @@ static int vmw_context_define(struct drm_device *dev, void *data, goto out_err; } - arg->cid = ctx->base.hash.key; + arg->cid = ctx->base.handle; out_err:vmw_resource_unreference (&res); out_unlock:
drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +4 -3
@@ -306,7 +306,8 @@ struct vmw_fence_manager *vmw_fence_manager_init(struct vmw_private *dev_priv)INIT_LIST_HEAD (&fman->cleanup_list);INIT_WORK (&fman->work, &vmw_fence_work_func); fman->fifo_down = true; - fman->user_fence_size =ttm_round_pot (sizeof (struct vmw_user_fence )); + fman->user_fence_size =ttm_round_pot (sizeof (struct vmw_user_fence )) + +TTM_OBJ_EXTRA_SIZE ; fman->fence_size =ttm_round_pot (sizeof (struct vmw_fence_obj )); fman->event_fence_action_size =ttm_round_pot (sizeof (struct vmw_event_fence_action ));
@@ -650,7 +651,7 @@ int vmw_user_fence_create(struct drm_file *file_priv, } *p_fence = &ufence->fence; - *p_handle = ufence->base.hash.key; + *p_handle = ufence->base.handle;return 0 ; out_err:
@@ -1137,7 +1138,7 @@ int vmw_fence_event_ioctl(struct drm_device *dev, void *data, "object.\n"); goto out_no_ref_obj; } - handle = base->hash.key; + handle = base->handle; }ttm_base_object_unref (&base); }
drivers/gpu/drm/vmwgfx/vmwgfx_resource_priv.h +5 -0
@@ -30,6 +30,11 @@#include "vmwgfx_drv.h" +/* +* Extra memory required by the resource id's ida storage, which is allocated +* separately from the base object itself. We estimate an on-average 128 bytes +* per ida. +*/ #define VMW_IDA_ACC_SIZE 128enum vmw_cmdbuf_res_state {
drivers/gpu/drm/vmwgfx/vmwgfx_shader.c +5 -11
@@ -740,13 +740,10 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv, };int ret; -/* -* Approximate idr memory usage with 128 bytes. It will be limited -* by maximum number_of shaders anyway. -*/ if (unlikely (vmw_user_shader_size ==0 )) vmw_user_shader_size = -ttm_round_pot (sizeof (struct vmw_user_shader )) +128 ; +ttm_round_pot (sizeof (struct vmw_user_shader )) + +VMW_IDA_ACC_SIZE +TTM_OBJ_EXTRA_SIZE ; ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), vmw_user_shader_size,
@@ -792,7 +789,7 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv, }if (handle) - *handle = ushader->base.hash.key; + *handle = ushader->base.handle; out_err:vmw_resource_unreference (&res); out:
@@ -814,13 +811,10 @@ static struct vmw_resource *vmw_shader_alloc(struct vmw_private *dev_priv, };int ret; -/* -* Approximate idr memory usage with 128 bytes. It will be limited -* by maximum number_of shaders anyway. -*/ if (unlikely (vmw_shader_size ==0 )) vmw_shader_size = -ttm_round_pot (sizeof (struct vmw_shader )) +128 ; +ttm_round_pot (sizeof (struct vmw_shader )) + +VMW_IDA_ACC_SIZE ; ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), vmw_shader_size,
drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c +3 -2
@@ -159,7 +159,8 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data, alloc_size = offsetof(struct vmw_user_simple_resource , simple) + func->size; - account_size =ttm_round_pot (alloc_size) +VMW_IDA_ACC_SIZE ; + account_size =ttm_round_pot (alloc_size) +VMW_IDA_ACC_SIZE + +TTM_OBJ_EXTRA_SIZE ; ret =ttm_read_lock (&dev_priv->reservation_sem, true);if (ret)
@@ -208,7 +209,7 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data, goto out_err; } - func->set_arg_handle (data, usimple->base.hash.key); + func->set_arg_handle (data, usimple->base.handle); out_err:vmw_resource_unreference (&res); out_ret:
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +9 -9
@@ -731,7 +731,7 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,if (unlikely (vmw_user_surface_size ==0 )) vmw_user_surface_size =ttm_round_pot (sizeof (*user_srf)) + -128 ; +VMW_IDA_ACC_SIZE +TTM_OBJ_EXTRA_SIZE ; num_sizes =0 ;for (i =0 ; i <DRM_VMW_MAX_SURFACE_FACES ; ++i) {
@@ -744,7 +744,7 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data, num_sizes == 0)return -EINVAL ; - size = vmw_user_surface_size +128 + + size = vmw_user_surface_size +ttm_round_pot (num_sizes *sizeof (struct drm_vmw_size )) +ttm_round_pot (num_sizes *sizeof (struct vmw_surface_offset ));
@@ -886,7 +886,7 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data, goto out_unlock; } - rep->sid = user_srf->prime.base.hash.key; + rep->sid = user_srf->prime.base.handle;vmw_resource_unreference (&res);ttm_read_unlock (&dev_priv->reservation_sem);
@@ -1024,7 +1024,7 @@ int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,if (unlikely (ret !=0 )) {DRM_ERROR ("copy_to_user failed %p %u\n" , user_sizes, srf->num_sizes); -ttm_ref_object_base_unref (tfile, base->hash.key,TTM_REF_USAGE ); +ttm_ref_object_base_unref (tfile, base->handle,TTM_REF_USAGE ); ret = -EFAULT ; }
@@ -1609,9 +1609,9 @@ vmw_gb_surface_define_internal(struct drm_device *dev,if (unlikely (vmw_user_surface_size ==0 )) vmw_user_surface_size =ttm_round_pot (sizeof (*user_srf)) + -128 ; +VMW_IDA_ACC_SIZE +TTM_OBJ_EXTRA_SIZE ; - size = vmw_user_surface_size +128 ; + size = vmw_user_surface_size;/* Define a surface based on the parameters. */ ret = vmw_surface_gb_priv_define(dev,
@@ -1683,7 +1683,7 @@ vmw_gb_surface_define_internal(struct drm_device *dev, goto out_unlock; } - rep->handle = user_srf->prime.base.hash.key; + rep->handle = user_srf->prime.base.handle; rep->backup_size = res->backup_size;if (res->backup) { rep->buffer_map_handle =
@@ -1745,7 +1745,7 @@ vmw_gb_surface_reference_internal(struct drm_device *dev,if (unlikely (ret !=0 )) {DRM_ERROR ("Could not add a reference to a GB surface " "backup buffer.\n" ); - (void )ttm_ref_object_base_unref (tfile, base->hash.key, + (void )ttm_ref_object_base_unref (tfile, base->handle,TTM_REF_USAGE ); goto out_bad_resource; }
@@ -1759,7 +1759,7 @@ vmw_gb_surface_reference_internal(struct drm_device *dev, rep->creq.base.array_size = srf->array_size; rep->creq.base.buffer_handle = backup_handle; rep->creq.base.base_size = srf->base_size; - rep->crep.handle = user_srf->prime.base.hash.key; + rep->crep.handle = user_srf->prime.base.handle; rep->crep.backup_size = srf->res.backup_size; rep->crep.buffer_handle = backup_handle; rep->crep.buffer_map_handle =
include/drm/ttm/ttm_object.h +10 -3
@@ -125,14 +125,14 @@ struct ttm_object_device;struct ttm_base_object {struct rcu_head rhead; -struct drm_hash_item hash; -enum ttm_object_type object_type; -bool shareable;struct ttm_object_file *tfile;struct kref refcount;void (*refcount_release) (struct ttm_base_object **base);void (*ref_obj_release) (struct ttm_base_object *base,enum ttm_ref_type ref_type); +u32 handle; +enum ttm_object_type object_type; +u32 shareable; };
@@ -351,4 +351,11 @@ extern int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,#define ttm_prime_object_kfree (__obj, __prime) \ kfree_rcu(__obj, __prime.base.rhead) + +/* +* Extra memory required by the base object's idr storage, which is allocated +* separately from the base object itself. We estimate an on-average 128 bytes +* per idr. +*/ +#define TTM_OBJ_EXTRA_SIZE 128#endif
Signature · 6 lines
2.14.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH -next 10/18] drm/ttm: Make the object handles idr-generated
Am 26.09.2018 um 18:18 schrieb Thomas Hellstrom:
Quoted 6 lines
Instead of generating user-space object handles based on a, possibly processed, hash of the kernel address of the object, use idr to generate and lookup those handles. This might improve somewhat on security since we loose all connections to the object's kernel address. Also idr is designed to do just this.
Quoted 7 lines
As a todo-item, since user-space handles are now generated in sequence, we can probably use a much simpler hash function to hash them.
Cc Christian König <[email protected]>Signed-off-by Thomas Hellstrom <[email protected]>Reviewed-by Sinclair Yeh <[email protected]>Reviewed-by Deepak Rawat <[email protected]>
Well NAK. I already proposed completely removing ttm_lock.c and ttm_object.c because vmwgfx is the only user of it.
Please move that functionality into the driver since it isn't TTM specific after all.
Christian.
Quoted 438 lines
--- drivers/gpu/drm/ttm/ttm_lock.c | 2 +- drivers/gpu/drm/ttm/ttm_object.c | 42 ++++++++++++------------- drivers/gpu/drm/vmwgfx/vmwgfx_bo.c | 7 +++-- drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 12 +++---- drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 7 +++-- drivers/gpu/drm/vmwgfx/vmwgfx_resource_priv.h | 5 +++ drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 16 +++------- drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c | 5 +-- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 18 +++++------ include/drm/ttm/ttm_object.h | 13 ++++++-- 10 files changed, 65 insertions(+), 62 deletions(-)drivers/gpu/drm/ttm/ttm_lock.c +1
-1@@ -267,7 +267,7 @@ EXPORT_SYMBOL(ttm_vt_lock);int ttm_vt_unlock (struct ttm_lock *lock) {return ttm_ref_object_base_unref (lock->vt_holder, - lock->base.hash.key,TTM_REF_USAGE ); + lock->base.handle,TTM_REF_USAGE ); }EXPORT_SYMBOL (ttm_vt_unlock);drivers/gpu/drm/ttm/ttm_object.c +20
-22@@ -95,6 +95,7 @@ struct ttm_object_device {struct dma_buf_ops ops;void (*dmabuf_release)(struct dma_buf *dma_buf);size_t dma_buf_size; +struct idr idr; };/** @@ -172,14 +173,15 @@ int ttm_base_object_init(struct ttm_object_file *tfile, base->ref_obj_release = ref_obj_release; base->object_type = object_type;kref_init (&base->refcount); +idr_preload (GFP_KERNEL );spin_lock (&tdev->object_lock); - ret =drm_ht_just_insert_please_rcu (&tdev->object_hash, - &base->hash, - (unsigned long )base,31 ,0 ,0 ); + ret =idr_alloc (&tdev->idr, base,0 ,0 ,GFP_NOWAIT );spin_unlock (&tdev->object_lock); -if (unlikely (ret !=0 )) - goto out_err0; +idr_preload_end (); +if (ret <0 ) +return ret; + base->handle = ret; ret =ttm_ref_object_add (tfile, base,TTM_REF_USAGE ,NULL , false);if (unlikely (ret !=0 )) goto out_err1;@@ -189,9 +191,8 @@ int ttm_base_object_init(struct ttm_object_file *tfile,return 0 ; out_err1:spin_lock (&tdev->object_lock); - (void )drm_ht_remove_item_rcu (&tdev->object_hash, &base->hash); +idr_remove (&tdev->idr, base->handle);spin_unlock (&tdev->object_lock); -out_err0:return ret; }EXPORT_SYMBOL (ttm_base_object_init);@@ -203,7 +204,7 @@ static void ttm_release_base(struct kref *kref)struct ttm_object_device *tdev = base->tfile->tdev;spin_lock (&tdev->object_lock); - (void )drm_ht_remove_item_rcu (&tdev->object_hash, &base->hash); +idr_remove (&tdev->idr, base->handle);spin_unlock (&tdev->object_lock);/* @@ -252,19 +253,13 @@ EXPORT_SYMBOL(ttm_base_object_lookup);struct ttm_base_object *ttm_base_object_lookup_for_ref (struct ttm_object_device *tdev,uint32_t key) { -struct ttm_base_object *base =NULL ; -struct drm_hash_item *hash; -struct drm_open_hash *ht = &tdev->object_hash; -int ret; +struct ttm_base_object *base;rcu_read_lock (); - ret =drm_ht_find_item_rcu (ht, key, &hash); + base =idr_find (&tdev->idr, key); -if (likely (ret ==0 )) { - base = drm_hash_entry(hash, struct ttm_base_object, hash); -if (!kref_get_unless_zero (&base->refcount)) - base =NULL ; - } +if (base && !kref_get_unless_zero (&base->refcount)) + base =NULL ;rcu_read_unlock ();return base;@@ -289,7 +284,7 @@ bool ttm_ref_object_exists(struct ttm_object_file *tfile,struct ttm_ref_object *ref;rcu_read_lock (); -if (unlikely (drm_ht_find_item_rcu (ht, base->hash.key, &hash) !=0 )) +if (unlikely (drm_ht_find_item_rcu (ht, base->handle, &hash) !=0 )) goto out_false;/* @@ -340,7 +335,7 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,while (ret == -EINVAL ) {rcu_read_lock (); - ret =drm_ht_find_item_rcu (ht, base->hash.key, &hash); + ret =drm_ht_find_item_rcu (ht, base->handle, &hash);if (ret ==0 ) { ref = drm_hash_entry(hash, struct ttm_ref_object, hash);@@ -364,7 +359,7 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,return -ENOMEM ; } - ref->hash.key = base->hash.key; + ref->hash.key = base->handle; ref->obj = base; ref->tfile = tfile; ref->ref_type = ref_type;@@ -519,6 +514,7 @@ ttm_object_device_init(struct ttm_mem_global *mem_glob,if (ret !=0 ) goto out_no_object_hash; +idr_init (&tdev->idr); tdev->ops = *ops; tdev->dmabuf_release = tdev->ops.release; tdev->ops.release = ttm_prime_dmabuf_release;@@ -538,6 +534,8 @@ void ttm_object_device_release(struct ttm_object_device **p_tdev) *p_tdev =NULL ; +WARN_ON_ONCE (!idr_is_empty (&tdev->idr)); +idr_destroy (&tdev->idr);drm_ht_remove (&tdev->object_hash);kfree (tdev);@@ -641,7 +639,7 @@ int ttm_prime_fd_to_handle(struct ttm_object_file *tfile, prime = (struct ttm_prime_object *) dma_buf->priv; base = &prime->base; - *handle = base->hash.key; + *handle = base->handle; ret =ttm_ref_object_add (tfile, base,TTM_REF_USAGE ,NULL , false);dma_buf_put (dma_buf);drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +4
-3@@ -441,7 +441,8 @@ static size_t vmw_bo_acc_size(struct vmw_private *dev_priv, size_t size, struct_size = backend_size +ttm_round_pot (sizeof (struct vmw_buffer_object )); user_struct_size = backend_size + -ttm_round_pot (sizeof (struct vmw_user_buffer_object )); +ttm_round_pot (sizeof (struct vmw_user_buffer_object )) + +TTM_OBJ_EXTRA_SIZE ; }if (dev_priv->map_mode == vmw_dma_alloc_coherent)@@ -631,7 +632,7 @@ int vmw_user_bo_alloc(struct vmw_private *dev_priv, *p_base = &user_bo->prime.base;kref_get (&(*p_base)->refcount); } - *handle = user_bo->prime.base.hash.key; + *handle = user_bo->prime.base.handle; out_no_base_object:return ret;@@ -940,7 +941,7 @@ int vmw_user_bo_reference(struct ttm_object_file *tfile, user_bo = container_of(vbo, struct vmw_user_buffer_object, vbo); - *handle = user_bo->prime.base.hash.key; + *handle = user_bo->prime.base.handle;return ttm_ref_object_add (tfile, &user_bo->prime.base,TTM_REF_USAGE ,NULL , false); }drivers/gpu/drm/vmwgfx/vmwgfx_context.c +4
-8@@ -755,14 +755,10 @@ static int vmw_context_define(struct drm_device *dev, void *data,return -EINVAL ; } -/* -* Approximate idr memory usage with 128 bytes. It will be limited -* by maximum number_of contexts anyway. -*/ -if (unlikely (vmw_user_context_size ==0 )) - vmw_user_context_size =ttm_round_pot (sizeof (*ctx)) +128 + - ((dev_priv->has_mob) ?vmw_cmdbuf_res_man_size () :0 ); + vmw_user_context_size =ttm_round_pot (sizeof (*ctx)) + + ((dev_priv->has_mob) ?vmw_cmdbuf_res_man_size () :0 ) + + +VMW_IDA_ACC_SIZE +TTM_OBJ_EXTRA_SIZE ; ret =ttm_read_lock (&dev_priv->reservation_sem, true);if (unlikely (ret !=0 ))@@ -807,7 +803,7 @@ static int vmw_context_define(struct drm_device *dev, void *data, goto out_err; } - arg->cid = ctx->base.hash.key; + arg->cid = ctx->base.handle; out_err:vmw_resource_unreference (&res); out_unlock:drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +4
-3@@ -306,7 +306,8 @@ struct vmw_fence_manager *vmw_fence_manager_init(struct vmw_private *dev_priv)INIT_LIST_HEAD (&fman->cleanup_list);INIT_WORK (&fman->work, &vmw_fence_work_func); fman->fifo_down = true; - fman->user_fence_size =ttm_round_pot (sizeof (struct vmw_user_fence )); + fman->user_fence_size =ttm_round_pot (sizeof (struct vmw_user_fence )) + +TTM_OBJ_EXTRA_SIZE ; fman->fence_size =ttm_round_pot (sizeof (struct vmw_fence_obj )); fman->event_fence_action_size =ttm_round_pot (sizeof (struct vmw_event_fence_action ));@@ -650,7 +651,7 @@ int vmw_user_fence_create(struct drm_file *file_priv, } *p_fence = &ufence->fence; - *p_handle = ufence->base.hash.key; + *p_handle = ufence->base.handle;return 0 ; out_err:@@ -1137,7 +1138,7 @@ int vmw_fence_event_ioctl(struct drm_device *dev, void *data, "object.\n"); goto out_no_ref_obj; } - handle = base->hash.key; + handle = base->handle; }ttm_base_object_unref (&base); }drivers/gpu/drm/vmwgfx/vmwgfx_resource_priv.h +5
-0@@ -30,6 +30,11 @@#include "vmwgfx_drv.h" +/* +* Extra memory required by the resource id's ida storage, which is allocated +* separately from the base object itself. We estimate an on-average 128 bytes +* per ida. +*/ #define VMW_IDA_ACC_SIZE 128enum vmw_cmdbuf_res_state {drivers/gpu/drm/vmwgfx/vmwgfx_shader.c +5
-11@@ -740,13 +740,10 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv, };int ret; -/* -* Approximate idr memory usage with 128 bytes. It will be limited -* by maximum number_of shaders anyway. -*/ if (unlikely (vmw_user_shader_size ==0 )) vmw_user_shader_size = -ttm_round_pot (sizeof (struct vmw_user_shader )) +128 ; +ttm_round_pot (sizeof (struct vmw_user_shader )) + +VMW_IDA_ACC_SIZE +TTM_OBJ_EXTRA_SIZE ; ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), vmw_user_shader_size,@@ -792,7 +789,7 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv, }if (handle) - *handle = ushader->base.hash.key; + *handle = ushader->base.handle; out_err:vmw_resource_unreference (&res); out:@@ -814,13 +811,10 @@ static struct vmw_resource *vmw_shader_alloc(struct vmw_private *dev_priv, };int ret; -/* -* Approximate idr memory usage with 128 bytes. It will be limited -* by maximum number_of shaders anyway. -*/ if (unlikely (vmw_shader_size ==0 )) vmw_shader_size = -ttm_round_pot (sizeof (struct vmw_shader )) +128 ; +ttm_round_pot (sizeof (struct vmw_shader )) + +VMW_IDA_ACC_SIZE ; ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), vmw_shader_size,drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c +3
-2@@ -159,7 +159,8 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data, alloc_size = offsetof(struct vmw_user_simple_resource , simple) + func->size; - account_size =ttm_round_pot (alloc_size) +VMW_IDA_ACC_SIZE ; + account_size =ttm_round_pot (alloc_size) +VMW_IDA_ACC_SIZE + +TTM_OBJ_EXTRA_SIZE ; ret =ttm_read_lock (&dev_priv->reservation_sem, true);if (ret)@@ -208,7 +209,7 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data, goto out_err; } - func->set_arg_handle (data, usimple->base.hash.key); + func->set_arg_handle (data, usimple->base.handle); out_err:vmw_resource_unreference (&res); out_ret:drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +9
-9@@ -731,7 +731,7 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,if (unlikely (vmw_user_surface_size ==0 )) vmw_user_surface_size =ttm_round_pot (sizeof (*user_srf)) + -128 ; +VMW_IDA_ACC_SIZE +TTM_OBJ_EXTRA_SIZE ; num_sizes =0 ;for (i =0 ; i <DRM_VMW_MAX_SURFACE_FACES ; ++i) {@@ -744,7 +744,7 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data, num_sizes == 0)return -EINVAL ; - size = vmw_user_surface_size +128 + + size = vmw_user_surface_size +ttm_round_pot (num_sizes *sizeof (struct drm_vmw_size )) +ttm_round_pot (num_sizes *sizeof (struct vmw_surface_offset ));@@ -886,7 +886,7 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data, goto out_unlock; } - rep->sid = user_srf->prime.base.hash.key; + rep->sid = user_srf->prime.base.handle;vmw_resource_unreference (&res);ttm_read_unlock (&dev_priv->reservation_sem);@@ -1024,7 +1024,7 @@ int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,if (unlikely (ret !=0 )) {DRM_ERROR ("copy_to_user failed %p %u\n" , user_sizes, srf->num_sizes); -ttm_ref_object_base_unref (tfile, base->hash.key,TTM_REF_USAGE ); +ttm_ref_object_base_unref (tfile, base->handle,TTM_REF_USAGE ); ret = -EFAULT ; }@@ -1609,9 +1609,9 @@ vmw_gb_surface_define_internal(struct drm_device *dev,if (unlikely (vmw_user_surface_size ==0 )) vmw_user_surface_size =ttm_round_pot (sizeof (*user_srf)) + -128 ; +VMW_IDA_ACC_SIZE +TTM_OBJ_EXTRA_SIZE ; - size = vmw_user_surface_size +128 ; + size = vmw_user_surface_size;/* Define a surface based on the parameters. */ ret = vmw_surface_gb_priv_define(dev,@@ -1683,7 +1683,7 @@ vmw_gb_surface_define_internal(struct drm_device *dev, goto out_unlock; } - rep->handle = user_srf->prime.base.hash.key; + rep->handle = user_srf->prime.base.handle; rep->backup_size = res->backup_size;if (res->backup) { rep->buffer_map_handle =@@ -1745,7 +1745,7 @@ vmw_gb_surface_reference_internal(struct drm_device *dev,if (unlikely (ret !=0 )) {DRM_ERROR ("Could not add a reference to a GB surface " "backup buffer.\n" ); - (void )ttm_ref_object_base_unref (tfile, base->hash.key, + (void )ttm_ref_object_base_unref (tfile, base->handle,TTM_REF_USAGE ); goto out_bad_resource; }@@ -1759,7 +1759,7 @@ vmw_gb_surface_reference_internal(struct drm_device *dev, rep->creq.base.array_size = srf->array_size; rep->creq.base.buffer_handle = backup_handle; rep->creq.base.base_size = srf->base_size; - rep->crep.handle = user_srf->prime.base.hash.key; + rep->crep.handle = user_srf->prime.base.handle; rep->crep.backup_size = srf->res.backup_size; rep->crep.buffer_handle = backup_handle; rep->crep.buffer_map_handle =include/drm/ttm/ttm_object.h +3
-3@@ -125,14 +125,14 @@ struct ttm_object_device;struct ttm_base_object {struct rcu_head rhead; -struct drm_hash_item hash; -enum ttm_object_type object_type; -bool shareable;struct ttm_object_file *tfile;struct kref refcount;void (*refcount_release) (struct ttm_base_object **base);void (*ref_obj_release) (struct ttm_base_object *base,enum ttm_ref_type ref_type); +u32 handle; +enum ttm_object_type object_type; +u32 shareable; };@@ -351,4 +351,11 @@ extern int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,
include/drm/ttm/ttm_object.h extern int ttm_prime_handle_to_fd(struct ttm_object_file *tfile, · line 361
Quoted 10 lines
include/drm/ttm/ttm_object.h +7
-0#define ttm_prime_object_kfree (__obj, __prime) \ kfree_rcu(__obj, __prime.base.rhead) + +/* +* Extra memory required by the base object's idr storage, which is allocated +* separately from the base object itself. We estimate an on-average 128 bytes +* per idr. +*/ +#define TTM_OBJ_EXTRA_SIZE 128#endif
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH -next 10/18] drm/ttm: Make the object handles idr-generated
Quoted 15 lines · Christian König
Am 26.09.2018 um 18:18 schrieb Thomas Hellstrom:
Quoted 6 lines
Instead of generating user-space object handles based on a, possibly processed, hash of the kernel address of the object, use idr to generate and lookup those handles. This might improve somewhat on security since we loose all connections to the object's kernel address. Also idr is designed to do just this.
Quoted 7 lines
As a todo-item, since user-space handles are now generated in sequence, we can probably use a much simpler hash function to hash them.
Cc Christian König <[email protected]>Signed-off-by Thomas Hellstrom <[email protected]>Reviewed-by Sinclair Yeh <[email protected]>Reviewed-by Deepak Rawat <[email protected]>
Quoted 5 lines
Well NAK. I already proposed completely removing
ttm_lock.candttm_object.cbecause vmwgfx is the only user of it.Please move that functionality into the driver since it isn't TTM specific after all.
Christian.
Actually, I thought that was already done in -next, but it wasn't. I vaguely recall seeing some patches doing that, but I might remember incorrectly or they were never pushed.
I'll move those files over.
/Thomas
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH -next 10/18] drm/ttm: Make the object handles idr-generated
Am 26.09.2018 um 18:46 schrieb Thomas Hellstrom:
Quoted 16 lines · Christian König
Quoted 15 lines
Am 26.09.2018 um 18:18 schrieb Thomas Hellstrom:
Quoted 13 lines
Instead of generating user-space object handles based on a, possibly processed, hash of the kernel address of the object, use idr to generate and lookup those handles. This might improve somewhat on security since we loose all connections to the object's kernel address. Also idr is designed to do just this.
As a todo-item, since user-space handles are now generated in sequence, we can probably use a much simpler hash function to hash them.
Cc Christian König <[email protected]>Signed-off-by Thomas Hellstrom <[email protected]>Reviewed-by Sinclair Yeh <[email protected]>Reviewed-by Deepak Rawat <[email protected]>
Quoted 6 lines
Quoted 5 lines
Well NAK. I already proposed completely removing
ttm_lock.candttm_object.cbecause vmwgfx is the only user of it.Please move that functionality into the driver since it isn't TTM specific after all.
Christian.
Actually, I thought that was already done in -next, but it wasn't. I vaguely recall seeing some patches doing that, but I might remember incorrectly or they were never pushed.
I asked for your opinion, but never got a response :)
Quoted 1 line
I'll move those files over.
Great thanks,
Christian.
Quoted 3 lines
/Thomas
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 11/18 drm/ttm: Look up objects without taking a reference
In reply to Thomas HellstromTypically when we look up objects under the rcu lock, we take a reference to make sure the returned object pointer is valid.
Now provide a function to look up an object and instead of taking a reference to it, keep the rcu lock held when returning the object pointer. This means that the object pointer is valid as long as the rcu lock is held, but the object may be doomed (its refcount may be zero). Any persistent usage of the object pointer outside of the rcu lock requires a reference to be taken using kref_get_unless_zero().
--- drivers/gpu/drm/ttm/ttm_object.c | 35 +++++++++++++++++++++++++++++++++++ include/drm/ttm/ttm_object.h | 15 +++++++++++++++ 2 files changed, 50 insertions(+)
drivers/gpu/drm/ttm/ttm_object.c +35 -0
@@ -228,6 +228,41 @@ void ttm_base_object_unref(struct ttm_base_object **p_base) }EXPORT_SYMBOL (ttm_base_object_unref); +/** +* ttm_base_object_noref_lookup - look up a base object without reference +* @tfile: The struct ttm_object_file the object is registered with. +* @key: The object handle. +* +* This function looks up a ttm base object and returns a pointer to it +* without refcounting the pointer. The returned pointer is only valid +* until ttm_base_object_noref_release() is called, and the object +* pointed to by the returned pointer may be doomed. Any persistent usage +* of the object requires a refcount to be taken using kref_get_unless_zero(). +* Iff this function returns successfully it needs to be paired with +* ttm_base_object_noref_release() and no sleeping- or scheduling functions +* may be called inbetween these function callse. +* +* Return: A pointer to the object if successful or NULL otherwise. +*/ +struct ttm_base_object * +ttm_base_object_noref_lookup (struct ttm_object_file *tfile,uint32_t key) +{ +struct drm_hash_item *hash; +struct drm_open_hash *ht = &tfile->ref_hash[TTM_REF_USAGE ]; +int ret; + +rcu_read_lock (); + ret =drm_ht_find_item_rcu (ht, key, &hash); +if (ret) { +rcu_read_unlock (); +return NULL ; + } + +__release (RCU ); + return drm_hash_entry(hash, struct ttm_ref_object, hash)->obj; +} +EXPORT_SYMBOL (ttm_base_object_noref_lookup); +struct ttm_base_object *ttm_base_object_lookup (struct ttm_object_file *tfile,uint32_t key) {
include/drm/ttm/ttm_object.h +15 -0
@@ -358,4 +358,19 @@ extern int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,* per idr. */ #define TTM_OBJ_EXTRA_SIZE 128 + +struct ttm_base_object * +ttm_base_object_noref_lookup (struct ttm_object_file *tfile,uint32_t key); + +/** +* ttm_base_object_noref_release - release a base object pointer looked up +* without reference +* +* Releases a base object pointer looked up with ttm_base_object_noref_lookup(). +*/ +static inline void ttm_base_object_noref_release (void ) +{ +__acquire (RCU ); +rcu_read_unlock (); +}#endif
Signature · 6 lines
2.14.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 12/18 drm/ttm: Export ttm_bo_reference_unless_doomed()
In reply to Thomas HellstromExport ttm_bo_reference_unless_doomed() to be used when looking up buffer objects that are removed from the lookup structure in the destructor.
--- drivers/gpu/drm/ttm/ttm_bo_vm.c | 3 +-- include/drm/ttm/ttm_bo_api.h | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_bo_vm.c +1 -2
@@ -409,8 +409,7 @@ static struct ttm_buffer_object *ttm_bo_vm_lookup(struct ttm_bo_device *bdev, node =drm_vma_offset_lookup_locked (&bdev->vma_manager, offset, pages);if (likely (node)) { bo = container_of(node, struct ttm_buffer_object, vma_node); -if (!kref_get_unless_zero (&bo->kref)) - bo =NULL ; + bo =ttm_bo_reference_unless_doomed (bo); }drm_vma_offset_unlock_lookup (&bdev->vma_manager);
include/drm/ttm/ttm_bo_api.h +18 -0
@@ -312,6 +312,24 @@ ttm_bo_reference(struct ttm_buffer_object *bo)return bo; } +/** +* ttm_bo_reference_unless_doomed - reference a struct ttm_buffer_object unless +* its refcount has already reached zero. +* @bo: The buffer object. +* +* Used to reference a TTM buffer object in lookups where the object is removed +* from the lookup structure during the destructor and for RCU lookups. +* +* Returns: @bo if the referencing was successful, NULL otherwise. +*/ +static inline __must_check struct ttm_buffer_object * +ttm_bo_reference_unless_doomed (struct ttm_buffer_object *bo) +{ +if (!kref_get_unless_zero (&bo->kref)) +return NULL ; +return bo; +} +/** * ttm_bo_wait - wait for buffer idle. *
Signature · 6 lines
2.14.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH -next 12/18] drm/ttm: Export ttm_bo_reference_unless_doomed()
Am 26.09.2018 um 18:18 schrieb Thomas Hellstrom:
Quoted 35 lines
Export
ttm_bo_reference_unless_doomed()to be used when looking up buffer objects that are removed from the lookup structure in the destructor.Cc Christian König <[email protected]>Signed-off-by Thomas Hellstrom <[email protected]>Reviewed-by Sinclair Yeh <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo_vm.c | 3 +-- include/drm/ttm/ttm_bo_api.h | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-)drivers/gpu/drm/ttm/ttm_bo_vm.c +1
-2@@ -409,8 +409,7 @@ static struct ttm_buffer_object *ttm_bo_vm_lookup(struct ttm_bo_device *bdev, node =drm_vma_offset_lookup_locked (&bdev->vma_manager, offset, pages);if (likely (node)) { bo = container_of(node, struct ttm_buffer_object, vma_node); -if (!kref_get_unless_zero (&bo->kref)) - bo =NULL ; + bo =ttm_bo_reference_unless_doomed (bo); }drm_vma_offset_unlock_lookup (&bdev->vma_manager);include/drm/ttm/ttm_bo_api.h +2
-0@@ -312,6 +312,24 @@ ttm_bo_reference(struct ttm_buffer_object *bo)return bo; } +/** +* ttm_bo_reference_unless_doomed - reference a struct ttm_buffer_object unless
include/drm/ttm/ttm_bo_api.h ttm_bo_reference(struct ttm_buffer_object *bo) · line 326
Quoted 10 lines
include/drm/ttm/ttm_bo_api.h +10
-0+* its refcount has already reached zero. +* @bo: The buffer object. +* +* Used to reference a TTM buffer object in lookups where the object is removed +* from the lookup structure during the destructor and for RCU lookups. +* +* Returns: @bo if the referencing was successful, NULL otherwise. +*/ +static inline __must_check struct ttm_buffer_object * +ttm_bo_reference_unless_doomed (struct ttm_buffer_object *bo)
Please name that ttm_bo_get_rcu(), we are in the process of renaming ttm_bo_reference into ttm_bo_get as well.
Christian.
include/drm/ttm/ttm_bo_api.h ttm_bo_reference(struct ttm_buffer_object *bo) · line 335
Quoted 9 lines
include/drm/ttm/ttm_bo_api.h +6
-0+{ +if (!kref_get_unless_zero (&bo->kref)) +return NULL ; +return bo; +} +/** * ttm_bo_wait - wait for buffer idle. *
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH -next 12/18] drm/ttm: Export ttm_bo_reference_unless_doomed()
Quoted 41 lines · Christian König
Am 26.09.2018 um 18:18 schrieb Thomas Hellstrom:
Quoted 40 lines
Export
ttm_bo_reference_unless_doomed()to be used when looking up buffer objects that are removed from the lookup structure in the destructor.Cc Christian König <[email protected]>Signed-off-by Thomas Hellstrom <[email protected]>Reviewed-by Sinclair Yeh <[email protected]>---
drivers/gpu/drm/ttm/ttm_bo_vm.c| 3 +-- include/drm/ttm/ttm_bo_api.h | 18 ++++++++++++++++++2 files changed, 19 insertions(+), 2 deletions(-)drivers/gpu/drm/ttm/ttm_bo_vm.c +1
-2@@ -409,8 +409,7 @@ static struct ttm_buffer_object *ttm_bo_vm_lookup(struct ttm_bo_device *bdev, node = drm_vma_offset_lookup_locked(&bdev->vma_manager, offset, pages); if (likely(node)) { bo = container_of(node, struct ttm_buffer_object, vma_node); - if (!kref_get_unless_zero(&bo->kref)) - bo = NULL; + bo = ttm_bo_reference_unless_doomed(bo); } drm_vma_offset_unlock_lookup(&bdev->vma_manager);include/drm/ttm/ttm_bo_api.h +0
-0@@ -312,6 +312,24 @@ ttm_bo_reference(struct ttm_buffer_object *bo) return bo; }+/**
+ *ttm_bo_reference_unless_doomed- reference a structttm_buffer_objectunless
+ * its refcount has already reached zero.
+ * @bo: The buffer object.
+ *
+ * Used to reference a TTM buffer object in lookups where the object is removed
Quoted 8 lines
include/drm/ttm/ttm_bo_api.h ttm_bo_reference(struct ttm_buffer_object *bo) · line 326
Quoted 6 lines
+ * from the lookup structure during the destructor and for RCU lookups.
+ *
+ * Returns: @bo if the referencing was successful, NULL otherwise.
+ */include/drm/ttm/ttm_bo_api.h +2
-0+static inline __must_check struct ttm_buffer_object * +ttm_bo_reference_unless_doomed (struct ttm_buffer_object *bo)Please name that
ttm_bo_get_rcu(), we are in the process of renamingttm_bo_referenceintottm_bo_getas well.
Could we call it ttm_bo_get_unless_doomed() or ttm_bo_get_unless_zero() to be even more consistent. (It's not restricted to rcu as the VM usage shows). Also "doomed" is more relevant for objects, "zero" is more relevant for the refcount itself?
/Thomas
Quoted 13 lines
Christian.
Quoted 9 lines
include/drm/ttm/ttm_bo_api.h +6
-0+{ + if (!kref_get_unless_zero(&bo->kref)) + return NULL; + return bo; +} +/**
*ttm_bo_wait- wait for buffer idle.
*
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH -next 12/18] drm/ttm: Export ttm_bo_reference_unless_doomed()
Am 26.09.2018 um 18:43 schrieb Thomas Hellstrom:
Quoted 52 lines · Christian König
Quoted 42 lines
Am 26.09.2018 um 18:18 schrieb Thomas Hellstrom:
Quoted 41 lines
Export
ttm_bo_reference_unless_doomed()to be used when looking up buffer objects that are removed from the lookup structure in the destructor.Cc Christian König <[email protected]>Signed-off-by Thomas Hellstrom <[email protected]>Reviewed-by Sinclair Yeh <[email protected]>---
drivers/gpu/drm/ttm/ttm_bo_vm.c| 3 +-- include/drm/ttm/ttm_bo_api.h | 18 ++++++++++++++++++2 files changed, 19 insertions(+), 2 deletions(-)drivers/gpu/drm/ttm/ttm_bo_vm.c +1
-2@@ -409,8 +409,7 @@ static struct ttm_buffer_object *ttm_bo_vm_lookup(struct ttm_bo_device *bdev, node = drm_vma_offset_lookup_locked(&bdev->vma_manager, offset, pages); if (likely(node)) { bo = container_of(node, struct ttm_buffer_object, vma_node); - if (!kref_get_unless_zero(&bo->kref)) - bo = NULL; + bo = ttm_bo_reference_unless_doomed(bo); } drm_vma_offset_unlock_lookup(&bdev->vma_manager);include/drm/ttm/ttm_bo_api.h +0
-0@@ -312,6 +312,24 @@ ttm_bo_reference(struct ttm_buffer_object *bo) return bo; }+/**
+ *ttm_bo_reference_unless_doomed- reference a structttm_buffer_objectunless
+ * its refcount has already reached zero.
+ * @bo: The buffer object.
+ *
+ * Used to reference a TTM buffer object in lookups where the object is removed
+ * from the lookup structure during the destructor and for RCUQuoted 8 lines
include/drm/ttm/ttm_bo_api.h ttm_bo_reference(struct ttm_buffer_object *bo) · line 326
Quoted 6 lines
lookups.
+ *
+ * Returns: @bo if the referencing was successful, NULL otherwise.
+ */include/drm/ttm/ttm_bo_api.h +2
-0+static inline __must_check struct ttm_buffer_object * +ttm_bo_reference_unless_doomed (struct ttm_buffer_object *bo)Please name that
ttm_bo_get_rcu(), we are in the process of renamingttm_bo_referenceintottm_bo_getas well.
Quoted 1 line
Could we call it
ttm_bo_get_unless_doomed()orttm_bo_get_unless_zero()to be even more consistent. (It's not restricted to rcu as the VM usage shows). Also "doomed" is more relevant for objects, "zero" is more relevant for the refcount itself?
ttm_bo_get_unless_zero() is fine with me as well.
Christian.
Quoted 19 lines
/Thomas
Quoted 13 lines
Christian.
Quoted 9 lines
include/drm/ttm/ttm_bo_api.h +6
-0+{ + if (!kref_get_unless_zero(&bo->kref)) + return NULL; + return bo; +} +/**
*ttm_bo_wait- wait for buffer idle.
*
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 13/18 drm/vmwgfx: Adapt validation code for reference-free lookups
In reply to Thomas HellstromAdapt the validation code so that vmw_validation_add[res|bo] can be called under an rcu read lock (non-sleeping) and with rcu-only protected resource- or buffer object pointers.
--- drivers/gpu/drm/vmwgfx/vmwgfx_validation.c | 61 ++++++++++++++++++++++++++++-- drivers/gpu/drm/vmwgfx/vmwgfx_validation.h | 19 +++++++++- 2 files changed, 74 insertions(+), 6 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_validation.c +57 -4
@@ -94,11 +94,12 @@ struct vmw_validation_res_node {* * Return: Pointer to the allocated memory on success. NULL on failure. */ -void *vmw_validation_mem_alloc (struct vmw_validation_context *ctx,size_t size) +void *vmw_validation_mem_alloc (struct vmw_validation_context *ctx, +unsigned int size) {void *addr; - size =ALIGN (size,sizeof (long )); + size =vmw_validation_align (size);if (size >PAGE_SIZE )return NULL ;
@@ -262,7 +263,9 @@ int vmw_validation_add_bo(struct vmw_validation_context *ctx, } } val_buf = &bo_node->base; - val_buf->bo =ttm_bo_reference (&vbo->base); + val_buf->bo =ttm_bo_reference_unless_doomed (&vbo->base); +if (!val_buf->bo) +return -ESRCH ; val_buf->shared = false;list_add_tail (&val_buf->head, &ctx->bo_list); bo_node->as_mob = as_mob;
@@ -313,7 +316,10 @@ int vmw_validation_add_resource(struct vmw_validation_context *ctx,return ret; } } - node->res =vmw_resource_reference (res); + node->res =vmw_resource_reference_unless_doomed (res); +if (!node->res) +return -ESRCH ; + node->first_usage =1 ;if (!res->dev_priv->has_mob) {list_add_tail (&node->head, &ctx->resource_list);
@@ -715,3 +721,50 @@ void vmw_validation_done(struct vmw_validation_context *ctx,mutex_unlock (ctx->res_mutex);vmw_validation_unref_lists (ctx); } + +/** +* vmw_validation_preload_bo - Preload the validation memory allocator for a +* call to vmw_validation_add_bo(). +* @ctx: Pointer to the validation context. +* +* Iff this function returns successfully, the next call to +* vmw_validation_add_bo() is guaranteed not to sleep. An error is not fatal +* but voids the guarantee. +* +* Returns: Zero if successful, %-EINVAL otherwise. +*/ +int vmw_validation_preload_bo (struct vmw_validation_context *ctx) +{ +unsigned int size =sizeof (struct vmw_validation_bo_node ); + +if (!vmw_validation_mem_alloc (ctx, size)) +return -ENOMEM ; + + ctx->mem_size_left += size; +return 0 ; +} + +/** +* vmw_validation_preload_res - Preload the validation memory allocator for a +* call to vmw_validation_add_res(). +* @ctx: Pointer to the validation context. +* @size: Size of the validation node extra data. See below. +* +* Iff this function returns successfully, the next call to +* vmw_validation_add_res() with the same or smaller @size is guaranteed not to +* sleep. An error is not fatal but voids the guarantee. +* +* Returns: Zero if successful, %-EINVAL otherwise. +*/ +int vmw_validation_preload_res (struct vmw_validation_context *ctx, +unsigned int size) +{ + size =vmw_validation_align (sizeof (struct vmw_validation_res_node ) + + size) + +vmw_validation_align (sizeof (struct vmw_validation_bo_node )); +if (!vmw_validation_mem_alloc (ctx, size)) +return -ENOMEM ; + + ctx->mem_size_left += size; +return 0 ; +}
drivers/gpu/drm/vmwgfx/vmwgfx_validation.h +17 -2
@@ -177,6 +177,18 @@ vmw_validation_context_init(struct vmw_validation_context *ctx)INIT_LIST_HEAD (&ctx->bo_list); } +/** +* vmw_validation_align - Align a validation memory allocation +* @val: The size to be aligned +* +* Returns: @val aligned to the granularity used by the validation memory +* allocator. +*/ +static inline unsigned int vmw_validation_align (unsigned int val) +{ +return ALIGN (val,sizeof (long )); +} +int vmw_validation_add_bo (struct vmw_validation_context *ctx,struct vmw_buffer_object *vbo,bool as_mob,bool cpu_blit);
@@ -207,6 +219,9 @@ void vmw_validation_revert(struct vmw_validation_context *ctx);void vmw_validation_done (struct vmw_validation_context *ctx,struct vmw_fence_obj *fence); -void *vmw_validation_mem_alloc (struct vmw_validation_context *ctx,size_t size); - +void *vmw_validation_mem_alloc (struct vmw_validation_context *ctx, +unsigned int size); +int vmw_validation_preload_bo (struct vmw_validation_context *ctx); +int vmw_validation_preload_res (struct vmw_validation_context *ctx, +unsigned int size);#endif
Signature · 6 lines
2.14.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 14/18 drm/vmwgfx: Look up user buffer objects without taking a reference
In reply to Thomas HellstromIdentically to how we look up ttm base objects witout reference, provide the same functionality to vmw user buffer objects which derive from them.
--- drivers/gpu/drm/vmwgfx/vmwgfx_bo.c | 41 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 12 +++++++++++ 2 files changed, 53 insertions(+)
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +41 -0
@@ -921,6 +921,47 @@ int vmw_user_bo_lookup(struct ttm_object_file *tfile,return 0 ; } +/** +* vmw_user_bo_noref_lookup - Look up a vmw user buffer object without reference +* @tfile: The TTM object file the handle is registered with. +* @handle: The user buffer object handle. +* +* This function looks up a struct vmw_user_bo and returns a pointer to the +* struct vmw_buffer_object it derives from without refcounting the pointer. +* The returned pointer is only valid until vmw_user_bo_noref_release() is +* called, and the object pointed to by the returned pointer may be doomed. +* Any persistent usage of the object requires a refcount to be taken using +* ttm_bo_reference_unless_doomed(). Iff this function returns successfully it +* needs to be paired with vmw_user_bo_noref_release() and no sleeping- +* or scheduling functions may be called inbetween these function calls. +* +* Return: A struct vmw_buffer_object pointer if successful or negative +* error pointer on failure. +*/ +struct vmw_buffer_object * +vmw_user_bo_noref_lookup (struct ttm_object_file *tfile,u32 handle) +{ +struct vmw_user_buffer_object *vmw_user_bo; +struct ttm_base_object *base; + + base =ttm_base_object_noref_lookup (tfile, handle); +if (!base) { +DRM_ERROR ("Invalid buffer object handle 0x%08lx.\n" , + (unsigned long )handle); +return ERR_PTR (-ESRCH ); + } + +if (unlikely (ttm_base_object_type (base) != ttm_buffer_type)) { +ttm_base_object_noref_release (); +DRM_ERROR ("Invalid buffer object handle 0x%08lx.\n" , + (unsigned long )handle); +return ERR_PTR (-EINVAL ); + } + + vmw_user_bo = container_of(base, struct vmw_user_buffer_object, + prime.base); +return &vmw_user_bo->vbo; +}/** * vmw_user_bo_reference - Open a handle to a vmw user buffer object.
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +12 -0
@@ -772,6 +772,18 @@ extern void vmw_bo_unmap(struct vmw_buffer_object *vbo);extern void vmw_bo_move_notify (struct ttm_buffer_object *bo,struct ttm_mem_reg *mem);extern void vmw_bo_swap_notify (struct ttm_buffer_object *bo); +extern struct vmw_buffer_object * +vmw_user_bo_noref_lookup (struct ttm_object_file *tfile,u32 handle); + +/** +* vmw_user_bo_noref_release - release a buffer object pointer looked up +* without reference +*/ +static inline void vmw_user_bo_noref_release (void ) +{ +ttm_base_object_noref_release (); +} +/** * Misc Ioctl functionality - vmwgfx_ioctl.c
Signature · 6 lines
2.14.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 15/18 drm/vmwgfx: Make buffer object lookups reference-free during validation
In reply to Thomas HellstromMake the process of looking up a buffer object and adding it to the validation list reference-free unless when it's actually added to the validation list where a single reference is taken.
This saves two locked atomic operations per command stream buffer object handle lookup.
--- drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 85 ++++++++++++--------------------- 1 file changed, 30 insertions(+), 55 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +30 -55
@@ -1137,7 +1137,7 @@ static void vmw_query_bo_switch_commit(struct vmw_private *dev_priv,* @sw_context: The software context used for this command batch validation. * @id: Pointer to the user-space handle to be translated. * @vmw_bo_p: Points to a location that, on successful return will carry -* a reference-counted pointer to the DMA buffer identified by the +* a non-reference-counted pointer to the buffer object identified by the * user-space handle in @id. * * This function saves information needed to translate a user-space buffer
@@ -1152,38 +1152,34 @@ static int vmw_translate_mob_ptr(struct vmw_private *dev_priv,SVGAMobId *id, struct vmw_buffer_object **vmw_bo_p) { - struct vmw_buffer_object *vmw_bo = NULL; + struct vmw_buffer_object *vmw_bo;uint32_t handle = *id;struct vmw_relocation *reloc;int ret; - ret =vmw_user_bo_lookup (sw_context->fp->tfile, handle, &vmw_bo,NULL ); -if (unlikely (ret !=0 )) { +vmw_validation_preload_bo (sw_context->ctx); + vmw_bo =vmw_user_bo_noref_lookup (sw_context->fp->tfile, handle); +if (IS_ERR (vmw_bo)) {DRM_ERROR ("Could not find or use MOB buffer.\n" ); - ret = -EINVAL ; - goto out_no_reloc; +return PTR_ERR (vmw_bo); } + ret =vmw_validation_add_bo (sw_context->ctx, vmw_bo, true, false); +vmw_user_bo_noref_release (); +if (unlikely (ret !=0 )) +return ret; + reloc =vmw_validation_mem_alloc (sw_context->ctx,sizeof (*reloc));if (!reloc) - goto out_no_reloc; +return -ENOMEM ; reloc->mob_loc = id; reloc->vbo = vmw_bo; - ret =vmw_validation_add_bo (sw_context->ctx, vmw_bo, true, false); -if (unlikely (ret !=0 )) - goto out_no_reloc; - *vmw_bo_p = vmw_bo;list_add_tail (&reloc->head, &sw_context->bo_relocations);return 0 ; - -out_no_reloc: -vmw_bo_unreference (&vmw_bo); - *vmw_bo_p =NULL ; -return ret; }/**
@@ -1194,7 +1190,7 @@ static int vmw_translate_mob_ptr(struct vmw_private *dev_priv,* @sw_context: The software context used for this command batch validation. * @ptr: Pointer to the user-space handle to be translated. * @vmw_bo_p: Points to a location that, on successful return will carry -* a reference-counted pointer to the DMA buffer identified by the +* a non-reference-counted pointer to the DMA buffer identified by the * user-space handle in @id. * * This function saves information needed to translate a user-space buffer
@@ -1210,38 +1206,33 @@ static int vmw_translate_guest_ptr(struct vmw_private *dev_priv,SVGAGuestPtr *ptr, struct vmw_buffer_object **vmw_bo_p) { - struct vmw_buffer_object *vmw_bo = NULL; + struct vmw_buffer_object *vmw_bo;uint32_t handle = ptr->gmrId;struct vmw_relocation *reloc;int ret; - ret =vmw_user_bo_lookup (sw_context->fp->tfile, handle, &vmw_bo,NULL ); -if (unlikely (ret !=0 )) { +vmw_validation_preload_bo (sw_context->ctx); + vmw_bo =vmw_user_bo_noref_lookup (sw_context->fp->tfile, handle); +if (IS_ERR (vmw_bo)) {DRM_ERROR ("Could not find or use GMR region.\n" ); - ret = -EINVAL ; - goto out_no_reloc; +return PTR_ERR (vmw_bo); } + ret =vmw_validation_add_bo (sw_context->ctx, vmw_bo, false, false); +vmw_user_bo_noref_release (); +if (unlikely (ret !=0 )) +return ret; + reloc =vmw_validation_mem_alloc (sw_context->ctx,sizeof (*reloc));if (!reloc) - goto out_no_reloc; +return -ENOMEM ; reloc->location = ptr; reloc->vbo = vmw_bo; - - ret =vmw_validation_add_bo (sw_context->ctx, vmw_bo, false, false); -if (unlikely (ret !=0 )) - goto out_no_reloc; - *vmw_bo_p = vmw_bo;list_add_tail (&reloc->head, &sw_context->bo_relocations);return 0 ; - -out_no_reloc: -vmw_bo_unreference (&vmw_bo); - *vmw_bo_p =NULL ; -return ret; }
@@ -1328,10 +1319,7 @@ static int vmw_cmd_dx_bind_query(struct vmw_private *dev_priv, sw_context->dx_query_mob = vmw_bo; sw_context->dx_query_ctx = sw_context->dx_ctx_node->ctx; - -vmw_bo_unreference (&vmw_bo); - -return ret; +return 0 ; }
@@ -1432,7 +1420,6 @@ static int vmw_cmd_end_gb_query(struct vmw_private *dev_priv, ret =vmw_query_bo_switch_prepare (dev_priv, vmw_bo, sw_context); -vmw_bo_unreference (&vmw_bo);return ret; }
@@ -1486,7 +1473,6 @@ static int vmw_cmd_end_query(struct vmw_private *dev_priv, ret =vmw_query_bo_switch_prepare (dev_priv, vmw_bo, sw_context); -vmw_bo_unreference (&vmw_bo);return ret; }
@@ -1519,7 +1505,6 @@ static int vmw_cmd_wait_gb_query(struct vmw_private *dev_priv,if (unlikely (ret !=0 ))return ret; -vmw_bo_unreference (&vmw_bo);return 0 ; }
@@ -1571,7 +1556,6 @@ static int vmw_cmd_wait_query(struct vmw_private *dev_priv,if (unlikely (ret !=0 ))return ret; -vmw_bo_unreference (&vmw_bo);return 0 ; }
@@ -1622,7 +1606,7 @@ static int vmw_cmd_dma(struct vmw_private *dev_priv,if (unlikely (ret !=0 )) {if (unlikely (ret != -ERESTARTSYS ))DRM_ERROR ("could not find surface for DMA.\n" ); - goto out_no_surface; +return ret; } srf =vmw_res_to_srf (sw_context->res_cache[vmw_res_surface].res);
@@ -1630,9 +1614,7 @@ static int vmw_cmd_dma(struct vmw_private *dev_priv,vmw_kms_cursor_snoop (srf, sw_context->fp->tfile, &vmw_bo->base, header); -out_no_surface: -vmw_bo_unreference (&vmw_bo); -return ret; +return 0 ; } static int vmw_cmd_draw(struct vmw_private *dev_priv,
@@ -1763,14 +1745,9 @@ static int vmw_cmd_check_define_gmrfb(struct vmw_private *dev_priv,SVGAFifoCmdDefineGMRFB body; } *cmd = buf; - ret =vmw_translate_guest_ptr (dev_priv, sw_context, - &cmd->body.ptr, - &vmw_bo); -if (unlikely (ret !=0 )) -return ret; - -vmw_bo_unreference (&vmw_bo); - +return vmw_translate_guest_ptr (dev_priv, sw_context, + &cmd->body.ptr, + &vmw_bo);return ret; }
@@ -1810,8 +1787,6 @@ static int vmw_cmd_res_switch_backup(struct vmw_private *dev_priv,vmw_validation_res_switch_backup (sw_context->ctx, info, vbo, backup_offset); -vmw_bo_unreference (&vbo); -return 0 ; }
Signature · 6 lines
2.14.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 16/18 drm/vmwgfx: Don't refcount command-buffer managed resource lookups during command buffer validation
In reply to Thomas HellstromThe 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.
--- drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf_res.c | 3 +- drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 69 +++++++++++------------------- 2 files changed, 27 insertions(+), 45 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf_res.c +1 -2
@@ -89,8 +89,7 @@ vmw_cmdbuf_res_lookup(struct vmw_cmdbuf_res_manager *man,if (unlikely (ret !=0 ))return ERR_PTR (ret); -return vmw_resource_reference - (drm_hash_entry(hash, struct vmw_cmdbuf_res, hash)->res); + return drm_hash_entry(hash, struct vmw_cmdbuf_res, hash)->res; }/**
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +26 -43
165 lines not on this page · raw message
Signature · 6 lines
2.14.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 17/18 drm/vmwgfx: Don't refcount cotable lookups during command buffer validation
In reply to Thomas HellstromThe 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.
--- drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 5 ++--- drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 5 ----- drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 3 ++- drivers/gpu/drm/vmwgfx/vmwgfx_so.c | 3 ++- 4 files changed, 6 insertions(+), 10 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_context.c +2 -3
@@ -861,9 +861,8 @@ struct vmw_resource *vmw_context_cotable(struct vmw_resource *ctx,if (cotable_type >=SVGA_COTABLE_DX10_MAX )return ERR_PTR (-EINVAL ); -return vmw_resource_reference - (container_of(ctx, struct vmw_user_context, res)-> - cotables[cotable_type]); + return container_of(ctx, struct vmw_user_context, res)-> + cotables[cotable_type]; }/**
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +0 -5
@@ -372,7 +372,6 @@ static int vmw_resource_context_res_add(struct vmw_private *dev_priv,continue ; ret =vmw_resource_val_add (sw_context, res); -vmw_resource_unreference (&res);if (unlikely (ret !=0 ))return ret; }
@@ -1266,7 +1265,6 @@ static int vmw_cmd_dx_define_query(struct vmw_private *dev_priv, cotable_res =vmw_context_cotable (ctx_node->ctx,SVGA_COTABLE_DXQUERY ); ret =vmw_cotable_notify (cotable_res, cmd->q.queryId); -vmw_resource_unreference (&cotable_res);return ret; }
@@ -2578,7 +2576,6 @@ static int vmw_cmd_dx_view_define(struct vmw_private *dev_priv, res =vmw_context_cotable (ctx_node->ctx, vmw_view_cotables[view_type]); ret =vmw_cotable_notify (res, cmd->defined_id); -vmw_resource_unreference (&res);if (unlikely (ret !=0 ))return ret;
@@ -2675,7 +2672,6 @@ static int vmw_cmd_dx_so_define(struct vmw_private *dev_priv, res =vmw_context_cotable (ctx_node->ctx, vmw_so_cotables[so_type]); cmd =container_of (header,typeof (*cmd), header); ret =vmw_cotable_notify (res, cmd->defined_id); -vmw_resource_unreference (&res);return ret; }
@@ -2806,7 +2802,6 @@ static int vmw_cmd_dx_define_shader(struct vmw_private *dev_priv, res =vmw_context_cotable (ctx_node->ctx,SVGA_COTABLE_DXSHADER ); ret =vmw_cotable_notify (res, cmd->body.shaderId); -vmw_resource_unreference (&res);if (ret)return ret;
drivers/gpu/drm/vmwgfx/vmwgfx_shader.c +2 -1
@@ -636,7 +636,8 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man, res = &shader->res; shader->ctx = ctx; - shader->cotable =vmw_context_cotable (ctx,SVGA_COTABLE_DXSHADER ); + shader->cotable =vmw_resource_reference + (vmw_context_cotable (ctx,SVGA_COTABLE_DXSHADER )); shader->id = user_key; shader->committed = false;INIT_LIST_HEAD (&shader->cotable_head);
drivers/gpu/drm/vmwgfx/vmwgfx_so.c +2 -1
@@ -366,7 +366,8 @@ int vmw_view_add(struct vmw_cmdbuf_res_manager *man, res = &view->res; view->ctx = ctx; view->srf =vmw_resource_reference (srf); - view->cotable =vmw_context_cotable (ctx, vmw_view_cotables[view_type]); + view->cotable =vmw_resource_reference + (vmw_context_cotable (ctx, vmw_view_cotables[view_type])); view->view_type = view_type; view->view_id = user_key; view->cmd_size = cmd_size;
Signature · 6 lines
2.14.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 18/18 drm/vmwgfx: Make user resource lookups reference-free during validation
In reply to Thomas HellstromMake the process of looking up a user resource and adding it to the validation list reference-free unless when it's actually added to the validation list where a single reference is taken.
This saves two locked atomic operations per command stream buffer object handle lookup, unless there is a lookup cache hit.
--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 18 ++- drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 267 ++++++++++++++++--------------- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 35 ++++ 3 files changed, 187 insertions(+), 133 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +15 -3
@@ -337,8 +337,6 @@ struct vmw_ctx_validation_info;* @last_query_ctx: Last context that submitted a query * @needs_post_query_barrier: Whether a query barrier is needed after * command submission -* @error_resource: Pointer to hold a reference to the resource causing -* an error * @staged_bindings: Cached per-context binding tracker * @staged_bindings_inuse: Whether the cached per-context binding tracker * is in use
@@ -365,7 +363,6 @@ struct vmw_sw_context{struct vmw_res_cache_entry res_cache[vmw_res_max];struct vmw_resource *last_query_ctx;bool needs_post_query_barrier; -struct vmw_resource *error_resource;struct vmw_ctx_binding_state *staged_bindings;bool staged_bindings_inuse;struct list_head staged_cmd_res;
@@ -698,6 +695,12 @@ extern int vmw_user_resource_lookup_handle(uint32_t handle, const struct vmw_user_resource_conv *converter, struct vmw_resource **p_res); +extern struct vmw_resource * +vmw_user_resource_noref_lookup_handle (struct vmw_private *dev_priv, +struct ttm_object_file *tfile, +uint32_t handle, +const struct vmw_user_resource_conv * + converter);extern int vmw_stream_claim_ioctl (struct drm_device *dev,void *data,struct drm_file *file_priv); extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
@@ -716,6 +719,15 @@ extern int vmw_query_readback_all(struct vmw_buffer_object *dx_query_mob);extern void vmw_resource_evict_all (struct vmw_private *dev_priv);extern void vmw_resource_unbind_list (struct vmw_buffer_object *vbo); +/** +* vmw_user_resource_noref_release - release a user resource pointer looked up +* without reference +*/ +static inline void vmw_user_resource_noref_release (void ) +{ +ttm_base_object_noref_release (); +} +/** * Buffer object helper functions - vmwgfx_bo.c */
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +137 -130
417 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +35 -0
@@ -230,6 +230,41 @@ int vmw_user_resource_lookup_handle(struct vmw_private *dev_priv,return ret; } +/** +* vmw_user_resource_lookup_handle - lookup a struct resource from a +* TTM user-space handle and perform basic type checks +* +* @dev_priv: Pointer to a device private struct +* @tfile: Pointer to a struct ttm_object_file identifying the caller +* @handle: The TTM user-space handle +* @converter: Pointer to an object describing the resource type +* @p_res: On successful return the location pointed to will contain +* a pointer to a refcounted struct vmw_resource. +* +* If the handle can't be found or is associated with an incorrect resource +* type, -EINVAL will be returned. +*/ +struct vmw_resource * +vmw_user_resource_noref_lookup_handle (struct vmw_private *dev_priv, +struct ttm_object_file *tfile, +uint32_t handle, +const struct vmw_user_resource_conv + *converter) +{ +struct ttm_base_object *base; + + base =ttm_base_object_noref_lookup (tfile, handle); +if (!base) +return ERR_PTR (-ESRCH ); + +if (unlikely (ttm_base_object_type (base) != converter->object_type)) { +ttm_base_object_noref_release (); +return ERR_PTR (-EINVAL ); + } + +return converter->base_obj_to_res (base); +} +/** * Helper function that looks either a surface or bo. *
Signature · 6 lines
2.14.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel