Packed virtqueue support for vhost
Subsystems (7)
v3 cover Packed virtqueue support for vhost
Hi all:
This series implements packed virtqueues which were described at [1]. In this version we try to address the performance regression saw by V2. The root cause is packed virtqueue need more times of userspace memory accesssing which turns out to be very expensive. Thanks to the help of 7f466032dc9e ("vhost: access vq metadata through kernel virtual address"), such overhead cold be eliminated. So in this version, we can see about 2% improvement for packed virtqueue on PPS.
More optimizations (e.g IN_ORDER) is on the road.
Please review.
[1] https://docs.oasis-open.org/virtio/virtio/v1.1/csprd01/virtio-v1.1-csprd01.html#x1-610007
This version were tested with:
- zercopy/datacopy
- mergeable buffer on/off
- TCP stream & virtio-user
Changes from V2:
- rebase on top of vhost metadata accelreation series
- introduce shadow used ring API
- new SET_VRING_BASE/GET_VRING_BASE that takes care about warp counter and index for both avail and used
- various twaeaks
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 (15):
vhost: simplify meta data pointer accessing
vhost: remove the unnecessary parameter of vhost_vq_avail_empty()
vhost: remove unnecessary parameter of
vhost_enable_notify()/vhost_disable_notify
vhost-net: don't use vhost_add_used_n() for zerocopy
vhost: introduce helpers to manipulate shadow used ring
vhost_net: switch TX to use shadow used ring API
vhost_net: calculate last used length once for mergeable buffer
vhost_net: switch to use shadow used ring API for RX
vhost: do not export vhost_add_used_n() and
vhost_add_used_and_signal_n()
vhost: hide used ring layout from device
vhost: do not use vring_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 | 200 +++--- drivers/vhost/scsi.c | 72 +- drivers/vhost/test.c | 6 +- drivers/vhost/vhost.c | 1508 +++++++++++++++++++++++++++++++++++------ drivers/vhost/vhost.h | 78 ++- drivers/vhost/vsock.c | 57 +- 6 files changed, 1513 insertions(+), 408 deletions(-)
Signature · 1 line
2.18.1
PATCH v3 1/15 vhost: simplify meta data pointer accessing
Instead of open coding meta pointer accessing through caches. This patch introduces vhost_get_meta_ptr()/vhost_put_meta_ptr() pair to reduce the code duplication and simplify its callers implementation. This is helpful for reducing LOC for packed virtqueue as well.
--- drivers/vhost/vhost.c | 207 ++++++++++++++---------------------------- 1 file changed, 70 insertions(+), 137 deletions(-)
drivers/vhost/vhost.c +70 -137
@@ -1194,25 +1194,37 @@ static inline void __user *__vhost_get_user(struct vhost_virtqueue *vq, ret; \ }) -static inline int vhost_put_avail_event (struct vhost_virtqueue *vq) -{#if VHOST_ARCH_CAN_ACCEL_UACCESS +static void *vhost_get_meta_ptr (struct vhost_virtqueue *vq,int type) +{struct vhost_map *map; -struct vring_used *used;if (!vq->iotlb) {rcu_read_lock (); + map =rcu_dereference (vq->maps[type]); +if (likely (map)) +return map->addr; +rcu_read_unlock (); + } +return NULL ; +} - map =rcu_dereference (vq->maps[VHOST_ADDR_USED ]); -if (likely (map)) { - used = map->addr; - *((__virtio16 *)&used->ring[vq->num]) = -cpu_to_vhost16 (vq, vq->avail_idx); -rcu_read_unlock (); -return 0 ; - } +static void vhost_put_meta_ptr (void ) +{ +rcu_read_unlock (); +} +#endif -rcu_read_unlock (); +static inline int vhost_put_avail_event (struct vhost_virtqueue *vq) +{ +#if VHOST_ARCH_CAN_ACCEL_UACCESS +struct vring_used *used =vhost_get_meta_ptr (vq,VHOST_ADDR_USED ); + +if (likely (used)) { + *((__virtio16 *)&used->ring[vq->num]) = +cpu_to_vhost16 (vq, vq->avail_idx); +vhost_put_meta_ptr (); +return 0 ; }#endif
@@ -1225,23 +1237,14 @@ static inline int vhost_put_used(struct vhost_virtqueue *vq, int count) {#if VHOST_ARCH_CAN_ACCEL_UACCESS -struct vhost_map *map; -struct vring_used *used; +struct vring_used *used =vhost_get_meta_ptr (vq,VHOST_ADDR_USED );size_t size; -if (!vq->iotlb) { -rcu_read_lock (); - - map =rcu_dereference (vq->maps[VHOST_ADDR_USED ]); -if (likely (map)) { - used = map->addr; - size = count *sizeof (*head); -memcpy (used->ring + idx, head, size); -rcu_read_unlock (); -return 0 ; - } - -rcu_read_unlock (); +if (likely (used)) { + size = count *sizeof (*head); +memcpy (used->ring + idx, head, size); +vhost_put_meta_ptr (); +return 0 ; }#endif
@@ -1253,21 +1256,12 @@ static inline int vhost_put_used_flags(struct vhost_virtqueue *vq) {#if VHOST_ARCH_CAN_ACCEL_UACCESS -struct vhost_map *map; -struct vring_used *used; - -if (!vq->iotlb) { -rcu_read_lock (); +struct vring_used *used =vhost_get_meta_ptr (vq,VHOST_ADDR_USED ); - map =rcu_dereference (vq->maps[VHOST_ADDR_USED ]); -if (likely (map)) { - used = map->addr; - used->flags =cpu_to_vhost16 (vq, vq->used_flags); -rcu_read_unlock (); -return 0 ; - } - -rcu_read_unlock (); +if (likely (used)) { + used->flags =cpu_to_vhost16 (vq, vq->used_flags); +vhost_put_meta_ptr (); +return 0 ; }#endif
@@ -1279,21 +1273,12 @@ static inline int vhost_put_used_idx(struct vhost_virtqueue *vq) {#if VHOST_ARCH_CAN_ACCEL_UACCESS -struct vhost_map *map; -struct vring_used *used; +struct vring_used *used =vhost_get_meta_ptr (vq,VHOST_ADDR_USED ); -if (!vq->iotlb) { -rcu_read_lock (); - - map =rcu_dereference (vq->maps[VHOST_ADDR_USED ]); -if (likely (map)) { - used = map->addr; - used->idx =cpu_to_vhost16 (vq, vq->last_used_idx); -rcu_read_unlock (); -return 0 ; - } - -rcu_read_unlock (); +if (likely (used)) { + used->idx =cpu_to_vhost16 (vq, vq->last_used_idx); +vhost_put_meta_ptr (); +return 0 ; }#endif
@@ -1343,21 +1328,12 @@ static inline int vhost_get_avail_idx(struct vhost_virtqueue *vq, __virtio16 *idx) {#if VHOST_ARCH_CAN_ACCEL_UACCESS -struct vhost_map *map; -struct vring_avail *avail; - -if (!vq->iotlb) { -rcu_read_lock (); +struct vring_avail *avail =vhost_get_meta_ptr (vq,VHOST_ADDR_AVAIL ); - map =rcu_dereference (vq->maps[VHOST_ADDR_AVAIL ]); -if (likely (map)) { - avail = map->addr; - *idx = avail->idx; -rcu_read_unlock (); -return 0 ; - } - -rcu_read_unlock (); +if (likely (avail)) { + *idx = avail->idx; +vhost_put_meta_ptr (); +return 0 ; }#endif
@@ -1368,21 +1344,12 @@ static inline int vhost_get_avail_head(struct vhost_virtqueue *vq, __virtio16 *head, int idx) {#if VHOST_ARCH_CAN_ACCEL_UACCESS -struct vhost_map *map; -struct vring_avail *avail; - -if (!vq->iotlb) { -rcu_read_lock (); - - map =rcu_dereference (vq->maps[VHOST_ADDR_AVAIL ]); -if (likely (map)) { - avail = map->addr; - *head = avail->ring[idx & (vq->num -1 )]; -rcu_read_unlock (); -return 0 ; - } +struct vring_avail *avail =vhost_get_meta_ptr (vq,VHOST_ADDR_AVAIL ); -rcu_read_unlock (); +if (likely (avail)) { + *head = avail->ring[idx & (vq->num -1 )]; +vhost_put_meta_ptr (); +return 0 ; }#endif
@@ -1394,21 +1361,12 @@ static inline int vhost_get_avail_flags(struct vhost_virtqueue *vq, __virtio16 *flags) {#if VHOST_ARCH_CAN_ACCEL_UACCESS -struct vhost_map *map; -struct vring_avail *avail; - -if (!vq->iotlb) { -rcu_read_lock (); +struct vring_avail *avail =vhost_get_meta_ptr (vq,VHOST_ADDR_AVAIL ); - map =rcu_dereference (vq->maps[VHOST_ADDR_AVAIL ]); -if (likely (map)) { - avail = map->addr; - *flags = avail->flags; -rcu_read_unlock (); -return 0 ; - } - -rcu_read_unlock (); +if (likely (avail)) { + *flags = avail->flags; +vhost_put_meta_ptr (); +return 0 ; }#endif
@@ -1419,19 +1377,12 @@ static inline int vhost_get_used_event(struct vhost_virtqueue *vq, __virtio16 *event) {#if VHOST_ARCH_CAN_ACCEL_UACCESS -struct vhost_map *map; -struct vring_avail *avail; +struct vring_avail *avail =vhost_get_meta_ptr (vq,VHOST_ADDR_AVAIL ); -if (!vq->iotlb) { -rcu_read_lock (); - map =rcu_dereference (vq->maps[VHOST_ADDR_AVAIL ]); -if (likely (map)) { - avail = map->addr; - *event = (__virtio16 )avail->ring[vq->num]; -rcu_read_unlock (); -return 0 ; - } -rcu_read_unlock (); +if (likely (avail)) { + *event = (__virtio16 )avail->ring[vq->num]; +vhost_put_meta_ptr (); +return 0 ; }#endif
@@ -1442,21 +1393,12 @@ static inline int vhost_get_used_idx(struct vhost_virtqueue *vq, __virtio16 *idx) {#if VHOST_ARCH_CAN_ACCEL_UACCESS -struct vhost_map *map; -struct vring_used *used; - -if (!vq->iotlb) { -rcu_read_lock (); - - map =rcu_dereference (vq->maps[VHOST_ADDR_USED ]); -if (likely (map)) { - used = map->addr; - *idx = used->idx; -rcu_read_unlock (); -return 0 ; - } +struct vring_used *used =vhost_get_meta_ptr (vq,VHOST_ADDR_USED ); -rcu_read_unlock (); +if (likely (used)) { + *idx = used->idx; +vhost_put_meta_ptr (); +return 0 ; }#endif
@@ -1467,21 +1409,12 @@ static inline int vhost_get_desc(struct vhost_virtqueue *vq, struct vring_desc *desc, int idx) {#if VHOST_ARCH_CAN_ACCEL_UACCESS -struct vhost_map *map; -struct vring_desc *d; - -if (!vq->iotlb) { -rcu_read_lock (); - - map =rcu_dereference (vq->maps[VHOST_ADDR_DESC ]); -if (likely (map)) { - d = map->addr; - *desc = *(d + idx); -rcu_read_unlock (); -return 0 ; - } +struct vring_desc *d =vhost_get_meta_ptr (vq,VHOST_ADDR_DESC ); -rcu_read_unlock (); +if (likely (d)) { + *desc = *(d + idx); +vhost_put_meta_ptr (); +return 0 ; }#endif
Signature · 1 line
2.18.1
PATCH v3 1/15 vhost: simplify meta data pointer accessing
In reply to Jason WangInstead of open coding meta pointer accessing through caches. This patch introduces vhost_get_meta_ptr()/vhost_put_meta_ptr() pair to reduce the code duplication and simplify its callers implementation. This is helpful for reducing LOC for packed virtqueue as well.
--- drivers/vhost/vhost.c | 207 ++++++++++++++---------------------------- 1 file changed, 70 insertions(+), 137 deletions(-)
drivers/vhost/vhost.c +70 -137
@@ -1194,25 +1194,37 @@ static inline void __user *__vhost_get_user(struct vhost_virtqueue *vq, ret; \ }) -static inline int vhost_put_avail_event (struct vhost_virtqueue *vq) -{#if VHOST_ARCH_CAN_ACCEL_UACCESS +static void *vhost_get_meta_ptr (struct vhost_virtqueue *vq,int type) +{struct vhost_map *map; -struct vring_used *used;if (!vq->iotlb) {rcu_read_lock (); + map =rcu_dereference (vq->maps[type]); +if (likely (map)) +return map->addr; +rcu_read_unlock (); + } +return NULL ; +} - map =rcu_dereference (vq->maps[VHOST_ADDR_USED ]); -if (likely (map)) { - used = map->addr; - *((__virtio16 *)&used->ring[vq->num]) = -cpu_to_vhost16 (vq, vq->avail_idx); -rcu_read_unlock (); -return 0 ; - } +static void vhost_put_meta_ptr (void ) +{ +rcu_read_unlock (); +} +#endif -rcu_read_unlock (); +static inline int vhost_put_avail_event (struct vhost_virtqueue *vq) +{ +#if VHOST_ARCH_CAN_ACCEL_UACCESS +struct vring_used *used =vhost_get_meta_ptr (vq,VHOST_ADDR_USED ); + +if (likely (used)) { + *((__virtio16 *)&used->ring[vq->num]) = +cpu_to_vhost16 (vq, vq->avail_idx); +vhost_put_meta_ptr (); +return 0 ; }#endif
@@ -1225,23 +1237,14 @@ static inline int vhost_put_used(struct vhost_virtqueue *vq, int count) {#if VHOST_ARCH_CAN_ACCEL_UACCESS -struct vhost_map *map; -struct vring_used *used; +struct vring_used *used =vhost_get_meta_ptr (vq,VHOST_ADDR_USED );size_t size; -if (!vq->iotlb) { -rcu_read_lock (); - - map =rcu_dereference (vq->maps[VHOST_ADDR_USED ]); -if (likely (map)) { - used = map->addr; - size = count *sizeof (*head); -memcpy (used->ring + idx, head, size); -rcu_read_unlock (); -return 0 ; - } - -rcu_read_unlock (); +if (likely (used)) { + size = count *sizeof (*head); +memcpy (used->ring + idx, head, size); +vhost_put_meta_ptr (); +return 0 ; }#endif
@@ -1253,21 +1256,12 @@ static inline int vhost_put_used_flags(struct vhost_virtqueue *vq) {#if VHOST_ARCH_CAN_ACCEL_UACCESS -struct vhost_map *map; -struct vring_used *used; - -if (!vq->iotlb) { -rcu_read_lock (); +struct vring_used *used =vhost_get_meta_ptr (vq,VHOST_ADDR_USED ); - map =rcu_dereference (vq->maps[VHOST_ADDR_USED ]); -if (likely (map)) { - used = map->addr; - used->flags =cpu_to_vhost16 (vq, vq->used_flags); -rcu_read_unlock (); -return 0 ; - } - -rcu_read_unlock (); +if (likely (used)) { + used->flags =cpu_to_vhost16 (vq, vq->used_flags); +vhost_put_meta_ptr (); +return 0 ; }#endif
@@ -1279,21 +1273,12 @@ static inline int vhost_put_used_idx(struct vhost_virtqueue *vq) {#if VHOST_ARCH_CAN_ACCEL_UACCESS -struct vhost_map *map; -struct vring_used *used; +struct vring_used *used =vhost_get_meta_ptr (vq,VHOST_ADDR_USED ); -if (!vq->iotlb) { -rcu_read_lock (); - - map =rcu_dereference (vq->maps[VHOST_ADDR_USED ]); -if (likely (map)) { - used = map->addr; - used->idx =cpu_to_vhost16 (vq, vq->last_used_idx); -rcu_read_unlock (); -return 0 ; - } - -rcu_read_unlock (); +if (likely (used)) { + used->idx =cpu_to_vhost16 (vq, vq->last_used_idx); +vhost_put_meta_ptr (); +return 0 ; }#endif
@@ -1343,21 +1328,12 @@ static inline int vhost_get_avail_idx(struct vhost_virtqueue *vq, __virtio16 *idx) {#if VHOST_ARCH_CAN_ACCEL_UACCESS -struct vhost_map *map; -struct vring_avail *avail; - -if (!vq->iotlb) { -rcu_read_lock (); +struct vring_avail *avail =vhost_get_meta_ptr (vq,VHOST_ADDR_AVAIL ); - map =rcu_dereference (vq->maps[VHOST_ADDR_AVAIL ]); -if (likely (map)) { - avail = map->addr; - *idx = avail->idx; -rcu_read_unlock (); -return 0 ; - } - -rcu_read_unlock (); +if (likely (avail)) { + *idx = avail->idx; +vhost_put_meta_ptr (); +return 0 ; }#endif
@@ -1368,21 +1344,12 @@ static inline int vhost_get_avail_head(struct vhost_virtqueue *vq, __virtio16 *head, int idx) {#if VHOST_ARCH_CAN_ACCEL_UACCESS -struct vhost_map *map; -struct vring_avail *avail; - -if (!vq->iotlb) { -rcu_read_lock (); - - map =rcu_dereference (vq->maps[VHOST_ADDR_AVAIL ]); -if (likely (map)) { - avail = map->addr; - *head = avail->ring[idx & (vq->num -1 )]; -rcu_read_unlock (); -return 0 ; - } +struct vring_avail *avail =vhost_get_meta_ptr (vq,VHOST_ADDR_AVAIL ); -rcu_read_unlock (); +if (likely (avail)) { + *head = avail->ring[idx & (vq->num -1 )]; +vhost_put_meta_ptr (); +return 0 ; }#endif
@@ -1394,21 +1361,12 @@ static inline int vhost_get_avail_flags(struct vhost_virtqueue *vq, __virtio16 *flags) {#if VHOST_ARCH_CAN_ACCEL_UACCESS -struct vhost_map *map; -struct vring_avail *avail; - -if (!vq->iotlb) { -rcu_read_lock (); +struct vring_avail *avail =vhost_get_meta_ptr (vq,VHOST_ADDR_AVAIL ); - map =rcu_dereference (vq->maps[VHOST_ADDR_AVAIL ]); -if (likely (map)) { - avail = map->addr; - *flags = avail->flags; -rcu_read_unlock (); -return 0 ; - } - -rcu_read_unlock (); +if (likely (avail)) { + *flags = avail->flags; +vhost_put_meta_ptr (); +return 0 ; }#endif
@@ -1419,19 +1377,12 @@ static inline int vhost_get_used_event(struct vhost_virtqueue *vq, __virtio16 *event) {#if VHOST_ARCH_CAN_ACCEL_UACCESS -struct vhost_map *map; -struct vring_avail *avail; +struct vring_avail *avail =vhost_get_meta_ptr (vq,VHOST_ADDR_AVAIL ); -if (!vq->iotlb) { -rcu_read_lock (); - map =rcu_dereference (vq->maps[VHOST_ADDR_AVAIL ]); -if (likely (map)) { - avail = map->addr; - *event = (__virtio16 )avail->ring[vq->num]; -rcu_read_unlock (); -return 0 ; - } -rcu_read_unlock (); +if (likely (avail)) { + *event = (__virtio16 )avail->ring[vq->num]; +vhost_put_meta_ptr (); +return 0 ; }#endif
@@ -1442,21 +1393,12 @@ static inline int vhost_get_used_idx(struct vhost_virtqueue *vq, __virtio16 *idx) {#if VHOST_ARCH_CAN_ACCEL_UACCESS -struct vhost_map *map; -struct vring_used *used; - -if (!vq->iotlb) { -rcu_read_lock (); - - map =rcu_dereference (vq->maps[VHOST_ADDR_USED ]); -if (likely (map)) { - used = map->addr; - *idx = used->idx; -rcu_read_unlock (); -return 0 ; - } +struct vring_used *used =vhost_get_meta_ptr (vq,VHOST_ADDR_USED ); -rcu_read_unlock (); +if (likely (used)) { + *idx = used->idx; +vhost_put_meta_ptr (); +return 0 ; }#endif
@@ -1467,21 +1409,12 @@ static inline int vhost_get_desc(struct vhost_virtqueue *vq, struct vring_desc *desc, int idx) {#if VHOST_ARCH_CAN_ACCEL_UACCESS -struct vhost_map *map; -struct vring_desc *d; - -if (!vq->iotlb) { -rcu_read_lock (); - - map =rcu_dereference (vq->maps[VHOST_ADDR_DESC ]); -if (likely (map)) { - d = map->addr; - *desc = *(d + idx); -rcu_read_unlock (); -return 0 ; - } +struct vring_desc *d =vhost_get_meta_ptr (vq,VHOST_ADDR_DESC ); -rcu_read_unlock (); +if (likely (d)) { + *desc = *(d + idx); +vhost_put_meta_ptr (); +return 0 ; }#endif
Signature · 1 line
2.18.1
PATCH v3 2/15 vhost: remove the unnecessary parameter of vhost_vq_avail_empty()
In reply to Jason WangIts dev parameter is not even used, so remove it.
--- drivers/vhost/net.c | 8 ++++---- drivers/vhost/vhost.c | 2 +- drivers/vhost/vhost.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/vhost/net.c +4 -4
@@ -498,7 +498,7 @@ static int sock_has_rx_data(struct socket *sock)static void vhost_net_busy_poll_try_queue (struct vhost_net *net,struct vhost_virtqueue *vq) { -if (!vhost_vq_avail_empty (&net->dev, vq)) { +if (!vhost_vq_avail_empty (vq)) {vhost_poll_queue (&vq->poll); }else if (unlikely (vhost_enable_notify (&net->dev, vq))) {vhost_disable_notify (&net->dev, vq);
@@ -540,8 +540,8 @@ static void vhost_net_busy_poll(struct vhost_net *net, }if ((sock_has_rx_data (sock) && - !vhost_vq_avail_empty (&net->dev, rvq)) || - !vhost_vq_avail_empty (&net->dev, tvq)) + !vhost_vq_avail_empty (rvq)) || + !vhost_vq_avail_empty (tvq))break ;cpu_relax ();
@@ -638,7 +638,7 @@ static int get_tx_bufs(struct vhost_net *net,static bool tx_can_batch (struct vhost_virtqueue *vq,size_t total_len) {return total_len <VHOST_NET_WEIGHT && - !vhost_vq_avail_empty (vq->dev, vq); + !vhost_vq_avail_empty (vq); }#define SKB_FRAG_PAGE_ORDER get_order(32768)
drivers/vhost/vhost.c +1 -1
@@ -2946,7 +2946,7 @@ void vhost_add_used_and_signal_n(struct vhost_dev *dev,EXPORT_SYMBOL_GPL (vhost_add_used_and_signal_n);/* return true if we're sure that avaiable ring is empty */ -bool vhost_vq_avail_empty (struct vhost_dev *dev,struct vhost_virtqueue *vq) +bool vhost_vq_avail_empty (struct vhost_virtqueue *vq) {__virtio16 avail_idx;int r;
drivers/vhost/vhost.h +1 -1
@@ -247,7 +247,7 @@ 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 *);void vhost_disable_notify (struct vhost_dev *,struct vhost_virtqueue *); -bool vhost_vq_avail_empty (struct vhost_dev *,struct vhost_virtqueue *); +bool vhost_vq_avail_empty (struct vhost_virtqueue *vq);bool vhost_enable_notify (struct vhost_dev *,struct vhost_virtqueue *); int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
Signature · 1 line
2.18.1
PATCH v3 2/15 vhost: remove the unnecessary parameter of vhost_vq_avail_empty()
In reply to Jason WangIts dev parameter is not even used, so remove it.
--- drivers/vhost/net.c | 8 ++++---- drivers/vhost/vhost.c | 2 +- drivers/vhost/vhost.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/vhost/net.c +4 -4
@@ -498,7 +498,7 @@ static int sock_has_rx_data(struct socket *sock)static void vhost_net_busy_poll_try_queue (struct vhost_net *net,struct vhost_virtqueue *vq) { -if (!vhost_vq_avail_empty (&net->dev, vq)) { +if (!vhost_vq_avail_empty (vq)) {vhost_poll_queue (&vq->poll); }else if (unlikely (vhost_enable_notify (&net->dev, vq))) {vhost_disable_notify (&net->dev, vq);
@@ -540,8 +540,8 @@ static void vhost_net_busy_poll(struct vhost_net *net, }if ((sock_has_rx_data (sock) && - !vhost_vq_avail_empty (&net->dev, rvq)) || - !vhost_vq_avail_empty (&net->dev, tvq)) + !vhost_vq_avail_empty (rvq)) || + !vhost_vq_avail_empty (tvq))break ;cpu_relax ();
@@ -638,7 +638,7 @@ static int get_tx_bufs(struct vhost_net *net,static bool tx_can_batch (struct vhost_virtqueue *vq,size_t total_len) {return total_len <VHOST_NET_WEIGHT && - !vhost_vq_avail_empty (vq->dev, vq); + !vhost_vq_avail_empty (vq); }#define SKB_FRAG_PAGE_ORDER get_order(32768)
drivers/vhost/vhost.c +1 -1
@@ -2946,7 +2946,7 @@ void vhost_add_used_and_signal_n(struct vhost_dev *dev,EXPORT_SYMBOL_GPL (vhost_add_used_and_signal_n);/* return true if we're sure that avaiable ring is empty */ -bool vhost_vq_avail_empty (struct vhost_dev *dev,struct vhost_virtqueue *vq) +bool vhost_vq_avail_empty (struct vhost_virtqueue *vq) {__virtio16 avail_idx;int r;
drivers/vhost/vhost.h +1 -1
@@ -247,7 +247,7 @@ 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 *);void vhost_disable_notify (struct vhost_dev *,struct vhost_virtqueue *); -bool vhost_vq_avail_empty (struct vhost_dev *,struct vhost_virtqueue *); +bool vhost_vq_avail_empty (struct vhost_virtqueue *vq);bool vhost_enable_notify (struct vhost_dev *,struct vhost_virtqueue *); int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
Signature · 1 line
2.18.1
PATCH v3 3/15 vhost: remove unnecessary parameter of vhost_enable_notify()/vhost_disable_notify
In reply to Jason WangIts dev parameter is not even used, so remove it.
--- drivers/vhost/net.c | 25 ++++++++++++------------- drivers/vhost/scsi.c | 12 ++++++------ drivers/vhost/test.c | 6 +++--- drivers/vhost/vhost.c | 4 ++-- drivers/vhost/vhost.h | 4 ++-- drivers/vhost/vsock.c | 14 +++++++------- 6 files changed, 32 insertions(+), 33 deletions(-)
drivers/vhost/net.c +12 -13
@@ -500,8 +500,8 @@ static void vhost_net_busy_poll_try_queue(struct vhost_net *net, {if (!vhost_vq_avail_empty (vq)) {vhost_poll_queue (&vq->poll); - }else if (unlikely (vhost_enable_notify (&net->dev, vq))) { -vhost_disable_notify (&net->dev, vq); + }else if (unlikely (vhost_enable_notify (vq))) { +vhost_disable_notify (vq);vhost_poll_queue (&vq->poll); } }
@@ -524,7 +524,7 @@ static void vhost_net_busy_poll(struct vhost_net *net,if (!mutex_trylock (&vq->mutex))return ; -vhost_disable_notify (&net->dev, vq); +vhost_disable_notify (vq); sock = rvq->private_data; busyloop_timeout = poll_rx ? rvq->busyloop_timeout:
@@ -552,7 +552,7 @@ static void vhost_net_busy_poll(struct vhost_net *net,if (poll_rx ||sock_has_rx_data (sock))vhost_net_busy_poll_try_queue (net, vq);else if (!poll_rx)/* On tx here, sock has no rx data. */ -vhost_enable_notify (&net->dev, rvq); +vhost_enable_notify (rvq);mutex_unlock (&vq->mutex); }
@@ -788,9 +788,8 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock)if (head == vq->num) {if (unlikely (busyloop_intr)) {vhost_poll_queue (&vq->poll); - }else if (unlikely (vhost_enable_notify (&net->dev, - vq))) { -vhost_disable_notify (&net->dev, vq); + }else if (unlikely (vhost_enable_notify (vq))) { +vhost_disable_notify (vq);continue ; }break ;
@@ -880,8 +879,8 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)if (head == vq->num) {if (unlikely (busyloop_intr)) {vhost_poll_queue (&vq->poll); - }else if (unlikely (vhost_enable_notify (&net->dev, vq))) { -vhost_disable_notify (&net->dev, vq); + }else if (unlikely (vhost_enable_notify (vq))) { +vhost_disable_notify (vq);continue ; }break ;
@@ -960,7 +959,7 @@ static void handle_tx(struct vhost_net *net)if (!vq_meta_prefetch (vq)) goto out; -vhost_disable_notify (&net->dev, vq); +vhost_disable_notify (vq);vhost_net_disable_vq (net, vq);if (vhost_sock_zcopy (sock))
@@ -1129,7 +1128,7 @@ static void handle_rx(struct vhost_net *net)if (!vq_meta_prefetch (vq)) goto out; -vhost_disable_notify (&net->dev, vq); +vhost_disable_notify (vq);vhost_net_disable_vq (net, vq); vhost_hlen = nvq->vhost_hlen;
@@ -1156,10 +1155,10 @@ static void handle_rx(struct vhost_net *net)if (!headcount) {if (unlikely (busyloop_intr)) {vhost_poll_queue (&vq->poll); - }else if (unlikely (vhost_enable_notify (&net->dev, vq))) { + }else if (unlikely (vhost_enable_notify (vq))) {/* They have slipped one in as we were * doing that: check again. */ -vhost_disable_notify (&net->dev, vq); +vhost_disable_notify (vq);continue ; }/* Nothing new? Wait for eventfd to tell us
drivers/vhost/scsi.c +6 -6
@@ -458,7 +458,7 @@ vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) } again: -vhost_disable_notify (&vs->dev, vq); +vhost_disable_notify (vq); head =vhost_get_vq_desc (vq, vq->iov,ARRAY_SIZE (vq->iov), &out, &in,NULL ,NULL );
@@ -467,7 +467,7 @@ vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt)return ; }if (head == vq->num) { -if (vhost_enable_notify (&vs->dev, vq)) +if (vhost_enable_notify (vq)) goto again; vs->vs_events_missed = true;return ;
@@ -828,8 +828,8 @@ vhost_scsi_get_desc(struct vhost_scsi *vs, struct vhost_virtqueue *vq,/* Nothing new? Wait for eventfd to tell us they refilled. */ if (vc->head == vq->num) { -if (unlikely (vhost_enable_notify (&vs->dev, vq))) { -vhost_disable_notify (&vs->dev, vq); +if (unlikely (vhost_enable_notify (vq))) { +vhost_disable_notify (vq); ret = -EAGAIN ; } goto done;
@@ -936,7 +936,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)memset (&vc,0 ,sizeof (vc)); vc.rsp_size =sizeof (struct virtio_scsi_cmd_resp ); -vhost_disable_notify (&vs->dev, vq); +vhost_disable_notify (vq); do { ret = vhost_scsi_get_desc(vs, vq, &vc);
@@ -1189,7 +1189,7 @@ vhost_scsi_ctl_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)memset (&vc,0 ,sizeof (vc)); -vhost_disable_notify (&vs->dev, vq); +vhost_disable_notify (vq); do { ret = vhost_scsi_get_desc(vs, vq, &vc);
drivers/vhost/test.c +3 -3
@@ -50,7 +50,7 @@ static void handle_vq(struct vhost_test *n)return ; } -vhost_disable_notify (&n->dev, vq); +vhost_disable_notify (vq);for (;;) { head = vhost_get_vq_desc(vq, vq->iov,
@@ -62,8 +62,8 @@ static void handle_vq(struct vhost_test *n)break ;/* Nothing new? Wait for eventfd to tell us they refilled. */ if (head == vq->num) { -if (unlikely (vhost_enable_notify (&n->dev, vq))) { -vhost_disable_notify (&n->dev, vq); +if (unlikely (vhost_enable_notify (vq))) { +vhost_disable_notify (vq);continue ; }break ;
drivers/vhost/vhost.c +2 -2
@@ -2964,7 +2964,7 @@ bool vhost_vq_avail_empty(struct vhost_virtqueue *vq)EXPORT_SYMBOL_GPL (vhost_vq_avail_empty);/* OK, now we need to know about added descriptors. */ -bool vhost_enable_notify (struct vhost_dev *dev,struct vhost_virtqueue *vq) +bool vhost_enable_notify (struct vhost_virtqueue *vq) {__virtio16 avail_idx;int r;
@@ -3002,7 +3002,7 @@ bool vhost_enable_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)EXPORT_SYMBOL_GPL (vhost_enable_notify);/* We don't need to be notified again. */ -void vhost_disable_notify (struct vhost_dev *dev,struct vhost_virtqueue *vq) +void vhost_disable_notify (struct vhost_virtqueue *vq) {int r;
drivers/vhost/vhost.h +2 -2
@@ -246,9 +246,9 @@ void vhost_add_used_and_signal(struct vhost_dev *, struct vhost_virtqueue *,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 *); -void vhost_disable_notify (struct vhost_dev *,struct vhost_virtqueue *); +void vhost_disable_notify (struct vhost_virtqueue *vq);bool vhost_vq_avail_empty (struct vhost_virtqueue *vq); -bool vhost_enable_notify (struct vhost_dev *,struct vhost_virtqueue *); +bool vhost_enable_notify (struct vhost_virtqueue *vq); int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log, unsigned int log_num, u64 len,
drivers/vhost/vsock.c +7 -7
@@ -96,7 +96,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock, goto out;/* Avoid further vmexits, we're already processing the virtqueue */ -vhost_disable_notify (&vsock->dev, vq); +vhost_disable_notify (vq); do { struct virtio_vsock_pkt *pkt;
@@ -109,7 +109,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,spin_lock_bh (&vsock->send_pkt_list_lock);if (list_empty (&vsock->send_pkt_list)) {spin_unlock_bh (&vsock->send_pkt_list_lock); -vhost_enable_notify (&vsock->dev, vq); +vhost_enable_notify (vq);break ; }
@@ -135,8 +135,8 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,/* We cannot finish yet if more buffers snuck in while * re-enabling notify. */ -if (unlikely (vhost_enable_notify (&vsock->dev, vq))) { -vhost_disable_notify (&vsock->dev, vq); +if (unlikely (vhost_enable_notify (vq))) { +vhost_disable_notify (vq);continue ; }break ;
@@ -369,7 +369,7 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)if (!vq->private_data) goto out; -vhost_disable_notify (&vsock->dev, vq); +vhost_disable_notify (vq); do { u32 len;
@@ -387,8 +387,8 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)break ;if (head == vq->num) { -if (unlikely (vhost_enable_notify (&vsock->dev, vq))) { -vhost_disable_notify (&vsock->dev, vq); +if (unlikely (vhost_enable_notify (vq))) { +vhost_disable_notify (vq);continue ; }break ;
Signature · 1 line
2.18.1
PATCH v3 3/15 vhost: remove unnecessary parameter of vhost_enable_notify()/vhost_disable_notify
In reply to Jason WangIts dev parameter is not even used, so remove it.
--- drivers/vhost/net.c | 25 ++++++++++++------------- drivers/vhost/scsi.c | 12 ++++++------ drivers/vhost/test.c | 6 +++--- drivers/vhost/vhost.c | 4 ++-- drivers/vhost/vhost.h | 4 ++-- drivers/vhost/vsock.c | 14 +++++++------- 6 files changed, 32 insertions(+), 33 deletions(-)
drivers/vhost/net.c +12 -13
@@ -500,8 +500,8 @@ static void vhost_net_busy_poll_try_queue(struct vhost_net *net, {if (!vhost_vq_avail_empty (vq)) {vhost_poll_queue (&vq->poll); - }else if (unlikely (vhost_enable_notify (&net->dev, vq))) { -vhost_disable_notify (&net->dev, vq); + }else if (unlikely (vhost_enable_notify (vq))) { +vhost_disable_notify (vq);vhost_poll_queue (&vq->poll); } }
@@ -524,7 +524,7 @@ static void vhost_net_busy_poll(struct vhost_net *net,if (!mutex_trylock (&vq->mutex))return ; -vhost_disable_notify (&net->dev, vq); +vhost_disable_notify (vq); sock = rvq->private_data; busyloop_timeout = poll_rx ? rvq->busyloop_timeout:
@@ -552,7 +552,7 @@ static void vhost_net_busy_poll(struct vhost_net *net,if (poll_rx ||sock_has_rx_data (sock))vhost_net_busy_poll_try_queue (net, vq);else if (!poll_rx)/* On tx here, sock has no rx data. */ -vhost_enable_notify (&net->dev, rvq); +vhost_enable_notify (rvq);mutex_unlock (&vq->mutex); }
@@ -788,9 +788,8 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock)if (head == vq->num) {if (unlikely (busyloop_intr)) {vhost_poll_queue (&vq->poll); - }else if (unlikely (vhost_enable_notify (&net->dev, - vq))) { -vhost_disable_notify (&net->dev, vq); + }else if (unlikely (vhost_enable_notify (vq))) { +vhost_disable_notify (vq);continue ; }break ;
@@ -880,8 +879,8 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)if (head == vq->num) {if (unlikely (busyloop_intr)) {vhost_poll_queue (&vq->poll); - }else if (unlikely (vhost_enable_notify (&net->dev, vq))) { -vhost_disable_notify (&net->dev, vq); + }else if (unlikely (vhost_enable_notify (vq))) { +vhost_disable_notify (vq);continue ; }break ;
@@ -960,7 +959,7 @@ static void handle_tx(struct vhost_net *net)if (!vq_meta_prefetch (vq)) goto out; -vhost_disable_notify (&net->dev, vq); +vhost_disable_notify (vq);vhost_net_disable_vq (net, vq);if (vhost_sock_zcopy (sock))
@@ -1129,7 +1128,7 @@ static void handle_rx(struct vhost_net *net)if (!vq_meta_prefetch (vq)) goto out; -vhost_disable_notify (&net->dev, vq); +vhost_disable_notify (vq);vhost_net_disable_vq (net, vq); vhost_hlen = nvq->vhost_hlen;
@@ -1156,10 +1155,10 @@ static void handle_rx(struct vhost_net *net)if (!headcount) {if (unlikely (busyloop_intr)) {vhost_poll_queue (&vq->poll); - }else if (unlikely (vhost_enable_notify (&net->dev, vq))) { + }else if (unlikely (vhost_enable_notify (vq))) {/* They have slipped one in as we were * doing that: check again. */ -vhost_disable_notify (&net->dev, vq); +vhost_disable_notify (vq);continue ; }/* Nothing new? Wait for eventfd to tell us
drivers/vhost/scsi.c +6 -6
@@ -458,7 +458,7 @@ vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) } again: -vhost_disable_notify (&vs->dev, vq); +vhost_disable_notify (vq); head =vhost_get_vq_desc (vq, vq->iov,ARRAY_SIZE (vq->iov), &out, &in,NULL ,NULL );
@@ -467,7 +467,7 @@ vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt)return ; }if (head == vq->num) { -if (vhost_enable_notify (&vs->dev, vq)) +if (vhost_enable_notify (vq)) goto again; vs->vs_events_missed = true;return ;
@@ -828,8 +828,8 @@ vhost_scsi_get_desc(struct vhost_scsi *vs, struct vhost_virtqueue *vq,/* Nothing new? Wait for eventfd to tell us they refilled. */ if (vc->head == vq->num) { -if (unlikely (vhost_enable_notify (&vs->dev, vq))) { -vhost_disable_notify (&vs->dev, vq); +if (unlikely (vhost_enable_notify (vq))) { +vhost_disable_notify (vq); ret = -EAGAIN ; } goto done;
@@ -936,7 +936,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)memset (&vc,0 ,sizeof (vc)); vc.rsp_size =sizeof (struct virtio_scsi_cmd_resp ); -vhost_disable_notify (&vs->dev, vq); +vhost_disable_notify (vq); do { ret = vhost_scsi_get_desc(vs, vq, &vc);
@@ -1189,7 +1189,7 @@ vhost_scsi_ctl_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)memset (&vc,0 ,sizeof (vc)); -vhost_disable_notify (&vs->dev, vq); +vhost_disable_notify (vq); do { ret = vhost_scsi_get_desc(vs, vq, &vc);
drivers/vhost/test.c +3 -3
@@ -50,7 +50,7 @@ static void handle_vq(struct vhost_test *n)return ; } -vhost_disable_notify (&n->dev, vq); +vhost_disable_notify (vq);for (;;) { head = vhost_get_vq_desc(vq, vq->iov,
@@ -62,8 +62,8 @@ static void handle_vq(struct vhost_test *n)break ;/* Nothing new? Wait for eventfd to tell us they refilled. */ if (head == vq->num) { -if (unlikely (vhost_enable_notify (&n->dev, vq))) { -vhost_disable_notify (&n->dev, vq); +if (unlikely (vhost_enable_notify (vq))) { +vhost_disable_notify (vq);continue ; }break ;
drivers/vhost/vhost.c +2 -2
@@ -2964,7 +2964,7 @@ bool vhost_vq_avail_empty(struct vhost_virtqueue *vq)EXPORT_SYMBOL_GPL (vhost_vq_avail_empty);/* OK, now we need to know about added descriptors. */ -bool vhost_enable_notify (struct vhost_dev *dev,struct vhost_virtqueue *vq) +bool vhost_enable_notify (struct vhost_virtqueue *vq) {__virtio16 avail_idx;int r;
@@ -3002,7 +3002,7 @@ bool vhost_enable_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)EXPORT_SYMBOL_GPL (vhost_enable_notify);/* We don't need to be notified again. */ -void vhost_disable_notify (struct vhost_dev *dev,struct vhost_virtqueue *vq) +void vhost_disable_notify (struct vhost_virtqueue *vq) {int r;
drivers/vhost/vhost.h +2 -2
@@ -246,9 +246,9 @@ void vhost_add_used_and_signal(struct vhost_dev *, struct vhost_virtqueue *,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 *); -void vhost_disable_notify (struct vhost_dev *,struct vhost_virtqueue *); +void vhost_disable_notify (struct vhost_virtqueue *vq);bool vhost_vq_avail_empty (struct vhost_virtqueue *vq); -bool vhost_enable_notify (struct vhost_dev *,struct vhost_virtqueue *); +bool vhost_enable_notify (struct vhost_virtqueue *vq); int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log, unsigned int log_num, u64 len,
drivers/vhost/vsock.c +7 -7
@@ -96,7 +96,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock, goto out;/* Avoid further vmexits, we're already processing the virtqueue */ -vhost_disable_notify (&vsock->dev, vq); +vhost_disable_notify (vq); do { struct virtio_vsock_pkt *pkt;
@@ -109,7 +109,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,spin_lock_bh (&vsock->send_pkt_list_lock);if (list_empty (&vsock->send_pkt_list)) {spin_unlock_bh (&vsock->send_pkt_list_lock); -vhost_enable_notify (&vsock->dev, vq); +vhost_enable_notify (vq);break ; }
@@ -135,8 +135,8 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,/* We cannot finish yet if more buffers snuck in while * re-enabling notify. */ -if (unlikely (vhost_enable_notify (&vsock->dev, vq))) { -vhost_disable_notify (&vsock->dev, vq); +if (unlikely (vhost_enable_notify (vq))) { +vhost_disable_notify (vq);continue ; }break ;
@@ -369,7 +369,7 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)if (!vq->private_data) goto out; -vhost_disable_notify (&vsock->dev, vq); +vhost_disable_notify (vq); do { u32 len;
@@ -387,8 +387,8 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)break ;if (head == vq->num) { -if (unlikely (vhost_enable_notify (&vsock->dev, vq))) { -vhost_disable_notify (&vsock->dev, vq); +if (unlikely (vhost_enable_notify (vq))) { +vhost_disable_notify (vq);continue ; }break ;
Signature · 1 line
2.18.1
PATCH v3 4/15 vhost-net: don't use vhost_add_used_n() for zerocopy
In reply to Jason WangWe tried to use vhost_add_used_n() for the packets that is not zero-copied. This can help to mitigate HOL issue but not a total solution. What's more, it may lead out of order completion and cause extra complexity for packed virtqueue implementation that needs to maintain wrap counters.
So this patch switch to constantly use vq->heads[] to maintain heads. This will ease the introduction of zerocopy shadow used ring API and reduce the complexity for packed virtqueues.
After this, vhost_net became a in order device.
--- drivers/vhost/net.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)
drivers/vhost/net.c +9 -12
@@ -894,9 +894,6 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)if (zcopy_used) {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].len =VHOST_DMA_IN_PROGRESS ; ubuf->callback = vhost_zerocopy_callback; ubuf->ctx = nvq->ubufs; ubuf->desc = nvq->upend_idx;
@@ -907,11 +904,14 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock) msg.msg_controllen =sizeof (ctl); ubufs = nvq->ubufs;atomic_inc (&ubufs->refcount); - nvq->upend_idx = (nvq->upend_idx +1 ) %UIO_MAXIOV ; }else { msg.msg_control =NULL ; ubufs =NULL ; } + vq->heads[nvq->upend_idx].id =cpu_to_vhost32 (vq, head); + vq->heads[nvq->upend_idx].len = zcopy_used ? +VHOST_DMA_IN_PROGRESS :VHOST_DMA_DONE_LEN ; + nvq->upend_idx = (nvq->upend_idx +1 ) %UIO_MAXIOV ; total_len += len;if (tx_can_batch (vq, total_len) &&likely (!vhost_exceeds_maxpend (net))) {
@@ -923,11 +923,10 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)/* TODO: Check specific error and bomb out unless ENOBUFS? */ err = sock->ops->sendmsg (sock, &msg, len);if (unlikely (err <0 )) { -if (zcopy_used) { +if (zcopy_used)vhost_net_ubuf_put (ubufs); - nvq->upend_idx = ((unsigned )nvq->upend_idx -1 ) - %UIO_MAXIOV ; - } + nvq->upend_idx = ((unsigned int )nvq->upend_idx -1 ) + %UIO_MAXIOV ;vhost_discard_vq_desc (vq,1 );vhost_net_enable_vq (net, vq);break ;
@@ -935,10 +934,8 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)if (err != len)pr_debug ("Truncated TX packet: " " len %d != %zd\n" , err, len); -if (!zcopy_used) -vhost_add_used_and_signal (&net->dev, vq, head,0 ); -else -vhost_zerocopy_signal_used (net, vq); + +vhost_zerocopy_signal_used (net, vq);vhost_net_tx_packet (net); }while (likely (!vhost_exceeds_weight (vq, ++sent_pkts, total_len))); }
Signature · 1 line
2.18.1
PATCH v3 4/15 vhost-net: don't use vhost_add_used_n() for zerocopy
In reply to Jason WangWe tried to use vhost_add_used_n() for the packets that is not zero-copied. This can help to mitigate HOL issue but not a total solution. What's more, it may lead out of order completion and cause extra complexity for packed virtqueue implementation that needs to maintain wrap counters.
So this patch switch to constantly use vq->heads[] to maintain heads. This will ease the introduction of zerocopy shadow used ring API and reduce the complexity for packed virtqueues.
After this, vhost_net became a in order device.
--- drivers/vhost/net.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)
drivers/vhost/net.c +9 -12
@@ -894,9 +894,6 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)if (zcopy_used) {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].len =VHOST_DMA_IN_PROGRESS ; ubuf->callback = vhost_zerocopy_callback; ubuf->ctx = nvq->ubufs; ubuf->desc = nvq->upend_idx;
@@ -907,11 +904,14 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock) msg.msg_controllen =sizeof (ctl); ubufs = nvq->ubufs;atomic_inc (&ubufs->refcount); - nvq->upend_idx = (nvq->upend_idx +1 ) %UIO_MAXIOV ; }else { msg.msg_control =NULL ; ubufs =NULL ; } + vq->heads[nvq->upend_idx].id =cpu_to_vhost32 (vq, head); + vq->heads[nvq->upend_idx].len = zcopy_used ? +VHOST_DMA_IN_PROGRESS :VHOST_DMA_DONE_LEN ; + nvq->upend_idx = (nvq->upend_idx +1 ) %UIO_MAXIOV ; total_len += len;if (tx_can_batch (vq, total_len) &&likely (!vhost_exceeds_maxpend (net))) {
@@ -923,11 +923,10 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)/* TODO: Check specific error and bomb out unless ENOBUFS? */ err = sock->ops->sendmsg (sock, &msg, len);if (unlikely (err <0 )) { -if (zcopy_used) { +if (zcopy_used)vhost_net_ubuf_put (ubufs); - nvq->upend_idx = ((unsigned )nvq->upend_idx -1 ) - %UIO_MAXIOV ; - } + nvq->upend_idx = ((unsigned int )nvq->upend_idx -1 ) + %UIO_MAXIOV ;vhost_discard_vq_desc (vq,1 );vhost_net_enable_vq (net, vq);break ;
@@ -935,10 +934,8 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)if (err != len)pr_debug ("Truncated TX packet: " " len %d != %zd\n" , err, len); -if (!zcopy_used) -vhost_add_used_and_signal (&net->dev, vq, head,0 ); -else -vhost_zerocopy_signal_used (net, vq); + +vhost_zerocopy_signal_used (net, vq);vhost_net_tx_packet (net); }while (likely (!vhost_exceeds_weight (vq, ++sent_pkts, total_len))); }
Signature · 1 line
2.18.1
PATCH v3 5/15 vhost: introduce helpers to manipulate shadow used ring
In reply to Jason WangWe open coding vq->heads[] in net.c for:
1) implementing batching which in fact a shadow used ring implementation.
2) maintain pending heads in order which is in fact another kind of shadow used ring
But this expose used ring layout for device which makes it hard to introduce new kind of ring like packed virtqueue. So this patch introduces two types of shadow used ring API:
1) shadow used ring API for batch updating of used heads
2) zerocopy shadow used API for maintaining pending heads and batch updating used heads
This can help to hide the used ring layout from device. Device should not mix using those two kinds of APIs.
--- drivers/vhost/vhost.c | 95 +++++++++++++++++++++++++++++++++++++------ drivers/vhost/vhost.h | 18 ++++++++ 2 files changed, 100 insertions(+), 13 deletions(-)
drivers/vhost/vhost.c +82 -13
@@ -486,6 +486,7 @@ static void vhost_vq_reset(struct vhost_dev *dev,#if VHOST_ARCH_CAN_ACCEL_UACCESS vhost_reset_vq_maps (vq);#endif + vq->nheads =0 ; }static int vhost_worker (void *data)
@@ -2790,25 +2791,28 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq, }EXPORT_SYMBOL_GPL (vhost_get_vq_desc); -/* Reverse the effect of vhost_get_vq_desc. Useful for error handling. */ -void vhost_discard_vq_desc (struct vhost_virtqueue *vq,int n) +static void vhost_withdraw_shadow_used (struct vhost_virtqueue *vq,int count) { - vq->last_avail_idx -= n; +BUG_ON (count > vq->nheads); + vq->nheads -= count; } -EXPORT_SYMBOL_GPL (vhost_discard_vq_desc); -/* After we've used one of their buffers, we tell them about it. We'll then -* want to notify the guest, using eventfd. */ -int vhost_add_used (struct vhost_virtqueue *vq,unsigned int head,int len) +/* Reverse the effect of vhost_get_vq_desc and +* vhost_add_shadow_used. Useful for error handleing +*/ +void vhost_discard_shadow_used (struct vhost_virtqueue *vq,int n) { -struct vring_used_elem heads = { -cpu_to_vhost32 (vq, head), -cpu_to_vhost32 (vq, len) - }; +vhost_withdraw_shadow_used (vq, n); +vhost_discard_vq_desc (vq, n); +} +EXPORT_SYMBOL_GPL (vhost_discard_shadow_used); -return vhost_add_used_n (vq, &heads,1 ); +/* Reverse the effect of vhost_get_vq_desc. Useful for error handling. */ +void vhost_discard_vq_desc (struct vhost_virtqueue *vq,int n) +{ + vq->last_avail_idx -= n; } -EXPORT_SYMBOL_GPL (vhost_add_used); +EXPORT_SYMBOL_GPL (vhost_discard_vq_desc); static int __vhost_add_used_n(struct vhost_virtqueue *vq, struct vring_used_elem *heads,
@@ -2842,6 +2846,41 @@ static int __vhost_add_used_n(struct vhost_virtqueue *vq,return 0 ; } +void vhost_set_zc_used_len (struct vhost_virtqueue *vq, +int idx,int len) +{ + vq->heads[idx].len = len; +} +EXPORT_SYMBOL_GPL (vhost_set_zc_used_len); + +int vhost_get_zc_used_len (struct vhost_virtqueue *vq,int idx) +{ +return vq->heads[idx].len; +} +EXPORT_SYMBOL_GPL (vhost_get_zc_used_len); + +void vhost_set_zc_used (struct vhost_virtqueue *vq, +int idx,unsigned int head,int len) +{ + vq->heads[idx].id = head; + vq->heads[idx].len = len; +} +EXPORT_SYMBOL_GPL (vhost_set_zc_used); + +void vhost_add_shadow_used (struct vhost_virtqueue *vq, +unsigned int head,int len) +{ +vhost_set_zc_used (vq, vq->nheads, head, len); + ++vq->nheads; +} +EXPORT_SYMBOL_GPL (vhost_add_shadow_used); + +int vhost_get_shadow_used_count (struct vhost_virtqueue *vq) +{ +return vq->nheads; +} +EXPORT_SYMBOL_GPL (vhost_get_shadow_used_count); +/* After we've used one of their buffers, we tell them about it. We'll then * want to notify the guest, using eventfd. */ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vring_used_elem *heads,
@@ -2879,6 +2918,19 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vring_used_elem *heads, }EXPORT_SYMBOL_GPL (vhost_add_used_n); +/* After we've used one of their buffers, we tell them about it. We'll then +* want to notify the guest, using eventfd. */ +int vhost_add_used (struct vhost_virtqueue *vq,unsigned int head,int len) +{ +struct vring_used_elem heads = { +cpu_to_vhost32 (vq, head), +cpu_to_vhost32 (vq, len) + }; + +return vhost_add_used_n (vq, &heads,1 ); +} +EXPORT_SYMBOL_GPL (vhost_add_used); +static bool vhost_notify (struct vhost_dev *dev,struct vhost_virtqueue *vq) {__u16 old, new;
@@ -2945,6 +2997,23 @@ void vhost_add_used_and_signal_n(struct vhost_dev *dev, }EXPORT_SYMBOL_GPL (vhost_add_used_and_signal_n); +void vhost_flush_shadow_used_and_signal (struct vhost_virtqueue *vq) + +{ +if (!vq->nheads) +return ; + +vhost_add_used_and_signal_n (vq->dev, vq, vq->heads, vq->nheads); + vq->nheads =0 ; +} +EXPORT_SYMBOL_GPL (vhost_flush_shadow_used_and_signal); + +void vhost_flush_zc_used_and_signal (struct vhost_virtqueue *vq,int idx,int n) +{ +vhost_add_used_and_signal_n (vq->dev, vq, &vq->heads[idx], n); +} +EXPORT_SYMBOL_GPL (vhost_flush_zc_used_and_signal); +/* return true if we're sure that avaiable ring is empty */ bool vhost_vq_avail_empty (struct vhost_virtqueue *vq) {
drivers/vhost/vhost.h +18 -0
@@ -163,6 +163,7 @@ struct vhost_virtqueue {struct iovec iotlb_iov[64 ];struct iovec *indirect;struct vring_used_elem *heads; +int nheads;/* Protected by virtqueue mutex. */ struct vhost_umem *umem;struct vhost_umem *iotlb;
@@ -241,10 +242,27 @@ int vhost_vq_init_access(struct vhost_virtqueue *);int vhost_add_used (struct vhost_virtqueue *,unsigned int head,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);void vhost_add_used_and_signal_n (struct vhost_dev *,struct vhost_virtqueue *,struct vring_used_elem *heads,unsigned count); + +/* Zerocopy shadow used ring API */ +void vhost_set_zc_used_len (struct vhost_virtqueue *vq, +int idx,int len); +int vhost_get_zc_used_len (struct vhost_virtqueue *vq,int idx); +void vhost_flush_zc_used_and_signal (struct vhost_virtqueue *vq,int idx,int n); +void vhost_set_zc_used (struct vhost_virtqueue *vq,int idx, +unsigned int head,int len); + +/* Non zerocopy shadow used ring API */ +void vhost_add_shadow_used (struct vhost_virtqueue *vq,unsigned int head, +int len); +void vhost_flush_shadow_used_and_signal (struct vhost_virtqueue *vq); +void vhost_discard_shadow_used (struct vhost_virtqueue *vq,int n); +int vhost_get_shadow_used_count (struct vhost_virtqueue *vq); +void vhost_signal (struct vhost_dev *,struct vhost_virtqueue *);void vhost_disable_notify (struct vhost_virtqueue *vq);bool vhost_vq_avail_empty (struct vhost_virtqueue *vq);
Signature · 1 line
2.18.1
PATCH v3 5/15 vhost: introduce helpers to manipulate shadow used ring
In reply to Jason WangWe open coding vq->heads[] in net.c for:
1) implementing batching which in fact a shadow used ring implementation.
2) maintain pending heads in order which is in fact another kind of shadow used ring
But this expose used ring layout for device which makes it hard to introduce new kind of ring like packed virtqueue. So this patch introduces two types of shadow used ring API:
1) shadow used ring API for batch updating of used heads
2) zerocopy shadow used API for maintaining pending heads and batch updating used heads
This can help to hide the used ring layout from device. Device should not mix using those two kinds of APIs.
--- drivers/vhost/vhost.c | 95 +++++++++++++++++++++++++++++++++++++------ drivers/vhost/vhost.h | 18 ++++++++ 2 files changed, 100 insertions(+), 13 deletions(-)
drivers/vhost/vhost.c +82 -13
@@ -486,6 +486,7 @@ static void vhost_vq_reset(struct vhost_dev *dev,#if VHOST_ARCH_CAN_ACCEL_UACCESS vhost_reset_vq_maps (vq);#endif + vq->nheads =0 ; }static int vhost_worker (void *data)
@@ -2790,25 +2791,28 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq, }EXPORT_SYMBOL_GPL (vhost_get_vq_desc); -/* Reverse the effect of vhost_get_vq_desc. Useful for error handling. */ -void vhost_discard_vq_desc (struct vhost_virtqueue *vq,int n) +static void vhost_withdraw_shadow_used (struct vhost_virtqueue *vq,int count) { - vq->last_avail_idx -= n; +BUG_ON (count > vq->nheads); + vq->nheads -= count; } -EXPORT_SYMBOL_GPL (vhost_discard_vq_desc); -/* After we've used one of their buffers, we tell them about it. We'll then -* want to notify the guest, using eventfd. */ -int vhost_add_used (struct vhost_virtqueue *vq,unsigned int head,int len) +/* Reverse the effect of vhost_get_vq_desc and +* vhost_add_shadow_used. Useful for error handleing +*/ +void vhost_discard_shadow_used (struct vhost_virtqueue *vq,int n) { -struct vring_used_elem heads = { -cpu_to_vhost32 (vq, head), -cpu_to_vhost32 (vq, len) - }; +vhost_withdraw_shadow_used (vq, n); +vhost_discard_vq_desc (vq, n); +} +EXPORT_SYMBOL_GPL (vhost_discard_shadow_used); -return vhost_add_used_n (vq, &heads,1 ); +/* Reverse the effect of vhost_get_vq_desc. Useful for error handling. */ +void vhost_discard_vq_desc (struct vhost_virtqueue *vq,int n) +{ + vq->last_avail_idx -= n; } -EXPORT_SYMBOL_GPL (vhost_add_used); +EXPORT_SYMBOL_GPL (vhost_discard_vq_desc); static int __vhost_add_used_n(struct vhost_virtqueue *vq, struct vring_used_elem *heads,
@@ -2842,6 +2846,41 @@ static int __vhost_add_used_n(struct vhost_virtqueue *vq,return 0 ; } +void vhost_set_zc_used_len (struct vhost_virtqueue *vq, +int idx,int len) +{ + vq->heads[idx].len = len; +} +EXPORT_SYMBOL_GPL (vhost_set_zc_used_len); + +int vhost_get_zc_used_len (struct vhost_virtqueue *vq,int idx) +{ +return vq->heads[idx].len; +} +EXPORT_SYMBOL_GPL (vhost_get_zc_used_len); + +void vhost_set_zc_used (struct vhost_virtqueue *vq, +int idx,unsigned int head,int len) +{ + vq->heads[idx].id = head; + vq->heads[idx].len = len; +} +EXPORT_SYMBOL_GPL (vhost_set_zc_used); + +void vhost_add_shadow_used (struct vhost_virtqueue *vq, +unsigned int head,int len) +{ +vhost_set_zc_used (vq, vq->nheads, head, len); + ++vq->nheads; +} +EXPORT_SYMBOL_GPL (vhost_add_shadow_used); + +int vhost_get_shadow_used_count (struct vhost_virtqueue *vq) +{ +return vq->nheads; +} +EXPORT_SYMBOL_GPL (vhost_get_shadow_used_count); +/* After we've used one of their buffers, we tell them about it. We'll then * want to notify the guest, using eventfd. */ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vring_used_elem *heads,
@@ -2879,6 +2918,19 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vring_used_elem *heads, }EXPORT_SYMBOL_GPL (vhost_add_used_n); +/* After we've used one of their buffers, we tell them about it. We'll then +* want to notify the guest, using eventfd. */ +int vhost_add_used (struct vhost_virtqueue *vq,unsigned int head,int len) +{ +struct vring_used_elem heads = { +cpu_to_vhost32 (vq, head), +cpu_to_vhost32 (vq, len) + }; + +return vhost_add_used_n (vq, &heads,1 ); +} +EXPORT_SYMBOL_GPL (vhost_add_used); +static bool vhost_notify (struct vhost_dev *dev,struct vhost_virtqueue *vq) {__u16 old, new;
@@ -2945,6 +2997,23 @@ void vhost_add_used_and_signal_n(struct vhost_dev *dev, }EXPORT_SYMBOL_GPL (vhost_add_used_and_signal_n); +void vhost_flush_shadow_used_and_signal (struct vhost_virtqueue *vq) + +{ +if (!vq->nheads) +return ; + +vhost_add_used_and_signal_n (vq->dev, vq, vq->heads, vq->nheads); + vq->nheads =0 ; +} +EXPORT_SYMBOL_GPL (vhost_flush_shadow_used_and_signal); + +void vhost_flush_zc_used_and_signal (struct vhost_virtqueue *vq,int idx,int n) +{ +vhost_add_used_and_signal_n (vq->dev, vq, &vq->heads[idx], n); +} +EXPORT_SYMBOL_GPL (vhost_flush_zc_used_and_signal); +/* return true if we're sure that avaiable ring is empty */ bool vhost_vq_avail_empty (struct vhost_virtqueue *vq) {
drivers/vhost/vhost.h +18 -0
@@ -163,6 +163,7 @@ struct vhost_virtqueue {struct iovec iotlb_iov[64 ];struct iovec *indirect;struct vring_used_elem *heads; +int nheads;/* Protected by virtqueue mutex. */ struct vhost_umem *umem;struct vhost_umem *iotlb;
@@ -241,10 +242,27 @@ int vhost_vq_init_access(struct vhost_virtqueue *);int vhost_add_used (struct vhost_virtqueue *,unsigned int head,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);void vhost_add_used_and_signal_n (struct vhost_dev *,struct vhost_virtqueue *,struct vring_used_elem *heads,unsigned count); + +/* Zerocopy shadow used ring API */ +void vhost_set_zc_used_len (struct vhost_virtqueue *vq, +int idx,int len); +int vhost_get_zc_used_len (struct vhost_virtqueue *vq,int idx); +void vhost_flush_zc_used_and_signal (struct vhost_virtqueue *vq,int idx,int n); +void vhost_set_zc_used (struct vhost_virtqueue *vq,int idx, +unsigned int head,int len); + +/* Non zerocopy shadow used ring API */ +void vhost_add_shadow_used (struct vhost_virtqueue *vq,unsigned int head, +int len); +void vhost_flush_shadow_used_and_signal (struct vhost_virtqueue *vq); +void vhost_discard_shadow_used (struct vhost_virtqueue *vq,int n); +int vhost_get_shadow_used_count (struct vhost_virtqueue *vq); +void vhost_signal (struct vhost_dev *,struct vhost_virtqueue *);void vhost_disable_notify (struct vhost_virtqueue *vq);bool vhost_vq_avail_empty (struct vhost_virtqueue *vq);
Signature · 1 line
2.18.1
PATCH v3 6/15 vhost_net: switch TX to use shadow used ring API
In reply to Jason WangThis patch switch to use shadow used ring API for transmission. This will help to hide used ring layout from device.
--- drivers/vhost/net.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-)
drivers/vhost/net.c +15 -16
@@ -361,22 +361,22 @@ static void vhost_zerocopy_signal_used(struct vhost_net *net, {struct vhost_net_virtqueue *nvq = container_of(vq, struct vhost_net_virtqueue, vq); -int i, add; +int i, add, len;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 ) + len =vhost_get_zc_used_len (vq, i); +if (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 (len)) { +vhost_set_zc_used_len (vq, i,VHOST_DMA_CLEAR_LEN ); ++j; }else break ; }while (j) { add =min (UIO_MAXIOV - nvq->done_idx, j); -vhost_add_used_and_signal_n (vq->dev, vq, - &vq->heads[nvq->done_idx], add); +vhost_flush_zc_used_and_signal (vq, nvq->done_idx, add); nvq->done_idx = (nvq->done_idx + add) %UIO_MAXIOV ; j -= add; }
@@ -391,8 +391,8 @@ 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 ? -VHOST_DMA_DONE_LEN :VHOST_DMA_FAILED_LEN ; +vhost_set_zc_used_len (vq, ubuf->desc, success ? +VHOST_DMA_DONE_LEN :VHOST_DMA_FAILED_LEN ); cnt =vhost_net_ubuf_put (ubufs);/*
@@ -480,7 +480,7 @@ static void vhost_tx_batch(struct vhost_net *net, } signal_used: -vhost_net_signal_used (nvq); +vhost_flush_shadow_used_and_signal (&nvq->vq); nvq->batched_xdp =0 ; }
@@ -776,7 +776,7 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock) do { bool busyloop_intr = false; - if (nvq->done_idx == VHOST_NET_BATCH) + if (vhost_get_shadow_used_count(vq) == VHOST_NET_BATCH) vhost_tx_batch(net, nvq, sock, &msg); head = get_tx_bufs(net, nvq, &msg, &out, &in, &len,
@@ -835,9 +835,7 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock)pr_debug ("Truncated TX packet: len %d != %zd\n" , err, len); done: - vq->heads[nvq->done_idx].id =cpu_to_vhost32 (vq, head); - vq->heads[nvq->done_idx].len =0 ; - ++nvq->done_idx; +vhost_add_shadow_used (vq,cpu_to_vhost32 (vq, head),0 ); }while (likely (!vhost_exceeds_weight (vq, ++sent_pkts, total_len)));vhost_tx_batch (net, nvq, sock, &msg);
@@ -908,9 +906,10 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock) msg.msg_control =NULL ; ubufs =NULL ; } - vq->heads[nvq->upend_idx].id =cpu_to_vhost32 (vq, head); - vq->heads[nvq->upend_idx].len = zcopy_used ? -VHOST_DMA_IN_PROGRESS :VHOST_DMA_DONE_LEN ; +vhost_set_zc_used (vq, nvq->upend_idx, +cpu_to_vhost32 (vq, head), + zcopy_used ?VHOST_DMA_IN_PROGRESS : +VHOST_DMA_DONE_LEN ); nvq->upend_idx = (nvq->upend_idx +1 ) %UIO_MAXIOV ; total_len += len; if (tx_can_batch(vq, total_len) &&
Signature · 1 line
2.18.1
PATCH v3 6/15 vhost_net: switch TX to use shadow used ring API
In reply to Jason WangThis patch switch to use shadow used ring API for transmission. This will help to hide used ring layout from device.
--- drivers/vhost/net.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-)
drivers/vhost/net.c +15 -16
@@ -361,22 +361,22 @@ static void vhost_zerocopy_signal_used(struct vhost_net *net, {struct vhost_net_virtqueue *nvq = container_of(vq, struct vhost_net_virtqueue, vq); -int i, add; +int i, add, len;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 ) + len =vhost_get_zc_used_len (vq, i); +if (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 (len)) { +vhost_set_zc_used_len (vq, i,VHOST_DMA_CLEAR_LEN ); ++j; }else break ; }while (j) { add =min (UIO_MAXIOV - nvq->done_idx, j); -vhost_add_used_and_signal_n (vq->dev, vq, - &vq->heads[nvq->done_idx], add); +vhost_flush_zc_used_and_signal (vq, nvq->done_idx, add); nvq->done_idx = (nvq->done_idx + add) %UIO_MAXIOV ; j -= add; }
@@ -391,8 +391,8 @@ 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 ? -VHOST_DMA_DONE_LEN :VHOST_DMA_FAILED_LEN ; +vhost_set_zc_used_len (vq, ubuf->desc, success ? +VHOST_DMA_DONE_LEN :VHOST_DMA_FAILED_LEN ); cnt =vhost_net_ubuf_put (ubufs);/*
@@ -480,7 +480,7 @@ static void vhost_tx_batch(struct vhost_net *net, } signal_used: -vhost_net_signal_used (nvq); +vhost_flush_shadow_used_and_signal (&nvq->vq); nvq->batched_xdp =0 ; }
@@ -776,7 +776,7 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock) do { bool busyloop_intr = false; - if (nvq->done_idx == VHOST_NET_BATCH) + if (vhost_get_shadow_used_count(vq) == VHOST_NET_BATCH) vhost_tx_batch(net, nvq, sock, &msg); head = get_tx_bufs(net, nvq, &msg, &out, &in, &len,
@@ -835,9 +835,7 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock)pr_debug ("Truncated TX packet: len %d != %zd\n" , err, len); done: - vq->heads[nvq->done_idx].id =cpu_to_vhost32 (vq, head); - vq->heads[nvq->done_idx].len =0 ; - ++nvq->done_idx; +vhost_add_shadow_used (vq,cpu_to_vhost32 (vq, head),0 ); }while (likely (!vhost_exceeds_weight (vq, ++sent_pkts, total_len)));vhost_tx_batch (net, nvq, sock, &msg);
@@ -908,9 +906,10 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock) msg.msg_control =NULL ; ubufs =NULL ; } - vq->heads[nvq->upend_idx].id =cpu_to_vhost32 (vq, head); - vq->heads[nvq->upend_idx].len = zcopy_used ? -VHOST_DMA_IN_PROGRESS :VHOST_DMA_DONE_LEN ; +vhost_set_zc_used (vq, nvq->upend_idx, +cpu_to_vhost32 (vq, head), + zcopy_used ?VHOST_DMA_IN_PROGRESS : +VHOST_DMA_DONE_LEN ); nvq->upend_idx = (nvq->upend_idx +1 ) %UIO_MAXIOV ; total_len += len; if (tx_can_batch(vq, total_len) &&
Signature · 1 line
2.18.1
PATCH v3 7/15 vhost_net: calculate last used length once for mergeable buffer
In reply to Jason WangThis patch tries to calculate last used length once instead of twice. This can help to convert to use shadow used ring API for RX.
--- drivers/vhost/net.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/vhost/net.c +2 -2
@@ -1065,12 +1065,12 @@ static int get_rx_bufs(struct vhost_virtqueue *vq, } 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; + heads[headcount].len =cpu_to_vhost32 (vq, + datalen >=0 ? len : len + datalen); ++headcount; seg += in; } - heads[headcount -1 ].len =cpu_to_vhost32 (vq, len + datalen); *iovcount = seg;if (unlikely (log)) *log_num = nlogs;
Signature · 1 line
2.18.1
PATCH v3 7/15 vhost_net: calculate last used length once for mergeable buffer
In reply to Jason WangThis patch tries to calculate last used length once instead of twice. This can help to convert to use shadow used ring API for RX.
--- drivers/vhost/net.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/vhost/net.c +2 -2
@@ -1065,12 +1065,12 @@ static int get_rx_bufs(struct vhost_virtqueue *vq, } 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; + heads[headcount].len =cpu_to_vhost32 (vq, + datalen >=0 ? len : len + datalen); ++headcount; seg += in; } - heads[headcount -1 ].len =cpu_to_vhost32 (vq, len + datalen); *iovcount = seg;if (unlikely (log)) *log_num = nlogs;
Signature · 1 line
2.18.1
PATCH v3 8/15 vhost_net: switch to use shadow used ring API for RX
In reply to Jason WangThis patch switches to use shadow used ring API for RX. This will help to hid used ring layout from device.
--- drivers/vhost/net.c | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-)
drivers/vhost/net.c +11 -26
@@ -445,18 +445,6 @@ static int vhost_net_enable_vq(struct vhost_net *n,return vhost_poll_start (poll, sock->file); } -static void vhost_net_signal_used (struct vhost_net_virtqueue *nvq) -{ -struct vhost_virtqueue *vq = &nvq->vq; -struct vhost_dev *dev = vq->dev; - -if (!nvq->done_idx) -return ; - -vhost_add_used_and_signal_n (dev, vq, vq->heads, nvq->done_idx); - nvq->done_idx =0 ; -} - static void vhost_tx_batch(struct vhost_net *net, struct vhost_net_virtqueue *nvq, struct socket *sock,
@@ -999,7 +987,7 @@ static int vhost_net_rx_peek_head_len(struct vhost_net *net, struct sock *sk,if (!len && rvq->busyloop_timeout) {/* Flush batched heads first */ -vhost_net_signal_used (rnvq); +vhost_flush_shadow_used_and_signal (rvq);/* Both tx vq and rx socket were polled here */ vhost_net_busy_poll (net, rvq, tvq, busyloop_intr, true);
@@ -1020,7 +1008,6 @@ static int vhost_net_rx_peek_head_len(struct vhost_net *net, struct sock *sk,* 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,
@@ -1063,11 +1050,11 @@ static int get_rx_bufs(struct vhost_virtqueue *vq, nlogs += *log_num; log += *log_num; } - heads[headcount].id =cpu_to_vhost32 (vq, d); len =iov_length (vq->iov + seg, in); datalen -= len; - heads[headcount].len =cpu_to_vhost32 (vq, - datalen >=0 ? len : len + datalen); +vhost_add_shadow_used (vq,cpu_to_vhost32 (vq, d), +cpu_to_vhost32 (vq, datalen >=0 ? len + : len + datalen)); ++headcount; seg += in; }
@@ -1082,7 +1069,7 @@ static int get_rx_bufs(struct vhost_virtqueue *vq, }return headcount; err: -vhost_discard_vq_desc (vq, headcount); +vhost_discard_shadow_used (vq, headcount);return r; }
@@ -1141,8 +1128,7 @@ static void handle_rx(struct vhost_net *net)break ; 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, + headcount =get_rx_bufs (vq, vhost_len, &in, vq_log, &log,likely (mergeable) ?UIO_MAXIOV :1 );/* On error, stop handling until the next kick. */ if (unlikely (headcount <0 ))
@@ -1189,7 +1175,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_shadow_used (vq, headcount);continue ; }/* Supply virtio_net_hdr if VHOST_NET_F_VIRTIO_NET_HDR */
@@ -1213,12 +1199,11 @@ 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_shadow_used (vq, headcount); goto out; } - nvq->done_idx += headcount; -if (nvq->done_idx >VHOST_NET_BATCH ) -vhost_net_signal_used (nvq); +if (vhost_get_shadow_used_count (vq) >VHOST_NET_BATCH ) +vhost_flush_shadow_used_and_signal (vq);if (unlikely (vq_log))vhost_log_write (vq, vq_log, log, vhost_len, vq->iov, in);
@@ -1230,7 +1215,7 @@ static void handle_rx(struct vhost_net *net)else if (!sock_len)vhost_net_enable_vq (net, vq); out: -vhost_net_signal_used (nvq); +vhost_flush_shadow_used_and_signal (vq);mutex_unlock (&vq->mutex); }
Signature · 1 line
2.18.1
PATCH v3 8/15 vhost_net: switch to use shadow used ring API for RX
In reply to Jason WangThis patch switches to use shadow used ring API for RX. This will help to hid used ring layout from device.
--- drivers/vhost/net.c | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-)
drivers/vhost/net.c +11 -26
@@ -445,18 +445,6 @@ static int vhost_net_enable_vq(struct vhost_net *n,return vhost_poll_start (poll, sock->file); } -static void vhost_net_signal_used (struct vhost_net_virtqueue *nvq) -{ -struct vhost_virtqueue *vq = &nvq->vq; -struct vhost_dev *dev = vq->dev; - -if (!nvq->done_idx) -return ; - -vhost_add_used_and_signal_n (dev, vq, vq->heads, nvq->done_idx); - nvq->done_idx =0 ; -} - static void vhost_tx_batch(struct vhost_net *net, struct vhost_net_virtqueue *nvq, struct socket *sock,
@@ -999,7 +987,7 @@ static int vhost_net_rx_peek_head_len(struct vhost_net *net, struct sock *sk,if (!len && rvq->busyloop_timeout) {/* Flush batched heads first */ -vhost_net_signal_used (rnvq); +vhost_flush_shadow_used_and_signal (rvq);/* Both tx vq and rx socket were polled here */ vhost_net_busy_poll (net, rvq, tvq, busyloop_intr, true);
@@ -1020,7 +1008,6 @@ static int vhost_net_rx_peek_head_len(struct vhost_net *net, struct sock *sk,* 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,
@@ -1063,11 +1050,11 @@ static int get_rx_bufs(struct vhost_virtqueue *vq, nlogs += *log_num; log += *log_num; } - heads[headcount].id =cpu_to_vhost32 (vq, d); len =iov_length (vq->iov + seg, in); datalen -= len; - heads[headcount].len =cpu_to_vhost32 (vq, - datalen >=0 ? len : len + datalen); +vhost_add_shadow_used (vq,cpu_to_vhost32 (vq, d), +cpu_to_vhost32 (vq, datalen >=0 ? len + : len + datalen)); ++headcount; seg += in; }
@@ -1082,7 +1069,7 @@ static int get_rx_bufs(struct vhost_virtqueue *vq, }return headcount; err: -vhost_discard_vq_desc (vq, headcount); +vhost_discard_shadow_used (vq, headcount);return r; }
@@ -1141,8 +1128,7 @@ static void handle_rx(struct vhost_net *net)break ; 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, + headcount =get_rx_bufs (vq, vhost_len, &in, vq_log, &log,likely (mergeable) ?UIO_MAXIOV :1 );/* On error, stop handling until the next kick. */ if (unlikely (headcount <0 ))
@@ -1189,7 +1175,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_shadow_used (vq, headcount);continue ; }/* Supply virtio_net_hdr if VHOST_NET_F_VIRTIO_NET_HDR */
@@ -1213,12 +1199,11 @@ 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_shadow_used (vq, headcount); goto out; } - nvq->done_idx += headcount; -if (nvq->done_idx >VHOST_NET_BATCH ) -vhost_net_signal_used (nvq); +if (vhost_get_shadow_used_count (vq) >VHOST_NET_BATCH ) +vhost_flush_shadow_used_and_signal (vq);if (unlikely (vq_log))vhost_log_write (vq, vq_log, log, vhost_len, vq->iov, in);
@@ -1230,7 +1215,7 @@ static void handle_rx(struct vhost_net *net)else if (!sock_len)vhost_net_enable_vq (net, vq); out: -vhost_net_signal_used (nvq); +vhost_flush_shadow_used_and_signal (vq);mutex_unlock (&vq->mutex); }
Signature · 1 line
2.18.1
PATCH v3 9/15 vhost: do not export vhost_add_used_n() and vhost_add_used_and_signal_n()
In reply to Jason WangWe would request device to use shadow used ring API. Then there's no need for exposing those to device.
--- drivers/vhost/vhost.c | 13 +++++++------ drivers/vhost/vhost.h | 4 ---- 2 files changed, 7 insertions(+), 10 deletions(-)
drivers/vhost/vhost.c +7 -6
@@ -2883,8 +2883,9 @@ EXPORT_SYMBOL_GPL(vhost_get_shadow_used_count);/* After we've used one of their buffers, we tell them about it. We'll then * want to notify the guest, using eventfd. */ -int vhost_add_used_n (struct vhost_virtqueue *vq,struct vring_used_elem *heads, -unsigned count) +static int vhost_add_used_n (struct vhost_virtqueue *vq, +struct vring_used_elem *heads, +unsigned count) {int start, n, r;
@@ -2988,14 +2989,14 @@ void vhost_add_used_and_signal(struct vhost_dev *dev,EXPORT_SYMBOL_GPL (vhost_add_used_and_signal);/* multi-buffer version of vhost_add_used_and_signal */ -void vhost_add_used_and_signal_n (struct vhost_dev *dev, -struct vhost_virtqueue *vq, -struct vring_used_elem *heads,unsigned count) +static void vhost_add_used_and_signal_n (struct vhost_dev *dev, +struct vhost_virtqueue *vq, +struct vring_used_elem *heads, +unsigned count) {vhost_add_used_n (vq, heads, count);vhost_signal (dev, vq); } -EXPORT_SYMBOL_GPL (vhost_add_used_and_signal_n);void vhost_flush_shadow_used_and_signal (struct vhost_virtqueue *vq)
drivers/vhost/vhost.h +0 -4
@@ -240,13 +240,9 @@ 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_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); -void vhost_add_used_and_signal_n (struct vhost_dev *,struct vhost_virtqueue *, -struct vring_used_elem *heads,unsigned count);/* Zerocopy shadow used ring API */ void vhost_set_zc_used_len(struct vhost_virtqueue *vq,
Signature · 1 line
2.18.1
PATCH v3 9/15 vhost: do not export vhost_add_used_n() and vhost_add_used_and_signal_n()
In reply to Jason WangWe would request device to use shadow used ring API. Then there's no need for exposing those to device.
--- drivers/vhost/vhost.c | 13 +++++++------ drivers/vhost/vhost.h | 4 ---- 2 files changed, 7 insertions(+), 10 deletions(-)
drivers/vhost/vhost.c +7 -6
@@ -2883,8 +2883,9 @@ EXPORT_SYMBOL_GPL(vhost_get_shadow_used_count);/* After we've used one of their buffers, we tell them about it. We'll then * want to notify the guest, using eventfd. */ -int vhost_add_used_n (struct vhost_virtqueue *vq,struct vring_used_elem *heads, -unsigned count) +static int vhost_add_used_n (struct vhost_virtqueue *vq, +struct vring_used_elem *heads, +unsigned count) {int start, n, r;
@@ -2988,14 +2989,14 @@ void vhost_add_used_and_signal(struct vhost_dev *dev,EXPORT_SYMBOL_GPL (vhost_add_used_and_signal);/* multi-buffer version of vhost_add_used_and_signal */ -void vhost_add_used_and_signal_n (struct vhost_dev *dev, -struct vhost_virtqueue *vq, -struct vring_used_elem *heads,unsigned count) +static void vhost_add_used_and_signal_n (struct vhost_dev *dev, +struct vhost_virtqueue *vq, +struct vring_used_elem *heads, +unsigned count) {vhost_add_used_n (vq, heads, count);vhost_signal (dev, vq); } -EXPORT_SYMBOL_GPL (vhost_add_used_and_signal_n);void vhost_flush_shadow_used_and_signal (struct vhost_virtqueue *vq)
drivers/vhost/vhost.h +0 -4
@@ -240,13 +240,9 @@ 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_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); -void vhost_add_used_and_signal_n (struct vhost_dev *,struct vhost_virtqueue *, -struct vring_used_elem *heads,unsigned count);/* Zerocopy shadow used ring API */ void vhost_set_zc_used_len(struct vhost_virtqueue *vq,
Signature · 1 line
2.18.1
PATCH v3 10/15 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 | 88 ++++++++++++++++++++++--------------------- drivers/vhost/scsi.c | 62 ++++++++++++++++-------------- drivers/vhost/vhost.c | 38 +++++++++++-------- drivers/vhost/vhost.h | 11 +++--- drivers/vhost/vsock.c | 43 +++++++++++---------- 5 files changed, 129 insertions(+), 113 deletions(-)
drivers/vhost/net.c +46 -42
@@ -546,25 +546,28 @@ static void vhost_net_busy_poll(struct vhost_net *net, }static int vhost_net_tx_get_vq_desc (struct vhost_net *net, -struct vhost_net_virtqueue *tnvq, +struct vring_used_elem *used_elem,unsigned int *out_num,unsigned int *in_num,struct msghdr *msghdr,bool *busyloop_intr) { +struct vhost_net_virtqueue *tnvq = &net->vqs[VHOST_NET_VQ_TX ];struct vhost_net_virtqueue *rnvq = &net->vqs[VHOST_NET_VQ_RX ];struct vhost_virtqueue *rvq = &rnvq->vq;struct vhost_virtqueue *tvq = &tnvq->vq; -int r =vhost_get_vq_desc (tvq, tvq->iov,ARRAY_SIZE (tvq->iov), +int r =vhost_get_vq_desc (tvq, used_elem, tvq->iov, +ARRAY_SIZE (tvq->iov), out_num, in_num,NULL ,NULL ); -if (r == tvq->num && tvq->busyloop_timeout) { +if (r == -ENOSPC && tvq->busyloop_timeout) {/* Flush batched packets first */ if (!vhost_sock_zcopy (tvq->private_data))vhost_tx_batch (net, tnvq, tvq->private_data, msghdr);vhost_net_busy_poll (net, rvq, tvq, busyloop_intr, false); - r =vhost_get_vq_desc (tvq, tvq->iov,ARRAY_SIZE (tvq->iov), + r =vhost_get_vq_desc (tvq, used_elem, tvq->iov, +ARRAY_SIZE (tvq->iov), out_num, in_num,NULL ,NULL ); }
@@ -593,6 +596,7 @@ static size_t init_iov_iter(struct vhost_virtqueue *vq, struct iov_iter *iter, } static int get_tx_bufs(struct vhost_net *net, + struct vring_used_elem *used_elem, struct vhost_net_virtqueue *nvq, struct msghdr *msg, unsigned int *out, unsigned int *in,
@@ -601,9 +605,10 @@ static int get_tx_bufs(struct vhost_net *net,struct vhost_virtqueue *vq = &nvq->vq;int ret; - ret =vhost_net_tx_get_vq_desc (net, nvq, out, in, msg, busyloop_intr); + ret =vhost_net_tx_get_vq_desc (net, used_elem, out, in, + msg, busyloop_intr); -if (ret <0 || ret == vq->num) +if (ret <0 || ret == -ENOSPC )return ret;if (*in) {
@@ -747,8 +752,8 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock) {struct vhost_net_virtqueue *nvq = &net->vqs[VHOST_NET_VQ_TX ];struct vhost_virtqueue *vq = &nvq->vq; +struct vring_used_elem used;unsigned out, in; -int head;struct msghdr msg = { .msg_name =NULL , .msg_namelen =0 ,
@@ -767,13 +772,11 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock)if (vhost_get_shadow_used_count (vq) ==VHOST_NET_BATCH )vhost_tx_batch (net, nvq, sock, &msg); - head =get_tx_bufs (net, nvq, &msg, &out, &in, &len, - &busyloop_intr); -/* On error, stop handling until the next kick. */ -if (unlikely (head <0 )) -break ; + err =get_tx_bufs (net, &used, + nvq, &msg, &out, &in, &len, + &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 (vq))) {
@@ -782,7 +785,9 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock) }break ; } - +/* On error, stop handling until the next kick. */ +if (unlikely (err <0 )) +break ; total_len += len;/* For simplicity, TX batching is only enabled if
@@ -823,7 +828,7 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock)pr_debug ("Truncated TX packet: len %d != %zd\n" , err, len); done: -vhost_add_shadow_used (vq,cpu_to_vhost32 (vq, head),0 ); +vhost_add_shadow_used (vq, &used,0 ); }while (likely (!vhost_exceeds_weight (vq, ++sent_pkts, total_len)));vhost_tx_batch (net, nvq, sock, &msg);
@@ -834,7 +839,6 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)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 ,
@@ -843,6 +847,7 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock) .msg_flags = MSG_DONTWAIT, };struct tun_msg_ctl ctl; +struct vring_used_elem used;size_t len, total_len =0 ;int err;struct vhost_net_ubuf_ref *uninitialized_var (ubufs );
@@ -856,13 +861,10 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)vhost_zerocopy_signal_used (net, vq); busyloop_intr = false; - head =get_tx_bufs (net, nvq, &msg, &out, &in, &len, - &busyloop_intr); -/* On error, stop handling until the next kick. */ -if (unlikely (head <0 )) -break ; + err =get_tx_bufs (net, &used, nvq, &msg, &out, &in, &len, + &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 (vq))) {
@@ -871,6 +873,9 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock) }break ; } +/* On error, stop handling until the next kick. */ +if (unlikely (err <0 )) +break ; zcopy_used = len >=VHOST_GOODCOPY_LEN && !vhost_exceeds_maxpend (net)
@@ -895,7 +900,7 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock) ubufs =NULL ; }vhost_set_zc_used (vq, nvq->upend_idx, -cpu_to_vhost32 (vq, head), + &used, zcopy_used ?VHOST_DMA_IN_PROGRESS :VHOST_DMA_DONE_LEN ); nvq->upend_idx = (nvq->upend_idx +1 ) %UIO_MAXIOV ;
@@ -921,7 +926,6 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)if (err != len)pr_debug ("Truncated TX packet: " " len %d != %zd\n" , err, len); -vhost_zerocopy_signal_used (net, vq);vhost_net_tx_packet (net); }while (likely (!vhost_exceeds_weight (vq, ++sent_pkts, total_len)));
@@ -1012,34 +1016,30 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,unsigned *iovcount, struct vhost_log *log, unsigned *log_num, - unsigned int quota) + unsigned int quota, + s16 *count) { unsigned int out, in;int seg =0 ;int headcount =0 ; -unsigned d; -int r, nlogs =0 ; +int r =0 , nlogs =0 ;/* len is always initialized before use since we are always called with * datalen > 0. */ u32 uninitialized_var (len ); +struct vring_used_elem uninitialized_var (used );while (datalen >0 && headcount < quota) {if (unlikely (seg >=UIO_MAXIOV )) { r = -ENOBUFS ; goto err; } - r =vhost_get_vq_desc (vq, vq->iov + seg, + r =vhost_get_vq_desc (vq, &used, 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);
@@ -1052,7 +1052,7 @@ static int get_rx_bufs(struct vhost_virtqueue *vq, } len =iov_length (vq->iov + seg, in); datalen -= len; -vhost_add_shadow_used (vq,cpu_to_vhost32 (vq, d), +vhost_add_shadow_used (vq, &used,cpu_to_vhost32 (vq, datalen >=0 ? len : len + datalen)); ++headcount;
@@ -1064,12 +1064,15 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,/* Detect overrun */ if (unlikely (datalen >0 )) { - r =UIO_MAXIOV +1 ; + headcount =UIO_MAXIOV +1 ; goto err; } -return headcount; + + *count = headcount; +return 0 ; err:vhost_discard_shadow_used (vq, headcount); + *count =0 ;return r; }
@@ -1128,13 +1131,11 @@ static void handle_rx(struct vhost_net *net)break ; sock_len += sock_hlen; vhost_len = sock_len + vhost_hlen; - headcount =get_rx_bufs (vq, 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 =get_rx_bufs (vq, 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 (vq))) {
@@ -1148,6 +1149,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 +34 -28
173 lines not on this page · raw message
drivers/vhost/vhost.c +22 -16
@@ -2651,6 +2651,7 @@ static int get_indirect(struct vhost_virtqueue *vq,* never a valid descriptor number) if none was found. A negative code is * returned on error. */ int vhost_get_vq_desc (struct vhost_virtqueue *vq, +struct vring_used_elem *used,struct iovec iov[],unsigned int iov_size,unsigned int *out_num,unsigned int *in_num,struct vhost_log *log,unsigned int *log_num)
@@ -2683,7 +2684,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,* invalid. */ if (vq->avail_idx == last_avail_idx) -return vq->num; +return -ENOSPC ;/* Only get avail ring entries after they have been * exposed by guest.
@@ -2700,6 +2701,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,return -EFAULT ; } + used->id = ring_head; head =vhost16_to_cpu (vq, ring_head);/* If their number is silly, that's an error. */
@@ -2787,10 +2789,17 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,/* Assume notifications from guest are disabled at this point, * if they aren't we would need to update avail_event index. */ BUG_ON (!(vq->used_flags &VRING_USED_F_NO_NOTIFY )); -return head; +return 0 ; }EXPORT_SYMBOL_GPL (vhost_get_vq_desc); +static void vhost_set_used_len (struct vhost_virtqueue *vq, +struct vring_used_elem *used,int len) +{ + used->len =cpu_to_vhost32 (vq, len); +} +EXPORT_SYMBOL_GPL (vhost_set_used_len); +static void vhost_withdraw_shadow_used (struct vhost_virtqueue *vq,int count) {BUG_ON (count > vq->nheads);
@@ -2860,17 +2869,17 @@ int vhost_get_zc_used_len(struct vhost_virtqueue *vq, int idx)EXPORT_SYMBOL_GPL (vhost_get_zc_used_len);void vhost_set_zc_used (struct vhost_virtqueue *vq, -int idx,unsigned int head,int len) +int idx,struct vring_used_elem *elem,int len) { - vq->heads[idx].id = head; - vq->heads[idx].len = len; + vq->heads[idx] = *elem; +vhost_set_zc_used_len (vq, idx, len); }EXPORT_SYMBOL_GPL (vhost_set_zc_used);void vhost_add_shadow_used (struct vhost_virtqueue *vq, -unsigned int head,int len) +struct vring_used_elem *elem,int len) { -vhost_set_zc_used (vq, vq->nheads, head, len); +vhost_set_zc_used (vq, vq->nheads, elem, len); ++vq->nheads; }EXPORT_SYMBOL_GPL (vhost_add_shadow_used);
@@ -2921,14 +2930,11 @@ EXPORT_SYMBOL_GPL(vhost_add_used_n);/* After we've used one of their buffers, we tell them about it. We'll then * want to notify the guest, using eventfd. */ -int vhost_add_used (struct vhost_virtqueue *vq,unsigned int head,int len) +int vhost_add_used (struct vhost_virtqueue *vq,struct vring_used_elem *used, +int len) { -struct vring_used_elem heads = { -cpu_to_vhost32 (vq, head), -cpu_to_vhost32 (vq, len) - }; - -return vhost_add_used_n (vq, &heads,1 ); +vhost_set_used_len (vq, used, len); +return vhost_add_used_n (vq, used,1 ); }EXPORT_SYMBOL_GPL (vhost_add_used);
@@ -2981,9 +2987,9 @@ EXPORT_SYMBOL_GPL(vhost_signal);/* And here's the combo meal deal. Supersize me! */ void vhost_add_used_and_signal (struct vhost_dev *dev,struct vhost_virtqueue *vq, -unsigned int head,int len) +struct vring_used_elem *used,int len) { -vhost_add_used (vq, head, len); +vhost_add_used (vq, used, len);vhost_signal (dev, vq); }EXPORT_SYMBOL_GPL (vhost_add_used_and_signal);
drivers/vhost/vhost.h +6 -5
@@ -233,16 +233,17 @@ 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);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 *,struct vring_used_elem *,int );void vhost_add_used_and_signal (struct vhost_dev *,struct vhost_virtqueue *, -unsigned int id,int len); +struct vring_used_elem *,int );/* Zerocopy shadow used ring API */ void vhost_set_zc_used_len(struct vhost_virtqueue *vq,
@@ -250,11 +251,11 @@ void vhost_set_zc_used_len(struct vhost_virtqueue *vq,int vhost_get_zc_used_len (struct vhost_virtqueue *vq,int idx);void vhost_flush_zc_used_and_signal (struct vhost_virtqueue *vq,int idx,int n);void vhost_set_zc_used (struct vhost_virtqueue *vq,int idx, -unsigned int head,int len); +struct vring_used_elem *elem,int len);/* Non zerocopy shadow used ring API */ -void vhost_add_shadow_used (struct vhost_virtqueue *vq,unsigned int head, -int len); +void vhost_add_shadow_used (struct vhost_virtqueue *vq, +struct vring_used_elem *elem,int len);void vhost_flush_shadow_used_and_signal (struct vhost_virtqueue *vq);void vhost_discard_shadow_used (struct vhost_virtqueue *vq,int n);int vhost_get_shadow_used_count (struct vhost_virtqueue *vq);
drivers/vhost/vsock.c +21 -22
101 lines not on this page · raw message
Signature · 1 line
2.18.1
PATCH v3 10/15 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 | 88 ++++++++++++++++++++++--------------------- drivers/vhost/scsi.c | 62 ++++++++++++++++-------------- drivers/vhost/vhost.c | 38 +++++++++++-------- drivers/vhost/vhost.h | 11 +++--- drivers/vhost/vsock.c | 43 +++++++++++---------- 5 files changed, 129 insertions(+), 113 deletions(-)
drivers/vhost/net.c +46 -42
@@ -546,25 +546,28 @@ static void vhost_net_busy_poll(struct vhost_net *net, }static int vhost_net_tx_get_vq_desc (struct vhost_net *net, -struct vhost_net_virtqueue *tnvq, +struct vring_used_elem *used_elem,unsigned int *out_num,unsigned int *in_num,struct msghdr *msghdr,bool *busyloop_intr) { +struct vhost_net_virtqueue *tnvq = &net->vqs[VHOST_NET_VQ_TX ];struct vhost_net_virtqueue *rnvq = &net->vqs[VHOST_NET_VQ_RX ];struct vhost_virtqueue *rvq = &rnvq->vq;struct vhost_virtqueue *tvq = &tnvq->vq; -int r =vhost_get_vq_desc (tvq, tvq->iov,ARRAY_SIZE (tvq->iov), +int r =vhost_get_vq_desc (tvq, used_elem, tvq->iov, +ARRAY_SIZE (tvq->iov), out_num, in_num,NULL ,NULL ); -if (r == tvq->num && tvq->busyloop_timeout) { +if (r == -ENOSPC && tvq->busyloop_timeout) {/* Flush batched packets first */ if (!vhost_sock_zcopy (tvq->private_data))vhost_tx_batch (net, tnvq, tvq->private_data, msghdr);vhost_net_busy_poll (net, rvq, tvq, busyloop_intr, false); - r =vhost_get_vq_desc (tvq, tvq->iov,ARRAY_SIZE (tvq->iov), + r =vhost_get_vq_desc (tvq, used_elem, tvq->iov, +ARRAY_SIZE (tvq->iov), out_num, in_num,NULL ,NULL ); }
@@ -593,6 +596,7 @@ static size_t init_iov_iter(struct vhost_virtqueue *vq, struct iov_iter *iter, } static int get_tx_bufs(struct vhost_net *net, + struct vring_used_elem *used_elem, struct vhost_net_virtqueue *nvq, struct msghdr *msg, unsigned int *out, unsigned int *in,
@@ -601,9 +605,10 @@ static int get_tx_bufs(struct vhost_net *net,struct vhost_virtqueue *vq = &nvq->vq;int ret; - ret =vhost_net_tx_get_vq_desc (net, nvq, out, in, msg, busyloop_intr); + ret =vhost_net_tx_get_vq_desc (net, used_elem, out, in, + msg, busyloop_intr); -if (ret <0 || ret == vq->num) +if (ret <0 || ret == -ENOSPC )return ret;if (*in) {
@@ -747,8 +752,8 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock) {struct vhost_net_virtqueue *nvq = &net->vqs[VHOST_NET_VQ_TX ];struct vhost_virtqueue *vq = &nvq->vq; +struct vring_used_elem used;unsigned out, in; -int head;struct msghdr msg = { .msg_name =NULL , .msg_namelen =0 ,
@@ -767,13 +772,11 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock)if (vhost_get_shadow_used_count (vq) ==VHOST_NET_BATCH )vhost_tx_batch (net, nvq, sock, &msg); - head =get_tx_bufs (net, nvq, &msg, &out, &in, &len, - &busyloop_intr); -/* On error, stop handling until the next kick. */ -if (unlikely (head <0 )) -break ; + err =get_tx_bufs (net, &used, + nvq, &msg, &out, &in, &len, + &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 (vq))) {
@@ -782,7 +785,9 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock) }break ; } - +/* On error, stop handling until the next kick. */ +if (unlikely (err <0 )) +break ; total_len += len;/* For simplicity, TX batching is only enabled if
@@ -823,7 +828,7 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock)pr_debug ("Truncated TX packet: len %d != %zd\n" , err, len); done: -vhost_add_shadow_used (vq,cpu_to_vhost32 (vq, head),0 ); +vhost_add_shadow_used (vq, &used,0 ); }while (likely (!vhost_exceeds_weight (vq, ++sent_pkts, total_len)));vhost_tx_batch (net, nvq, sock, &msg);
@@ -834,7 +839,6 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)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 ,
@@ -843,6 +847,7 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock) .msg_flags = MSG_DONTWAIT, };struct tun_msg_ctl ctl; +struct vring_used_elem used;size_t len, total_len =0 ;int err;struct vhost_net_ubuf_ref *uninitialized_var (ubufs );
@@ -856,13 +861,10 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)vhost_zerocopy_signal_used (net, vq); busyloop_intr = false; - head =get_tx_bufs (net, nvq, &msg, &out, &in, &len, - &busyloop_intr); -/* On error, stop handling until the next kick. */ -if (unlikely (head <0 )) -break ; + err =get_tx_bufs (net, &used, nvq, &msg, &out, &in, &len, + &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 (vq))) {
@@ -871,6 +873,9 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock) }break ; } +/* On error, stop handling until the next kick. */ +if (unlikely (err <0 )) +break ; zcopy_used = len >=VHOST_GOODCOPY_LEN && !vhost_exceeds_maxpend (net)
@@ -895,7 +900,7 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock) ubufs =NULL ; }vhost_set_zc_used (vq, nvq->upend_idx, -cpu_to_vhost32 (vq, head), + &used, zcopy_used ?VHOST_DMA_IN_PROGRESS :VHOST_DMA_DONE_LEN ); nvq->upend_idx = (nvq->upend_idx +1 ) %UIO_MAXIOV ;
@@ -921,7 +926,6 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)if (err != len)pr_debug ("Truncated TX packet: " " len %d != %zd\n" , err, len); -vhost_zerocopy_signal_used (net, vq);vhost_net_tx_packet (net); }while (likely (!vhost_exceeds_weight (vq, ++sent_pkts, total_len)));
@@ -1012,34 +1016,30 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,unsigned *iovcount, struct vhost_log *log, unsigned *log_num, - unsigned int quota) + unsigned int quota, + s16 *count) { unsigned int out, in;int seg =0 ;int headcount =0 ; -unsigned d; -int r, nlogs =0 ; +int r =0 , nlogs =0 ;/* len is always initialized before use since we are always called with * datalen > 0. */ u32 uninitialized_var (len ); +struct vring_used_elem uninitialized_var (used );while (datalen >0 && headcount < quota) {if (unlikely (seg >=UIO_MAXIOV )) { r = -ENOBUFS ; goto err; } - r =vhost_get_vq_desc (vq, vq->iov + seg, + r =vhost_get_vq_desc (vq, &used, 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);
@@ -1052,7 +1052,7 @@ static int get_rx_bufs(struct vhost_virtqueue *vq, } len =iov_length (vq->iov + seg, in); datalen -= len; -vhost_add_shadow_used (vq,cpu_to_vhost32 (vq, d), +vhost_add_shadow_used (vq, &used,cpu_to_vhost32 (vq, datalen >=0 ? len : len + datalen)); ++headcount;
@@ -1064,12 +1064,15 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,/* Detect overrun */ if (unlikely (datalen >0 )) { - r =UIO_MAXIOV +1 ; + headcount =UIO_MAXIOV +1 ; goto err; } -return headcount; + + *count = headcount; +return 0 ; err:vhost_discard_shadow_used (vq, headcount); + *count =0 ;return r; }
@@ -1128,13 +1131,11 @@ static void handle_rx(struct vhost_net *net)break ; sock_len += sock_hlen; vhost_len = sock_len + vhost_hlen; - headcount =get_rx_bufs (vq, 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 =get_rx_bufs (vq, 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 (vq))) {
@@ -1148,6 +1149,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 +34 -28
173 lines not on this page · raw message
drivers/vhost/vhost.c +22 -16
@@ -2651,6 +2651,7 @@ static int get_indirect(struct vhost_virtqueue *vq,* never a valid descriptor number) if none was found. A negative code is * returned on error. */ int vhost_get_vq_desc (struct vhost_virtqueue *vq, +struct vring_used_elem *used,struct iovec iov[],unsigned int iov_size,unsigned int *out_num,unsigned int *in_num,struct vhost_log *log,unsigned int *log_num)
@@ -2683,7 +2684,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,* invalid. */ if (vq->avail_idx == last_avail_idx) -return vq->num; +return -ENOSPC ;/* Only get avail ring entries after they have been * exposed by guest.
@@ -2700,6 +2701,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,return -EFAULT ; } + used->id = ring_head; head =vhost16_to_cpu (vq, ring_head);/* If their number is silly, that's an error. */
@@ -2787,10 +2789,17 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,/* Assume notifications from guest are disabled at this point, * if they aren't we would need to update avail_event index. */ BUG_ON (!(vq->used_flags &VRING_USED_F_NO_NOTIFY )); -return head; +return 0 ; }EXPORT_SYMBOL_GPL (vhost_get_vq_desc); +static void vhost_set_used_len (struct vhost_virtqueue *vq, +struct vring_used_elem *used,int len) +{ + used->len =cpu_to_vhost32 (vq, len); +} +EXPORT_SYMBOL_GPL (vhost_set_used_len); +static void vhost_withdraw_shadow_used (struct vhost_virtqueue *vq,int count) {BUG_ON (count > vq->nheads);
@@ -2860,17 +2869,17 @@ int vhost_get_zc_used_len(struct vhost_virtqueue *vq, int idx)EXPORT_SYMBOL_GPL (vhost_get_zc_used_len);void vhost_set_zc_used (struct vhost_virtqueue *vq, -int idx,unsigned int head,int len) +int idx,struct vring_used_elem *elem,int len) { - vq->heads[idx].id = head; - vq->heads[idx].len = len; + vq->heads[idx] = *elem; +vhost_set_zc_used_len (vq, idx, len); }EXPORT_SYMBOL_GPL (vhost_set_zc_used);void vhost_add_shadow_used (struct vhost_virtqueue *vq, -unsigned int head,int len) +struct vring_used_elem *elem,int len) { -vhost_set_zc_used (vq, vq->nheads, head, len); +vhost_set_zc_used (vq, vq->nheads, elem, len); ++vq->nheads; }EXPORT_SYMBOL_GPL (vhost_add_shadow_used);
@@ -2921,14 +2930,11 @@ EXPORT_SYMBOL_GPL(vhost_add_used_n);/* After we've used one of their buffers, we tell them about it. We'll then * want to notify the guest, using eventfd. */ -int vhost_add_used (struct vhost_virtqueue *vq,unsigned int head,int len) +int vhost_add_used (struct vhost_virtqueue *vq,struct vring_used_elem *used, +int len) { -struct vring_used_elem heads = { -cpu_to_vhost32 (vq, head), -cpu_to_vhost32 (vq, len) - }; - -return vhost_add_used_n (vq, &heads,1 ); +vhost_set_used_len (vq, used, len); +return vhost_add_used_n (vq, used,1 ); }EXPORT_SYMBOL_GPL (vhost_add_used);
@@ -2981,9 +2987,9 @@ EXPORT_SYMBOL_GPL(vhost_signal);/* And here's the combo meal deal. Supersize me! */ void vhost_add_used_and_signal (struct vhost_dev *dev,struct vhost_virtqueue *vq, -unsigned int head,int len) +struct vring_used_elem *used,int len) { -vhost_add_used (vq, head, len); +vhost_add_used (vq, used, len);vhost_signal (dev, vq); }EXPORT_SYMBOL_GPL (vhost_add_used_and_signal);
drivers/vhost/vhost.h +6 -5
@@ -233,16 +233,17 @@ 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);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 *,struct vring_used_elem *,int );void vhost_add_used_and_signal (struct vhost_dev *,struct vhost_virtqueue *, -unsigned int id,int len); +struct vring_used_elem *,int );/* Zerocopy shadow used ring API */ void vhost_set_zc_used_len(struct vhost_virtqueue *vq,
@@ -250,11 +251,11 @@ void vhost_set_zc_used_len(struct vhost_virtqueue *vq,int vhost_get_zc_used_len (struct vhost_virtqueue *vq,int idx);void vhost_flush_zc_used_and_signal (struct vhost_virtqueue *vq,int idx,int n);void vhost_set_zc_used (struct vhost_virtqueue *vq,int idx, -unsigned int head,int len); +struct vring_used_elem *elem,int len);/* Non zerocopy shadow used ring API */ -void vhost_add_shadow_used (struct vhost_virtqueue *vq,unsigned int head, -int len); +void vhost_add_shadow_used (struct vhost_virtqueue *vq, +struct vring_used_elem *elem,int len);void vhost_flush_shadow_used_and_signal (struct vhost_virtqueue *vq);void vhost_discard_shadow_used (struct vhost_virtqueue *vq,int n);int vhost_get_shadow_used_count (struct vhost_virtqueue *vq);
drivers/vhost/vsock.c +21 -22
101 lines not on this page · raw message
Signature · 1 line
2.18.1
PATCH v3 11/15 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 | 10 +++++----- drivers/vhost/scsi.c | 8 ++++---- drivers/vhost/vhost.c | 38 +++++++++++++++++++++++--------------- drivers/vhost/vhost.h | 21 +++++++++++++++------ drivers/vhost/vsock.c | 4 ++-- 5 files changed, 49 insertions(+), 32 deletions(-)
drivers/vhost/net.c +5 -5
@@ -546,7 +546,7 @@ static void vhost_net_busy_poll(struct vhost_net *net, }static int vhost_net_tx_get_vq_desc (struct vhost_net *net, -struct vring_used_elem *used_elem, +struct vhost_used_elem *used_elem,unsigned int *out_num,unsigned int *in_num,struct msghdr *msghdr,bool *busyloop_intr) {
@@ -596,7 +596,7 @@ static size_t init_iov_iter(struct vhost_virtqueue *vq, struct iov_iter *iter, } static int get_tx_bufs(struct vhost_net *net, - struct vring_used_elem *used_elem, + struct vhost_used_elem *used_elem, struct vhost_net_virtqueue *nvq, struct msghdr *msg, unsigned int *out, unsigned int *in,
@@ -752,7 +752,7 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock) {struct vhost_net_virtqueue *nvq = &net->vqs[VHOST_NET_VQ_TX ];struct vhost_virtqueue *vq = &nvq->vq; -struct vring_used_elem used; +struct vhost_used_elem used;unsigned out, in;struct msghdr msg = { .msg_name =NULL ,
@@ -847,7 +847,7 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock) .msg_flags = MSG_DONTWAIT, };struct tun_msg_ctl ctl; -struct vring_used_elem used; +struct vhost_used_elem used;size_t len, total_len =0 ;int err;struct vhost_net_ubuf_ref *uninitialized_var (ubufs );
@@ -1027,7 +1027,7 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,* datalen > 0. */ u32 uninitialized_var (len ); -struct vring_used_elem uninitialized_var (used ); +struct vhost_used_elem uninitialized_var (used );while (datalen >0 && headcount < quota) {if (unlikely (seg >=UIO_MAXIOV )) {
drivers/vhost/scsi.c +4 -4
@@ -72,7 +72,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 */
@@ -213,7 +213,7 @@ struct vhost_scsi {* Context for processing request and control queue operations. */ struct vhost_scsi_ctx { -struct vring_used_elem head; +struct vhost_used_elem head;unsigned int out, in;size_t req_size, rsp_size;size_t out_size, in_size;
@@ -449,7 +449,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;
@@ -821,7 +821,7 @@ vhost_scsi_get_desc(struct vhost_scsi *vs, struct vhost_virtqueue *vq, NULL, NULL);pr_debug ("vhost_get_vq_desc: head: %d, out: %u in: %u\n" , - vc->head.id, vc->out, vc->in); + vc->head.elem.id, vc->out, vc->in);/* Nothing new? Wait for eventfd to tell us they refilled. */ if (ret == -ENOSPC ) {
drivers/vhost/vhost.c +23 -15
@@ -2651,7 +2651,7 @@ static int get_indirect(struct vhost_virtqueue *vq,* never a valid descriptor number) if none was found. A negative code is * returned on error. */ int vhost_get_vq_desc (struct vhost_virtqueue *vq, -struct vring_used_elem *used, +struct vhost_used_elem *used,struct iovec iov[],unsigned int iov_size,unsigned int *out_num,unsigned int *in_num,struct vhost_log *log,unsigned int *log_num)
@@ -2701,7 +2701,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,return -EFAULT ; } - used->id = ring_head; + used->elem.id = ring_head; head =vhost16_to_cpu (vq, ring_head);/* If their number is silly, that's an error. */
@@ -2793,13 +2793,20 @@ 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 vring_used_elem *used,int len) +void vhost_set_used_len (struct vhost_virtqueue *vq, +struct vhost_used_elem *used,int len) { - used->len =cpu_to_vhost32 (vq, len); + used->elem.len =cpu_to_vhost32 (vq, len); }EXPORT_SYMBOL_GPL (vhost_set_used_len); +__virtio32 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); +static void vhost_withdraw_shadow_used (struct vhost_virtqueue *vq,int count) {BUG_ON (count > vq->nheads);
@@ -2824,9 +2831,10 @@ void vhost_discard_vq_desc(struct vhost_virtqueue *vq, int n)EXPORT_SYMBOL_GPL (vhost_discard_vq_desc);static int __vhost_add_used_n (struct vhost_virtqueue *vq, -struct vring_used_elem *heads, +struct vhost_used_elem *shadow,unsigned count) { +struct vring_used_elem *heads = (struct vring_used_elem *)shadow;struct vring_used_elem __user *used;u16 old, new;int start;
@@ -2858,18 +2866,18 @@ static int __vhost_add_used_n(struct vhost_virtqueue *vq,void vhost_set_zc_used_len (struct vhost_virtqueue *vq,int idx,int len) { - vq->heads[idx].len = len; + vq->heads[idx].elem.len = len; }EXPORT_SYMBOL_GPL (vhost_set_zc_used_len);int vhost_get_zc_used_len (struct vhost_virtqueue *vq,int idx) { -return vq->heads[idx].len; +return vq->heads[idx].elem.len; }EXPORT_SYMBOL_GPL (vhost_get_zc_used_len); -void vhost_set_zc_used (struct vhost_virtqueue *vq, -int idx,struct vring_used_elem *elem,int len) +void vhost_set_zc_used (struct vhost_virtqueue *vq,int idx, +struct vhost_used_elem *elem,int len) { vq->heads[idx] = *elem;vhost_set_zc_used_len (vq, idx, len);
@@ -2877,7 +2885,7 @@ void vhost_set_zc_used(struct vhost_virtqueue *vq,EXPORT_SYMBOL_GPL (vhost_set_zc_used);void vhost_add_shadow_used (struct vhost_virtqueue *vq, -struct vring_used_elem *elem,int len) +struct vhost_used_elem *elem,int len) {vhost_set_zc_used (vq, vq->nheads, elem, len); ++vq->nheads;
@@ -2893,7 +2901,7 @@ EXPORT_SYMBOL_GPL(vhost_get_shadow_used_count);/* After we've used one of their buffers, we tell them about it. We'll then * want to notify the guest, using eventfd. */ static int vhost_add_used_n (struct vhost_virtqueue *vq, -struct vring_used_elem *heads, +struct vhost_used_elem *heads,unsigned count) {int start, n, r;
@@ -2930,7 +2938,7 @@ EXPORT_SYMBOL_GPL(vhost_add_used_n);/* After we've used one of their buffers, we tell them about it. We'll then * want to notify the guest, using eventfd. */ -int vhost_add_used (struct vhost_virtqueue *vq,struct vring_used_elem *used, +int vhost_add_used (struct vhost_virtqueue *vq,struct vhost_used_elem *used,int len) {vhost_set_used_len (vq, used, len);
@@ -2987,7 +2995,7 @@ EXPORT_SYMBOL_GPL(vhost_signal);/* And here's the combo meal deal. Supersize me! */ void vhost_add_used_and_signal (struct vhost_dev *dev,struct vhost_virtqueue *vq, -struct vring_used_elem *used,int len) +struct vhost_used_elem *used,int len) {vhost_add_used (vq, used, len);vhost_signal (dev, vq);
@@ -2997,7 +3005,7 @@ EXPORT_SYMBOL_GPL(vhost_add_used_and_signal);/* multi-buffer version of vhost_add_used_and_signal */ static void vhost_add_used_and_signal_n (struct vhost_dev *dev,struct vhost_virtqueue *vq, -struct vring_used_elem *heads, +struct vhost_used_elem *heads,unsigned count) {vhost_add_used_n (vq, heads, count);
drivers/vhost/vhost.h +15 -6
@@ -37,6 +37,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);
@@ -162,7 +166,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;int nheads;/* Protected by virtqueue mutex. */ struct vhost_umem *umem;
@@ -233,17 +237,22 @@ 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);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 *,struct vring_used_elem *,int ); +int vhost_add_used (struct vhost_virtqueue *,struct vhost_used_elem *,int );void vhost_add_used_and_signal (struct vhost_dev *,struct vhost_virtqueue *, -struct vring_used_elem *,int ); +struct vhost_used_elem *,int ); + +__virtio32 vhost_get_used_len (struct vhost_virtqueue *vq, +struct vhost_used_elem *used); +void vhost_set_used_len (struct vhost_virtqueue *vq, +struct vhost_used_elem *used,int len);/* Zerocopy shadow used ring API */ void vhost_set_zc_used_len(struct vhost_virtqueue *vq,
@@ -251,11 +260,11 @@ void vhost_set_zc_used_len(struct vhost_virtqueue *vq,int vhost_get_zc_used_len (struct vhost_virtqueue *vq,int idx);void vhost_flush_zc_used_and_signal (struct vhost_virtqueue *vq,int idx,int n);void vhost_set_zc_used (struct vhost_virtqueue *vq,int idx, -struct vring_used_elem *elem,int len); +struct vhost_used_elem *elem,int len);/* Non zerocopy shadow used ring API */ void vhost_add_shadow_used (struct vhost_virtqueue *vq, -struct vring_used_elem *elem,int len); +struct vhost_used_elem *elem,int len);void vhost_flush_shadow_used_and_signal (struct vhost_virtqueue *vq);void vhost_discard_shadow_used (struct vhost_virtqueue *vq,int n);int vhost_get_shadow_used_count (struct vhost_virtqueue *vq);
drivers/vhost/vsock.c +2 -2
@@ -100,7 +100,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock, do { 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;
@@ -148,7 +148,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,break ; } - len =vhost32_to_cpu (vq, used.len); + len =vhost_get_used_len (&used);iov_iter_init (&iov_iter,READ , &vq->iov[out], in, len); nbytes =copy_to_iter (&pkt->hdr,sizeof (pkt->hdr), &iov_iter);
Signature · 1 line
2.18.1
PATCH v3 11/15 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 | 10 +++++----- drivers/vhost/scsi.c | 8 ++++---- drivers/vhost/vhost.c | 38 +++++++++++++++++++++++--------------- drivers/vhost/vhost.h | 21 +++++++++++++++------ drivers/vhost/vsock.c | 4 ++-- 5 files changed, 49 insertions(+), 32 deletions(-)
drivers/vhost/net.c +5 -5
@@ -546,7 +546,7 @@ static void vhost_net_busy_poll(struct vhost_net *net, }static int vhost_net_tx_get_vq_desc (struct vhost_net *net, -struct vring_used_elem *used_elem, +struct vhost_used_elem *used_elem,unsigned int *out_num,unsigned int *in_num,struct msghdr *msghdr,bool *busyloop_intr) {
@@ -596,7 +596,7 @@ static size_t init_iov_iter(struct vhost_virtqueue *vq, struct iov_iter *iter, } static int get_tx_bufs(struct vhost_net *net, - struct vring_used_elem *used_elem, + struct vhost_used_elem *used_elem, struct vhost_net_virtqueue *nvq, struct msghdr *msg, unsigned int *out, unsigned int *in,
@@ -752,7 +752,7 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock) {struct vhost_net_virtqueue *nvq = &net->vqs[VHOST_NET_VQ_TX ];struct vhost_virtqueue *vq = &nvq->vq; -struct vring_used_elem used; +struct vhost_used_elem used;unsigned out, in;struct msghdr msg = { .msg_name =NULL ,
@@ -847,7 +847,7 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock) .msg_flags = MSG_DONTWAIT, };struct tun_msg_ctl ctl; -struct vring_used_elem used; +struct vhost_used_elem used;size_t len, total_len =0 ;int err;struct vhost_net_ubuf_ref *uninitialized_var (ubufs );
@@ -1027,7 +1027,7 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,* datalen > 0. */ u32 uninitialized_var (len ); -struct vring_used_elem uninitialized_var (used ); +struct vhost_used_elem uninitialized_var (used );while (datalen >0 && headcount < quota) {if (unlikely (seg >=UIO_MAXIOV )) {
drivers/vhost/scsi.c +4 -4
@@ -72,7 +72,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 */
@@ -213,7 +213,7 @@ struct vhost_scsi {* Context for processing request and control queue operations. */ struct vhost_scsi_ctx { -struct vring_used_elem head; +struct vhost_used_elem head;unsigned int out, in;size_t req_size, rsp_size;size_t out_size, in_size;
@@ -449,7 +449,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;
@@ -821,7 +821,7 @@ vhost_scsi_get_desc(struct vhost_scsi *vs, struct vhost_virtqueue *vq, NULL, NULL);pr_debug ("vhost_get_vq_desc: head: %d, out: %u in: %u\n" , - vc->head.id, vc->out, vc->in); + vc->head.elem.id, vc->out, vc->in);/* Nothing new? Wait for eventfd to tell us they refilled. */ if (ret == -ENOSPC ) {
drivers/vhost/vhost.c +23 -15
@@ -2651,7 +2651,7 @@ static int get_indirect(struct vhost_virtqueue *vq,* never a valid descriptor number) if none was found. A negative code is * returned on error. */ int vhost_get_vq_desc (struct vhost_virtqueue *vq, -struct vring_used_elem *used, +struct vhost_used_elem *used,struct iovec iov[],unsigned int iov_size,unsigned int *out_num,unsigned int *in_num,struct vhost_log *log,unsigned int *log_num)
@@ -2701,7 +2701,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,return -EFAULT ; } - used->id = ring_head; + used->elem.id = ring_head; head =vhost16_to_cpu (vq, ring_head);/* If their number is silly, that's an error. */
@@ -2793,13 +2793,20 @@ 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 vring_used_elem *used,int len) +void vhost_set_used_len (struct vhost_virtqueue *vq, +struct vhost_used_elem *used,int len) { - used->len =cpu_to_vhost32 (vq, len); + used->elem.len =cpu_to_vhost32 (vq, len); }EXPORT_SYMBOL_GPL (vhost_set_used_len); +__virtio32 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); +static void vhost_withdraw_shadow_used (struct vhost_virtqueue *vq,int count) {BUG_ON (count > vq->nheads);
@@ -2824,9 +2831,10 @@ void vhost_discard_vq_desc(struct vhost_virtqueue *vq, int n)EXPORT_SYMBOL_GPL (vhost_discard_vq_desc);static int __vhost_add_used_n (struct vhost_virtqueue *vq, -struct vring_used_elem *heads, +struct vhost_used_elem *shadow,unsigned count) { +struct vring_used_elem *heads = (struct vring_used_elem *)shadow;struct vring_used_elem __user *used;u16 old, new;int start;
@@ -2858,18 +2866,18 @@ static int __vhost_add_used_n(struct vhost_virtqueue *vq,void vhost_set_zc_used_len (struct vhost_virtqueue *vq,int idx,int len) { - vq->heads[idx].len = len; + vq->heads[idx].elem.len = len; }EXPORT_SYMBOL_GPL (vhost_set_zc_used_len);int vhost_get_zc_used_len (struct vhost_virtqueue *vq,int idx) { -return vq->heads[idx].len; +return vq->heads[idx].elem.len; }EXPORT_SYMBOL_GPL (vhost_get_zc_used_len); -void vhost_set_zc_used (struct vhost_virtqueue *vq, -int idx,struct vring_used_elem *elem,int len) +void vhost_set_zc_used (struct vhost_virtqueue *vq,int idx, +struct vhost_used_elem *elem,int len) { vq->heads[idx] = *elem;vhost_set_zc_used_len (vq, idx, len);
@@ -2877,7 +2885,7 @@ void vhost_set_zc_used(struct vhost_virtqueue *vq,EXPORT_SYMBOL_GPL (vhost_set_zc_used);void vhost_add_shadow_used (struct vhost_virtqueue *vq, -struct vring_used_elem *elem,int len) +struct vhost_used_elem *elem,int len) {vhost_set_zc_used (vq, vq->nheads, elem, len); ++vq->nheads;
@@ -2893,7 +2901,7 @@ EXPORT_SYMBOL_GPL(vhost_get_shadow_used_count);/* After we've used one of their buffers, we tell them about it. We'll then * want to notify the guest, using eventfd. */ static int vhost_add_used_n (struct vhost_virtqueue *vq, -struct vring_used_elem *heads, +struct vhost_used_elem *heads,unsigned count) {int start, n, r;
@@ -2930,7 +2938,7 @@ EXPORT_SYMBOL_GPL(vhost_add_used_n);/* After we've used one of their buffers, we tell them about it. We'll then * want to notify the guest, using eventfd. */ -int vhost_add_used (struct vhost_virtqueue *vq,struct vring_used_elem *used, +int vhost_add_used (struct vhost_virtqueue *vq,struct vhost_used_elem *used,int len) {vhost_set_used_len (vq, used, len);
@@ -2987,7 +2995,7 @@ EXPORT_SYMBOL_GPL(vhost_signal);/* And here's the combo meal deal. Supersize me! */ void vhost_add_used_and_signal (struct vhost_dev *dev,struct vhost_virtqueue *vq, -struct vring_used_elem *used,int len) +struct vhost_used_elem *used,int len) {vhost_add_used (vq, used, len);vhost_signal (dev, vq);
@@ -2997,7 +3005,7 @@ EXPORT_SYMBOL_GPL(vhost_add_used_and_signal);/* multi-buffer version of vhost_add_used_and_signal */ static void vhost_add_used_and_signal_n (struct vhost_dev *dev,struct vhost_virtqueue *vq, -struct vring_used_elem *heads, +struct vhost_used_elem *heads,unsigned count) {vhost_add_used_n (vq, heads, count);
drivers/vhost/vhost.h +15 -6
@@ -37,6 +37,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);
@@ -162,7 +166,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;int nheads;/* Protected by virtqueue mutex. */ struct vhost_umem *umem;
@@ -233,17 +237,22 @@ 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);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 *,struct vring_used_elem *,int ); +int vhost_add_used (struct vhost_virtqueue *,struct vhost_used_elem *,int );void vhost_add_used_and_signal (struct vhost_dev *,struct vhost_virtqueue *, -struct vring_used_elem *,int ); +struct vhost_used_elem *,int ); + +__virtio32 vhost_get_used_len (struct vhost_virtqueue *vq, +struct vhost_used_elem *used); +void vhost_set_used_len (struct vhost_virtqueue *vq, +struct vhost_used_elem *used,int len);/* Zerocopy shadow used ring API */ void vhost_set_zc_used_len(struct vhost_virtqueue *vq,
@@ -251,11 +260,11 @@ void vhost_set_zc_used_len(struct vhost_virtqueue *vq,int vhost_get_zc_used_len (struct vhost_virtqueue *vq,int idx);void vhost_flush_zc_used_and_signal (struct vhost_virtqueue *vq,int idx,int n);void vhost_set_zc_used (struct vhost_virtqueue *vq,int idx, -struct vring_used_elem *elem,int len); +struct vhost_used_elem *elem,int len);/* Non zerocopy shadow used ring API */ void vhost_add_shadow_used (struct vhost_virtqueue *vq, -struct vring_used_elem *elem,int len); +struct vhost_used_elem *elem,int len);void vhost_flush_shadow_used_and_signal (struct vhost_virtqueue *vq);void vhost_discard_shadow_used (struct vhost_virtqueue *vq,int n);int vhost_get_shadow_used_count (struct vhost_virtqueue *vq);
drivers/vhost/vsock.c +2 -2
@@ -100,7 +100,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock, do { 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;
@@ -148,7 +148,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,break ; } - len =vhost32_to_cpu (vq, used.len); + len =vhost_get_used_len (&used);iov_iter_init (&iov_iter,READ , &vq->iov[out], in, len); nbytes =copy_to_iter (&pkt->hdr,sizeof (pkt->hdr), &iov_iter);
Signature · 1 line
2.18.1
PATCH v3 12/15 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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/vhost/vhost.c +5 -5
@@ -1178,7 +1178,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) { \
@@ -1186,7 +1186,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 \
@@ -1230,7 +1230,7 @@ static inline int vhost_put_avail_event(struct vhost_virtqueue *vq)#endif return vhost_put_user (vq,cpu_to_vhost16 (vq, vq->avail_idx), -vhost_avail_event (vq)); +vhost_avail_event (vq),VHOST_ADDR_USED ); } static inline int vhost_put_used(struct vhost_virtqueue *vq,
@@ -1267,7 +1267,7 @@ static inline int vhost_put_used_flags(struct vhost_virtqueue *vq)#endif return vhost_put_user (vq,cpu_to_vhost16 (vq, vq->used_flags), - &vq->used->flags); + &vq->used->flags,VHOST_ADDR_USED ); }static inline int vhost_put_used_idx (struct vhost_virtqueue *vq)
@@ -1284,7 +1284,7 @@ static inline int vhost_put_used_idx(struct vhost_virtqueue *vq)#endif return vhost_put_user (vq,cpu_to_vhost16 (vq, vq->last_used_idx), - &vq->used->idx); + &vq->used->idx,VHOST_ADDR_USED ); }#define vhost_get_user (vq, x, ptr, type) \
Signature · 1 line
2.18.1
PATCH v3 12/15 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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/vhost/vhost.c +5 -5
@@ -1178,7 +1178,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) { \
@@ -1186,7 +1186,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 \
@@ -1230,7 +1230,7 @@ static inline int vhost_put_avail_event(struct vhost_virtqueue *vq)#endif return vhost_put_user (vq,cpu_to_vhost16 (vq, vq->avail_idx), -vhost_avail_event (vq)); +vhost_avail_event (vq),VHOST_ADDR_USED ); } static inline int vhost_put_used(struct vhost_virtqueue *vq,
@@ -1267,7 +1267,7 @@ static inline int vhost_put_used_flags(struct vhost_virtqueue *vq)#endif return vhost_put_user (vq,cpu_to_vhost16 (vq, vq->used_flags), - &vq->used->flags); + &vq->used->flags,VHOST_ADDR_USED ); }static inline int vhost_put_used_idx (struct vhost_virtqueue *vq)
@@ -1284,7 +1284,7 @@ static inline int vhost_put_used_idx(struct vhost_virtqueue *vq)#endif return vhost_put_user (vq,cpu_to_vhost16 (vq, vq->last_used_idx), - &vq->used->idx); + &vq->used->idx,VHOST_ADDR_USED ); }#define vhost_get_user (vq, x, ptr, type) \
Signature · 1 line
2.18.1
PATCH v3 13/15 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 | 6 +- drivers/vhost/vhost.c | 980 ++++++++++++++++++++++++++++++++++++++---- drivers/vhost/vhost.h | 24 +- 3 files changed, 925 insertions(+), 85 deletions(-)
drivers/vhost/net.c +3 -3
@@ -799,7 +799,7 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock) goto done; }else if (unlikely (err != -ENOSPC )) {vhost_tx_batch (net, nvq, sock, &msg); -vhost_discard_vq_desc (vq,1 ); +vhost_discard_vq_desc (vq, &used);vhost_net_enable_vq (net, vq);break ; }
@@ -820,7 +820,7 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock)/* TODO: Check specific error and bomb out unless ENOBUFS? */ err = sock->ops->sendmsg (sock, &msg, len);if (unlikely (err <0 )) { -vhost_discard_vq_desc (vq,1 ); +vhost_discard_vq_desc (vq, &used);vhost_net_enable_vq (net, vq);break ; }
@@ -919,7 +919,7 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)vhost_net_ubuf_put (ubufs); nvq->upend_idx = ((unsigned int )nvq->upend_idx -1 ) %UIO_MAXIOV ; -vhost_discard_vq_desc (vq,1 ); +vhost_discard_vq_desc (vq, &used);vhost_net_enable_vq (net, vq);break ; }
drivers/vhost/vhost.c +902 -78
1,215 lines not on this page · raw message
drivers/vhost/vhost.h +20 -4
@@ -37,8 +37,17 @@ struct vhost_poll {struct vhost_dev *dev; }; +struct vring_packed_used_elem { +__u16 id; +__u16 count; +__u32 len; +}; +struct vhost_used_elem { -struct vring_used_elem elem; +union { +struct vring_used_elem elem; +struct vring_packed_used_elem packed_elem; + }; };void vhost_work_init (struct vhost_work *work,vhost_work_fn_t fn);
@@ -112,7 +121,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;
@@ -166,7 +178,7 @@ struct vhost_virtqueue {struct iovec iov[UIO_MAXIOV ];struct iovec iotlb_iov[64 ];struct iovec *indirect; -struct vhost_used_elem *heads; +void *heads;int nheads;/* Protected by virtqueue mutex. */ struct vhost_umem *umem;
@@ -188,6 +200,9 @@ struct vhost_virtqueue {u32 busyloop_timeout;spinlock_t mmu_lock;int invalidate_count; +bool last_used_wrap_counter; +bool avail_wrap_counter; +bool last_avail_wrap_counter; };struct vhost_msg_node {
@@ -241,7 +256,8 @@ 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); -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 vhost_vq_init_access (struct vhost_virtqueue *);int vhost_add_used (struct vhost_virtqueue *,struct vhost_used_elem *,int );
Signature · 1 line
2.18.1
PATCH v3 13/15 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 | 6 +- drivers/vhost/vhost.c | 980 ++++++++++++++++++++++++++++++++++++++---- drivers/vhost/vhost.h | 24 +- 3 files changed, 925 insertions(+), 85 deletions(-)
drivers/vhost/net.c +3 -3
@@ -799,7 +799,7 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock) goto done; }else if (unlikely (err != -ENOSPC )) {vhost_tx_batch (net, nvq, sock, &msg); -vhost_discard_vq_desc (vq,1 ); +vhost_discard_vq_desc (vq, &used);vhost_net_enable_vq (net, vq);break ; }
@@ -820,7 +820,7 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock)/* TODO: Check specific error and bomb out unless ENOBUFS? */ err = sock->ops->sendmsg (sock, &msg, len);if (unlikely (err <0 )) { -vhost_discard_vq_desc (vq,1 ); +vhost_discard_vq_desc (vq, &used);vhost_net_enable_vq (net, vq);break ; }
@@ -919,7 +919,7 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)vhost_net_ubuf_put (ubufs); nvq->upend_idx = ((unsigned int )nvq->upend_idx -1 ) %UIO_MAXIOV ; -vhost_discard_vq_desc (vq,1 ); +vhost_discard_vq_desc (vq, &used);vhost_net_enable_vq (net, vq);break ; }
drivers/vhost/vhost.c +902 -78
1,215 lines not on this page · raw message
drivers/vhost/vhost.h +20 -4
@@ -37,8 +37,17 @@ struct vhost_poll {struct vhost_dev *dev; }; +struct vring_packed_used_elem { +__u16 id; +__u16 count; +__u32 len; +}; +struct vhost_used_elem { -struct vring_used_elem elem; +union { +struct vring_used_elem elem; +struct vring_packed_used_elem packed_elem; + }; };void vhost_work_init (struct vhost_work *work,vhost_work_fn_t fn);
@@ -112,7 +121,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;
@@ -166,7 +178,7 @@ struct vhost_virtqueue {struct iovec iov[UIO_MAXIOV ];struct iovec iotlb_iov[64 ];struct iovec *indirect; -struct vhost_used_elem *heads; +void *heads;int nheads;/* Protected by virtqueue mutex. */ struct vhost_umem *umem;
@@ -188,6 +200,9 @@ struct vhost_virtqueue {u32 busyloop_timeout;spinlock_t mmu_lock;int invalidate_count; +bool last_used_wrap_counter; +bool avail_wrap_counter; +bool last_avail_wrap_counter; };struct vhost_msg_node {
@@ -241,7 +256,8 @@ 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); -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 vhost_vq_init_access (struct vhost_virtqueue *);int vhost_add_used (struct vhost_virtqueue *,struct vhost_used_elem *,int );
Signature · 1 line
2.18.1
PATCH v3 14/15 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 | 265 +++++++++++++++++++++++++++++++++++++++--- drivers/vhost/vhost.h | 11 +- 2 files changed, 255 insertions(+), 21 deletions(-)
drivers/vhost/vhost.c +247 -18
@@ -1524,6 +1524,76 @@ static inline int vhost_put_desc_flags(struct vhost_virtqueue *vq,return vhost_put_user (vq, *flags, &desc->flags,VHOST_ADDR_DESC ); } +static int vhost_get_driver_off_wrap (struct vhost_virtqueue *vq, +__virtio16 *off_wrap) +{ +#if VHOST_ARCH_CAN_ACCEL_UACCESS +struct vring_packed_desc_event *event = +vhost_get_meta_ptr (vq,VHOST_ADDR_AVAIL ); +if (likely (event)) { + *off_wrap = event->off_wrap; +vhost_put_meta_ptr (); +return 0 ; + } +#endif +return vhost_get_user (vq, *off_wrap, + &vq->driver_event->off_wrap, +VHOST_ADDR_AVAIL ); +} + +static int vhost_get_driver_flags (struct vhost_virtqueue *vq, +__virtio16 *driver_flags) +{ +#if VHOST_ARCH_CAN_ACCEL_UACCESS +struct vring_packed_desc_event *event = +vhost_get_meta_ptr (vq,VHOST_ADDR_AVAIL ); + +if (likely (event)) { + *driver_flags = event->flags; +vhost_put_meta_ptr (); +return 0 ; + } +#endif +return vhost_get_user (vq, *driver_flags, &vq->driver_event->flags, +VHOST_ADDR_AVAIL ); +} + +static int vhost_put_device_off_wrap (struct vhost_virtqueue *vq, +__virtio16 *off_wrap) +{ +#if VHOST_ARCH_CAN_ACCEL_UACCESS +struct vring_packed_desc_event *event = +vhost_get_meta_ptr (vq,VHOST_ADDR_USED ); + +if (likely (event)) { + event->off_wrap = *off_wrap; +vhost_put_meta_ptr (); +return 0 ; + } +#endif +return vhost_put_user (vq, *off_wrap, + &vq->device_event->off_wrap, +VHOST_ADDR_USED ); +} + +static int vhost_put_device_flags (struct vhost_virtqueue *vq, +__virtio16 *device_flags) +{ +#if VHOST_ARCH_CAN_ACCEL_UACCESS +struct vring_packed_desc_event *event = +vhost_get_meta_ptr (vq,VHOST_ADDR_USED ); + +if (likely (event)) { + event->flags = *device_flags; +vhost_put_meta_ptr (); +return 0 ; + } +#endif +return vhost_put_user (vq, *device_flags, + &vq->device_event->flags, +VHOST_ADDR_USED ); +} +static int vhost_new_umem_range (struct vhost_umem *umem,u64 start,u64 size,u64 end,u64 userspace_addr,int perm)
@@ -1809,10 +1879,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 (packed, num *sizeof (*packed)) && -access_ok (packed, num *sizeof (*packed)); +access_ok (packed, num *sizeof (*packed)) && +access_ok (driver_event,sizeof (*driver_event)) && +access_ok (device_event,sizeof (*device_event)); } static int vq_access_ok_split(struct vhost_virtqueue *vq, unsigned int num,
@@ -1904,16 +1979,25 @@ static void vhost_vq_map_prefetch(struct vhost_virtqueue *vq) }#endif -int vq_meta_prefetch (struct vhost_virtqueue *vq) +static int vq_iotlb_prefetch_packed (struct vhost_virtqueue *vq) { -unsigned int num = vq->num; +int num = vq->num; -if (!vq->iotlb) { -#if VHOST_ARCH_CAN_ACCEL_UACCESS -vhost_vq_map_prefetch (vq); -#endif -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_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 ); +} + +static int vq_iotlb_prefetch_split (struct vhost_virtqueue *vq) +{ +unsigned int num = vq->num; return iotlb_access_ok(vq, VHOST_ACCESS_RO, (u64)(uintptr_t)vq->desc,
@@ -1928,6 +2012,21 @@ int vq_meta_prefetch(struct vhost_virtqueue *vq)vhost_get_used_size (vq, num), VHOST_ADDR_USED); } + +int vq_meta_prefetch (struct vhost_virtqueue *vq) +{ +if (!vq->iotlb) { +#if VHOST_ARCH_CAN_ACCEL_UACCESS +vhost_vq_map_prefetch (vq); +#endif +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_meta_prefetch);/* Can we log writes? */
@@ -2620,6 +2719,48 @@ 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_device_flags (vq, &device_flags)) +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_device_off_wrap (vq, &device_off_wrap)) +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_avail_event (vq))
@@ -3689,16 +3830,13 @@ int vhost_add_used(struct vhost_virtqueue *vq, struct vhost_used_elem *used, }EXPORT_SYMBOL_GPL (vhost_add_used); -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. */
@@ -3731,6 +3869,62 @@ 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_driver_flags (vq, &event_flags)) { +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_PACKED_EVENT_FLAG_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_PACKED_EVENT_FLAG_DESC )) +return event_flags != +cpu_to_vhost16 (vq,VRING_PACKED_EVENT_FLAG_DISABLE ); + +/* Read desc event flags before event_off and event_wrap */ +smp_rmb (); + +if (vhost_get_driver_off_wrap (vq, &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) {
@@ -3836,10 +4030,34 @@ EXPORT_SYMBOL_GPL(vhost_vq_avail_empty);static bool vhost_enable_notify_packed (struct vhost_virtqueue *vq) {struct vring_packed_desc *d = vq->desc_packed + vq->avail_idx; -__virtio16 flags; +__virtio16 flags =cpu_to_vhost16 (vq,VRING_PACKED_EVENT_FLAG_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_PACKED_EVENT_FLAG_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.
@@ -3901,7 +4119,18 @@ EXPORT_SYMBOL_GPL(vhost_enable_notify);static void vhost_disable_notify_packed (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_PACKED_EVENT_FLAG_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_virtqueue *vq)
drivers/vhost/vhost.h +8 -3
@@ -125,9 +125,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; + };#if VHOST_ARCH_CAN_ACCEL_UACCESS /* Read by memory accessors, modified by meta data * prefetching, MMU notifier and vring ioctl().
Signature · 1 line
2.18.1
PATCH v3 14/15 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 | 265 +++++++++++++++++++++++++++++++++++++++--- drivers/vhost/vhost.h | 11 +- 2 files changed, 255 insertions(+), 21 deletions(-)
drivers/vhost/vhost.c +247 -18
@@ -1524,6 +1524,76 @@ static inline int vhost_put_desc_flags(struct vhost_virtqueue *vq,return vhost_put_user (vq, *flags, &desc->flags,VHOST_ADDR_DESC ); } +static int vhost_get_driver_off_wrap (struct vhost_virtqueue *vq, +__virtio16 *off_wrap) +{ +#if VHOST_ARCH_CAN_ACCEL_UACCESS +struct vring_packed_desc_event *event = +vhost_get_meta_ptr (vq,VHOST_ADDR_AVAIL ); +if (likely (event)) { + *off_wrap = event->off_wrap; +vhost_put_meta_ptr (); +return 0 ; + } +#endif +return vhost_get_user (vq, *off_wrap, + &vq->driver_event->off_wrap, +VHOST_ADDR_AVAIL ); +} + +static int vhost_get_driver_flags (struct vhost_virtqueue *vq, +__virtio16 *driver_flags) +{ +#if VHOST_ARCH_CAN_ACCEL_UACCESS +struct vring_packed_desc_event *event = +vhost_get_meta_ptr (vq,VHOST_ADDR_AVAIL ); + +if (likely (event)) { + *driver_flags = event->flags; +vhost_put_meta_ptr (); +return 0 ; + } +#endif +return vhost_get_user (vq, *driver_flags, &vq->driver_event->flags, +VHOST_ADDR_AVAIL ); +} + +static int vhost_put_device_off_wrap (struct vhost_virtqueue *vq, +__virtio16 *off_wrap) +{ +#if VHOST_ARCH_CAN_ACCEL_UACCESS +struct vring_packed_desc_event *event = +vhost_get_meta_ptr (vq,VHOST_ADDR_USED ); + +if (likely (event)) { + event->off_wrap = *off_wrap; +vhost_put_meta_ptr (); +return 0 ; + } +#endif +return vhost_put_user (vq, *off_wrap, + &vq->device_event->off_wrap, +VHOST_ADDR_USED ); +} + +static int vhost_put_device_flags (struct vhost_virtqueue *vq, +__virtio16 *device_flags) +{ +#if VHOST_ARCH_CAN_ACCEL_UACCESS +struct vring_packed_desc_event *event = +vhost_get_meta_ptr (vq,VHOST_ADDR_USED ); + +if (likely (event)) { + event->flags = *device_flags; +vhost_put_meta_ptr (); +return 0 ; + } +#endif +return vhost_put_user (vq, *device_flags, + &vq->device_event->flags, +VHOST_ADDR_USED ); +} +static int vhost_new_umem_range (struct vhost_umem *umem,u64 start,u64 size,u64 end,u64 userspace_addr,int perm)
@@ -1809,10 +1879,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 (packed, num *sizeof (*packed)) && -access_ok (packed, num *sizeof (*packed)); +access_ok (packed, num *sizeof (*packed)) && +access_ok (driver_event,sizeof (*driver_event)) && +access_ok (device_event,sizeof (*device_event)); } static int vq_access_ok_split(struct vhost_virtqueue *vq, unsigned int num,
@@ -1904,16 +1979,25 @@ static void vhost_vq_map_prefetch(struct vhost_virtqueue *vq) }#endif -int vq_meta_prefetch (struct vhost_virtqueue *vq) +static int vq_iotlb_prefetch_packed (struct vhost_virtqueue *vq) { -unsigned int num = vq->num; +int num = vq->num; -if (!vq->iotlb) { -#if VHOST_ARCH_CAN_ACCEL_UACCESS -vhost_vq_map_prefetch (vq); -#endif -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_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 ); +} + +static int vq_iotlb_prefetch_split (struct vhost_virtqueue *vq) +{ +unsigned int num = vq->num; return iotlb_access_ok(vq, VHOST_ACCESS_RO, (u64)(uintptr_t)vq->desc,
@@ -1928,6 +2012,21 @@ int vq_meta_prefetch(struct vhost_virtqueue *vq)vhost_get_used_size (vq, num), VHOST_ADDR_USED); } + +int vq_meta_prefetch (struct vhost_virtqueue *vq) +{ +if (!vq->iotlb) { +#if VHOST_ARCH_CAN_ACCEL_UACCESS +vhost_vq_map_prefetch (vq); +#endif +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_meta_prefetch);/* Can we log writes? */
@@ -2620,6 +2719,48 @@ 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_device_flags (vq, &device_flags)) +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_device_off_wrap (vq, &device_off_wrap)) +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_avail_event (vq))
@@ -3689,16 +3830,13 @@ int vhost_add_used(struct vhost_virtqueue *vq, struct vhost_used_elem *used, }EXPORT_SYMBOL_GPL (vhost_add_used); -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. */
@@ -3731,6 +3869,62 @@ 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_driver_flags (vq, &event_flags)) { +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_PACKED_EVENT_FLAG_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_PACKED_EVENT_FLAG_DESC )) +return event_flags != +cpu_to_vhost16 (vq,VRING_PACKED_EVENT_FLAG_DISABLE ); + +/* Read desc event flags before event_off and event_wrap */ +smp_rmb (); + +if (vhost_get_driver_off_wrap (vq, &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) {
@@ -3836,10 +4030,34 @@ EXPORT_SYMBOL_GPL(vhost_vq_avail_empty);static bool vhost_enable_notify_packed (struct vhost_virtqueue *vq) {struct vring_packed_desc *d = vq->desc_packed + vq->avail_idx; -__virtio16 flags; +__virtio16 flags =cpu_to_vhost16 (vq,VRING_PACKED_EVENT_FLAG_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_PACKED_EVENT_FLAG_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.
@@ -3901,7 +4119,18 @@ EXPORT_SYMBOL_GPL(vhost_enable_notify);static void vhost_disable_notify_packed (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_PACKED_EVENT_FLAG_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_virtqueue *vq)
drivers/vhost/vhost.h +8 -3
@@ -125,9 +125,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; + };#if VHOST_ARCH_CAN_ACCEL_UACCESS /* Read by memory accessors, modified by meta data * prefetching, MMU notifier and vring ioctl().
Signature · 1 line
2.18.1
PATCH v3 15/15 vhost: enable packed virtqueues
In reply to Jason WangThis patch enables packed virtqueue support for vhost.
Testpmd (virtio-user) + vhost_net shows about 2.6% improvemetn on TX PPS:
Before: 5.75Mpps
After : 5.90Mpps
--- drivers/vhost/vhost.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/vhost/vhost.h +2 -1
@@ -326,7 +326,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.18.1
PATCH v3 15/15 vhost: enable packed virtqueues
In reply to Jason WangThis patch enables packed virtqueue support for vhost.
Testpmd (virtio-user) + vhost_net shows about 2.6% improvemetn on TX PPS:
Before: 5.75Mpps
After : 5.90Mpps
--- drivers/vhost/vhost.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/vhost/vhost.h +2 -1
@@ -326,7 +326,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.18.1
Michael S. Tsirkin
maintainerQuoted 10 lines · Jason Wang
Hi all:
This series implements packed virtqueues which were described at [1]. In this version we try to address the performance regression saw by V2. The root cause is packed virtqueue need more times of userspace memory accesssing which turns out to be very expensive. Thanks to the help of
7f466032dc9e("vhost: access vq metadata through kernel virtual address"), such overhead cold be eliminated. So in this version, we can see about 2% improvement for packed virtqueue on PPS.
Great job, thanks!
Pls allow a bit more review time than usual as this is a big patchset. Should be done by Tuesday.
-next material anyway.
Quoted 93 lines
More optimizations (e.g
IN_ORDER) is on the road.Please review.
[1] https://docs.oasis-open.org/virtio/virtio/v1.1/csprd01/virtio-v1.1-csprd01.html#x1-610007
This version were tested with:
- zercopy/datacopy
- mergeable buffer on/off
- TCP stream & virtio-userChanges from V2:
- rebase on top of vhost metadata accelreation series
- introduce shadow used ring API
- new SET_VRING_BASE/GET_VRING_BASE that takes care about warp counter and index for both avail and used
- various twaeaksChanges 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 duringvhost_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 syncing
-last_used_idx
- renameused_wrap_countertolast_used_wrap_counter
- rebase to net-nextChanges from RFC V4:
- fixsignalled_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 checkingdesc_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 (15):
vhost: simplify meta data pointer accessing
vhost: remove the unnecessary parameter ofvhost_vq_avail_empty()
vhost: remove unnecessary parameter of
vhost_enable_notify()/vhost_disable_notify
vhost-net: don't usevhost_add_used_n()for zerocopy
vhost: introduce helpers to manipulate shadow used ring
vhost_net: switch TX to use shadow used ring API
vhost_net: calculate last used length once for mergeable buffer
vhost_net: switch to use shadow used ring API for RX
vhost: do not exportvhost_add_used_n()and
vhost_add_used_and_signal_n()
vhost: hide used ring layout from device
vhost: do not usevring_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 | 200 +++--- drivers/vhost/scsi.c | 72 +- drivers/vhost/test.c | 6 +- drivers/vhost/vhost.c | 1508 +++++++++++++++++++++++++++++++++++------ drivers/vhost/vhost.h | 78 ++- drivers/vhost/vsock.c | 57 +- 6 files changed, 1513 insertions(+), 408 deletions(-)Signature · 1 line
2.18.1
Michael S. Tsirkin
maintainerQuoted 10 lines · Jason Wang
Hi all:
This series implements packed virtqueues which were described at [1]. In this version we try to address the performance regression saw by V2. The root cause is packed virtqueue need more times of userspace memory accesssing which turns out to be very expensive. Thanks to the help of
7f466032dc9e("vhost: access vq metadata through kernel virtual address"), such overhead cold be eliminated. So in this version, we can see about 2% improvement for packed virtqueue on PPS.
Great job, thanks!
Pls allow a bit more review time than usual as this is a big patchset. Should be done by Tuesday.
-next material anyway.
Quoted 93 lines
More optimizations (e.g
IN_ORDER) is on the road.Please review.
[1] https://docs.oasis-open.org/virtio/virtio/v1.1/csprd01/virtio-v1.1-csprd01.html#x1-610007
This version were tested with:
- zercopy/datacopy
- mergeable buffer on/off
- TCP stream & virtio-userChanges from V2:
- rebase on top of vhost metadata accelreation series
- introduce shadow used ring API
- new SET_VRING_BASE/GET_VRING_BASE that takes care about warp counter and index for both avail and used
- various twaeaksChanges 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 duringvhost_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 syncing
-last_used_idx
- renameused_wrap_countertolast_used_wrap_counter
- rebase to net-nextChanges from RFC V4:
- fixsignalled_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 checkingdesc_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 (15):
vhost: simplify meta data pointer accessing
vhost: remove the unnecessary parameter ofvhost_vq_avail_empty()
vhost: remove unnecessary parameter of
vhost_enable_notify()/vhost_disable_notify
vhost-net: don't usevhost_add_used_n()for zerocopy
vhost: introduce helpers to manipulate shadow used ring
vhost_net: switch TX to use shadow used ring API
vhost_net: calculate last used length once for mergeable buffer
vhost_net: switch to use shadow used ring API for RX
vhost: do not exportvhost_add_used_n()and
vhost_add_used_and_signal_n()
vhost: hide used ring layout from device
vhost: do not usevring_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 | 200 +++--- drivers/vhost/scsi.c | 72 +- drivers/vhost/test.c | 6 +- drivers/vhost/vhost.c | 1508 +++++++++++++++++++++++++++++++++++------ drivers/vhost/vhost.h | 78 ++- drivers/vhost/vsock.c | 57 +- 6 files changed, 1513 insertions(+), 408 deletions(-)Signature · 1 line
2.18.1
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Jason Wang
Hi all:
This series implements packed virtqueues which were described at [1]. In this version we try to address the performance regression saw by V2. The root cause is packed virtqueue need more times of userspace memory accesssing which turns out to be very expensive. Thanks to the help of
7f466032dc9e("vhost: access vq metadata through kernel virtual address"), such overhead cold be eliminated. So in this version, we can see about 2% improvement for packed virtqueue on PPS.
Quoted 4 lines
Great job, thanks!
Pls allow a bit more review time than usual as this is a big patchset. Should be done by Tuesday.
-next material anyway.
Sure, just to confirm, I think this should go for your vhost tree?.
Thanks
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Jason Wang
Hi all:
This series implements packed virtqueues which were described at [1]. In this version we try to address the performance regression saw by V2. The root cause is packed virtqueue need more times of userspace memory accesssing which turns out to be very expensive. Thanks to the help of
7f466032dc9e("vhost: access vq metadata through kernel virtual address"), such overhead cold be eliminated. So in this version, we can see about 2% improvement for packed virtqueue on PPS.
Quoted 4 lines
Great job, thanks!
Pls allow a bit more review time than usual as this is a big patchset. Should be done by Tuesday.
-next material anyway.
Sure, just to confirm, I think this should go for your vhost tree?.
Thanks
Michael S. Tsirkin
maintainerQuoted 19 lines · Jason Wang
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Jason Wang
Hi all:
This series implements packed virtqueues which were described at [1]. In this version we try to address the performance regression saw by V2. The root cause is packed virtqueue need more times of userspace memory accesssing which turns out to be very expensive. Thanks to the help of
7f466032dc9e("vhost: access vq metadata through kernel virtual address"), such overhead cold be eliminated. So in this version, we can see about 2% improvement for packed virtqueue on PPS.Quoted 4 lines
Great job, thanks!
Pls allow a bit more review time than usual as this is a big patchset. Should be done by Tuesday.
-next material anyway.
Quoted 3 lines
Sure, just to confirm, I think this should go for your vhost tree?.
Thanks
I think this makes sense, yes.
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerQuoted 19 lines · Jason Wang
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Jason Wang
Hi all:
This series implements packed virtqueues which were described at [1]. In this version we try to address the performance regression saw by V2. The root cause is packed virtqueue need more times of userspace memory accesssing which turns out to be very expensive. Thanks to the help of
7f466032dc9e("vhost: access vq metadata through kernel virtual address"), such overhead cold be eliminated. So in this version, we can see about 2% improvement for packed virtqueue on PPS.Quoted 4 lines
Great job, thanks!
Pls allow a bit more review time than usual as this is a big patchset. Should be done by Tuesday.
-next material anyway.
Quoted 3 lines
Sure, just to confirm, I think this should go for your vhost tree?.
Thanks
I think this makes sense, yes.