[2/4] net/virtio-user: fix the control vq support
Checks
Commit Message
This patch fixed below issues in the packed ring based control
vq support in virtio user:
1. The idx_hdr should be used_idx instead of the id in the desc;
2. We just need to write out a single used descriptor for each
descriptor list;
3. The avail/used bits should be initialized to 0;
Meanwhile, make the function name consistent with other parts.
Fixes: 48a4464029a7 ("net/virtio-user: support control VQ for packed")
Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
---
drivers/net/virtio/virtio_ethdev.c | 11 ++++++
.../net/virtio/virtio_user/virtio_user_dev.c | 37 +++++++++++--------
drivers/net/virtio/virtio_user_ethdev.c | 7 +---
3 files changed, 34 insertions(+), 21 deletions(-)
Comments
On 1/22/19 6:01 PM, Tiwei Bie wrote:
> This patch fixed below issues in the packed ring based control
> vq support in virtio user:
>
> 1. The idx_hdr should be used_idx instead of the id in the desc;
> 2. We just need to write out a single used descriptor for each
> descriptor list;
> 3. The avail/used bits should be initialized to 0;
>
> Meanwhile, make the function name consistent with other parts.
>
> Fixes: 48a4464029a7 ("net/virtio-user: support control VQ for packed")
>
> Signed-off-by: Tiwei Bie<tiwei.bie@intel.com>
> ---
> drivers/net/virtio/virtio_ethdev.c | 11 ++++++
> .../net/virtio/virtio_user/virtio_user_dev.c | 37 +++++++++++--------
> drivers/net/virtio/virtio_user_ethdev.c | 7 +---
> 3 files changed, 34 insertions(+), 21 deletions(-)
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Thanks,
Maxime
@@ -224,6 +224,17 @@ virtio_send_command_packed(struct virtnet_ctl *cvq,
vq->used_wrap_counter ^= 1;
}
+ PMD_INIT_LOG(DEBUG, "vq->vq_free_cnt=%d\n"
+ "vq->vq_avail_idx=%d\n"
+ "vq->vq_used_cons_idx=%d\n"
+ "vq->avail_wrap_counter=%d\n"
+ "vq->used_wrap_counter=%d\n",
+ vq->vq_free_cnt,
+ vq->vq_avail_idx,
+ vq->vq_used_cons_idx,
+ vq->avail_wrap_counter,
+ vq->used_wrap_counter);
+
result = cvq->virtio_net_hdr_mz->addr;
return result;
}
@@ -632,9 +632,9 @@ desc_is_avail(struct vring_packed_desc *desc, bool wrap_counter)
}
static uint32_t
-virtio_user_handle_ctrl_msg_pq(struct virtio_user_dev *dev,
- struct vring_packed *vring,
- uint16_t idx_hdr)
+virtio_user_handle_ctrl_msg_packed(struct virtio_user_dev *dev,
+ struct vring_packed *vring,
+ uint16_t idx_hdr)
{
struct virtio_net_ctrl_hdr *hdr;
virtio_net_ctrl_ack status = ~0;
@@ -671,6 +671,10 @@ virtio_user_handle_ctrl_msg_pq(struct virtio_user_dev *dev,
*(virtio_net_ctrl_ack *)(uintptr_t)
vring->desc_packed[idx_status].addr = status;
+ /* Update used descriptor */
+ vring->desc_packed[idx_hdr].id = vring->desc_packed[idx_status].id;
+ vring->desc_packed[idx_hdr].len = sizeof(status);
+
return n_descs;
}
@@ -679,24 +683,25 @@ virtio_user_handle_cq_packed(struct virtio_user_dev *dev, uint16_t queue_idx)
{
struct virtio_user_queue *vq = &dev->packed_queues[queue_idx];
struct vring_packed *vring = &dev->packed_vrings[queue_idx];
- uint16_t id, n_descs;
+ uint16_t n_descs;
while (desc_is_avail(&vring->desc_packed[vq->used_idx],
vq->used_wrap_counter)) {
- id = vring->desc_packed[vq->used_idx].id;
- n_descs = virtio_user_handle_ctrl_msg_pq(dev, vring, id);
+ n_descs = virtio_user_handle_ctrl_msg_packed(dev, vring,
+ vq->used_idx);
- do {
- vring->desc_packed[vq->used_idx].flags =
- VRING_DESC_F_AVAIL(vq->used_wrap_counter) |
- VRING_DESC_F_USED(vq->used_wrap_counter);
- if (++vq->used_idx >= dev->queue_size) {
- vq->used_idx -= dev->queue_size;
- vq->used_wrap_counter ^= 1;
- }
- n_descs--;
- } while (n_descs);
+ rte_smp_wmb();
+ vring->desc_packed[vq->used_idx].flags =
+ VRING_DESC_F_WRITE |
+ VRING_DESC_F_AVAIL(vq->used_wrap_counter) |
+ VRING_DESC_F_USED(vq->used_wrap_counter);
+
+ vq->used_idx += n_descs;
+ if (vq->used_idx >= dev->queue_size) {
+ vq->used_idx -= dev->queue_size;
+ vq->used_wrap_counter ^= 1;
+ }
}
}
@@ -274,7 +274,6 @@ virtio_user_get_queue_num(struct virtio_hw *hw, uint16_t queue_id __rte_unused)
static void
virtio_user_setup_queue_packed(struct virtqueue *vq,
struct virtio_user_dev *dev)
-
{
uint16_t queue_idx = vq->vq_queue_index;
struct vring_packed *vring;
@@ -300,10 +299,8 @@ virtio_user_setup_queue_packed(struct virtqueue *vq,
dev->packed_queues[queue_idx].avail_wrap_counter = true;
dev->packed_queues[queue_idx].used_wrap_counter = true;
- for (i = 0; i < vring->num; i++) {
- vring->desc_packed[i].flags = VRING_DESC_F_USED(1) |
- VRING_DESC_F_AVAIL(1);
- }
+ for (i = 0; i < vring->num; i++)
+ vring->desc_packed[i].flags = 0;
}
static void