netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
To: Alexander Lobakin <aleksander.lobakin@intel.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Toke Høiland-Jørgensen" <toke@redhat.com>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Stanislav Fomichev" <sdf@fomichev.me>,
	"Magnus Karlsson" <magnus.karlsson@intel.com>,
	nex.sw.ncis.osdt.itp.upstreaming@intel.com, bpf@vger.kernel.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v2 05/18] xdp, xsk: constify read-only arguments of some static inline helpers
Date: Thu, 17 Oct 2024 13:14:22 +0200	[thread overview]
Message-ID: <ZxDxjj4SPT0Y9KyP@boxer> (raw)
In-Reply-To: <20241015145350.4077765-6-aleksander.lobakin@intel.com>

On Tue, Oct 15, 2024 at 04:53:37PM +0200, Alexander Lobakin wrote:
> Lots of read-only helpers for &xdp_buff and &xdp_frame, such as getting
> the frame length, skb_shared_info etc., don't have their arguments
> marked with `const` for no reason. Add the missing annotations to leave
> less place for mistakes and more for optimization.

Same comment as in previous patch.
Good stuff regardless.

> 
> Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
> ---
>  include/net/xdp.h           | 29 +++++++++++++++++------------
>  include/net/xdp_sock_drv.h  | 11 ++++++-----
>  include/net/xsk_buff_pool.h |  2 +-
>  3 files changed, 24 insertions(+), 18 deletions(-)
> 
> diff --git a/include/net/xdp.h b/include/net/xdp.h
> index e6770dd40c91..197808df1ee1 100644
> --- a/include/net/xdp.h
> +++ b/include/net/xdp.h
> @@ -88,7 +88,7 @@ struct xdp_buff {
>  	u32 flags; /* supported values defined in xdp_buff_flags */
>  };
>  
> -static __always_inline bool xdp_buff_has_frags(struct xdp_buff *xdp)
> +static __always_inline bool xdp_buff_has_frags(const struct xdp_buff *xdp)
>  {
>  	return !!(xdp->flags & XDP_FLAGS_HAS_FRAGS);
>  }
> @@ -103,7 +103,8 @@ static __always_inline void xdp_buff_clear_frags_flag(struct xdp_buff *xdp)
>  	xdp->flags &= ~XDP_FLAGS_HAS_FRAGS;
>  }
>  
> -static __always_inline bool xdp_buff_is_frag_pfmemalloc(struct xdp_buff *xdp)
> +static __always_inline bool
> +xdp_buff_is_frag_pfmemalloc(const struct xdp_buff *xdp)
>  {
>  	return !!(xdp->flags & XDP_FLAGS_FRAGS_PF_MEMALLOC);
>  }
> @@ -144,15 +145,16 @@ xdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start,
>  	 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
>  
>  static inline struct skb_shared_info *
> -xdp_get_shared_info_from_buff(struct xdp_buff *xdp)
> +xdp_get_shared_info_from_buff(const struct xdp_buff *xdp)
>  {
>  	return (struct skb_shared_info *)xdp_data_hard_end(xdp);
>  }
>  
> -static __always_inline unsigned int xdp_get_buff_len(struct xdp_buff *xdp)
> +static __always_inline unsigned int
> +xdp_get_buff_len(const struct xdp_buff *xdp)
>  {
>  	unsigned int len = xdp->data_end - xdp->data;
> -	struct skb_shared_info *sinfo;
> +	const struct skb_shared_info *sinfo;
>  
>  	if (likely(!xdp_buff_has_frags(xdp)))
>  		goto out;
> @@ -177,12 +179,13 @@ struct xdp_frame {
>  	u32 flags; /* supported values defined in xdp_buff_flags */
>  };
>  
> -static __always_inline bool xdp_frame_has_frags(struct xdp_frame *frame)
> +static __always_inline bool xdp_frame_has_frags(const struct xdp_frame *frame)
>  {
>  	return !!(frame->flags & XDP_FLAGS_HAS_FRAGS);
>  }
>  
> -static __always_inline bool xdp_frame_is_frag_pfmemalloc(struct xdp_frame *frame)
> +static __always_inline bool
> +xdp_frame_is_frag_pfmemalloc(const struct xdp_frame *frame)
>  {
>  	return !!(frame->flags & XDP_FLAGS_FRAGS_PF_MEMALLOC);
>  }
> @@ -201,7 +204,7 @@ static __always_inline void xdp_frame_bulk_init(struct xdp_frame_bulk *bq)
>  }
>  
>  static inline struct skb_shared_info *
> -xdp_get_shared_info_from_frame(struct xdp_frame *frame)
> +xdp_get_shared_info_from_frame(const struct xdp_frame *frame)
>  {
>  	void *data_hard_start = frame->data - frame->headroom - sizeof(*frame);
>  
> @@ -249,7 +252,8 @@ int xdp_alloc_skb_bulk(void **skbs, int n_skb, gfp_t gfp);
>  struct xdp_frame *xdpf_clone(struct xdp_frame *xdpf);
>  
>  static inline
> -void xdp_convert_frame_to_buff(struct xdp_frame *frame, struct xdp_buff *xdp)
> +void xdp_convert_frame_to_buff(const struct xdp_frame *frame,
> +			       struct xdp_buff *xdp)
>  {
>  	xdp->data_hard_start = frame->data - frame->headroom - sizeof(*frame);
>  	xdp->data = frame->data;
> @@ -260,7 +264,7 @@ void xdp_convert_frame_to_buff(struct xdp_frame *frame, struct xdp_buff *xdp)
>  }
>  
>  static inline
> -int xdp_update_frame_from_buff(struct xdp_buff *xdp,
> +int xdp_update_frame_from_buff(const struct xdp_buff *xdp,
>  			       struct xdp_frame *xdp_frame)
>  {
>  	int metasize, headroom;
> @@ -317,9 +321,10 @@ void xdp_flush_frame_bulk(struct xdp_frame_bulk *bq);
>  void xdp_return_frame_bulk(struct xdp_frame *xdpf,
>  			   struct xdp_frame_bulk *bq);
>  
> -static __always_inline unsigned int xdp_get_frame_len(struct xdp_frame *xdpf)
> +static __always_inline unsigned int
> +xdp_get_frame_len(const struct xdp_frame *xdpf)
>  {
> -	struct skb_shared_info *sinfo;
> +	const struct skb_shared_info *sinfo;
>  	unsigned int len = xdpf->len;
>  
>  	if (likely(!xdp_frame_has_frags(xdpf)))
> diff --git a/include/net/xdp_sock_drv.h b/include/net/xdp_sock_drv.h
> index 40085afd9160..f3175a5d28f7 100644
> --- a/include/net/xdp_sock_drv.h
> +++ b/include/net/xdp_sock_drv.h
> @@ -101,7 +101,7 @@ static inline struct xdp_buff *xsk_buff_alloc(struct xsk_buff_pool *pool)
>  	return xp_alloc(pool);
>  }
>  
> -static inline bool xsk_is_eop_desc(struct xdp_desc *desc)
> +static inline bool xsk_is_eop_desc(const struct xdp_desc *desc)
>  {
>  	return !xp_mb_desc(desc);
>  }
> @@ -143,7 +143,7 @@ static inline void xsk_buff_add_frag(struct xdp_buff *xdp)
>  	list_add_tail(&frag->list_node, &frag->pool->xskb_list);
>  }
>  
> -static inline struct xdp_buff *xsk_buff_get_frag(struct xdp_buff *first)
> +static inline struct xdp_buff *xsk_buff_get_frag(const struct xdp_buff *first)
>  {
>  	struct xdp_buff_xsk *xskb = container_of(first, struct xdp_buff_xsk, xdp);
>  	struct xdp_buff *ret = NULL;
> @@ -200,7 +200,8 @@ static inline void *xsk_buff_raw_get_data(struct xsk_buff_pool *pool, u64 addr)
>  		XDP_TXMD_FLAGS_CHECKSUM | \
>  	0)
>  
> -static inline bool xsk_buff_valid_tx_metadata(struct xsk_tx_metadata *meta)
> +static inline bool
> +xsk_buff_valid_tx_metadata(const struct xsk_tx_metadata *meta)
>  {
>  	return !(meta->flags & ~XDP_TXMD_FLAGS_VALID);
>  }
> @@ -337,7 +338,7 @@ static inline struct xdp_buff *xsk_buff_alloc(struct xsk_buff_pool *pool)
>  	return NULL;
>  }
>  
> -static inline bool xsk_is_eop_desc(struct xdp_desc *desc)
> +static inline bool xsk_is_eop_desc(const struct xdp_desc *desc)
>  {
>  	return false;
>  }
> @@ -360,7 +361,7 @@ static inline void xsk_buff_add_frag(struct xdp_buff *xdp)
>  {
>  }
>  
> -static inline struct xdp_buff *xsk_buff_get_frag(struct xdp_buff *first)
> +static inline struct xdp_buff *xsk_buff_get_frag(const struct xdp_buff *first)
>  {
>  	return NULL;
>  }
> diff --git a/include/net/xsk_buff_pool.h b/include/net/xsk_buff_pool.h
> index bb03cee716b3..3832997cc605 100644
> --- a/include/net/xsk_buff_pool.h
> +++ b/include/net/xsk_buff_pool.h
> @@ -183,7 +183,7 @@ static inline bool xp_desc_crosses_non_contig_pg(struct xsk_buff_pool *pool,
>  	       !(pool->dma_pages[addr >> PAGE_SHIFT] & XSK_NEXT_PG_CONTIG_MASK);
>  }
>  
> -static inline bool xp_mb_desc(struct xdp_desc *desc)
> +static inline bool xp_mb_desc(const struct xdp_desc *desc)
>  {
>  	return desc->options & XDP_PKT_CONTD;
>  }
> -- 
> 2.46.2
> 

  reply	other threads:[~2024-10-17 11:14 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-15 14:53 [PATCH net-next v2 00/18] idpf: XDP chapter III: core XDP changes (+libeth_xdp) Alexander Lobakin
2024-10-15 14:53 ` [PATCH net-next v2 01/18] jump_label: export static_key_slow_{inc,dec}_cpuslocked() Alexander Lobakin
2024-10-17 11:06   ` Maciej Fijalkowski
2024-10-21 13:53     ` Alexander Lobakin
2024-10-22 12:52       ` Maciej Fijalkowski
2024-10-15 14:53 ` [PATCH net-next v2 02/18] skbuff: allow 2-4-argument skb_frag_dma_map() Alexander Lobakin
2024-10-15 14:53 ` [PATCH net-next v2 03/18] unroll: add generic loop unroll helpers Alexander Lobakin
2024-10-15 14:53 ` [PATCH net-next v2 04/18] bpf, xdp: constify some bpf_prog * function arguments Alexander Lobakin
2024-10-17 11:12   ` Maciej Fijalkowski
2024-10-21 13:56     ` Alexander Lobakin
2024-10-22 12:55       ` Maciej Fijalkowski
2024-10-15 14:53 ` [PATCH net-next v2 05/18] xdp, xsk: constify read-only arguments of some static inline helpers Alexander Lobakin
2024-10-17 11:14   ` Maciej Fijalkowski [this message]
2024-10-21 13:57     ` Alexander Lobakin
2024-10-15 14:53 ` [PATCH net-next v2 06/18] xdp: allow attaching already registered memory model to xdp_rxq_info Alexander Lobakin
2024-10-15 14:53 ` [PATCH net-next v2 07/18] net: Register system page pool as an XDP memory model Alexander Lobakin
2024-10-17 11:32   ` Maciej Fijalkowski
2024-10-21 14:00     ` Alexander Lobakin
2024-10-15 14:53 ` [PATCH net-next v2 08/18] page_pool: make page_pool_put_page_bulk() actually handle array of pages Alexander Lobakin
2024-10-17 11:33   ` Maciej Fijalkowski
2024-10-21 14:03     ` Alexander Lobakin
2024-10-15 14:53 ` [PATCH net-next v2 09/18] page_pool: allow mixing PPs within one bulk Alexander Lobakin
2024-10-15 14:53 ` [PATCH net-next v2 10/18] xdp: get rid of xdp_frame::mem.id Alexander Lobakin
2024-10-15 14:53 ` [PATCH net-next v2 11/18] xdp: add generic xdp_buff_add_frag() Alexander Lobakin
2024-10-17 12:26   ` Maciej Fijalkowski
2024-10-21 14:10     ` Alexander Lobakin
2024-10-22 13:00       ` Maciej Fijalkowski
2024-10-15 14:53 ` [PATCH net-next v2 12/18] xdp: add generic xdp_build_skb_from_buff() Alexander Lobakin
2024-10-17 12:34   ` Maciej Fijalkowski
2024-10-21 14:20     ` Alexander Lobakin
2024-10-15 14:53 ` [PATCH net-next v2 13/18] xsk: allow attaching XSk pool via xdp_rxq_info_reg_mem_model() Alexander Lobakin
2024-10-17 12:49   ` Maciej Fijalkowski
2024-10-21 14:23     ` Alexander Lobakin
2024-10-15 14:53 ` [PATCH net-next v2 14/18] xsk: make xsk_buff_add_frag really add a frag via __xdp_buff_add_frag() Alexander Lobakin
2024-10-17 13:04   ` Maciej Fijalkowski
2024-10-15 14:53 ` [PATCH net-next v2 15/18] xsk: add generic XSk &xdp_buff -> skb conversion Alexander Lobakin
2024-10-18 12:48   ` Maciej Fijalkowski
2024-10-15 14:53 ` [PATCH net-next v2 16/18] xsk: add helper to get &xdp_desc's DMA and meta pointer in one go Alexander Lobakin
2024-10-22 15:42   ` Maciej Fijalkowski
2024-10-23 14:50     ` Alexander Lobakin
2024-10-15 14:53 ` [PATCH net-next v2 17/18] libeth: support native XDP and register memory model Alexander Lobakin
2024-10-15 14:53 ` [PATCH net-next v2 18/18] libeth: add a couple of XDP helpers (libeth_xdp) Alexander Lobakin

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=ZxDxjj4SPT0Y9KyP@boxer \
    --to=maciej.fijalkowski@intel.com \
    --cc=aleksander.lobakin@intel.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=magnus.karlsson@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=nex.sw.ncis.osdt.itp.upstreaming@intel.com \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=toke@redhat.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).