vhost_net: re-poll only on EAGAIN or ENOBUFS
authorJason Wang <jasowang@redhat.com>
Wed, 2 May 2012 03:42:32 +0000 (11:42 +0800)
committerMichael S. Tsirkin <mst@redhat.com>
Wed, 2 May 2012 15:22:24 +0000 (18:22 +0300)
Currently, we restart tx polling unconditionally when sendmsg()
fails. This would cause unnecessary wakeups of vhost wokers and waste
cpu utlization when evil userspace(guest driver) is able to hit EFAULT or
EINVAL.

The polling is only needed when the socket send buffer were exceeded or not
enough memory. So fix this by restarting polling only when sendmsg() returns
EAGAIN/ENOBUFS.

Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
drivers/vhost/net.c

index 35abe9019ba7b2d7242d54f819b7f6a4d57e506a..f54b1d5fc234eae0bcc3313d7709c5e3b8c619e0 100644 (file)
@@ -257,7 +257,8 @@ static void handle_tx(struct vhost_net *net)
                                        UIO_MAXIOV;
                        }
                        vhost_discard_vq_desc(vq, 1);
-                       tx_poll_start(net, sock);
+                       if (err == -EAGAIN || err == -ENOBUFS)
+                               tx_poll_start(net, sock);
                        break;
                }
                if (err != len)