virtio-user: ctrl vq support for packed
RFC 1/1 virtio-user: ctrl vq support for packed
This adds support to virtio-user for control virtqueues and reverts commit "5e4e7a752 net/virtio-user: fail if cq used with packed vq".
I add a struct virtio_user_queue to have a place for wrap counters and avail/used index (which is not needed for split ring because it has those in shared memory).
This is a RFC because it only supports in-order use of descriptors in the ring. I'm looking for ideas how to change this without the .next field in the descriptor as we have it with split virtqueues.
--- drivers/net/virtio/virtio_ethdev.c | 11 +- .../net/virtio/virtio_user/virtio_user_dev.c | 101 ++++++++++++++++-- .../net/virtio/virtio_user/virtio_user_dev.h | 14 ++- drivers/net/virtio/virtio_user_ethdev.c | 25 ++++- 4 files changed, 135 insertions(+), 16 deletions(-)
drivers/net/virtio/virtio_ethdev.c +8 -3
@@ -153,6 +153,7 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,uint16_t flags;int sum =0 ;int k; +int ndescs =0 ;/* * Format is enforced in qemu code:
@@ -162,7 +163,6 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,*/ head = vq->vq_avail_idx; wrap_counter = vq->avail_wrap_counter; - desc[head].flags =VRING_DESC_F_NEXT ; desc[head].addr = cvq->virtio_net_hdr_mem; desc[head].len =sizeof (struct virtio_net_ctrl_hdr ); vq->vq_free_cnt--;
@@ -170,6 +170,7 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, vq->vq_avail_idx -= vq->vq_nentries; vq->avail_wrap_counter ^=1 ; } + ndescs++;for (k =0 ; k < pkt_num; k++) { desc[vq->vq_avail_idx].addr = cvq->virtio_net_hdr_mem
@@ -188,6 +189,7 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, vq->vq_avail_idx -= vq->vq_nentries; vq->avail_wrap_counter ^=1 ; } + ndescs++; }
@@ -198,6 +200,7 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, flags |=VRING_DESC_F_AVAIL (vq->avail_wrap_counter) |VRING_DESC_F_USED (!vq->avail_wrap_counter); desc[vq->vq_avail_idx].flags = flags; + flags =VRING_DESC_F_NEXT ; flags |=VRING_DESC_F_AVAIL (wrap_counter) |VRING_DESC_F_USED (!wrap_counter);
@@ -209,6 +212,7 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, vq->vq_avail_idx -= vq->vq_nentries; vq->avail_wrap_counter ^=1 ; } + ndescs++;virtqueue_notify (vq);
@@ -220,8 +224,9 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,/* now get used descriptors */ while (desc_is_used (&desc[vq->vq_used_cons_idx], vq)) { - vq->vq_free_cnt++; -if (++vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_free_cnt += ndescs; + vq->vq_used_cons_idx += ndescs; +if (vq->vq_used_cons_idx >= vq->vq_nentries) { vq->vq_used_cons_idx -= vq->vq_nentries; vq->used_wrap_counter ^=1 ; }
drivers/net/virtio/virtio_user/virtio_user_dev.c +90 -11
127 lines not on this page · raw message
drivers/net/virtio/virtio_user/virtio_user_dev.h +13 -1
@@ -11,6 +11,12 @@#include "../virtio_ring.h" #include "vhost.h" +struct virtio_user_queue { +uint16_t avail_idx, used_idx; +uint16_t used_wrap_counter; +uint16_t avail_wrap_counter; +}; +struct virtio_user_dev {/* for vhost_user backend */ int vhostfd;
@@ -39,7 +45,12 @@ struct virtio_user_dev {uint16_t port_id;uint8_t mac_addr[ETHER_ADDR_LEN ];char path[PATH_MAX ]; -struct vring vrings[VIRTIO_MAX_VIRTQUEUES ]; +union { +struct vring vrings[VIRTIO_MAX_VIRTQUEUES ]; +struct vring_packed packed_vrings[VIRTIO_MAX_VIRTQUEUES ]; + }; +struct virtio_user_queue queues[VIRTIO_MAX_VIRTQUEUES ]; +struct virtio_user_backend_ops *ops;pthread_mutex_t mutex;bool started;
@@ -53,5 +64,6 @@ int virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues, int mrg_rxbuf, int in_order, int packed_vq);void virtio_user_dev_uninit (struct virtio_user_dev *dev);void virtio_user_handle_cq (struct virtio_user_dev *dev,uint16_t queue_idx); +void virtio_user_handle_cq_packed (struct virtio_user_dev *dev,uint16_t queue_idx);uint8_t virtio_user_handle_mq (struct virtio_user_dev *dev,uint16_t q_pairs);#endif
drivers/net/virtio/virtio_user_ethdev.c +24 -1
@@ -277,6 +277,26 @@ virtio_user_setup_queue(struct virtio_hw *hw, struct virtqueue *vq)struct virtio_user_dev *dev =virtio_user_get_dev (hw);uint16_t queue_idx = vq->vq_queue_index;uint64_t desc_addr, avail_addr, used_addr; +struct virtio_user_queue *vq_user = &dev->queues[queue_idx]; + +if (vtpci_packed_queue (hw)) { + desc_addr = (uintptr_t )vq->vq_ring_virt_mem; + avail_addr = desc_addr + vq->vq_nentries * +sizeof (struct vring_packed_desc ); + used_addr =RTE_ALIGN_CEIL (avail_addr + +sizeof (struct vring_packed_desc_event ), +VIRTIO_PCI_VRING_ALIGN ); + dev->packed_vrings[queue_idx].num = vq->vq_nentries; + dev->packed_vrings[queue_idx].desc_packed = + (void *)(uintptr_t )desc_addr; + dev->packed_vrings[queue_idx].driver_event = + (void *)(uintptr_t )avail_addr; + dev->packed_vrings[queue_idx].device_event = + (void *)(uintptr_t )used_addr; + vq_user->avail_wrap_counter = true; + vq_user->used_wrap_counter = true; +return 0 ; + } desc_addr = (uintptr_t )vq->vq_ring_virt_mem; avail_addr = desc_addr + vq->vq_nentries *sizeof (struct vring_desc );
@@ -317,7 +337,10 @@ virtio_user_notify_queue(struct virtio_hw *hw, struct virtqueue *vq)struct virtio_user_dev *dev =virtio_user_get_dev (hw);if (hw->cvq && (hw->cvq->vq == vq)) { -virtio_user_handle_cq (dev, vq->vq_queue_index); +if (vtpci_packed_queue (vq->hw)) +virtio_user_handle_cq_packed (dev, vq->vq_queue_index); +else +virtio_user_handle_cq (dev, vq->vq_queue_index);return ; }
Signature · 1 line
2.17.2
Hi Jens,
Quoted 74 lines · Jens Freimann
This adds support to virtio-user for control virtqueues and reverts commit "
5e4e7a752net/virtio-user: fail if cq used with packed vq".I add a struct
virtio_user_queueto have a place for wrap counters and avail/used index (which is not needed for split ring because it has those in shared memory).This is a RFC because it only supports in-order use of descriptors in the ring. I'm looking for ideas how to change this without the .next field in the descriptor as we have it with split virtqueues.
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 11 +- .../net/virtio/virtio_user/virtio_user_dev.c | 101 ++++++++++++++++-- .../net/virtio/virtio_user/virtio_user_dev.h | 14 ++- drivers/net/virtio/virtio_user_ethdev.c | 25 ++++- 4 files changed, 135 insertions(+), 16 deletions(-)drivers/net/virtio/virtio_ethdev.c +5
-1@@ -153,6 +153,7 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,uint16_t flags;int sum =0 ;int k; +int ndescs =0 ;/* * Format is enforced in qemu code: @@ -162,7 +163,6 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,*/ head = vq->vq_avail_idx; wrap_counter = vq->avail_wrap_counter; - desc[head].flags =VRING_DESC_F_NEXT ; desc[head].addr = cvq->virtio_net_hdr_mem; desc[head].len =sizeof (struct virtio_net_ctrl_hdr ); vq->vq_free_cnt--;@@ -170,6 +170,7 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, vq->vq_avail_idx -= vq->vq_nentries; vq->avail_wrap_counter ^=1 ; } + ndescs++;for (k =0 ; k < pkt_num; k++) { desc[vq->vq_avail_idx].addr = cvq->virtio_net_hdr_mem@@ -188,6 +189,7 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, vq->vq_avail_idx -= vq->vq_nentries; vq->avail_wrap_counter ^=1 ; } + ndescs++; }@@ -198,6 +200,7 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, flags |=VRING_DESC_F_AVAIL (vq->avail_wrap_counter) |VRING_DESC_F_USED (!vq->avail_wrap_counter); desc[vq->vq_avail_idx].flags = flags; + flags =VRING_DESC_F_NEXT ; flags |=VRING_DESC_F_AVAIL (wrap_counter) |VRING_DESC_F_USED (!wrap_counter);@@ -209,6 +212,7 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, vq->vq_avail_idx -= vq->vq_nentries; vq->avail_wrap_counter ^=1 ; } + ndescs++;virtqueue_notify (vq);@@ -220,8 +224,9 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
drivers/net/virtio/virtio_ethdev.c virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, · line 232
Quoted 10 lines
drivers/net/virtio/virtio_ethdev.c +3
-2/* now get used descriptors */ while (desc_is_used (&desc[vq->vq_used_cons_idx], vq)) { - vq->vq_free_cnt++; -if (++vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_free_cnt += ndescs; + vq->vq_used_cons_idx += ndescs; +if (vq->vq_used_cons_idx >= vq->vq_nentries) { vq->vq_used_cons_idx -= vq->vq_nentries; vq->used_wrap_counter ^=1 ; }
I'm not sure why this change is needed.
Why not getting used descriptor one by one as it was before? If it does not work, doesn't that mean that the desc chain is not marked as used properly by the device?
Thanks,
Maxime