From: Dor Laor <dor.laor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: kvm-devel
<kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>,
virtualization
<virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>,
Rusty Russell <rusty-8n+1lVoiYb80n/F98K4Iww@public.gmane.org>,
Anthony Liguori
<aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>,
Subject: [Virtio-for-kvm] [PATCH 7/13] [Mostly resend] virtio additions
Date: Fri, 21 Dec 2007 17:24:21 +0200 [thread overview]
Message-ID: <476BDAA5.20406@qumranet.com> (raw)
From e49289d5a2137118a61b00a184a07f47ba9d04f5 Mon Sep 17 00:00:00 2001
From: Anthony Liguori <aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
Date: Wed, 7 Nov 2007 20:46:31 -0600
Subject: [PATCH] virtio: free transmit skbs when notified, not on next xmit.
This fixes a potential dangling xmit problem.
We also suppress refill interrupts until we need them.
Signed-off-by: Rusty Russell <rusty-8n+1lVoiYb80n/F98K4Iww@public.gmane.org>
---
drivers/net/virtio_net.c | 69
++++++++++++++++++++++++++++++++-------------
1 files changed, 49 insertions(+), 20 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 6526e0b..c4f970e 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -35,6 +35,8 @@ struct virtnet_info
struct net_device *dev;
struct napi_struct napi;
+ struct tasklet_struct xmit_free;
+
/* TX coalescing. */
struct hrtimer tx_timer;
@@ -59,13 +61,40 @@ static inline void vnet_hdr_to_sg(struct scatterlist
*sg, struct sk_buff *skb)
sg_init_one(sg, skb_vnet_hdr(skb), sizeof(struct virtio_net_hdr));
}
-static bool skb_xmit_done(struct virtqueue *rvq)
+static unsigned free_old_xmit_skbs(struct virtnet_info *vi)
{
- struct virtnet_info *vi = rvq->vdev->priv;
+ struct sk_buff *skb;
+ unsigned int len, i = 0;
+
+ while ((skb = vi->svq->vq_ops->get_buf(vi->svq, &len)) != NULL) {
+ pr_debug("Sent skb %p\n", skb);
+ __skb_unlink(skb, &vi->send);
+ vi->dev->stats.tx_bytes += len;
+ vi->dev->stats.tx_packets++;
+ kfree_skb(skb);
+ i++;
+ }
+ return i;
+}
+
+static void xmit_free(unsigned long data)
+{
+ struct virtnet_info *vi = (void *)data;
+
+ netif_tx_lock(vi->dev);
+ free_old_xmit_skbs(vi);
+ netif_tx_unlock(vi->dev);
/* In case we were waiting for output buffers. */
netif_wake_queue(vi->dev);
- return true;
+}
+
+static bool skb_xmit_done(struct virtqueue *rvq)
+{
+ struct virtnet_info *vi = rvq->vdev->priv;
+
+ tasklet_schedule(&vi->xmit_free);
+ return false;
}
static void receive_skb(struct net_device *dev, struct sk_buff *skb,
@@ -216,20 +245,6 @@ again:
return received;
}
-static void free_old_xmit_skbs(struct virtnet_info *vi)
-{
- struct sk_buff *skb;
- unsigned int len;
-
- while ((skb = vi->svq->vq_ops->get_buf(vi->svq, &len)) != NULL) {
- pr_debug("Sent skb %p\n", skb);
- __skb_unlink(skb, &vi->send);
- vi->dev->stats.tx_bytes += len;
- vi->dev->stats.tx_packets++;
- kfree_skb(skb);
- }
-}
-
static enum hrtimer_restart kick_xmit(struct hrtimer *t)
{
struct virtnet_info *vi = container_of(t,struct virtnet_info,tx_timer);
@@ -257,8 +272,6 @@ static int start_xmit(struct sk_buff *skb, struct
net_device *dev)
pr_debug("%s: xmit %p %s\n", dev->name, skb, print_mac(mac, dest));
- free_old_xmit_skbs(vi);
-
/* Encode metadata header at front. */
hdr = skb_vnet_hdr(skb);
if (skb->ip_summed == CHECKSUM_PARTIAL) {
@@ -290,10 +303,24 @@ static int start_xmit(struct sk_buff *skb, struct
net_device *dev)
vnet_hdr_to_sg(sg, skb);
num = skb_to_sgvec(skb, sg+1, 0, skb->len) + 1;
__skb_queue_head(&vi->send, skb);
+
+again:
err = vi->svq->vq_ops->add_buf(vi->svq, sg, num, 0, skb);
if (err) {
+ /* Can we free any used skbs? */
+ if (free_old_xmit_skbs(vi))
+ goto again;
+
+ /* Activate callback for using skbs: if this fails it
+ * means some were used in the meantime. */
+ if (unlikely(!vi->svq->vq_ops->restart(vi->svq))) {
+ printk("Unlikely: restart svq failed\n");
+ goto again;
+ }
+
+ __skb_unlink(skb, &vi->send);
+
pr_debug("%s: virtio not prepared to send\n", dev->name);
- skb_unlink(skb, &vi->send);
if (vi->out_max != vi->out_num)
printk("%s: out_max changed from %u to %u\n",
dev->name, vi->out_max, vi->out_num);
@@ -403,6 +430,8 @@ static int virtnet_probe(struct virtio_device *vdev)
vi->tx_timer.cb_mode = HRTIMER_CB_SOFTIRQ;
vi->out_max = -1U;
+ tasklet_init(&vi->xmit_free, xmit_free, (unsigned long)vi);
+
/* We expect two virtqueues, receive then send. */
vi->rvq = vdev->config->find_vq(vdev, 0, skb_recv_done);
if (IS_ERR(vi->rvq)) {
--
1.5.3.3
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
reply other threads:[~2007-12-21 15:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=476BDAA5.20406@qumranet.com \
--to=dor.laor-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org \
--cc=dor.laor-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
--cc=rusty-8n+1lVoiYb80n/F98K4Iww@public.gmane.org \
--cc=virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.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.