Skip to content

Commit 7416790

Browse files
paravmellanoxjgunthorpe
authored andcommitted
RDMA/core: Introduce and use API to read port immutable data
Currently mlx5 driver caches port GID table length for 2 ports. It is also cached by IB core as port immutable data. When mlx5 representor ports are present, which are usually more than 2, invalid access to port_caps array can happen while validating the GID table length which is only for 2 ports. To avoid this, take help of the IB cores port immutable data by exposing an API to read the port immutable fields. Remove mlx5 driver's internal cache, thereby reduce code and data. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Parav Pandit <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 7a58779 commit 7416790

File tree

5 files changed

+23
-58
lines changed

5 files changed

+23
-58
lines changed

drivers/infiniband/core/device.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,20 @@ static int setup_port_data(struct ib_device *device)
848848
return 0;
849849
}
850850

851+
/**
852+
* ib_port_immutable_read() - Read rdma port's immutable data
853+
* @dev - IB device
854+
* @port - port number whose immutable data to read. It starts with index 1 and
855+
* valid upto including rdma_end_port().
856+
*/
857+
const struct ib_port_immutable*
858+
ib_port_immutable_read(struct ib_device *dev, unsigned int port)
859+
{
860+
WARN_ON(!rdma_is_port_valid(dev, port));
861+
return &dev->port_data[port].immutable;
862+
}
863+
EXPORT_SYMBOL(ib_port_immutable_read);
864+
851865
void ib_get_device_fw_str(struct ib_device *dev, char *str)
852866
{
853867
if (dev->ops.get_dev_fw_str)

drivers/infiniband/hw/mlx5/main.c

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,41 +2964,6 @@ static void get_ext_port_caps(struct mlx5_ib_dev *dev)
29642964
mlx5_query_ext_port_caps(dev, port);
29652965
}
29662966

2967-
static int __get_port_caps(struct mlx5_ib_dev *dev, u8 port)
2968-
{
2969-
struct ib_port_attr *pprops = NULL;
2970-
int err = -ENOMEM;
2971-
2972-
pprops = kzalloc(sizeof(*pprops), GFP_KERNEL);
2973-
if (!pprops)
2974-
goto out;
2975-
2976-
err = mlx5_ib_query_port(&dev->ib_dev, port, pprops);
2977-
if (err) {
2978-
mlx5_ib_warn(dev, "query_port %d failed %d\n",
2979-
port, err);
2980-
goto out;
2981-
}
2982-
2983-
dev->port_caps[port - 1].gid_table_len = pprops->gid_tbl_len;
2984-
mlx5_ib_dbg(dev, "port %d: pkey_table_len %d, gid_table_len %d\n",
2985-
port, dev->pkey_table_len, pprops->gid_tbl_len);
2986-
2987-
out:
2988-
kfree(pprops);
2989-
return err;
2990-
}
2991-
2992-
static int get_port_caps(struct mlx5_ib_dev *dev, u8 port)
2993-
{
2994-
/* For representors use port 1, is this is the only native
2995-
* port
2996-
*/
2997-
if (dev->is_rep)
2998-
return __get_port_caps(dev, 1);
2999-
return __get_port_caps(dev, port);
3000-
}
3001-
30022967
static u8 mlx5_get_umr_fence(u8 umr_fence_cap)
30032968
{
30042969
switch (umr_fence_cap) {
@@ -3472,10 +3437,6 @@ static bool mlx5_ib_bind_slave_port(struct mlx5_ib_dev *ibdev,
34723437
if (err)
34733438
goto unbind;
34743439

3475-
err = get_port_caps(ibdev, mlx5_core_native_port_num(mpi->mdev));
3476-
if (err)
3477-
goto unbind;
3478-
34793440
err = mlx5_add_netdev_notifier(ibdev, port_num);
34803441
if (err) {
34813442
mlx5_ib_err(ibdev, "failed adding netdev notifier for port %u\n",
@@ -3553,11 +3514,9 @@ static int mlx5_ib_init_multiport_master(struct mlx5_ib_dev *dev)
35533514
break;
35543515
}
35553516
}
3556-
if (!bound) {
3557-
get_port_caps(dev, i + 1);
3517+
if (!bound)
35583518
mlx5_ib_dbg(dev, "no free port found for port %d\n",
35593519
i + 1);
3560-
}
35613520
}
35623521

35633522
list_add_tail(&dev->ib_dev_list, &mlx5_ib_dev_list);
@@ -3940,18 +3899,6 @@ static int mlx5_ib_stage_init_init(struct mlx5_ib_dev *dev)
39403899
if (err)
39413900
goto err_mp;
39423901

3943-
if (!mlx5_core_mp_enabled(mdev)) {
3944-
for (i = 1; i <= dev->num_ports; i++) {
3945-
err = get_port_caps(dev, i);
3946-
if (err)
3947-
break;
3948-
}
3949-
} else {
3950-
err = get_port_caps(dev, mlx5_core_native_port_num(mdev));
3951-
}
3952-
if (err)
3953-
goto err_mp;
3954-
39553902
err = mlx5_query_max_pkeys(&dev->ib_dev, &dev->pkey_table_len);
39563903
if (err)
39573904
goto err_mp;

drivers/infiniband/hw/mlx5/mlx5_ib.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,6 @@ struct mlx5_var_table {
10371037
};
10381038

10391039
struct mlx5_port_caps {
1040-
int gid_table_len;
10411040
bool has_smi;
10421041
u8 ext_port_cap;
10431042
};

drivers/infiniband/hw/mlx5/qp.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3176,11 +3176,13 @@ static int mlx5_set_path(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp,
31763176
alt ? attr->alt_pkey_index : attr->pkey_index);
31773177

31783178
if (ah_flags & IB_AH_GRH) {
3179-
if (grh->sgid_index >=
3180-
dev->port_caps[port - 1].gid_table_len) {
3179+
const struct ib_port_immutable *immutable;
3180+
3181+
immutable = ib_port_immutable_read(&dev->ib_dev, port);
3182+
if (grh->sgid_index >= immutable->gid_tbl_len) {
31813183
pr_err("sgid_index (%u) too large. max is %d\n",
31823184
grh->sgid_index,
3183-
dev->port_caps[port - 1].gid_table_len);
3185+
immutable->gid_tbl_len);
31843186
return -EINVAL;
31853187
}
31863188
}

include/rdma/ib_verbs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4674,4 +4674,7 @@ static inline u32 rdma_calc_flow_label(u32 lqpn, u32 rqpn)
46744674

46754675
return (u32)(v & IB_GRH_FLOWLABEL_MASK);
46764676
}
4677+
4678+
const struct ib_port_immutable*
4679+
ib_port_immutable_read(struct ib_device *dev, unsigned int port);
46774680
#endif /* IB_VERBS_H */

0 commit comments

Comments
 (0)