Skip to content

Commit 8ceb135

Browse files
committed
RDMA/device: Consolidate ib_device per_port data into one place
There is no reason to have three allocations of per-port data. Combine them together and make the lifetime for all the per-port data match the struct ib_device. Following patches will require more port-specific data, now there is a good place to put it. Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent ea1075e commit 8ceb135

File tree

4 files changed

+78
-94
lines changed

4 files changed

+78
-94
lines changed

drivers/infiniband/core/cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,8 +881,8 @@ static int _gid_table_setup_one(struct ib_device *ib_dev)
881881
for (port = 0; port < ib_dev->phys_port_cnt; port++) {
882882
u8 rdma_port = port + rdma_start_port(ib_dev);
883883

884-
table = alloc_gid_table(
885-
ib_dev->port_immutable[rdma_port].gid_tbl_len);
884+
table = alloc_gid_table(
885+
ib_dev->port_data[rdma_port].immutable.gid_tbl_len);
886886
if (!table)
887887
goto rollback_table_setup;
888888

drivers/infiniband/core/device.c

Lines changed: 22 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,7 @@ static void ib_device_release(struct device *device)
293293
WARN_ON(refcount_read(&dev->refcount));
294294
ib_cache_release_one(dev);
295295
ib_security_release_port_pkey_list(dev);
296-
kfree(dev->port_pkey_list);
297-
kfree(dev->port_immutable);
296+
kfree(dev->port_data);
298297
xa_destroy(&dev->client_data);
299298
kfree(dev);
300299
}
@@ -468,27 +467,31 @@ static int verify_immutable(const struct ib_device *dev, u8 port)
468467
rdma_max_mad_size(dev, port) != 0);
469468
}
470469

471-
static int read_port_immutable(struct ib_device *device)
470+
static int setup_port_data(struct ib_device *device)
472471
{
473472
unsigned int port;
474473
int ret;
475474

476-
/**
477-
* device->port_immutable is indexed directly by the port number to make
475+
/*
476+
* device->port_data is indexed directly by the port number to make
478477
* access to this data as efficient as possible.
479478
*
480-
* Therefore port_immutable is declared as a 1 based array with
481-
* potential empty slots at the beginning.
479+
* Therefore port_data is declared as a 1 based array with potential
480+
* empty slots at the beginning.
482481
*/
483-
device->port_immutable =
484-
kcalloc(rdma_end_port(device) + 1,
485-
sizeof(*device->port_immutable), GFP_KERNEL);
486-
if (!device->port_immutable)
482+
device->port_data = kcalloc(rdma_end_port(device) + 1,
483+
sizeof(*device->port_data), GFP_KERNEL);
484+
if (!device->port_data)
487485
return -ENOMEM;
488486

489487
rdma_for_each_port (device, port) {
490-
ret = device->ops.get_port_immutable(
491-
device, port, &device->port_immutable[port]);
488+
struct ib_port_data *pdata = &device->port_data[port];
489+
490+
spin_lock_init(&pdata->pkey_list_lock);
491+
INIT_LIST_HEAD(&pdata->pkey_list);
492+
493+
ret = device->ops.get_port_immutable(device, port,
494+
&pdata->immutable);
492495
if (ret)
493496
return ret;
494497

@@ -507,30 +510,6 @@ void ib_get_device_fw_str(struct ib_device *dev, char *str)
507510
}
508511
EXPORT_SYMBOL(ib_get_device_fw_str);
509512

510-
static int setup_port_pkey_list(struct ib_device *device)
511-
{
512-
int i;
513-
514-
/**
515-
* device->port_pkey_list is indexed directly by the port number,
516-
* Therefore it is declared as a 1 based array with potential empty
517-
* slots at the beginning.
518-
*/
519-
device->port_pkey_list = kcalloc(rdma_end_port(device) + 1,
520-
sizeof(*device->port_pkey_list),
521-
GFP_KERNEL);
522-
523-
if (!device->port_pkey_list)
524-
return -ENOMEM;
525-
526-
for (i = 0; i < (rdma_end_port(device) + 1); i++) {
527-
spin_lock_init(&device->port_pkey_list[i].list_lock);
528-
INIT_LIST_HEAD(&device->port_pkey_list[i].pkey_list);
529-
}
530-
531-
return 0;
532-
}
533-
534513
static void ib_policy_change_task(struct work_struct *work)
535514
{
536515
struct ib_device *dev;
@@ -668,10 +647,9 @@ static int setup_device(struct ib_device *device)
668647
if (ret)
669648
return ret;
670649

671-
ret = read_port_immutable(device);
650+
ret = setup_port_data(device);
672651
if (ret) {
673-
dev_warn(&device->dev,
674-
"Couldn't create per port immutable data\n");
652+
dev_warn(&device->dev, "Couldn't create per-port data\n");
675653
return ret;
676654
}
677655

@@ -683,12 +661,6 @@ static int setup_device(struct ib_device *device)
683661
return ret;
684662
}
685663

686-
ret = setup_port_pkey_list(device);
687-
if (ret) {
688-
dev_warn(&device->dev, "Couldn't create per port_pkey_list\n");
689-
return ret;
690-
}
691-
692664
return 0;
693665
}
694666

@@ -1221,7 +1193,8 @@ int ib_find_gid(struct ib_device *device, union ib_gid *gid,
12211193
if (!rdma_protocol_ib(device, port))
12221194
continue;
12231195

1224-
for (i = 0; i < device->port_immutable[port].gid_tbl_len; ++i) {
1196+
for (i = 0; i < device->port_data[port].immutable.gid_tbl_len;
1197+
++i) {
12251198
ret = rdma_query_gid(device, port, i, &tmp_gid);
12261199
if (ret)
12271200
return ret;
@@ -1253,7 +1226,8 @@ int ib_find_pkey(struct ib_device *device,
12531226
u16 tmp_pkey;
12541227
int partial_ix = -1;
12551228

1256-
for (i = 0; i < device->port_immutable[port_num].pkey_tbl_len; ++i) {
1229+
for (i = 0; i < device->port_data[port_num].immutable.pkey_tbl_len;
1230+
++i) {
12571231
ret = ib_query_pkey(device, port_num, i, &tmp_pkey);
12581232
if (ret)
12591233
return ret;

drivers/infiniband/core/security.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,15 @@ static struct pkey_index_qp_list *get_pkey_idx_qp_list(struct ib_port_pkey *pp)
4949
struct pkey_index_qp_list *tmp_pkey;
5050
struct ib_device *dev = pp->sec->dev;
5151

52-
spin_lock(&dev->port_pkey_list[pp->port_num].list_lock);
53-
list_for_each_entry(tmp_pkey,
54-
&dev->port_pkey_list[pp->port_num].pkey_list,
55-
pkey_index_list) {
52+
spin_lock(&dev->port_data[pp->port_num].pkey_list_lock);
53+
list_for_each_entry (tmp_pkey, &dev->port_data[pp->port_num].pkey_list,
54+
pkey_index_list) {
5655
if (tmp_pkey->pkey_index == pp->pkey_index) {
5756
pkey = tmp_pkey;
5857
break;
5958
}
6059
}
61-
spin_unlock(&dev->port_pkey_list[pp->port_num].list_lock);
60+
spin_unlock(&dev->port_data[pp->port_num].pkey_list_lock);
6261
return pkey;
6362
}
6463

@@ -263,12 +262,12 @@ static int port_pkey_list_insert(struct ib_port_pkey *pp)
263262
if (!pkey)
264263
return -ENOMEM;
265264

266-
spin_lock(&dev->port_pkey_list[port_num].list_lock);
265+
spin_lock(&dev->port_data[port_num].pkey_list_lock);
267266
/* Check for the PKey again. A racing process may
268267
* have created it.
269268
*/
270269
list_for_each_entry(tmp_pkey,
271-
&dev->port_pkey_list[port_num].pkey_list,
270+
&dev->port_data[port_num].pkey_list,
272271
pkey_index_list) {
273272
if (tmp_pkey->pkey_index == pp->pkey_index) {
274273
kfree(pkey);
@@ -283,9 +282,9 @@ static int port_pkey_list_insert(struct ib_port_pkey *pp)
283282
spin_lock_init(&pkey->qp_list_lock);
284283
INIT_LIST_HEAD(&pkey->qp_list);
285284
list_add(&pkey->pkey_index_list,
286-
&dev->port_pkey_list[port_num].pkey_list);
285+
&dev->port_data[port_num].pkey_list);
287286
}
288-
spin_unlock(&dev->port_pkey_list[port_num].list_lock);
287+
spin_unlock(&dev->port_data[port_num].pkey_list_lock);
289288
}
290289

291290
spin_lock(&pkey->qp_list_lock);
@@ -551,9 +550,8 @@ void ib_security_cache_change(struct ib_device *device,
551550
{
552551
struct pkey_index_qp_list *pkey;
553552

554-
list_for_each_entry(pkey,
555-
&device->port_pkey_list[port_num].pkey_list,
556-
pkey_index_list) {
553+
list_for_each_entry (pkey, &device->port_data[port_num].pkey_list,
554+
pkey_index_list) {
557555
check_pkey_qps(pkey,
558556
device,
559557
port_num,
@@ -569,7 +567,7 @@ void ib_security_release_port_pkey_list(struct ib_device *device)
569567
rdma_for_each_port (device, i) {
570568
list_for_each_entry_safe(pkey,
571569
tmp_pkey,
572-
&device->port_pkey_list[i].pkey_list,
570+
&device->port_data[i].pkey_list,
573571
pkey_index_list) {
574572
list_del(&pkey->pkey_index_list);
575573
kfree(pkey);

0 commit comments

Comments
 (0)