Skip to content

Commit

Permalink
drm: Make hashtab rcu-safe
Browse files Browse the repository at this point in the history
TTM base objects will be the first consumer.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
  • Loading branch information
Thomas Hellstrom authored and Dave Airlie committed Nov 20, 2012
1 parent dedfdff commit d714455
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions drivers/gpu/drm/drm_hashtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ void drm_ht_verbose_list(struct drm_open_hash *ht, unsigned long key)
hashed_key = hash_long(key, ht->order);
DRM_DEBUG("Key is 0x%08lx, Hashed key is 0x%08x\n", key, hashed_key);
h_list = &ht->table[hashed_key];
hlist_for_each(list, h_list) {
entry = hlist_entry(list, struct drm_hash_item, head);
hlist_for_each_entry_rcu(entry, list, h_list, head)
DRM_DEBUG("count %d, key: 0x%08lx\n", count++, entry->key);
}
}

static struct hlist_node *drm_ht_find_key(struct drm_open_hash *ht,
Expand All @@ -83,8 +81,7 @@ static struct hlist_node *drm_ht_find_key(struct drm_open_hash *ht,

hashed_key = hash_long(key, ht->order);
h_list = &ht->table[hashed_key];
hlist_for_each(list, h_list) {
entry = hlist_entry(list, struct drm_hash_item, head);
hlist_for_each_entry_rcu(entry, list, h_list, head) {
if (entry->key == key)
return list;
if (entry->key > key)
Expand All @@ -105,18 +102,17 @@ int drm_ht_insert_item(struct drm_open_hash *ht, struct drm_hash_item *item)
hashed_key = hash_long(key, ht->order);
h_list = &ht->table[hashed_key];
parent = NULL;
hlist_for_each(list, h_list) {
entry = hlist_entry(list, struct drm_hash_item, head);
hlist_for_each_entry_rcu(entry, list, h_list, head) {
if (entry->key == key)
return -EINVAL;
if (entry->key > key)
break;
parent = list;
}
if (parent) {
hlist_add_after(parent, &item->head);
hlist_add_after_rcu(parent, &item->head);
} else {
hlist_add_head(&item->head, h_list);
hlist_add_head_rcu(&item->head, h_list);
}
return 0;
}
Expand Down Expand Up @@ -171,15 +167,15 @@ int drm_ht_remove_key(struct drm_open_hash *ht, unsigned long key)

list = drm_ht_find_key(ht, key);
if (list) {
hlist_del_init(list);
hlist_del_init_rcu(list);
return 0;
}
return -EINVAL;
}

int drm_ht_remove_item(struct drm_open_hash *ht, struct drm_hash_item *item)
{
hlist_del_init(&item->head);
hlist_del_init_rcu(&item->head);
return 0;
}
EXPORT_SYMBOL(drm_ht_remove_item);
Expand Down

0 comments on commit d714455

Please sign in to comment.