From: David Marchand <david.marchand@redhat.com>
To: maxime.coquelin@redhat.com, dev@dpdk.org
Cc: bruce.richardson@intel.com, Chenbo Xia <chenbox@nvidia.com>
Subject: [PATCH v2 6/6] vhost: simplify some descriptor handling
Date: Fri, 4 Sep 2026 09:46:48 +0200 [thread overview]
Message-ID: <20260904074649.1979166-7-david.marchand@redhat.com> (raw)
In-Reply-To: <20260904074649.1979166-1-david.marchand@redhat.com>
Now that the async datapath has been removed, move back the descriptors
copy/filling code in desc_to_mbuf/mbuf_to_desc and eliminate an
intermediate helper.
Tracking buf_iova is not needed in the descriptor to mbuf case.
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
lib/vhost/virtio_net.c | 78 ++++++++++++++++--------------------------
1 file changed, 30 insertions(+), 48 deletions(-)
diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index 79034ae036..9b1ef8f10c 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -76,6 +76,12 @@ vhost_queue_stats_update(const struct virtio_net *dev, struct vhost_virtqueue *v
}
}
+static __rte_always_inline bool
+vhost_can_batch_copy(struct vhost_virtqueue *vq, uint32_t cpy_len)
+{
+ return cpy_len <= MAX_BATCH_LEN && vq->batch_copy_nb_elems < vq->size;
+}
+
static inline void
do_data_copy_enqueue(struct virtio_net *dev, struct vhost_virtqueue *vq)
__rte_requires_shared_capability(&vq->iotlb_lock)
@@ -843,44 +849,6 @@ copy_vnet_hdr_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
}
}
-static __rte_always_inline void
-sync_fill_seg(struct virtio_net *dev, struct vhost_virtqueue *vq,
- struct rte_mbuf *m, uint32_t mbuf_offset,
- uint64_t buf_addr, uint64_t buf_iova, uint32_t cpy_len, bool to_desc)
- __rte_requires_shared_capability(&vq->iotlb_lock)
-{
- struct batch_copy_elem *batch_copy = vq->batch_copy_elems;
-
- if (likely(cpy_len > MAX_BATCH_LEN || vq->batch_copy_nb_elems >= vq->size)) {
- if (to_desc) {
- rte_memcpy((void *)((uintptr_t)(buf_addr)),
- rte_pktmbuf_mtod_offset(m, void *, mbuf_offset),
- cpy_len);
- vhost_log_cache_write_iova(dev, vq, buf_iova, cpy_len);
- PRINT_PACKET(dev, (uintptr_t)(buf_addr), cpy_len, 0);
- } else {
- rte_memcpy(rte_pktmbuf_mtod_offset(m, void *, mbuf_offset),
- (void *)((uintptr_t)(buf_addr)),
- cpy_len);
- }
- } else {
- if (to_desc) {
- batch_copy[vq->batch_copy_nb_elems].dst =
- (void *)((uintptr_t)(buf_addr));
- batch_copy[vq->batch_copy_nb_elems].src =
- rte_pktmbuf_mtod_offset(m, void *, mbuf_offset);
- batch_copy[vq->batch_copy_nb_elems].log_addr = buf_iova;
- } else {
- batch_copy[vq->batch_copy_nb_elems].dst =
- rte_pktmbuf_mtod_offset(m, void *, mbuf_offset);
- batch_copy[vq->batch_copy_nb_elems].src =
- (void *)((uintptr_t)(buf_addr));
- }
- batch_copy[vq->batch_copy_nb_elems].len = cpy_len;
- vq->batch_copy_nb_elems++;
- }
-}
-
static __rte_always_inline int
mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
struct rte_mbuf *m, struct buf_vector *buf_vec,
@@ -976,9 +944,22 @@ mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
cpy_len = RTE_MIN(buf_avail, mbuf_avail);
- sync_fill_seg(dev, vq, m, mbuf_offset,
- buf_addr + buf_offset,
- buf_iova + buf_offset, cpy_len, true);
+ if (likely(!vhost_can_batch_copy(vq, cpy_len))) {
+ rte_memcpy(RTE_PTR_ADD(buf_addr, buf_offset),
+ rte_pktmbuf_mtod_offset(m, void *, mbuf_offset),
+ cpy_len);
+ vhost_log_cache_write_iova(dev, vq, buf_iova + buf_offset, cpy_len);
+ PRINT_PACKET(dev, RTE_PTR_ADD(buf_addr, buf_offset), cpy_len, 0);
+ } else {
+ vq->batch_copy_elems[vq->batch_copy_nb_elems].dst =
+ RTE_PTR_ADD(buf_addr, buf_offset);
+ vq->batch_copy_elems[vq->batch_copy_nb_elems].src =
+ rte_pktmbuf_mtod_offset(m, void *, mbuf_offset);
+ vq->batch_copy_elems[vq->batch_copy_nb_elems].log_addr =
+ buf_iova + buf_offset;
+ vq->batch_copy_elems[vq->batch_copy_nb_elems].len = cpy_len;
+ vq->batch_copy_nb_elems++;
+ }
mbuf_avail -= cpy_len;
mbuf_offset += cpy_len;
@@ -1679,7 +1660,7 @@ desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
__rte_requires_shared_capability(&vq->iotlb_lock)
{
uint32_t buf_avail, buf_offset, buf_len;
- uint64_t buf_addr, buf_iova;
+ uint64_t buf_addr;
uint32_t mbuf_avail, mbuf_offset;
uint32_t hdr_remain = dev->vhost_hlen;
uint32_t cpy_len;
@@ -1710,7 +1691,6 @@ desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
}
buf_addr = buf_vec[vec_idx].buf_addr;
- buf_iova = buf_vec[vec_idx].buf_iova;
buf_len = buf_vec[vec_idx].buf_len;
buf_offset = hdr_remain;
buf_avail = buf_vec[vec_idx].buf_len - hdr_remain;
@@ -1725,14 +1705,17 @@ desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
while (1) {
cpy_len = RTE_MIN(buf_avail, mbuf_avail);
- if (likely(hdr && cur == m)) {
+ if (likely((hdr && cur == m) || !vhost_can_batch_copy(vq, cpy_len))) {
rte_memcpy(rte_pktmbuf_mtod_offset(cur, void *, mbuf_offset),
(void *)((uintptr_t)(buf_addr + buf_offset)),
cpy_len);
} else {
- sync_fill_seg(dev, vq, cur, mbuf_offset,
- buf_addr + buf_offset,
- buf_iova + buf_offset, cpy_len, false);
+ vq->batch_copy_elems[vq->batch_copy_nb_elems].dst =
+ rte_pktmbuf_mtod_offset(cur, void *, mbuf_offset);
+ vq->batch_copy_elems[vq->batch_copy_nb_elems].src =
+ RTE_PTR_ADD(buf_addr, buf_offset);
+ vq->batch_copy_elems[vq->batch_copy_nb_elems].len = cpy_len;
+ vq->batch_copy_nb_elems++;
}
mbuf_avail -= cpy_len;
@@ -1746,7 +1729,6 @@ desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
break;
buf_addr = buf_vec[vec_idx].buf_addr;
- buf_iova = buf_vec[vec_idx].buf_iova;
buf_len = buf_vec[vec_idx].buf_len;
buf_offset = 0;
--
2.54.0
prev parent reply other threads:[~2026-09-04 7:47 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 15:31 [RFC 0/3] Drop vhost async (DMA-accelerated) datapath David Marchand
2026-07-23 15:31 ` [RFC 1/3] examples: stop using vhost async datapath David Marchand
2026-08-25 11:39 ` David Marchand
2026-07-23 15:31 ` [RFC 2/3] vhost: refuse " David Marchand
2026-07-23 15:31 ` [RFC 3/3] vhost: drop " David Marchand
2026-08-18 9:10 ` [RFC 0/3] Drop vhost async (DMA-accelerated) datapath Maxime Coquelin
2026-08-26 14:02 ` [PATCH 0/5] " David Marchand
2026-08-26 14:02 ` [PATCH 1/5] vhost: decouple guest pages population from async datapath David Marchand
2026-08-26 14:02 ` [PATCH 2/5] examples/vhost: stop using " David Marchand
2026-08-26 14:02 ` [PATCH 3/5] vhost: drop " David Marchand
2026-08-26 14:02 ` [PATCH 4/5] vhost: rename packed layout helpers for batches David Marchand
2026-08-26 14:02 ` [PATCH 5/5] vhost: simplify some descriptor handling David Marchand
2026-09-04 7:46 ` [PATCH v2 0/6] Drop vhost async (DMA-accelerated) datapath David Marchand
2026-09-04 7:46 ` [PATCH v2 1/6] vhost: decouple guest pages population from async datapath David Marchand
2026-09-04 7:46 ` [PATCH v2 2/6] examples/vhost: stop using " David Marchand
2026-09-04 7:46 ` [PATCH v2 3/6] examples/vdpa: remove dependency on PCI library David Marchand
2026-09-04 7:46 ` [PATCH v2 4/6] vhost: drop async datapath David Marchand
2026-09-04 7:46 ` [PATCH v2 5/6] vhost: rename packed layout helpers for batches David Marchand
2026-09-04 7:46 ` David Marchand [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260904074649.1979166-7-david.marchand@redhat.com \
--to=david.marchand@redhat.com \
--cc=bruce.richardson@intel.com \
--cc=chenbox@nvidia.com \
--cc=dev@dpdk.org \
--cc=maxime.coquelin@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.