netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ian Campbell <ian.campbell@citrix.com>
To: netdev@vger.kernel.org
Cc: Ian Campbell <ian.campbell@citrix.com>,
	xen-devel@lists.xen.org, Eric Dumazet <edumazet@google.com>,
	Konrad Rzeszutek Wilk <konrad@kernel.org>,
	ANNIE LI <annie.li@oracle.com>,
	Sander Eikelenboom <linux@eikelenboom.it>,
	Stefan Bader <stefan.bader@canonical.com>
Subject: [PATCH] xen/netfront: handle compound page fragments on transmit
Date: Tue, 20 Nov 2012 11:40:06 +0000	[thread overview]
Message-ID: <1353411606-15940-1-git-send-email-ian.campbell@citrix.com> (raw)
In-Reply-To: <1353403286.18229.159.camel@zakaz.uk.xensource.com>

An SKB paged fragment can consist of a compound page with order > 0.
However the netchannel protocol deals only in PAGE_SIZE frames.

Handle this in xennet_make_frags by iterating over the frames which
make up the page.

This is the netfront equivalent to 6a8ed462f16b for netback.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Cc: netdev@vger.kernel.org
Cc: xen-devel@lists.xen.org
Cc: Eric Dumazet <edumazet@google.com>
Cc: Konrad Rzeszutek Wilk <konrad@kernel.org>
Cc: ANNIE LI <annie.li@oracle.com>
Cc: Sander Eikelenboom <linux@eikelenboom.it>
Cc: Stefan Bader <stefan.bader@canonical.com>
---
 drivers/net/xen-netfront.c |   58 +++++++++++++++++++++++++++++++++----------
 1 files changed, 44 insertions(+), 14 deletions(-)

diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index caa0110..a12b99a 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -452,24 +452,54 @@ static void xennet_make_frags(struct sk_buff *skb, struct net_device *dev,
 	/* Grant backend access to each skb fragment page. */
 	for (i = 0; i < frags; i++) {
 		skb_frag_t *frag = skb_shinfo(skb)->frags + i;
+		struct page *page = skb_frag_page(frag);
+		unsigned long size = skb_frag_size(frag);
+		unsigned long offset = frag->page_offset;
 
-		tx->flags |= XEN_NETTXF_more_data;
+		/* Data must not cross a page boundary. */
+		BUG_ON(size + offset > PAGE_SIZE<<compound_order(page));
 
-		id = get_id_from_freelist(&np->tx_skb_freelist, np->tx_skbs);
-		np->tx_skbs[id].skb = skb_get(skb);
-		tx = RING_GET_REQUEST(&np->tx, prod++);
-		tx->id = id;
-		ref = gnttab_claim_grant_reference(&np->gref_tx_head);
-		BUG_ON((signed short)ref < 0);
+		/* Skip unused frames from start of page */
+		page += offset >> PAGE_SHIFT;
+		offset &= ~PAGE_MASK;
 
-		mfn = pfn_to_mfn(page_to_pfn(skb_frag_page(frag)));
-		gnttab_grant_foreign_access_ref(ref, np->xbdev->otherend_id,
-						mfn, GNTMAP_readonly);
+		while (size > 0) {
+			unsigned long bytes;
 
-		tx->gref = np->grant_tx_ref[id] = ref;
-		tx->offset = frag->page_offset;
-		tx->size = skb_frag_size(frag);
-		tx->flags = 0;
+			BUG_ON(offset >= PAGE_SIZE);
+
+			bytes = PAGE_SIZE - offset;
+			if (bytes > size)
+				bytes = size;
+
+			tx->flags |= XEN_NETTXF_more_data;
+
+			id = get_id_from_freelist(&np->tx_skb_freelist, np->tx_skbs);
+			np->tx_skbs[id].skb = skb_get(skb);
+			tx = RING_GET_REQUEST(&np->tx, prod++);
+			tx->id = id;
+			ref = gnttab_claim_grant_reference(&np->gref_tx_head);
+			BUG_ON((signed short)ref < 0);
+
+			mfn = pfn_to_mfn(page_to_pfn(page));
+			gnttab_grant_foreign_access_ref(ref, np->xbdev->otherend_id,
+							mfn, GNTMAP_readonly);
+
+			tx->gref = np->grant_tx_ref[id] = ref;
+			tx->offset = offset;
+			tx->size = bytes;
+			tx->flags = 0;
+
+			offset += bytes;
+			size -= bytes;
+
+			/* Next frame */
+			if (offset == PAGE_SIZE && size) {
+				BUG_ON(!PageCompound(page));
+				page++;
+				offset = 0;
+			}
+		}
 	}
 
 	np->tx.req_prod_pvt = prod;
-- 
1.7.2.5

  parent reply	other threads:[~2012-11-20 11:40 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-09 13:47 compound skb frag pages appearing in start_xmit Ian Campbell
2012-10-09 13:54 ` Eric Dumazet
2012-10-09 14:01   ` Eric Dumazet
2012-10-09 14:23     ` Ian Campbell
2012-10-09 14:33       ` Eric Dumazet
2012-10-09 14:54         ` Ian Campbell
2012-10-09 14:17   ` Ian Campbell
2012-10-09 14:27     ` Eric Dumazet
2012-10-09 14:40       ` Ian Campbell
2012-10-09 14:51         ` Eric Dumazet
2012-10-10 10:13         ` [Xen-devel] " Ian Campbell
2012-10-10 12:24           ` Sander Eikelenboom
2012-10-10 12:29             ` [Xen-devel] " Ian Campbell
2012-10-10 13:31               ` Sander Eikelenboom
2012-10-10 13:09           ` Ian Campbell
2012-10-10 14:49             ` Sander Eikelenboom
2012-10-11  8:02               ` Ian Campbell
2012-10-11 10:00                 ` Sander Eikelenboom
2012-10-11 10:05                   ` Eric Dumazet
2012-10-11 10:14                     ` Ian Campbell
2012-10-11 10:20                       ` Sander Eikelenboom
2012-11-15  2:31                       ` ANNIE LI
2012-11-19 15:43                         ` Sander Eikelenboom
2012-11-20  8:30                           ` [Xen-devel] " Stefan Bader
2012-11-20  9:21                             ` Ian Campbell
2012-11-20 11:36                               ` [Xen-devel] " Ian Campbell
2012-11-21  2:42                                 ` ANNIE LI
2012-11-20 11:40                               ` Ian Campbell [this message]
2012-11-20 12:28                                 ` [Xen-devel] [PATCH] xen/netfront: handle compound page fragments on transmit Jan Beulich
2012-11-20 13:35                                   ` Ian Campbell
2012-11-20 13:51                                     ` Jan Beulich
2012-11-20 14:14                                       ` Ian Campbell
2012-11-20 14:32                                         ` Jan Beulich
2012-11-20 15:06                                           ` Ian Campbell
2012-11-20 15:28                                             ` Eric Dumazet
2012-11-20 15:54                                               ` Ian Campbell
2012-11-20 15:44                                             ` Jan Beulich
2012-11-20 16:14                                               ` Eric Dumazet
2012-11-20 13:30                                 ` Stefan Bader
2012-11-20 13:45                                   ` Sander Eikelenboom
2012-11-20 14:45                                 ` Eric Dumazet
2012-11-20 15:05                                   ` Ian Campbell
2012-11-21  2:52                                 ` ANNIE LI
2012-11-21 11:09                                   ` Ian Campbell

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=1353411606-15940-1-git-send-email-ian.campbell@citrix.com \
    --to=ian.campbell@citrix.com \
    --cc=annie.li@oracle.com \
    --cc=edumazet@google.com \
    --cc=konrad@kernel.org \
    --cc=linux@eikelenboom.it \
    --cc=netdev@vger.kernel.org \
    --cc=stefan.bader@canonical.com \
    --cc=xen-devel@lists.xen.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).