Skip to content

Commit 4dfd532

Browse files
Matthew Wilcoxjgunthorpe
authored andcommitted
ucma: Convert multicast_idr to XArray
Signed-off-by: Matthew Wilcox <willy@infradead.org> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent 9bcb894 commit 4dfd532

1 file changed

Lines changed: 11 additions & 19 deletions

File tree

‎drivers/infiniband/core/ucma.c‎

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ struct ucma_context {
104104

105105
struct ucma_multicast {
106106
struct ucma_context *ctx;
107-
int id;
107+
u32 id;
108108
int events_reported;
109109

110110
u64 uid;
@@ -124,7 +124,7 @@ struct ucma_event {
124124

125125
static DEFINE_MUTEX(mut);
126126
static DEFINE_IDR(ctx_idr);
127-
static DEFINE_IDR(multicast_idr);
127+
static DEFINE_XARRAY_ALLOC(multicast_table);
128128

129129
static const struct file_operations ucma_fops;
130130

@@ -238,13 +238,10 @@ static struct ucma_multicast* ucma_alloc_multicast(struct ucma_context *ctx)
238238
if (!mc)
239239
return NULL;
240240

241-
mutex_lock(&mut);
242-
mc->id = idr_alloc(&multicast_idr, NULL, 0, 0, GFP_KERNEL);
243-
mutex_unlock(&mut);
244-
if (mc->id < 0)
241+
mc->ctx = ctx;
242+
if (xa_alloc(&multicast_table, &mc->id, NULL, xa_limit_32b, GFP_KERNEL))
245243
goto error;
246244

247-
mc->ctx = ctx;
248245
list_add_tail(&mc->list, &ctx->mc_list);
249246
return mc;
250247

@@ -540,7 +537,7 @@ static void ucma_cleanup_multicast(struct ucma_context *ctx)
540537
mutex_lock(&mut);
541538
list_for_each_entry_safe(mc, tmp, &ctx->mc_list, list) {
542539
list_del(&mc->list);
543-
idr_remove(&multicast_idr, mc->id);
540+
xa_erase(&multicast_table, mc->id);
544541
kfree(mc);
545542
}
546543
mutex_unlock(&mut);
@@ -1431,9 +1428,7 @@ static ssize_t ucma_process_join(struct ucma_file *file,
14311428
goto err3;
14321429
}
14331430

1434-
mutex_lock(&mut);
1435-
idr_replace(&multicast_idr, mc, mc->id);
1436-
mutex_unlock(&mut);
1431+
xa_store(&multicast_table, mc->id, mc, 0);
14371432

14381433
mutex_unlock(&file->mut);
14391434
ucma_put_ctx(ctx);
@@ -1443,9 +1438,7 @@ static ssize_t ucma_process_join(struct ucma_file *file,
14431438
rdma_leave_multicast(ctx->cm_id, (struct sockaddr *) &mc->addr);
14441439
ucma_cleanup_mc_events(mc);
14451440
err2:
1446-
mutex_lock(&mut);
1447-
idr_remove(&multicast_idr, mc->id);
1448-
mutex_unlock(&mut);
1441+
xa_erase(&multicast_table, mc->id);
14491442
list_del(&mc->list);
14501443
kfree(mc);
14511444
err1:
@@ -1507,17 +1500,17 @@ static ssize_t ucma_leave_multicast(struct ucma_file *file,
15071500
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
15081501
return -EFAULT;
15091502

1510-
mutex_lock(&mut);
1511-
mc = idr_find(&multicast_idr, cmd.id);
1503+
xa_lock(&multicast_table);
1504+
mc = xa_load(&multicast_table, cmd.id);
15121505
if (!mc)
15131506
mc = ERR_PTR(-ENOENT);
15141507
else if (mc->ctx->file != file)
15151508
mc = ERR_PTR(-EINVAL);
15161509
else if (!atomic_inc_not_zero(&mc->ctx->ref))
15171510
mc = ERR_PTR(-ENXIO);
15181511
else
1519-
idr_remove(&multicast_idr, mc->id);
1520-
mutex_unlock(&mut);
1512+
__xa_erase(&multicast_table, mc->id);
1513+
xa_unlock(&multicast_table);
15211514

15221515
if (IS_ERR(mc)) {
15231516
ret = PTR_ERR(mc);
@@ -1846,7 +1839,6 @@ static void __exit ucma_cleanup(void)
18461839
device_remove_file(ucma_misc.this_device, &dev_attr_abi_version);
18471840
misc_deregister(&ucma_misc);
18481841
idr_destroy(&ctx_idr);
1849-
idr_destroy(&multicast_idr);
18501842
}
18511843

18521844
module_init(ucma_init);

0 commit comments

Comments
 (0)