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=1796360267; b=QNuEN/e/dt6HOrSoS1hhga/nih2J5imsI+oMlPebCtVu3eziAZrznRqRFQ73Z8mYfvx3 GFmvjk1CPH4x5WkR4s1O69vEKUkl06BHBa7m68E57BB1UtXmn27j9ho8KT+And1+obKZm ahLhCqT80FXb5Aop/kmBc238ttJdHHkWsjlsFLu9tsqc5Eqb5b0L+yXwROnptOUZKMAK3 qJLsdVSjWJrJT3CUokPOz8IHOjtbkC+dukcMXGZ8ZSh2BE037ufgUN0w64khydOg66Iip Yocgv+egyC5rh4EirycOk8hE5zs1hvL1J6zGMt5xfiitnUHH+GRSq/IshUMeRTN5tww== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796360267; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=X8J2hbxlutgw1LztmWfFj1XNtD1oQvL2F9wo9paCpjg=; b=Dr5x82dmhgJ8iAKlZrxicNIy33sV9bMq8WsDk2Q4G00izXnOBCBXD4TjwJKg/kxlLwc9 v9sGvzqRQyaUZO2V39dkeI2VE37IaMCvftO7l/aaQLkXd8pmjVh/m7iNgwcWQZtzLeYoo kSPTK9zMSGHr2AtpA0aotW8C3w4aJl4BX4XHF3+ZGzqwPHMbPeKX2wZSLh2PrwNdPQuv8 5rmB6R5fZalvbsYWeCuFXuvqVIcUJ3oRuo/JfAdP9xRCvVeldhsU3GrcPi3j/YAj6FL7l geoF41fST+CHoC+A4hstzzVEw6lbCaReKSPE8syr+1qvkjybik36nEd21lO+Qbu2mKQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Y+zoCN9z; 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 6C5C5606A322 for ; Fri, 4 Dec 2026 04:57:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Y+zoCN9z Received: by smtp.kernel.org (Postfix) with ESMTPSA id 369C11F000C2; Fri, 4 Dec 2026 04:57:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796360267; bh=X8J2hbxlutgw1LztmWfFj1XNtD1oQvL2F9wo9paCpjg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Y+zoCN9z0J9GYnSmXoNolD8ZKD07bSRgUfNopHdAhi/8LRUgSnKW7eazwN2U2J8NC u6sDdOeC3EaVn+KT/YONC0fl2t3PyjvI5nTvuLIz46WMq44FubMGoz8fT+E39hs9zp CqqEwnl1Wuvxs3eWF8XaxW5u8JPtYfoGJZ3Q8iGD72hkGTXfCUReCm07JqVme71wMJ ujf5PQHzZvliQPq3iB2DNxqTAz40UyHITUTdyh3pgfybWe3/QNVsL/Tnmpc9mWlq7C MPhFPUoZGpL4qN+S/pINAj9LAdZp4vPHYwQzipYgeO4WEG1kOCB/RFZUsKdL1rvi+A cei/m3sdvIafw== From: Sasha Levin To: stable@vger.kernel.org Cc: "Michael S. Tsirkin" , Seohyeon Maeng , minki@morningstarsec.dev, Jason Wang , Sasha Levin 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 Message-ID: <20261204045718.2696688-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120220-jellied-negligee-d19c@gregkh> References: <2026120220-jellied-negligee-d19c@gregkh> 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 From: "Michael S. Tsirkin" [ 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 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 [ 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 --- 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