Skip to content

Commit e435941

Browse files
vvfedorenkoSaeed Mahameed
authored andcommitted
mlx5: fix skb leak while fifo resync and push
During ptp resync operation SKBs were poped from the fifo but were never freed neither by napi_consume nor by dev_kfree_skb_any. Add call to napi_consume_skb to properly free SKBs. Another leak was happening because mlx5e_skb_fifo_has_room() had an error in the check. Comparing free running counters works well unless C promotes the types to something wider than the counter. In this case counters are u16 but the result of the substraction is promouted to int and it causes wrong result (negative value) of the check when producer have already overlapped but consumer haven't yet. Explicit cast to u16 fixes the issue. Fixes: 58a5189 ("net/mlx5e: Add resiliency for PTP TX port timestamp") Reviewed-by: Gal Pressman <[email protected]> Reviewed-by: Tariq Toukan <[email protected]> Signed-off-by: Vadim Fedorenko <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent bfeda96 commit e435941

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ static bool mlx5e_ptp_ts_cqe_drop(struct mlx5e_ptpsq *ptpsq, u16 skb_cc, u16 skb
8686
return (ptpsq->ts_cqe_ctr_mask && (skb_cc != skb_id));
8787
}
8888

89-
static void mlx5e_ptp_skb_fifo_ts_cqe_resync(struct mlx5e_ptpsq *ptpsq, u16 skb_cc, u16 skb_id)
89+
static void mlx5e_ptp_skb_fifo_ts_cqe_resync(struct mlx5e_ptpsq *ptpsq, u16 skb_cc,
90+
u16 skb_id, int budget)
9091
{
9192
struct skb_shared_hwtstamps hwts = {};
9293
struct sk_buff *skb;
@@ -98,6 +99,7 @@ static void mlx5e_ptp_skb_fifo_ts_cqe_resync(struct mlx5e_ptpsq *ptpsq, u16 skb_
9899
hwts.hwtstamp = mlx5e_skb_cb_get_hwts(skb)->cqe_hwtstamp;
99100
skb_tstamp_tx(skb, &hwts);
100101
ptpsq->cq_stats->resync_cqe++;
102+
napi_consume_skb(skb, budget);
101103
skb_cc = PTP_WQE_CTR2IDX(ptpsq->skb_fifo_cc);
102104
}
103105
}
@@ -119,7 +121,7 @@ static void mlx5e_ptp_handle_ts_cqe(struct mlx5e_ptpsq *ptpsq,
119121
}
120122

121123
if (mlx5e_ptp_ts_cqe_drop(ptpsq, skb_cc, skb_id))
122-
mlx5e_ptp_skb_fifo_ts_cqe_resync(ptpsq, skb_cc, skb_id);
124+
mlx5e_ptp_skb_fifo_ts_cqe_resync(ptpsq, skb_cc, skb_id, budget);
123125

124126
skb = mlx5e_skb_fifo_pop(&ptpsq->skb_fifo);
125127
hwtstamp = mlx5e_cqe_ts_to_ns(sq->ptp_cyc2time, sq->clock, get_cqe_ts(cqe));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void mlx5e_free_txqsq_descs(struct mlx5e_txqsq *sq);
8686
static inline bool
8787
mlx5e_skb_fifo_has_room(struct mlx5e_skb_fifo *fifo)
8888
{
89-
return (*fifo->pc - *fifo->cc) < fifo->mask;
89+
return (u16)(*fifo->pc - *fifo->cc) < fifo->mask;
9090
}
9191

9292
static inline bool

0 commit comments

Comments
 (0)