linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Matteo Croce <mcroce@linux.microsoft.com>, netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Julia Lawall <julia.lawall@inria.fr>
Subject: Re: [PATCH net-next v2 2/3] net: use skb_for_each_frag() helper where possible
Date: Mon, 12 Apr 2021 09:40:13 +0200	[thread overview]
Message-ID: <44e9ef55-cafd-6613-938b-381ff84d3fc5@gmail.com> (raw)
In-Reply-To: <20210412003802.51613-3-mcroce@linux.microsoft.com>



On 4/12/21 2:38 AM, Matteo Croce wrote:
> From: Matteo Croce <mcroce@microsoft.com>
> 
> use the new helper macro skb_for_each_frag() which allows to iterate
> through all the SKB fragments.
> 
> The patch was created with Coccinelle, this was the semantic patch:
> 
> @@
> struct sk_buff *skb;
> identifier i;
> statement S;
> iterator name skb_for_each_frag;
> @@
> -for (i = 0; i < skb_shinfo(skb)->nr_frags; \(++i\|i++\))
> +skb_for_each_frag(skb, i)
>  S
> @@
> struct skb_shared_info *sinfo;
> struct sk_buff *skb;
> identifier i;
> statement S;
> iterator name skb_for_each_frag;
> @@


I disagree with this part :

>  sinfo = skb_shinfo(skb)
>  ...
> -for (i = 0; i < sinfo->nr_frags; \(++i\|i++\))
> +skb_for_each_frag(skb, i)
>  S
>


> index bde781f46b41..5de00477eaf9 100644
> --- a/net/ipv4/tcp_output.c
> +++ b/net/ipv4/tcp_output.c
> @@ -1644,7 +1644,7 @@ static int __pskb_trim_head(struct sk_buff *skb, int len)
>  	eat = len;
>  	k = 0;
>  	shinfo = skb_shinfo(skb);
> -	for (i = 0; i < shinfo->nr_frags; i++) {
> +	skb_for_each_frag(skb, i) {
>  		int size = skb_frag_size(&shinfo->frags[i]);
>  
>  		if (size <= eat) {

This will force the compiler to re-evaluate skb_shinfo(skb)->nr_frags in the loop,
since atomic operations like skb_frag_unref() have a memory clobber.

skb_shinfo(skb)->nr_frags has to reload three vars.

The macro should only be used when the code had

for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)



  reply	other threads:[~2021-04-12  7:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-12  0:37 [PATCH net-next v2 0/3] introduce skb_for_each_frag() Matteo Croce
2021-04-12  0:38 ` [PATCH net-next v2 1/3] skbuff: add helper to walk over the fraglist Matteo Croce
2021-04-12  0:38 ` [PATCH net-next v2 2/3] net: use skb_for_each_frag() helper where possible Matteo Croce
2021-04-12  7:40   ` Eric Dumazet [this message]
2021-04-12  0:38 ` [PATCH net-next v2 3/3] net: use skb_for_each_frag() in illegal_highdma() Matteo Croce
2021-04-13  7:53 ` [PATCH net-next v2 0/3] introduce skb_for_each_frag() David Laight
2021-04-16 22:44   ` Matteo Croce
2021-04-17 11:07     ` David Laight

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=44e9ef55-cafd-6613-938b-381ff84d3fc5@gmail.com \
    --to=eric.dumazet@gmail.com \
    --cc=davem@davemloft.net \
    --cc=julia.lawall@inria.fr \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcroce@linux.microsoft.com \
    --cc=netdev@vger.kernel.org \
    /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).