All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] xen-netback: fix xenvif_count_skb_slots()
@ 2013-10-04 16:26 Paul Durrant
  2013-10-07  0:06 ` Matt Wilson
                   ` (7 more replies)
  0 siblings, 8 replies; 24+ messages in thread
From: Paul Durrant @ 2013-10-04 16:26 UTC (permalink / raw)
  To: xen-devel, netdev
  Cc: Paul Durrant, Xi Xiong, Matt Wilson, Annie Li, Wei Liu, Ian Campbell

Commit 4f0581d25827d5e864bcf07b05d73d0d12a20a5c introduced an error into
xenvif_count_skb_slots() for skbs with a linear area spanning a page
boundary. The alignment of skb->data needs to be taken into account, not
just the head length. This patch fixes the issue by dry-running the code
from xenvif_gop_skb() (and adjusting the comment above the function to note
that).

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Cc: Xi Xiong <xixiong@amazon.com>
Cc: Matt Wilson <msw@amazon.com>
Cc: Annie Li <annie.li@oracle.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Cc: Ian Campbell <Ian.Campbell@citrix.com>

---
 drivers/net/xen-netback/netback.c |   17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index d0b0feb..6f680f4 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -223,15 +223,28 @@ static bool start_new_rx_buffer(int offset, unsigned long size, int head)
 /*
  * Figure out how many ring slots we're going to need to send @skb to
  * the guest. This function is essentially a dry run of
- * xenvif_gop_frag_copy.
+ * xenvif_gop_skb.
  */
 unsigned int xenvif_count_skb_slots(struct xenvif *vif, struct sk_buff *skb)
 {
+	unsigned char *data;
 	unsigned int count;
 	int i, copy_off;
 	struct skb_cb_overlay *sco;
 
-	count = DIV_ROUND_UP(skb_headlen(skb), PAGE_SIZE);
+	count = 0;
+
+	data = skb->data;
+	while (data < skb_tail_pointer(skb)) {
+		unsigned int offset = offset_in_page(data);
+		unsigned int len = PAGE_SIZE - offset;
+
+		if (data + len > skb_tail_pointer(skb))
+			len = skb_tail_pointer(skb) - data;
+
+		count++;
+		data += len;
+	}
 
 	copy_off = skb_headlen(skb) % PAGE_SIZE;
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 24+ messages in thread
* [PATCH net-next] xen-netback: fix xenvif_count_skb_slots()
@ 2013-10-04 16:26 Paul Durrant
  0 siblings, 0 replies; 24+ messages in thread
From: Paul Durrant @ 2013-10-04 16:26 UTC (permalink / raw)
  To: xen-devel, netdev
  Cc: Wei Liu, Ian Campbell, Annie Li, Paul Durrant, Matt Wilson, Xi Xiong

Commit 4f0581d25827d5e864bcf07b05d73d0d12a20a5c introduced an error into
xenvif_count_skb_slots() for skbs with a linear area spanning a page
boundary. The alignment of skb->data needs to be taken into account, not
just the head length. This patch fixes the issue by dry-running the code
from xenvif_gop_skb() (and adjusting the comment above the function to note
that).

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Cc: Xi Xiong <xixiong@amazon.com>
Cc: Matt Wilson <msw@amazon.com>
Cc: Annie Li <annie.li@oracle.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Cc: Ian Campbell <Ian.Campbell@citrix.com>

---
 drivers/net/xen-netback/netback.c |   17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index d0b0feb..6f680f4 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -223,15 +223,28 @@ static bool start_new_rx_buffer(int offset, unsigned long size, int head)
 /*
  * Figure out how many ring slots we're going to need to send @skb to
  * the guest. This function is essentially a dry run of
- * xenvif_gop_frag_copy.
+ * xenvif_gop_skb.
  */
 unsigned int xenvif_count_skb_slots(struct xenvif *vif, struct sk_buff *skb)
 {
+	unsigned char *data;
 	unsigned int count;
 	int i, copy_off;
 	struct skb_cb_overlay *sco;
 
-	count = DIV_ROUND_UP(skb_headlen(skb), PAGE_SIZE);
+	count = 0;
+
+	data = skb->data;
+	while (data < skb_tail_pointer(skb)) {
+		unsigned int offset = offset_in_page(data);
+		unsigned int len = PAGE_SIZE - offset;
+
+		if (data + len > skb_tail_pointer(skb))
+			len = skb_tail_pointer(skb) - data;
+
+		count++;
+		data += len;
+	}
 
 	copy_off = skb_headlen(skb) % PAGE_SIZE;
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2013-10-07 20:03 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-04 16:26 [PATCH net-next] xen-netback: fix xenvif_count_skb_slots() Paul Durrant
2013-10-07  0:06 ` Matt Wilson
2013-10-07  0:06 ` Matt Wilson
2013-10-07  0:07   ` Matt Wilson
2013-10-07 10:17     ` Paul Durrant
2013-10-07 10:17     ` Paul Durrant
2013-10-07  0:07   ` Matt Wilson
2013-10-07  9:50 ` David Vrabel
2013-10-07  9:50 ` [Xen-devel] " David Vrabel
2013-10-07 10:23   ` Paul Durrant
2013-10-07 10:37     ` Paul Durrant
2013-10-07 10:37     ` [Xen-devel] " Paul Durrant
2013-10-07 10:53       ` Wei Liu
2013-10-07 10:53       ` [Xen-devel] " Wei Liu
2013-10-07 10:23   ` Paul Durrant
2013-10-07 10:01 ` Wei Liu
2013-10-07 10:12   ` Paul Durrant
2013-10-07 10:12   ` Paul Durrant
2013-10-07 10:01 ` Wei Liu
2013-10-07 19:36 ` David Miller
2013-10-07 20:03   ` Ian Campbell
2013-10-07 20:03   ` Ian Campbell
2013-10-07 19:36 ` David Miller
2013-10-04 16:26 Paul Durrant

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.