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 |
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 --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, ¶m->frags_info); + err = mlx5e_build_rq_frags_info(mdev, params, xsk, ¶m->frags_info); + if (err) + return err; ndsegs = param->frags_info.num_frags; }