diff mbox series

[net] net: mellanox: mlxbf_gige: Fix skb_panic splat under memory pressure

Message ID 20230522190713.82417-1-tbogendoerfer@suse.de (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net] net: mellanox: mlxbf_gige: Fix skb_panic splat under memory pressure | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/fixes_present fail Series targets non-next tree, but doesn't contain any Fixes tags
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch warning WARNING: line length of 84 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Thomas Bogendoerfer May 22, 2023, 7:07 p.m. UTC
Do skp_put() after a new skb has been successfully allocated otherwise
the reused skb leads to skp_panics or incorrect packet sizes.

Signed-off-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
---
 .../ethernet/mellanox/mlxbf_gige/mlxbf_gige_rx.c    | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Comments

Jakub Kicinski May 24, 2023, 3:42 a.m. UTC | #1
On Mon, 22 May 2023 21:07:13 +0200 Thomas Bogendoerfer wrote:
> Do skp_put() after a new skb has been successfully allocated otherwise
> the reused skb leads to skp_panics or incorrect packet sizes.

s/skp/skb/

Please add a Fixes tag pointing at the patch which introduced 
the problem (could be the first commit adding this driver).

> Signed-off-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
> ---
>  .../ethernet/mellanox/mlxbf_gige/mlxbf_gige_rx.c    | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_rx.c b/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_rx.c
> index afa3b92a6905..2c132849a76d 100644
> --- a/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_rx.c
> +++ b/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_rx.c
> @@ -245,18 +245,19 @@ static bool mlxbf_gige_rx_packet(struct mlxbf_gige *priv, int *rx_pkts)
>  
>  		skb = priv->rx_skb[rx_pi_rem];
>  
> -		skb_put(skb, datalen);
> -
> -		skb->ip_summed = CHECKSUM_NONE; /* device did not checksum packet */
> -
> -		skb->protocol = eth_type_trans(skb, netdev);
> -
>  		/* Alloc another RX SKB for this same index */
>  		rx_skb = mlxbf_gige_alloc_skb(priv, MLXBF_GIGE_DEFAULT_BUF_SZ,
>  					      &rx_buf_dma, DMA_FROM_DEVICE);
>  		if (!rx_skb)
>  			return false;
>  		priv->rx_skb[rx_pi_rem] = rx_skb;
> +
> +		skb_put(skb, datalen);
> +
> +		skb->ip_summed = CHECKSUM_NONE; /* device did not checksum packet */
> +
> +		skb->protocol = eth_type_trans(skb, netdev);
>
>  		dma_unmap_single(priv->dev, *rx_wqe_addr,
>  				 MLXBF_GIGE_DEFAULT_BUF_SZ, DMA_FROM_DEVICE);

You should move the code here, after the dma_unmap().
eth_type_trans() will access the payload and until dma_unmap
the data should not be accessed by the CPU.

>  		*rx_wqe_addr = rx_buf_dma;
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_rx.c b/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_rx.c
index afa3b92a6905..2c132849a76d 100644
--- a/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_rx.c
+++ b/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_rx.c
@@ -245,18 +245,19 @@  static bool mlxbf_gige_rx_packet(struct mlxbf_gige *priv, int *rx_pkts)
 
 		skb = priv->rx_skb[rx_pi_rem];
 
-		skb_put(skb, datalen);
-
-		skb->ip_summed = CHECKSUM_NONE; /* device did not checksum packet */
-
-		skb->protocol = eth_type_trans(skb, netdev);
-
 		/* Alloc another RX SKB for this same index */
 		rx_skb = mlxbf_gige_alloc_skb(priv, MLXBF_GIGE_DEFAULT_BUF_SZ,
 					      &rx_buf_dma, DMA_FROM_DEVICE);
 		if (!rx_skb)
 			return false;
 		priv->rx_skb[rx_pi_rem] = rx_skb;
+
+		skb_put(skb, datalen);
+
+		skb->ip_summed = CHECKSUM_NONE; /* device did not checksum packet */
+
+		skb->protocol = eth_type_trans(skb, netdev);
+
 		dma_unmap_single(priv->dev, *rx_wqe_addr,
 				 MLXBF_GIGE_DEFAULT_BUF_SZ, DMA_FROM_DEVICE);
 		*rx_wqe_addr = rx_buf_dma;