Packed virtqueue support for vhost
Subsystems (7)
v2 cover Packed virtqueue support for vhost
Hi all:
This series implements packed virtqueues. The code were tested with Tiwei's guest driver series at https://patchwork.ozlabs.org/cover/942297/
Pktgen test for both RX and TX does not show obvious difference with split virtqueues. The main bottleneck is the guest Linux driver, since it can not stress vhost for a 100% CPU utilization. A full TCP benchmark is ongoing. Will test virtio-net pmd as well when it was ready.
Notes:
- This version depends on Tiwei's series at https://patchwork.ozlabs.org/cover/942297/
This version were tested with:
- Zerocopy (Out of Order) support
- vIOMMU support
- mergeable buffer on/off
- busy polling on/off
- vsock (nc-vsock)
Changes from V1:
- drop uapi patch and use Tiwei's
- split the enablement of packed virtqueue into a separate patch
Changes from RFC V5:
- save unnecessary barriers during vhost_add_used_packed_n()
- more compact math for event idx
- fix failure of SET_VRING_BASE when avail_wrap_counter is true
- fix not copy avail_wrap_counter during GET_VRING_BASE
- introduce SET_VRING_USED_BASE/GET_VRING_USED_BASE for syncing last_used_idx
- rename used_wrap_counter to last_used_wrap_counter
- rebase to net-next
Changes from RFC V4:
- fix signalled_used index recording
- track avail index correctly
- various minor fixes
Changes from RFC V3:
- Fix math on event idx checking
- Sync last avail wrap counter through GET/SET_VRING_BASE
- remove desc_event prefix in the driver/device structure
Changes from RFC V2:
- do not use & in checking desc_event_flags
- off should be most significant bit
- remove the workaround of mergeable buffer for dpdk prototype
- id should be in the last descriptor in the chain
- keep _F_WRITE for write descriptor when adding used
- device flags updating should use ADDR_USED type
- return error on unexpected unavail descriptor in a chain
- return false in vhost_ve_avail_empty is descriptor is available
- track last seen avail_wrap_counter
- correctly examine available descriptor in get_indirect_packed()
- vhost_idx_diff should return u16 instead of bool
Changes from RFC V1:
- Refactor vhost used elem code to avoid open coding on used elem
- Event suppression support (compile test only).
- Indirect descriptor support (compile test only).
- Zerocopy support.
- vIOMMU support.
- SCSI/VSOCK support (compile test only).
- Fix several bugs
Jason Wang (8):
vhost: move get_rx_bufs to vhost.c
vhost: hide used ring layout from device
vhost: do not use vring_used_elem
vhost_net: do not explicitly manipulate vhost_used_elem
vhost: vhost_put_user() can accept metadata type
vhost: packed ring support
vhost: event suppression for packed ring
vhost: enable packed virtqueues
drivers/vhost/net.c | 143 ++----- drivers/vhost/scsi.c | 62 +-- drivers/vhost/vhost.c | 994 ++++++++++++++++++++++++++++++++++++++++----- drivers/vhost/vhost.h | 55 ++- drivers/vhost/vsock.c | 42 +- include/uapi/linux/vhost.h | 7 + 6 files changed, 1035 insertions(+), 268 deletions(-)
Signature · 1 line
2.7.4
PATCH v2 1/8 vhost: move get_rx_bufs to vhost.c
Move get_rx_bufs() to vhost.c and rename it to vhost_get_bufs(). This helps to hide vring internal layout from specific device implementation. Packed ring implementation will benefit from this.
--- drivers/vhost/net.c | 83 ++------------------------------------------------- drivers/vhost/vhost.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/vhost/vhost.h | 7 +++++ 3 files changed, 88 insertions(+), 80 deletions(-)
drivers/vhost/net.c +3 -80
@@ -702,83 +702,6 @@ static int vhost_net_rx_peek_head_len(struct vhost_net *net, struct sock *sk,return len; } -/* This is a multi-buffer version of vhost_get_desc, that works if -* vq has read descriptors only. -* @vq - the relevant virtqueue -* @datalen - data length we'll be reading -* @iovcount - returned count of io vectors we fill -* @log - vhost log -* @log_num - log offset -* @quota - headcount quota, 1 for big buffer -* returns number of buffer heads allocated, negative on error -*/ -static int get_rx_bufs (struct vhost_virtqueue *vq, -struct vring_used_elem *heads, -int datalen, -unsigned *iovcount, -struct vhost_log *log, -unsigned *log_num, -unsigned int quota) -{ -unsigned int out, in; -int seg =0 ; -int headcount =0 ; -unsigned d; -int r, nlogs =0 ; -/* len is always initialized before use since we are always called with -* datalen > 0. -*/ -u32 uninitialized_var (len ); - -while (datalen >0 && headcount < quota) { -if (unlikely (seg >=UIO_MAXIOV )) { - r = -ENOBUFS ; - goto err; - } - r =vhost_get_vq_desc (vq, vq->iov + seg, -ARRAY_SIZE (vq->iov) - seg, &out, - &in, log, log_num); -if (unlikely (r <0 )) - goto err; - - d = r; -if (d == vq->num) { - r =0 ; - goto err; - } -if (unlikely (out || in <=0 )) { -vq_err (vq,"unexpected descriptor format for RX: " -"out %d, in %d\n" , out, in); - r = -EINVAL ; - goto err; - } -if (unlikely (log)) { - nlogs += *log_num; - log += *log_num; - } - heads[headcount].id =cpu_to_vhost32 (vq, d); - len =iov_length (vq->iov + seg, in); - heads[headcount].len =cpu_to_vhost32 (vq, len); - datalen -= len; - ++headcount; - seg += in; - } - heads[headcount -1 ].len =cpu_to_vhost32 (vq, len + datalen); - *iovcount = seg; -if (unlikely (log)) - *log_num = nlogs; - -/* Detect overrun */ -if (unlikely (datalen >0 )) { - r =UIO_MAXIOV +1 ; - goto err; - } -return headcount; -err: -vhost_discard_vq_desc (vq, headcount); -return r; -} -/* Expects to be always run from workqueue - which acts as * read-size critical section for our kind of RCU. */ static void handle_rx (struct vhost_net *net)
@@ -831,9 +754,9 @@ static void handle_rx(struct vhost_net *net) &busyloop_intr))) { sock_len += sock_hlen; vhost_len = sock_len + vhost_hlen; - headcount =get_rx_bufs (vq, vq->heads + nvq->done_idx, - vhost_len, &in, vq_log, &log, -likely (mergeable) ?UIO_MAXIOV :1 ); + headcount =vhost_get_bufs (vq, vq->heads + nvq->done_idx, + vhost_len, &in, vq_log, &log, +likely (mergeable) ?UIO_MAXIOV :1 );/* On error, stop handling until the next kick. */ if (unlikely (headcount <0 )) goto out;
drivers/vhost/vhost.c +78 -0
84 lines not on this page · raw message
drivers/vhost/vhost.h +7 -0
@@ -185,6 +185,13 @@ int vhost_get_vq_desc(struct vhost_virtqueue *, struct iovec iov[], unsigned int iov_count, unsigned int *out_num, unsigned int *in_num, struct vhost_log *log, unsigned int *log_num); +int vhost_get_bufs (struct vhost_virtqueue *vq, +struct vring_used_elem *heads, +int datalen, +unsigned *iovcount, +struct vhost_log *log, +unsigned *log_num, +unsigned int quota);void vhost_discard_vq_desc (struct vhost_virtqueue *,int n);int vhost_vq_init_access (struct vhost_virtqueue *);
Signature · 1 line
2.7.4
PATCH v2 1/8 vhost: move get_rx_bufs to vhost.c
In reply to Jason WangMove get_rx_bufs() to vhost.c and rename it to vhost_get_bufs(). This helps to hide vring internal layout from specific device implementation. Packed ring implementation will benefit from this.
--- drivers/vhost/net.c | 83 ++------------------------------------------------- drivers/vhost/vhost.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/vhost/vhost.h | 7 +++++ 3 files changed, 88 insertions(+), 80 deletions(-)
drivers/vhost/net.c +3 -80
@@ -702,83 +702,6 @@ static int vhost_net_rx_peek_head_len(struct vhost_net *net, struct sock *sk,return len; } -/* This is a multi-buffer version of vhost_get_desc, that works if -* vq has read descriptors only. -* @vq - the relevant virtqueue -* @datalen - data length we'll be reading -* @iovcount - returned count of io vectors we fill -* @log - vhost log -* @log_num - log offset -* @quota - headcount quota, 1 for big buffer -* returns number of buffer heads allocated, negative on error -*/ -static int get_rx_bufs (struct vhost_virtqueue *vq, -struct vring_used_elem *heads, -int datalen, -unsigned *iovcount, -struct vhost_log *log, -unsigned *log_num, -unsigned int quota) -{ -unsigned int out, in; -int seg =0 ; -int headcount =0 ; -unsigned d; -int r, nlogs =0 ; -/* len is always initialized before use since we are always called with -* datalen > 0. -*/ -u32 uninitialized_var (len ); - -while (datalen >0 && headcount < quota) { -if (unlikely (seg >=UIO_MAXIOV )) { - r = -ENOBUFS ; - goto err; - } - r =vhost_get_vq_desc (vq, vq->iov + seg, -ARRAY_SIZE (vq->iov) - seg, &out, - &in, log, log_num); -if (unlikely (r <0 )) - goto err; - - d = r; -if (d == vq->num) { - r =0 ; - goto err; - } -if (unlikely (out || in <=0 )) { -vq_err (vq,"unexpected descriptor format for RX: " -"out %d, in %d\n" , out, in); - r = -EINVAL ; - goto err; - } -if (unlikely (log)) { - nlogs += *log_num; - log += *log_num; - } - heads[headcount].id =cpu_to_vhost32 (vq, d); - len =iov_length (vq->iov + seg, in); - heads[headcount].len =cpu_to_vhost32 (vq, len); - datalen -= len; - ++headcount; - seg += in; - } - heads[headcount -1 ].len =cpu_to_vhost32 (vq, len + datalen); - *iovcount = seg; -if (unlikely (log)) - *log_num = nlogs; - -/* Detect overrun */ -if (unlikely (datalen >0 )) { - r =UIO_MAXIOV +1 ; - goto err; - } -return headcount; -err: -vhost_discard_vq_desc (vq, headcount); -return r; -} -/* Expects to be always run from workqueue - which acts as * read-size critical section for our kind of RCU. */ static void handle_rx (struct vhost_net *net)
@@ -831,9 +754,9 @@ static void handle_rx(struct vhost_net *net) &busyloop_intr))) { sock_len += sock_hlen; vhost_len = sock_len + vhost_hlen; - headcount =get_rx_bufs (vq, vq->heads + nvq->done_idx, - vhost_len, &in, vq_log, &log, -likely (mergeable) ?UIO_MAXIOV :1 ); + headcount =vhost_get_bufs (vq, vq->heads + nvq->done_idx, + vhost_len, &in, vq_log, &log, +likely (mergeable) ?UIO_MAXIOV :1 );/* On error, stop handling until the next kick. */ if (unlikely (headcount <0 )) goto out;
drivers/vhost/vhost.c +78 -0
84 lines not on this page · raw message
drivers/vhost/vhost.h +7 -0
@@ -185,6 +185,13 @@ int vhost_get_vq_desc(struct vhost_virtqueue *, struct iovec iov[], unsigned int iov_count, unsigned int *out_num, unsigned int *in_num, struct vhost_log *log, unsigned int *log_num); +int vhost_get_bufs (struct vhost_virtqueue *vq, +struct vring_used_elem *heads, +int datalen, +unsigned *iovcount, +struct vhost_log *log, +unsigned *log_num, +unsigned int quota);void vhost_discard_vq_desc (struct vhost_virtqueue *,int n);int vhost_vq_init_access (struct vhost_virtqueue *);
Signature · 1 line
2.7.4
PATCH v2 2/8 vhost: hide used ring layout from device
In reply to Jason WangWe used to return descriptor head by vhost_get_vq_desc() to device and pass it back to vhost_add_used() and its friends. This exposes the internal used ring layout to device which makes it hard to be extended for e.g packed ring layout.
So this patch tries to hide the used ring layout by
- letting vhost_get_vq_desc() return pointer to struct vring_used_elem
- accepting pointer to struct vring_used_elem in vhost_add_used() and vhost_add_used_and_signal()
This could help to hide used ring layout and make it easier to implement packed ring on top.
--- drivers/vhost/net.c | 48 +++++++++++++++++++++------------------ drivers/vhost/scsi.c | 62 +++++++++++++++++++++++++++------------------------ drivers/vhost/vhost.c | 52 +++++++++++++++++++++--------------------- drivers/vhost/vhost.h | 9 +++++--- drivers/vhost/vsock.c | 42 +++++++++++++++++----------------- 5 files changed, 113 insertions(+), 100 deletions(-)
drivers/vhost/net.c +26 -22
@@ -430,15 +430,16 @@ static int vhost_net_enable_vq(struct vhost_net *n,static int vhost_net_tx_get_vq_desc (struct vhost_net *net,struct vhost_virtqueue *vq, +struct vring_used_elem *used_elem,struct iovec iov[],unsigned int iov_size,unsigned int *out_num,unsigned int *in_num,bool *busyloop_intr) {unsigned long uninitialized_var (endtime ); -int r =vhost_get_vq_desc (vq, vq->iov,ARRAY_SIZE (vq->iov), +int r =vhost_get_vq_desc (vq, used_elem, vq->iov,ARRAY_SIZE (vq->iov), out_num, in_num,NULL ,NULL ); -if (r == vq->num && vq->busyloop_timeout) { +if (r == -ENOSPC && vq->busyloop_timeout) {preempt_disable (); endtime =busy_clock () + vq->busyloop_timeout;while (vhost_can_busy_poll (endtime)) {
@@ -451,8 +452,9 @@ static int vhost_net_tx_get_vq_desc(struct vhost_net *net,cpu_relax (); }preempt_enable (); - r =vhost_get_vq_desc (vq, vq->iov,ARRAY_SIZE (vq->iov), - out_num, in_num,NULL ,NULL ); + r =vhost_get_vq_desc (vq, used_elem, vq->iov, +ARRAY_SIZE (vq->iov), out_num, in_num, +NULL ,NULL ); }return r;
@@ -474,7 +476,6 @@ static void handle_tx(struct vhost_net *net)struct vhost_net_virtqueue *nvq = &net->vqs[VHOST_NET_VQ_TX ];struct vhost_virtqueue *vq = &nvq->vq;unsigned out, in; -int head;struct msghdr msg = { .msg_name =NULL , .msg_namelen =0 ,
@@ -487,6 +488,7 @@ static void handle_tx(struct vhost_net *net)size_t hdr_size;struct socket *sock;struct vhost_net_ubuf_ref *uninitialized_var (ubufs ); +struct vring_used_elem used;bool zcopy, zcopy_used;int sent_pkts =0 ;
@@ -512,14 +514,11 @@ static void handle_tx(struct vhost_net *net)vhost_zerocopy_signal_used (net, vq); busyloop_intr = false; - head =vhost_net_tx_get_vq_desc (net, vq, vq->iov, -ARRAY_SIZE (vq->iov), - &out, &in, &busyloop_intr); -/* On error, stop handling until the next kick. */ -if (unlikely (head <0 )) -break ; + err =vhost_net_tx_get_vq_desc (net, vq, &used, vq->iov, +ARRAY_SIZE (vq->iov), + &out, &in, &busyloop_intr);/* Nothing new? Wait for eventfd to tell us they refilled. */ -if (head == vq->num) { +if (err == -ENOSPC ) {if (unlikely (busyloop_intr)) {vhost_poll_queue (&vq->poll); }else if (unlikely (vhost_enable_notify (&net->dev, vq))) {
@@ -528,6 +527,9 @@ static void handle_tx(struct vhost_net *net) }break ; } +/* On error, stop handling until the next kick. */ +if (unlikely (err <0 )) +break ;if (in) {vq_err (vq,"Unexpected descriptor format for TX: " "out %d, int %d\n" , out, in);
@@ -555,7 +557,8 @@ static void handle_tx(struct vhost_net *net)struct ubuf_info *ubuf; ubuf = nvq->ubuf_info + nvq->upend_idx; - vq->heads[nvq->upend_idx].id =cpu_to_vhost32 (vq, head); + vq->heads[nvq->upend_idx].id = +cpu_to_vhost32 (vq, used.id); vq->heads[nvq->upend_idx].len =VHOST_DMA_IN_PROGRESS ; ubuf->callback = vhost_zerocopy_callback; ubuf->ctx = nvq->ubufs;
@@ -596,7 +599,7 @@ static void handle_tx(struct vhost_net *net)pr_debug ("Truncated TX packet: " " len %d != %zd\n" , err, len);if (!zcopy_used) -vhost_add_used_and_signal (&net->dev, vq, head,0 ); +vhost_add_used_and_signal (&net->dev, vq, &used,0 );else vhost_zerocopy_signal_used (net, vq);vhost_net_tx_packet (net);
@@ -754,17 +757,15 @@ static void handle_rx(struct vhost_net *net) &busyloop_intr))) { sock_len += sock_hlen; vhost_len = sock_len + vhost_hlen; - headcount =vhost_get_bufs (vq, vq->heads + nvq->done_idx, - vhost_len, &in, vq_log, &log, -likely (mergeable) ?UIO_MAXIOV :1 ); -/* On error, stop handling until the next kick. */ -if (unlikely (headcount <0 )) - goto out; + err =vhost_get_bufs (vq, vq->heads + nvq->done_idx, + vhost_len, &in, vq_log, &log, +likely (mergeable) ?UIO_MAXIOV :1 , + &headcount);/* OK, now we need to know about added descriptors. */ -if (!headcount) { +if (err == -ENOSPC ) {if (unlikely (busyloop_intr)) {vhost_poll_queue (&vq->poll); - }else if (unlikely (vhost_enable_notify (&net->dev, vq))) { + }else if (unlikely (vhost_enable_notify (&net->dev, vq))) {/* They have slipped one in as we were * doing that: check again. */ vhost_disable_notify (&net->dev, vq);
@@ -775,6 +776,9 @@ static void handle_rx(struct vhost_net *net) goto out; } busyloop_intr = false; +/* On error, stop handling until the next kick. */ +if (unlikely (err <0 )) + goto out;if (nvq->rx_ring) msg.msg_control =vhost_net_buf_consume (&nvq->rxq);/* On overrun, truncate and discard */
drivers/vhost/scsi.c +33 -29
187 lines not on this page · raw message
drivers/vhost/vhost.c +27 -25
133 lines not on this page · raw message
drivers/vhost/vhost.h +6 -3
@@ -182,6 +182,7 @@ bool vhost_vq_access_ok(struct vhost_virtqueue *vq);bool vhost_log_access_ok (struct vhost_dev *);int vhost_get_vq_desc (struct vhost_virtqueue *, +struct vring_used_elem *used_elem,struct iovec iov[],unsigned int iov_count,unsigned int *out_num,unsigned int *in_num,struct vhost_log *log,unsigned int *log_num);
@@ -191,15 +192,17 @@ int vhost_get_bufs(struct vhost_virtqueue *vq,unsigned *iovcount, struct vhost_log *log, unsigned *log_num, - unsigned int quota); + unsigned int quota, + s16 *count);void vhost_discard_vq_desc (struct vhost_virtqueue *,int n);int vhost_vq_init_access (struct vhost_virtqueue *); -int vhost_add_used (struct vhost_virtqueue *,unsigned int head,int len); +int vhost_add_used (struct vhost_virtqueue *vq, +struct vring_used_elem *elem,int len);int vhost_add_used_n (struct vhost_virtqueue *,struct vring_used_elem *heads,unsigned count);void vhost_add_used_and_signal (struct vhost_dev *,struct vhost_virtqueue *, -unsigned int id,int len); +struct vring_used_elem *,int len);void vhost_add_used_and_signal_n (struct vhost_dev *,struct vhost_virtqueue *,struct vring_used_elem *heads,unsigned count);void vhost_signal (struct vhost_dev *,struct vhost_virtqueue *);
drivers/vhost/vsock.c +21 -21
100 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v2 2/8 vhost: hide used ring layout from device
In reply to Jason WangWe used to return descriptor head by vhost_get_vq_desc() to device and pass it back to vhost_add_used() and its friends. This exposes the internal used ring layout to device which makes it hard to be extended for e.g packed ring layout.
So this patch tries to hide the used ring layout by
- letting vhost_get_vq_desc() return pointer to struct vring_used_elem
- accepting pointer to struct vring_used_elem in vhost_add_used() and vhost_add_used_and_signal()
This could help to hide used ring layout and make it easier to implement packed ring on top.
--- drivers/vhost/net.c | 48 +++++++++++++++++++++------------------ drivers/vhost/scsi.c | 62 +++++++++++++++++++++++++++------------------------ drivers/vhost/vhost.c | 52 +++++++++++++++++++++--------------------- drivers/vhost/vhost.h | 9 +++++--- drivers/vhost/vsock.c | 42 +++++++++++++++++----------------- 5 files changed, 113 insertions(+), 100 deletions(-)
drivers/vhost/net.c +26 -22
@@ -430,15 +430,16 @@ static int vhost_net_enable_vq(struct vhost_net *n,static int vhost_net_tx_get_vq_desc (struct vhost_net *net,struct vhost_virtqueue *vq, +struct vring_used_elem *used_elem,struct iovec iov[],unsigned int iov_size,unsigned int *out_num,unsigned int *in_num,bool *busyloop_intr) {unsigned long uninitialized_var (endtime ); -int r =vhost_get_vq_desc (vq, vq->iov,ARRAY_SIZE (vq->iov), +int r =vhost_get_vq_desc (vq, used_elem, vq->iov,ARRAY_SIZE (vq->iov), out_num, in_num,NULL ,NULL ); -if (r == vq->num && vq->busyloop_timeout) { +if (r == -ENOSPC && vq->busyloop_timeout) {preempt_disable (); endtime =busy_clock () + vq->busyloop_timeout;while (vhost_can_busy_poll (endtime)) {
@@ -451,8 +452,9 @@ static int vhost_net_tx_get_vq_desc(struct vhost_net *net,cpu_relax (); }preempt_enable (); - r =vhost_get_vq_desc (vq, vq->iov,ARRAY_SIZE (vq->iov), - out_num, in_num,NULL ,NULL ); + r =vhost_get_vq_desc (vq, used_elem, vq->iov, +ARRAY_SIZE (vq->iov), out_num, in_num, +NULL ,NULL ); }return r;
@@ -474,7 +476,6 @@ static void handle_tx(struct vhost_net *net)struct vhost_net_virtqueue *nvq = &net->vqs[VHOST_NET_VQ_TX ];struct vhost_virtqueue *vq = &nvq->vq;unsigned out, in; -int head;struct msghdr msg = { .msg_name =NULL , .msg_namelen =0 ,
@@ -487,6 +488,7 @@ static void handle_tx(struct vhost_net *net)size_t hdr_size;struct socket *sock;struct vhost_net_ubuf_ref *uninitialized_var (ubufs ); +struct vring_used_elem used;bool zcopy, zcopy_used;int sent_pkts =0 ;
@@ -512,14 +514,11 @@ static void handle_tx(struct vhost_net *net)vhost_zerocopy_signal_used (net, vq); busyloop_intr = false; - head =vhost_net_tx_get_vq_desc (net, vq, vq->iov, -ARRAY_SIZE (vq->iov), - &out, &in, &busyloop_intr); -/* On error, stop handling until the next kick. */ -if (unlikely (head <0 )) -break ; + err =vhost_net_tx_get_vq_desc (net, vq, &used, vq->iov, +ARRAY_SIZE (vq->iov), + &out, &in, &busyloop_intr);/* Nothing new? Wait for eventfd to tell us they refilled. */ -if (head == vq->num) { +if (err == -ENOSPC ) {if (unlikely (busyloop_intr)) {vhost_poll_queue (&vq->poll); }else if (unlikely (vhost_enable_notify (&net->dev, vq))) {
@@ -528,6 +527,9 @@ static void handle_tx(struct vhost_net *net) }break ; } +/* On error, stop handling until the next kick. */ +if (unlikely (err <0 )) +break ;if (in) {vq_err (vq,"Unexpected descriptor format for TX: " "out %d, int %d\n" , out, in);
@@ -555,7 +557,8 @@ static void handle_tx(struct vhost_net *net)struct ubuf_info *ubuf; ubuf = nvq->ubuf_info + nvq->upend_idx; - vq->heads[nvq->upend_idx].id =cpu_to_vhost32 (vq, head); + vq->heads[nvq->upend_idx].id = +cpu_to_vhost32 (vq, used.id); vq->heads[nvq->upend_idx].len =VHOST_DMA_IN_PROGRESS ; ubuf->callback = vhost_zerocopy_callback; ubuf->ctx = nvq->ubufs;
@@ -596,7 +599,7 @@ static void handle_tx(struct vhost_net *net)pr_debug ("Truncated TX packet: " " len %d != %zd\n" , err, len);if (!zcopy_used) -vhost_add_used_and_signal (&net->dev, vq, head,0 ); +vhost_add_used_and_signal (&net->dev, vq, &used,0 );else vhost_zerocopy_signal_used (net, vq);vhost_net_tx_packet (net);
@@ -754,17 +757,15 @@ static void handle_rx(struct vhost_net *net) &busyloop_intr))) { sock_len += sock_hlen; vhost_len = sock_len + vhost_hlen; - headcount =vhost_get_bufs (vq, vq->heads + nvq->done_idx, - vhost_len, &in, vq_log, &log, -likely (mergeable) ?UIO_MAXIOV :1 ); -/* On error, stop handling until the next kick. */ -if (unlikely (headcount <0 )) - goto out; + err =vhost_get_bufs (vq, vq->heads + nvq->done_idx, + vhost_len, &in, vq_log, &log, +likely (mergeable) ?UIO_MAXIOV :1 , + &headcount);/* OK, now we need to know about added descriptors. */ -if (!headcount) { +if (err == -ENOSPC ) {if (unlikely (busyloop_intr)) {vhost_poll_queue (&vq->poll); - }else if (unlikely (vhost_enable_notify (&net->dev, vq))) { + }else if (unlikely (vhost_enable_notify (&net->dev, vq))) {/* They have slipped one in as we were * doing that: check again. */ vhost_disable_notify (&net->dev, vq);
@@ -775,6 +776,9 @@ static void handle_rx(struct vhost_net *net) goto out; } busyloop_intr = false; +/* On error, stop handling until the next kick. */ +if (unlikely (err <0 )) + goto out;if (nvq->rx_ring) msg.msg_control =vhost_net_buf_consume (&nvq->rxq);/* On overrun, truncate and discard */
drivers/vhost/scsi.c +33 -29
187 lines not on this page · raw message
drivers/vhost/vhost.c +27 -25
133 lines not on this page · raw message
drivers/vhost/vhost.h +6 -3
@@ -182,6 +182,7 @@ bool vhost_vq_access_ok(struct vhost_virtqueue *vq);bool vhost_log_access_ok (struct vhost_dev *);int vhost_get_vq_desc (struct vhost_virtqueue *, +struct vring_used_elem *used_elem,struct iovec iov[],unsigned int iov_count,unsigned int *out_num,unsigned int *in_num,struct vhost_log *log,unsigned int *log_num);
@@ -191,15 +192,17 @@ int vhost_get_bufs(struct vhost_virtqueue *vq,unsigned *iovcount, struct vhost_log *log, unsigned *log_num, - unsigned int quota); + unsigned int quota, + s16 *count);void vhost_discard_vq_desc (struct vhost_virtqueue *,int n);int vhost_vq_init_access (struct vhost_virtqueue *); -int vhost_add_used (struct vhost_virtqueue *,unsigned int head,int len); +int vhost_add_used (struct vhost_virtqueue *vq, +struct vring_used_elem *elem,int len);int vhost_add_used_n (struct vhost_virtqueue *,struct vring_used_elem *heads,unsigned count);void vhost_add_used_and_signal (struct vhost_dev *,struct vhost_virtqueue *, -unsigned int id,int len); +struct vring_used_elem *,int len);void vhost_add_used_and_signal_n (struct vhost_dev *,struct vhost_virtqueue *,struct vring_used_elem *heads,unsigned count);void vhost_signal (struct vhost_dev *,struct vhost_virtqueue *);
drivers/vhost/vsock.c +21 -21
100 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v2 3/8 vhost: do not use vring_used_elem
In reply to Jason WangInstead of depending on the exported vring_used_elem, this patch switches to use a new internal structure vhost_used_elem which embed vring_used_elem in itself. This could be used to let vhost to record extra metadata for the incoming packed ring layout.
--- drivers/vhost/net.c | 19 +++++++------- drivers/vhost/scsi.c | 10 ++++---- drivers/vhost/vhost.c | 68 ++++++++++++--------------------------------------- drivers/vhost/vhost.h | 18 ++++++++------ drivers/vhost/vsock.c | 6 ++--- 5 files changed, 45 insertions(+), 76 deletions(-)
drivers/vhost/net.c +10 -9
@@ -348,10 +348,10 @@ static void vhost_zerocopy_signal_used(struct vhost_net *net,int j =0 ;for (i = nvq->done_idx; i != nvq->upend_idx; i = (i +1 ) %UIO_MAXIOV ) { -if (vq->heads[i].len ==VHOST_DMA_FAILED_LEN ) +if (vq->heads[i].elem.len ==VHOST_DMA_FAILED_LEN )vhost_net_tx_err (net); -if (VHOST_DMA_IS_DONE (vq->heads[i].len)) { - vq->heads[i].len =VHOST_DMA_CLEAR_LEN ; +if (VHOST_DMA_IS_DONE (vq->heads[i].elem.len)) { + vq->heads[i].elem.len =VHOST_DMA_CLEAR_LEN ; ++j; }else break ;
@@ -374,7 +374,7 @@ static void vhost_zerocopy_callback(struct ubuf_info *ubuf, bool success)rcu_read_lock_bh ();/* set len to mark this desc buffers done DMA */ - vq->heads[ubuf->desc].len = success ? + vq->heads[ubuf->desc].elem.len = success ?VHOST_DMA_DONE_LEN :VHOST_DMA_FAILED_LEN ; cnt =vhost_net_ubuf_put (ubufs);
@@ -430,7 +430,7 @@ static int vhost_net_enable_vq(struct vhost_net *n,static int vhost_net_tx_get_vq_desc (struct vhost_net *net,struct vhost_virtqueue *vq, -struct vring_used_elem *used_elem, +struct vhost_used_elem *used_elem,struct iovec iov[],unsigned int iov_size,unsigned int *out_num,unsigned int *in_num,bool *busyloop_intr)
@@ -488,7 +488,7 @@ static void handle_tx(struct vhost_net *net)size_t hdr_size;struct socket *sock;struct vhost_net_ubuf_ref *uninitialized_var (ubufs ); -struct vring_used_elem used; +struct vhost_used_elem used;bool zcopy, zcopy_used;int sent_pkts =0 ;
@@ -557,9 +557,10 @@ static void handle_tx(struct vhost_net *net)struct ubuf_info *ubuf; ubuf = nvq->ubuf_info + nvq->upend_idx; - vq->heads[nvq->upend_idx].id = -cpu_to_vhost32 (vq, used.id); - vq->heads[nvq->upend_idx].len =VHOST_DMA_IN_PROGRESS ; + vq->heads[nvq->upend_idx].elem.id = +cpu_to_vhost32 (vq, used.elem.id); + vq->heads[nvq->upend_idx].elem.len = +VHOST_DMA_IN_PROGRESS ; ubuf->callback = vhost_zerocopy_callback; ubuf->ctx = nvq->ubufs; ubuf->desc = nvq->upend_idx;
drivers/vhost/scsi.c +5 -5
@@ -67,7 +67,7 @@ struct vhost_scsi_inflight {struct vhost_scsi_cmd {/* Descriptor from vhost_get_vq_desc() for virt_queue segment */ -struct vring_used_elem tvc_vq_used; +struct vhost_used_elem tvc_vq_used;/* virtio-scsi initiator task attribute */ int tvc_task_attr;/* virtio-scsi response incoming iovecs */
@@ -441,7 +441,7 @@ vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt)struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT ].vq;struct virtio_scsi_event *event = &evt->event;struct virtio_scsi_event __user *eventp; -struct vring_used_elem used; +struct vhost_used_elem used;unsigned out, in;int ret;
@@ -785,7 +785,7 @@ static void vhost_scsi_submission_work(struct work_struct *work)static void vhost_scsi_send_bad_target (struct vhost_scsi *vs,struct vhost_virtqueue *vq, -struct vring_used_elem *used,unsigned out) +struct vhost_used_elem *used,unsigned out) {struct virtio_scsi_cmd_resp __user *resp;struct virtio_scsi_cmd_resp rsp;
@@ -808,7 +808,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)struct virtio_scsi_cmd_req v_req;struct virtio_scsi_cmd_req_pi v_req_pi;struct vhost_scsi_cmd *cmd; -struct vring_used_elem used; +struct vhost_used_elem used;struct iov_iter out_iter, in_iter, prot_iter, data_iter;u64 tag;u32 exp_data_len, data_direction;
@@ -837,7 +837,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)ARRAY_SIZE (vq->iov), &out, &in, NULL, NULL);pr_debug ("vhost_get_vq_desc: head: %d, out: %u in: %u\n" , - used.id, out, in); + used.elem.id, out, in);/* Nothing new? Wait for eventfd to tell us they refilled. */ if (ret == -ENOSPC ) {if (unlikely (vhost_enable_notify (&vs->dev, vq))) {
drivers/vhost/vhost.c +16 -52
142 lines not on this page · raw message
drivers/vhost/vhost.h +11 -7
@@ -34,6 +34,10 @@ struct vhost_poll {struct vhost_dev *dev; }; +struct vhost_used_elem { +struct vring_used_elem elem; +}; +void vhost_work_init (struct vhost_work *work,vhost_work_fn_t fn);void vhost_work_queue (struct vhost_dev *dev,struct vhost_work *work);bool vhost_has_work (struct vhost_dev *dev);
@@ -126,7 +130,7 @@ struct vhost_virtqueue {struct iovec iov[UIO_MAXIOV ];struct iovec iotlb_iov[64 ];struct iovec *indirect; -struct vring_used_elem *heads; +struct vhost_used_elem *heads;/* Protected by virtqueue mutex. */ struct vhost_umem *umem;struct vhost_umem *iotlb;
@@ -182,12 +186,12 @@ bool vhost_vq_access_ok(struct vhost_virtqueue *vq);bool vhost_log_access_ok (struct vhost_dev *);int vhost_get_vq_desc (struct vhost_virtqueue *, -struct vring_used_elem *used_elem, +struct vhost_used_elem *used_elem,struct iovec iov[],unsigned int iov_count,unsigned int *out_num,unsigned int *in_num,struct vhost_log *log,unsigned int *log_num); int vhost_get_bufs(struct vhost_virtqueue *vq, - struct vring_used_elem *heads, + struct vhost_used_elem *heads, int datalen, unsigned *iovcount, struct vhost_log *log,
@@ -198,13 +202,13 @@ void vhost_discard_vq_desc(struct vhost_virtqueue *, int n);int vhost_vq_init_access (struct vhost_virtqueue *);int vhost_add_used (struct vhost_virtqueue *vq, -struct vring_used_elem *elem,int len); -int vhost_add_used_n (struct vhost_virtqueue *,struct vring_used_elem *heads, +struct vhost_used_elem *elem,int len); +int vhost_add_used_n (struct vhost_virtqueue *vq,struct vhost_used_elem *heads,unsigned count);void vhost_add_used_and_signal (struct vhost_dev *,struct vhost_virtqueue *, -struct vring_used_elem *,int len); +struct vhost_used_elem *,int len);void vhost_add_used_and_signal_n (struct vhost_dev *,struct vhost_virtqueue *, -struct vring_used_elem *heads,unsigned count); +struct vhost_used_elem *heads,unsigned count);void vhost_signal (struct vhost_dev *,struct vhost_virtqueue *);void vhost_disable_notify (struct vhost_dev *,struct vhost_virtqueue *);bool vhost_vq_avail_empty (struct vhost_dev *,struct vhost_virtqueue *);
drivers/vhost/vsock.c +3 -3
@@ -98,7 +98,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,for (;;) {struct virtio_vsock_pkt *pkt; -struct vring_used_elem used; +struct vhost_used_elem used;struct iov_iter iov_iter;unsigned out, in;size_t nbytes;
@@ -146,7 +146,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,break ; } - len =vhost32_to_cpu (vq, used.len); + len =vhost32_to_cpu (vq, used.elem.len);iov_iter_init (&iov_iter,READ , &vq->iov[out], in, len); nbytes =copy_to_iter (&pkt->hdr,sizeof (pkt->hdr), &iov_iter);
@@ -346,7 +346,7 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work) struct vhost_vsock *vsock = container_of(vq->dev, struct vhost_vsock, dev);struct virtio_vsock_pkt *pkt; -struct vring_used_elem used; +struct vhost_used_elem used;int ret;unsigned int out, in;bool added = false;
Signature · 1 line
2.7.4
PATCH v2 3/8 vhost: do not use vring_used_elem
In reply to Jason WangInstead of depending on the exported vring_used_elem, this patch switches to use a new internal structure vhost_used_elem which embed vring_used_elem in itself. This could be used to let vhost to record extra metadata for the incoming packed ring layout.
--- drivers/vhost/net.c | 19 +++++++------- drivers/vhost/scsi.c | 10 ++++---- drivers/vhost/vhost.c | 68 ++++++++++++--------------------------------------- drivers/vhost/vhost.h | 18 ++++++++------ drivers/vhost/vsock.c | 6 ++--- 5 files changed, 45 insertions(+), 76 deletions(-)
drivers/vhost/net.c +10 -9
@@ -348,10 +348,10 @@ static void vhost_zerocopy_signal_used(struct vhost_net *net,int j =0 ;for (i = nvq->done_idx; i != nvq->upend_idx; i = (i +1 ) %UIO_MAXIOV ) { -if (vq->heads[i].len ==VHOST_DMA_FAILED_LEN ) +if (vq->heads[i].elem.len ==VHOST_DMA_FAILED_LEN )vhost_net_tx_err (net); -if (VHOST_DMA_IS_DONE (vq->heads[i].len)) { - vq->heads[i].len =VHOST_DMA_CLEAR_LEN ; +if (VHOST_DMA_IS_DONE (vq->heads[i].elem.len)) { + vq->heads[i].elem.len =VHOST_DMA_CLEAR_LEN ; ++j; }else break ;
@@ -374,7 +374,7 @@ static void vhost_zerocopy_callback(struct ubuf_info *ubuf, bool success)rcu_read_lock_bh ();/* set len to mark this desc buffers done DMA */ - vq->heads[ubuf->desc].len = success ? + vq->heads[ubuf->desc].elem.len = success ?VHOST_DMA_DONE_LEN :VHOST_DMA_FAILED_LEN ; cnt =vhost_net_ubuf_put (ubufs);
@@ -430,7 +430,7 @@ static int vhost_net_enable_vq(struct vhost_net *n,static int vhost_net_tx_get_vq_desc (struct vhost_net *net,struct vhost_virtqueue *vq, -struct vring_used_elem *used_elem, +struct vhost_used_elem *used_elem,struct iovec iov[],unsigned int iov_size,unsigned int *out_num,unsigned int *in_num,bool *busyloop_intr)
@@ -488,7 +488,7 @@ static void handle_tx(struct vhost_net *net)size_t hdr_size;struct socket *sock;struct vhost_net_ubuf_ref *uninitialized_var (ubufs ); -struct vring_used_elem used; +struct vhost_used_elem used;bool zcopy, zcopy_used;int sent_pkts =0 ;
@@ -557,9 +557,10 @@ static void handle_tx(struct vhost_net *net)struct ubuf_info *ubuf; ubuf = nvq->ubuf_info + nvq->upend_idx; - vq->heads[nvq->upend_idx].id = -cpu_to_vhost32 (vq, used.id); - vq->heads[nvq->upend_idx].len =VHOST_DMA_IN_PROGRESS ; + vq->heads[nvq->upend_idx].elem.id = +cpu_to_vhost32 (vq, used.elem.id); + vq->heads[nvq->upend_idx].elem.len = +VHOST_DMA_IN_PROGRESS ; ubuf->callback = vhost_zerocopy_callback; ubuf->ctx = nvq->ubufs; ubuf->desc = nvq->upend_idx;
drivers/vhost/scsi.c +5 -5
@@ -67,7 +67,7 @@ struct vhost_scsi_inflight {struct vhost_scsi_cmd {/* Descriptor from vhost_get_vq_desc() for virt_queue segment */ -struct vring_used_elem tvc_vq_used; +struct vhost_used_elem tvc_vq_used;/* virtio-scsi initiator task attribute */ int tvc_task_attr;/* virtio-scsi response incoming iovecs */
@@ -441,7 +441,7 @@ vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt)struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT ].vq;struct virtio_scsi_event *event = &evt->event;struct virtio_scsi_event __user *eventp; -struct vring_used_elem used; +struct vhost_used_elem used;unsigned out, in;int ret;
@@ -785,7 +785,7 @@ static void vhost_scsi_submission_work(struct work_struct *work)static void vhost_scsi_send_bad_target (struct vhost_scsi *vs,struct vhost_virtqueue *vq, -struct vring_used_elem *used,unsigned out) +struct vhost_used_elem *used,unsigned out) {struct virtio_scsi_cmd_resp __user *resp;struct virtio_scsi_cmd_resp rsp;
@@ -808,7 +808,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)struct virtio_scsi_cmd_req v_req;struct virtio_scsi_cmd_req_pi v_req_pi;struct vhost_scsi_cmd *cmd; -struct vring_used_elem used; +struct vhost_used_elem used;struct iov_iter out_iter, in_iter, prot_iter, data_iter;u64 tag;u32 exp_data_len, data_direction;
@@ -837,7 +837,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)ARRAY_SIZE (vq->iov), &out, &in, NULL, NULL);pr_debug ("vhost_get_vq_desc: head: %d, out: %u in: %u\n" , - used.id, out, in); + used.elem.id, out, in);/* Nothing new? Wait for eventfd to tell us they refilled. */ if (ret == -ENOSPC ) {if (unlikely (vhost_enable_notify (&vs->dev, vq))) {
drivers/vhost/vhost.c +16 -52
142 lines not on this page · raw message
drivers/vhost/vhost.h +11 -7
@@ -34,6 +34,10 @@ struct vhost_poll {struct vhost_dev *dev; }; +struct vhost_used_elem { +struct vring_used_elem elem; +}; +void vhost_work_init (struct vhost_work *work,vhost_work_fn_t fn);void vhost_work_queue (struct vhost_dev *dev,struct vhost_work *work);bool vhost_has_work (struct vhost_dev *dev);
@@ -126,7 +130,7 @@ struct vhost_virtqueue {struct iovec iov[UIO_MAXIOV ];struct iovec iotlb_iov[64 ];struct iovec *indirect; -struct vring_used_elem *heads; +struct vhost_used_elem *heads;/* Protected by virtqueue mutex. */ struct vhost_umem *umem;struct vhost_umem *iotlb;
@@ -182,12 +186,12 @@ bool vhost_vq_access_ok(struct vhost_virtqueue *vq);bool vhost_log_access_ok (struct vhost_dev *);int vhost_get_vq_desc (struct vhost_virtqueue *, -struct vring_used_elem *used_elem, +struct vhost_used_elem *used_elem,struct iovec iov[],unsigned int iov_count,unsigned int *out_num,unsigned int *in_num,struct vhost_log *log,unsigned int *log_num); int vhost_get_bufs(struct vhost_virtqueue *vq, - struct vring_used_elem *heads, + struct vhost_used_elem *heads, int datalen, unsigned *iovcount, struct vhost_log *log,
@@ -198,13 +202,13 @@ void vhost_discard_vq_desc(struct vhost_virtqueue *, int n);int vhost_vq_init_access (struct vhost_virtqueue *);int vhost_add_used (struct vhost_virtqueue *vq, -struct vring_used_elem *elem,int len); -int vhost_add_used_n (struct vhost_virtqueue *,struct vring_used_elem *heads, +struct vhost_used_elem *elem,int len); +int vhost_add_used_n (struct vhost_virtqueue *vq,struct vhost_used_elem *heads,unsigned count);void vhost_add_used_and_signal (struct vhost_dev *,struct vhost_virtqueue *, -struct vring_used_elem *,int len); +struct vhost_used_elem *,int len);void vhost_add_used_and_signal_n (struct vhost_dev *,struct vhost_virtqueue *, -struct vring_used_elem *heads,unsigned count); +struct vhost_used_elem *heads,unsigned count);void vhost_signal (struct vhost_dev *,struct vhost_virtqueue *);void vhost_disable_notify (struct vhost_dev *,struct vhost_virtqueue *);bool vhost_vq_avail_empty (struct vhost_dev *,struct vhost_virtqueue *);
drivers/vhost/vsock.c +3 -3
@@ -98,7 +98,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,for (;;) {struct virtio_vsock_pkt *pkt; -struct vring_used_elem used; +struct vhost_used_elem used;struct iov_iter iov_iter;unsigned out, in;size_t nbytes;
@@ -146,7 +146,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,break ; } - len =vhost32_to_cpu (vq, used.len); + len =vhost32_to_cpu (vq, used.elem.len);iov_iter_init (&iov_iter,READ , &vq->iov[out], in, len); nbytes =copy_to_iter (&pkt->hdr,sizeof (pkt->hdr), &iov_iter);
@@ -346,7 +346,7 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work) struct vhost_vsock *vsock = container_of(vq->dev, struct vhost_vsock, dev);struct virtio_vsock_pkt *pkt; -struct vring_used_elem used; +struct vhost_used_elem used;int ret;unsigned int out, in;bool added = false;
Signature · 1 line
2.7.4
PATCH v2 4/8 vhost_net: do not explicitly manipulate vhost_used_elem
In reply to Jason WangTwo helpers of setting/getting used len were introduced to avoid explicitly manipulating vhost_used_elem in zerocopy code. This will be used to hide used_elem internals and simplify packed ring implementation.
--- drivers/vhost/net.c | 11 +++++------ drivers/vhost/vhost.c | 12 ++++++++++-- drivers/vhost/vhost.h | 5 +++++ 3 files changed, 20 insertions(+), 8 deletions(-)
drivers/vhost/net.c +5 -6
@@ -348,9 +348,10 @@ static void vhost_zerocopy_signal_used(struct vhost_net *net,int j =0 ;for (i = nvq->done_idx; i != nvq->upend_idx; i = (i +1 ) %UIO_MAXIOV ) { -if (vq->heads[i].elem.len ==VHOST_DMA_FAILED_LEN ) +if (vhost_get_used_len (vq, &vq->heads[i]) == +VHOST_DMA_FAILED_LEN )vhost_net_tx_err (net); -if (VHOST_DMA_IS_DONE (vq->heads[i].elem.len)) { +if (VHOST_DMA_IS_DONE (vhost_get_used_len (vq, &vq->heads[i]))) { vq->heads[i].elem.len =VHOST_DMA_CLEAR_LEN ; ++j; }else
@@ -557,10 +558,8 @@ static void handle_tx(struct vhost_net *net)struct ubuf_info *ubuf; ubuf = nvq->ubuf_info + nvq->upend_idx; - vq->heads[nvq->upend_idx].elem.id = -cpu_to_vhost32 (vq, used.elem.id); - vq->heads[nvq->upend_idx].elem.len = -VHOST_DMA_IN_PROGRESS ; +vhost_set_used_len (vq, &used,VHOST_DMA_IN_PROGRESS ); + vq->heads[nvq->upend_idx] = used; ubuf->callback = vhost_zerocopy_callback; ubuf->ctx = nvq->ubufs; ubuf->desc = nvq->upend_idx;
drivers/vhost/vhost.c +10 -2
@@ -2071,11 +2071,19 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq, }EXPORT_SYMBOL_GPL (vhost_get_vq_desc); -static void vhost_set_used_len (struct vhost_virtqueue *vq, -struct vhost_used_elem *used,int len) +void vhost_set_used_len (struct vhost_virtqueue *vq, +struct vhost_used_elem *used,int len) { used->elem.len =cpu_to_vhost32 (vq, len); } +EXPORT_SYMBOL_GPL (vhost_set_used_len); + +int vhost_get_used_len (struct vhost_virtqueue *vq, +struct vhost_used_elem *used) +{ +return vhost32_to_cpu (vq, used->elem.len); +} +EXPORT_SYMBOL_GPL (vhost_get_used_len);/* This is a multi-buffer version of vhost_get_desc, that works if * vq has read descriptors only.
drivers/vhost/vhost.h +5 -0
@@ -198,6 +198,11 @@ int vhost_get_bufs(struct vhost_virtqueue *vq,unsigned *log_num, unsigned int quota, s16 *count); +void vhost_set_used_len (struct vhost_virtqueue *vq, +struct vhost_used_elem *used, +int len); +int vhost_get_used_len (struct vhost_virtqueue *vq, +struct vhost_used_elem *used);void vhost_discard_vq_desc (struct vhost_virtqueue *,int n);int vhost_vq_init_access (struct vhost_virtqueue *);
Signature · 1 line
2.7.4
PATCH v2 4/8 vhost_net: do not explicitly manipulate vhost_used_elem
In reply to Jason WangTwo helpers of setting/getting used len were introduced to avoid explicitly manipulating vhost_used_elem in zerocopy code. This will be used to hide used_elem internals and simplify packed ring implementation.
--- drivers/vhost/net.c | 11 +++++------ drivers/vhost/vhost.c | 12 ++++++++++-- drivers/vhost/vhost.h | 5 +++++ 3 files changed, 20 insertions(+), 8 deletions(-)
drivers/vhost/net.c +5 -6
@@ -348,9 +348,10 @@ static void vhost_zerocopy_signal_used(struct vhost_net *net,int j =0 ;for (i = nvq->done_idx; i != nvq->upend_idx; i = (i +1 ) %UIO_MAXIOV ) { -if (vq->heads[i].elem.len ==VHOST_DMA_FAILED_LEN ) +if (vhost_get_used_len (vq, &vq->heads[i]) == +VHOST_DMA_FAILED_LEN )vhost_net_tx_err (net); -if (VHOST_DMA_IS_DONE (vq->heads[i].elem.len)) { +if (VHOST_DMA_IS_DONE (vhost_get_used_len (vq, &vq->heads[i]))) { vq->heads[i].elem.len =VHOST_DMA_CLEAR_LEN ; ++j; }else
@@ -557,10 +558,8 @@ static void handle_tx(struct vhost_net *net)struct ubuf_info *ubuf; ubuf = nvq->ubuf_info + nvq->upend_idx; - vq->heads[nvq->upend_idx].elem.id = -cpu_to_vhost32 (vq, used.elem.id); - vq->heads[nvq->upend_idx].elem.len = -VHOST_DMA_IN_PROGRESS ; +vhost_set_used_len (vq, &used,VHOST_DMA_IN_PROGRESS ); + vq->heads[nvq->upend_idx] = used; ubuf->callback = vhost_zerocopy_callback; ubuf->ctx = nvq->ubufs; ubuf->desc = nvq->upend_idx;
drivers/vhost/vhost.c +10 -2
@@ -2071,11 +2071,19 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq, }EXPORT_SYMBOL_GPL (vhost_get_vq_desc); -static void vhost_set_used_len (struct vhost_virtqueue *vq, -struct vhost_used_elem *used,int len) +void vhost_set_used_len (struct vhost_virtqueue *vq, +struct vhost_used_elem *used,int len) { used->elem.len =cpu_to_vhost32 (vq, len); } +EXPORT_SYMBOL_GPL (vhost_set_used_len); + +int vhost_get_used_len (struct vhost_virtqueue *vq, +struct vhost_used_elem *used) +{ +return vhost32_to_cpu (vq, used->elem.len); +} +EXPORT_SYMBOL_GPL (vhost_get_used_len);/* This is a multi-buffer version of vhost_get_desc, that works if * vq has read descriptors only.
drivers/vhost/vhost.h +5 -0
@@ -198,6 +198,11 @@ int vhost_get_bufs(struct vhost_virtqueue *vq,unsigned *log_num, unsigned int quota, s16 *count); +void vhost_set_used_len (struct vhost_virtqueue *vq, +struct vhost_used_elem *used, +int len); +int vhost_get_used_len (struct vhost_virtqueue *vq, +struct vhost_used_elem *used);void vhost_discard_vq_desc (struct vhost_virtqueue *,int n);int vhost_vq_init_access (struct vhost_virtqueue *);
Signature · 1 line
2.7.4
PATCH v2 5/8 vhost: vhost_put_user() can accept metadata type
In reply to Jason WangWe assumes used ring update is the only user for vhost_put_user() in the past. This may not be the case for the incoming packed ring which may update the descriptor ring for used. So introduce a new type parameter.
--- drivers/vhost/vhost.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/vhost/vhost.c +7 -7
@@ -814,7 +814,7 @@ static inline void __user *__vhost_get_user(struct vhost_virtqueue *vq,return __vhost_get_user_slow (vq, addr, size, type); } -#define vhost_put_user (vq, x, ptr) \ +#define vhost_put_user (vq, x, ptr, type) \ ({ \ int ret = -EFAULT; \ if (!vq->iotlb) { \
@@ -822,7 +822,7 @@ static inline void __user *__vhost_get_user(struct vhost_virtqueue *vq, }else { \__typeof__ (ptr) to = \ (__typeof__ (ptr ))__vhost_get_user (vq, ptr, \ -sizeof (*ptr),VHOST_ADDR_USED ); \ +sizeof (*ptr), type); \if (to !=NULL ) \ ret =__put_user (x, to); \else \
@@ -1687,7 +1687,7 @@ static int vhost_update_used_flags(struct vhost_virtqueue *vq) {void __user *used;if (vhost_put_user (vq,cpu_to_vhost16 (vq, vq->used_flags), - &vq->used->flags) <0 ) + &vq->used->flags,VHOST_ADDR_USED ) <0 )return -EFAULT ;if (unlikely (vq->log_used)) {/* Make sure the flag is seen before log. */
@@ -1706,7 +1706,7 @@ static int vhost_update_used_flags(struct vhost_virtqueue *vq)static int vhost_update_avail_event (struct vhost_virtqueue *vq,u16 avail_event) {if (vhost_put_user (vq,cpu_to_vhost16 (vq, vq->avail_idx), -vhost_avail_event (vq))) +vhost_avail_event (vq),VHOST_ADDR_USED ))return -EFAULT ;if (unlikely (vq->log_used)) {void __user *used;
@@ -2189,12 +2189,12 @@ static int __vhost_add_used_n(struct vhost_virtqueue *vq, used = vq->used->ring + start;for (i =0 ; i < count; i++) {if (unlikely (vhost_put_user (vq, heads[i].elem.id, - &used[i].id))) { + &used[i].id,VHOST_ADDR_USED ))) {vq_err (vq,"Failed to write used id" );return -EFAULT ; }if (unlikely (vhost_put_user (vq, heads[i].elem.len, - &used[i].len))) { + &used[i].len,VHOST_ADDR_USED ))) {vq_err (vq,"Failed to write used len" );return -EFAULT ; }
@@ -2240,7 +2240,7 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vhost_used_elem *heads,/* Make sure buffer is written before we update index. */ smp_wmb ();if (vhost_put_user (vq,cpu_to_vhost16 (vq, vq->last_used_idx), - &vq->used->idx)) { + &vq->used->idx,VHOST_ADDR_USED )) {vq_err (vq,"Failed to increment used idx" );return -EFAULT ; }
Signature · 1 line
2.7.4
PATCH v2 5/8 vhost: vhost_put_user() can accept metadata type
In reply to Jason WangWe assumes used ring update is the only user for vhost_put_user() in the past. This may not be the case for the incoming packed ring which may update the descriptor ring for used. So introduce a new type parameter.
--- drivers/vhost/vhost.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/vhost/vhost.c +7 -7
@@ -814,7 +814,7 @@ static inline void __user *__vhost_get_user(struct vhost_virtqueue *vq,return __vhost_get_user_slow (vq, addr, size, type); } -#define vhost_put_user (vq, x, ptr) \ +#define vhost_put_user (vq, x, ptr, type) \ ({ \ int ret = -EFAULT; \ if (!vq->iotlb) { \
@@ -822,7 +822,7 @@ static inline void __user *__vhost_get_user(struct vhost_virtqueue *vq, }else { \__typeof__ (ptr) to = \ (__typeof__ (ptr ))__vhost_get_user (vq, ptr, \ -sizeof (*ptr),VHOST_ADDR_USED ); \ +sizeof (*ptr), type); \if (to !=NULL ) \ ret =__put_user (x, to); \else \
@@ -1687,7 +1687,7 @@ static int vhost_update_used_flags(struct vhost_virtqueue *vq) {void __user *used;if (vhost_put_user (vq,cpu_to_vhost16 (vq, vq->used_flags), - &vq->used->flags) <0 ) + &vq->used->flags,VHOST_ADDR_USED ) <0 )return -EFAULT ;if (unlikely (vq->log_used)) {/* Make sure the flag is seen before log. */
@@ -1706,7 +1706,7 @@ static int vhost_update_used_flags(struct vhost_virtqueue *vq)static int vhost_update_avail_event (struct vhost_virtqueue *vq,u16 avail_event) {if (vhost_put_user (vq,cpu_to_vhost16 (vq, vq->avail_idx), -vhost_avail_event (vq))) +vhost_avail_event (vq),VHOST_ADDR_USED ))return -EFAULT ;if (unlikely (vq->log_used)) {void __user *used;
@@ -2189,12 +2189,12 @@ static int __vhost_add_used_n(struct vhost_virtqueue *vq, used = vq->used->ring + start;for (i =0 ; i < count; i++) {if (unlikely (vhost_put_user (vq, heads[i].elem.id, - &used[i].id))) { + &used[i].id,VHOST_ADDR_USED ))) {vq_err (vq,"Failed to write used id" );return -EFAULT ; }if (unlikely (vhost_put_user (vq, heads[i].elem.len, - &used[i].len))) { + &used[i].len,VHOST_ADDR_USED ))) {vq_err (vq,"Failed to write used len" );return -EFAULT ; }
@@ -2240,7 +2240,7 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vhost_used_elem *heads,/* Make sure buffer is written before we update index. */ smp_wmb ();if (vhost_put_user (vq,cpu_to_vhost16 (vq, vq->last_used_idx), - &vq->used->idx)) { + &vq->used->idx,VHOST_ADDR_USED )) {vq_err (vq,"Failed to increment used idx" );return -EFAULT ; }
Signature · 1 line
2.7.4
PATCH v2 6/8 vhost: packed ring support
In reply to Jason WangThis patch introduces basic support for packed ring. The idea behinds packed ring is to use a single descriptor ring instead of three different rings (avail, used and descriptor). This could help to reduce the cache contention and PCI transactions. So it was designed to help for the performance for both software implementation and hardware implementation.
The implementation was straightforward, packed version of vhost core (whose name has a packed suffix) helpers were introduced and previous helpers were renamed with a split suffix. Then the exported helpers can just do a switch to go to the correct internal helpers.
The event suppression (device area and driver area) were not implemented. It will be done on top with another patch.
For more information of packed ring, please refer Virtio spec.
--- drivers/vhost/net.c | 12 +- drivers/vhost/vhost.c | 653 ++++++++++++++++++++++++++++++++++++++++++--- drivers/vhost/vhost.h | 13 +- include/uapi/linux/vhost.h | 7 + 4 files changed, 640 insertions(+), 45 deletions(-)
drivers/vhost/net.c +7 -5
@@ -591,7 +591,7 @@ static void handle_tx(struct vhost_net *net) nvq->upend_idx = ((unsigned )nvq->upend_idx -1 ) %UIO_MAXIOV ; } -vhost_discard_vq_desc (vq,1 ); +vhost_discard_vq_desc (vq, &used,1 );vhost_net_enable_vq (net, vq);break ; }
@@ -755,10 +755,12 @@ static void handle_rx(struct vhost_net *net)while ((sock_len =vhost_net_rx_peek_head_len (net, sock->sk, &busyloop_intr))) { +struct vhost_used_elem *used = vq->heads + nvq->done_idx; + sock_len += sock_hlen; vhost_len = sock_len + vhost_hlen; - err =vhost_get_bufs (vq, vq->heads + nvq->done_idx, - vhost_len, &in, vq_log, &log, + err =vhost_get_bufs (vq, used, vhost_len, + &in, vq_log, &log,likely (mergeable) ?UIO_MAXIOV :1 , &headcount);/* OK, now we need to know about added descriptors. */
@@ -806,7 +808,7 @@ static void handle_rx(struct vhost_net *net)if (unlikely (err != sock_len)) {pr_debug ("Discarded rx packet: " " len %d, expected %zd\n" , err, sock_len); -vhost_discard_vq_desc (vq, headcount); +vhost_discard_vq_desc (vq, used,1 );continue ; }/* Supply virtio_net_hdr if VHOST_NET_F_VIRTIO_NET_HDR */
@@ -830,7 +832,7 @@ static void handle_rx(struct vhost_net *net) copy_to_iter(&num_buffers, sizeof num_buffers, &fixup) != sizeof num_buffers) {vq_err (vq,"Failed num_buffers write" ); -vhost_discard_vq_desc (vq, headcount); +vhost_discard_vq_desc (vq, used,1 ); goto out; } nvq->done_idx += headcount;
drivers/vhost/vhost.c +615 -38
799 lines not on this page · raw message
drivers/vhost/vhost.h +11 -2
@@ -36,6 +36,7 @@ struct vhost_poll {struct vhost_used_elem {struct vring_used_elem elem; +int count; };void vhost_work_init (struct vhost_work *work,vhost_work_fn_t fn);
@@ -91,7 +92,10 @@ struct vhost_virtqueue {/* The actual ring of buffers. */ struct mutex mutex;unsigned int num; -struct vring_desc __user *desc; +union { +struct vring_desc __user *desc; +struct vring_packed_desc __user *desc_packed; + };struct vring_avail __user *avail;struct vring_used __user *used;const struct vhost_umem_node *meta_iotlb[VHOST_NUM_ADDRS ];
@@ -148,6 +152,9 @@ struct vhost_virtqueue {bool user_be;#endif u32 busyloop_timeout; +bool last_used_wrap_counter; +bool avail_wrap_counter; +bool last_avail_wrap_counter; };struct vhost_msg_node {
@@ -203,7 +210,9 @@ void vhost_set_used_len(struct vhost_virtqueue *vq, int len);int vhost_get_used_len (struct vhost_virtqueue *vq,struct vhost_used_elem *used); -void vhost_discard_vq_desc (struct vhost_virtqueue *,int n); +void vhost_discard_vq_desc (struct vhost_virtqueue *vq, +struct vhost_used_elem *elem, +int n);int vhost_vq_init_access (struct vhost_virtqueue *); int vhost_add_used(struct vhost_virtqueue *vq,
include/uapi/linux/vhost.h +7 -0
@@ -160,6 +160,13 @@ struct vhost_memory {#define VHOST_GET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x24, \ struct vhost_vring_state) +/* Base value where queue looks for used descriptors */ +#define VHOST_SET_VRING_USED_BASE _IOW(VHOST_VIRTIO, 0x25, \ + struct vhost_vring_state) +/* Get accessor: reads index, writes value in num */ +#define VHOST_GET_VRING_USED_BASE _IOWR(VHOST_VIRTIO, 0x26, \ + struct vhost_vring_state) +/* VHOST_NET specific defines */ /* Attach virtio net ring to a raw socket, or tap device.
Signature · 1 line
2.7.4
Re: [PATCH net-next V2 6/8] vhost: packed ring support
On Mon, Jul 16, 2018 at 11:28:09AM +0800, Jason Wang wrote:
[...]
Quoted 27 lines
drivers/vhost/vhost.c +19
-0@@ -1367,10 +1397,48 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg vq->last_avail_idx = s.num;/* Forget the cached index value. */ vq->avail_idx = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) { + vq->last_avail_wrap_counter = wrap_counter; + vq->avail_wrap_counter = vq->last_avail_wrap_counter; + }break ;case VHOST_GET_VRING_BASE : s.index = idx; s.num = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_avail_wrap_counter <<31 ; +if (copy_to_user (argp, &s,sizeof (s))) + r = -EFAULT ; +break ; +case VHOST_SET_VRING_USED_BASE : +/* Moving base with an active backend? +* You don't want to do that. +*/ +if (vq->private_data) { + r = -EBUSY ; +break ; + } +if (copy_from_user (&s, argp,sizeof (s))) { + r = -EFAULT ;
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1432
Quoted 10 lines
drivers/vhost/vhost.c +10
-0+break ; + } +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) { + wrap_counter = s.num >>31 ; + s.num &= ~(1 <<31 ); + } +if (s.num >0xffff ) { + r = -EINVAL ; +break ; + }
Do we want to put wrap_counter at bit 15?
If put wrap_counter at bit 31, the check (s.num > 0xffff) won't be able to catch the illegal index 0x8000~0xffff for packed ring.
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1437
Quoted 5 lines
drivers/vhost/vhost.c +5
-0+ vq->last_used_idx = s.num; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + vq->last_used_wrap_counter = wrap_counter; +break ; +case VHOST_GET_VRING_USED_BASE :
Do we need the new VHOST_GET_VRING_USED_BASE andVHOST_SET_VRING_USED_BASE ops?
We are going to merge below series in DPDK:
http://patches.dpdk.org/patch/45874/
We may need to reach an agreement first.
Quoted 7 lines
drivers/vhost/vhost.c +4
-0+ s.index = idx; + s.num = vq->last_used_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_used_wrap_counter <<31 ;if (copy_to_user (argp, &s,sizeof s)) r = -EFAULT ;break ;
[...]
Michael S. Tsirkin
maintainerRe: [PATCH net-next V2 6/8] vhost: packed ring support
Quoted 33 lines · Tiwei Bie
On Mon, Jul 16, 2018 at 11:28:09AM +0800, Jason Wang wrote:
[...]Quoted 31 lines
drivers/vhost/vhost.c +23
-0@@ -1367,10 +1397,48 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg vq->last_avail_idx = s.num;/* Forget the cached index value. */ vq->avail_idx = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) { + vq->last_avail_wrap_counter = wrap_counter; + vq->avail_wrap_counter = vq->last_avail_wrap_counter; + }break ;case VHOST_GET_VRING_BASE : s.index = idx; s.num = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_avail_wrap_counter <<31 ; +if (copy_to_user (argp, &s,sizeof (s))) + r = -EFAULT ; +break ; +case VHOST_SET_VRING_USED_BASE : +/* Moving base with an active backend? +* You don't want to do that. +*/ +if (vq->private_data) { + r = -EBUSY ; +break ; + } +if (copy_from_user (&s, argp,sizeof (s))) { + r = -EFAULT ; +break ; + } +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) { + wrap_counter = s.num >>31 ;
Quoted 8 lines
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1432
Quoted 6 lines
drivers/vhost/vhost.c +6
-0+ s.num &= ~(1 <<31 ); + } +if (s.num >0xffff ) { + r = -EINVAL ; +break ; + }Do we want to put
wrap_counterat bit 15?
I think I second that - seems to be consistent with e.g. event suppression structure and the proposed extension to driver notifications.
Quoted 28 lines
If put
wrap_counterat bit 31, the check (s.num >0xffff) won't be able to catch the illegal index 0x8000~0xffff for packed ring.drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1437
Quoted 5 lines
drivers/vhost/vhost.c +5
-0+ vq->last_used_idx = s.num; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + vq->last_used_wrap_counter = wrap_counter; +break ; +case VHOST_GET_VRING_USED_BASE :Do we need the new
VHOST_GET_VRING_USED_BASEandVHOST_SET_VRING_USED_BASEops?We are going to merge below series in DPDK:
http://patches.dpdk.org/patch/45874/
We may need to reach an agreement first.
Quoted 7 lines
drivers/vhost/vhost.c +4
-0+ s.index = idx; + s.num = vq->last_used_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_used_wrap_counter <<31 ;if (copy_to_user (argp, &s,sizeof s)) r = -EFAULT ;break ;[...]
Re: [PATCH net-next V2 6/8] vhost: packed ring support
Quoted 41 lines · Michael S. Tsirkin
Quoted 32 lines · Tiwei Bie
On Mon, Jul 16, 2018 at 11:28:09AM +0800, Jason Wang wrote:
[...]Quoted 30 lines
drivers/vhost/vhost.c +22
-0@@ -1367,10 +1397,48 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg vq->last_avail_idx = s.num;/* Forget the cached index value. */ vq->avail_idx = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) { + vq->last_avail_wrap_counter = wrap_counter; + vq->avail_wrap_counter = vq->last_avail_wrap_counter; + }break ;case VHOST_GET_VRING_BASE : s.index = idx; s.num = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_avail_wrap_counter <<31 ; +if (copy_to_user (argp, &s,sizeof (s))) + r = -EFAULT ; +break ; +case VHOST_SET_VRING_USED_BASE : +/* Moving base with an active backend? +* You don't want to do that. +*/ +if (vq->private_data) { + r = -EBUSY ; +break ; + } +if (copy_from_user (&s, argp,sizeof (s))) { + r = -EFAULT ; +break ; + } +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) {Quoted 8 lines
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1432
Quoted 7 lines
drivers/vhost/vhost.c +7
-0+ wrap_counter = s.num >>31 ; + s.num &= ~(1 <<31 ); + } +if (s.num >0xffff ) { + r = -EINVAL ; +break ; + }Do we want to put
wrap_counterat bit 15?
Quoted 3 lines
I think I second that - seems to be consistent with e.g. event suppression structure and the proposed extension to driver notifications.
Ok, I assumes packed virtqueue support 64K but looks not. I can change it to bit 15 and GET_VRING_BASE need to be changed as well.
Quoted 6 lines
Quoted 6 lines
If put
wrap_counterat bit 31, the check (s.num >0xffff) won't be able to catch the illegal index 0x8000~0xffff for packed ring.
Do we need to clarify this in the spec?
Quoted 8 lines
Quoted 8 lines
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1437
Quoted 5 lines
drivers/vhost/vhost.c +5
-0+ vq->last_used_idx = s.num; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + vq->last_used_wrap_counter = wrap_counter; +break ; +case VHOST_GET_VRING_USED_BASE :Do we need the new
VHOST_GET_VRING_USED_BASEandVHOST_SET_VRING_USED_BASEops?
Quoted 5 lines
Quoted 5 lines
We are going to merge below series in DPDK:
http://patches.dpdk.org/patch/45874/
We may need to reach an agreement first.
If we agree that 64K virtqueue won't be supported, I'm ok with either.
Btw the code assumes used_wrap_counter is equal to avail_wrap_counter which looks wrong?
Thanks
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
drivers/vhost/vhost.c +4
-0+ s.index = idx; + s.num = vq->last_used_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_used_wrap_counter <<31 ;if (copy_to_user (argp, &s,sizeof s)) r = -EFAULT ;break ;[...]
Michael S. Tsirkin
maintainerRe: [PATCH net-next V2 6/8] vhost: packed ring support
Quoted 53 lines · Jason Wang
Quoted 41 lines · Michael S. Tsirkin
Quoted 32 lines · Tiwei Bie
On Mon, Jul 16, 2018 at 11:28:09AM +0800, Jason Wang wrote:
[...]Quoted 30 lines
drivers/vhost/vhost.c +22
-0@@ -1367,10 +1397,48 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg vq->last_avail_idx = s.num;/* Forget the cached index value. */ vq->avail_idx = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) { + vq->last_avail_wrap_counter = wrap_counter; + vq->avail_wrap_counter = vq->last_avail_wrap_counter; + }break ;case VHOST_GET_VRING_BASE : s.index = idx; s.num = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_avail_wrap_counter <<31 ; +if (copy_to_user (argp, &s,sizeof (s))) + r = -EFAULT ; +break ; +case VHOST_SET_VRING_USED_BASE : +/* Moving base with an active backend? +* You don't want to do that. +*/ +if (vq->private_data) { + r = -EBUSY ; +break ; + } +if (copy_from_user (&s, argp,sizeof (s))) { + r = -EFAULT ; +break ; + } +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) {Quoted 8 lines
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1432
Quoted 7 lines
drivers/vhost/vhost.c +7
-0+ wrap_counter = s.num >>31 ; + s.num &= ~(1 <<31 ); + } +if (s.num >0xffff ) { + r = -EINVAL ; +break ; + }Do we want to put
wrap_counterat bit 15?Quoted 3 lines
I think I second that - seems to be consistent with e.g. event suppression structure and the proposed extension to driver notifications.
Ok, I assumes packed virtqueue support 64K but looks not. I can change it to bit 15 and
GET_VRING_BASEneed to be changed as well.Quoted 2 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
If put
wrap_counterat bit 31, the check (s.num >0xffff) won't be able to catch the illegal index 0x8000~0xffff for packed ring.Do we need to clarify this in the spec?
Isn't this all internal vhost stuff?
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1437
Quoted 5 lines
drivers/vhost/vhost.c +5
-0+ vq->last_used_idx = s.num; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + vq->last_used_wrap_counter = wrap_counter; +break ; +case VHOST_GET_VRING_USED_BASE :Do we need the new
VHOST_GET_VRING_USED_BASEandVHOST_SET_VRING_USED_BASEops?
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
We are going to merge below series in DPDK:
http://patches.dpdk.org/patch/45874/
We may need to reach an agreement first.
If we agree that 64K virtqueue won't be supported, I'm ok with either.
Well the spec says right at the beginning:
Packed virtqueues support up to 2 15 entries each.
Quoted 14 lines
Btw the code assumes
used_wrap_counteris equal toavail_wrap_counterwhich looks wrong?Thanks
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
drivers/vhost/vhost.c +4
-0+ s.index = idx; + s.num = vq->last_used_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_used_wrap_counter <<31 ;if (copy_to_user (argp, &s,sizeof s)) r = -EFAULT ;break ;[...]
Re: [PATCH net-next V2 6/8] vhost: packed ring support
Quoted 51 lines · Michael S. Tsirkin
Quoted 50 lines · Jason Wang
Quoted 41 lines · Michael S. Tsirkin
Quoted 32 lines · Tiwei Bie
On Mon, Jul 16, 2018 at 11:28:09AM +0800, Jason Wang wrote:
[...]Quoted 30 lines
drivers/vhost/vhost.c +22
-0@@ -1367,10 +1397,48 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg vq->last_avail_idx = s.num;/* Forget the cached index value. */ vq->avail_idx = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) { + vq->last_avail_wrap_counter = wrap_counter; + vq->avail_wrap_counter = vq->last_avail_wrap_counter; + }break ;case VHOST_GET_VRING_BASE : s.index = idx; s.num = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_avail_wrap_counter <<31 ; +if (copy_to_user (argp, &s,sizeof (s))) + r = -EFAULT ; +break ; +case VHOST_SET_VRING_USED_BASE : +/* Moving base with an active backend? +* You don't want to do that. +*/ +if (vq->private_data) { + r = -EBUSY ; +break ; + } +if (copy_from_user (&s, argp,sizeof (s))) { + r = -EFAULT ; +break ; + } +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) {Quoted 8 lines
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1432
Quoted 7 lines
drivers/vhost/vhost.c +7
-0+ wrap_counter = s.num >>31 ; + s.num &= ~(1 <<31 ); + } +if (s.num >0xffff ) { + r = -EINVAL ; +break ; + }Do we want to put
wrap_counterat bit 15?Quoted 3 lines
I think I second that - seems to be consistent with e.g. event suppression structure and the proposed extension to driver notifications.
Ok, I assumes packed virtqueue support 64K but looks not. I can change it to bit 15 and
GET_VRING_BASEneed to be changed as well.Quoted 1 line
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
If put
wrap_counterat bit 31, the check (s.num >0xffff) won't be able to catch the illegal index 0x8000~0xffff for packed ring.Do we need to clarify this in the spec?
Isn't this all internal vhost stuff?
I meant the illegal index 0x8000-0xffff.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1437
Quoted 6 lines
drivers/vhost/vhost.c +5
-0+ vq->last_used_idx = s.num; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + vq->last_used_wrap_counter = wrap_counter; +break ; +case VHOST_GET_VRING_USED_BASE :Do we need the new
VHOST_GET_VRING_USED_BASEandVHOST_SET_VRING_USED_BASEops?We are going to merge below series in DPDK:
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
http://patches.dpdk.org/patch/45874/
We may need to reach an agreement first.
If we agree that 64K virtqueue won't be supported, I'm ok with either.
Well the spec says right at the beginning:
Packed virtqueues support up to 2 15 entries each.
Ok. I get it.
Then I can change vhost to match what dpdk did.
Thanks
Quoted 15 lines
Quoted 15 lines
Btw the code assumes
used_wrap_counteris equal toavail_wrap_counterwhich looks wrong?Thanks
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
drivers/vhost/vhost.c +4
-0+ s.index = idx; + s.num = vq->last_used_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_used_wrap_counter <<31 ;if (copy_to_user (argp, &s,sizeof s)) r = -EFAULT ;break ;[...]
Michael S. Tsirkin
maintainerRe: [PATCH net-next V2 6/8] vhost: packed ring support
Quoted 54 lines · Jason Wang
Quoted 51 lines · Michael S. Tsirkin
Quoted 50 lines · Jason Wang
Quoted 41 lines · Michael S. Tsirkin
Quoted 32 lines · Tiwei Bie
On Mon, Jul 16, 2018 at 11:28:09AM +0800, Jason Wang wrote:
[...]Quoted 30 lines
drivers/vhost/vhost.c +22
-0@@ -1367,10 +1397,48 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg vq->last_avail_idx = s.num;/* Forget the cached index value. */ vq->avail_idx = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) { + vq->last_avail_wrap_counter = wrap_counter; + vq->avail_wrap_counter = vq->last_avail_wrap_counter; + }break ;case VHOST_GET_VRING_BASE : s.index = idx; s.num = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_avail_wrap_counter <<31 ; +if (copy_to_user (argp, &s,sizeof (s))) + r = -EFAULT ; +break ; +case VHOST_SET_VRING_USED_BASE : +/* Moving base with an active backend? +* You don't want to do that. +*/ +if (vq->private_data) { + r = -EBUSY ; +break ; + } +if (copy_from_user (&s, argp,sizeof (s))) { + r = -EFAULT ; +break ; + } +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) {Quoted 8 lines
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1432
Quoted 7 lines
drivers/vhost/vhost.c +7
-0+ wrap_counter = s.num >>31 ; + s.num &= ~(1 <<31 ); + } +if (s.num >0xffff ) { + r = -EINVAL ; +break ; + }Do we want to put
wrap_counterat bit 15?Quoted 3 lines
I think I second that - seems to be consistent with e.g. event suppression structure and the proposed extension to driver notifications.
Ok, I assumes packed virtqueue support 64K but looks not. I can change it to bit 15 and
GET_VRING_BASEneed to be changed as well.Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
If put
wrap_counterat bit 31, the check (s.num >0xffff) won't be able to catch the illegal index 0x8000~0xffff for packed ring.Do we need to clarify this in the spec?
Isn't this all internal vhost stuff?
I meant the illegal index 0x8000-0xffff.
It does say packed virtqueues support up to 2 15 entries each.
But yes we can add a requirement that devices do not expose larger rings. Split does not support 2**16 either, right? With 2**16 enties avail index becomes 0 and ring looks empty.
Quoted 41 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1437
Quoted 7 lines
drivers/vhost/vhost.c +5
-0+ vq->last_used_idx = s.num; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + vq->last_used_wrap_counter = wrap_counter; +break ; +case VHOST_GET_VRING_USED_BASE :Do we need the new
VHOST_GET_VRING_USED_BASEandVHOST_SET_VRING_USED_BASEops?We are going to merge below series in DPDK:
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
http://patches.dpdk.org/patch/45874/
We may need to reach an agreement first.
If we agree that 64K virtqueue won't be supported, I'm ok with either.
Well the spec says right at the beginning:
Packed virtqueues support up to 2 15 entries each.
Ok. I get it.
Then I can change vhost to match what dpdk did.
Thanks
Quoted 15 lines
Quoted 15 lines
Btw the code assumes
used_wrap_counteris equal toavail_wrap_counterwhich looks wrong?Thanks
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
drivers/vhost/vhost.c +4
-0+ s.index = idx; + s.num = vq->last_used_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_used_wrap_counter <<31 ;if (copy_to_user (argp, &s,sizeof s)) r = -EFAULT ;break ;[...]
Re: [PATCH net-next V2 6/8] vhost: packed ring support
Quoted 55 lines · Michael S. Tsirkin
Quoted 54 lines · Jason Wang
Quoted 53 lines · Michael S. Tsirkin
Quoted 52 lines · Jason Wang
Quoted 41 lines · Michael S. Tsirkin
Quoted 32 lines · Tiwei Bie
On Mon, Jul 16, 2018 at 11:28:09AM +0800, Jason Wang wrote:
[...]Quoted 30 lines
(quoted diff) +22
-0@@ -1367,10 +1397,48 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg vq->last_avail_idx = s.num; /* Forget the cached index value. */ vq->avail_idx = vq->last_avail_idx; + if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) { + vq->last_avail_wrap_counter = wrap_counter; + vq->avail_wrap_counter = vq->last_avail_wrap_counter; + } break; case VHOST_GET_VRING_BASE: s.index = idx; s.num = vq->last_avail_idx; + if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) + s.num |= vq->last_avail_wrap_counter << 31; + if (copy_to_user(argp, &s, sizeof(s))) + r = -EFAULT; + break; + case VHOST_SET_VRING_USED_BASE: + /* Moving base with an active backend? + * You don't want to do that. + */ + if (vq->private_data) { + r = -EBUSY; + break; + } + if (copy_from_user(&s, argp, sizeof(s))) { + r = -EFAULT; + break; + } + if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) {Quoted 8 lines
Review long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1432
Quoted 7 lines
(quoted diff) +7
-0+ wrap_counter = s.num >> 31; + s.num &= ~(1 << 31); + } + if (s.num > 0xffff) { + r = -EINVAL; + break; + }Do we want to put
wrap_counterat bit 15?Quoted 3 lines
I think I second that - seems to be consistent with e.g. event suppression structure and the proposed extension to driver notifications.
Ok, I assumes packed virtqueue support 64K but looks not. I can change it to bit 15 and
GET_VRING_BASEneed to be changed as well.Quoted 4 lines
Quoted 4 lines
If put
wrap_counterat bit 31, the check (s.num >0xffff) won't be able to catch the illegal index 0x8000~0xffff for packed ring.
Quoted 9 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line
Do we need to clarify this in the spec?
Isn't this all internal vhost stuff?
I meant the illegal index 0x8000-0xffff.
It does say packed virtqueues support up to 2 15 entries each.
But yes we can add a requirement that devices do not expose larger rings. Split does not support 2**16 either, right? With 2**16 enties avail index becomes 0 and ring looks empty.
Yes, so it's better to clarify this in the spec.
Thanks
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerRe: [PATCH net-next V2 6/8] vhost: packed ring support
In reply to Jason WangQuoted 54 lines · Jason Wang
Quoted 51 lines · Michael S. Tsirkin
Quoted 50 lines · Jason Wang
Quoted 41 lines · Michael S. Tsirkin
Quoted 32 lines · Tiwei Bie
On Mon, Jul 16, 2018 at 11:28:09AM +0800, Jason Wang wrote:
[...]Quoted 30 lines
drivers/vhost/vhost.c +22
-0@@ -1367,10 +1397,48 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg vq->last_avail_idx = s.num;/* Forget the cached index value. */ vq->avail_idx = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) { + vq->last_avail_wrap_counter = wrap_counter; + vq->avail_wrap_counter = vq->last_avail_wrap_counter; + }break ;case VHOST_GET_VRING_BASE : s.index = idx; s.num = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_avail_wrap_counter <<31 ; +if (copy_to_user (argp, &s,sizeof (s))) + r = -EFAULT ; +break ; +case VHOST_SET_VRING_USED_BASE : +/* Moving base with an active backend? +* You don't want to do that. +*/ +if (vq->private_data) { + r = -EBUSY ; +break ; + } +if (copy_from_user (&s, argp,sizeof (s))) { + r = -EFAULT ; +break ; + } +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) {Quoted 8 lines
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1432
Quoted 7 lines
drivers/vhost/vhost.c +7
-0+ wrap_counter = s.num >>31 ; + s.num &= ~(1 <<31 ); + } +if (s.num >0xffff ) { + r = -EINVAL ; +break ; + }Do we want to put
wrap_counterat bit 15?Quoted 3 lines
I think I second that - seems to be consistent with e.g. event suppression structure and the proposed extension to driver notifications.
Ok, I assumes packed virtqueue support 64K but looks not. I can change it to bit 15 and
GET_VRING_BASEneed to be changed as well.Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
If put
wrap_counterat bit 31, the check (s.num >0xffff) won't be able to catch the illegal index 0x8000~0xffff for packed ring.Do we need to clarify this in the spec?
Isn't this all internal vhost stuff?
I meant the illegal index 0x8000-0xffff.
It does say packed virtqueues support up to 2 15 entries each.
But yes we can add a requirement that devices do not expose larger rings. Split does not support 2**16 either, right? With 2**16 enties avail index becomes 0 and ring looks empty.
Quoted 18 lines
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1437
Quoted 7 lines
drivers/vhost/vhost.c +5
-0+ vq->last_used_idx = s.num; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + vq->last_used_wrap_counter = wrap_counter; +break ; +case VHOST_GET_VRING_USED_BASE :Do we need the new
VHOST_GET_VRING_USED_BASEandVHOST_SET_VRING_USED_BASEops?Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
We are going to merge below series in DPDK:
http://patches.dpdk.org/patch/45874/
We may need to reach an agreement first.
If we agree that 64K virtqueue won't be supported, I'm ok with either.
Well the spec says right at the beginning:
Quoted 23 lines
Quoted 1 line
Packed virtqueues support up to 2 15 entries each.
Ok. I get it.
Then I can change vhost to match what dpdk did.
Thanks
Quoted 15 lines
Quoted 15 lines
Btw the code assumes
used_wrap_counteris equal toavail_wrap_counterwhich looks wrong?Thanks
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
drivers/vhost/vhost.c +4
-0+ s.index = idx; + s.num = vq->last_used_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_used_wrap_counter <<31 ;if (copy_to_user (argp, &s,sizeof s)) r = -EFAULT ;break ;[...]
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH net-next V2 6/8] vhost: packed ring support
In reply to Michael S. TsirkinQuoted 51 lines · Michael S. Tsirkin
Quoted 50 lines · Jason Wang
Quoted 41 lines · Michael S. Tsirkin
Quoted 32 lines · Tiwei Bie
On Mon, Jul 16, 2018 at 11:28:09AM +0800, Jason Wang wrote:
[...]Quoted 30 lines
drivers/vhost/vhost.c +22
-0@@ -1367,10 +1397,48 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg vq->last_avail_idx = s.num;/* Forget the cached index value. */ vq->avail_idx = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) { + vq->last_avail_wrap_counter = wrap_counter; + vq->avail_wrap_counter = vq->last_avail_wrap_counter; + }break ;case VHOST_GET_VRING_BASE : s.index = idx; s.num = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_avail_wrap_counter <<31 ; +if (copy_to_user (argp, &s,sizeof (s))) + r = -EFAULT ; +break ; +case VHOST_SET_VRING_USED_BASE : +/* Moving base with an active backend? +* You don't want to do that. +*/ +if (vq->private_data) { + r = -EBUSY ; +break ; + } +if (copy_from_user (&s, argp,sizeof (s))) { + r = -EFAULT ; +break ; + } +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) {Quoted 8 lines
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1432
Quoted 7 lines
drivers/vhost/vhost.c +7
-0+ wrap_counter = s.num >>31 ; + s.num &= ~(1 <<31 ); + } +if (s.num >0xffff ) { + r = -EINVAL ; +break ; + }Do we want to put
wrap_counterat bit 15?Quoted 3 lines
I think I second that - seems to be consistent with e.g. event suppression structure and the proposed extension to driver notifications.
Ok, I assumes packed virtqueue support 64K but looks not. I can change it to bit 15 and
GET_VRING_BASEneed to be changed as well.Quoted 1 line
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
If put
wrap_counterat bit 31, the check (s.num >0xffff) won't be able to catch the illegal index 0x8000~0xffff for packed ring.Do we need to clarify this in the spec?
Isn't this all internal vhost stuff?
I meant the illegal index 0x8000-0xffff.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1437
Quoted 6 lines
drivers/vhost/vhost.c +5
-0+ vq->last_used_idx = s.num; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + vq->last_used_wrap_counter = wrap_counter; +break ; +case VHOST_GET_VRING_USED_BASE :Do we need the new
VHOST_GET_VRING_USED_BASEandVHOST_SET_VRING_USED_BASEops?We are going to merge below series in DPDK:
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
http://patches.dpdk.org/patch/45874/
We may need to reach an agreement first.
If we agree that 64K virtqueue won't be supported, I'm ok with either.
Well the spec says right at the beginning:
Packed virtqueues support up to 2 15 entries each.
Ok. I get it.
Then I can change vhost to match what dpdk did.
Thanks
Quoted 7 lines
Quoted 7 lines
Btw the code assumes
used_wrap_counteris equal toavail_wrap_counterwhich looks wrong?Thanks
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
drivers/vhost/vhost.c +4
-0+ s.index = idx; + s.num = vq->last_used_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_used_wrap_counter <<31 ;if (copy_to_user (argp, &s,sizeof s)) r = -EFAULT ;break ;[...]
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerRe: [PATCH net-next V2 6/8] vhost: packed ring support
In reply to Jason WangQuoted 53 lines · Jason Wang
Quoted 41 lines · Michael S. Tsirkin
Quoted 32 lines · Tiwei Bie
On Mon, Jul 16, 2018 at 11:28:09AM +0800, Jason Wang wrote:
[...]Quoted 30 lines
drivers/vhost/vhost.c +22
-0@@ -1367,10 +1397,48 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg vq->last_avail_idx = s.num;/* Forget the cached index value. */ vq->avail_idx = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) { + vq->last_avail_wrap_counter = wrap_counter; + vq->avail_wrap_counter = vq->last_avail_wrap_counter; + }break ;case VHOST_GET_VRING_BASE : s.index = idx; s.num = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_avail_wrap_counter <<31 ; +if (copy_to_user (argp, &s,sizeof (s))) + r = -EFAULT ; +break ; +case VHOST_SET_VRING_USED_BASE : +/* Moving base with an active backend? +* You don't want to do that. +*/ +if (vq->private_data) { + r = -EBUSY ; +break ; + } +if (copy_from_user (&s, argp,sizeof (s))) { + r = -EFAULT ; +break ; + } +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) {Quoted 8 lines
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1432
Quoted 7 lines
drivers/vhost/vhost.c +7
-0+ wrap_counter = s.num >>31 ; + s.num &= ~(1 <<31 ); + } +if (s.num >0xffff ) { + r = -EINVAL ; +break ; + }Do we want to put
wrap_counterat bit 15?Quoted 3 lines
I think I second that - seems to be consistent with e.g. event suppression structure and the proposed extension to driver notifications.
Ok, I assumes packed virtqueue support 64K but looks not. I can change it to bit 15 and
GET_VRING_BASEneed to be changed as well.Quoted 2 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
If put
wrap_counterat bit 31, the check (s.num >0xffff) won't be able to catch the illegal index 0x8000~0xffff for packed ring.Do we need to clarify this in the spec?
Isn't this all internal vhost stuff?
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1437
Quoted 5 lines
drivers/vhost/vhost.c +5
-0+ vq->last_used_idx = s.num; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + vq->last_used_wrap_counter = wrap_counter; +break ; +case VHOST_GET_VRING_USED_BASE :Do we need the new
VHOST_GET_VRING_USED_BASEandVHOST_SET_VRING_USED_BASEops?
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
We are going to merge below series in DPDK:
http://patches.dpdk.org/patch/45874/
We may need to reach an agreement first.
If we agree that 64K virtqueue won't be supported, I'm ok with either.
Well the spec says right at the beginning:
Packed virtqueues support up to 2 15 entries each.
Quoted 14 lines
Btw the code assumes
used_wrap_counteris equal toavail_wrap_counterwhich looks wrong?Thanks
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
drivers/vhost/vhost.c +4
-0+ s.index = idx; + s.num = vq->last_used_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_used_wrap_counter <<31 ;if (copy_to_user (argp, &s,sizeof s)) r = -EFAULT ;break ;[...]
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH net-next V2 6/8] vhost: packed ring support
In reply to Jason WangQuoted 68 lines · Jason Wang
Quoted 42 lines · Michael S. Tsirkin
Quoted 33 lines · Tiwei Bie
On Mon, Jul 16, 2018 at 11:28:09AM +0800, Jason Wang wrote:
[...]Quoted 31 lines
(quoted diff) +0
-0@@ -1367,10 +1397,48 @@ long vhost_vring_ioctl(struct vhost_dev *d,unsigned int ioctl, void
__user*arg
vq->last_avail_idx= s.num;
/* Forget the cached index value. */vq->avail_idx=vq->last_avail_idx;
+ if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) { +vq->last_avail_wrap_counter=wrap_counter; +vq->avail_wrap_counter=vq->last_avail_wrap_counter; + }
break;
caseVHOST_GET_VRING_BASE:
s.index = idx;
s.num =vq->last_avail_idx;
+ if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) + s.num |=vq->last_avail_wrap_counter<< 31; + if (copy_to_user(argp, &s, sizeof(s)))
+ r =-EFAULT;
+ break;
+ caseVHOST_SET_VRING_USED_BASE:
+ /* Moving base with an active backend?
+ * You don't want to do that.
+ */
+ if (vq->private_data) {
+ r =-EBUSY;
+ break;
+ }
+ if (copy_from_user(&s, argp, sizeof(s))) {
+ r =-EFAULT;
+ break;
+ }
+ if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) {Quoted 8 lines
Quoted 7 lines
+
wrap_counter= s.num >> 31;
+ s.num &= ~(1 << 31);
+ }
+ if (s.num >0xffff) {
+ r =-EINVAL;
+ break;
+ }Do we want to put
wrap_counterat bit 15?Quoted 3 lines
I think I second that - seems to be consistent with e.g. event suppression structure and the proposed extension to driver notifications.
Ok, I assumes packed virtqueue support 64K but looks not. I can change it to bit 15 and
GET_VRING_BASEneed to be changed as well.Quoted 6 lines
Quoted 6 lines
If put
wrap_counterat bit 31, the check (s.num >0xffff) won't be able to catch the illegal index 0x8000~0xffff for packed ring.Do we need to clarify this in the spec?
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
+
vq->last_used_idx= s.num;
+ if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) +vq->last_used_wrap_counter=wrap_counter; + break;
+ caseVHOST_GET_VRING_USED_BASE:Do we need the new
VHOST_GET_VRING_USED_BASEandVHOST_SET_VRING_USED_BASEops?
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
We are going to merge below series in DPDK:
http://patches.dpdk.org/patch/45874/
We may need to reach an agreement first.
If we agree that 64K virtqueue won't be supported, I'm ok with either.
I'm fine to put wrap_counter at bit 15.
I will post a new version of the DPDK series soon.
Quoted 1 line
Btw the code assumes
used_wrap_counteris equal toavail_wrap_counterwhich looks wrong?
For split ring, we used to set the last_used_idx to the same value as last_avail_idx as VHOST_USER_GET_VRING_BASE cannot be called while the ring is being processed, so their value is always the same at the time the request is handled.
I kept the same behavior for packed ring, and so the wrap counter have to be the same.
Regards,
Maxime
Quoted 12 lines
Thanks
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
+ s.index = idx;
+ s.num =vq->last_used_idx;
+ if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) + s.num |=vq->last_used_wrap_counter<< 31; if (copy_to_user(argp, &s, sizeof s)) r =-EFAULT;
break;[...]
Re: [PATCH net-next V2 6/8] vhost: packed ring support
Quoted 81 lines · Maxime Coquelin
Quoted 68 lines · Jason Wang
Quoted 42 lines · Michael S. Tsirkin
Quoted 33 lines · Tiwei Bie
On Mon, Jul 16, 2018 at 11:28:09AM +0800, Jason Wang wrote:
[...]Quoted 31 lines
drivers/vhost/vhost.c +4
-0@@ -1367,10 +1397,48 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg vq->last_avail_idx = s.num; /* Forget the cached index value. */ vq->avail_idx = vq->last_avail_idx; + if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) { + vq->last_avail_wrap_counter = wrap_counter; + vq->avail_wrap_counter = vq->last_avail_wrap_counter; + } break;case
VHOST_GET_VRING_BASE:
s.index = idx;
s.num =vq->last_avail_idx;
+ if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) + s.num |=vq->last_avail_wrap_counter<< 31; + if (copy_to_user(argp, &s, sizeof(s)))
+ r =-EFAULT;
+ break;
+ caseVHOST_SET_VRING_USED_BASE:
+ /* Moving base with an active backend?
+ * You don't want to do that.
+ */
+ if (vq->private_data) {
+ r =-EBUSY;
+ break;
+ }
+ if (copy_from_user(&s, argp, sizeof(s))) { + r =-EFAULT;
+ break;
+ }
+ if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) {Quoted 8 lines
Quoted 7 lines
+
wrap_counter= s.num >> 31;
+ s.num &= ~(1 << 31);
+ }
+ if (s.num >0xffff) {
+ r =-EINVAL;
+ break;
+ }Do we want to put
wrap_counterat bit 15?Quoted 3 lines
I think I second that - seems to be consistent with e.g. event suppression structure and the proposed extension to driver notifications.
Ok, I assumes packed virtqueue support 64K but looks not. I can change it to bit 15 and
GET_VRING_BASEneed to be changed as well.Quoted 6 lines
Quoted 6 lines
If put
wrap_counterat bit 31, the check (s.num >0xffff) won't be able to catch the illegal index 0x8000~0xffff for packed ring.Do we need to clarify this in the spec?
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
+
vq->last_used_idx= s.num;
+ if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) +vq->last_used_wrap_counter=wrap_counter; + break;
+ caseVHOST_GET_VRING_USED_BASE:Do we need the new
VHOST_GET_VRING_USED_BASEandVHOST_SET_VRING_USED_BASEops?Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
We are going to merge below series in DPDK:
http://patches.dpdk.org/patch/45874/
We may need to reach an agreement first.
If we agree that 64K virtqueue won't be supported, I'm ok with either.
I'm fine to put
wrap_counterat bit 15.
I will post a new version of the DPDK series soon.
Quoted 6 lines
Quoted 1 line
Btw the code assumes
used_wrap_counteris equal toavail_wrap_counterwhich looks wrong?For split ring, we used to set the
last_used_idxto the same value aslast_avail_idxasVHOST_USER_GET_VRING_BASEcannot be called while the ring is being processed, so their value is always the same at the time the request is handled.
I may miss something, but it looks to me we should sync last_used_idx from used_idx.
Thanks
Quoted 20 lines
I kept the same behavior for packed ring, and so the wrap counter have to be the same.
Regards,
MaximeQuoted 12 lines
Thanks
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
+ s.index = idx;
+ s.num =vq->last_used_idx;
+ if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) + s.num |=vq->last_used_wrap_counter<< 31; if (copy_to_user(argp, &s, sizeof s)) r =-EFAULT;
break;[...]
Re: [PATCH net-next V2 6/8] vhost: packed ring support
Quoted 85 lines · Jason Wang
Quoted 83 lines · Maxime Coquelin
Quoted 68 lines · Jason Wang
Quoted 42 lines · Michael S. Tsirkin
Quoted 33 lines · Tiwei Bie
On Mon, Jul 16, 2018 at 11:28:09AM +0800, Jason Wang wrote:
[...]Quoted 31 lines
drivers/vhost/vhost.c +4
-0@@ -1367,10 +1397,48 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg vq->last_avail_idx = s.num; /* Forget the cached index value. */ vq->avail_idx = vq->last_avail_idx; + if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) { + vq->last_avail_wrap_counter = wrap_counter; + vq->avail_wrap_counter = vq->last_avail_wrap_counter; + } break;case
VHOST_GET_VRING_BASE:
s.index = idx;
s.num =vq->last_avail_idx;
+ if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) + s.num |=vq->last_avail_wrap_counter<< 31; + if (copy_to_user(argp, &s, sizeof(s)))
+ r =-EFAULT;
+ break;
+ caseVHOST_SET_VRING_USED_BASE:
+ /* Moving base with an active backend?
+ * You don't want to do that.
+ */
+ if (vq->private_data) {
+ r =-EBUSY;
+ break;
+ }
+ if (copy_from_user(&s, argp, sizeof(s))) { + r =-EFAULT;
+ break;
+ }
+ if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) {Quoted 8 lines
Quoted 7 lines
+
wrap_counter= s.num >> 31;
+ s.num &= ~(1 << 31);
+ }
+ if (s.num >0xffff) {
+ r =-EINVAL;
+ break;
+ }Do we want to put
wrap_counterat bit 15?Quoted 3 lines
I think I second that - seems to be consistent with e.g. event suppression structure and the proposed extension to driver notifications.
Ok, I assumes packed virtqueue support 64K but looks not. I can change it to bit 15 and
GET_VRING_BASEneed to be changed as well.Quoted 6 lines
Quoted 6 lines
If put
wrap_counterat bit 31, the check (s.num >0xffff) won't be able to catch the illegal index 0x8000~0xffff for packed ring.Do we need to clarify this in the spec?
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
+
vq->last_used_idx= s.num;
+ if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) +vq->last_used_wrap_counter=wrap_counter; + break;
+ caseVHOST_GET_VRING_USED_BASE:Do we need the new
VHOST_GET_VRING_USED_BASEandVHOST_SET_VRING_USED_BASEops?Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
We are going to merge below series in DPDK:
http://patches.dpdk.org/patch/45874/
We may need to reach an agreement first.
If we agree that 64K virtqueue won't be supported, I'm ok with either.
I'm fine to put
wrap_counterat bit 15.
I will post a new version of the DPDK series soon.Quoted 1 line
Btw the code assumes
used_wrap_counteris equal toavail_wrap_counterwhich looks wrong?
Quoted 7 lines
Quoted 4 lines
For split ring, we used to set the
last_used_idxto the same value aslast_avail_idxasVHOST_USER_GET_VRING_BASEcannot be called while the ring is being processed, so their value is always the same at the time the request is handled.I may miss something, but it looks to me we should sync
last_used_idxfromused_idx.
Ok, so as proposed off-list by Jason, we could extend VHOST_USER_[GET|SET]_VRING_BASE to have the following payload when VIRTIO_F_RING_PACKED is negotiated:
Bit[0:14] avail index
Bit[15] avail wrap counter
Bit[16:30] used index
Bit[31] used wrap counter
Is everyone ok with that?
Another thing that I'd like to discuss is how do we reconnect in case of user backend crash. When it happens, the frontend hasn't queried the backend for last_avail_idx/last_used_idx and their wrap counters.
With split ring, when it happens, we set last_avail_idx to device's used index (see virtio_queue_restore_last_avail_idx()).
Problem with packed ring is that wrap counters information is only in the backend.
Can we get device's used index and deduce the wrap counter value from corresponding descriptor flag?
Any thoughts?
Regards,
Maxime
Quoted 23 lines
Thanks
Quoted 20 lines
I kept the same behavior for packed ring, and so the wrap counter have to be the same.
Regards,
MaximeQuoted 12 lines
Thanks
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
+ s.index = idx;
+ s.num =vq->last_used_idx;
+ if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) + s.num |=vq->last_used_wrap_counter<< 31; if (copy_to_user(argp, &s, sizeof s)) r =-EFAULT;
break;[...]
Re: [PATCH net-next V2 6/8] vhost: packed ring support
In reply to Maxime CoquelinQuoted 81 lines · Maxime Coquelin
Quoted 68 lines · Jason Wang
Quoted 42 lines · Michael S. Tsirkin
Quoted 33 lines · Tiwei Bie
On Mon, Jul 16, 2018 at 11:28:09AM +0800, Jason Wang wrote:
[...]Quoted 31 lines
drivers/vhost/vhost.c +4
-0@@ -1367,10 +1397,48 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg vq->last_avail_idx = s.num; /* Forget the cached index value. */ vq->avail_idx = vq->last_avail_idx; + if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) { + vq->last_avail_wrap_counter = wrap_counter; + vq->avail_wrap_counter = vq->last_avail_wrap_counter; + } break;case
VHOST_GET_VRING_BASE:
s.index = idx;
s.num =vq->last_avail_idx;
+ if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) + s.num |=vq->last_avail_wrap_counter<< 31; + if (copy_to_user(argp, &s, sizeof(s)))
+ r =-EFAULT;
+ break;
+ caseVHOST_SET_VRING_USED_BASE:
+ /* Moving base with an active backend?
+ * You don't want to do that.
+ */
+ if (vq->private_data) {
+ r =-EBUSY;
+ break;
+ }
+ if (copy_from_user(&s, argp, sizeof(s))) { + r =-EFAULT;
+ break;
+ }
+ if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) {Quoted 8 lines
Quoted 7 lines
+
wrap_counter= s.num >> 31;
+ s.num &= ~(1 << 31);
+ }
+ if (s.num >0xffff) {
+ r =-EINVAL;
+ break;
+ }Do we want to put
wrap_counterat bit 15?Quoted 3 lines
I think I second that - seems to be consistent with e.g. event suppression structure and the proposed extension to driver notifications.
Ok, I assumes packed virtqueue support 64K but looks not. I can change it to bit 15 and
GET_VRING_BASEneed to be changed as well.Quoted 6 lines
Quoted 6 lines
If put
wrap_counterat bit 31, the check (s.num >0xffff) won't be able to catch the illegal index 0x8000~0xffff for packed ring.Do we need to clarify this in the spec?
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
+
vq->last_used_idx= s.num;
+ if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) +vq->last_used_wrap_counter=wrap_counter; + break;
+ caseVHOST_GET_VRING_USED_BASE:Do we need the new
VHOST_GET_VRING_USED_BASEandVHOST_SET_VRING_USED_BASEops?Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
We are going to merge below series in DPDK:
http://patches.dpdk.org/patch/45874/
We may need to reach an agreement first.
If we agree that 64K virtqueue won't be supported, I'm ok with either.
I'm fine to put
wrap_counterat bit 15.
I will post a new version of the DPDK series soon.
Quoted 6 lines
Quoted 1 line
Btw the code assumes
used_wrap_counteris equal toavail_wrap_counterwhich looks wrong?For split ring, we used to set the
last_used_idxto the same value aslast_avail_idxasVHOST_USER_GET_VRING_BASEcannot be called while the ring is being processed, so their value is always the same at the time the request is handled.
I may miss something, but it looks to me we should sync last_used_idx from used_idx.
Thanks
Quoted 20 lines
I kept the same behavior for packed ring, and so the wrap counter have to be the same.
Regards,
MaximeQuoted 12 lines
Thanks
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
+ s.index = idx;
+ s.num =vq->last_used_idx;
+ if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) + s.num |=vq->last_used_wrap_counter<< 31; if (copy_to_user(argp, &s, sizeof s)) r =-EFAULT;
break;[...]
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH net-next V2 6/8] vhost: packed ring support
In reply to Michael S. TsirkinQuoted 41 lines · Michael S. Tsirkin
Quoted 32 lines · Tiwei Bie
On Mon, Jul 16, 2018 at 11:28:09AM +0800, Jason Wang wrote:
[...]Quoted 30 lines
drivers/vhost/vhost.c +22
-0@@ -1367,10 +1397,48 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg vq->last_avail_idx = s.num;/* Forget the cached index value. */ vq->avail_idx = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) { + vq->last_avail_wrap_counter = wrap_counter; + vq->avail_wrap_counter = vq->last_avail_wrap_counter; + }break ;case VHOST_GET_VRING_BASE : s.index = idx; s.num = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_avail_wrap_counter <<31 ; +if (copy_to_user (argp, &s,sizeof (s))) + r = -EFAULT ; +break ; +case VHOST_SET_VRING_USED_BASE : +/* Moving base with an active backend? +* You don't want to do that. +*/ +if (vq->private_data) { + r = -EBUSY ; +break ; + } +if (copy_from_user (&s, argp,sizeof (s))) { + r = -EFAULT ; +break ; + } +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) {Quoted 8 lines
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1432
Quoted 7 lines
drivers/vhost/vhost.c +7
-0+ wrap_counter = s.num >>31 ; + s.num &= ~(1 <<31 ); + } +if (s.num >0xffff ) { + r = -EINVAL ; +break ; + }Do we want to put
wrap_counterat bit 15?
Quoted 3 lines
I think I second that - seems to be consistent with e.g. event suppression structure and the proposed extension to driver notifications.
Ok, I assumes packed virtqueue support 64K but looks not. I can change it to bit 15 and GET_VRING_BASE need to be changed as well.
Quoted 6 lines
Quoted 6 lines
If put
wrap_counterat bit 31, the check (s.num >0xffff) won't be able to catch the illegal index 0x8000~0xffff for packed ring.
Do we need to clarify this in the spec?
Quoted 8 lines
Quoted 8 lines
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1437
Quoted 5 lines
drivers/vhost/vhost.c +5
-0+ vq->last_used_idx = s.num; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + vq->last_used_wrap_counter = wrap_counter; +break ; +case VHOST_GET_VRING_USED_BASE :Do we need the new
VHOST_GET_VRING_USED_BASEandVHOST_SET_VRING_USED_BASEops?
Quoted 5 lines
Quoted 5 lines
We are going to merge below series in DPDK:
http://patches.dpdk.org/patch/45874/
We may need to reach an agreement first.
If we agree that 64K virtqueue won't be supported, I'm ok with either.
Btw the code assumes used_wrap_counter is equal to avail_wrap_counter which looks wrong?
Thanks
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
drivers/vhost/vhost.c +4
-0+ s.index = idx; + s.num = vq->last_used_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_used_wrap_counter <<31 ;if (copy_to_user (argp, &s,sizeof s)) r = -EFAULT ;break ;[...]
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerRe: [PATCH net-next V2 6/8] vhost: packed ring support
In reply to Tiwei BieQuoted 33 lines · Tiwei Bie
On Mon, Jul 16, 2018 at 11:28:09AM +0800, Jason Wang wrote:
[...]Quoted 31 lines
drivers/vhost/vhost.c +23
-0@@ -1367,10 +1397,48 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg vq->last_avail_idx = s.num;/* Forget the cached index value. */ vq->avail_idx = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) { + vq->last_avail_wrap_counter = wrap_counter; + vq->avail_wrap_counter = vq->last_avail_wrap_counter; + }break ;case VHOST_GET_VRING_BASE : s.index = idx; s.num = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_avail_wrap_counter <<31 ; +if (copy_to_user (argp, &s,sizeof (s))) + r = -EFAULT ; +break ; +case VHOST_SET_VRING_USED_BASE : +/* Moving base with an active backend? +* You don't want to do that. +*/ +if (vq->private_data) { + r = -EBUSY ; +break ; + } +if (copy_from_user (&s, argp,sizeof (s))) { + r = -EFAULT ; +break ; + } +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) { + wrap_counter = s.num >>31 ;
Quoted 8 lines
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1432
Quoted 6 lines
drivers/vhost/vhost.c +6
-0+ s.num &= ~(1 <<31 ); + } +if (s.num >0xffff ) { + r = -EINVAL ; +break ; + }Do we want to put
wrap_counterat bit 15?
I think I second that - seems to be consistent with e.g. event suppression structure and the proposed extension to driver notifications.
Quoted 28 lines
If put
wrap_counterat bit 31, the check (s.num >0xffff) won't be able to catch the illegal index 0x8000~0xffff for packed ring.drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1437
Quoted 5 lines
drivers/vhost/vhost.c +5
-0+ vq->last_used_idx = s.num; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + vq->last_used_wrap_counter = wrap_counter; +break ; +case VHOST_GET_VRING_USED_BASE :Do we need the new
VHOST_GET_VRING_USED_BASEandVHOST_SET_VRING_USED_BASEops?We are going to merge below series in DPDK:
http://patches.dpdk.org/patch/45874/
We may need to reach an agreement first.
Quoted 7 lines
drivers/vhost/vhost.c +4
-0+ s.index = idx; + s.num = vq->last_used_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_used_wrap_counter <<31 ;if (copy_to_user (argp, &s,sizeof s)) r = -EFAULT ;break ;[...]
Re: [PATCH net-next V2 6/8] vhost: packed ring support
In reply to Jason WangOn Mon, Jul 16, 2018 at 11:28:09AM +0800, Jason Wang wrote:
[...]
Quoted 27 lines
drivers/vhost/vhost.c +19
-0@@ -1367,10 +1397,48 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg vq->last_avail_idx = s.num;/* Forget the cached index value. */ vq->avail_idx = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) { + vq->last_avail_wrap_counter = wrap_counter; + vq->avail_wrap_counter = vq->last_avail_wrap_counter; + }break ;case VHOST_GET_VRING_BASE : s.index = idx; s.num = vq->last_avail_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_avail_wrap_counter <<31 ; +if (copy_to_user (argp, &s,sizeof (s))) + r = -EFAULT ; +break ; +case VHOST_SET_VRING_USED_BASE : +/* Moving base with an active backend? +* You don't want to do that. +*/ +if (vq->private_data) { + r = -EBUSY ; +break ; + } +if (copy_from_user (&s, argp,sizeof (s))) { + r = -EFAULT ;
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1432
Quoted 10 lines
drivers/vhost/vhost.c +10
-0+break ; + } +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) { + wrap_counter = s.num >>31 ; + s.num &= ~(1 <<31 ); + } +if (s.num >0xffff ) { + r = -EINVAL ; +break ; + }
Do we want to put wrap_counter at bit 15?
If put wrap_counter at bit 31, the check (s.num > 0xffff) won't be able to catch the illegal index 0x8000~0xffff for packed ring.
drivers/vhost/vhost.c long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg · line 1437
Quoted 5 lines
drivers/vhost/vhost.c +5
-0+ vq->last_used_idx = s.num; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + vq->last_used_wrap_counter = wrap_counter; +break ; +case VHOST_GET_VRING_USED_BASE :
Do we need the new VHOST_GET_VRING_USED_BASE andVHOST_SET_VRING_USED_BASE ops?
We are going to merge below series in DPDK:
http://patches.dpdk.org/patch/45874/
We may need to reach an agreement first.
Quoted 7 lines
drivers/vhost/vhost.c +4
-0+ s.index = idx; + s.num = vq->last_used_idx; +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) + s.num |= vq->last_used_wrap_counter <<31 ;if (copy_to_user (argp, &s,sizeof s)) r = -EFAULT ;break ;
[...]
PATCH v2 6/8 vhost: packed ring support
In reply to Jason WangThis patch introduces basic support for packed ring. The idea behinds packed ring is to use a single descriptor ring instead of three different rings (avail, used and descriptor). This could help to reduce the cache contention and PCI transactions. So it was designed to help for the performance for both software implementation and hardware implementation.
The implementation was straightforward, packed version of vhost core (whose name has a packed suffix) helpers were introduced and previous helpers were renamed with a split suffix. Then the exported helpers can just do a switch to go to the correct internal helpers.
The event suppression (device area and driver area) were not implemented. It will be done on top with another patch.
For more information of packed ring, please refer Virtio spec.
--- drivers/vhost/net.c | 12 +- drivers/vhost/vhost.c | 653 ++++++++++++++++++++++++++++++++++++++++++--- drivers/vhost/vhost.h | 13 +- include/uapi/linux/vhost.h | 7 + 4 files changed, 640 insertions(+), 45 deletions(-)
drivers/vhost/net.c +7 -5
@@ -591,7 +591,7 @@ static void handle_tx(struct vhost_net *net) nvq->upend_idx = ((unsigned )nvq->upend_idx -1 ) %UIO_MAXIOV ; } -vhost_discard_vq_desc (vq,1 ); +vhost_discard_vq_desc (vq, &used,1 );vhost_net_enable_vq (net, vq);break ; }
@@ -755,10 +755,12 @@ static void handle_rx(struct vhost_net *net)while ((sock_len =vhost_net_rx_peek_head_len (net, sock->sk, &busyloop_intr))) { +struct vhost_used_elem *used = vq->heads + nvq->done_idx; + sock_len += sock_hlen; vhost_len = sock_len + vhost_hlen; - err =vhost_get_bufs (vq, vq->heads + nvq->done_idx, - vhost_len, &in, vq_log, &log, + err =vhost_get_bufs (vq, used, vhost_len, + &in, vq_log, &log,likely (mergeable) ?UIO_MAXIOV :1 , &headcount);/* OK, now we need to know about added descriptors. */
@@ -806,7 +808,7 @@ static void handle_rx(struct vhost_net *net)if (unlikely (err != sock_len)) {pr_debug ("Discarded rx packet: " " len %d, expected %zd\n" , err, sock_len); -vhost_discard_vq_desc (vq, headcount); +vhost_discard_vq_desc (vq, used,1 );continue ; }/* Supply virtio_net_hdr if VHOST_NET_F_VIRTIO_NET_HDR */
@@ -830,7 +832,7 @@ static void handle_rx(struct vhost_net *net) copy_to_iter(&num_buffers, sizeof num_buffers, &fixup) != sizeof num_buffers) {vq_err (vq,"Failed num_buffers write" ); -vhost_discard_vq_desc (vq, headcount); +vhost_discard_vq_desc (vq, used,1 ); goto out; } nvq->done_idx += headcount;
drivers/vhost/vhost.c +615 -38
799 lines not on this page · raw message
drivers/vhost/vhost.h +11 -2
@@ -36,6 +36,7 @@ struct vhost_poll {struct vhost_used_elem {struct vring_used_elem elem; +int count; };void vhost_work_init (struct vhost_work *work,vhost_work_fn_t fn);
@@ -91,7 +92,10 @@ struct vhost_virtqueue {/* The actual ring of buffers. */ struct mutex mutex;unsigned int num; -struct vring_desc __user *desc; +union { +struct vring_desc __user *desc; +struct vring_packed_desc __user *desc_packed; + };struct vring_avail __user *avail;struct vring_used __user *used;const struct vhost_umem_node *meta_iotlb[VHOST_NUM_ADDRS ];
@@ -148,6 +152,9 @@ struct vhost_virtqueue {bool user_be;#endif u32 busyloop_timeout; +bool last_used_wrap_counter; +bool avail_wrap_counter; +bool last_avail_wrap_counter; };struct vhost_msg_node {
@@ -203,7 +210,9 @@ void vhost_set_used_len(struct vhost_virtqueue *vq, int len);int vhost_get_used_len (struct vhost_virtqueue *vq,struct vhost_used_elem *used); -void vhost_discard_vq_desc (struct vhost_virtqueue *,int n); +void vhost_discard_vq_desc (struct vhost_virtqueue *vq, +struct vhost_used_elem *elem, +int n);int vhost_vq_init_access (struct vhost_virtqueue *); int vhost_add_used(struct vhost_virtqueue *vq,
include/uapi/linux/vhost.h +7 -0
@@ -160,6 +160,13 @@ struct vhost_memory {#define VHOST_GET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x24, \ struct vhost_vring_state) +/* Base value where queue looks for used descriptors */ +#define VHOST_SET_VRING_USED_BASE _IOW(VHOST_VIRTIO, 0x25, \ + struct vhost_vring_state) +/* Get accessor: reads index, writes value in num */ +#define VHOST_GET_VRING_USED_BASE _IOWR(VHOST_VIRTIO, 0x26, \ + struct vhost_vring_state) +/* VHOST_NET specific defines */ /* Attach virtio net ring to a raw socket, or tap device.
Signature · 1 line
2.7.4
PATCH v2 7/8 vhost: event suppression for packed ring
In reply to Jason WangThis patch introduces support for event suppression. This is done by have a two areas: device area and driver area. One side could then try to disable or enable (delayed) notification from other side by using a boolean hint or event index interface in the areas.
For more information, please refer Virtio spec.
--- drivers/vhost/vhost.c | 191 ++++++++++++++++++++++++++++++++++++++++++++++---- drivers/vhost/vhost.h | 10 ++- 2 files changed, 185 insertions(+), 16 deletions(-)
drivers/vhost/vhost.c +177 -14
@@ -1115,10 +1115,15 @@ static int vq_access_ok_packed(struct vhost_virtqueue *vq, unsigned int num, struct vring_used __user *used) {struct vring_packed_desc *packed = (struct vring_packed_desc *)desc; +struct vring_packed_desc_event *driver_event = + (struct vring_packed_desc_event *)avail; +struct vring_packed_desc_event *device_event = + (struct vring_packed_desc_event *)used; -/* TODO: check device area and driver area */ return access_ok (VERIFY_READ , packed, num *sizeof (*packed)) && -access_ok (VERIFY_WRITE , packed, num *sizeof (*packed)); +access_ok (VERIFY_WRITE , packed, num *sizeof (*packed)) && +access_ok (VERIFY_READ , driver_event,sizeof (*driver_event)) && +access_ok (VERIFY_WRITE , device_event,sizeof (*device_event)); } static int vq_access_ok_split(struct vhost_virtqueue *vq, unsigned int num,
@@ -1193,14 +1198,27 @@ static bool iotlb_access_ok(struct vhost_virtqueue *vq,return true; } -int vq_iotlb_prefetch (struct vhost_virtqueue *vq) +int vq_iotlb_prefetch_packed (struct vhost_virtqueue *vq) +{ +int num = vq->num; + +return iotlb_access_ok (vq,VHOST_ACCESS_RO , (u64 )(uintptr_t )vq->desc, + num *sizeof (*vq->desc),VHOST_ADDR_DESC ) && +iotlb_access_ok (vq,VHOST_ACCESS_WO , (u64 )(uintptr_t )vq->desc, + num *sizeof (*vq->desc),VHOST_ADDR_DESC ) && +iotlb_access_ok (vq,VHOST_ACCESS_RO , + (u64 )(uintptr_t )vq->driver_event, +sizeof (*vq->driver_event),VHOST_ADDR_AVAIL ) && +iotlb_access_ok (vq,VHOST_ACCESS_WO , + (u64 )(uintptr_t )vq->device_event, +sizeof (*vq->device_event),VHOST_ADDR_USED ); +} + +int vq_iotlb_prefetch_split (struct vhost_virtqueue *vq) {size_t s =vhost_has_feature (vq,VIRTIO_RING_F_EVENT_IDX ) ?2 :0 ;unsigned int num = vq->num; -if (!vq->iotlb) -return 1 ; -return iotlb_access_ok (vq,VHOST_ACCESS_RO , (u64 )(uintptr_t )vq->desc, num *sizeof (*vq->desc),VHOST_ADDR_DESC ) && iotlb_access_ok(vq, VHOST_ACCESS_RO, (u64)(uintptr_t)vq->avail,
@@ -1212,6 +1230,17 @@ int vq_iotlb_prefetch(struct vhost_virtqueue *vq) num *sizeof (*vq->used->ring) + s, VHOST_ADDR_USED); } + +int vq_iotlb_prefetch (struct vhost_virtqueue *vq) +{ +if (!vq->iotlb) +return 1 ; + +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) +return vq_iotlb_prefetch_packed (vq); +else +return vq_iotlb_prefetch_split (vq); +}EXPORT_SYMBOL_GPL (vq_iotlb_prefetch);/* Can we log writes? */
@@ -1771,6 +1800,50 @@ static int vhost_update_used_flags(struct vhost_virtqueue *vq)return 0 ; } +static int vhost_update_device_flags (struct vhost_virtqueue *vq, +__virtio16 device_flags) +{ +void __user *flags; + +if (vhost_put_user (vq, device_flags, &vq->device_event->flags, +VHOST_ADDR_USED ) <0 ) +return -EFAULT ; +if (unlikely (vq->log_used)) { +/* Make sure the flag is seen before log. */ +smp_wmb (); +/* Log used flag write. */ + flags = &vq->device_event->flags; +log_write (vq->log_base, vq->log_addr + + (flags - (void __user *)vq->device_event), +sizeof (vq->device_event->flags)); +if (vq->log_ctx) +eventfd_signal (vq->log_ctx,1 ); + } +return 0 ; +} + +static int vhost_update_device_off_wrap (struct vhost_virtqueue *vq, +__virtio16 device_off_wrap) +{ +void __user *off_wrap; + +if (vhost_put_user (vq, device_off_wrap, &vq->device_event->off_wrap, +VHOST_ADDR_USED ) <0 ) +return -EFAULT ; +if (unlikely (vq->log_used)) { +/* Make sure the flag is seen before log. */ +smp_wmb (); +/* Log used flag write. */ + off_wrap = &vq->device_event->off_wrap; +log_write (vq->log_base, vq->log_addr + + (off_wrap - (void __user *)vq->device_event), +sizeof (vq->device_event->off_wrap)); +if (vq->log_ctx) +eventfd_signal (vq->log_ctx,1 ); + } +return 0 ; +} +static int vhost_update_avail_event (struct vhost_virtqueue *vq,u16 avail_event) { if (vhost_put_user(vq, cpu_to_vhost16(vq, vq->avail_idx),
@@ -2754,16 +2827,13 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, }EXPORT_SYMBOL_GPL (vhost_add_used_n); -static bool vhost_notify (struct vhost_dev *dev,struct vhost_virtqueue *vq) +static bool vhost_notify_split (struct vhost_dev *dev, +struct vhost_virtqueue *vq) {__u16 old, new;__virtio16 event;bool v; -/* TODO: check driver area */ -if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) -return true; -/* Flush out used index updates. This is paired * with the barrier that the Guest executes when enabling * interrupts. */
@@ -2796,6 +2866,64 @@ static bool vhost_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)return vring_need_event (vhost16_to_cpu (vq, event), new, old); } +static bool vhost_notify_packed (struct vhost_dev *dev, +struct vhost_virtqueue *vq) +{ +__virtio16 event_off_wrap, event_flags; +__u16 old, new, off_wrap; +bool v; + +/* Flush out used descriptors updates. This is paired +* with the barrier that the Guest executes when enabling +* interrupts. +*/ +smp_mb (); + +if (vhost_get_avail (vq, event_flags, + &vq->driver_event->flags) <0 ) { +vq_err (vq,"Failed to get driver desc_event_flags" ); +return true; + } + +if (!vhost_has_feature (vq,VIRTIO_RING_F_EVENT_IDX )) +return event_flags != +cpu_to_vhost16 (vq,VRING_EVENT_F_DISABLE ); + + old = vq->signalled_used; + v = vq->signalled_used_valid; + new = vq->signalled_used = vq->last_used_idx; + vq->signalled_used_valid = true; + +if (event_flags !=cpu_to_vhost16 (vq,VRING_EVENT_F_DESC )) +return event_flags != +cpu_to_vhost16 (vq,VRING_EVENT_F_DISABLE ); + +/* Read desc event flags before event_off and event_wrap */ +smp_rmb (); + +if (vhost_get_avail (vq, event_off_wrap, + &vq->driver_event->off_wrap) <0 ) { +vq_err (vq,"Failed to get driver desc_event_off/wrap" ); +return true; + } + + off_wrap =vhost16_to_cpu (vq, event_off_wrap); + +if (unlikely (!v)) +return true; + +return vhost_vring_packed_need_event (vq, vq->last_used_wrap_counter, + off_wrap, new, old); +} + +static bool vhost_notify (struct vhost_dev *dev,struct vhost_virtqueue *vq) +{ +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) +return vhost_notify_packed (dev, vq); +else +return vhost_notify_split (dev, vq); +} +/* This actually signals the guest, using eventfd. */ void vhost_signal (struct vhost_dev *dev,struct vhost_virtqueue *vq) {
@@ -2873,10 +3001,34 @@ static bool vhost_enable_notify_packed(struct vhost_dev *dev, struct vhost_virtqueue *vq) {struct vring_packed_desc *d = vq->desc_packed + vq->avail_idx; -__virtio16 flags; +__virtio16 flags =cpu_to_vhost16 (vq,VRING_EVENT_F_ENABLE );int ret; -/* TODO: enable notification through device area */ +if (!(vq->used_flags &VRING_USED_F_NO_NOTIFY )) +return false; + vq->used_flags &= ~VRING_USED_F_NO_NOTIFY ; + +if (vhost_has_feature (vq,VIRTIO_RING_F_EVENT_IDX )) { +__virtio16 off_wrap =cpu_to_vhost16 (vq, vq->avail_idx | + vq->avail_wrap_counter <<15 ); + + ret =vhost_update_device_off_wrap (vq, off_wrap); +if (ret) { +vq_err (vq,"Failed to write to off warp at %p: %d\n" , + &vq->device_event->off_wrap, ret); +return false; + } +/* Make sure off_wrap is wrote before flags */ +smp_wmb (); + flags =cpu_to_vhost16 (vq,VRING_EVENT_F_DESC ); + } + + ret =vhost_update_device_flags (vq, flags); +if (ret) { +vq_err (vq,"Failed to enable notification at %p: %d\n" , + &vq->device_event->flags, ret); +return false; + }/* They could have slipped one in as we were doing that: make * sure it's written, then check again.
@@ -2943,7 +3095,18 @@ EXPORT_SYMBOL_GPL(vhost_enable_notify);static void vhost_disable_notify_packed (struct vhost_dev *dev,struct vhost_virtqueue *vq) { -/* TODO: disable notification through device area */ +__virtio16 flags; +int r; + +if (vq->used_flags &VRING_USED_F_NO_NOTIFY ) +return ; + vq->used_flags |=VRING_USED_F_NO_NOTIFY ; + + flags =cpu_to_vhost16 (vq,VRING_EVENT_F_DISABLE ); + r =vhost_update_device_flags (vq, flags); +if (r) +vq_err (vq,"Failed to enable notification at %p: %d\n" , + &vq->device_event->flags, r); } static void vhost_disable_notify_split(struct vhost_dev *dev,
drivers/vhost/vhost.h +8 -2
@@ -96,8 +96,14 @@ struct vhost_virtqueue {struct vring_desc __user *desc;struct vring_packed_desc __user *desc_packed; }; -struct vring_avail __user *avail; -struct vring_used __user *used; +union { +struct vring_avail __user *avail; +struct vring_packed_desc_event __user *driver_event; + }; +union { +struct vring_used __user *used; +struct vring_packed_desc_event __user *device_event; + };const struct vhost_umem_node *meta_iotlb[VHOST_NUM_ADDRS ];struct file *kick;struct eventfd_ctx *call_ctx;
Signature · 1 line
2.7.4
PATCH v2 7/8 vhost: event suppression for packed ring
In reply to Jason WangThis patch introduces support for event suppression. This is done by have a two areas: device area and driver area. One side could then try to disable or enable (delayed) notification from other side by using a boolean hint or event index interface in the areas.
For more information, please refer Virtio spec.
--- drivers/vhost/vhost.c | 191 ++++++++++++++++++++++++++++++++++++++++++++++---- drivers/vhost/vhost.h | 10 ++- 2 files changed, 185 insertions(+), 16 deletions(-)
drivers/vhost/vhost.c +177 -14
@@ -1115,10 +1115,15 @@ static int vq_access_ok_packed(struct vhost_virtqueue *vq, unsigned int num, struct vring_used __user *used) {struct vring_packed_desc *packed = (struct vring_packed_desc *)desc; +struct vring_packed_desc_event *driver_event = + (struct vring_packed_desc_event *)avail; +struct vring_packed_desc_event *device_event = + (struct vring_packed_desc_event *)used; -/* TODO: check device area and driver area */ return access_ok (VERIFY_READ , packed, num *sizeof (*packed)) && -access_ok (VERIFY_WRITE , packed, num *sizeof (*packed)); +access_ok (VERIFY_WRITE , packed, num *sizeof (*packed)) && +access_ok (VERIFY_READ , driver_event,sizeof (*driver_event)) && +access_ok (VERIFY_WRITE , device_event,sizeof (*device_event)); } static int vq_access_ok_split(struct vhost_virtqueue *vq, unsigned int num,
@@ -1193,14 +1198,27 @@ static bool iotlb_access_ok(struct vhost_virtqueue *vq,return true; } -int vq_iotlb_prefetch (struct vhost_virtqueue *vq) +int vq_iotlb_prefetch_packed (struct vhost_virtqueue *vq) +{ +int num = vq->num; + +return iotlb_access_ok (vq,VHOST_ACCESS_RO , (u64 )(uintptr_t )vq->desc, + num *sizeof (*vq->desc),VHOST_ADDR_DESC ) && +iotlb_access_ok (vq,VHOST_ACCESS_WO , (u64 )(uintptr_t )vq->desc, + num *sizeof (*vq->desc),VHOST_ADDR_DESC ) && +iotlb_access_ok (vq,VHOST_ACCESS_RO , + (u64 )(uintptr_t )vq->driver_event, +sizeof (*vq->driver_event),VHOST_ADDR_AVAIL ) && +iotlb_access_ok (vq,VHOST_ACCESS_WO , + (u64 )(uintptr_t )vq->device_event, +sizeof (*vq->device_event),VHOST_ADDR_USED ); +} + +int vq_iotlb_prefetch_split (struct vhost_virtqueue *vq) {size_t s =vhost_has_feature (vq,VIRTIO_RING_F_EVENT_IDX ) ?2 :0 ;unsigned int num = vq->num; -if (!vq->iotlb) -return 1 ; -return iotlb_access_ok (vq,VHOST_ACCESS_RO , (u64 )(uintptr_t )vq->desc, num *sizeof (*vq->desc),VHOST_ADDR_DESC ) && iotlb_access_ok(vq, VHOST_ACCESS_RO, (u64)(uintptr_t)vq->avail,
@@ -1212,6 +1230,17 @@ int vq_iotlb_prefetch(struct vhost_virtqueue *vq) num *sizeof (*vq->used->ring) + s, VHOST_ADDR_USED); } + +int vq_iotlb_prefetch (struct vhost_virtqueue *vq) +{ +if (!vq->iotlb) +return 1 ; + +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) +return vq_iotlb_prefetch_packed (vq); +else +return vq_iotlb_prefetch_split (vq); +}EXPORT_SYMBOL_GPL (vq_iotlb_prefetch);/* Can we log writes? */
@@ -1771,6 +1800,50 @@ static int vhost_update_used_flags(struct vhost_virtqueue *vq)return 0 ; } +static int vhost_update_device_flags (struct vhost_virtqueue *vq, +__virtio16 device_flags) +{ +void __user *flags; + +if (vhost_put_user (vq, device_flags, &vq->device_event->flags, +VHOST_ADDR_USED ) <0 ) +return -EFAULT ; +if (unlikely (vq->log_used)) { +/* Make sure the flag is seen before log. */ +smp_wmb (); +/* Log used flag write. */ + flags = &vq->device_event->flags; +log_write (vq->log_base, vq->log_addr + + (flags - (void __user *)vq->device_event), +sizeof (vq->device_event->flags)); +if (vq->log_ctx) +eventfd_signal (vq->log_ctx,1 ); + } +return 0 ; +} + +static int vhost_update_device_off_wrap (struct vhost_virtqueue *vq, +__virtio16 device_off_wrap) +{ +void __user *off_wrap; + +if (vhost_put_user (vq, device_off_wrap, &vq->device_event->off_wrap, +VHOST_ADDR_USED ) <0 ) +return -EFAULT ; +if (unlikely (vq->log_used)) { +/* Make sure the flag is seen before log. */ +smp_wmb (); +/* Log used flag write. */ + off_wrap = &vq->device_event->off_wrap; +log_write (vq->log_base, vq->log_addr + + (off_wrap - (void __user *)vq->device_event), +sizeof (vq->device_event->off_wrap)); +if (vq->log_ctx) +eventfd_signal (vq->log_ctx,1 ); + } +return 0 ; +} +static int vhost_update_avail_event (struct vhost_virtqueue *vq,u16 avail_event) { if (vhost_put_user(vq, cpu_to_vhost16(vq, vq->avail_idx),
@@ -2754,16 +2827,13 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, }EXPORT_SYMBOL_GPL (vhost_add_used_n); -static bool vhost_notify (struct vhost_dev *dev,struct vhost_virtqueue *vq) +static bool vhost_notify_split (struct vhost_dev *dev, +struct vhost_virtqueue *vq) {__u16 old, new;__virtio16 event;bool v; -/* TODO: check driver area */ -if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) -return true; -/* Flush out used index updates. This is paired * with the barrier that the Guest executes when enabling * interrupts. */
@@ -2796,6 +2866,64 @@ static bool vhost_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)return vring_need_event (vhost16_to_cpu (vq, event), new, old); } +static bool vhost_notify_packed (struct vhost_dev *dev, +struct vhost_virtqueue *vq) +{ +__virtio16 event_off_wrap, event_flags; +__u16 old, new, off_wrap; +bool v; + +/* Flush out used descriptors updates. This is paired +* with the barrier that the Guest executes when enabling +* interrupts. +*/ +smp_mb (); + +if (vhost_get_avail (vq, event_flags, + &vq->driver_event->flags) <0 ) { +vq_err (vq,"Failed to get driver desc_event_flags" ); +return true; + } + +if (!vhost_has_feature (vq,VIRTIO_RING_F_EVENT_IDX )) +return event_flags != +cpu_to_vhost16 (vq,VRING_EVENT_F_DISABLE ); + + old = vq->signalled_used; + v = vq->signalled_used_valid; + new = vq->signalled_used = vq->last_used_idx; + vq->signalled_used_valid = true; + +if (event_flags !=cpu_to_vhost16 (vq,VRING_EVENT_F_DESC )) +return event_flags != +cpu_to_vhost16 (vq,VRING_EVENT_F_DISABLE ); + +/* Read desc event flags before event_off and event_wrap */ +smp_rmb (); + +if (vhost_get_avail (vq, event_off_wrap, + &vq->driver_event->off_wrap) <0 ) { +vq_err (vq,"Failed to get driver desc_event_off/wrap" ); +return true; + } + + off_wrap =vhost16_to_cpu (vq, event_off_wrap); + +if (unlikely (!v)) +return true; + +return vhost_vring_packed_need_event (vq, vq->last_used_wrap_counter, + off_wrap, new, old); +} + +static bool vhost_notify (struct vhost_dev *dev,struct vhost_virtqueue *vq) +{ +if (vhost_has_feature (vq,VIRTIO_F_RING_PACKED )) +return vhost_notify_packed (dev, vq); +else +return vhost_notify_split (dev, vq); +} +/* This actually signals the guest, using eventfd. */ void vhost_signal (struct vhost_dev *dev,struct vhost_virtqueue *vq) {
@@ -2873,10 +3001,34 @@ static bool vhost_enable_notify_packed(struct vhost_dev *dev, struct vhost_virtqueue *vq) {struct vring_packed_desc *d = vq->desc_packed + vq->avail_idx; -__virtio16 flags; +__virtio16 flags =cpu_to_vhost16 (vq,VRING_EVENT_F_ENABLE );int ret; -/* TODO: enable notification through device area */ +if (!(vq->used_flags &VRING_USED_F_NO_NOTIFY )) +return false; + vq->used_flags &= ~VRING_USED_F_NO_NOTIFY ; + +if (vhost_has_feature (vq,VIRTIO_RING_F_EVENT_IDX )) { +__virtio16 off_wrap =cpu_to_vhost16 (vq, vq->avail_idx | + vq->avail_wrap_counter <<15 ); + + ret =vhost_update_device_off_wrap (vq, off_wrap); +if (ret) { +vq_err (vq,"Failed to write to off warp at %p: %d\n" , + &vq->device_event->off_wrap, ret); +return false; + } +/* Make sure off_wrap is wrote before flags */ +smp_wmb (); + flags =cpu_to_vhost16 (vq,VRING_EVENT_F_DESC ); + } + + ret =vhost_update_device_flags (vq, flags); +if (ret) { +vq_err (vq,"Failed to enable notification at %p: %d\n" , + &vq->device_event->flags, ret); +return false; + }/* They could have slipped one in as we were doing that: make * sure it's written, then check again.
@@ -2943,7 +3095,18 @@ EXPORT_SYMBOL_GPL(vhost_enable_notify);static void vhost_disable_notify_packed (struct vhost_dev *dev,struct vhost_virtqueue *vq) { -/* TODO: disable notification through device area */ +__virtio16 flags; +int r; + +if (vq->used_flags &VRING_USED_F_NO_NOTIFY ) +return ; + vq->used_flags |=VRING_USED_F_NO_NOTIFY ; + + flags =cpu_to_vhost16 (vq,VRING_EVENT_F_DISABLE ); + r =vhost_update_device_flags (vq, flags); +if (r) +vq_err (vq,"Failed to enable notification at %p: %d\n" , + &vq->device_event->flags, r); } static void vhost_disable_notify_split(struct vhost_dev *dev,
drivers/vhost/vhost.h +8 -2
@@ -96,8 +96,14 @@ struct vhost_virtqueue {struct vring_desc __user *desc;struct vring_packed_desc __user *desc_packed; }; -struct vring_avail __user *avail; -struct vring_used __user *used; +union { +struct vring_avail __user *avail; +struct vring_packed_desc_event __user *driver_event; + }; +union { +struct vring_used __user *used; +struct vring_packed_desc_event __user *device_event; + };const struct vhost_umem_node *meta_iotlb[VHOST_NUM_ADDRS ];struct file *kick;struct eventfd_ctx *call_ctx;
Signature · 1 line
2.7.4
PATCH v2 8/8 vhost: enable packed virtqueues
In reply to Jason Wang--- drivers/vhost/vhost.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/vhost/vhost.h +2 -1
@@ -264,7 +264,8 @@ enum { (1ULL <<VIRTIO_RING_F_EVENT_IDX ) | (1ULL <<VHOST_F_LOG_ALL ) | (1ULL <<VIRTIO_F_ANY_LAYOUT ) | - (1ULL << VIRTIO_F_VERSION_1) + (1ULL <<VIRTIO_F_VERSION_1 ) | + (1ULL << VIRTIO_F_RING_PACKED) };static inline bool vhost_has_feature (struct vhost_virtqueue *vq,int bit)
Signature · 1 line
2.7.4
PATCH v2 8/8 vhost: enable packed virtqueues
In reply to Jason Wang--- drivers/vhost/vhost.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/vhost/vhost.h +2 -1
@@ -264,7 +264,8 @@ enum { (1ULL <<VIRTIO_RING_F_EVENT_IDX ) | (1ULL <<VHOST_F_LOG_ALL ) | (1ULL <<VIRTIO_F_ANY_LAYOUT ) | - (1ULL << VIRTIO_F_VERSION_1) + (1ULL <<VIRTIO_F_VERSION_1 ) | + (1ULL << VIRTIO_F_RING_PACKED) };static inline bool vhost_has_feature (struct vhost_virtqueue *vq,int bit)
Signature · 1 line
2.7.4
Michael S. Tsirkin
maintainerQuoted 11 lines · Jason Wang
Hi all:
This series implements packed virtqueues. The code were tested with Tiwei's guest driver series at https://patchwork.ozlabs.org/cover/942297/
Pktgen test for both RX and TX does not show obvious difference with split virtqueues. The main bottleneck is the guest Linux driver, since it can not stress vhost for a 100% CPU utilization. A full TCP benchmark is ongoing. Will test virtio-net pmd as well when it was ready.
Well the question then is why we should bother merging this if this doesn't give a performance gain. Do you see a gain in CPU utilization maybe?
If not - let's wait for that TCP benchmark result?
Quoted 81 lines
Notes:
- This version depends on Tiwei's series at https://patchwork.ozlabs.org/cover/942297/This version were tested with:
- Zerocopy (Out of Order) support
- vIOMMU support
- mergeable buffer on/off
- busy polling on/off
- vsock (nc-vsock)Changes from V1:
- drop uapi patch and use Tiwei's
- split the enablement of packed virtqueue into a separate patchChanges from RFC V5:
- save unnecessary barriers during
vhost_add_used_packed_n()
- more compact math for event idx
- fix failure ofSET_VRING_BASEwhenavail_wrap_counteris true
- fix not copyavail_wrap_counterduringGET_VRING_BASE
- introduce SET_VRING_USED_BASE/GET_VRING_USED_BASE for syncinglast_used_idx
- renameused_wrap_countertolast_used_wrap_counter
- rebase to net-nextChanges from RFC V4:
- fix
signalled_usedindex recording
- track avail index correctly
- various minor fixesChanges from RFC V3:
- Fix math on event idx checking
- Sync last avail wrap counter through GET/SET_VRING_BASE
- removedesc_eventprefix in the driver/device structureChanges from RFC V2:
- do not use & in checking
desc_event_flags
- off should be most significant bit
- remove the workaround of mergeable buffer for dpdk prototype
- id should be in the last descriptor in the chain
- keep_F_WRITEfor write descriptor when adding used
- device flags updating should useADDR_USEDtype
- return error on unexpected unavail descriptor in a chain
- return false invhost_ve_avail_emptyis descriptor is available
- track last seenavail_wrap_counter
- correctly examine available descriptor inget_indirect_packed()
-vhost_idx_diffshould return u16 instead of boolChanges from RFC V1:
- Refactor vhost used elem code to avoid open coding on used elem
- Event suppression support (compile test only).
- Indirect descriptor support (compile test only).
- Zerocopy support.
- vIOMMU support.
- SCSI/VSOCK support (compile test only).
- Fix several bugsJason Wang (8):
vhost: moveget_rx_bufstovhost.c
vhost: hide used ring layout from device
vhost: do not usevring_used_elem
vhost_net: do not explicitly manipulatevhost_used_elem
vhost:vhost_put_user()can accept metadata type
vhost: packed ring support
vhost: event suppression for packed ring
vhost: enable packed virtqueuesdrivers/vhost/net.c | 143 ++----- drivers/vhost/scsi.c | 62 +-- drivers/vhost/vhost.c | 994 ++++++++++++++++++++++++++++++++++++++++----- drivers/vhost/vhost.h | 55 ++- drivers/vhost/vsock.c | 42 +- include/uapi/linux/vhost.h | 7 + 6 files changed, 1035 insertions(+), 268 deletions(-)Signature · 1 line
2.7.4
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Jason Wang
Hi all:
This series implements packed virtqueues. The code were tested with Tiwei's guest driver series at https://patchwork.ozlabs.org/cover/942297/
Quoted 7 lines
Quoted 5 lines
Pktgen test for both RX and TX does not show obvious difference with split virtqueues. The main bottleneck is the guest Linux driver, since it can not stress vhost for a 100% CPU utilization. A full TCP benchmark is ongoing. Will test virtio-net pmd as well when it was ready.
Well the question then is why we should bother merging this if this doesn't give a performance gain.
We meet bottlenecks at other places. I can only test Linux driver which has lots of overheads e.g interrupts. And perf show only a small fraction of time were spent on e.g virtqueue manipulation. I hope virtio-net pmd can give us different result but we don't have one ready for testing now. (Jen's V4 have bugs thus can not work with this series).
Quoted 2 lines
Do you see
a gain in CPU utilization maybe?
Unfortunately not.
Quoted 2 lines
If not - let's wait for that TCP benchmark result?
We can, but you know TCP_STREAM result is sometime misleading.
A brunch of other patches of mine were rebased on this and then blocked on this series. Consider we don't meet regression, maybe we can merge this first and try optimizations or fixups on top?
Thanks
Quoted 82 lines
Quoted 82 lines
Notes:
- This version depends on Tiwei's series at https://patchwork.ozlabs.org/cover/942297/This version were tested with:
- Zerocopy (Out of Order) support
- vIOMMU support
- mergeable buffer on/off
- busy polling on/off
- vsock (nc-vsock)Changes from V1:
- drop uapi patch and use Tiwei's
- split the enablement of packed virtqueue into a separate patchChanges from RFC V5:
- save unnecessary barriers during
vhost_add_used_packed_n()
- more compact math for event idx
- fix failure ofSET_VRING_BASEwhenavail_wrap_counteris true
- fix not copyavail_wrap_counterduringGET_VRING_BASE
- introduce SET_VRING_USED_BASE/GET_VRING_USED_BASE for syncinglast_used_idx
- renameused_wrap_countertolast_used_wrap_counter
- rebase to net-nextChanges from RFC V4:
- fix
signalled_usedindex recording
- track avail index correctly
- various minor fixesChanges from RFC V3:
- Fix math on event idx checking
- Sync last avail wrap counter through GET/SET_VRING_BASE
- removedesc_eventprefix in the driver/device structureChanges from RFC V2:
- do not use & in checking
desc_event_flags
- off should be most significant bit
- remove the workaround of mergeable buffer for dpdk prototype
- id should be in the last descriptor in the chain
- keep_F_WRITEfor write descriptor when adding used
- device flags updating should useADDR_USEDtype
- return error on unexpected unavail descriptor in a chain
- return false invhost_ve_avail_emptyis descriptor is available
- track last seenavail_wrap_counter
- correctly examine available descriptor inget_indirect_packed()
-vhost_idx_diffshould return u16 instead of boolChanges from RFC V1:
- Refactor vhost used elem code to avoid open coding on used elem
- Event suppression support (compile test only).
- Indirect descriptor support (compile test only).
- Zerocopy support.
- vIOMMU support.
- SCSI/VSOCK support (compile test only).
- Fix several bugsJason Wang (8):
vhost: moveget_rx_bufstovhost.c
vhost: hide used ring layout from device
vhost: do not usevring_used_elem
vhost_net: do not explicitly manipulatevhost_used_elem
vhost:vhost_put_user()can accept metadata type
vhost: packed ring support
vhost: event suppression for packed ring
vhost: enable packed virtqueuesdrivers/vhost/net.c | 143 ++----- drivers/vhost/scsi.c | 62 +-- drivers/vhost/vhost.c | 994 ++++++++++++++++++++++++++++++++++++++++----- drivers/vhost/vhost.h | 55 ++- drivers/vhost/vsock.c | 42 +- include/uapi/linux/vhost.h | 7 + 6 files changed, 1035 insertions(+), 268 deletions(-)Signature · 1 line
2.7.4
Michael S. Tsirkin
maintainerQuoted 15 lines · Jason Wang
Quoted 12 lines · Michael S. Tsirkin
Quoted 11 lines · Jason Wang
Hi all:
This series implements packed virtqueues. The code were tested with Tiwei's guest driver series at https://patchwork.ozlabs.org/cover/942297/
Pktgen test for both RX and TX does not show obvious difference with split virtqueues. The main bottleneck is the guest Linux driver, since it can not stress vhost for a 100% CPU utilization. A full TCP benchmark is ongoing. Will test virtio-net pmd as well when it was ready.
Quoted 8 lines
Quoted 2 lines
Well the question then is why we should bother merging this if this doesn't give a performance gain.
We meet bottlenecks at other places. I can only test Linux driver which has lots of overheads e.g interrupts. And perf show only a small fraction of time were spent on e.g virtqueue manipulation. I hope virtio-net pmd can give us different result but we don't have one ready for testing now. (Jen's V4 have bugs thus can not work with this series).
Can't linux busy poll? And how about testing loopback with XDP?
Quoted 8 lines
Quoted 2 lines
Do you see
a gain in CPU utilization maybe?Unfortunately not.
Quoted 2 lines
If not - let's wait for that TCP benchmark result?
Quoted 7 lines
We can, but you know
TCP_STREAMresult is sometime misleading.A brunch of other patches of mine were rebased on this and then blocked on this series. Consider we don't meet regression, maybe we can merge this first and try optimizations or fixups on top?
Thanks
I'm not sure I understand this approach. Packed ring is just an optimization. What value is there in merging it if it does not help speed?
Quoted 82 lines
Quoted 82 lines
Quoted 82 lines
Notes:
- This version depends on Tiwei's series at https://patchwork.ozlabs.org/cover/942297/This version were tested with:
- Zerocopy (Out of Order) support
- vIOMMU support
- mergeable buffer on/off
- busy polling on/off
- vsock (nc-vsock)Changes from V1:
- drop uapi patch and use Tiwei's
- split the enablement of packed virtqueue into a separate patchChanges from RFC V5:
- save unnecessary barriers during
vhost_add_used_packed_n()
- more compact math for event idx
- fix failure ofSET_VRING_BASEwhenavail_wrap_counteris true
- fix not copyavail_wrap_counterduringGET_VRING_BASE
- introduce SET_VRING_USED_BASE/GET_VRING_USED_BASE for syncinglast_used_idx
- renameused_wrap_countertolast_used_wrap_counter
- rebase to net-nextChanges from RFC V4:
- fix
signalled_usedindex recording
- track avail index correctly
- various minor fixesChanges from RFC V3:
- Fix math on event idx checking
- Sync last avail wrap counter through GET/SET_VRING_BASE
- removedesc_eventprefix in the driver/device structureChanges from RFC V2:
- do not use & in checking
desc_event_flags
- off should be most significant bit
- remove the workaround of mergeable buffer for dpdk prototype
- id should be in the last descriptor in the chain
- keep_F_WRITEfor write descriptor when adding used
- device flags updating should useADDR_USEDtype
- return error on unexpected unavail descriptor in a chain
- return false invhost_ve_avail_emptyis descriptor is available
- track last seenavail_wrap_counter
- correctly examine available descriptor inget_indirect_packed()
-vhost_idx_diffshould return u16 instead of boolChanges from RFC V1:
- Refactor vhost used elem code to avoid open coding on used elem
- Event suppression support (compile test only).
- Indirect descriptor support (compile test only).
- Zerocopy support.
- vIOMMU support.
- SCSI/VSOCK support (compile test only).
- Fix several bugsJason Wang (8):
vhost: moveget_rx_bufstovhost.c
vhost: hide used ring layout from device
vhost: do not usevring_used_elem
vhost_net: do not explicitly manipulatevhost_used_elem
vhost:vhost_put_user()can accept metadata type
vhost: packed ring support
vhost: event suppression for packed ring
vhost: enable packed virtqueuesdrivers/vhost/net.c | 143 ++----- drivers/vhost/scsi.c | 62 +-- drivers/vhost/vhost.c | 994 ++++++++++++++++++++++++++++++++++++++++----- drivers/vhost/vhost.h | 55 ++- drivers/vhost/vsock.c | 42 +- include/uapi/linux/vhost.h | 7 + 6 files changed, 1035 insertions(+), 268 deletions(-)Signature · 1 line
2.7.4
Quoted 15 lines · Michael S. Tsirkin
Quoted 14 lines · Jason Wang
Quoted 12 lines · Michael S. Tsirkin
Quoted 11 lines · Jason Wang
Hi all:
This series implements packed virtqueues. The code were tested with Tiwei's guest driver series at https://patchwork.ozlabs.org/cover/942297/
Pktgen test for both RX and TX does not show obvious difference with split virtqueues. The main bottleneck is the guest Linux driver, since it can not stress vhost for a 100% CPU utilization. A full TCP benchmark is ongoing. Will test virtio-net pmd as well when it was ready.
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
Well the question then is why we should bother merging this if this doesn't give a performance gain.
We meet bottlenecks at other places. I can only test Linux driver which has lots of overheads e.g interrupts. And perf show only a small fraction of time were spent on e.g virtqueue manipulation. I hope virtio-net pmd can give us different result but we don't have one ready for testing now. (Jen's V4 have bugs thus can not work with this series).
Can't linux busy poll?
For vhost busy polling, there's no difference since guest can not give vhost enough stress. For guest busy polling, it does not work for the packets generated by pktgen.
Quoted 1 line
And how about testing loopback with XDP?
No difference, I even shortcut both the tun_get_user() on host and netif_receive_skb() in guest.
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Do you see
a gain in CPU utilization maybe?Unfortunately not.
Quoted 1 line
If not - let's wait for that TCP benchmark result?
We can, but you know
TCP_STREAMresult is sometime misleading.
Quoted 7 lines
Quoted 5 lines
A brunch of other patches of mine were rebased on this and then blocked on this series. Consider we don't meet regression, maybe we can merge this first and try optimizations or fixups on top?
Thanks
I'm not sure I understand this approach. Packed ring is just an optimization. What value is there in merging it if it does not help speed?
If you want to support migration from dpdk or vDPA backend. And we still have the chance to see the performance with virito-net pmd in the future. If this does not make sense for you, I will leave this series until we can get results from virtio-net pmd (or find a way that packed virtqueue outperform). And I will start to post other optimizations on vhost.
Thanks
Quoted 80 lines
Quoted 80 lines
Quoted 80 lines
Quoted 80 lines
Notes:
- This version depends on Tiwei's series at https://patchwork.ozlabs.org/cover/942297/This version were tested with:
- Zerocopy (Out of Order) support
- vIOMMU support
- mergeable buffer on/off
- busy polling on/off
- vsock (nc-vsock)Changes from V1:
- drop uapi patch and use Tiwei's
- split the enablement of packed virtqueue into a separate patchChanges from RFC V5:
- save unnecessary barriers during
vhost_add_used_packed_n()
- more compact math for event idx
- fix failure ofSET_VRING_BASEwhenavail_wrap_counteris true
- fix not copyavail_wrap_counterduringGET_VRING_BASE
- introduce SET_VRING_USED_BASE/GET_VRING_USED_BASE for syncinglast_used_idx
- renameused_wrap_countertolast_used_wrap_counter
- rebase to net-nextChanges from RFC V4:
- fix
signalled_usedindex recording
- track avail index correctly
- various minor fixesChanges from RFC V3:
- Fix math on event idx checking
- Sync last avail wrap counter through GET/SET_VRING_BASE
- removedesc_eventprefix in the driver/device structureChanges from RFC V2:
- do not use & in checking
desc_event_flags
- off should be most significant bit
- remove the workaround of mergeable buffer for dpdk prototype
- id should be in the last descriptor in the chain
- keep_F_WRITEfor write descriptor when adding used
- device flags updating should useADDR_USEDtype
- return error on unexpected unavail descriptor in a chain
- return false invhost_ve_avail_emptyis descriptor is available
- track last seenavail_wrap_counter
- correctly examine available descriptor inget_indirect_packed()
-vhost_idx_diffshould return u16 instead of boolChanges from RFC V1:
- Refactor vhost used elem code to avoid open coding on used elem
- Event suppression support (compile test only).
- Indirect descriptor support (compile test only).
- Zerocopy support.
- vIOMMU support.
- SCSI/VSOCK support (compile test only).
- Fix several bugsJason Wang (8):
vhost: moveget_rx_bufstovhost.c
vhost: hide used ring layout from device
vhost: do not usevring_used_elem
vhost_net: do not explicitly manipulatevhost_used_elem
vhost:vhost_put_user()can accept metadata type
vhost: packed ring support
vhost: event suppression for packed ring
vhost: enable packed virtqueuesdrivers/vhost/net.c | 143 ++----- drivers/vhost/scsi.c | 62 +-- drivers/vhost/vhost.c | 994 ++++++++++++++++++++++++++++++++++++++++----- drivers/vhost/vhost.h | 55 ++- drivers/vhost/vsock.c | 42 +- include/uapi/linux/vhost.h | 7 + 6 files changed, 1035 insertions(+), 268 deletions(-)
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Signature · 1 line
2.7.4
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerQuoted 4 lines · Jason Wang
Quoted 2 lines
I'm not sure I understand this approach. Packed ring is just an optimization. What value is there in merging it if it does not help speed?
If you want to support migration from dpdk or vDPA backend.
Migration from dpdk is a mess: if you add new features you fix migration from new one but break migration from old one. So I'm not too worried until dpdk guys implement one of the migration versioning proposals that have been floating around for years.
I think vDPAs are using split ring right now. They will likely switch to packed ring in the future, but it will probably take some time before they do.
Quoted 5 lines
And we still
have the chance to see the performance with virito-net pmd in the future. If this does not make sense for you, I will leave this series until we can get results from virtio-net pmd (or find a way that packed virtqueue outperform).
This makes sense to me. If there's a gain that is only observed with the pmd driver, I think that's still fine, but we do need to see it.
Quoted 3 lines
And I will start to post other optimizations on vhost.
Thanks
Thanks a lot!
Signature · 1 line
MST
Michael S. Tsirkin
maintainerQuoted 4 lines · Jason Wang
Quoted 2 lines
I'm not sure I understand this approach. Packed ring is just an optimization. What value is there in merging it if it does not help speed?
If you want to support migration from dpdk or vDPA backend.
Migration from dpdk is a mess: if you add new features you fix migration from new one but break migration from old one. So I'm not too worried until dpdk guys implement one of the migration versioning proposals that have been floating around for years.
I think vDPAs are using split ring right now. They will likely switch to packed ring in the future, but it will probably take some time before they do.
Quoted 5 lines
And we still
have the chance to see the performance with virito-net pmd in the future. If this does not make sense for you, I will leave this series until we can get results from virtio-net pmd (or find a way that packed virtqueue outperform).
This makes sense to me. If there's a gain that is only observed with the pmd driver, I think that's still fine, but we do need to see it.
Quoted 3 lines
And I will start to post other optimizations on vhost.
Thanks
Thanks a lot!
Signature · 1 line
MST
David Miller
maintainerFrom: "Michael S. Tsirkin" <[email protected]>
Date: Mon, 16 Jul 2018 15:49:04 +0300
Quoted 3 lines
I'm not sure I understand this approach. Packed ring is just an optimization. What value is there in merging it if it does not help speed?
So it seems that both Tiwei's and Jason's packed patch sets are kind of in limbo due to this discussion.
If I understand Jason correctly, he's trying to say that although this work doesn't show improvements by itself, however it paves the way such that optimizaations done in the future will be more visible.
I kind of can see Michael's viewpoint too, in that we should put this stuff in later when it does actually show some difference.
Therefore, I'll mark both patch sets as "deferred" for now.
Let me know if I should do something else.
Thanks!
Michael S. Tsirkin
maintainerQuoted 15 lines · Jason Wang
Quoted 12 lines · Michael S. Tsirkin
Quoted 11 lines · Jason Wang
Hi all:
This series implements packed virtqueues. The code were tested with Tiwei's guest driver series at https://patchwork.ozlabs.org/cover/942297/
Pktgen test for both RX and TX does not show obvious difference with split virtqueues. The main bottleneck is the guest Linux driver, since it can not stress vhost for a 100% CPU utilization. A full TCP benchmark is ongoing. Will test virtio-net pmd as well when it was ready.
Quoted 8 lines
Quoted 2 lines
Well the question then is why we should bother merging this if this doesn't give a performance gain.
We meet bottlenecks at other places. I can only test Linux driver which has lots of overheads e.g interrupts. And perf show only a small fraction of time were spent on e.g virtqueue manipulation. I hope virtio-net pmd can give us different result but we don't have one ready for testing now. (Jen's V4 have bugs thus can not work with this series).
Can't linux busy poll? And how about testing loopback with XDP?
Quoted 8 lines
Quoted 2 lines
Do you see
a gain in CPU utilization maybe?Unfortunately not.
Quoted 2 lines
If not - let's wait for that TCP benchmark result?
Quoted 7 lines
We can, but you know
TCP_STREAMresult is sometime misleading.A brunch of other patches of mine were rebased on this and then blocked on this series. Consider we don't meet regression, maybe we can merge this first and try optimizations or fixups on top?
Thanks
I'm not sure I understand this approach. Packed ring is just an optimization. What value is there in merging it if it does not help speed?
Quoted 80 lines
Quoted 80 lines
Quoted 80 lines
Notes:
- This version depends on Tiwei's series at https://patchwork.ozlabs.org/cover/942297/This version were tested with:
- Zerocopy (Out of Order) support
- vIOMMU support
- mergeable buffer on/off
- busy polling on/off
- vsock (nc-vsock)Changes from V1:
- drop uapi patch and use Tiwei's
- split the enablement of packed virtqueue into a separate patchChanges from RFC V5:
- save unnecessary barriers during
vhost_add_used_packed_n()
- more compact math for event idx
- fix failure ofSET_VRING_BASEwhenavail_wrap_counteris true
- fix not copyavail_wrap_counterduringGET_VRING_BASE
- introduce SET_VRING_USED_BASE/GET_VRING_USED_BASE for syncinglast_used_idx
- renameused_wrap_countertolast_used_wrap_counter
- rebase to net-nextChanges from RFC V4:
- fix
signalled_usedindex recording
- track avail index correctly
- various minor fixesChanges from RFC V3:
- Fix math on event idx checking
- Sync last avail wrap counter through GET/SET_VRING_BASE
- removedesc_eventprefix in the driver/device structureChanges from RFC V2:
- do not use & in checking
desc_event_flags
- off should be most significant bit
- remove the workaround of mergeable buffer for dpdk prototype
- id should be in the last descriptor in the chain
- keep_F_WRITEfor write descriptor when adding used
- device flags updating should useADDR_USEDtype
- return error on unexpected unavail descriptor in a chain
- return false invhost_ve_avail_emptyis descriptor is available
- track last seenavail_wrap_counter
- correctly examine available descriptor inget_indirect_packed()
-vhost_idx_diffshould return u16 instead of boolChanges from RFC V1:
- Refactor vhost used elem code to avoid open coding on used elem
- Event suppression support (compile test only).
- Indirect descriptor support (compile test only).
- Zerocopy support.
- vIOMMU support.
- SCSI/VSOCK support (compile test only).
- Fix several bugsJason Wang (8):
vhost: moveget_rx_bufstovhost.c
vhost: hide used ring layout from device
vhost: do not usevring_used_elem
vhost_net: do not explicitly manipulatevhost_used_elem
vhost:vhost_put_user()can accept metadata type
vhost: packed ring support
vhost: event suppression for packed ring
vhost: enable packed virtqueuesdrivers/vhost/net.c | 143 ++----- drivers/vhost/scsi.c | 62 +-- drivers/vhost/vhost.c | 994 ++++++++++++++++++++++++++++++++++++++++----- drivers/vhost/vhost.h | 55 ++- drivers/vhost/vsock.c | 42 +- include/uapi/linux/vhost.h | 7 + 6 files changed, 1035 insertions(+), 268 deletions(-)
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Signature · 1 line
2.7.4
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Jason Wang
Hi all:
This series implements packed virtqueues. The code were tested with Tiwei's guest driver series at https://patchwork.ozlabs.org/cover/942297/
Quoted 7 lines
Quoted 5 lines
Pktgen test for both RX and TX does not show obvious difference with split virtqueues. The main bottleneck is the guest Linux driver, since it can not stress vhost for a 100% CPU utilization. A full TCP benchmark is ongoing. Will test virtio-net pmd as well when it was ready.
Well the question then is why we should bother merging this if this doesn't give a performance gain.
We meet bottlenecks at other places. I can only test Linux driver which has lots of overheads e.g interrupts. And perf show only a small fraction of time were spent on e.g virtqueue manipulation. I hope virtio-net pmd can give us different result but we don't have one ready for testing now. (Jen's V4 have bugs thus can not work with this series).
Quoted 2 lines
Do you see
a gain in CPU utilization maybe?
Unfortunately not.
Quoted 2 lines
If not - let's wait for that TCP benchmark result?
We can, but you know TCP_STREAM result is sometime misleading.
A brunch of other patches of mine were rebased on this and then blocked on this series. Consider we don't meet regression, maybe we can merge this first and try optimizations or fixups on top?
Thanks
Quoted 80 lines
Quoted 80 lines
Notes:
- This version depends on Tiwei's series at https://patchwork.ozlabs.org/cover/942297/This version were tested with:
- Zerocopy (Out of Order) support
- vIOMMU support
- mergeable buffer on/off
- busy polling on/off
- vsock (nc-vsock)Changes from V1:
- drop uapi patch and use Tiwei's
- split the enablement of packed virtqueue into a separate patchChanges from RFC V5:
- save unnecessary barriers during
vhost_add_used_packed_n()
- more compact math for event idx
- fix failure ofSET_VRING_BASEwhenavail_wrap_counteris true
- fix not copyavail_wrap_counterduringGET_VRING_BASE
- introduce SET_VRING_USED_BASE/GET_VRING_USED_BASE for syncinglast_used_idx
- renameused_wrap_countertolast_used_wrap_counter
- rebase to net-nextChanges from RFC V4:
- fix
signalled_usedindex recording
- track avail index correctly
- various minor fixesChanges from RFC V3:
- Fix math on event idx checking
- Sync last avail wrap counter through GET/SET_VRING_BASE
- removedesc_eventprefix in the driver/device structureChanges from RFC V2:
- do not use & in checking
desc_event_flags
- off should be most significant bit
- remove the workaround of mergeable buffer for dpdk prototype
- id should be in the last descriptor in the chain
- keep_F_WRITEfor write descriptor when adding used
- device flags updating should useADDR_USEDtype
- return error on unexpected unavail descriptor in a chain
- return false invhost_ve_avail_emptyis descriptor is available
- track last seenavail_wrap_counter
- correctly examine available descriptor inget_indirect_packed()
-vhost_idx_diffshould return u16 instead of boolChanges from RFC V1:
- Refactor vhost used elem code to avoid open coding on used elem
- Event suppression support (compile test only).
- Indirect descriptor support (compile test only).
- Zerocopy support.
- vIOMMU support.
- SCSI/VSOCK support (compile test only).
- Fix several bugsJason Wang (8):
vhost: moveget_rx_bufstovhost.c
vhost: hide used ring layout from device
vhost: do not usevring_used_elem
vhost_net: do not explicitly manipulatevhost_used_elem
vhost:vhost_put_user()can accept metadata type
vhost: packed ring support
vhost: event suppression for packed ring
vhost: enable packed virtqueuesdrivers/vhost/net.c | 143 ++----- drivers/vhost/scsi.c | 62 +-- drivers/vhost/vhost.c | 994 ++++++++++++++++++++++++++++++++++++++++----- drivers/vhost/vhost.h | 55 ++- drivers/vhost/vsock.c | 42 +- include/uapi/linux/vhost.h | 7 + 6 files changed, 1035 insertions(+), 268 deletions(-)
Quoted 2 lines
Quoted 2 lines
Signature · 1 line
2.7.4
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization