diff mbox series

[net-next,01/15] net/mlx5e: Validate MTU when building non-linear legacy RQ fragments info

Message ID 20220317185424.287982-2-saeed@kernel.org (mailing list archive)
State Accepted
Commit 7c3b4df594b6c51c1fc95e6fd9f949bdddff34b5
Delegated to: Netdev Maintainers
Headers show
Series [net-next,01/15] net/mlx5e: Validate MTU when building non-linear legacy RQ fragments info | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Pull request is its own cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 3 of 3 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning WARNING: line length of 87 exceeds 80 columns WARNING: line length of 90 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Saeed Mahameed March 17, 2022, 6:54 p.m. UTC
From: Maxim Mikityanskiy <maximmi@nvidia.com>

mlx5e_build_rq_frags_info() assumes that MTU is not bigger than
PAGE_SIZE * MLX5E_MAX_RX_FRAGS, which is 16K for 4K pages. Currently,
the firmware limits MTU to 10K, so the assumption doesn't lead to a bug.

This commits adds an additional driver check for reliability, since the
firmware boundary might be changed.

The calculation is taken to a separate function with a comment
explaining it. It's a preparation for the following patches that
introcuce XDP multi buffer support.

Signed-off-by: Maxim Mikityanskiy <maximmi@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
---
 .../ethernet/mellanox/mlx5/core/en/params.c   | 34 +++++++++++++++----
 1 file changed, 27 insertions(+), 7 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org March 18, 2022, 11 a.m. UTC | #1
Hello:

This series was applied to netdev/net-next.git (master)
by Saeed Mahameed <saeedm@nvidia.com>:

On Thu, 17 Mar 2022 11:54:10 -0700 you wrote:
> From: Maxim Mikityanskiy <maximmi@nvidia.com>
> 
> mlx5e_build_rq_frags_info() assumes that MTU is not bigger than
> PAGE_SIZE * MLX5E_MAX_RX_FRAGS, which is 16K for 4K pages. Currently,
> the firmware limits MTU to 10K, so the assumption doesn't lead to a bug.
> 
> This commits adds an additional driver check for reliability, since the
> firmware boundary might be changed.
> 
> [...]

Here is the summary with links:
  - [net-next,01/15] net/mlx5e: Validate MTU when building non-linear legacy RQ fragments info
    https://git.kernel.org/netdev/net-next/c/7c3b4df594b6
  - [net-next,02/15] net/mlx5e: Add headroom only to the first fragment in legacy RQ
    https://git.kernel.org/netdev/net-next/c/c3cce0fff3a3
  - [net-next,03/15] net/mlx5e: Build SKB in place over the first fragment in non-linear legacy RQ
    https://git.kernel.org/netdev/net-next/c/8d35fb57fd90
  - [net-next,04/15] net/mlx5e: RX, Test the XDP program existence out of the handler
    https://git.kernel.org/netdev/net-next/c/e26eceb90b01
  - [net-next,05/15] net/mlx5e: Drop the len output parameter from mlx5e_xdp_handle
    https://git.kernel.org/netdev/net-next/c/064990d0b65f
  - [net-next,06/15] net/mlx5e: Drop cqe_bcnt32 from mlx5e_skb_from_cqe_mpwrq_linear
    https://git.kernel.org/netdev/net-next/c/998923932f13
  - [net-next,07/15] net/mlx5: DR, Adjust structure member to reduce memory hole
    https://git.kernel.org/netdev/net-next/c/8f8533650325
  - [net-next,08/15] net/mlx5: DR, Remove mr_addr rkey from struct mlx5dr_icm_chunk
    https://git.kernel.org/netdev/net-next/c/003f4f9acb05
  - [net-next,09/15] net/mlx5: DR, Remove icm_addr from mlx5dr_icm_chunk to reduce memory
    https://git.kernel.org/netdev/net-next/c/5c4f9b6e91e8
  - [net-next,10/15] net/mlx5: DR, Remove num_of_entries byte_size from struct mlx5_dr_icm_chunk
    https://git.kernel.org/netdev/net-next/c/f51bb5179300
  - [net-next,11/15] net/mlx5: DR, Remove 4 members from mlx5dr_ste_htbl to reduce memory
    https://git.kernel.org/netdev/net-next/c/597534bd5633
  - [net-next,12/15] net/mlx5: DR, Remove hw_ste from mlx5dr_ste to reduce memory
    https://git.kernel.org/netdev/net-next/c/0d7f1595bb96
  - [net-next,13/15] net/mlx5: CT: Remove extra rhashtable remove on tuple entries
    https://git.kernel.org/netdev/net-next/c/ebf04231cf14
  - [net-next,14/15] net/mlx5: Remove unused exported contiguous coherent buffer allocation API
    https://git.kernel.org/netdev/net-next/c/4206fe40b2c0
  - [net-next,15/15] net/mlx5: Remove unused fill page array API function
    https://git.kernel.org/netdev/net-next/c/770c9a3a01af

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/params.c b/drivers/net/ethernet/mellanox/mlx5/core/en/params.c
index 0bd8698f7226..0f258e7a65e0 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/params.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/params.c
@@ -392,16 +392,23 @@  void mlx5e_build_create_cq_param(struct mlx5e_create_cq_param *ccp, struct mlx5e
 	};
 }
 
+static int mlx5e_max_nonlinear_mtu(int frag_size)
+{
+	/* Optimization for small packets: the last fragment is bigger than the others. */
+	return (MLX5E_MAX_RX_FRAGS - 1) * frag_size + PAGE_SIZE;
+}
+
 #define DEFAULT_FRAG_SIZE (2048)
 
-static void mlx5e_build_rq_frags_info(struct mlx5_core_dev *mdev,
-				      struct mlx5e_params *params,
-				      struct mlx5e_xsk_param *xsk,
-				      struct mlx5e_rq_frags_info *info)
+static int mlx5e_build_rq_frags_info(struct mlx5_core_dev *mdev,
+				     struct mlx5e_params *params,
+				     struct mlx5e_xsk_param *xsk,
+				     struct mlx5e_rq_frags_info *info)
 {
 	u32 byte_count = MLX5E_SW2HW_MTU(params, params->sw_mtu);
 	int frag_size_max = DEFAULT_FRAG_SIZE;
 	u32 buf_size = 0;
+	int max_mtu;
 	int i;
 
 	if (mlx5_fpga_is_ipsec_device(mdev))
@@ -420,10 +427,18 @@  static void mlx5e_build_rq_frags_info(struct mlx5_core_dev *mdev,
 		goto out;
 	}
 
-	if (byte_count > PAGE_SIZE +
-	    (MLX5E_MAX_RX_FRAGS - 1) * frag_size_max)
+	max_mtu = mlx5e_max_nonlinear_mtu(frag_size_max);
+	if (byte_count > max_mtu) {
 		frag_size_max = PAGE_SIZE;
 
+		max_mtu = mlx5e_max_nonlinear_mtu(frag_size_max);
+		if (byte_count > max_mtu) {
+			mlx5_core_err(mdev, "MTU %u is too big for non-linear legacy RQ (max %d)\n",
+				      params->sw_mtu, max_mtu);
+			return -EINVAL;
+		}
+	}
+
 	i = 0;
 	while (buf_size < byte_count) {
 		int frag_size = byte_count - buf_size;
@@ -444,6 +459,8 @@  static void mlx5e_build_rq_frags_info(struct mlx5_core_dev *mdev,
 out:
 	info->wqe_bulk = max_t(u8, info->wqe_bulk, 8);
 	info->log_num_frags = order_base_2(info->num_frags);
+
+	return 0;
 }
 
 static u8 mlx5e_get_rqwq_log_stride(u8 wq_type, int ndsegs)
@@ -540,6 +557,7 @@  int mlx5e_build_rq_param(struct mlx5_core_dev *mdev,
 	void *rqc = param->rqc;
 	void *wq = MLX5_ADDR_OF(rqc, rqc, wq);
 	int ndsegs = 1;
+	int err;
 
 	switch (params->rq_wq_type) {
 	case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ: {
@@ -579,7 +597,9 @@  int mlx5e_build_rq_param(struct mlx5_core_dev *mdev,
 	}
 	default: /* MLX5_WQ_TYPE_CYCLIC */
 		MLX5_SET(wq, wq, log_wq_sz, params->log_rq_mtu_frames);
-		mlx5e_build_rq_frags_info(mdev, params, xsk, &param->frags_info);
+		err = mlx5e_build_rq_frags_info(mdev, params, xsk, &param->frags_info);
+		if (err)
+			return err;
 		ndsegs = param->frags_info.num_frags;
 	}