Commit 0df91bb6 authored by Jason Gunthorpe's avatar Jason Gunthorpe

RDMA/devices: Use xarray to store the client_data

Now that we have a small ID for each client we can use xarray instead of
linearly searching linked lists for client data. This will give much
faster and scalable client data lookup, and will lets us revise the
locking scheme.

Since xarray can store 'going_down' using a mark just entirely eliminate
the struct ib_client_data and directly store the client_data value in the
xarray. However this does require a special iterator as we must still
iterate over any NULL client_data values.

Also eliminate the client_data_lock in favour of internal xarray locking.
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent e59178d8
...@@ -51,30 +51,72 @@ MODULE_AUTHOR("Roland Dreier"); ...@@ -51,30 +51,72 @@ MODULE_AUTHOR("Roland Dreier");
MODULE_DESCRIPTION("core kernel InfiniBand API"); MODULE_DESCRIPTION("core kernel InfiniBand API");
MODULE_LICENSE("Dual BSD/GPL"); MODULE_LICENSE("Dual BSD/GPL");
struct ib_client_data {
struct list_head list;
struct ib_client *client;
void * data;
/* The device or client is going down. Do not call client or device
* callbacks other than remove(). */
bool going_down;
};
struct workqueue_struct *ib_comp_wq; struct workqueue_struct *ib_comp_wq;
struct workqueue_struct *ib_comp_unbound_wq; struct workqueue_struct *ib_comp_unbound_wq;
struct workqueue_struct *ib_wq; struct workqueue_struct *ib_wq;
EXPORT_SYMBOL_GPL(ib_wq); EXPORT_SYMBOL_GPL(ib_wq);
/* The device_list and clients contain devices and clients after their /*
* registration has completed, and the devices and clients are removed * devices contains devices that have had their names assigned. The
* during unregistration. */ * devices may not be registered. Users that care about the registration
static LIST_HEAD(device_list); * status need to call ib_device_try_get() on the device to ensure it is
* registered, and keep it registered, for the required duration.
*
*/
static DEFINE_XARRAY_FLAGS(devices, XA_FLAGS_ALLOC);
/*
* Note that if the *rwsem is held and the *_REGISTERED mark is seen then the
* object is guaranteed to be and remain registered for the duration of the
* lock.
*/
#define DEVICE_REGISTERED XA_MARK_1
static LIST_HEAD(client_list); static LIST_HEAD(client_list);
#define CLIENT_REGISTERED XA_MARK_1 #define CLIENT_REGISTERED XA_MARK_1
static DEFINE_XARRAY_FLAGS(clients, XA_FLAGS_ALLOC); static DEFINE_XARRAY_FLAGS(clients, XA_FLAGS_ALLOC);
/* /*
* device_mutex and lists_rwsem protect access to both device_list and * If client_data is registered then the corresponding client must also still
* be registered.
*/
#define CLIENT_DATA_REGISTERED XA_MARK_1
/*
* xarray has this behavior where it won't iterate over NULL values stored in
* allocated arrays. So we need our own iterator to see all values stored in
* the array. This does the same thing as xa_for_each except that it also
* returns NULL valued entries if the array is allocating. Simplified to only
* work on simple xarrays.
*/
static void *xan_find_marked(struct xarray *xa, unsigned long *indexp,
xa_mark_t filter)
{
XA_STATE(xas, xa, *indexp);
void *entry;
rcu_read_lock();
do {
entry = xas_find_marked(&xas, ULONG_MAX, filter);
if (xa_is_zero(entry))
break;
} while (xas_retry(&xas, entry));
rcu_read_unlock();
if (entry) {
*indexp = xas.xa_index;
if (xa_is_zero(entry))
return NULL;
return entry;
}
return XA_ERROR(-ENOENT);
}
#define xan_for_each_marked(xa, index, entry, filter) \
for (index = 0, entry = xan_find_marked(xa, &(index), filter); \
!xa_is_err(entry); \
(index)++, entry = xan_find_marked(xa, &(index), filter))
/*
* device_mutex and lists_rwsem protect access to both devices and
* clients. device_mutex protects writer access by device and client * clients. device_mutex protects writer access by device and client
* registration / de-registration. lists_rwsem protects reader access to * registration / de-registration. lists_rwsem protects reader access to
* these lists. Iterators of these lists must lock it for read, while updates * these lists. Iterators of these lists must lock it for read, while updates
...@@ -135,17 +177,6 @@ static int ib_device_check_mandatory(struct ib_device *device) ...@@ -135,17 +177,6 @@ static int ib_device_check_mandatory(struct ib_device *device)
return 0; return 0;
} }
static struct ib_device *__ib_device_get_by_index(u32 index)
{
struct ib_device *device;
list_for_each_entry(device, &device_list, core_list)
if (device->index == index)
return device;
return NULL;
}
/* /*
* Caller must perform ib_device_put() to return the device reference count * Caller must perform ib_device_put() to return the device reference count
* when ib_device_get_by_index() returns valid device pointer. * when ib_device_get_by_index() returns valid device pointer.
...@@ -155,7 +186,7 @@ struct ib_device *ib_device_get_by_index(u32 index) ...@@ -155,7 +186,7 @@ struct ib_device *ib_device_get_by_index(u32 index)
struct ib_device *device; struct ib_device *device;
down_read(&lists_rwsem); down_read(&lists_rwsem);
device = __ib_device_get_by_index(index); device = xa_load(&devices, index);
if (device) { if (device) {
if (!ib_device_try_get(device)) if (!ib_device_try_get(device))
device = NULL; device = NULL;
...@@ -181,8 +212,9 @@ EXPORT_SYMBOL(ib_device_put); ...@@ -181,8 +212,9 @@ EXPORT_SYMBOL(ib_device_put);
static struct ib_device *__ib_device_get_by_name(const char *name) static struct ib_device *__ib_device_get_by_name(const char *name)
{ {
struct ib_device *device; struct ib_device *device;
unsigned long index;
list_for_each_entry(device, &device_list, core_list) xa_for_each (&devices, index, device)
if (!strcmp(name, dev_name(&device->dev))) if (!strcmp(name, dev_name(&device->dev)))
return device; return device;
...@@ -216,12 +248,13 @@ int ib_device_rename(struct ib_device *ibdev, const char *name) ...@@ -216,12 +248,13 @@ int ib_device_rename(struct ib_device *ibdev, const char *name)
static int alloc_name(struct ib_device *ibdev, const char *name) static int alloc_name(struct ib_device *ibdev, const char *name)
{ {
struct ib_device *device; struct ib_device *device;
unsigned long index;
struct ida inuse; struct ida inuse;
int rc; int rc;
int i; int i;
ida_init(&inuse); ida_init(&inuse);
list_for_each_entry(device, &device_list, core_list) { xa_for_each (&devices, index, device) {
char buf[IB_DEVICE_NAME_MAX]; char buf[IB_DEVICE_NAME_MAX];
if (sscanf(dev_name(&device->dev), name, &i) != 1) if (sscanf(dev_name(&device->dev), name, &i) != 1)
...@@ -256,6 +289,7 @@ static void ib_device_release(struct device *device) ...@@ -256,6 +289,7 @@ static void ib_device_release(struct device *device)
ib_security_release_port_pkey_list(dev); ib_security_release_port_pkey_list(dev);
kfree(dev->port_pkey_list); kfree(dev->port_pkey_list);
kfree(dev->port_immutable); kfree(dev->port_immutable);
xa_destroy(&dev->client_data);
kfree(dev); kfree(dev);
} }
...@@ -306,8 +340,11 @@ struct ib_device *_ib_alloc_device(size_t size) ...@@ -306,8 +340,11 @@ 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);
rwlock_init(&device->client_data_lock); /*
INIT_LIST_HEAD(&device->client_data_list); * client_data needs to be alloc because we don't want our mark to be
* destroyed if the user stores NULL in the client data.
*/
xa_init_flags(&device->client_data, XA_FLAGS_ALLOC);
INIT_LIST_HEAD(&device->port_list); INIT_LIST_HEAD(&device->port_list);
init_completion(&device->unreg_completion); init_completion(&device->unreg_completion);
...@@ -323,7 +360,7 @@ EXPORT_SYMBOL(_ib_alloc_device); ...@@ -323,7 +360,7 @@ EXPORT_SYMBOL(_ib_alloc_device);
*/ */
void ib_dealloc_device(struct ib_device *device) void ib_dealloc_device(struct ib_device *device)
{ {
WARN_ON(!list_empty(&device->client_data_list)); WARN_ON(!xa_empty(&device->client_data));
WARN_ON(refcount_read(&device->refcount)); WARN_ON(refcount_read(&device->refcount));
rdma_restrack_clean(device); rdma_restrack_clean(device);
put_device(&device->dev); put_device(&device->dev);
...@@ -332,26 +369,20 @@ EXPORT_SYMBOL(ib_dealloc_device); ...@@ -332,26 +369,20 @@ EXPORT_SYMBOL(ib_dealloc_device);
static int add_client_context(struct ib_device *device, struct ib_client *client) static int add_client_context(struct ib_device *device, struct ib_client *client)
{ {
struct ib_client_data *context; void *entry;
if (!device->kverbs_provider && !client->no_kverbs_req) if (!device->kverbs_provider && !client->no_kverbs_req)
return -EOPNOTSUPP; return -EOPNOTSUPP;
context = kmalloc(sizeof(*context), GFP_KERNEL);
if (!context)
return -ENOMEM;
context->client = client;
context->data = NULL;
context->going_down = false;
down_write(&lists_rwsem); down_write(&lists_rwsem);
write_lock_irq(&device->client_data_lock); entry = xa_store(&device->client_data, client->client_id, NULL,
list_add(&context->list, &device->client_data_list); GFP_KERNEL);
write_unlock_irq(&device->client_data_lock); if (!xa_is_err(entry))
xa_set_mark(&device->client_data, client->client_id,
CLIENT_DATA_REGISTERED);
up_write(&lists_rwsem); up_write(&lists_rwsem);
return 0; return xa_err(entry);
} }
static int verify_immutable(const struct ib_device *dev, u8 port) static int verify_immutable(const struct ib_device *dev, u8 port)
...@@ -428,9 +459,10 @@ static int setup_port_pkey_list(struct ib_device *device) ...@@ -428,9 +459,10 @@ static int setup_port_pkey_list(struct ib_device *device)
static void ib_policy_change_task(struct work_struct *work) static void ib_policy_change_task(struct work_struct *work)
{ {
struct ib_device *dev; struct ib_device *dev;
unsigned long index;
down_read(&lists_rwsem); down_read(&lists_rwsem);
list_for_each_entry(dev, &device_list, core_list) { xa_for_each_marked (&devices, index, dev, DEVICE_REGISTERED) {
int i; int i;
for (i = rdma_start_port(dev); i <= rdma_end_port(dev); i++) { for (i = rdma_start_port(dev); i <= rdma_end_port(dev); i++) {
...@@ -461,28 +493,48 @@ static int ib_security_change(struct notifier_block *nb, unsigned long event, ...@@ -461,28 +493,48 @@ static int ib_security_change(struct notifier_block *nb, unsigned long event,
return NOTIFY_OK; return NOTIFY_OK;
} }
/** /*
* __dev_new_index - allocate an device index * Assign the unique string device name and the unique device index.
*
* Returns a suitable unique value for a new device interface
* number. It assumes that there are less than 2^32-1 ib devices
* will be present in the system.
*/ */
static u32 __dev_new_index(void) static int assign_name(struct ib_device *device, const char *name)
{ {
/* static u32 last_id;
* The device index to allow stable naming. int ret;
* Similar to struct net -> ifindex.
*/
static u32 index;
for (;;) { /* Assign a unique name to the device */
if (!(++index)) if (strchr(name, '%'))
index = 1; ret = alloc_name(device, name);
else
ret = dev_set_name(&device->dev, name);
if (ret)
goto out;
if (__ib_device_get_by_name(dev_name(&device->dev))) {
ret = -ENFILE;
goto out;
}
strlcpy(device->name, dev_name(&device->dev), IB_DEVICE_NAME_MAX);
if (!__ib_device_get_by_index(index)) /* Cyclically allocate a user visible ID for the device */
return index; device->index = last_id;
ret = xa_alloc(&devices, &device->index, INT_MAX, device, GFP_KERNEL);
if (ret == -ENOSPC) {
device->index = 0;
ret = xa_alloc(&devices, &device->index, INT_MAX, device,
GFP_KERNEL);
} }
if (ret)
goto out;
last_id = device->index + 1;
ret = 0;
out:
return ret;
}
static void release_name(struct ib_device *device)
{
xa_erase(&devices, device->index);
} }
static void setup_dma_device(struct ib_device *device) static void setup_dma_device(struct ib_device *device)
...@@ -572,34 +624,21 @@ int ib_register_device(struct ib_device *device, const char *name) ...@@ -572,34 +624,21 @@ int ib_register_device(struct ib_device *device, const char *name)
mutex_lock(&device_mutex); mutex_lock(&device_mutex);
if (strchr(name, '%')) { ret = assign_name(device, name);
ret = alloc_name(device, name); if (ret)
if (ret)
goto out;
} else {
ret = dev_set_name(&device->dev, name);
if (ret)
goto out;
}
if (__ib_device_get_by_name(dev_name(&device->dev))) {
ret = -ENFILE;
goto out; goto out;
}
strlcpy(device->name, dev_name(&device->dev), IB_DEVICE_NAME_MAX);
ret = setup_device(device); ret = setup_device(device);
if (ret) if (ret)
goto out; goto out_name;
ret = ib_cache_setup_one(device); ret = ib_cache_setup_one(device);
if (ret) { if (ret) {
dev_warn(&device->dev, dev_warn(&device->dev,
"Couldn't set up InfiniBand P_Key/GID cache\n"); "Couldn't set up InfiniBand P_Key/GID cache\n");
goto out; goto out_name;
} }
device->index = __dev_new_index();
ib_device_register_rdmacg(device); ib_device_register_rdmacg(device);
ret = ib_device_register_sysfs(device); ret = ib_device_register_sysfs(device);
...@@ -616,7 +655,7 @@ int ib_register_device(struct ib_device *device, const char *name) ...@@ -616,7 +655,7 @@ int ib_register_device(struct ib_device *device, const char *name)
client->add(device); client->add(device);
down_write(&lists_rwsem); down_write(&lists_rwsem);
list_add_tail(&device->core_list, &device_list); xa_set_mark(&devices, device->index, DEVICE_REGISTERED);
up_write(&lists_rwsem); up_write(&lists_rwsem);
mutex_unlock(&device_mutex); mutex_unlock(&device_mutex);
return 0; return 0;
...@@ -624,6 +663,8 @@ int ib_register_device(struct ib_device *device, const char *name) ...@@ -624,6 +663,8 @@ int ib_register_device(struct ib_device *device, const char *name)
cg_cleanup: cg_cleanup:
ib_device_unregister_rdmacg(device); ib_device_unregister_rdmacg(device);
ib_cache_cleanup_one(device); ib_cache_cleanup_one(device);
out_name:
release_name(device);
out: out:
mutex_unlock(&device_mutex); mutex_unlock(&device_mutex);
return ret; return ret;
...@@ -638,8 +679,8 @@ EXPORT_SYMBOL(ib_register_device); ...@@ -638,8 +679,8 @@ EXPORT_SYMBOL(ib_register_device);
*/ */
void ib_unregister_device(struct ib_device *device) void ib_unregister_device(struct ib_device *device)
{ {
struct ib_client_data *context, *tmp; struct ib_client *client;
unsigned long flags; unsigned long index;
/* /*
* Wait for all netlink command callers to finish working on the * Wait for all netlink command callers to finish working on the
...@@ -651,34 +692,31 @@ void ib_unregister_device(struct ib_device *device) ...@@ -651,34 +692,31 @@ void ib_unregister_device(struct ib_device *device)
mutex_lock(&device_mutex); mutex_lock(&device_mutex);
down_write(&lists_rwsem); down_write(&lists_rwsem);
list_del(&device->core_list); xa_clear_mark(&devices, device->index, DEVICE_REGISTERED);
write_lock_irq(&device->client_data_lock); xa_for_each (&clients, index, client)
list_for_each_entry(context, &device->client_data_list, list) xa_clear_mark(&device->client_data, index,
context->going_down = true; CLIENT_DATA_REGISTERED);
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_reverse(client, &client_list, list)
if (context->client->remove) if (xa_get_mark(&device->client_data, client->client_id,
context->client->remove(device, context->data); CLIENT_DATA_REGISTERED) &&
} client->remove)
client->remove(device, xa_load(&device->client_data,
client->client_id));
up_read(&lists_rwsem); up_read(&lists_rwsem);
ib_device_unregister_sysfs(device); ib_device_unregister_sysfs(device);
ib_device_unregister_rdmacg(device); ib_device_unregister_rdmacg(device);
release_name(device);
mutex_unlock(&device_mutex); mutex_unlock(&device_mutex);
ib_cache_cleanup_one(device); ib_cache_cleanup_one(device);
down_write(&lists_rwsem); down_write(&lists_rwsem);
write_lock_irqsave(&device->client_data_lock, flags); xa_destroy(&device->client_data);
list_for_each_entry_safe(context, tmp, &device->client_data_list,
list) {
list_del(&context->list);
kfree(context);
}
write_unlock_irqrestore(&device->client_data_lock, flags);
up_write(&lists_rwsem); up_write(&lists_rwsem);
} }
EXPORT_SYMBOL(ib_unregister_device); EXPORT_SYMBOL(ib_unregister_device);
...@@ -725,6 +763,7 @@ static int assign_client_id(struct ib_client *client) ...@@ -725,6 +763,7 @@ static int assign_client_id(struct ib_client *client)
int ib_register_client(struct ib_client *client) int ib_register_client(struct ib_client *client)
{ {
struct ib_device *device; struct ib_device *device;
unsigned long index;
int ret; int ret;
mutex_lock(&device_mutex); mutex_lock(&device_mutex);
...@@ -734,7 +773,7 @@ int ib_register_client(struct ib_client *client) ...@@ -734,7 +773,7 @@ int ib_register_client(struct ib_client *client)
return ret; return ret;
} }
list_for_each_entry(device, &device_list, core_list) xa_for_each_marked (&devices, index, device, DEVICE_REGISTERED)
if (!add_client_context(device, client) && client->add) if (!add_client_context(device, client) && client->add)
client->add(device); client->add(device);
...@@ -758,8 +797,8 @@ EXPORT_SYMBOL(ib_register_client); ...@@ -758,8 +797,8 @@ EXPORT_SYMBOL(ib_register_client);
*/ */
void ib_unregister_client(struct ib_client *client) void ib_unregister_client(struct ib_client *client)
{ {
struct ib_client_data *context;
struct ib_device *device; struct ib_device *device;
unsigned long index;
mutex_lock(&device_mutex); mutex_lock(&device_mutex);
...@@ -767,37 +806,19 @@ void ib_unregister_client(struct ib_client *client) ...@@ -767,37 +806,19 @@ void ib_unregister_client(struct ib_client *client)
xa_clear_mark(&clients, client->client_id, CLIENT_REGISTERED); xa_clear_mark(&clients, client->client_id, CLIENT_REGISTERED);
up_write(&lists_rwsem); up_write(&lists_rwsem);
list_for_each_entry(device, &device_list, core_list) { xa_for_each_marked (&devices, index, device, DEVICE_REGISTERED) {
struct ib_client_data *found_context = NULL;
down_write(&lists_rwsem); down_write(&lists_rwsem);
write_lock_irq(&device->client_data_lock); xa_clear_mark(&device->client_data, client->client_id,
list_for_each_entry(context, &device->client_data_list, list) CLIENT_DATA_REGISTERED);
if (context->client == client) {
context->going_down = true;
found_context = context;
break;
}
write_unlock_irq(&device->client_data_lock);
up_write(&lists_rwsem); up_write(&lists_rwsem);
if (client->remove) if (client->remove)
client->remove(device, found_context ? client->remove(device, xa_load(&device->client_data,
found_context->data : NULL); client->client_id));
if (!found_context) {
dev_warn(&device->dev,
"No client context found for %s\n",
client->name);
continue;
}
down_write(&lists_rwsem); down_write(&lists_rwsem);
write_lock_irq(&device->client_data_lock); xa_erase(&device->client_data, client->client_id);
list_del(&found_context->list);
write_unlock_irq(&device->client_data_lock);
up_write(&lists_rwsem); up_write(&lists_rwsem);
kfree(found_context);
} }
down_write(&lists_rwsem); down_write(&lists_rwsem);
...@@ -808,59 +829,28 @@ void ib_unregister_client(struct ib_client *client) ...@@ -808,59 +829,28 @@ void ib_unregister_client(struct ib_client *client)
} }
EXPORT_SYMBOL(ib_unregister_client); EXPORT_SYMBOL(ib_unregister_client);
/**
* ib_get_client_data - Get IB client context
* @device:Device to get context for
* @client:Client to get context for
*
* ib_get_client_data() returns client context set with
* ib_set_client_data().
*/
void *ib_get_client_data(struct ib_device *device, struct ib_client *client)
{
struct ib_client_data *context;
void *ret = NULL;
unsigned long flags;
read_lock_irqsave(&device->client_data_lock, flags);
list_for_each_entry(context, &device->client_data_list, list)
if (context->client == client) {
ret = context->data;
break;
}
read_unlock_irqrestore(&device->client_data_lock, flags);
return ret;
}
EXPORT_SYMBOL(ib_get_client_data);
/** /**
* ib_set_client_data - Set IB client context * ib_set_client_data - Set IB client context
* @device:Device to set context for * @device:Device to set context for
* @client:Client to set context for * @client:Client to set context for
* @data:Context to set * @data:Context to set
* *
* ib_set_client_data() sets client context that can be retrieved with * ib_set_client_data() sets client context data that can be retrieved with
* ib_get_client_data(). * ib_get_client_data(). This can only be called while the client is
* registered to the device, once the ib_client remove() callback returns this
* cannot be called.
*/ */
void ib_set_client_data(struct ib_device *device, struct ib_client *client, void ib_set_client_data(struct ib_device *device, struct ib_client *client,
void *data) void *data)
{ {
struct ib_client_data *context; void *rc;
unsigned long flags;
write_lock_irqsave(&device->client_data_lock, flags);
list_for_each_entry(context, &device->client_data_list, list)
if (context->client == client) {
context->data = data;
goto out;
}
dev_warn(&device->dev, "No client context found for %s\n", if (WARN_ON(IS_ERR(data)))
client->name); data = NULL;
out: rc = xa_store(&device->client_data, client->client_id, data,
write_unlock_irqrestore(&device->client_data_lock, flags); GFP_KERNEL);
WARN_ON(xa_is_err(rc));
} }
EXPORT_SYMBOL(ib_set_client_data); EXPORT_SYMBOL(ib_set_client_data);
...@@ -1018,9 +1008,10 @@ void ib_enum_all_roce_netdevs(roce_netdev_filter filter, ...@@ -1018,9 +1008,10 @@ void ib_enum_all_roce_netdevs(roce_netdev_filter filter,
void *cookie) void *cookie)
{ {
struct ib_device *dev; struct ib_device *dev;
unsigned long index;
down_read(&lists_rwsem); down_read(&lists_rwsem);
list_for_each_entry(dev, &device_list, core_list) xa_for_each_marked (&devices, index, dev, DEVICE_REGISTERED)
ib_enum_roce_netdev(dev, filter, filter_cookie, cb, cookie); ib_enum_roce_netdev(dev, filter, filter_cookie, cb, cookie);
up_read(&lists_rwsem); up_read(&lists_rwsem);
} }
...@@ -1034,12 +1025,13 @@ void ib_enum_all_roce_netdevs(roce_netdev_filter filter, ...@@ -1034,12 +1025,13 @@ void ib_enum_all_roce_netdevs(roce_netdev_filter filter,
int ib_enum_all_devs(nldev_callback nldev_cb, struct sk_buff *skb, int ib_enum_all_devs(nldev_callback nldev_cb, struct sk_buff *skb,
struct netlink_callback *cb) struct netlink_callback *cb)
{ {
unsigned long index;
struct ib_device *dev; struct ib_device *dev;
unsigned int idx = 0; unsigned int idx = 0;
int ret = 0; int ret = 0;
down_read(&lists_rwsem); down_read(&lists_rwsem);
list_for_each_entry(dev, &device_list, core_list) { xa_for_each_marked (&devices, index, dev, DEVICE_REGISTERED) {
ret = nldev_cb(dev, skb, cb, idx); ret = nldev_cb(dev, skb, cb, idx);
if (ret) if (ret)
break; break;
...@@ -1212,26 +1204,25 @@ struct net_device *ib_get_net_dev_by_params(struct ib_device *dev, ...@@ -1212,26 +1204,25 @@ struct net_device *ib_get_net_dev_by_params(struct ib_device *dev,
const struct sockaddr *addr) const struct sockaddr *addr)
{ {
struct net_device *net_dev = NULL; struct net_device *net_dev = NULL;
struct ib_client_data *context; unsigned long index;
void *client_data;
if (!rdma_protocol_ib(dev, port)) if (!rdma_protocol_ib(dev, port))
return NULL; return NULL;
down_read(&lists_rwsem); down_read(&lists_rwsem);
list_for_each_entry(context, &dev->client_data_list, list) { xan_for_each_marked (&dev->client_data, index, client_data,
struct ib_client *client = context->client; CLIENT_DATA_REGISTERED) {
struct ib_client *client = xa_load(&clients, index);
if (context->going_down) if (!client || !client->get_net_dev_by_params)
continue; continue;
if (client->get_net_dev_by_params) { net_dev = client->get_net_dev_by_params(dev, port, pkey, gid,
net_dev = client->get_net_dev_by_params(dev, port, pkey, addr, client_data);
gid, addr, if (net_dev)
context->data); break;
if (net_dev)
break;
}
} }
up_read(&lists_rwsem); up_read(&lists_rwsem);
...@@ -1462,6 +1453,7 @@ static void __exit ib_core_cleanup(void) ...@@ -1462,6 +1453,7 @@ static void __exit ib_core_cleanup(void)
/* Make sure that any pending umem accounting work is done. */ /* Make sure that any pending umem accounting work is done. */
destroy_workqueue(ib_wq); destroy_workqueue(ib_wq);
WARN_ON(!xa_empty(&clients)); WARN_ON(!xa_empty(&clients));
WARN_ON(!xa_empty(&devices));
} }
MODULE_ALIAS_RDMA_NETLINK(RDMA_NL_LS, 4); MODULE_ALIAS_RDMA_NETLINK(RDMA_NL_LS, 4);
......
...@@ -2542,12 +2542,7 @@ struct ib_device { ...@@ -2542,12 +2542,7 @@ 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;
rwlock_t client_data_lock; struct xarray client_data;
struct list_head core_list;
/* Access to the client_data_list is protected by the client_data_lock
* rwlock and the lists_rwsem read-write semaphore
*/
struct list_head client_data_list;
struct ib_cache cache; struct ib_cache cache;
/** /**
...@@ -2660,7 +2655,21 @@ void ib_unregister_device(struct ib_device *device); ...@@ -2660,7 +2655,21 @@ void ib_unregister_device(struct ib_device *device);
int ib_register_client (struct ib_client *client); int ib_register_client (struct ib_client *client);
void ib_unregister_client(struct ib_client *client); void ib_unregister_client(struct ib_client *client);
void *ib_get_client_data(struct ib_device *device, struct ib_client *client); /**
* ib_get_client_data - Get IB client context
* @device:Device to get context for
* @client:Client to get context for
*
* ib_get_client_data() returns the client context data set with
* ib_set_client_data(). This can only be called while the client is
* registered to the device, once the ib_client remove() callback returns this
* cannot be called.
*/
static inline void *ib_get_client_data(struct ib_device *device,
struct ib_client *client)
{
return xa_load(&device->client_data, client->client_id);
}
void ib_set_client_data(struct ib_device *device, struct ib_client *client, void ib_set_client_data(struct ib_device *device, struct ib_client *client,
void *data); void *data);
void ib_set_device_ops(struct ib_device *device, void ib_set_device_ops(struct ib_device *device,
......
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