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

drm: use drm_file to tag vm-bos

Rather than using "struct file*", use "struct drm_file*" as tag VM tag for
BOs. This will pave the way for "struct drm_file*" without any "struct
file*" back-pointer.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/20160901124837.680-3-dh.herrmann@gmail.com

authored by

David Herrmann and committed by
Daniel Vetter
d9a1f0b4 75ae95a7

+51 -41
+2 -1
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
··· 226 226 227 227 if (amdgpu_ttm_tt_get_usermm(bo->ttm)) 228 228 return -EPERM; 229 - return drm_vma_node_verify_access(&rbo->gem_base.vma_node, filp); 229 + return drm_vma_node_verify_access(&rbo->gem_base.vma_node, 230 + filp->private_data); 230 231 } 231 232 232 233 static void amdgpu_move_null(struct ttm_buffer_object *bo,
+2 -1
drivers/gpu/drm/ast/ast_ttm.c
··· 150 150 { 151 151 struct ast_bo *astbo = ast_bo(bo); 152 152 153 - return drm_vma_node_verify_access(&astbo->gem.vma_node, filp); 153 + return drm_vma_node_verify_access(&astbo->gem.vma_node, 154 + filp->private_data); 154 155 } 155 156 156 157 static int ast_ttm_io_mem_reserve(struct ttm_bo_device *bdev,
+2 -1
drivers/gpu/drm/bochs/bochs_mm.c
··· 128 128 { 129 129 struct bochs_bo *bochsbo = bochs_bo(bo); 130 130 131 - return drm_vma_node_verify_access(&bochsbo->gem.vma_node, filp); 131 + return drm_vma_node_verify_access(&bochsbo->gem.vma_node, 132 + filp->private_data); 132 133 } 133 134 134 135 static int bochs_ttm_io_mem_reserve(struct ttm_bo_device *bdev,
+2 -1
drivers/gpu/drm/cirrus/cirrus_ttm.c
··· 150 150 { 151 151 struct cirrus_bo *cirrusbo = cirrus_bo(bo); 152 152 153 - return drm_vma_node_verify_access(&cirrusbo->gem.vma_node, filp); 153 + return drm_vma_node_verify_access(&cirrusbo->gem.vma_node, 154 + filp->private_data); 154 155 } 155 156 156 157 static int cirrus_ttm_io_mem_reserve(struct ttm_bo_device *bdev,
+4 -4
drivers/gpu/drm/drm_gem.c
··· 257 257 258 258 if (drm_core_check_feature(dev, DRIVER_PRIME)) 259 259 drm_gem_remove_prime_handles(obj, file_priv); 260 - drm_vma_node_revoke(&obj->vma_node, file_priv->filp); 260 + drm_vma_node_revoke(&obj->vma_node, file_priv); 261 261 262 262 if (dev->driver->gem_close_object) 263 263 dev->driver->gem_close_object(obj, file_priv); ··· 372 372 373 373 handle = ret; 374 374 375 - ret = drm_vma_node_allow(&obj->vma_node, file_priv->filp); 375 + ret = drm_vma_node_allow(&obj->vma_node, file_priv); 376 376 if (ret) 377 377 goto err_remove; 378 378 ··· 386 386 return 0; 387 387 388 388 err_revoke: 389 - drm_vma_node_revoke(&obj->vma_node, file_priv->filp); 389 + drm_vma_node_revoke(&obj->vma_node, file_priv); 390 390 err_remove: 391 391 spin_lock(&file_priv->table_lock); 392 392 idr_remove(&file_priv->object_idr, handle); ··· 991 991 if (!obj) 992 992 return -EINVAL; 993 993 994 - if (!drm_vma_node_is_allowed(node, filp)) { 994 + if (!drm_vma_node_is_allowed(node, priv)) { 995 995 drm_gem_object_unreference_unlocked(obj); 996 996 return -EACCES; 997 997 }
+20 -20
drivers/gpu/drm/drm_vma_manager.c
··· 25 25 #include <drm/drmP.h> 26 26 #include <drm/drm_mm.h> 27 27 #include <drm/drm_vma_manager.h> 28 - #include <linux/fs.h> 29 28 #include <linux/mm.h> 30 29 #include <linux/module.h> 31 30 #include <linux/rbtree.h> ··· 251 252 /** 252 253 * drm_vma_node_allow - Add open-file to list of allowed users 253 254 * @node: Node to modify 254 - * @filp: Open file to add 255 + * @tag: Tag of file to remove 255 256 * 256 - * Add @filp to the list of allowed open-files for this node. If @filp is 257 + * Add @tag to the list of allowed open-files for this node. If @tag is 257 258 * already on this list, the ref-count is incremented. 258 259 * 259 260 * The list of allowed-users is preserved across drm_vma_offset_add() and ··· 268 269 * RETURNS: 269 270 * 0 on success, negative error code on internal failure (out-of-mem) 270 271 */ 271 - int drm_vma_node_allow(struct drm_vma_offset_node *node, struct file *filp) 272 + int drm_vma_node_allow(struct drm_vma_offset_node *node, struct drm_file *tag) 272 273 { 273 274 struct rb_node **iter; 274 275 struct rb_node *parent = NULL; ··· 289 290 parent = *iter; 290 291 entry = rb_entry(*iter, struct drm_vma_offset_file, vm_rb); 291 292 292 - if (filp == entry->vm_filp) { 293 + if (tag == entry->vm_tag) { 293 294 entry->vm_count++; 294 295 goto unlock; 295 - } else if (filp > entry->vm_filp) { 296 + } else if (tag > entry->vm_tag) { 296 297 iter = &(*iter)->rb_right; 297 298 } else { 298 299 iter = &(*iter)->rb_left; ··· 304 305 goto unlock; 305 306 } 306 307 307 - new->vm_filp = filp; 308 + new->vm_tag = tag; 308 309 new->vm_count = 1; 309 310 rb_link_node(&new->vm_rb, parent, iter); 310 311 rb_insert_color(&new->vm_rb, &node->vm_files); ··· 320 321 /** 321 322 * drm_vma_node_revoke - Remove open-file from list of allowed users 322 323 * @node: Node to modify 323 - * @filp: Open file to remove 324 + * @tag: Tag of file to remove 324 325 * 325 - * Decrement the ref-count of @filp in the list of allowed open-files on @node. 326 - * If the ref-count drops to zero, remove @filp from the list. You must call 327 - * this once for every drm_vma_node_allow() on @filp. 326 + * Decrement the ref-count of @tag in the list of allowed open-files on @node. 327 + * If the ref-count drops to zero, remove @tag from the list. You must call 328 + * this once for every drm_vma_node_allow() on @tag. 328 329 * 329 330 * This is locked against concurrent access internally. 330 331 * 331 - * If @filp is not on the list, nothing is done. 332 + * If @tag is not on the list, nothing is done. 332 333 */ 333 - void drm_vma_node_revoke(struct drm_vma_offset_node *node, struct file *filp) 334 + void drm_vma_node_revoke(struct drm_vma_offset_node *node, 335 + struct drm_file *tag) 334 336 { 335 337 struct drm_vma_offset_file *entry; 336 338 struct rb_node *iter; ··· 341 341 iter = node->vm_files.rb_node; 342 342 while (likely(iter)) { 343 343 entry = rb_entry(iter, struct drm_vma_offset_file, vm_rb); 344 - if (filp == entry->vm_filp) { 344 + if (tag == entry->vm_tag) { 345 345 if (!--entry->vm_count) { 346 346 rb_erase(&entry->vm_rb, &node->vm_files); 347 347 kfree(entry); 348 348 } 349 349 break; 350 - } else if (filp > entry->vm_filp) { 350 + } else if (tag > entry->vm_tag) { 351 351 iter = iter->rb_right; 352 352 } else { 353 353 iter = iter->rb_left; ··· 361 361 /** 362 362 * drm_vma_node_is_allowed - Check whether an open-file is granted access 363 363 * @node: Node to check 364 - * @filp: Open-file to check for 364 + * @tag: Tag of file to remove 365 365 * 366 - * Search the list in @node whether @filp is currently on the list of allowed 366 + * Search the list in @node whether @tag is currently on the list of allowed 367 367 * open-files (see drm_vma_node_allow()). 368 368 * 369 369 * This is locked against concurrent access internally. ··· 372 372 * true iff @filp is on the list 373 373 */ 374 374 bool drm_vma_node_is_allowed(struct drm_vma_offset_node *node, 375 - struct file *filp) 375 + struct drm_file *tag) 376 376 { 377 377 struct drm_vma_offset_file *entry; 378 378 struct rb_node *iter; ··· 382 382 iter = node->vm_files.rb_node; 383 383 while (likely(iter)) { 384 384 entry = rb_entry(iter, struct drm_vma_offset_file, vm_rb); 385 - if (filp == entry->vm_filp) 385 + if (tag == entry->vm_tag) 386 386 break; 387 - else if (filp > entry->vm_filp) 387 + else if (tag > entry->vm_tag) 388 388 iter = iter->rb_right; 389 389 else 390 390 iter = iter->rb_left;
+2 -1
drivers/gpu/drm/mgag200/mgag200_ttm.c
··· 150 150 { 151 151 struct mgag200_bo *mgabo = mgag200_bo(bo); 152 152 153 - return drm_vma_node_verify_access(&mgabo->gem.vma_node, filp); 153 + return drm_vma_node_verify_access(&mgabo->gem.vma_node, 154 + filp->private_data); 154 155 } 155 156 156 157 static int mgag200_ttm_io_mem_reserve(struct ttm_bo_device *bdev,
+2 -1
drivers/gpu/drm/nouveau/nouveau_bo.c
··· 1315 1315 { 1316 1316 struct nouveau_bo *nvbo = nouveau_bo(bo); 1317 1317 1318 - return drm_vma_node_verify_access(&nvbo->gem.vma_node, filp); 1318 + return drm_vma_node_verify_access(&nvbo->gem.vma_node, 1319 + filp->private_data); 1319 1320 } 1320 1321 1321 1322 static int
+2 -1
drivers/gpu/drm/qxl/qxl_ttm.c
··· 210 210 { 211 211 struct qxl_bo *qbo = to_qxl_bo(bo); 212 212 213 - return drm_vma_node_verify_access(&qbo->gem_base.vma_node, filp); 213 + return drm_vma_node_verify_access(&qbo->gem_base.vma_node, 214 + filp->private_data); 214 215 } 215 216 216 217 static int qxl_ttm_io_mem_reserve(struct ttm_bo_device *bdev,
+2 -1
drivers/gpu/drm/radeon/radeon_ttm.c
··· 237 237 238 238 if (radeon_ttm_tt_has_userptr(bo->ttm)) 239 239 return -EPERM; 240 - return drm_vma_node_verify_access(&rbo->gem_base.vma_node, filp); 240 + return drm_vma_node_verify_access(&rbo->gem_base.vma_node, 241 + filp->private_data); 241 242 } 242 243 243 244 static void radeon_move_null(struct ttm_buffer_object *bo,
+11 -9
include/drm/drm_vma_manager.h
··· 24 24 */ 25 25 26 26 #include <drm/drm_mm.h> 27 - #include <linux/fs.h> 28 27 #include <linux/mm.h> 29 28 #include <linux/module.h> 30 29 #include <linux/rbtree.h> 31 30 #include <linux/spinlock.h> 32 31 #include <linux/types.h> 33 32 33 + struct drm_file; 34 + 34 35 struct drm_vma_offset_file { 35 36 struct rb_node vm_rb; 36 - struct file *vm_filp; 37 + struct drm_file *vm_tag; 37 38 unsigned long vm_count; 38 39 }; 39 40 ··· 61 60 void drm_vma_offset_remove(struct drm_vma_offset_manager *mgr, 62 61 struct drm_vma_offset_node *node); 63 62 64 - int drm_vma_node_allow(struct drm_vma_offset_node *node, struct file *filp); 65 - void drm_vma_node_revoke(struct drm_vma_offset_node *node, struct file *filp); 63 + int drm_vma_node_allow(struct drm_vma_offset_node *node, struct drm_file *tag); 64 + void drm_vma_node_revoke(struct drm_vma_offset_node *node, 65 + struct drm_file *tag); 66 66 bool drm_vma_node_is_allowed(struct drm_vma_offset_node *node, 67 - struct file *filp); 67 + struct drm_file *tag); 68 68 69 69 /** 70 70 * drm_vma_offset_exact_lookup_locked() - Look up node by exact address ··· 216 214 /** 217 215 * drm_vma_node_verify_access() - Access verification helper for TTM 218 216 * @node: Offset node 219 - * @filp: Open-file 217 + * @tag: Tag of file to check 220 218 * 221 - * This checks whether @filp is granted access to @node. It is the same as 219 + * This checks whether @tag is granted access to @node. It is the same as 222 220 * drm_vma_node_is_allowed() but suitable as drop-in helper for TTM 223 221 * verify_access() callbacks. 224 222 * ··· 226 224 * 0 if access is granted, -EACCES otherwise. 227 225 */ 228 226 static inline int drm_vma_node_verify_access(struct drm_vma_offset_node *node, 229 - struct file *filp) 227 + struct drm_file *tag) 230 228 { 231 - return drm_vma_node_is_allowed(node, filp) ? 0 : -EACCES; 229 + return drm_vma_node_is_allowed(node, tag) ? 0 : -EACCES; 232 230 } 233 231 234 232 #endif /* __DRM_VMA_MANAGER_H__ */