From 4a7d6455b07845d92e025da222f11de519f90def Mon Sep 17 00:00:00 2001 From: Cong Ding Date: Mon, 3 Dec 2012 10:24:54 +0000 Subject: tools:virtio: fix compilation warning We do not allow old-style function definition. Always spell foo(void) if a function does not take any parameters. Signed-off-by: Cong Ding Signed-off-by: Michael S. Tsirkin diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c index e626fa5..6d25dcd 100644 --- a/tools/virtio/virtio_test.c +++ b/tools/virtio/virtio_test.c @@ -232,7 +232,7 @@ const struct option longopts[] = { } }; -static void help() +static void help(void) { fprintf(stderr, "Usage: virtio_test [--help]" " [--no-indirect]" -- cgit v0.10.2 From 935cdee7ee159569b0aaa10bd9244660f6672b08 Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Thu, 6 Dec 2012 14:03:34 +0200 Subject: vhost: avoid backend flush on vring ops vring changes already do a flush internally where appropriate, so we do not need a second flush. It's currently not very expensive but a follow-up patch makes flush more heavy-weight, so remove the extra flush here to avoid regressing performance if call or kick fds are changed on data path. Signed-off-by: Michael S. Tsirkin diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index ff6c919..1802ab6 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -942,8 +942,11 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl, return vhost_net_reset_owner(n); default: mutex_lock(&n->dev.mutex); - r = vhost_dev_ioctl(&n->dev, ioctl, arg); - vhost_net_flush(n); + r = vhost_dev_ioctl(&n->dev, ioctl, argp); + if (r == -ENOIOCTLCMD) + r = vhost_vring_ioctl(&n->dev, ioctl, argp); + else + vhost_net_flush(n); mutex_unlock(&n->dev.mutex); return r; } diff --git a/drivers/vhost/tcm_vhost.c b/drivers/vhost/tcm_vhost.c index ef88844..33e5f90 100644 --- a/drivers/vhost/tcm_vhost.c +++ b/drivers/vhost/tcm_vhost.c @@ -970,7 +970,10 @@ static long vhost_scsi_ioctl(struct file *f, unsigned int ioctl, return vhost_scsi_set_features(vs, features); default: mutex_lock(&vs->dev.mutex); - r = vhost_dev_ioctl(&vs->dev, ioctl, arg); + r = vhost_dev_ioctl(&vs->dev, ioctl, argp); + /* TODO: flush backend after dev ioctl. */ + if (r == -ENOIOCTLCMD) + r = vhost_vring_ioctl(&vs->dev, ioctl, argp); mutex_unlock(&vs->dev.mutex); return r; } diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 5a3d0f1..34389f7 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -607,7 +607,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m) return 0; } -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp) +long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp) { struct file *eventfp, *filep = NULL; bool pollstart = false, pollstop = false; @@ -802,9 +802,8 @@ static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp) } /* Caller must have device mutex */ -long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, unsigned long arg) +long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp) { - void __user *argp = (void __user *)arg; struct file *eventfp, *filep = NULL; struct eventfd_ctx *ctx = NULL; u64 p; @@ -875,7 +874,7 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, unsigned long arg) fput(filep); break; default: - r = vhost_set_vring(d, ioctl, argp); + r = -ENOIOCTLCMD; break; } done: diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 5e19e3d..2639c58 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -164,7 +164,8 @@ long vhost_dev_check_owner(struct vhost_dev *); long vhost_dev_reset_owner(struct vhost_dev *); void vhost_dev_cleanup(struct vhost_dev *, bool locked); void vhost_dev_stop(struct vhost_dev *); -long vhost_dev_ioctl(struct vhost_dev *, unsigned int ioctl, unsigned long arg); +long vhost_dev_ioctl(struct vhost_dev *, unsigned int ioctl, void __user *argp); +long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp); int vhost_vq_access_ok(struct vhost_virtqueue *vq); int vhost_log_access_ok(struct vhost_dev *); -- cgit v0.10.2 From 1280c27f8e29acf4af2da914e80ec27c3dbd5c01 Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Tue, 4 Dec 2012 00:17:14 +0200 Subject: vhost-net: flush outstanding DMAs on memory change When memory map changes, we need to flush outstanding DMAs as they might in theory reference old memory addresses. To do this simply stop initiating new DMAs and wait for ubufs ref count to drop to 0. Afterwards reset the count back to 1. Signed-off-by: Michael S. Tsirkin diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index 1802ab6..6a86deb 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -83,6 +83,8 @@ struct vhost_net { /* Number of times zerocopy TX recently failed. * Protected by tx vq lock. */ unsigned tx_zcopy_err; + /* Flush in progress. Protected by tx vq lock. */ + bool tx_flush; }; static void vhost_net_tx_packet(struct vhost_net *net) @@ -101,7 +103,11 @@ static void vhost_net_tx_err(struct vhost_net *net) static bool vhost_net_tx_select_zcopy(struct vhost_net *net) { - return net->tx_packets / 64 >= net->tx_zcopy_err; + /* TX flush waits for outstanding DMAs to be done. + * Don't start new DMAs. + */ + return !net->tx_flush && + net->tx_packets / 64 >= net->tx_zcopy_err; } static bool vhost_sock_zcopy(struct socket *sock) @@ -679,6 +685,17 @@ static void vhost_net_flush(struct vhost_net *n) { vhost_net_flush_vq(n, VHOST_NET_VQ_TX); vhost_net_flush_vq(n, VHOST_NET_VQ_RX); + if (n->dev.vqs[VHOST_NET_VQ_TX].ubufs) { + mutex_lock(&n->dev.vqs[VHOST_NET_VQ_TX].mutex); + n->tx_flush = true; + mutex_unlock(&n->dev.vqs[VHOST_NET_VQ_TX].mutex); + /* Wait for all lower device DMAs done. */ + vhost_ubuf_put_and_wait(n->dev.vqs[VHOST_NET_VQ_TX].ubufs); + mutex_lock(&n->dev.vqs[VHOST_NET_VQ_TX].mutex); + n->tx_flush = false; + kref_init(&n->dev.vqs[VHOST_NET_VQ_TX].ubufs->kref); + mutex_unlock(&n->dev.vqs[VHOST_NET_VQ_TX].mutex); + } } static int vhost_net_release(struct inode *inode, struct file *f) @@ -686,18 +703,10 @@ static int vhost_net_release(struct inode *inode, struct file *f) struct vhost_net *n = f->private_data; struct socket *tx_sock; struct socket *rx_sock; - int i; vhost_net_stop(n, &tx_sock, &rx_sock); vhost_net_flush(n); vhost_dev_stop(&n->dev); - for (i = 0; i < n->dev.nvqs; ++i) { - /* Wait for all lower device DMAs done. */ - if (n->dev.vqs[i].ubufs) - vhost_ubuf_put_and_wait(n->dev.vqs[i].ubufs); - - vhost_zerocopy_signal_used(n, &n->dev.vqs[i]); - } vhost_dev_cleanup(&n->dev, false); if (tx_sock) fput(tx_sock->file); @@ -826,6 +835,7 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd) n->tx_packets = 0; n->tx_zcopy_err = 0; + n->tx_flush = false; } mutex_unlock(&vq->mutex); -- cgit v0.10.2 From cedb9bdce099206290a2bdd02ce47a7b253b6a84 Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Thu, 6 Dec 2012 17:00:18 +0200 Subject: vhost-net: skip head management if no outstanding For short packets zerocopy mode adds overhead of managing heads which isn't necessary: we could simly update used ring directly same as with zerocopy disabled. Things seem to run a bit faster if we detect and bypass head management when zcopy isn't used. Signed-off-by: Michael S. Tsirkin diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index 6a86deb..aa76ca7 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -241,7 +241,7 @@ static void handle_tx(struct vhost_net *net) size_t hdr_size; struct socket *sock; struct vhost_ubuf_ref *uninitialized_var(ubufs); - bool zcopy; + bool zcopy, zcopy_used; /* TODO: check that we are running from vhost_worker? */ sock = rcu_dereference_check(vq->private_data, 1); @@ -319,8 +319,11 @@ static void handle_tx(struct vhost_net *net) iov_length(vq->hdr, s), hdr_size); break; } + zcopy_used = zcopy && (len >= VHOST_GOODCOPY_LEN || + vq->upend_idx != vq->done_idx); + /* use msg_control to pass vhost zerocopy ubuf info to skb */ - if (zcopy) { + if (zcopy_used) { vq->heads[vq->upend_idx].id = head; if (!vhost_net_tx_select_zcopy(net) || len < VHOST_GOODCOPY_LEN) { @@ -348,7 +351,7 @@ static void handle_tx(struct vhost_net *net) /* TODO: Check specific error and bomb out unless ENOBUFS? */ err = sock->ops->sendmsg(NULL, sock, &msg, len); if (unlikely(err < 0)) { - if (zcopy) { + if (zcopy_used) { if (ubufs) vhost_ubuf_put(ubufs); vq->upend_idx = ((unsigned)vq->upend_idx - 1) % @@ -362,7 +365,7 @@ static void handle_tx(struct vhost_net *net) if (err != len) pr_debug("Truncated TX packet: " " len %d != %zd\n", err, len); - if (!zcopy) + if (!zcopy_used) vhost_add_used_and_signal(&net->dev, vq, head, 0); else vhost_zerocopy_signal_used(net, vq); -- cgit v0.10.2 From f9611c43ab0ddaf547b395c90fb842f55959334c Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Thu, 6 Dec 2012 14:56:00 +0200 Subject: vhost-net: enable zerocopy tx by default Zero copy TX has been around for a while now. We seem to be down to eliminating theoretical bugs and performance tuning at this point: it's probably time to enable it by default so that most users get the benefit. Keep the flag around meanwhile so users can experiment with disabling this if they experience regressions. I expect that we will remove it in the future. Signed-off-by: Michael S. Tsirkin diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index aa76ca7..ebd08b2 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -30,9 +30,10 @@ #include "vhost.h" -static int experimental_zcopytx; +static int experimental_zcopytx = 1; module_param(experimental_zcopytx, int, 0444); -MODULE_PARM_DESC(experimental_zcopytx, "Enable Experimental Zero Copy TX"); +MODULE_PARM_DESC(experimental_zcopytx, "Enable Zero Copy TX;" + " 1 -Enable; 0 - Disable"); /* Max number of bytes transferred before requeueing the job. * Using this limit prevents one virtqueue from starving others. */ -- cgit v0.10.2 From 405d55c99da7a3045275fdb1a30614293a53c6e7 Mon Sep 17 00:00:00 2001 From: Wei Yongjun Date: Wed, 7 Nov 2012 20:53:25 +0800 Subject: tcm_vhost: remove unused variable in vhost_scsi_allocate_cmd() The variable se_sess is initialized but never used otherwise, so remove the unused variable. dpatch engine is used to auto generate this patch. (https://github.com/weiyj/dpatch) Signed-off-by: Wei Yongjun Signed-off-by: Michael S. Tsirkin diff --git a/drivers/vhost/tcm_vhost.c b/drivers/vhost/tcm_vhost.c index 33e5f90..79e7e4d 100644 --- a/drivers/vhost/tcm_vhost.c +++ b/drivers/vhost/tcm_vhost.c @@ -414,14 +414,12 @@ static struct tcm_vhost_cmd *vhost_scsi_allocate_cmd( { struct tcm_vhost_cmd *tv_cmd; struct tcm_vhost_nexus *tv_nexus; - struct se_session *se_sess; tv_nexus = tv_tpg->tpg_nexus; if (!tv_nexus) { pr_err("Unable to locate active struct tcm_vhost_nexus\n"); return ERR_PTR(-EIO); } - se_sess = tv_nexus->tvn_se_sess; tv_cmd = kzalloc(sizeof(struct tcm_vhost_cmd), GFP_ATOMIC); if (!tv_cmd) { -- cgit v0.10.2