]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mlx5: fix skb leak while fifo resync and push
authorVadim Fedorenko <vadfed@meta.com>
Thu, 2 Feb 2023 17:13:54 +0000 (09:13 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 11 Mar 2023 12:55:27 +0000 (13:55 +0100)
[ Upstream commit 61bdcce45938f6ddb538199826bd6e69eb86e7b7 ]

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: 2037d365f6e3 ("net/mlx5e: Add resiliency for PTP TX port timestamp")
Reviewed-by: Gal Pressman <gal@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c
drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h

index 8469e9c38670653499a2355c50b319491ae39460..b72de2b520ecbe3fc9d553fa9712f3ca71418e27 100644 (file)
@@ -86,7 +86,8 @@ static bool mlx5e_ptp_ts_cqe_drop(struct mlx5e_ptpsq *ptpsq, u16 skb_cc, u16 skb
        return (ptpsq->ts_cqe_ctr_mask && (skb_cc != skb_id));
 }
 
-static void mlx5e_ptp_skb_fifo_ts_cqe_resync(struct mlx5e_ptpsq *ptpsq, u16 skb_cc, u16 skb_id)
+static void mlx5e_ptp_skb_fifo_ts_cqe_resync(struct mlx5e_ptpsq *ptpsq, u16 skb_cc,
+                                            u16 skb_id, int budget)
 {
        struct skb_shared_hwtstamps hwts = {};
        struct sk_buff *skb;
@@ -98,6 +99,7 @@ static void mlx5e_ptp_skb_fifo_ts_cqe_resync(struct mlx5e_ptpsq *ptpsq, u16 skb_
                hwts.hwtstamp = mlx5e_skb_cb_get_hwts(skb)->cqe_hwtstamp;
                skb_tstamp_tx(skb, &hwts);
                ptpsq->cq_stats->resync_cqe++;
+               napi_consume_skb(skb, budget);
                skb_cc = PTP_WQE_CTR2IDX(ptpsq->skb_fifo_cc);
        }
 }
@@ -119,7 +121,7 @@ static void mlx5e_ptp_handle_ts_cqe(struct mlx5e_ptpsq *ptpsq,
        }
 
        if (mlx5e_ptp_ts_cqe_drop(ptpsq, skb_cc, skb_id))
-               mlx5e_ptp_skb_fifo_ts_cqe_resync(ptpsq, skb_cc, skb_id);
+               mlx5e_ptp_skb_fifo_ts_cqe_resync(ptpsq, skb_cc, skb_id, budget);
 
        skb = mlx5e_skb_fifo_pop(&ptpsq->skb_fifo);
        hwtstamp = mlx5e_cqe_ts_to_ns(sq->ptp_cyc2time, sq->clock, get_cqe_ts(cqe));
index 853f312cd757257a84f297ce1ef1a91dc5c7d4c8..15a5a57b47b85873cd2c7cfb5da6ab7082146081 100644 (file)
@@ -81,7 +81,7 @@ void mlx5e_free_txqsq_descs(struct mlx5e_txqsq *sq);
 static inline bool
 mlx5e_skb_fifo_has_room(struct mlx5e_skb_fifo *fifo)
 {
-       return (*fifo->pc - *fifo->cc) < fifo->mask;
+       return (u16)(*fifo->pc - *fifo->cc) < fifo->mask;
 }
 
 static inline bool