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=1796360002; b=4lB3N/sDLl6VKTR9zewzNDuLAh//3ULQ1K1sGRa7yHRcsJAzTxEDlbn9MbYW0EU+t3VT jEHdG+ueTIEzmraLbZliwPyUA3pBbavmz0LINmZX1a584Q9mf9RJIn+gUbajEPJjHOYBO KtuYcOof/lKt2iacbO0HxSrttUDVg+gOeSXONRczRWt10uCzriNm7s2RU6SdKGbVFP+Aw gp4KCiqCqFyBEt52z/o5Pxt5a6/feKWJREiNLXSfVolInVy6F9oFxf/M59A7fDD8/dFtI yj3ZNMmYq+bpVOVM3ZW2XTs4GZG2sGMFCtS2q/8ZMlpW+k1PAF4KoCivcaRA+es8TDw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796360002; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=P3/FGVg9ezZj8IChZXfwPjOso61J1LJVsGSuaHzsuds=; b=LvUbgNTg9M0wGr6CGhFwyY+1hHRiwTcUJzGKUg5dud4gNeMcnJOJLwBFpzuz1SutepZ9 UyzIGGa8vYD8ymISjUhnBoJ5BFO/qZmEp/ioNsNiRK0gxUW8VIITyRQzAlsSErrCibZAw wfKDWzyMjAbfEy1v3yA0CP29kZoqey4ei/6fJRWfXqEvpeOD2Q2iAoGs1p6CbvaHu7lzq s7D8Ika2Xp/wz5XJBMcvL7HVVZiNW9KHSuJEfu/Dxsqgmx3HKTRHHjKtEdK3rxIEHxENk WR0XwnN13nVHHfGM0X+Rsdt2IQ7COOve8Nb7aMT9ZNV7Djkus3E0Q+jFPewgonvds+Q== 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=VWxqjFB3; 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 85DAA606A32F for ; Fri, 4 Dec 2026 04:53:22 +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=VWxqjFB3 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A72E1F00934; Fri, 4 Dec 2026 04:53:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796360002; bh=P3/FGVg9ezZj8IChZXfwPjOso61J1LJVsGSuaHzsuds=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VWxqjFB31f3eqTEhxI+20CJhp/P8i6IXaMZ0bZJh3pPLkiS5YEL7CNg40nVx8tA41 4CjT0Trm49jWScFU11Hj/DxmjphHQRs1yhyFKbDSU0OORFz4AGPUa4mzAqD2ui+vJW xZD8DJd+gJXarGROBNTVbpIT0bdX7zuBliDYduK32Xgdkb5gH+ElwGWEyIJ4hPIOFn vv/WF3hK4OFwzEzwnJFvpA3yu101TMvzIx7fMVxcfuu/PDboI84QphaeyZODI+QP+j vMNG7Pmp1n+oyegEmskHmAW9iIkVjFlsAj3o5MDe7F5yq9HfkFu+dKJqIVtGZkKdbE ZrlIrEZ1f3G7Q== From: Sasha Levin To: stable@vger.kernel.org Cc: "Michael S. Tsirkin" , Seohyeon Maeng , minki@morningstarsec.dev, Jason Wang , Sasha Levin Subject: [PATCH 6.12.y] vhost: split out-of-order used ring batches at every wrap Date: Thu, 3 Dec 2026 23:53:20 -0500 Message-ID: <20261204045250.2676757-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120219-sassy-entering-757d@gregkh> References: <2026120219-sassy-entering-757d@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: Moved the split-at-ring-end logic into vhost_add_used_n() as a loop, because vhost_add_used_n_ooo() doesn't exist in this tree. ] 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 bacb48308b084..90c3c41276008 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -3035,21 +3035,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