Add vhost zero copy callback to release guest kernel buffers
Subsystems (4)
RFC PATCH v2 4/5 Add vhost zero copy callback to release guest kernel buffers
This patch uses msg_control to pass vhost callback to macvtap (any better idea to pass this in a simple way?). vhost doesn't notify guest to release buffers until the underlying lower device DMA has done for these buffers. This vq can not be reset if any outstanding reference.
Signed-off-by Shirley Ma <[email protected]>
---
drivers/vhost/net.c | 13 ++++++++++- drivers/vhost/vhost.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/vhost/vhost.h | 7 ++++++ 3 files changed, 75 insertions(+), 1 deletions(-)
drivers/vhost/net.c +12 -1
@@ -128,6 +128,7 @@ static void handle_tx(struct vhost_net *net)int err, wmem;size_t hdr_size;struct socket *sock; +struct skb_ubuf_info pend;/* TODO: check that we are running from vhost_worker? * Not sure it's worth it, it's straight-forward enough. */
@@ -189,6 +190,13 @@ static void handle_tx(struct vhost_net *net) iov_length(vq->hdr, s), hdr_size);break ; } +/* use msg_control to pass vhost zerocopy ubuf info here */ +if (sock_flag (sock->sk,SOCK_ZEROCOPY )) { + pend.callback = vq->callback; + pend.desc = head; + msg.msg_control = &pend; + msg.msg_controllen =sizeof (pend); + }/* TODO: Check specific error and bomb out unless ENOBUFS? */ err = sock->ops->sendmsg (NULL , sock, &msg, len);if (unlikely (err <0 )) {
@@ -199,7 +207,10 @@ static void handle_tx(struct vhost_net *net)if (err != len)pr_debug ("Truncated TX packet: " " len %d != %zd\n" , err, len); -vhost_add_used_and_signal (&net->dev, vq, head,0 ); +if (sock_flag (sock->sk,SOCK_ZEROCOPY )) +vhost_zerocopy_add_used_and_signal (vq); +else +vhost_add_used_and_signal (&net->dev, vq, head,0 ); total_len += len;if (unlikely (total_len >=VHOST_NET_WEIGHT )) {vhost_poll_queue (&vq->poll);
drivers/vhost/vhost.c +56 -0
87 lines not on this page · raw message
drivers/vhost/vhost.h +7 -0
@@ -108,6 +108,11 @@ struct vhost_virtqueue {/* Log write descriptors */ void __user *log_base;struct vhost_log *log; +/* vhost zerocopy */ +atomic_t refcnt;/* num of outstanding DMAs */ +spinlock_t zerocopy_lock; +int upend_cnt;/* num of buffers DMA has done, not notify guest yet */ +void (*callback)(struct sk_buff *skb);/* notify guest DMA done */ };struct vhost_dev {
@@ -154,6 +159,8 @@ bool vhost_enable_notify(struct vhost_virtqueue *);int vhost_log_write (struct vhost_virtqueue *vq,struct vhost_log *log,unsigned int log_num,u64 len); +void vhost_zerocopy_callback (struct sk_buff *skb); +void vhost_zerocopy_add_used_and_signal (struct vhost_virtqueue *vq);#define vq_err (vq, fmt, ...) do { \ pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \