Re: [PATCH v2 2/2] virtio-net: make all RX paths handle erors consistently

2013-12-01 Thread David Miller
From: "Michael S. Tsirkin" 
Date: Thu, 28 Nov 2013 13:30:59 +0200

> receive mergeable now handles errors internally.
> Do same for big and small packet paths, otherwise
> the logic is too hard to follow.
> 
> Signed-off-by: Michael S. Tsirkin 
> Acked-by: Jason Wang 

Applied and I fixed the subject text to use an underscore '_' instead
of a dash '-' for "virtio_net: ".
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 2/2] virtio-net: make all RX paths handle erors consistently

2013-12-01 Thread David Miller
From: Michael S. Tsirkin m...@redhat.com
Date: Thu, 28 Nov 2013 13:30:59 +0200

 receive mergeable now handles errors internally.
 Do same for big and small packet paths, otherwise
 the logic is too hard to follow.
 
 Signed-off-by: Michael S. Tsirkin m...@redhat.com
 Acked-by: Jason Wang jasow...@redhat.com

Applied and I fixed the subject text to use an underscore '_' instead
of a dash '-' for virtio_net: .
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 2/2] virtio-net: make all RX paths handle erors consistently

2013-11-28 Thread Michael S. Tsirkin
receive mergeable now handles errors internally.
Do same for big and small packet paths, otherwise
the logic is too hard to follow.

Signed-off-by: Michael S. Tsirkin 
Acked-by: Jason Wang 
---

I don't see a bug in current code but I think it's still
a good idea to queue this in 3.13, for consistency.

 drivers/net/virtio_net.c | 54 +---
 1 file changed, 37 insertions(+), 17 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 5408de6..4b01946 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -299,6 +299,35 @@ static struct sk_buff *page_to_skb(struct receive_queue 
*rq,
return skb;
 }
 
+static struct sk_buff *receive_small(void *buf, unsigned int len)
+{
+   struct sk_buff * skb = buf;
+
+   len -= sizeof(struct virtio_net_hdr);
+   skb_trim(skb, len);
+
+   return skb;
+}
+
+static struct sk_buff *receive_big(struct net_device *dev,
+  struct receive_queue *rq,
+  void *buf,
+  unsigned int len)
+{
+   struct page *page = buf;
+   struct sk_buff *skb = page_to_skb(rq, page, 0, len, PAGE_SIZE);
+
+   if (unlikely(!skb))
+   goto err;
+
+   return skb;
+
+err:
+   dev->stats.rx_dropped++;
+   give_pages(rq, page);
+   return NULL;
+}
+
 static struct sk_buff *receive_mergeable(struct net_device *dev,
 struct receive_queue *rq,
 void *buf,
@@ -392,7 +421,6 @@ static void receive_buf(struct receive_queue *rq, void 
*buf, unsigned int len)
struct net_device *dev = vi->dev;
struct virtnet_stats *stats = this_cpu_ptr(vi->stats);
struct sk_buff *skb;
-   struct page *page;
struct skb_vnet_hdr *hdr;
 
if (unlikely(len < sizeof(struct virtio_net_hdr) + ETH_HLEN)) {
@@ -407,23 +435,15 @@ static void receive_buf(struct receive_queue *rq, void 
*buf, unsigned int len)
return;
}
 
-   if (!vi->mergeable_rx_bufs && !vi->big_packets) {
-   skb = buf;
-   len -= sizeof(struct virtio_net_hdr);
-   skb_trim(skb, len);
-   } else if (vi->mergeable_rx_bufs) {
+   if (vi->mergeable_rx_bufs)
skb = receive_mergeable(dev, rq, buf, len);
-   if (unlikely(!skb))
-   return;
-   } else {
-   page = buf;
-   skb = page_to_skb(rq, page, 0, len, PAGE_SIZE);
-   if (unlikely(!skb)) {
-   dev->stats.rx_dropped++;
-   give_pages(rq, page);
-   return;
-   }
-   }
+   else if (vi->big_packets)
+   skb = receive_big(dev, rq, buf, len);
+   else
+   skb = receive_small(buf, len);
+
+   if (unlikely(!skb))
+   return;
 
hdr = skb_vnet_hdr(skb);
 
-- 
MST

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 2/2] virtio-net: make all RX paths handle erors consistently

2013-11-28 Thread Michael S. Tsirkin
receive mergeable now handles errors internally.
Do same for big and small packet paths, otherwise
the logic is too hard to follow.

Signed-off-by: Michael S. Tsirkin m...@redhat.com
Acked-by: Jason Wang jasow...@redhat.com
---

I don't see a bug in current code but I think it's still
a good idea to queue this in 3.13, for consistency.

 drivers/net/virtio_net.c | 54 +---
 1 file changed, 37 insertions(+), 17 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 5408de6..4b01946 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -299,6 +299,35 @@ static struct sk_buff *page_to_skb(struct receive_queue 
*rq,
return skb;
 }
 
+static struct sk_buff *receive_small(void *buf, unsigned int len)
+{
+   struct sk_buff * skb = buf;
+
+   len -= sizeof(struct virtio_net_hdr);
+   skb_trim(skb, len);
+
+   return skb;
+}
+
+static struct sk_buff *receive_big(struct net_device *dev,
+  struct receive_queue *rq,
+  void *buf,
+  unsigned int len)
+{
+   struct page *page = buf;
+   struct sk_buff *skb = page_to_skb(rq, page, 0, len, PAGE_SIZE);
+
+   if (unlikely(!skb))
+   goto err;
+
+   return skb;
+
+err:
+   dev-stats.rx_dropped++;
+   give_pages(rq, page);
+   return NULL;
+}
+
 static struct sk_buff *receive_mergeable(struct net_device *dev,
 struct receive_queue *rq,
 void *buf,
@@ -392,7 +421,6 @@ static void receive_buf(struct receive_queue *rq, void 
*buf, unsigned int len)
struct net_device *dev = vi-dev;
struct virtnet_stats *stats = this_cpu_ptr(vi-stats);
struct sk_buff *skb;
-   struct page *page;
struct skb_vnet_hdr *hdr;
 
if (unlikely(len  sizeof(struct virtio_net_hdr) + ETH_HLEN)) {
@@ -407,23 +435,15 @@ static void receive_buf(struct receive_queue *rq, void 
*buf, unsigned int len)
return;
}
 
-   if (!vi-mergeable_rx_bufs  !vi-big_packets) {
-   skb = buf;
-   len -= sizeof(struct virtio_net_hdr);
-   skb_trim(skb, len);
-   } else if (vi-mergeable_rx_bufs) {
+   if (vi-mergeable_rx_bufs)
skb = receive_mergeable(dev, rq, buf, len);
-   if (unlikely(!skb))
-   return;
-   } else {
-   page = buf;
-   skb = page_to_skb(rq, page, 0, len, PAGE_SIZE);
-   if (unlikely(!skb)) {
-   dev-stats.rx_dropped++;
-   give_pages(rq, page);
-   return;
-   }
-   }
+   else if (vi-big_packets)
+   skb = receive_big(dev, rq, buf, len);
+   else
+   skb = receive_small(buf, len);
+
+   if (unlikely(!skb))
+   return;
 
hdr = skb_vnet_hdr(skb);
 
-- 
MST

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/