aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Hellstrom <thellstrom@vmware.com>2018-09-26 09:55:16 -0400
committerThomas Hellstrom <thellstrom@vmware.com>2018-09-27 10:14:48 -0400
commite14c02e6b6990e9f6ee18a214a22ac26bae1b25e (patch)
tree42258a937b40f01e9dcd935b089f68f6f824a0c3
parentc7eae62666ade1c8c9960085911e420227144d5a (diff)
drm/vmwgfx: Look up objects without taking a reference
Typically 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(). Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com> Reviewed-by: Sinclair Yeh <syeh@vmware.com>
-rw-r--r--drivers/gpu/drm/vmwgfx/ttm_object.c35
-rw-r--r--drivers/gpu/drm/vmwgfx/ttm_object.h15
2 files changed, 50 insertions, 0 deletions
diff --git a/drivers/gpu/drm/vmwgfx/ttm_object.c b/drivers/gpu/drm/vmwgfx/ttm_object.c
index c5df2d7828e6..36990b80e790 100644
--- a/drivers/gpu/drm/vmwgfx/ttm_object.c
+++ b/drivers/gpu/drm/vmwgfx/ttm_object.c
@@ -225,6 +225,41 @@ void ttm_base_object_unref(struct ttm_base_object **p_base)
225 kref_put(&base->refcount, ttm_release_base); 225 kref_put(&base->refcount, ttm_release_base);
226} 226}
227 227
228/**
229 * ttm_base_object_noref_lookup - look up a base object without reference
230 * @tfile: The struct ttm_object_file the object is registered with.
231 * @key: The object handle.
232 *
233 * This function looks up a ttm base object and returns a pointer to it
234 * without refcounting the pointer. The returned pointer is only valid
235 * until ttm_base_object_noref_release() is called, and the object
236 * pointed to by the returned pointer may be doomed. Any persistent usage
237 * of the object requires a refcount to be taken using kref_get_unless_zero().
238 * Iff this function returns successfully it needs to be paired with
239 * ttm_base_object_noref_release() and no sleeping- or scheduling functions
240 * may be called inbetween these function callse.
241 *
242 * Return: A pointer to the object if successful or NULL otherwise.
243 */
244struct ttm_base_object *
245ttm_base_object_noref_lookup(struct ttm_object_file *tfile, uint32_t key)
246{
247 struct drm_hash_item *hash;
248 struct drm_open_hash *ht = &tfile->ref_hash[TTM_REF_USAGE];
249 int ret;
250
251 rcu_read_lock();
252 ret = drm_ht_find_item_rcu(ht, key, &hash);
253 if (ret) {
254 rcu_read_unlock();
255 return NULL;
256 }
257
258 __release(RCU);
259 return drm_hash_entry(hash, struct ttm_ref_object, hash)->obj;
260}
261EXPORT_SYMBOL(ttm_base_object_noref_lookup);
262
228struct ttm_base_object *ttm_base_object_lookup(struct ttm_object_file *tfile, 263struct ttm_base_object *ttm_base_object_lookup(struct ttm_object_file *tfile,
229 uint32_t key) 264 uint32_t key)
230{ 265{
diff --git a/drivers/gpu/drm/vmwgfx/ttm_object.h b/drivers/gpu/drm/vmwgfx/ttm_object.h
index 7aa213f5d677..50d26c7ff42d 100644
--- a/drivers/gpu/drm/vmwgfx/ttm_object.h
+++ b/drivers/gpu/drm/vmwgfx/ttm_object.h
@@ -357,4 +357,19 @@ extern int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,
357 * per idr. 357 * per idr.
358 */ 358 */
359#define TTM_OBJ_EXTRA_SIZE 128 359#define TTM_OBJ_EXTRA_SIZE 128
360
361struct ttm_base_object *
362ttm_base_object_noref_lookup(struct ttm_object_file *tfile, uint32_t key);
363
364/**
365 * ttm_base_object_noref_release - release a base object pointer looked up
366 * without reference
367 *
368 * Releases a base object pointer looked up with ttm_base_object_noref_lookup().
369 */
370static inline void ttm_base_object_noref_release(void)
371{
372 __acquire(RCU);
373 rcu_read_unlock();
374}
360#endif 375#endif