From: Maxime Coquelin <maxime.coque...@redhat.com> this patch is changed from https://gitlab.com/mcoquelin/dpdk-next-virtio/-/commit/a89dc311f2d03e99b8180f377b4a60a0e94 the biggest change is moving the mmaping-related process to the Previous patch
Signed-off-by: Cindy Lu <l...@redhat.com> --- lib/vhost/vduse.c | 43 ++++++++++++++++++++++++++----------- lib/vhost/virtio_net.c | 22 +++++++++++++++++++ lib/vhost/virtio_net_ctrl.c | 4 ++++ 3 files changed, 56 insertions(+), 13 deletions(-) diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c index 4b9bfdbe73..28701dd126 100644 --- a/lib/vhost/vduse.c +++ b/lib/vhost/vduse.c @@ -165,7 +165,7 @@ vduse_control_queue_event(int fd, void *arg, int *remove __rte_unused) } static void -vduse_vring_setup(struct virtio_net *dev, unsigned int index) +vduse_vring_setup(struct virtio_net *dev, unsigned int index, bool reconnect) { struct vhost_virtqueue *vq = dev->virtqueue[index]; struct vhost_vring_addr *ra = &vq->ring_addrs; @@ -181,15 +181,13 @@ vduse_vring_setup(struct virtio_net *dev, unsigned int index) return; } - VHOST_LOG_CONFIG(dev->ifname, INFO, "VQ %u info:\n", index); - VHOST_LOG_CONFIG(dev->ifname, INFO, "\tnum: %u\n", vq_info.num); - VHOST_LOG_CONFIG(dev->ifname, INFO, "\tdesc_addr: %llx\n", vq_info.desc_addr); - VHOST_LOG_CONFIG(dev->ifname, INFO, "\tdriver_addr: %llx\n", vq_info.driver_addr); - VHOST_LOG_CONFIG(dev->ifname, INFO, "\tdevice_addr: %llx\n", vq_info.device_addr); - VHOST_LOG_CONFIG(dev->ifname, INFO, "\tavail_idx: %u\n", vq_info.split.avail_index); - VHOST_LOG_CONFIG(dev->ifname, INFO, "\tready: %u\n", vq_info.ready); - - vq->last_avail_idx = vq_info.split.avail_index; + if (reconnect) { + vq->last_avail_idx = vq->log->last_avail_idx; + vq->last_used_idx = vq->log->last_avail_idx; + } else { + vq->last_avail_idx = vq_info.split.avail_index; + vq->last_used_idx = vq_info.split.avail_index; + } vq->size = vq_info.num; vq->ready = vq_info.ready; vq->enabled = true; @@ -197,6 +195,14 @@ vduse_vring_setup(struct virtio_net *dev, unsigned int index) ra->avail_user_addr = vq_info.driver_addr; ra->used_user_addr = vq_info.device_addr; + VHOST_LOG_CONFIG(dev->ifname, INFO, "VQ %u info:\n", index); + VHOST_LOG_CONFIG(dev->ifname, INFO, "\tnum: %u\n", vq_info.num); + VHOST_LOG_CONFIG(dev->ifname, INFO, "\tdesc_addr: %llx\n", vq_info.desc_addr); + VHOST_LOG_CONFIG(dev->ifname, INFO, "\tdriver_addr: %llx\n", vq_info.driver_addr); + VHOST_LOG_CONFIG(dev->ifname, INFO, "\tdevice_addr: %llx\n", vq_info.device_addr); + VHOST_LOG_CONFIG(dev->ifname, INFO, "\tavail_idx: %u\n", vq->last_avail_idx); + VHOST_LOG_CONFIG(dev->ifname, INFO, "\tready: %u\n", vq_info.ready); + vq->kickfd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); if (vq->kickfd < 0) { VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to init kickfd for VQ %u: %s\n", @@ -250,7 +256,7 @@ vduse_vring_setup(struct virtio_net *dev, unsigned int index) } static void -vduse_device_start(struct virtio_net *dev) +vduse_device_start(struct virtio_net *dev, bool reconnect) { unsigned int i, ret; @@ -268,6 +274,16 @@ vduse_device_start(struct virtio_net *dev) return; } + if (reconnect && dev->features != dev->log->features) { + VHOST_LOG_CONFIG(dev->ifname, ERR, + "Mismatch between reconnect file features 0x%" PRIx64 + " & device features 0x%" PRIx64 "\n", + dev->log->features, dev->features); + return; + } + + dev->log->features = dev->features; + VHOST_LOG_CONFIG(dev->ifname, INFO, "negotiated Virtio features: 0x%" PRIx64 "\n", dev->features); @@ -281,7 +297,7 @@ vduse_device_start(struct virtio_net *dev) } for (i = 0; i < dev->nr_vring; i++) - vduse_vring_setup(dev, i); + vduse_vring_setup(dev, i, reconnect); dev->flags |= VIRTIO_DEV_READY; @@ -335,9 +351,10 @@ vduse_events_handler(int fd, void *arg, int *remove __rte_unused) VHOST_LOG_CONFIG(dev->ifname, INFO, "\tnew status: 0x%08x\n", req.s.status); dev->status = req.s.status; + dev->log->status = dev->status; if (dev->status & VIRTIO_DEVICE_STATUS_DRIVER_OK) - vduse_device_start(dev); + vduse_device_start(dev, false); resp.result = VDUSE_REQ_RESULT_OK; break; diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index be28ea5151..49cce787bc 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -1443,6 +1443,8 @@ virtio_dev_rx_split(struct virtio_net *dev, struct vhost_virtqueue *vq, } vq->last_avail_idx += num_buffers; + if (vq->log) + vq->log->last_avail_idx = vq->last_avail_idx; } do_data_copy_enqueue(dev, vq); @@ -1838,6 +1840,8 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, struct vhost_virtqueue pkts_info[slot_idx].mbuf = pkts[pkt_idx]; vq->last_avail_idx += num_buffers; + if (vq->log) + vq->log->last_avail_idx = vq->last_avail_idx; } if (unlikely(pkt_idx == 0)) @@ -1866,6 +1870,8 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, struct vhost_virtqueue /* recover shadow used ring and available ring */ vq->shadow_used_idx -= num_descs; vq->last_avail_idx -= num_descs; + if (vq->log) + vq->log->last_avail_idx = vq->last_avail_idx; } /* keep used descriptors */ @@ -2077,9 +2083,15 @@ dma_error_handler_packed(struct vhost_virtqueue *vq, uint16_t slot_idx, if (vq->last_avail_idx >= descs_err) { vq->last_avail_idx -= descs_err; + if (vq->log) + vq->log->last_avail_idx = vq->last_avail_idx; } else { vq->last_avail_idx = vq->last_avail_idx + vq->size - descs_err; vq->avail_wrap_counter ^= 1; + if (vq->log) { + vq->log->last_avail_idx = vq->last_avail_idx; + vq->log->avail_wrap_counter = vq->avail_wrap_counter; + } } if (async->buffer_idx_packed >= buffers_err) @@ -3161,6 +3173,8 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq, rte_pktmbuf_free_bulk(&pkts[i - 1], count - i + 1); vq->last_avail_idx += i; + if (vq->log) + vq->log->last_avail_idx = vq->last_avail_idx; do_data_copy_dequeue(vq); if (unlikely(i < count)) @@ -3796,6 +3810,8 @@ virtio_dev_tx_async_split(struct virtio_net *dev, struct vhost_virtqueue *vq, async->desc_idx_split++; vq->last_avail_idx++; + if (vq->log) + vq->log->last_avail_idx = vq->last_avail_idx; } if (unlikely(dropped)) @@ -3814,6 +3830,8 @@ virtio_dev_tx_async_split(struct virtio_net *dev, struct vhost_virtqueue *vq, pkt_idx = n_xfer; /* recover available ring */ vq->last_avail_idx -= pkt_err; + if (vq->log) + vq->log->last_avail_idx = vq->last_avail_idx; /** * recover async channel copy related structures and free pktmbufs @@ -4093,6 +4111,10 @@ virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, vq->last_avail_idx += vq->size - descs_err; vq->avail_wrap_counter ^= 1; } + if (vq->log) { + vq->log->last_avail_idx = vq->last_avail_idx; + vq->log->avail_wrap_counter = vq->avail_wrap_counter; + } } async->pkts_idx += pkt_idx; diff --git a/lib/vhost/virtio_net_ctrl.c b/lib/vhost/virtio_net_ctrl.c index 36e34153e7..00c55a12e5 100644 --- a/lib/vhost/virtio_net_ctrl.c +++ b/lib/vhost/virtio_net_ctrl.c @@ -168,6 +168,8 @@ virtio_net_ctrl_pop(struct virtio_net *dev, struct vhost_virtqueue *cvq, cvq->last_avail_idx++; if (cvq->last_avail_idx >= cvq->size) cvq->last_avail_idx -= cvq->size; + if (cvq->log) + cvq->log->last_avail_idx = cvq->last_avail_idx; if (dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX)) vhost_avail_event(cvq) = cvq->last_avail_idx; @@ -180,6 +182,8 @@ virtio_net_ctrl_pop(struct virtio_net *dev, struct vhost_virtqueue *cvq, cvq->last_avail_idx++; if (cvq->last_avail_idx >= cvq->size) cvq->last_avail_idx -= cvq->size; + if (cvq->log) + cvq->log->last_avail_idx = cvq->last_avail_idx; if (dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX)) vhost_avail_event(cvq) = cvq->last_avail_idx; -- 2.34.3