Skip to content

Commit d460c27

Browse files
Maxim MikityanskiySaeed Mahameed
authored andcommitted
net/mlx5e: Fix the max MTU check in case of XDP
MLX5E_XDP_MAX_MTU was calculated incorrectly. It didn't account for NET_IP_ALIGN and MLX5E_HW2SW_MTU, and it also misused MLX5_SKB_FRAG_SZ. This commit fixes the calculations and adds a brief explanation for the formula used. Fixes: a26a5bd ("net/mlx5e: Restrict the combination of large MTU and XDP") Signed-off-by: Maxim Mikityanskiy <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 12fc512 commit d460c27

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@
3333
#include <linux/bpf_trace.h>
3434
#include "en/xdp.h"
3535

36+
int mlx5e_xdp_max_mtu(struct mlx5e_params *params)
37+
{
38+
int hr = NET_IP_ALIGN + XDP_PACKET_HEADROOM;
39+
40+
/* Let S := SKB_DATA_ALIGN(sizeof(struct skb_shared_info)).
41+
* The condition checked in mlx5e_rx_is_linear_skb is:
42+
* SKB_DATA_ALIGN(sw_mtu + hard_mtu + hr) + S <= PAGE_SIZE (1)
43+
* (Note that hw_mtu == sw_mtu + hard_mtu.)
44+
* What is returned from this function is:
45+
* max_mtu = PAGE_SIZE - S - hr - hard_mtu (2)
46+
* After assigning sw_mtu := max_mtu, the left side of (1) turns to
47+
* SKB_DATA_ALIGN(PAGE_SIZE - S) + S, which is equal to PAGE_SIZE,
48+
* because both PAGE_SIZE and S are already aligned. Any number greater
49+
* than max_mtu would make the left side of (1) greater than PAGE_SIZE,
50+
* so max_mtu is the maximum MTU allowed.
51+
*/
52+
53+
return MLX5E_HW2SW_MTU(params, SKB_MAX_HEAD(hr));
54+
}
55+
3656
static inline bool
3757
mlx5e_xmit_xdp_buff(struct mlx5e_xdpsq *sq, struct mlx5e_dma_info *di,
3858
struct xdp_buff *xdp)

drivers/net/ethernet/mellanox/mlx5/core/en/xdp.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@
3434

3535
#include "en.h"
3636

37-
#define MLX5E_XDP_MAX_MTU ((int)(PAGE_SIZE - \
38-
MLX5_SKB_FRAG_SZ(XDP_PACKET_HEADROOM)))
3937
#define MLX5E_XDP_MIN_INLINE (ETH_HLEN + VLAN_HLEN)
4038
#define MLX5E_XDP_TX_EMPTY_DS_COUNT \
4139
(sizeof(struct mlx5e_tx_wqe) / MLX5_SEND_WQE_DS)
4240
#define MLX5E_XDP_TX_DS_COUNT (MLX5E_XDP_TX_EMPTY_DS_COUNT + 1 /* SG DS */)
4341

42+
int mlx5e_xdp_max_mtu(struct mlx5e_params *params);
4443
bool mlx5e_xdp_handle(struct mlx5e_rq *rq, struct mlx5e_dma_info *di,
4544
void *va, u16 *rx_headroom, u32 *len);
4645
bool mlx5e_poll_xdpsq_cq(struct mlx5e_cq *cq, struct mlx5e_rq *rq);

drivers/net/ethernet/mellanox/mlx5/core/en_main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3777,7 +3777,7 @@ int mlx5e_change_mtu(struct net_device *netdev, int new_mtu,
37773777
if (params->xdp_prog &&
37783778
!mlx5e_rx_is_linear_skb(priv->mdev, &new_channels.params)) {
37793779
netdev_err(netdev, "MTU(%d) > %d is not allowed while XDP enabled\n",
3780-
new_mtu, MLX5E_XDP_MAX_MTU);
3780+
new_mtu, mlx5e_xdp_max_mtu(params));
37813781
err = -EINVAL;
37823782
goto out;
37833783
}
@@ -4212,7 +4212,8 @@ static int mlx5e_xdp_allowed(struct mlx5e_priv *priv, struct bpf_prog *prog)
42124212

42134213
if (!mlx5e_rx_is_linear_skb(priv->mdev, &new_channels.params)) {
42144214
netdev_warn(netdev, "XDP is not allowed with MTU(%d) > %d\n",
4215-
new_channels.params.sw_mtu, MLX5E_XDP_MAX_MTU);
4215+
new_channels.params.sw_mtu,
4216+
mlx5e_xdp_max_mtu(&new_channels.params));
42164217
return -EINVAL;
42174218
}
42184219

0 commit comments

Comments
 (0)