Skip to content

Commit 2372bcd

Browse files
committed
Merge branch 'mlx4-queue-reinit'
Martin KaFai Lau says: ==================== mlx4: Misc bug fixes after reinitializing queues This patchset fixes misc bugs after reinitializing queues (e.g. by ethtool -L). v2: * Add another fix to mem leak in tx_ring[t] and tx_cq[t] * In mlx4_en_try_alloc_resources(), move all xdp_prog logic after calling mlx4_en_alloc_resources() ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 6d04dfc + 770f822 commit 2372bcd

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

drivers/net/ethernet/mellanox/mlx4/en_ethtool.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ static int mlx4_en_set_ringparam(struct net_device *dev,
10991099
memcpy(&new_prof, priv->prof, sizeof(struct mlx4_en_port_profile));
11001100
new_prof.tx_ring_size = tx_size;
11011101
new_prof.rx_ring_size = rx_size;
1102-
err = mlx4_en_try_alloc_resources(priv, tmp, &new_prof);
1102+
err = mlx4_en_try_alloc_resources(priv, tmp, &new_prof, true);
11031103
if (err)
11041104
goto out;
11051105

@@ -1774,7 +1774,7 @@ static int mlx4_en_set_channels(struct net_device *dev,
17741774
new_prof.tx_ring_num[TX_XDP] = xdp_count;
17751775
new_prof.rx_ring_num = channel->rx_count;
17761776

1777-
err = mlx4_en_try_alloc_resources(priv, tmp, &new_prof);
1777+
err = mlx4_en_try_alloc_resources(priv, tmp, &new_prof, true);
17781778
if (err)
17791779
goto out;
17801780

drivers/net/ethernet/mellanox/mlx4/en_netdev.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,8 @@ static void mlx4_en_free_resources(struct mlx4_en_priv *priv)
20422042
if (priv->tx_cq[t] && priv->tx_cq[t][i])
20432043
mlx4_en_destroy_cq(priv, &priv->tx_cq[t][i]);
20442044
}
2045+
kfree(priv->tx_ring[t]);
2046+
kfree(priv->tx_cq[t]);
20452047
}
20462048

20472049
for (i = 0; i < priv->rx_ring_num; i++) {
@@ -2184,9 +2186,11 @@ static void mlx4_en_update_priv(struct mlx4_en_priv *dst,
21842186

21852187
int mlx4_en_try_alloc_resources(struct mlx4_en_priv *priv,
21862188
struct mlx4_en_priv *tmp,
2187-
struct mlx4_en_port_profile *prof)
2189+
struct mlx4_en_port_profile *prof,
2190+
bool carry_xdp_prog)
21882191
{
2189-
int t;
2192+
struct bpf_prog *xdp_prog;
2193+
int i, t;
21902194

21912195
mlx4_en_copy_priv(tmp, priv, prof);
21922196

@@ -2200,6 +2204,23 @@ int mlx4_en_try_alloc_resources(struct mlx4_en_priv *priv,
22002204
}
22012205
return -ENOMEM;
22022206
}
2207+
2208+
/* All rx_rings has the same xdp_prog. Pick the first one. */
2209+
xdp_prog = rcu_dereference_protected(
2210+
priv->rx_ring[0]->xdp_prog,
2211+
lockdep_is_held(&priv->mdev->state_lock));
2212+
2213+
if (xdp_prog && carry_xdp_prog) {
2214+
xdp_prog = bpf_prog_add(xdp_prog, tmp->rx_ring_num);
2215+
if (IS_ERR(xdp_prog)) {
2216+
mlx4_en_free_resources(tmp);
2217+
return PTR_ERR(xdp_prog);
2218+
}
2219+
for (i = 0; i < tmp->rx_ring_num; i++)
2220+
rcu_assign_pointer(tmp->rx_ring[i]->xdp_prog,
2221+
xdp_prog);
2222+
}
2223+
22032224
return 0;
22042225
}
22052226

@@ -2214,7 +2235,6 @@ void mlx4_en_destroy_netdev(struct net_device *dev)
22142235
{
22152236
struct mlx4_en_priv *priv = netdev_priv(dev);
22162237
struct mlx4_en_dev *mdev = priv->mdev;
2217-
int t;
22182238

22192239
en_dbg(DRV, priv, "Destroying netdev on port:%d\n", priv->port);
22202240

@@ -2248,11 +2268,6 @@ void mlx4_en_destroy_netdev(struct net_device *dev)
22482268
mlx4_en_free_resources(priv);
22492269
mutex_unlock(&mdev->state_lock);
22502270

2251-
for (t = 0; t < MLX4_EN_NUM_TX_TYPES; t++) {
2252-
kfree(priv->tx_ring[t]);
2253-
kfree(priv->tx_cq[t]);
2254-
}
2255-
22562271
free_netdev(dev);
22572272
}
22582273

@@ -2755,7 +2770,7 @@ static int mlx4_xdp_set(struct net_device *dev, struct bpf_prog *prog)
27552770
en_warn(priv, "Reducing the number of TX rings, to not exceed the max total rings number.\n");
27562771
}
27572772

2758-
err = mlx4_en_try_alloc_resources(priv, tmp, &new_prof);
2773+
err = mlx4_en_try_alloc_resources(priv, tmp, &new_prof, false);
27592774
if (err) {
27602775
if (prog)
27612776
bpf_prog_sub(prog, priv->rx_ring_num - 1);
@@ -3499,7 +3514,7 @@ int mlx4_en_reset_config(struct net_device *dev,
34993514
memcpy(&new_prof, priv->prof, sizeof(struct mlx4_en_port_profile));
35003515
memcpy(&new_prof.hwtstamp_config, &ts_config, sizeof(ts_config));
35013516

3502-
err = mlx4_en_try_alloc_resources(priv, tmp, &new_prof);
3517+
err = mlx4_en_try_alloc_resources(priv, tmp, &new_prof, true);
35033518
if (err)
35043519
goto out;
35053520

drivers/net/ethernet/mellanox/mlx4/mlx4_en.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,8 @@ void mlx4_en_set_stats_bitmap(struct mlx4_dev *dev,
679679

680680
int mlx4_en_try_alloc_resources(struct mlx4_en_priv *priv,
681681
struct mlx4_en_priv *tmp,
682-
struct mlx4_en_port_profile *prof);
682+
struct mlx4_en_port_profile *prof,
683+
bool carry_xdp_prog);
683684
void mlx4_en_safe_replace_resources(struct mlx4_en_priv *priv,
684685
struct mlx4_en_priv *tmp);
685686

0 commit comments

Comments
 (0)