All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Ian Campbell <Ian.Campbell@citrix.com>
Cc: David Miller <davem@davemloft.net>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"eric.dumazet@gmail.com" <eric.dumazet@gmail.com>
Subject: Re: [PATCH RFC 1/6] skbuff: support per-page destructors in copy_ubufs
Date: Thu, 10 May 2012 21:42:46 +0300	[thread overview]
Message-ID: <20120510184246.GE14647@redhat.com> (raw)
In-Reply-To: <1336671977.14220.26.camel@zakaz.uk.xensource.com>

On Thu, May 10, 2012 at 06:46:17PM +0100, Ian Campbell wrote:
> On Mon, 2012-05-07 at 14:54 +0100, Michael S. Tsirkin wrote:
> 
> >  	/* skb frags point to kernel buffers */
> >  	for (i = skb_shinfo(skb)->nr_frags; i > 0; i--) {
> > +		skb_frag_t *f = &skb_shinfo(skb)->frags[i];
> 
> This needs to be ....->frags[i - 1]

Good catch.
  	for (i = skb_shinfo(skb)->nr_frags - 1; i >= 0; i--) {
		skb_frag_t *f = &skb_shinfo(skb)->frags[i];

would be a bit clearer though.

> otherwise you put every new frag one too high and don't do anything to
> frag 0, which leaves the old destructor pointer in place and leads to a
> double free.
> 
> I think skb_frag_set_destructor and skb_copy_frag_destructor need to
> clear and propagate respectively (or maybe just clear in both cases) the
> destructor_arg field since it is otherwise not initialised when we set
> SKBTX_DEV_ZEROCOPY and that can trigger wrong behaviour in this
> function.
> 
> Ian.

Agree, let's just clear it.



> > +		if (unlikely((!uarg && !f->page.destructor)))
> > +			continue;
> >  		__skb_fill_page_desc(skb, i-1, head, 0,
> >  				     skb_shinfo(skb)->frags[i - 1].size);
> >  		head = (struct page *)head->private;
> 

So the below on top then. I pushed these on
top of my zerocopy branch - can you confirm pls?

---

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 930a50e..e52bc8d 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -1270,8 +1270,10 @@ static inline void skb_frag_set_destructor(struct sk_buff *skb, int i,
 {
 	skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
 	frag->page.destructor = destroy;
-	if (destroy)
+	if (destroy) {
 		skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
+		skb_shinfo(skb)->destructor_arg = NULL;
+	}
 }
 
 /**
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index b7fc47e..453f621 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -753,12 +753,11 @@ int skb_copy_ubufs(struct sk_buff *skb, gfp_t gfp_mask)
 		uarg->callback(uarg);
 
 	/* skb frags point to kernel buffers */
-	for (i = skb_shinfo(skb)->nr_frags; i > 0; i--) {
+	for (i = skb_shinfo(skb)->nr_frags - 1; i >= 0; i--) {
 		skb_frag_t *f = &skb_shinfo(skb)->frags[i];
 		if (unlikely((!uarg && !f->page.destructor)))
 			continue;
-		__skb_fill_page_desc(skb, i-1, head, 0,
-				     skb_shinfo(skb)->frags[i - 1].size);
+		__skb_fill_page_desc(skb, i, head, 0, f->size);
 		head = (struct page *)head->private;
 	}
 

  reply	other threads:[~2012-05-10 18:42 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-07 13:53 [PATCH RFC 0/6] copy aside frags with destructors (was [PATCH 7/9] net: add skb_orphan_frags to copy aside frags with destructors) Michael S. Tsirkin
2012-05-07 13:54 ` [PATCH RFC 1/6] skbuff: support per-page destructors in copy_ubufs Michael S. Tsirkin
2012-05-10 17:46   ` Ian Campbell
2012-05-10 18:42     ` Michael S. Tsirkin [this message]
2012-05-11  9:00       ` Ian Campbell
2012-05-11 10:58         ` Ian Campbell
2012-05-11 12:08           ` Michael S. Tsirkin
2012-05-11 16:30             ` Michael S. Tsirkin
2012-05-12  6:01               ` Ian Campbell
2012-05-13 10:10                 ` Michael S. Tsirkin
2012-05-11 21:12             ` David Miller
2012-05-07 13:54 ` [PATCH RFC 2/6] skbuff: add an api to orphan frags Michael S. Tsirkin
2012-05-08 12:47   ` Michael S. Tsirkin
2012-05-07 13:54 ` [PATCH RFC 3/6] skbuff: convert to skb_orphan_frags Michael S. Tsirkin
2012-05-07 13:54 ` [PATCH RFC 4/6] tun: orphan frags on xmit Michael S. Tsirkin
2012-05-08 14:36   ` Michael S. Tsirkin
2012-05-07 13:54 ` [PATCH RFC 5/6] net: orphan frags on receive Michael S. Tsirkin
2012-05-09 13:54   ` Ian Campbell
2012-05-09 15:12     ` Michael S. Tsirkin
2012-05-14 19:18     ` Michael S. Tsirkin
2012-05-07 13:54 ` [PATCH RFC 6/6] skbuff: set zerocopy flag on frag destructor Michael S. Tsirkin
2012-05-08 12:46   ` Michael S. Tsirkin
2012-05-08  9:41 ` [PATCH RFC 0/6] copy aside frags with destructors (was [PATCH 7/9] net: add skb_orphan_frags to copy aside frags with destructors) Michael S. Tsirkin
2012-05-08 10:54   ` Ian Campbell
2012-05-08 14:49     ` Michael S. Tsirkin
2012-05-09 13:18 ` Ian Campbell
2012-05-09 13:52   ` Michael S. Tsirkin
2012-05-09 14:01     ` Ian Campbell
2012-05-09 15:27       ` Michael S. Tsirkin
2012-05-09 14:56     ` Michael S. Tsirkin

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=20120510184246.GE14647@redhat.com \
    --to=mst@redhat.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.