Linux kernel -stable discussions
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] vhost: split out-of-order used ring batches at every wrap" failed to apply to 6.1-stable tree
@ 2026-12-02 13:46 gregkh
  2026-12-04  5:01 ` [PATCH 6.1.y] vhost: split out-of-order used ring batches at every wrap Sasha Levin
  0 siblings, 1 reply; 2+ messages in thread
From: gregkh @ 2026-12-02 13:46 UTC (permalink / raw)
  To: mst, bioloidgp, jasowangio; +Cc: stable


The patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x 5570a998b884c988dbe105430d7e2d8e9411e37e
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2026120220-overrule-rebel-abe4@gregkh' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'

Possible dependencies:



thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 5570a998b884c988dbe105430d7e2d8e9411e37e Mon Sep 17 00:00:00 2001
From: "Michael S. Tsirkin" <mst@redhat.com>
Date: Fri, 6 Nov 2026 09:11:07 -0500
Subject: [PATCH] vhost: split out-of-order used ring batches at every wrap

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>

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index ea127af58ada..ce80f7cbc224 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -3153,18 +3153,21 @@ static int vhost_add_used_n_ooo(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;
-	}
-	return __vhost_add_used_n(vq, heads, count);
+	} while (count);
+
+	return 0;
 }
 
 static int vhost_add_used_n_in_order(struct vhost_virtqueue *vq,


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 6.1.y] vhost: split out-of-order used ring batches at every wrap
  2026-12-02 13:46 FAILED: patch "[PATCH] vhost: split out-of-order used ring batches at every wrap" failed to apply to 6.1-stable tree gregkh
@ 2026-12-04  5:01 ` Sasha Levin
  0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2026-12-04  5:01 UTC (permalink / raw)
  To: stable; +Cc: Michael S. Tsirkin, Seohyeon Maeng, minki, Jason Wang,
	Sasha Levin

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: Adapted the loop fix to vhost_add_used_n(), where the older code has no separate out-of-order helper, and kept its trailing smp_wmb() and index-update tail. ]
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 3e0ed85898b90..451663f834cb9 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -2438,21 +2438,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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-04  5:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 13:46 FAILED: patch "[PATCH] vhost: split out-of-order used ring batches at every wrap" failed to apply to 6.1-stable tree gregkh
2026-12-04  5:01 ` [PATCH 6.1.y] vhost: split out-of-order used ring batches at every wrap Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox