From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
Seohyeon Maeng <bioloidgp@gmail.com>,
minki@morningstarsec.dev, Jason Wang <jasowangio@gmail.com>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.6.y] vhost: split out-of-order used ring batches at every wrap
Date: Thu, 3 Dec 2026 23:57:45 -0500 [thread overview]
Message-ID: <20261204045718.2696688-1-sashal@kernel.org> (raw)
In-Reply-To: <2026120220-jellied-negligee-d19c@gregkh>
From: "Michael S. Tsirkin" <mst@redhat.com>
[ Upstream commit 5570a998b884c988dbe105430d7e2d8e9411e37e ]
When a completion batch larger than the remaining space in the used
ring is added without VIRTIO_F_IN_ORDER, vhost_add_used_n_ooo() splits
it at the ring boundary only once. vhost-net can batch up to
VHOST_NET_BATCH TX completions, so with a queue smaller than half the
batch the tail of the second chunk runs past the end of the used ring
and into whatever follows it in the vhost owner's address space: with
a 32 entry queue, last_used_idx % 32 == 3 and a 64 entry batch, three
used entries are written past the ring.
To fix, keep splitting the remaining batch at each wrap until it is
exhausted.
Cc: stable@vger.kernel.org
Reported-by: Seohyeon Maeng <bioloidgp@gmail.com>
Cc: minki@morningstarsec.dev
Fixes: 2b3b35eb989 ("vhost_net: batch used ring update in rx")
Fixes: 4afb52c2af44 ("vhost_net: batch update used ring for datacopy TX")
Cc: Jason Wang <jasowangio@gmail.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
[ sashal: Backport applies the loop-based split to vhost_add_used_n() directly, since the out-of-order helper doesn't exist here, and keeps the trailing smp_wmb() and used-index update. ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/vhost/vhost.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 8fc9bf3783c8b..a9b7c6bd5e195 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -2837,21 +2837,19 @@ static int __vhost_add_used_n(struct vhost_virtqueue *vq,
int vhost_add_used_n(struct vhost_virtqueue *vq, struct vring_used_elem *heads,
unsigned count)
{
- int start, n, r;
+ unsigned int n;
+ int r;
- start = vq->last_used_idx & (vq->num - 1);
- n = vq->num - start;
- if (n < count) {
+ do {
+ unsigned int start = vq->last_used_idx & (vq->num - 1);
+
+ n = min(vq->num - start, count);
r = __vhost_add_used_n(vq, heads, n);
if (r < 0)
return r;
heads += n;
count -= n;
- }
- r = __vhost_add_used_n(vq, heads, count);
-
- if (r < 0)
- return r;
+ } while (count);
/* Make sure buffer is written before we update index. */
smp_wmb();
--
2.53.0
prev parent reply other threads:[~2026-12-04 4:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 13:46 FAILED: patch "[PATCH] vhost: split out-of-order used ring batches at every wrap" failed to apply to 6.6-stable tree gregkh
2026-12-04 4:57 ` Sasha Levin [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=20261204045718.2696688-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=bioloidgp@gmail.com \
--cc=jasowangio@gmail.com \
--cc=minki@morningstarsec.dev \
--cc=mst@redhat.com \
--cc=stable@vger.kernel.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