From nobody Sat Apr 11 21:30:07 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1772645847; cv=none; d=zohomail.com; s=zohoarc; b=WCAnMQ62qJCo1bi9UEBg9Pq538sIi/SCPf2p4OZ3H6jQd1RJBvWYkESvWg4T5b9gg5W5oNuH/+7NcAvTztuh1R78Vs9J6sVKWfs2Nxa5fEr0Kd9HWSiRnRmooMGxprF8IfqkimtsVV4v32px5y+9Uy8xOJzjd5JDaqStSWjc0Gw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772645847; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RnTF0bzItgxS8wl6QLBtm3YJkJAnJBXxnfqNeCkSIJA=; b=DRew431ysBZzN0kbw/uVOUdm8He9/LKEIUJKMEfaXCpjty9Q8ZVnloMiaNymy4QwF1udgBGwP7SGw4+ebTB04ME67CUvpwq1uyWMFkEarzkqCtoGEKKwTRwcAJa4H6AaXmgDM+lSUp8/+tEfQtzAT/DMbRjoIJIbSN+S9TS2K+0= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772645847114608.2035485819346; Wed, 4 Mar 2026 09:37:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vxq8e-0003Be-KF; Wed, 04 Mar 2026 12:36:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxq8W-0003AK-Uw for qemu-devel@nongnu.org; Wed, 04 Mar 2026 12:35:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxq8V-0004rE-Dj for qemu-devel@nongnu.org; Wed, 04 Mar 2026 12:35:52 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-263-7jrVYYEFPROajdBDapMF0A-1; Wed, 04 Mar 2026 12:35:47 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 408ED180034E; Wed, 4 Mar 2026 17:35:46 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.224.212]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 47CAD1958DC5; Wed, 4 Mar 2026 17:35:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772645750; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RnTF0bzItgxS8wl6QLBtm3YJkJAnJBXxnfqNeCkSIJA=; b=OUYg9Gz09NShtkVe9nlw8rHCA69XuLinSXZHCuzM6ZmjG0vaewo2fl6pakcmu4BUtDTIal EY/2LmPoVDmV31h59qbvq0YeY1/TM9NxVyyvIrElyDkmGWoAZXVOtvS1HsUO0xbcO/f/zS IDAAPfWOLBLwGPYRL2cFpjB1/9REu+M= X-MC-Unique: 7jrVYYEFPROajdBDapMF0A-1 X-Mimecast-MFC-AGG-ID: 7jrVYYEFPROajdBDapMF0A_1772645746 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Jason Wang , Dragos Tatulea DE , Jonah Palmer , "Michael S. Tsirkin" , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Lei Yang , Koushik Dutta , Stefano Garzarella , qemu-stable@nongnu.org, Cindy Lu , Maxime Coquelin Subject: [PATCH 1/7] virtio: Allow to fill a whole virtqueue in order Date: Wed, 4 Mar 2026 18:35:29 +0100 Message-ID: <20260304173535.2702587-2-eperezma@redhat.com> In-Reply-To: <20260304173535.2702587-1-eperezma@redhat.com> References: <20260304173535.2702587-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 0 X-Spam_score: -0.0 X-Spam_bar: / X-Spam_report: (-0.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.703, RCVD_IN_VALIDITY_SAFE_BLOCKED=1.386, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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 @redhat.com) X-ZM-MESSAGEID: 1772645848747158500 As the while steps < max_steps is already one less than the vq size, the right maximum max_steps variable is queue length, not the maximum possible remainder of % vq->vring.num. Fixes: b44135daa37 ("virtio: virtqueue_ordered_fill - VIRTIO_F_IN_ORDER sup= port") Signed-off-by: Eugenio P=C3=A9rez --- Personally I'd just remove max_steps and let it be vq->vring.num, but let's make the minimal changes for now. --- hw/virtio/virtio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index e9d553295257..17f171551892 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -980,7 +980,7 @@ static void virtqueue_ordered_fill(VirtQueue *vq, const= VirtQueueElement *elem, * We shouldn't need to increase 'i' by more than or equal to * the distance between used_idx and last_avail_idx (max_steps). */ - max_steps =3D (vq->last_avail_idx - vq->used_idx) % vq->vring.num; + max_steps =3D MIN(vq->last_avail_idx - vq->used_idx, vq->vring.num); =20 /* Search for element in vq->used_elems */ while (steps < max_steps) { --=20 2.53.0 From nobody Sat Apr 11 21:30:07 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1772645788; cv=none; d=zohomail.com; s=zohoarc; b=GzBqBTxQBjShg85Gkbv/3QPxy16y1bW1jXXg1Jw4Vgn57uOGsTn3bhUZ3lFSwjGsoHnBb/Fl6B2WBuqMmv38LQo8kI1FQ05pTCtEYbQl7uTL5YrtWFWY4t4bSKgb/cyU0JADZ1E55zzSKkpHOxrrSeDzamNhXBSEYOcbejbZa/g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772645788; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=pJcBbWgk55Xy56aKGdb0PF2VLcZ2WdttuXvg1P3uOiQ=; b=FFaic1xIBTCEFyByacxPaB+2yK6FEjt73eva1yCl9sWBPpxrJzU+HjzqH1HJYPUMMiIxHCNgkchHiIFrF9XM6Y90Jzgcv9Ql690VU2oXRV/x58S+B4OXTgWl0Yt0+0ws0Kk6bQAAzQIHpxmv7Ol2VaPTHT5Ew+JLBY0NgVCr6pM= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772645788509457.39484069898515; Wed, 4 Mar 2026 09:36:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vxq8i-0003CN-9u; Wed, 04 Mar 2026 12:36:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxq8g-0003By-F3 for qemu-devel@nongnu.org; Wed, 04 Mar 2026 12:36:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxq8d-0004sC-5K for qemu-devel@nongnu.org; Wed, 04 Mar 2026 12:36:01 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-648-HKQLJMZtOHyBGUPV9aGh8A-1; Wed, 04 Mar 2026 12:35:51 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C80F7195609D; Wed, 4 Mar 2026 17:35:50 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.224.212]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BB7BF1958DC5; Wed, 4 Mar 2026 17:35:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772645755; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pJcBbWgk55Xy56aKGdb0PF2VLcZ2WdttuXvg1P3uOiQ=; b=B8e3STCCN8iVohedm3InJp5cMDC6IqmGiil/sUuw+q0iu+LPJmj4eDKM2a7Rx5IXFFZ5Jt BcMYFSu6Ao3BL//cRsWv9E1sP+5rDfmttHZkYE/h/xPkEdaTkPa9fSy5q+ZRMGs+fER2S5 OvhCU9BXESv9UOqUy4r4I0IsFOMM99I= X-MC-Unique: HKQLJMZtOHyBGUPV9aGh8A-1 X-Mimecast-MFC-AGG-ID: HKQLJMZtOHyBGUPV9aGh8A_1772645750 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Jason Wang , Dragos Tatulea DE , Jonah Palmer , "Michael S. Tsirkin" , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Lei Yang , Koushik Dutta , Stefano Garzarella , qemu-stable@nongnu.org, Cindy Lu , Maxime Coquelin Subject: [PATCH 2/7] vhost: move svq next desc array to descs state struct Date: Wed, 4 Mar 2026 18:35:30 +0100 Message-ID: <20260304173535.2702587-3-eperezma@redhat.com> In-Reply-To: <20260304173535.2702587-1-eperezma@redhat.com> References: <20260304173535.2702587-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 33 X-Spam_score: 3.3 X-Spam_bar: +++ X-Spam_report: (3.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.703, RCVD_IN_VALIDITY_SAFE_BLOCKED=1.386, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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 @redhat.com) X-ZM-MESSAGEID: 1772645790557158500 It's the right place for it as it is part of the descriptor state. We save the memory management of the array, and make the code changes of the next patches easier. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 14 ++++++-------- hw/virtio/vhost-shadow-virtqueue.h | 12 ++++++------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 6242aeb69c1a..901253d06e50 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -175,7 +175,7 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirt= queue *svq, hwaddr *sg, for (n =3D 0; n < num; n++) { if (more_descs || (n + 1 < num)) { descs[i].flags =3D flags | cpu_to_le16(VRING_DESC_F_NEXT); - descs[i].next =3D cpu_to_le16(svq->desc_next[i]); + descs[i].next =3D cpu_to_le16(svq->desc_state[i].next); } else { descs[i].flags =3D flags; } @@ -183,10 +183,10 @@ static bool vhost_svq_vring_write_descs(VhostShadowVi= rtqueue *svq, hwaddr *sg, descs[i].len =3D cpu_to_le32(iovec[n].iov_len); =20 last =3D i; - i =3D svq->desc_next[i]; + i =3D svq->desc_state[i].next; } =20 - svq->free_head =3D svq->desc_next[last]; + svq->free_head =3D svq->desc_state[last].next; return true; } =20 @@ -432,7 +432,7 @@ static uint16_t vhost_svq_last_desc_of_chain(const Vhos= tShadowVirtqueue *svq, uint16_t num, uint16_t i) { for (uint16_t j =3D 0; j < (num - 1); ++j) { - i =3D svq->desc_next[i]; + i =3D svq->desc_state[i].next; } =20 return i; @@ -473,7 +473,7 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadowV= irtqueue *svq, num =3D svq->desc_state[used_elem.id].ndescs; svq->desc_state[used_elem.id].ndescs =3D 0; last_used_chain =3D vhost_svq_last_desc_of_chain(svq, num, used_elem.i= d); - svq->desc_next[last_used_chain] =3D svq->free_head; + svq->desc_state[last_used_chain].next =3D svq->free_head; svq->free_head =3D used_elem.id; svq->num_free +=3D num; =20 @@ -705,9 +705,8 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIOD= evice *vdev, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYM= OUS, -1, 0); svq->desc_state =3D g_new0(SVQDescState, svq->vring.num); - svq->desc_next =3D g_new0(uint16_t, svq->vring.num); for (unsigned i =3D 0; i < svq->vring.num - 1; i++) { - svq->desc_next[i] =3D i + 1; + svq->desc_state[i].next =3D i + 1; } } =20 @@ -744,7 +743,6 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) virtqueue_unpop(svq->vq, next_avail_elem, 0); } svq->vq =3D NULL; - g_free(svq->desc_next); g_free(svq->desc_state); munmap(svq->vring.desc, vhost_svq_driver_area_size(svq)); munmap(svq->vring.used, vhost_svq_device_area_size(svq)); diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 9c273739d6df..f52c33e65046 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -23,6 +23,12 @@ typedef struct SVQDescState { * guest's */ unsigned int ndescs; + + /* + * Backup next field for each descriptor so we can recover securely, n= ot + * needing to trust the device access. + */ + uint16_t next; } SVQDescState; =20 typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; @@ -84,12 +90,6 @@ typedef struct VhostShadowVirtqueue { /* Next VirtQueue element that guest made available */ VirtQueueElement *next_guest_avail_elem; =20 - /* - * Backup next field for each descriptor so we can recover securely, n= ot - * needing to trust the device access. - */ - uint16_t *desc_next; - /* Caller callbacks */ const VhostShadowVirtqueueOps *ops; =20 --=20 2.53.0 From nobody Sat Apr 11 21:30:07 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1772645890; cv=none; d=zohomail.com; s=zohoarc; b=LZ6qQ+oPtvPJ/4NO5d/Y5QnNUF1FnelXY3gm32t2QZCo/+RJfFPvHDKK5lSCbobnMpV0yR7uNLcAAaO3iNowhCm/s51oNuqFPwfvpJ+D4DZdEK8jPPT8yryiKt8Zc8MT4AnezI+PTpmOnk+6CheWHwy8mOrAJpSX9uw8rpcwWv4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772645890; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=EzDXKMg2pefPTIknL0wUIxM1JWnVeUAX/c1HcIFUrMc=; b=Pea0L7RHQSm6ISYdiflNcsphogqQ49gMzco8O8VMShHGlaPeQysNFbGo1nkL+7FJBkbow8jwGPDJ3yTVP22ZsJOJmNFXCD9pls/GaBXgL9X/PNPsXDMMtkLK+yPyT+XicC6nWBym2wT1F3SBhtkJDXr6DS6rODdbLF15aGVgzso= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772645890743440.39304234415295; Wed, 4 Mar 2026 09:38:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vxq8y-0003JT-6J; Wed, 04 Mar 2026 12:36:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxq8k-0003Ca-KS for qemu-devel@nongnu.org; Wed, 04 Mar 2026 12:36:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxq8g-0004sy-5L for qemu-devel@nongnu.org; Wed, 04 Mar 2026 12:36:05 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-395-ArCh8zowPi-My8UpH2SOYQ-1; Wed, 04 Mar 2026 12:35:56 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4B1B419560A1; Wed, 4 Mar 2026 17:35:55 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.224.212]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4E3951958DC7; Wed, 4 Mar 2026 17:35:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772645759; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EzDXKMg2pefPTIknL0wUIxM1JWnVeUAX/c1HcIFUrMc=; b=dNMQo8/NcfEKAKVJYUfsukw9T9Z/IP2asNb6bVgasqWOgH0TbfVyMx3Wfnt1f2xeQ/x1ws DycjqZCRPg+pCV5S1n1Iu8hmp+8wu2pnyy19ETk8NvuaXB47FlSt5B5oEYAStWrLPJyzth MYSKiu8JQ3H81IwiwqlyrnzA13YnXio= X-MC-Unique: ArCh8zowPi-My8UpH2SOYQ-1 X-Mimecast-MFC-AGG-ID: ArCh8zowPi-My8UpH2SOYQ_1772645755 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Jason Wang , Dragos Tatulea DE , Jonah Palmer , "Michael S. Tsirkin" , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Lei Yang , Koushik Dutta , Stefano Garzarella , qemu-stable@nongnu.org, Cindy Lu , Maxime Coquelin Subject: [PATCH 3/7] vhost: factor out the descriptor next fetching Date: Wed, 4 Mar 2026 18:35:31 +0100 Message-ID: <20260304173535.2702587-4-eperezma@redhat.com> In-Reply-To: <20260304173535.2702587-1-eperezma@redhat.com> References: <20260304173535.2702587-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 33 X-Spam_score: 3.3 X-Spam_bar: +++ X-Spam_report: (3.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.703, RCVD_IN_VALIDITY_SAFE_BLOCKED=1.386, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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 @redhat.com) X-ZM-MESSAGEID: 1772645892766158500 The next field will not be used if IN_ORDER is enabled. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 901253d06e50..7adacd4f542a 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -139,6 +139,20 @@ static bool vhost_svq_translate_addr(const VhostShadow= Virtqueue *svq, return true; } =20 +/** + * Get the next descriptor in the chain in SVQ vring from a descriptor id + * + * @svq Shadow Virtqueue + * @id ID of the descriptor + * + * Return the id of the next descriptor. + */ +static uint16_t vhost_svq_next_desc(const VhostShadowVirtqueue *svq, + uint16_t id) +{ + return svq->desc_state[id].next; +} + /** * Write descriptors to SVQ vring * @@ -173,9 +187,11 @@ static bool vhost_svq_vring_write_descs(VhostShadowVir= tqueue *svq, hwaddr *sg, } =20 for (n =3D 0; n < num; n++) { + uint16_t next =3D vhost_svq_next_desc(svq, i); + if (more_descs || (n + 1 < num)) { descs[i].flags =3D flags | cpu_to_le16(VRING_DESC_F_NEXT); - descs[i].next =3D cpu_to_le16(svq->desc_state[i].next); + descs[i].next =3D cpu_to_le16(next); } else { descs[i].flags =3D flags; } @@ -183,10 +199,10 @@ static bool vhost_svq_vring_write_descs(VhostShadowVi= rtqueue *svq, hwaddr *sg, descs[i].len =3D cpu_to_le32(iovec[n].iov_len); =20 last =3D i; - i =3D svq->desc_state[i].next; + i =3D next; } =20 - svq->free_head =3D svq->desc_state[last].next; + svq->free_head =3D vhost_svq_next_desc(svq, last); return true; } =20 @@ -432,7 +448,7 @@ static uint16_t vhost_svq_last_desc_of_chain(const Vhos= tShadowVirtqueue *svq, uint16_t num, uint16_t i) { for (uint16_t j =3D 0; j < (num - 1); ++j) { - i =3D svq->desc_state[i].next; + i =3D vhost_svq_next_desc(svq, i); } =20 return i; --=20 2.53.0 From nobody Sat Apr 11 21:30:07 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1772645891; cv=none; d=zohomail.com; s=zohoarc; b=H4HcMQaVWN+Jw9REgD+N/S69/kObdfXu0axclMssD61SdclHIWek3Glf/tjdJzQce+Vx7aYf2TafYN0PFYhjqSrtO5BlAYGX8GLO0O+gdG6rvV5eAL+hSXbD6u4WE1i2N8A45ceRu548EGvw+M2Dee+gX0MRosNgcnPiDtpJzq0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772645891; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jAOW4K1EpW75YeuYdYjpjD4JVh2qQvzbdBEf2KCXE/Q=; b=WiKTHkyK2Z9U268Zfa1x8bW38ficDroUHLPUuMXYF18Gez7LZ0gf0potztgeqbnqoAzoHt3mv1A0P1K9wB8PuMRCH5/UzYKu5fiQJ927/3hJFJoD3oh+x/6nz3aFIqsY9YqMMcu/OHNmv2FNPndEIgIfT6Y7ojgeVi8O9YBsq2k= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772645891181644.3771326249997; Wed, 4 Mar 2026 09:38:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vxq8y-0003JU-61; Wed, 04 Mar 2026 12:36:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxq8k-0003Cd-Ox for qemu-devel@nongnu.org; Wed, 04 Mar 2026 12:36:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxq8j-0004tu-30 for qemu-devel@nongnu.org; Wed, 04 Mar 2026 12:36:06 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-177-9AtE4JQEOXG_we_zdqTudA-1; Wed, 04 Mar 2026 12:36:01 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E56D319560B5; Wed, 4 Mar 2026 17:35:59 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.224.212]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C55D81958DC5; Wed, 4 Mar 2026 17:35:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772645764; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jAOW4K1EpW75YeuYdYjpjD4JVh2qQvzbdBEf2KCXE/Q=; b=V3u1J747omeN+D3eaAJj1bCx6yAeymcf4S6b2Jz/mBc87AZHlCdKoD+tgDLVyiK3btWPQ0 84B/BaGYtKNkbZonHWOZz56ig7NCLhYVnJTMwuvfCPahj5Vrg128R4cm2PiROb3V4mhe+f yZAE1UBles5l0viupP/h8z+yMnw4nBQ= X-MC-Unique: 9AtE4JQEOXG_we_zdqTudA-1 X-Mimecast-MFC-AGG-ID: 9AtE4JQEOXG_we_zdqTudA_1772645760 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Jason Wang , Dragos Tatulea DE , Jonah Palmer , "Michael S. Tsirkin" , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Lei Yang , Koushik Dutta , Stefano Garzarella , qemu-stable@nongnu.org, Cindy Lu , Maxime Coquelin Subject: [PATCH 4/7] vhost: factor out the get of last used desc in SVQ Date: Wed, 4 Mar 2026 18:35:32 +0100 Message-ID: <20260304173535.2702587-5-eperezma@redhat.com> In-Reply-To: <20260304173535.2702587-1-eperezma@redhat.com> References: <20260304173535.2702587-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 33 X-Spam_score: 3.3 X-Spam_bar: +++ X-Spam_report: (3.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.703, RCVD_IN_VALIDITY_SAFE_BLOCKED=1.386, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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 @redhat.com) X-ZM-MESSAGEID: 1772645892788158500 This code path is modified to handle in order devices. Abstract here so we can generalize on the caller. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.c | 45 +++++++++++++++++++----------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 7adacd4f542a..e7e3c9155cd0 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -444,6 +444,25 @@ static void vhost_svq_disable_notification(VhostShadow= Virtqueue *svq) } } =20 +/* + * Gets the next buffer id and moves forward the used idx, so the next time + * SVQ calls this function will get the next one. + * + * @svq: Shadow VirtQueue + * @len: Consumed length by the device. + * + * Return the next descriptor consumed by the device. + */ +static uint16_t vhost_svq_get_last_used_split(VhostShadowVirtqueue *svq, + uint32_t *len) +{ + const vring_used_t *used =3D svq->vring.used; + uint16_t last_used =3D svq->last_used_idx++ & (svq->vring.num - 1); + + *len =3D le32_to_cpu(used->ring[last_used].len); + return le32_to_cpu(used->ring[last_used].id); +} + static uint16_t vhost_svq_last_desc_of_chain(const VhostShadowVirtqueue *s= vq, uint16_t num, uint16_t i) { @@ -458,8 +477,6 @@ G_GNUC_WARN_UNUSED_RESULT static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq, uint32_t *len) { - const vring_used_t *used =3D svq->vring.used; - vring_used_elem_t used_elem; uint16_t last_used, last_used_chain, num; =20 if (!vhost_svq_more_used(svq)) { @@ -468,33 +485,29 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShado= wVirtqueue *svq, =20 /* Only get used array entries after they have been exposed by dev */ smp_rmb(); - last_used =3D svq->last_used_idx & (svq->vring.num - 1); - used_elem.id =3D le32_to_cpu(used->ring[last_used].id); - used_elem.len =3D le32_to_cpu(used->ring[last_used].len); + last_used =3D vhost_svq_get_last_used_split(svq, len); =20 - svq->last_used_idx++; - if (unlikely(used_elem.id >=3D svq->vring.num)) { + if (unlikely(last_used >=3D svq->vring.num)) { qemu_log_mask(LOG_GUEST_ERROR, "Device %s says index %u is used", - svq->vdev->name, used_elem.id); + svq->vdev->name, last_used); return NULL; } =20 - if (unlikely(!svq->desc_state[used_elem.id].ndescs)) { + if (unlikely(!svq->desc_state[last_used].ndescs)) { qemu_log_mask(LOG_GUEST_ERROR, "Device %s says index %u is used, but it was not available", - svq->vdev->name, used_elem.id); + svq->vdev->name, last_used); return NULL; } =20 - num =3D svq->desc_state[used_elem.id].ndescs; - svq->desc_state[used_elem.id].ndescs =3D 0; - last_used_chain =3D vhost_svq_last_desc_of_chain(svq, num, used_elem.i= d); + num =3D svq->desc_state[last_used].ndescs; + svq->desc_state[last_used].ndescs =3D 0; + last_used_chain =3D vhost_svq_last_desc_of_chain(svq, num, last_used); svq->desc_state[last_used_chain].next =3D svq->free_head; - svq->free_head =3D used_elem.id; + svq->free_head =3D last_used; svq->num_free +=3D num; =20 - *len =3D used_elem.len; - return g_steal_pointer(&svq->desc_state[used_elem.id].elem); + return g_steal_pointer(&svq->desc_state[last_used].elem); } =20 /** --=20 2.53.0 From nobody Sat Apr 11 21:30:07 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1772645815; cv=none; d=zohomail.com; s=zohoarc; b=HmoiAb4aGRG7k08erdTwKK+2Qy7c+6OEr2gPJFD1aa9D9B6Cn+UkAs7xfF7WEq6b+pmbFkbPe8djnOj2KyjrPhHaKcHPvGDBLP3GSVfbv66bSgax23ZFMHbGjHXExkZE+v7GptV0aIPC0TLUwJny1dFikNroquz+P1cSlMxjYOI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772645815; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CH5QCvElWuMKlv3q8MrRwa9vvlKsZCp58YnKNPAF+ZU=; b=PKndcWxWzdj5fQyqRTMMYpsIxJGqTGcA9uBHf7cl+mCp9ucVICCHT/bb1qpx7xv79k7DHlfRgnrZ/2KmiN+23cihKlBa/L5sK70ch9FWaZClFiKX7PHTiHGNh/Flo0x7o5+kyq28/aLK7IFf/EXqfB6JObrP97Ng7I9gE1+Gnos= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772645815521577.8611765196408; Wed, 4 Mar 2026 09:36:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vxq90-0003MU-Fa; Wed, 04 Mar 2026 12:36:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxq8n-0003De-P0 for qemu-devel@nongnu.org; Wed, 04 Mar 2026 12:36:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxq8l-0004uk-Ho for qemu-devel@nongnu.org; Wed, 04 Mar 2026 12:36:09 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-553--pSsULqLMf2bfkhrxF4vdg-1; Wed, 04 Mar 2026 12:36:05 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5BACD18005B4; Wed, 4 Mar 2026 17:36:04 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.224.212]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6C70D1958DC5; Wed, 4 Mar 2026 17:36:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772645766; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CH5QCvElWuMKlv3q8MrRwa9vvlKsZCp58YnKNPAF+ZU=; b=JQ14q7HPvBIpwqcCC5B9rufPvQXLUcXhxs18Mn2nqnk2L4OLT2T80uiYfo5XFZFIJv0F62 hlBQdbZsSVB2rV78t3Cblkx8iUdh/Sw8d4F7+jUVDLkwvi1FENKW/5Nc5kF3IJjI28F/rN QzVQDwRtmKWYHLWaE/lP2PMNnK1URRE= X-MC-Unique: -pSsULqLMf2bfkhrxF4vdg-1 X-Mimecast-MFC-AGG-ID: -pSsULqLMf2bfkhrxF4vdg_1772645764 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Jason Wang , Dragos Tatulea DE , Jonah Palmer , "Michael S. Tsirkin" , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Lei Yang , Koushik Dutta , Stefano Garzarella , qemu-stable@nongnu.org, Cindy Lu , Maxime Coquelin Subject: [PATCH 5/7] vhost: factor out the detach buf logic in SVQ Date: Wed, 4 Mar 2026 18:35:33 +0100 Message-ID: <20260304173535.2702587-6-eperezma@redhat.com> In-Reply-To: <20260304173535.2702587-1-eperezma@redhat.com> References: <20260304173535.2702587-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 0 X-Spam_score: -0.0 X-Spam_bar: / X-Spam_report: (-0.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.703, RCVD_IN_VALIDITY_SAFE_BLOCKED=1.386, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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 @redhat.com) X-ZM-MESSAGEID: 1772645818710158500 This code path is modified to handle in order devices. Abstract here so we can generalize on the caller. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index e7e3c9155cd0..2d8fc82cc06f 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -473,11 +473,24 @@ static uint16_t vhost_svq_last_desc_of_chain(const Vh= ostShadowVirtqueue *svq, return i; } =20 +G_GNUC_WARN_UNUSED_RESULT +static VirtQueueElement *vhost_svq_detach_buf(VhostShadowVirtqueue *svq, + uint16_t id) +{ + uint16_t num =3D svq->desc_state[id].ndescs; + uint16_t last_used_chain =3D vhost_svq_last_desc_of_chain(svq, num, id= ); + + svq->desc_state[last_used_chain].next =3D svq->free_head; + svq->free_head =3D id; + + return g_steal_pointer(&svq->desc_state[id].elem); +} + G_GNUC_WARN_UNUSED_RESULT static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq, uint32_t *len) { - uint16_t last_used, last_used_chain, num; + uint16_t last_used; =20 if (!vhost_svq_more_used(svq)) { return NULL; @@ -500,14 +513,9 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadow= Virtqueue *svq, return NULL; } =20 - num =3D svq->desc_state[last_used].ndescs; + svq->num_free +=3D svq->desc_state[last_used].ndescs; svq->desc_state[last_used].ndescs =3D 0; - last_used_chain =3D vhost_svq_last_desc_of_chain(svq, num, last_used); - svq->desc_state[last_used_chain].next =3D svq->free_head; - svq->free_head =3D last_used; - svq->num_free +=3D num; - - return g_steal_pointer(&svq->desc_state[last_used].elem); + return vhost_svq_detach_buf(svq, last_used); } =20 /** --=20 2.53.0 From nobody Sat Apr 11 21:30:07 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1772645873; cv=none; d=zohomail.com; s=zohoarc; b=PhTy1iFBzYQ3Z3KK5njadzWV84YbsEC0534cpPLqNDkltr84ibVjGuxBf9e7LKN9z8qoVoSd1XeQW/cGCmTfXaeTZCQjhhA5Kv1oWvR2ojY1hjZEpKAzUu0ndofaBspife96SKRTGdypxjCJE5rWnuPsMDv32ze7J9w7SdWYLww= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772645873; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VtPai8/b13235tXiHfqfh6KX3mRBdNsS410cZ9nv1As=; b=Sl1DtM+p0XnPZBkDL/Jzy2kd6j8s7So74fTmBsoTcx5ev1256Rp1I3CVHAbu+U44wApO2Jr5tG2yl14B4w8AW8Bb3w6XLV9PFOUHXAcsH/YPb6m7twanbMD50CprgFzkjnr4QHY9f2cG8i1E4mMz+RMqYrYAIj67je9JuTOvByE= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772645873271324.0683844271575; Wed, 4 Mar 2026 09:37:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vxq98-0003U9-CM; Wed, 04 Mar 2026 12:36:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxq8t-0003FB-Fj for qemu-devel@nongnu.org; Wed, 04 Mar 2026 12:36:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxq8r-0004va-O6 for qemu-devel@nongnu.org; Wed, 04 Mar 2026 12:36:15 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-343-NGZdSyXtM3aQ7Mhj2w9U5A-1; Wed, 04 Mar 2026 12:36:09 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C72BC1956095; Wed, 4 Mar 2026 17:36:08 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.224.212]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D61591958DC5; Wed, 4 Mar 2026 17:36:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772645773; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VtPai8/b13235tXiHfqfh6KX3mRBdNsS410cZ9nv1As=; b=TVD3/zOa6h1UdszHl3E1LtIaS+E6LdK7Udv+/BSJiKC2KAvXOaRjo6Sj+0sqauy3k9oPWb 2r8twVsijdMGODclYvo5d4aRUZatYC0VZWq8FYsfi6wru59mNKheiAbYP1d1f0mZ6Mz9lo rEN4xavDasBugxTgWPhB01KgBuRCZZ4= X-MC-Unique: NGZdSyXtM3aQ7Mhj2w9U5A-1 X-Mimecast-MFC-AGG-ID: NGZdSyXtM3aQ7Mhj2w9U5A_1772645768 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Jason Wang , Dragos Tatulea DE , Jonah Palmer , "Michael S. Tsirkin" , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Lei Yang , Koushik Dutta , Stefano Garzarella , qemu-stable@nongnu.org, Cindy Lu , Maxime Coquelin Subject: [PATCH 6/7] vhost: add in_order feature to shadow virtqueue Date: Wed, 4 Mar 2026 18:35:34 +0100 Message-ID: <20260304173535.2702587-7-eperezma@redhat.com> In-Reply-To: <20260304173535.2702587-1-eperezma@redhat.com> References: <20260304173535.2702587-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 33 X-Spam_score: 3.3 X-Spam_bar: +++ X-Spam_report: (3.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.703, RCVD_IN_VALIDITY_SAFE_BLOCKED=1.386, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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 @redhat.com) X-ZM-MESSAGEID: 1772645875429139100 Some vdpa devices benefit from the in order feature. Add support to SVQ so QEMU can migrate these. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 137 +++++++++++++++++++++++++++-- hw/virtio/vhost-shadow-virtqueue.h | 36 ++++++-- 2 files changed, 160 insertions(+), 13 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 2d8fc82cc06f..60212fcd7bf3 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -12,11 +12,14 @@ =20 #include "qemu/error-report.h" #include "qapi/error.h" +#include "qemu/iov.h" #include "qemu/main-loop.h" #include "qemu/log.h" #include "qemu/memalign.h" #include "linux-headers/linux/vhost.h" =20 +#define VIRTIO_RING_NOT_IN_BATCH UINT16_MAX + /** * Validate the transport device features that both guests can use with th= e SVQ * and SVQs can use with the device. @@ -150,7 +153,33 @@ static bool vhost_svq_translate_addr(const VhostShadow= Virtqueue *svq, static uint16_t vhost_svq_next_desc(const VhostShadowVirtqueue *svq, uint16_t id) { - return svq->desc_state[id].next; + if (virtio_vdev_has_feature(svq->vdev, VIRTIO_F_IN_ORDER)) { + return (id =3D=3D svq->vring.num) ? 0 : ++id; + } else { + return svq->desc_state[id].next; + } +} + +/** + * Updates the SVQ free_head member after adding them to the SVQ avail rin= g. + * The new free_head is the next descriptor that SVQ will make available by + * forwarding a new guest descriptor. + * + * @svq Shadow Virtqueue + * @num Number of descriptors added + * @id ID of the last descriptor added to the SVQ avail ring. + */ +static void vhost_svq_update_free_head(VhostShadowVirtqueue *svq, + size_t num, uint16_t id) +{ + if (virtio_vdev_has_feature(svq->vdev, VIRTIO_F_IN_ORDER)) { + svq->free_head +=3D num; + if (svq->free_head >=3D svq->vring.num) { + svq->free_head -=3D svq->vring.num; + } + } else { + svq->free_head =3D vhost_svq_next_desc(svq, id); + } } =20 /** @@ -202,7 +231,7 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirt= queue *svq, hwaddr *sg, i =3D next; } =20 - svq->free_head =3D vhost_svq_next_desc(svq, last); + vhost_svq_update_free_head(svq, num, last); return true; } =20 @@ -306,6 +335,9 @@ int vhost_svq_add(VhostShadowVirtqueue *svq, const stru= ct iovec *out_sg, svq->num_free -=3D ndescs; svq->desc_state[qemu_head].elem =3D elem; svq->desc_state[qemu_head].ndescs =3D ndescs; + if (virtio_vdev_has_feature(svq->vdev, VIRTIO_F_IN_ORDER)) { + svq->desc_state[qemu_head].in_bytes =3D iov_size(in_sg, in_num); + } vhost_svq_kick(svq); return 0; } @@ -401,6 +433,12 @@ static void vhost_handle_guest_kick_notifier(EventNoti= fier *n) static bool vhost_svq_more_used(VhostShadowVirtqueue *svq) { uint16_t *used_idx =3D &svq->vring.used->idx; + + if (virtio_vdev_has_feature(svq->vdev, VIRTIO_F_IN_ORDER) && + svq->batch_last.id !=3D VIRTIO_RING_NOT_IN_BATCH) { + return true; + } + if (svq->last_used_idx !=3D svq->shadow_used_idx) { return true; } @@ -463,6 +501,47 @@ static uint16_t vhost_svq_get_last_used_split(VhostSha= dowVirtqueue *svq, return le32_to_cpu(used->ring[last_used].id); } =20 +/* + * Gets the next buffer id and moves forward the used idx, so the next time + * SVQ calls this function will get the next one. IN_ORDER version + * + * @svq: Shadow VirtQueue + * @len: Consumed length by the device. + * + * Return the next descriptor consumed by the device. + */ +static int32_t vhost_svq_get_last_used_split_in_order( + VhostShadowVirtqueue *svq, + uint32_t *len) +{ + unsigned num =3D svq->vring.num; + const vring_used_t *used =3D svq->vring.used; + uint16_t last_used =3D svq->last_used & (num - 1); + uint16_t last_used_idx =3D svq->last_used_idx & (num - 1); + + if (svq->batch_last.id =3D=3D VIRTIO_RING_NOT_IN_BATCH) { + svq->batch_last.id =3D le32_to_cpu(used->ring[last_used_idx].id); + svq->batch_last.len =3D le32_to_cpu(used->ring[last_used_idx].len); + } + + if (unlikely(last_used >=3D num)) { + qemu_log_mask(LOG_GUEST_ERROR, "Device %s says index %u is used", + svq->vdev->name, last_used); + return -1; + } + + if (svq->batch_last.id =3D=3D last_used) { + svq->batch_last.id =3D VIRTIO_RING_NOT_IN_BATCH; + *len =3D svq->batch_last.len; + } else { + *len =3D svq->desc_state[last_used].in_bytes; + } + + svq->last_used +=3D svq->desc_state[last_used].ndescs; + svq->last_used_idx++; + return last_used; +} + static uint16_t vhost_svq_last_desc_of_chain(const VhostShadowVirtqueue *s= vq, uint16_t num, uint16_t i) { @@ -474,8 +553,8 @@ static uint16_t vhost_svq_last_desc_of_chain(const Vhos= tShadowVirtqueue *svq, } =20 G_GNUC_WARN_UNUSED_RESULT -static VirtQueueElement *vhost_svq_detach_buf(VhostShadowVirtqueue *svq, - uint16_t id) +static VirtQueueElement *vhost_svq_detach_buf_split(VhostShadowVirtqueue *= svq, + uint16_t id) { uint16_t num =3D svq->desc_state[id].ndescs; uint16_t last_used_chain =3D vhost_svq_last_desc_of_chain(svq, num, id= ); @@ -486,6 +565,33 @@ static VirtQueueElement *vhost_svq_detach_buf(VhostSha= dowVirtqueue *svq, return g_steal_pointer(&svq->desc_state[id].elem); } =20 +G_GNUC_WARN_UNUSED_RESULT +static VirtQueueElement *vhost_svq_detach_buf_split_in_order( + VhostShadowVirtqueue *svq, + uint16_t id) +{ + return g_steal_pointer(&svq->desc_state[id].elem); +} + +/* + * Return the descriptor id (and the chain of ids) to the free list + * + * @svq: Shadow Virtqueue + * @id: Id of the buffer to return. + * + * Return the element associated to the buffer if any. + */ +G_GNUC_WARN_UNUSED_RESULT +static VirtQueueElement *vhost_svq_detach_buf(VhostShadowVirtqueue *svq, + uint16_t id) +{ + if (virtio_vdev_has_feature(svq->vdev, VIRTIO_F_IN_ORDER)) { + return vhost_svq_detach_buf_split_in_order(svq, id); + } else { + return vhost_svq_detach_buf_split(svq, id); + } +} + G_GNUC_WARN_UNUSED_RESULT static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq, uint32_t *len) @@ -498,7 +604,18 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadow= Virtqueue *svq, =20 /* Only get used array entries after they have been exposed by dev */ smp_rmb(); - last_used =3D vhost_svq_get_last_used_split(svq, len); + + if (virtio_vdev_has_feature(svq->vdev, VIRTIO_F_IN_ORDER)) { + int32_t r; + r =3D vhost_svq_get_last_used_split_in_order(svq, len); + if (r < 0) { + return NULL; + } + + last_used =3D r; + } else { + last_used =3D vhost_svq_get_last_used_split(svq, len); + } =20 if (unlikely(last_used >=3D svq->vring.num)) { qemu_log_mask(LOG_GUEST_ERROR, "Device %s says index %u is used", @@ -726,6 +843,8 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIOD= evice *vdev, svq->next_guest_avail_elem =3D NULL; svq->shadow_avail_idx =3D 0; svq->shadow_used_idx =3D 0; + memset(&svq->batch_last, 0, sizeof(svq->batch_last)); + svq->last_used =3D 0; svq->last_used_idx =3D 0; svq->vdev =3D vdev; svq->vq =3D vq; @@ -742,8 +861,12 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIO= Device *vdev, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYM= OUS, -1, 0); svq->desc_state =3D g_new0(SVQDescState, svq->vring.num); - for (unsigned i =3D 0; i < svq->vring.num - 1; i++) { - svq->desc_state[i].next =3D i + 1; + if (virtio_vdev_has_feature(svq->vdev, VIRTIO_F_IN_ORDER)) { + svq->batch_last.id =3D VIRTIO_RING_NOT_IN_BATCH; + } else { + for (unsigned i =3D 0; i < svq->vring.num - 1; i++) { + svq->desc_state[i].next =3D i + 1; + } } } =20 diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index f52c33e65046..ec16a1e83858 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -24,11 +24,19 @@ typedef struct SVQDescState { */ unsigned int ndescs; =20 - /* - * Backup next field for each descriptor so we can recover securely, n= ot - * needing to trust the device access. - */ - uint16_t next; + union { + /* + * Total length of the available buffer that is writable by the de= vice. + * Only used in packed vq. + */ + uint32_t in_bytes; + + /* + * Backup next field for each descriptor so we can recover securel= y, not + * needing to trust the device access. Only used in split vq. + */ + uint16_t next; + }; } SVQDescState; =20 typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; @@ -99,9 +107,25 @@ typedef struct VhostShadowVirtqueue { /* Next head to expose to the device */ uint16_t shadow_avail_idx; =20 - /* Next free descriptor */ + /* + * Next free descriptor. + * + * Without IN_ORDER free_head is used as a linked list head, and + * desc_next[id] is the next element. + * With IN_ORDER free_head is the next available buffer index. + */ uint16_t free_head; =20 + /* + * Last used element of the processing batch of used descriptors if + * IN_ORDER. + * If SVQ is not processing a batch of descriptors id is set to UINT_M= AX. + */ + vring_used_elem_t batch_last; + + /* Last used id if IN_ORDER and split vq */ + uint16_t last_used; + /* Last seen used idx */ uint16_t shadow_used_idx; =20 --=20 2.53.0 From nobody Sat Apr 11 21:30:07 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1772645801; cv=none; d=zohomail.com; s=zohoarc; b=FQ+zWlTZjMhFf4KIGtlNsaGF56UGB+C4z9fHlt4lloPNjn2+ou3qtn6hHNiQy7YmO8cd+i6+Nbo7B1gH9uU1V+UpM6RO1gGND7RExtmzUdxNabZLTPPBdAg4q1i76BhnvA7Jys7jepqZ2S1WTEH87FUhxlSS4W9LdjDoVG+rq/A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772645801; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=J1Ns80YWnorqMSyd8Ph1KA5Ic9bY2iXm7dP6tOz7QXo=; b=RlC99+KonqBOPckbO9Bk2B51s4kq5coepgUS/PJs75a/z9yxhUIuydf4gnmVbQUxxqTMH9oX3Y2VK+EabsCSZ/B27NsGbTEx5UDBzWvv+bgJROFMuXcnZdNw+j11FUBoVuFeOeVDxidKnPeDdl2mB1lJHQsKs4mnC8bgpAQJpcU= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177264580121415.187805009353497; Wed, 4 Mar 2026 09:36:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vxq95-0003Sb-JY; Wed, 04 Mar 2026 12:36:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxq91-0003N0-I2 for qemu-devel@nongnu.org; Wed, 04 Mar 2026 12:36:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxq8x-0004wO-Bt for qemu-devel@nongnu.org; Wed, 04 Mar 2026 12:36:23 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-455-MrwwfZYiPNizVJ-MqlVl5w-1; Wed, 04 Mar 2026 12:36:14 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6457B1956089; Wed, 4 Mar 2026 17:36:13 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.224.212]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4D9DB1958DC7; Wed, 4 Mar 2026 17:36:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772645777; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J1Ns80YWnorqMSyd8Ph1KA5Ic9bY2iXm7dP6tOz7QXo=; b=YTlfAyopJZmxf+1QvByAlqjhwYKEQqIciS3s4pjcfSR9ltPY6MDy6V7K9UJVZAi+FT3sG2 IW+k/6/HcnEu9YZx1k6z9vHLV2uQ5lxJVJNYuE4cmh2f96oRvhzbKOroPkFctexLPYun1a e+w2uFjcXCPIujfjXo8SM8xw+0CbAso= X-MC-Unique: MrwwfZYiPNizVJ-MqlVl5w-1 X-Mimecast-MFC-AGG-ID: MrwwfZYiPNizVJ-MqlVl5w_1772645773 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Jason Wang , Dragos Tatulea DE , Jonah Palmer , "Michael S. Tsirkin" , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Lei Yang , Koushik Dutta , Stefano Garzarella , qemu-stable@nongnu.org, Cindy Lu , Maxime Coquelin Subject: [PATCH 7/7] vhost: accept in order feature flag Date: Wed, 4 Mar 2026 18:35:35 +0100 Message-ID: <20260304173535.2702587-8-eperezma@redhat.com> In-Reply-To: <20260304173535.2702587-1-eperezma@redhat.com> References: <20260304173535.2702587-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 33 X-Spam_score: 3.3 X-Spam_bar: +++ X-Spam_report: (3.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.703, RCVD_IN_VALIDITY_SAFE_BLOCKED=1.386, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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 @redhat.com) X-ZM-MESSAGEID: 1772645802947139100 Let's accept the feature flag with all the infrastructure to process it in place. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- 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 60212fcd7bf3..bcb7f2ffc79f 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -38,6 +38,7 @@ bool vhost_svq_valid_features(uint64_t features, Error **= errp) case VIRTIO_F_ANY_LAYOUT: case VIRTIO_RING_F_EVENT_IDX: case VIRTIO_RING_F_INDIRECT_DESC: + case VIRTIO_F_IN_ORDER: continue; =20 case VIRTIO_F_ACCESS_PLATFORM: --=20 2.53.0