netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
To: Maxim Mikityanskiy <maximmi@nvidia.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Björn Töpel" <bjorn@kernel.org>,
	"Magnus Karlsson" <magnus.karlsson@intel.com>,
	"Saeed Mahameed" <saeedm@nvidia.com>,
	"Jonathan Lemon" <jonathan.lemon@gmail.com>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Jesper Dangaard Brouer" <hawk@kernel.org>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"Tariq Toukan" <tariqt@nvidia.com>,
	"Gal Pressman" <gal@nvidia.com>,
	netdev@vger.kernel.org
Subject: Re: [PATCH net] net/mlx5e: xsk: Discard unaligned XSK frames on striding RQ
Date: Mon, 1 Aug 2022 15:41:41 +0200	[thread overview]
Message-ID: <YufYFQ6JN91lQbso@boxer> (raw)
In-Reply-To: <20220729121356.3990867-1-maximmi@nvidia.com>

On Fri, Jul 29, 2022 at 03:13:56PM +0300, Maxim Mikityanskiy wrote:
> Striding RQ uses MTT page mapping, where each page corresponds to an XSK
> frame. MTT pages have alignment requirements, and XSK frames don't have
> any alignment guarantees in the unaligned mode. Frames with improper
> alignment must be discarded, otherwise the packet data will be written
> at a wrong address.

Hey Maxim,
can you explain what MTT stands for?

> 
> Fixes: 282c0c798f8e ("net/mlx5e: Allow XSK frames smaller than a page")
> Signed-off-by: Maxim Mikityanskiy <maximmi@nvidia.com>
> Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
> Reviewed-by: Saeed Mahameed <saeedm@nvidia.com>
> ---
>  .../net/ethernet/mellanox/mlx5/core/en/xsk/rx.h    | 14 ++++++++++++++
>  include/net/xdp_sock_drv.h                         | 11 +++++++++++
>  2 files changed, 25 insertions(+)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.h b/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.h
> index a8cfab4a393c..cc18d97d8ee0 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.h
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.h
> @@ -7,6 +7,8 @@
>  #include "en.h"
>  #include <net/xdp_sock_drv.h>
>  
> +#define MLX5E_MTT_PTAG_MASK 0xfffffffffffffff8ULL

What if PAGE_SIZE != 4096 ? Is aligned mode with 2k frame fine for MTT
case?

> +
>  /* RX data path */
>  
>  struct sk_buff *mlx5e_xsk_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq,
> @@ -21,6 +23,7 @@ struct sk_buff *mlx5e_xsk_skb_from_cqe_linear(struct mlx5e_rq *rq,
>  static inline int mlx5e_xsk_page_alloc_pool(struct mlx5e_rq *rq,
>  					    struct mlx5e_dma_info *dma_info)
>  {
> +retry:
>  	dma_info->xsk = xsk_buff_alloc(rq->xsk_pool);
>  	if (!dma_info->xsk)
>  		return -ENOMEM;
> @@ -32,6 +35,17 @@ static inline int mlx5e_xsk_page_alloc_pool(struct mlx5e_rq *rq,
>  	 */
>  	dma_info->addr = xsk_buff_xdp_get_frame_dma(dma_info->xsk);
>  
> +	/* MTT page mapping has alignment requirements. If they are not
> +	 * satisfied, leak the descriptor so that it won't come again, and try
> +	 * to allocate a new one.
> +	 */
> +	if (rq->wq_type == MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ) {
> +		if (unlikely(dma_info->addr & ~MLX5E_MTT_PTAG_MASK)) {
> +			xsk_buff_discard(dma_info->xsk);
> +			goto retry;
> +		}
> +	}

I don't know your hardware much, but how would this work out performance
wise? Are there any config combos (page size vs chunk size in unaligned
mode) that you would forbid during pool attach to queue or would you
better allow anything?

Also would be helpful if you would describe the use case you're fixing.

Thanks!

> +
>  	return 0;
>  }
>  
> diff --git a/include/net/xdp_sock_drv.h b/include/net/xdp_sock_drv.h
> index 4aa031849668..0774ce97c2f1 100644
> --- a/include/net/xdp_sock_drv.h
> +++ b/include/net/xdp_sock_drv.h
> @@ -95,6 +95,13 @@ static inline void xsk_buff_free(struct xdp_buff *xdp)
>  	xp_free(xskb);
>  }
>  
> +static inline void xsk_buff_discard(struct xdp_buff *xdp)
> +{
> +	struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);
> +
> +	xp_release(xskb);
> +}
> +
>  static inline void xsk_buff_set_size(struct xdp_buff *xdp, u32 size)
>  {
>  	xdp->data = xdp->data_hard_start + XDP_PACKET_HEADROOM;
> @@ -238,6 +245,10 @@ static inline void xsk_buff_free(struct xdp_buff *xdp)
>  {
>  }
>  
> +static inline void xsk_buff_discard(struct xdp_buff *xdp)
> +{
> +}
> +
>  static inline void xsk_buff_set_size(struct xdp_buff *xdp, u32 size)
>  {
>  }
> -- 
> 2.25.1
> 

  parent reply	other threads:[~2022-08-01 13:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-29 12:13 [PATCH net] net/mlx5e: xsk: Discard unaligned XSK frames on striding RQ Maxim Mikityanskiy
2022-08-01  8:08 ` Maxim Mikityanskiy
2022-08-01 13:41 ` Maciej Fijalkowski [this message]
2022-08-01 15:49   ` Maxim Mikityanskiy
2022-08-02 10:54     ` Paolo Abeni
2022-08-02 12:54       ` Maciej Fijalkowski
2022-08-02 13:40 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YufYFQ6JN91lQbso@boxer \
    --to=maciej.fijalkowski@intel.com \
    --cc=ast@kernel.org \
    --cc=bjorn@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gal@nvidia.com \
    --cc=hawk@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=jonathan.lemon@gmail.com \
    --cc=kuba@kernel.org \
    --cc=magnus.karlsson@intel.com \
    --cc=maximmi@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).