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

drm/ttm: Add a ttm_ref_object_exists function

A function to be used to check whether a caller has put a ref object
(opened) a struct ttm_base_object

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>

+50
+46
drivers/gpu/drm/ttm/ttm_object.c
··· 270 270 } 271 271 EXPORT_SYMBOL(ttm_base_object_lookup_for_ref); 272 272 273 + /** 274 + * ttm_ref_object_exists - Check whether a caller has a valid ref object 275 + * (has opened) a base object. 276 + * 277 + * @tfile: Pointer to a struct ttm_object_file identifying the caller. 278 + * @base: Pointer to a struct base object. 279 + * 280 + * Checks wether the caller identified by @tfile has put a valid USAGE 281 + * reference object on the base object identified by @base. 282 + */ 283 + bool ttm_ref_object_exists(struct ttm_object_file *tfile, 284 + struct ttm_base_object *base) 285 + { 286 + struct drm_open_hash *ht = &tfile->ref_hash[TTM_REF_USAGE]; 287 + struct drm_hash_item *hash; 288 + struct ttm_ref_object *ref; 289 + 290 + rcu_read_lock(); 291 + if (unlikely(drm_ht_find_item_rcu(ht, base->hash.key, &hash) != 0)) 292 + goto out_false; 293 + 294 + /* 295 + * Verify that the ref object is really pointing to our base object. 296 + * Our base object could actually be dead, and the ref object pointing 297 + * to another base object with the same handle. 298 + */ 299 + ref = drm_hash_entry(hash, struct ttm_ref_object, hash); 300 + if (unlikely(base != ref->obj)) 301 + goto out_false; 302 + 303 + /* 304 + * Verify that the ref->obj pointer was actually valid! 305 + */ 306 + rmb(); 307 + if (unlikely(atomic_read(&ref->kref.refcount) == 0)) 308 + goto out_false; 309 + 310 + rcu_read_unlock(); 311 + return true; 312 + 313 + out_false: 314 + rcu_read_unlock(); 315 + return false; 316 + } 317 + EXPORT_SYMBOL(ttm_ref_object_exists); 318 + 273 319 int ttm_ref_object_add(struct ttm_object_file *tfile, 274 320 struct ttm_base_object *base, 275 321 enum ttm_ref_type ref_type, bool *existed)
+4
include/drm/ttm/ttm_object.h
··· 244 244 extern int ttm_ref_object_add(struct ttm_object_file *tfile, 245 245 struct ttm_base_object *base, 246 246 enum ttm_ref_type ref_type, bool *existed); 247 + 248 + extern bool ttm_ref_object_exists(struct ttm_object_file *tfile, 249 + struct ttm_base_object *base); 250 + 247 251 /** 248 252 * ttm_ref_object_base_unref 249 253 *