From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381212; b=pm8ehO7HGR2fHFXGji9RCOUkDXZAdpWxAQg+bqEtwQTpe9CY0NdPUGNHrr/66kFGKwmR lzBaKnnTkk9IGWlxTWpmHBB5qafQGqyhzdxcWkIPdr6A3EPRr+P/1MhB6AY1DV21L4elN 4sbtUZejkuv4Rt55EoxSe8t26AbjTR44sclk6lZ/kPWE7jG6nJfULkg+0GgJc6Ai3HgeO W9Ffxqe0rPWJN4flwzyB125XkkL2T1wmwEfVj1JuCS0HvZHJ344DGZ2DZC7bViXry/SYy Odlkfq8UKS3gW7D4c9hio02/vEiVD1U3hBsoIciO01GwuYI/qrMVlNB8bodGIGxRzVQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381212; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=t6sXzJ0HnSuA+wsJk+IDOIfpk0O2DFFRFDG/Yc91Qrs=; b=g0DZHhD5WJv9kMm8RLHIjl5ER8iKJJKJVH0lV74/g2eUlPhBHmsoqAfNn0dg+/ryqoGT Ln1rYde6ahpwi+KezZAlDbpYOPqUy9loJsiu6ek7nt0oAa89DYIvhnEMf8vPJ+hQfmTRx XeQmCDa7EQHZa2RpdvAQJN8jovERXyONlhd7HBG7hb/Sh5LQXlBS0twLigIxk46NRVBRL GywYvqeRfuRbBaZyapTBU8Mju5D1U1xjXfUXBxEScfaqnStalf2e5ozzIkvXBmR83Nd1A fuxIpU/jwATNaBMTGZvaX0zELFWUEgw8GezQsfC4BnJ18qBAHzxqz0qDfcOGOx7yWew== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=vYqOVU1z; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAA51606A32C; Fri, 4 Dec 2026 10:46:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=vYqOVU1z Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2C811F000CE; Fri, 4 Dec 2026 10:46:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381212; bh=t6sXzJ0HnSuA+wsJk+IDOIfpk0O2DFFRFDG/Yc91Qrs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=vYqOVU1zElfX02lpkMAdesv4GeUWC+Td1GnaNkq7A1SDh8B+V9NXz7Ik8MxxnR0wi arxpUCLefm2ivHcTLIy60fds4pxlCinpFRlfAT7RJ2ynAnhGhalPTjRYydjQqIiNTN Z5m7XQ04xGVnRSwsdRAH7RaKT1bN1IP0jd6xUjZE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Seohyeon Maeng , minki@morningstarsec.dev, Jason Wang , "Michael S. Tsirkin" Subject: [PATCH 7.3 606/742] vhost: split out-of-order used ring batches at every wrap Date: Fri, 4 Dec 2026 19:07:50 +0900 Message-ID: <20261204100651.217238941@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michael S. Tsirkin commit 5570a998b884c988dbe105430d7e2d8e9411e37e upstream. 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 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 Signed-off-by: Michael S. Tsirkin Signed-off-by: Greg Kroah-Hartman --- drivers/vhost/vhost.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -3137,18 +3137,21 @@ static int vhost_add_used_n_ooo(struct v 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,