Skip to contentSkip to conversation

vhost cleanups and separate module

PATCH Superseded Asias He 4 participants 14 messages May 3, 2013 – May 13, 2013

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Asias He

author
#0 lore raw

cover vhost cleanups and separate module

Asias He (3):
vhost: Remove vhost_enable_zcopy in vhost.h
vhost: Move VHOST_NET_FEATURES to net.c
vhost: Make vhost a separate module

 drivers/vhost/Kconfig  |  8 ++++++++
 drivers/vhost/Makefile |  3 ++-
 drivers/vhost/net.c    |  6 ++++++
 drivers/vhost/scsi.c   |  1 -
 drivers/vhost/vhost.c  | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 drivers/vhost/vhost.h  |  8 ++------
 6 files changed, 67 insertions(+), 9 deletions(-)
Signature · 1 line
1.8.1.4
author
#1 lore raw

PATCH 1/3 vhost: Remove vhost_enable_zcopy in vhost.h

It is net.c specific.

---
 drivers/vhost/vhost.h | 3 ---
 1 file changed, 3 deletions(-)
drivers/vhost/vhost.h +0 -3
index b58f4ae..4330209 100644
@@ -191,7 +191,4 @@ static inline int vhost_has_feature(struct vhost_dev *dev, int bit)
 	acked_features = rcu_dereference_index_check(dev->acked_features, 1);
 	return acked_features & (1 << bit);
 }
-
-void vhost_enable_zcopy(int vq);
-
 #endif
Signature · 1 line
1.8.1.4
author
#2 lore raw

PATCH 1/3 vhost: Remove vhost_enable_zcopy in vhost.h

In reply to Asias He

It is net.c specific.

---
 drivers/vhost/vhost.h | 3 ---
 1 file changed, 3 deletions(-)
drivers/vhost/vhost.h +0 -3
index b58f4ae..4330209 100644
@@ -191,7 +191,4 @@ static inline int vhost_has_feature(struct vhost_dev *dev, int bit)
 	acked_features = rcu_dereference_index_check(dev->acked_features, 1);
 	return acked_features & (1 << bit);
 }
-
-void vhost_enable_zcopy(int vq);
-
 #endif
Signature · 1 line
1.8.1.4
author
#3 lore raw

PATCH 2/3 vhost: Move VHOST_NET_FEATURES to net.c

In reply to Asias He

vhost.h should not depend on device specific marcos like VHOST_NET_F_VIRTIO_NET_HDR and VIRTIO_NET_F_MRG_RXBUF.

---
 drivers/vhost/net.c   | 6 ++++++
 drivers/vhost/vhost.h | 3 ---
 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/vhost/net.c +6 -0
index a3645bd..b2f6b41 100644
@@ -59,6 +59,12 @@ MODULE_PARM_DESC(experimental_zcopytx, "Enable Zero Copy TX;"
 #define VHOST_DMA_IS_DONE(len) ((len) >= VHOST_DMA_DONE_LEN)
 
 enum {
+	VHOST_NET_FEATURES = VHOST_FEATURES |
+			 (1ULL << VHOST_NET_F_VIRTIO_NET_HDR) |
+			 (1ULL << VIRTIO_NET_F_MRG_RXBUF),
+};
+
+enum {
 	VHOST_NET_VQ_RX = 0,
 	VHOST_NET_VQ_TX = 1,
 	VHOST_NET_VQ_MAX = 2,
drivers/vhost/vhost.h +0 -3
index 4330209..cc9ebf0 100644
@@ -177,9 +177,6 @@ enum {
 			 (1ULL << VIRTIO_RING_F_INDIRECT_DESC) |
 			 (1ULL << VIRTIO_RING_F_EVENT_IDX) |
 			 (1ULL << VHOST_F_LOG_ALL),
-	VHOST_NET_FEATURES = VHOST_FEATURES |
-			 (1ULL << VHOST_NET_F_VIRTIO_NET_HDR) |
-			 (1ULL << VIRTIO_NET_F_MRG_RXBUF),
 };
 
 static inline int vhost_has_feature(struct vhost_dev *dev, int bit)
Signature · 1 line
1.8.1.4
author
#5 lore raw

PATCH 3/3 vhost: Make vhost a separate module

In reply to Asias He

Currently, vhost-net and vhost-scsi are sharing the vhost core code. However, vhost-scsi shares the code by including the vhost.c file directly.

Making vhost a separate module makes it is easier to share code with other vhost devices.

---
 drivers/vhost/Kconfig  |  8 ++++++++
 drivers/vhost/Makefile |  3 ++-
 drivers/vhost/scsi.c   |  1 -
 drivers/vhost/vhost.c  | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 drivers/vhost/vhost.h  |  2 ++
 5 files changed, 61 insertions(+), 3 deletions(-)
drivers/vhost/Kconfig +8 -0
index 8b9226d..017a1e8 100644
@@ -1,6 +1,7 @@
 config VHOST_NET
 	tristate "Host kernel accelerator for virtio net"
 	depends on NET && EVENTFD && (TUN || !TUN) && (MACVTAP || !MACVTAP)
+	select VHOST
 	select VHOST_RING
 	---help---
 	  This kernel module can be loaded in host kernel to accelerate
@@ -13,6 +14,7 @@ config VHOST_NET
 config VHOST_SCSI
 	tristate "VHOST_SCSI TCM fabric driver"
 	depends on TARGET_CORE && EVENTFD && m
+	select VHOST
 	select VHOST_RING
 	default n
 	---help---
@@ -24,3 +26,9 @@ config VHOST_RING
 	---help---
 	  This option is selected by any driver which needs to access
 	  the host side of a virtio ring.
+
+config VHOST
+	tristate
+	---help---
+	  This option is selected by any driver which needs to access
+	  the core of vhost.
drivers/vhost/Makefile +2 -1
index 654e9afb..e0441c3 100644
@@ -1,7 +1,8 @@
 obj-$(CONFIG_VHOST_NET) += vhost_net.o
-vhost_net-y := vhost.o net.o
+vhost_net-y := net.o
 
 obj-$(CONFIG_VHOST_SCSI) += vhost_scsi.o
 vhost_scsi-y := scsi.o
 
 obj-$(CONFIG_VHOST_RING) += vringh.o
+obj-$(CONFIG_VHOST)	+= vhost.o
drivers/vhost/scsi.c +0 -1
index 5179f7a..2dcb94a 100644
@@ -49,7 +49,6 @@
 #include <linux/llist.h>
 #include <linux/bitmap.h>
 
-#include "vhost.c"
 #include "vhost.h"
 
 #define TCM_VHOST_VERSION  "v0.1"
drivers/vhost/vhost.c +49 -1

232 lines not on this page · raw message

drivers/vhost/vhost.h +2 -0
index cc9ebf0..6fefebf 100644
@@ -46,6 +46,8 @@ int vhost_poll_start(struct vhost_poll *poll, struct file *file);
 void vhost_poll_stop(struct vhost_poll *poll);
 void vhost_poll_flush(struct vhost_poll *poll);
 void vhost_poll_queue(struct vhost_poll *poll);
+void vhost_work_flush(struct vhost_dev *dev, struct vhost_work *work);
+long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp);
 
 struct vhost_log {
 	u64 addr;
Signature · 1 line
1.8.1.4
author
#4 lore raw

PATCH 2/3 vhost: Move VHOST_NET_FEATURES to net.c

In reply to Asias He

vhost.h should not depend on device specific marcos like VHOST_NET_F_VIRTIO_NET_HDR and VIRTIO_NET_F_MRG_RXBUF.

---
 drivers/vhost/net.c   | 6 ++++++
 drivers/vhost/vhost.h | 3 ---
 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/vhost/net.c +6 -0
index a3645bd..b2f6b41 100644
@@ -59,6 +59,12 @@ MODULE_PARM_DESC(experimental_zcopytx, "Enable Zero Copy TX;"
 #define VHOST_DMA_IS_DONE(len) ((len) >= VHOST_DMA_DONE_LEN)
 
 enum {
+	VHOST_NET_FEATURES = VHOST_FEATURES |
+			 (1ULL << VHOST_NET_F_VIRTIO_NET_HDR) |
+			 (1ULL << VIRTIO_NET_F_MRG_RXBUF),
+};
+
+enum {
 	VHOST_NET_VQ_RX = 0,
 	VHOST_NET_VQ_TX = 1,
 	VHOST_NET_VQ_MAX = 2,
drivers/vhost/vhost.h +0 -3
index 4330209..cc9ebf0 100644
@@ -177,9 +177,6 @@ enum {
 			 (1ULL << VIRTIO_RING_F_INDIRECT_DESC) |
 			 (1ULL << VIRTIO_RING_F_EVENT_IDX) |
 			 (1ULL << VHOST_F_LOG_ALL),
-	VHOST_NET_FEATURES = VHOST_FEATURES |
-			 (1ULL << VHOST_NET_F_VIRTIO_NET_HDR) |
-			 (1ULL << VIRTIO_NET_F_MRG_RXBUF),
 };
 
 static inline int vhost_has_feature(struct vhost_dev *dev, int bit)
Signature · 1 line
1.8.1.4
author
#6 lore raw

PATCH 3/3 vhost: Make vhost a separate module

In reply to Asias He

Currently, vhost-net and vhost-scsi are sharing the vhost core code. However, vhost-scsi shares the code by including the vhost.c file directly.

Making vhost a separate module makes it is easier to share code with other vhost devices.

---
 drivers/vhost/Kconfig  |  8 ++++++++
 drivers/vhost/Makefile |  3 ++-
 drivers/vhost/scsi.c   |  1 -
 drivers/vhost/vhost.c  | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 drivers/vhost/vhost.h  |  2 ++
 5 files changed, 61 insertions(+), 3 deletions(-)
drivers/vhost/Kconfig +8 -0
index 8b9226d..017a1e8 100644
@@ -1,6 +1,7 @@
 config VHOST_NET
 	tristate "Host kernel accelerator for virtio net"
 	depends on NET && EVENTFD && (TUN || !TUN) && (MACVTAP || !MACVTAP)
+	select VHOST
 	select VHOST_RING
 	---help---
 	  This kernel module can be loaded in host kernel to accelerate
@@ -13,6 +14,7 @@ config VHOST_NET
 config VHOST_SCSI
 	tristate "VHOST_SCSI TCM fabric driver"
 	depends on TARGET_CORE && EVENTFD && m
+	select VHOST
 	select VHOST_RING
 	default n
 	---help---
@@ -24,3 +26,9 @@ config VHOST_RING
 	---help---
 	  This option is selected by any driver which needs to access
 	  the host side of a virtio ring.
+
+config VHOST
+	tristate
+	---help---
+	  This option is selected by any driver which needs to access
+	  the core of vhost.
drivers/vhost/Makefile +2 -1
index 654e9afb..e0441c3 100644
@@ -1,7 +1,8 @@
 obj-$(CONFIG_VHOST_NET) += vhost_net.o
-vhost_net-y := vhost.o net.o
+vhost_net-y := net.o
 
 obj-$(CONFIG_VHOST_SCSI) += vhost_scsi.o
 vhost_scsi-y := scsi.o
 
 obj-$(CONFIG_VHOST_RING) += vringh.o
+obj-$(CONFIG_VHOST)	+= vhost.o
drivers/vhost/scsi.c +0 -1
index 5179f7a..2dcb94a 100644
@@ -49,7 +49,6 @@
 #include <linux/llist.h>
 #include <linux/bitmap.h>
 
-#include "vhost.c"
 #include "vhost.h"
 
 #define TCM_VHOST_VERSION  "v0.1"
drivers/vhost/vhost.c +49 -1

232 lines not on this page · raw message

drivers/vhost/vhost.h +2 -0
index cc9ebf0..6fefebf 100644
@@ -46,6 +46,8 @@ int vhost_poll_start(struct vhost_poll *poll, struct file *file);
 void vhost_poll_stop(struct vhost_poll *poll);
 void vhost_poll_flush(struct vhost_poll *poll);
 void vhost_poll_queue(struct vhost_poll *poll);
+void vhost_work_flush(struct vhost_dev *dev, struct vhost_work *work);
+long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp);
 
 struct vhost_log {
 	u64 addr;
Signature · 1 line
1.8.1.4
#7 lore raw
In reply to Asias He
Quoted 4 lines · Asias He

Asias He (3):
vhost: Remove vhost_enable_zcopy in vhost.h
vhost: Move VHOST_NET_FEATURES to net.c
vhost: Make vhost a separate module

I like these cleanups, MST pleasee apply.

I have some other cleanups which are on hold for the moment pending MST's vhost_net simplification. MST, how's that going?

Thanks,
Rusty.

author
#8 lore raw

Hello Rusty,

Quoted 10 lines · Rusty Russell
Quoted 4 lines · Asias He

Asias He (3):
vhost: Remove vhost_enable_zcopy in vhost.h
vhost: Move VHOST_NET_FEATURES to net.c
vhost: Make vhost a separate module

I like these cleanups, MST pleasee apply.

I have some other cleanups which are on hold for the moment pending MST's vhost_net simplification. MST, how's that going?

Do you mean patches in your rusty/vringh branch? I want to do the frame assumption conversion for vhost-scsi on top of the vringh series.

Quoted 2 lines

Thanks,
Rusty.

Signature · 1 line
Asias
#9 lore raw
In reply to Rusty Russell
Quoted 7 lines · Rusty Russell
Quoted 4 lines · Asias He

Asias He (3):
vhost: Remove vhost_enable_zcopy in vhost.h
vhost: Move VHOST_NET_FEATURES to net.c
vhost: Make vhost a separate module

I like these cleanups, MST pleasee apply.

Absolutely. Except it's 3.11 material and I can only usefully create a -next branch once -rc1 is out.

Quoted 2 lines

I have some other cleanups which are on hold for the moment pending MST's vhost_net simplification. MST, how's that going?

Not too well. The array of status bytes which was designed to complete packets in order turns out to be a very efficient datastructure:

It gives us a way to signal completions that is completely lockless for multiple completers, and using the producer/consumer model saves extra scans for the common case.

Overall I can save some memory and clean up some code but can't get rid of the producer/consumer idices (currently named upend/done indices) which is what you asked me to do.
Your cleanups basically don't work with zcopy because they ignore the upend/done indices?
Would you like to post them, noting they only work with zcopy off, and we'll look for a way to apply them, together?

Quoted 2 lines

Thanks,
Rusty.

#10 lore raw
Quoted 22 lines · Michael S. Tsirkin
Quoted 7 lines · Rusty Russell
Quoted 4 lines · Asias He

Asias He (3):
vhost: Remove vhost_enable_zcopy in vhost.h
vhost: Move VHOST_NET_FEATURES to net.c
vhost: Make vhost a separate module

I like these cleanups, MST pleasee apply.

Absolutely. Except it's 3.11 material and I can only usefully create a -next branch once -rc1 is out.

Quoted 2 lines

I have some other cleanups which are on hold for the moment pending MST's vhost_net simplification. MST, how's that going?

Not too well. The array of status bytes which was designed to complete packets in order turns out to be a very efficient datastructure:

It gives us a way to signal completions that is completely lockless for multiple completers, and using the producer/consumer model saves extra scans for the common case.

Quoted 7 lines

Overall I can save some memory and clean up some code but can't get rid of the producer/consumer idices (currently named upend/done indices) which is what you asked me to do.
Your cleanups basically don't work with zcopy because they ignore the upend/done indices?
Would you like to post them, noting they only work with zcopy off, and we'll look for a way to apply them, together?

Not quite; it's just that I don't understand that code. It seemed to be achieving something (ordered completion) which was entirely unnecessary, so I went on with other things while you removed it. Now that's not possible, I'll revisit.

AFAICT we should always do zero copy. Though I do wonder if we should use a dedicated hook to get an skb into the tun driver and generate it ourselves, rather than going sg -> iov -> skb.

Cheers,
Rusty.

#11 lore raw
Quoted 31 lines · Rusty Russell
Quoted 22 lines · Michael S. Tsirkin
Quoted 7 lines · Rusty Russell
Quoted 4 lines · Asias He

Asias He (3):
vhost: Remove vhost_enable_zcopy in vhost.h
vhost: Move VHOST_NET_FEATURES to net.c
vhost: Make vhost a separate module

I like these cleanups, MST pleasee apply.

Absolutely. Except it's 3.11 material and I can only usefully create a -next branch once -rc1 is out.

Quoted 2 lines

I have some other cleanups which are on hold for the moment pending MST's vhost_net simplification. MST, how's that going?

Not too well. The array of status bytes which was designed to complete packets in order turns out to be a very efficient datastructure:

It gives us a way to signal completions that is completely lockless for multiple completers, and using the producer/consumer model saves extra scans for the common case.

Quoted 7 lines

Overall I can save some memory and clean up some code but can't get rid of the producer/consumer idices (currently named upend/done indices) which is what you asked me to do.
Your cleanups basically don't work with zcopy because they ignore the upend/done indices?
Would you like to post them, noting they only work with zcopy off, and we'll look for a way to apply them, together?

Quoted 6 lines

Not quite; it's just that I don't understand that code. It seemed to be achieving something (ordered completion) which was entirely unnecessary, so I went on with other things while you removed it. Now that's not possible, I'll revisit.

AFAICT we should always do zero copy.

It seems not to be a win for small packets.
I speculate the issue is that ring space isn't released as promptly. Further, we can't do it safely for guest to guest and guest to host. And if we try, net core just does a packet copy later (which is less efficient). So there's a hack in place to detect that and suppress zero copy.

Quoted 6 lines

Though I do wonder if we should
use a dedicated hook to get an skb into the tun driver and generate it ourselves, rather than going sg -> iov -> skb.

Cheers,
Rusty.

I think we'd have to export two interfaces:
- alloc_skb()
.... add frags ...
- send_skb

the code to add frags could maybe use some
library functions ...

Signature · 1 line
MST
#12 lore raw
Quoted 9 lines · Michael S. Tsirkin
Quoted 1 line · Rusty Russell

AFAICT we should always do zero copy.

It seems not to be a win for small packets.
I speculate the issue is that ring space isn't released as promptly. Further, we can't do it safely for guest to guest and guest to host. And if we try, net core just does a packet copy later (which is less efficient). So there's a hack in place to detect that and suppress zero copy.

AFAICT there are two places we should copy. One is small packets:
latency plus refcount/callbacks aren't a win. The other is weird packets (eg. more than 1000 segements), which we currently drop.

Quoted 7 lines
Quoted 6 lines

Though I do wonder if we should
use a dedicated hook to get an skb into the tun driver and generate it ourselves, rather than going sg -> iov -> skb.

Cheers,
Rusty.

Quoted 7 lines

I think we'd have to export two interfaces:
- alloc_skb()
.... add frags ...
- send_skb

the code to add frags could maybe use some
library functions ...

I think we just need send_skb for the socket. We can build the skb ourselves. But yes that frag-handling code should be factored out.

I'll see how I go.

Cheers,
Rusty.

#13 lore raw
In reply to Michael S. Tsirkin
Quoted 33 lines · Michael S. Tsirkin
Quoted 32 lines · Rusty Russell
Quoted 19 lines · Michael S. Tsirkin
Quoted 6 lines · Rusty Russell
Quoted 4 lines · Asias He

Asias He (3):
vhost: Remove vhost_enable_zcopy in vhost.h
vhost: Move VHOST_NET_FEATURES to net.c
vhost: Make vhost a separate module

I like these cleanups, MST pleasee apply.

Absolutely. Except it's 3.11 material and I can only usefully create a -next branch once -rc1 is out.

Quoted 2 lines

I have some other cleanups which are on hold for the moment pending MST's vhost_net simplification. MST, how's that going?

Not too well. The array of status bytes which was designed to complete packets in order turns out to be a very efficient datastructure:

It gives us a way to signal completions that is completely lockless for multiple completers, and using the producer/consumer model saves extra scans for the common case.

Quoted 7 lines

Overall I can save some memory and clean up some code but can't get rid of the producer/consumer idices (currently named upend/done indices) which is what you asked me to do.
Your cleanups basically don't work with zcopy because they ignore the upend/done indices?
Would you like to post them, noting they only work with zcopy off, and we'll look for a way to apply them, together?

Not quite; it's just that I don't understand that code. It seemed to be achieving something (ordered completion) which was entirely unnecessary, so I went on with other things while you removed it. Now that's not possible, I'll revisit.

Quoted 7 lines
Quoted 1 line

AFAICT we should always do zero copy.

It seems not to be a win for small packets.
I speculate the issue is that ring space isn't released as promptly. Further, we can't do it safely for guest to guest and guest to host. And if we try, net core just does a packet copy later (which is less efficient). So there's a hack in place to detect that and suppress zero copy.

We can do something to eliminate this copy:

- change the vnet header to NET_SKB_PAD
- use build_skb() to build the skb->data from the page directly

Then for packet size smaller than PAGE_SIZE - NET_SKB_PAD - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)), we can build the packet directly instead of copy 128 bytes.

Quoted 15 lines
Quoted 7 lines

Though I do wonder if we should
use a dedicated hook to get an skb into the tun driver and generate it ourselves, rather than going sg -> iov -> skb.

Cheers,
Rusty.

I think we'd have to export two interfaces:
- alloc_skb()
.... add frags ...
- send_skb

the code to add frags could maybe use some
library functions ...