Skip to content

Commit 87bcef1

Browse files
ameryhungkuba-moo
authored andcommitted
net/mlx5e: RX, Fix generating skb from non-linear xdp_buff for striding RQ
XDP programs can change the layout of an xdp_buff through bpf_xdp_adjust_tail() and bpf_xdp_adjust_head(). Therefore, the driver cannot assume the size of the linear data area nor fragments. Fix the bug in mlx5 by generating skb according to xdp_buff after XDP programs run. Currently, when handling multi-buf XDP, the mlx5 driver assumes the layout of an xdp_buff to be unchanged. That is, the linear data area continues to be empty and fragments remain the same. This may cause the driver to generate erroneous skb or triggering a kernel warning. When an XDP program added linear data through bpf_xdp_adjust_head(), the linear data will be ignored as mlx5e_build_linear_skb() builds an skb without linear data and then pull data from fragments to fill the linear data area. When an XDP program has shrunk the non-linear data through bpf_xdp_adjust_tail(), the delta passed to __pskb_pull_tail() may exceed the actual nonlinear data size and trigger the BUG_ON in it. To fix the issue, first record the original number of fragments. If the number of fragments changes after the XDP program runs, rewind the end fragment pointer by the difference and recalculate the truesize. Then, build the skb with the linear data area matching the xdp_buff. Finally, only pull data in if there is non-linear data and fill the linear part up to 256 bytes. Fixes: f52ac70 ("net/mlx5e: RX, Add XDP multi-buffer support in Striding RQ") Signed-off-by: Amery Hung <[email protected]> Signed-off-by: Tariq Toukan <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent afd5ba5 commit 87bcef1

File tree

1 file changed

+23
-3
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+23
-3
lines changed

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,7 @@ mlx5e_skb_from_cqe_mpwrq_nonlinear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *w
20402040
u32 byte_cnt = cqe_bcnt;
20412041
struct skb_shared_info *sinfo;
20422042
unsigned int truesize = 0;
2043+
u32 pg_consumed_bytes;
20432044
struct bpf_prog *prog;
20442045
struct sk_buff *skb;
20452046
u32 linear_frame_sz;
@@ -2093,7 +2094,8 @@ mlx5e_skb_from_cqe_mpwrq_nonlinear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *w
20932094

20942095
while (byte_cnt) {
20952096
/* Non-linear mode, hence non-XSK, which always uses PAGE_SIZE. */
2096-
u32 pg_consumed_bytes = min_t(u32, PAGE_SIZE - frag_offset, byte_cnt);
2097+
pg_consumed_bytes =
2098+
min_t(u32, PAGE_SIZE - frag_offset, byte_cnt);
20972099

20982100
if (test_bit(MLX5E_RQ_STATE_SHAMPO, &rq->state))
20992101
truesize += pg_consumed_bytes;
@@ -2109,10 +2111,15 @@ mlx5e_skb_from_cqe_mpwrq_nonlinear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *w
21092111
}
21102112

21112113
if (prog) {
2114+
u8 nr_frags_free, old_nr_frags = sinfo->nr_frags;
2115+
u32 len;
2116+
21122117
if (mlx5e_xdp_handle(rq, prog, mxbuf)) {
21132118
if (__test_and_clear_bit(MLX5E_RQ_FLAG_XDP_XMIT, rq->flags)) {
21142119
struct mlx5e_frag_page *pfp;
21152120

2121+
frag_page -= old_nr_frags - sinfo->nr_frags;
2122+
21162123
for (pfp = head_page; pfp < frag_page; pfp++)
21172124
pfp->frags++;
21182125

@@ -2123,9 +2130,19 @@ mlx5e_skb_from_cqe_mpwrq_nonlinear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *w
21232130
return NULL; /* page/packet was consumed by XDP */
21242131
}
21252132

2133+
nr_frags_free = old_nr_frags - sinfo->nr_frags;
2134+
if (unlikely(nr_frags_free)) {
2135+
frag_page -= nr_frags_free;
2136+
truesize -= (nr_frags_free - 1) * PAGE_SIZE +
2137+
ALIGN(pg_consumed_bytes,
2138+
BIT(rq->mpwqe.log_stride_sz));
2139+
}
2140+
2141+
len = mxbuf->xdp.data_end - mxbuf->xdp.data;
2142+
21262143
skb = mlx5e_build_linear_skb(
21272144
rq, mxbuf->xdp.data_hard_start, linear_frame_sz,
2128-
mxbuf->xdp.data - mxbuf->xdp.data_hard_start, 0,
2145+
mxbuf->xdp.data - mxbuf->xdp.data_hard_start, len,
21292146
mxbuf->xdp.data - mxbuf->xdp.data_meta);
21302147
if (unlikely(!skb)) {
21312148
mlx5e_page_release_fragmented(rq->page_pool,
@@ -2150,8 +2167,11 @@ mlx5e_skb_from_cqe_mpwrq_nonlinear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *w
21502167
do
21512168
pagep->frags++;
21522169
while (++pagep < frag_page);
2170+
2171+
headlen = min_t(u16, MLX5E_RX_MAX_HEAD - len,
2172+
skb->data_len);
2173+
__pskb_pull_tail(skb, headlen);
21532174
}
2154-
__pskb_pull_tail(skb, headlen);
21552175
} else {
21562176
dma_addr_t addr;
21572177

0 commit comments

Comments
 (0)