Skip to content

Commit 1f893f5

Browse files
shayshyiSaeed Mahameed
authored andcommitted
net/mlx5: Devcom, serialize devcom registration
From one hand, mlx5 driver is allowing to probe PFs in parallel. From the other hand, devcom, which is a share resource between PFs, is registered without any lock. This might resulted in memory problems. Hence, use the global mlx5_dev_list_lock in order to serialize devcom registration. Fixes: fadd59f ("net/mlx5: Introduce inter-device communication mechanism") Signed-off-by: Shay Drory <[email protected]> Reviewed-by: Mark Bloch <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent af87194 commit 1f893f5

File tree

1 file changed

+14
-5
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core/lib

1 file changed

+14
-5
lines changed

drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <linux/mlx5/vport.h>
55
#include "lib/devcom.h"
6+
#include "mlx5_core.h"
67

78
static LIST_HEAD(devcom_list);
89

@@ -77,6 +78,7 @@ struct mlx5_devcom *mlx5_devcom_register_device(struct mlx5_core_dev *dev)
7778
if (MLX5_CAP_GEN(dev, num_lag_ports) != MLX5_DEVCOM_PORTS_SUPPORTED)
7879
return NULL;
7980

81+
mlx5_dev_list_lock();
8082
sguid0 = mlx5_query_nic_system_image_guid(dev);
8183
list_for_each_entry(iter, &devcom_list, list) {
8284
struct mlx5_core_dev *tmp_dev = NULL;
@@ -102,8 +104,10 @@ struct mlx5_devcom *mlx5_devcom_register_device(struct mlx5_core_dev *dev)
102104

103105
if (!priv) {
104106
priv = mlx5_devcom_list_alloc();
105-
if (!priv)
106-
return ERR_PTR(-ENOMEM);
107+
if (!priv) {
108+
devcom = ERR_PTR(-ENOMEM);
109+
goto out;
110+
}
107111

108112
idx = 0;
109113
new_priv = true;
@@ -114,12 +118,14 @@ struct mlx5_devcom *mlx5_devcom_register_device(struct mlx5_core_dev *dev)
114118
if (!devcom) {
115119
if (new_priv)
116120
kfree(priv);
117-
return ERR_PTR(-ENOMEM);
121+
devcom = ERR_PTR(-ENOMEM);
122+
goto out;
118123
}
119124

120125
if (new_priv)
121126
list_add(&priv->list, &devcom_list);
122-
127+
out:
128+
mlx5_dev_list_unlock();
123129
return devcom;
124130
}
125131

@@ -132,6 +138,7 @@ void mlx5_devcom_unregister_device(struct mlx5_devcom *devcom)
132138
if (IS_ERR_OR_NULL(devcom))
133139
return;
134140

141+
mlx5_dev_list_lock();
135142
priv = devcom->priv;
136143
priv->devs[devcom->idx] = NULL;
137144

@@ -142,10 +149,12 @@ void mlx5_devcom_unregister_device(struct mlx5_devcom *devcom)
142149
break;
143150

144151
if (i != MLX5_DEVCOM_PORTS_SUPPORTED)
145-
return;
152+
goto out;
146153

147154
list_del(&priv->list);
148155
kfree(priv);
156+
out:
157+
mlx5_dev_list_unlock();
149158
}
150159

151160
void mlx5_devcom_register_component(struct mlx5_devcom *devcom,

0 commit comments

Comments
 (0)