Commit e1f540c3 authored by Parav Pandit's avatar Parav Pandit Committed by Jason Gunthorpe

RDMA/core: Define client_data_lock as rwlock instead of spinlock

Even though device registration/unregistration and client
registration/unregistration is not a performance path, define the
client_data_lock as rwlock for code clarity.
Signed-off-by: default avatarParav Pandit <parav@mellanox.com>
Reviewed-by: default avatarDaniel Jurgens <danielj@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 2d65f49f
...@@ -270,7 +270,7 @@ struct ib_device *ib_alloc_device(size_t size) ...@@ -270,7 +270,7 @@ struct ib_device *ib_alloc_device(size_t size)
INIT_LIST_HEAD(&device->event_handler_list); INIT_LIST_HEAD(&device->event_handler_list);
spin_lock_init(&device->event_handler_lock); spin_lock_init(&device->event_handler_lock);
spin_lock_init(&device->client_data_lock); rwlock_init(&device->client_data_lock);
INIT_LIST_HEAD(&device->client_data_list); INIT_LIST_HEAD(&device->client_data_list);
INIT_LIST_HEAD(&device->port_list); INIT_LIST_HEAD(&device->port_list);
...@@ -307,9 +307,9 @@ static int add_client_context(struct ib_device *device, struct ib_client *client ...@@ -307,9 +307,9 @@ static int add_client_context(struct ib_device *device, struct ib_client *client
context->going_down = false; context->going_down = false;
down_write(&lists_rwsem); down_write(&lists_rwsem);
spin_lock_irq(&device->client_data_lock); write_lock_irq(&device->client_data_lock);
list_add(&context->list, &device->client_data_list); list_add(&context->list, &device->client_data_list);
spin_unlock_irq(&device->client_data_lock); write_unlock_irq(&device->client_data_lock);
up_write(&lists_rwsem); up_write(&lists_rwsem);
return 0; return 0;
...@@ -586,10 +586,10 @@ void ib_unregister_device(struct ib_device *device) ...@@ -586,10 +586,10 @@ void ib_unregister_device(struct ib_device *device)
down_write(&lists_rwsem); down_write(&lists_rwsem);
list_del(&device->core_list); list_del(&device->core_list);
spin_lock_irq(&device->client_data_lock); write_lock_irq(&device->client_data_lock);
list_for_each_entry(context, &device->client_data_list, list) list_for_each_entry(context, &device->client_data_list, list)
context->going_down = true; context->going_down = true;
spin_unlock_irq(&device->client_data_lock); write_unlock_irq(&device->client_data_lock);
downgrade_write(&lists_rwsem); downgrade_write(&lists_rwsem);
list_for_each_entry(context, &device->client_data_list, list) { list_for_each_entry(context, &device->client_data_list, list) {
...@@ -609,13 +609,13 @@ void ib_unregister_device(struct ib_device *device) ...@@ -609,13 +609,13 @@ void ib_unregister_device(struct ib_device *device)
kfree(device->port_pkey_list); kfree(device->port_pkey_list);
down_write(&lists_rwsem); down_write(&lists_rwsem);
spin_lock_irqsave(&device->client_data_lock, flags); write_lock_irqsave(&device->client_data_lock, flags);
list_for_each_entry_safe(context, tmp, &device->client_data_list, list_for_each_entry_safe(context, tmp, &device->client_data_list,
list) { list) {
list_del(&context->list); list_del(&context->list);
kfree(context); kfree(context);
} }
spin_unlock_irqrestore(&device->client_data_lock, flags); write_unlock_irqrestore(&device->client_data_lock, flags);
up_write(&lists_rwsem); up_write(&lists_rwsem);
device->reg_state = IB_DEV_UNREGISTERED; device->reg_state = IB_DEV_UNREGISTERED;
...@@ -678,14 +678,14 @@ void ib_unregister_client(struct ib_client *client) ...@@ -678,14 +678,14 @@ void ib_unregister_client(struct ib_client *client)
struct ib_client_data *found_context = NULL; struct ib_client_data *found_context = NULL;
down_write(&lists_rwsem); down_write(&lists_rwsem);
spin_lock_irq(&device->client_data_lock); write_lock_irq(&device->client_data_lock);
list_for_each_entry(context, &device->client_data_list, list) list_for_each_entry(context, &device->client_data_list, list)
if (context->client == client) { if (context->client == client) {
context->going_down = true; context->going_down = true;
found_context = context; found_context = context;
break; break;
} }
spin_unlock_irq(&device->client_data_lock); write_unlock_irq(&device->client_data_lock);
up_write(&lists_rwsem); up_write(&lists_rwsem);
if (client->remove) if (client->remove)
...@@ -699,9 +699,9 @@ void ib_unregister_client(struct ib_client *client) ...@@ -699,9 +699,9 @@ void ib_unregister_client(struct ib_client *client)
} }
down_write(&lists_rwsem); down_write(&lists_rwsem);
spin_lock_irq(&device->client_data_lock); write_lock_irq(&device->client_data_lock);
list_del(&found_context->list); list_del(&found_context->list);
spin_unlock_irq(&device->client_data_lock); write_unlock_irq(&device->client_data_lock);
up_write(&lists_rwsem); up_write(&lists_rwsem);
kfree(found_context); kfree(found_context);
} }
...@@ -724,13 +724,13 @@ void *ib_get_client_data(struct ib_device *device, struct ib_client *client) ...@@ -724,13 +724,13 @@ void *ib_get_client_data(struct ib_device *device, struct ib_client *client)
void *ret = NULL; void *ret = NULL;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&device->client_data_lock, flags); read_lock_irqsave(&device->client_data_lock, flags);
list_for_each_entry(context, &device->client_data_list, list) list_for_each_entry(context, &device->client_data_list, list)
if (context->client == client) { if (context->client == client) {
ret = context->data; ret = context->data;
break; break;
} }
spin_unlock_irqrestore(&device->client_data_lock, flags); read_unlock_irqrestore(&device->client_data_lock, flags);
return ret; return ret;
} }
...@@ -751,7 +751,7 @@ void ib_set_client_data(struct ib_device *device, struct ib_client *client, ...@@ -751,7 +751,7 @@ void ib_set_client_data(struct ib_device *device, struct ib_client *client,
struct ib_client_data *context; struct ib_client_data *context;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&device->client_data_lock, flags); write_lock_irqsave(&device->client_data_lock, flags);
list_for_each_entry(context, &device->client_data_list, list) list_for_each_entry(context, &device->client_data_list, list)
if (context->client == client) { if (context->client == client) {
context->data = data; context->data = data;
...@@ -762,7 +762,7 @@ void ib_set_client_data(struct ib_device *device, struct ib_client *client, ...@@ -762,7 +762,7 @@ void ib_set_client_data(struct ib_device *device, struct ib_client *client,
device->name, client->name); device->name, client->name);
out: out:
spin_unlock_irqrestore(&device->client_data_lock, flags); write_unlock_irqrestore(&device->client_data_lock, flags);
} }
EXPORT_SYMBOL(ib_set_client_data); EXPORT_SYMBOL(ib_set_client_data);
......
...@@ -2256,10 +2256,11 @@ struct ib_device { ...@@ -2256,10 +2256,11 @@ struct ib_device {
struct list_head event_handler_list; struct list_head event_handler_list;
spinlock_t event_handler_lock; spinlock_t event_handler_lock;
spinlock_t client_data_lock; rwlock_t client_data_lock;
struct list_head core_list; struct list_head core_list;
/* Access to the client_data_list is protected by the client_data_lock /* Access to the client_data_list is protected by the client_data_lock
* spinlock and the lists_rwsem read-write semaphore */ * rwlock and the lists_rwsem read-write semaphore
*/
struct list_head client_data_list; struct list_head client_data_list;
struct ib_cache cache; struct ib_cache cache;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment