From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: dev@dpdk.org, chenbox@nvidia.com, david.marchand@redhat.com,
bnemeth@redhat.com, echaudro@redhat.com
Cc: Maxime Coquelin <maxime.coquelin@redhat.com>, stable@dpdk.org
Subject: [PATCH v2 1/2] vhost: fix memory leak in Virtio Tx split path
Date: Wed, 31 Jan 2024 20:53:08 +0100 [thread overview]
Message-ID: <20240131195309.2808015-1-maxime.coquelin@redhat.com> (raw)
When vIOMMU is enabled and Virtio device is bound to kernel
driver in guest, rte_vhost_dequeue_burst() will often return
early because of IOTLB misses.
This patch fixes a mbuf leak occurring in this case.
Fixes: 242695f6122a ("vhost: allocate and free packets in bulk in Tx split")
Cc: stable@dpdk.org
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
Changes in v2:
==============
- Fix descriptors leak (David)
- Rebased on top of next-virtio
---
lib/vhost/virtio_net.c | 24 ++++++------------------
1 file changed, 6 insertions(+), 18 deletions(-)
diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index c738b7edc9..9951842b9f 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -3104,7 +3104,6 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
{
uint16_t i;
uint16_t avail_entries;
- uint16_t dropped = 0;
static bool allocerr_warned;
/*
@@ -3143,11 +3142,8 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
update_shadow_used_ring_split(vq, head_idx, 0);
- if (unlikely(buf_len <= dev->vhost_hlen)) {
- dropped += 1;
- i++;
+ if (unlikely(buf_len <= dev->vhost_hlen))
break;
- }
buf_len -= dev->vhost_hlen;
@@ -3164,8 +3160,6 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
buf_len, mbuf_pool->name);
allocerr_warned = true;
}
- dropped += 1;
- i++;
break;
}
@@ -3176,27 +3170,21 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
VHOST_DATA_LOG(dev->ifname, ERR, "failed to copy desc to mbuf.");
allocerr_warned = true;
}
- dropped += 1;
- i++;
break;
}
-
}
- if (dropped)
- rte_pktmbuf_free_bulk(&pkts[i - 1], count - i + 1);
+ if (unlikely(count != i))
+ rte_pktmbuf_free_bulk(&pkts[i], count - i);
- vq->last_avail_idx += i;
-
- do_data_copy_dequeue(vq);
- if (unlikely(i < count))
- vq->shadow_used_idx = i;
if (likely(vq->shadow_used_idx)) {
+ vq->last_avail_idx += vq->shadow_used_idx;
+ do_data_copy_dequeue(vq);
flush_shadow_used_ring_split(dev, vq);
vhost_vring_call_split(dev, vq);
}
- return (i - dropped);
+ return i;
}
__rte_noinline
--
2.43.0
next reply other threads:[~2024-01-31 19:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-31 19:53 Maxime Coquelin [this message]
2024-01-31 19:53 ` [PATCH v2 2/2] vhost: add new mbuf allocation failure statistic Maxime Coquelin
2024-02-01 8:10 ` David Marchand
2024-02-01 8:29 ` Maxime Coquelin
2024-02-06 10:31 ` David Marchand
2024-02-06 14:59 ` Maxime Coquelin
2024-02-06 10:29 ` [PATCH v2 1/2] vhost: fix memory leak in Virtio Tx split path David Marchand
2024-02-06 13:57 ` Maxime Coquelin
2024-02-06 14:59 ` Maxime Coquelin
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=20240131195309.2808015-1-maxime.coquelin@redhat.com \
--to=maxime.coquelin@redhat.com \
--cc=bnemeth@redhat.com \
--cc=chenbox@nvidia.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=echaudro@redhat.com \
--cc=stable@dpdk.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).