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

drm/vmwgfx: Look up user buffer objects without taking a reference

Identically to how we look up ttm base objects witout reference, provide
the same functionality to vmw user buffer objects which derive from them.

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

+53
+41
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
··· 921 921 return 0; 922 922 } 923 923 924 + /** 925 + * vmw_user_bo_noref_lookup - Look up a vmw user buffer object without reference 926 + * @tfile: The TTM object file the handle is registered with. 927 + * @handle: The user buffer object handle. 928 + * 929 + * This function looks up a struct vmw_user_bo and returns a pointer to the 930 + * struct vmw_buffer_object it derives from without refcounting the pointer. 931 + * The returned pointer is only valid until vmw_user_bo_noref_release() is 932 + * called, and the object pointed to by the returned pointer may be doomed. 933 + * Any persistent usage of the object requires a refcount to be taken using 934 + * ttm_bo_reference_unless_doomed(). Iff this function returns successfully it 935 + * needs to be paired with vmw_user_bo_noref_release() and no sleeping- 936 + * or scheduling functions may be called inbetween these function calls. 937 + * 938 + * Return: A struct vmw_buffer_object pointer if successful or negative 939 + * error pointer on failure. 940 + */ 941 + struct vmw_buffer_object * 942 + vmw_user_bo_noref_lookup(struct ttm_object_file *tfile, u32 handle) 943 + { 944 + struct vmw_user_buffer_object *vmw_user_bo; 945 + struct ttm_base_object *base; 946 + 947 + base = ttm_base_object_noref_lookup(tfile, handle); 948 + if (!base) { 949 + DRM_ERROR("Invalid buffer object handle 0x%08lx.\n", 950 + (unsigned long)handle); 951 + return ERR_PTR(-ESRCH); 952 + } 953 + 954 + if (unlikely(ttm_base_object_type(base) != ttm_buffer_type)) { 955 + ttm_base_object_noref_release(); 956 + DRM_ERROR("Invalid buffer object handle 0x%08lx.\n", 957 + (unsigned long)handle); 958 + return ERR_PTR(-EINVAL); 959 + } 960 + 961 + vmw_user_bo = container_of(base, struct vmw_user_buffer_object, 962 + prime.base); 963 + return &vmw_user_bo->vbo; 964 + } 924 965 925 966 /** 926 967 * vmw_user_bo_reference - Open a handle to a vmw user buffer object.
+12
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
··· 772 772 extern void vmw_bo_move_notify(struct ttm_buffer_object *bo, 773 773 struct ttm_mem_reg *mem); 774 774 extern void vmw_bo_swap_notify(struct ttm_buffer_object *bo); 775 + extern struct vmw_buffer_object * 776 + vmw_user_bo_noref_lookup(struct ttm_object_file *tfile, u32 handle); 777 + 778 + /** 779 + * vmw_user_bo_noref_release - release a buffer object pointer looked up 780 + * without reference 781 + */ 782 + static inline void vmw_user_bo_noref_release(void) 783 + { 784 + ttm_base_object_noref_release(); 785 + } 786 + 775 787 776 788 /** 777 789 * Misc Ioctl functionality - vmwgfx_ioctl.c