From nobody Mon Nov 23 04:28:04 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=baidu.com ARC-Seal: i=1; a=rsa-sha256; t=1793757725; cv=none; d=zohomail.com; s=zohoarc; b=hmaY/ErZexyA/57mYcVPN4U1dO7tDRYHpmTN7rMIJhTGS6hUrcTflCMW0xtPBcoioFPGzDR8iWxn6tTjzp4vTEdGA23GVMS4Bth3DPx3gZyLPNFULOaO4GwAKY6HP9QWxCu7nEwNwSwSWI9nJeHM95gkCxFOVT7BbBmdXE7wY8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793757725; h=Content-Type:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HmNXJnJakzF+agSM7PBFoIpbOPfctNHD2b33l/K7Q8o=; b=Wlqh04/j1XJVZH7xHBeC/t33iv/vVPU/dVrn+nEtxFJk+iBoCL7UDpdyUokTvaaxIowqlteSs3x17GKxLbO+3MNU8pHC2OWdk9um5bgaAODXcO/agSI7ovJchbSS+GUCW9q2QqU4C1rYbFot3utTZwiMDXf/vmDTjwnvQ1uigD0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793757725835380.37379645183773; Tue, 3 Nov 2026 18:02:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOQJS-0007Dc-MW; Tue, 03 Nov 2026 21:01:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOQJQ-0007DD-7Y for qemu-devel@nongnu.org; Tue, 03 Nov 2026 21:01:16 -0500 Received: from outbound.baidu.com ([180.76.5.236]) by eggs.gnu.org with smtp (Exim 4.90_1) (envelope-from ) id 1xOQJL-0003QP-L9 for qemu-devel@nongnu.org; Tue, 03 Nov 2026 21:01:15 -0500 X-MD-Sfrom: lirongqing@baidu.com X-MD-SrcIP: 172.31.50.47 From: lirongqing To: , , Stefano Garzarella , CC: Li RongQing Subject: [PATCH] virtio: Reset free_head on shadow virtqueue start Date: Wed, 4 Nov 2026 10:00:53 +0800 Message-ID: <20261104020053.2548-1-lirongqing@baidu.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.127.73.8] X-ClientProxiedBy: bjkjy-exc2.internal.baidu.com (172.31.50.46) To bjkjy-exc3.internal.baidu.com (172.31.50.47) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baidu.com; s=selector1; t=1793757662; bh=HmNXJnJakzF+agSM7PBFoIpbOPfctNHD2b33l/K7Q8o=; h=From:To:CC:Subject:Date:Message-ID:Content-Type; b=Z9VaDfkX2kg2DsD+0nrJq4q7yf7hn8tAvGl0Ut+5tHFRFFLg78rWUe5FYnZc3kWhO 6Gsr2dLqqz6U+ufev3gGMgEQy/joP2IWdhG11FOokbdDolNPY0rxAh2uzFcQpjw9Sn VegYmkctong493RB8BtXxSpIYDw+NSLOAeDaK/kzvuDQn7jwnsDHZba9+m5KVFwteP wkDnZ3VOIIBCM9kO46Wcw57fESp7rW5hFwddwIYdJrA/lORiOoN4eHJbhYJB4hzFVZ oQTwmpc0fBQXEOaJHOi1S4rXRQy/tmzZYvcToMJRgCBWxC80aZM77Ibtgp/jJxzmAt vOFYPDQLNCL8g== Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=180.76.5.236; envelope-from=prvs=md1762E48BC8=lirongqing@baidu.com; helo=outbound.baidu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @baidu.com) X-ZM-MESSAGEID: 1793757731392158500 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Li RongQing free_head tracks the index of the next free descriptor in the SVQ descriptor ring. It is used by vhost_svq_vring_write_descs() to choose where to place new descriptors, and is updated as descriptors are allocated and recycled. free_head is zero-initialized when the SVQ is created through vhost_svq_new() (g_new0), but it is not reset in vhost_svq_start(). The start function already resets the rest of the ring state (shadow_avail_idx, shadow_used_idx, last_used, last_used_idx and num_free), yet free_head is left untouched. Since an SVQ can be stopped and restarted on the same object, for example across vDPA device migration or control virtqueue processing, a stale free_head from the previous run survives into the new one. This causes new descriptors to be written at the wrong position of the SVQ descriptor ring, corrupting it. Reset free_head to 0 in vhost_svq_start() so that descriptor allocation always begins from the head of a fresh ring. Fixes: 100890f7cad5 ("vhost: Shadow virtqueue buffers forwarding") Signed-off-by: Li RongQing Reviewed-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index c97bd9f..462c86d 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -857,6 +857,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIOD= evice *vdev, svq->shadow_used_idx =3D 0; memset(&svq->batch_last, 0, sizeof(svq->batch_last)); svq->last_used =3D 0; + svq->free_head =3D 0; svq->last_used_idx =3D 0; svq->vdev =3D vdev; svq->vq =3D vq; --=20 2.9.4