From nobody Sun Feb 8 13:45:28 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658140380; cv=none; d=zohomail.com; s=zohoarc; b=T4rw1et3eoDNGRTrLtCt0FMrOGzNiznj5U1QUeOixu4VptjUan7uWZh/bsTh2qQtvvflyFS8hmYgCl03L4TWAZubL2GKeA7s3V4zQlWHWlfEsU1vuV9fwSxCupyc+k4jved8ZsVy4CIhS3g4ryuYZk/8Gdw6CpwC2tufElKgtQo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658140380; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6L+zkqyrOy7sN7BmI3DCR8EYimimD4zP/iapI/JldHg=; b=irrTfRwGwG8HBPbTPgzT6EYDeOy88+DljIRGQ2rIfNL5AK9+NugW+I5Q24h5jJEmLN+AbGLGMpN5eWSzn4FvQ7v6JAZbzlVZ+LbZrtmAnt5w7PehFaNmOpU49SzDdtuKMlyVf5Y0bb6BVRI0VoAOcpscOznRfUsmG1jesWKUg80= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658140380288434.13723750236045; Mon, 18 Jul 2022 03:33:00 -0700 (PDT) Received: from localhost ([::1]:53906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDO3f-00037T-6N for importer@patchew.org; Mon, 18 Jul 2022 06:32:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54494) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO0u-0000Be-85 for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:45287) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO0r-0001Az-Ji for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:06 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-6-wqhSAfslMDmZzcIjBFFCBg-1; Mon, 18 Jul 2022 06:30:00 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1157885A584; Mon, 18 Jul 2022 10:30:00 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04BF92166B26; Mon, 18 Jul 2022 10:29:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658140204; 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=6L+zkqyrOy7sN7BmI3DCR8EYimimD4zP/iapI/JldHg=; b=QEtJ8TA/n4XzHZ55rSJ4ZUz8LnpJUZonk5mfiGquXOPAnOJjNBc7qmfgELciawUN2V7cfj ofhMo2a6ygFul/5L1wTqk02zPRxL+W38l3BPhxEh3rRMxrY516Nb+7Bw3DKsx8xAIizV7P DxFNC0/lat5PpYkWv5MirZ2jM2GcHHA= X-MC-Unique: wqhSAfslMDmZzcIjBFFCBg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Gautam Dawar , Cornelia Huck , Laurent Vivier , Paolo Bonzini , "Gonglei (Arei)" , Zhu Lingshan , Stefan Hajnoczi , Liuxiangdong , Jason Wang , Stefano Garzarella , Eli Cohen , Harpreet Singh Anand , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Parav Pandit Subject: [PATCH v4 01/19] vhost: move descriptor translation to vhost_svq_vring_write_descs Date: Mon, 18 Jul 2022 12:29:31 +0200 Message-Id: <20220718102949.2868267-2-eperezma@redhat.com> In-Reply-To: <20220718102949.2868267-1-eperezma@redhat.com> References: <20220718102949.2868267-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658140382381100001 It's done for both in and out descriptors so it's better placed here. Acked-by: Jason Wang Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.c | 38 +++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 56c96ebd13..e2184a4481 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -122,17 +122,35 @@ static bool vhost_svq_translate_addr(const VhostShado= wVirtqueue *svq, return true; } =20 -static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg, - const struct iovec *iovec, size_t num, - bool more_descs, bool write) +/** + * Write descriptors to SVQ vring + * + * @svq: The shadow virtqueue + * @sg: Cache for hwaddr + * @iovec: The iovec from the guest + * @num: iovec length + * @more_descs: True if more descriptors come in the chain + * @write: True if they are writeable descriptors + * + * Return true if success, false otherwise and print error. + */ +static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr = *sg, + const struct iovec *iovec, size_t = num, + bool more_descs, bool write) { uint16_t i =3D svq->free_head, last =3D svq->free_head; unsigned n; uint16_t flags =3D write ? cpu_to_le16(VRING_DESC_F_WRITE) : 0; vring_desc_t *descs =3D svq->vring.desc; + bool ok; =20 if (num =3D=3D 0) { - return; + return true; + } + + ok =3D vhost_svq_translate_addr(svq, sg, iovec, num); + if (unlikely(!ok)) { + return false; } =20 for (n =3D 0; n < num; n++) { @@ -150,6 +168,7 @@ static void vhost_vring_write_descs(VhostShadowVirtqueu= e *svq, hwaddr *sg, } =20 svq->free_head =3D le16_to_cpu(svq->desc_next[last]); + return true; } =20 static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, @@ -169,21 +188,18 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue = *svq, return false; } =20 - ok =3D vhost_svq_translate_addr(svq, sgs, elem->out_sg, elem->out_num); + ok =3D vhost_svq_vring_write_descs(svq, sgs, elem->out_sg, elem->out_n= um, + elem->in_num > 0, false); if (unlikely(!ok)) { return false; } - vhost_vring_write_descs(svq, sgs, elem->out_sg, elem->out_num, - elem->in_num > 0, false); - =20 - ok =3D vhost_svq_translate_addr(svq, sgs, elem->in_sg, elem->in_num); + ok =3D vhost_svq_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num= , false, + true); if (unlikely(!ok)) { return false; } =20 - vhost_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num, false, tr= ue); - /* * Put the entry in the available array (but don't update avail->idx u= ntil * they do sync). --=20 2.31.1 From nobody Sun Feb 8 13:45:28 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658140541; cv=none; d=zohomail.com; s=zohoarc; b=VVyYwlzYmv6/8K3KuK+IpUC1c9cX4azPs/N+KdGI0CtiMHDqntJbQapMY70MnSN4gugnfEyUV/2j1wNrqammgpWo689cqVOuTJ+gYadwPbOdFAgm10bXE87YMLqvlB0YHBIuZvGI2KUZgf/6ZrVPcanLjhGKyn9YDov+eZUujXc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658140541; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=90R/ykNmYemsZUIo8Txp8n7gclp9lHJx8ek2yyJR/wY=; b=VOskybmDPGrdRKT74QZMz/MSG/JskA4e8S6E4nBexyztjzWe3RpmCGuk0Q7vR7lMRPUAQsOc1U40XjtrPQoGLR81CUvGQlwSY67pj28D4h+DmrrbDiUUM5Xx2ZSEzUgb0CJPmmtPFHiGTaN4zwzw88dKPypmpZ57eO6X7DvQOqQ= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658140541747947.1913296545827; Mon, 18 Jul 2022 03:35:41 -0700 (PDT) Received: from localhost ([::1]:33540 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDO6E-0000RE-81 for importer@patchew.org; Mon, 18 Jul 2022 06:35:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO18-0000MT-DH for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26718) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO14-0001PN-E5 for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:21 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-450-fX6F-giGMYaXzKF_eTOcKA-1; Mon, 18 Jul 2022 06:30:05 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 554A4802D1C; Mon, 18 Jul 2022 10:30:05 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 862C02166B29; Mon, 18 Jul 2022 10:30:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658140216; 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=90R/ykNmYemsZUIo8Txp8n7gclp9lHJx8ek2yyJR/wY=; b=ORrp/xpo68+fc+rLVjHGqIyNBvVoiV0gVEgAYDazQZuzFZABpSjiOgMKSb/tN6u2Alr7iP wCV+FA9L1dVD5gKHuXh27h7RLLqgPP3X2f1cH4chLfm+SwovKYER/f4uruY7xBIQYQp0vo CTTcSHFYH/UhaM004s5NqxzlEcnsFLA= X-MC-Unique: fX6F-giGMYaXzKF_eTOcKA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Gautam Dawar , Cornelia Huck , Laurent Vivier , Paolo Bonzini , "Gonglei (Arei)" , Zhu Lingshan , Stefan Hajnoczi , Liuxiangdong , Jason Wang , Stefano Garzarella , Eli Cohen , Harpreet Singh Anand , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Parav Pandit Subject: [PATCH v4 02/19] virtio-net: Expose MAC_TABLE_ENTRIES Date: Mon, 18 Jul 2022 12:29:32 +0200 Message-Id: <20220718102949.2868267-3-eperezma@redhat.com> In-Reply-To: <20220718102949.2868267-1-eperezma@redhat.com> References: <20220718102949.2868267-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658140543069100001 vhost-vdpa control virtqueue needs to know the maximum entries supported by the virtio-net device, so we know if it is possible to apply the filter. Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/virtio-net.h | 3 +++ hw/net/virtio-net.c | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index eb87032627..cce1c554f7 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -35,6 +35,9 @@ OBJECT_DECLARE_SIMPLE_TYPE(VirtIONet, VIRTIO_NET) * and latency. */ #define TX_BURST 256 =20 +/* Maximum VIRTIO_NET_CTRL_MAC_TABLE_SET unicast + multicast entries. */ +#define MAC_TABLE_ENTRIES 64 + typedef struct virtio_net_conf { uint32_t txtimer; diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 7ad948ee7c..f83e96e4ce 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -49,7 +49,6 @@ =20 #define VIRTIO_NET_VM_VERSION 11 =20 -#define MAC_TABLE_ENTRIES 64 #define MAX_VLAN (1 << 12) /* Per 802.1Q definition */ =20 /* previously fixed value */ --=20 2.31.1 From nobody Sun Feb 8 13:45:28 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658140387; cv=none; d=zohomail.com; s=zohoarc; b=Ue83NAtuabpUzql0s0gJiU/+G1D0zG5dgbICJ0rqvusbMxBNXoM7LGakmizBD/lsYk06eIz/zsIymKyRmDBCUuzHlkixc80BdjI/8ytOEEFZilPY6OV+roVq9f1neXvM8Y96bhwVYQ7WM0lOeko66HdN+qUKuZwNRSF0BQB3cPs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658140387; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=h3mO/9TxV/PKzNbYdTqanE3vzAOu/fz5OE4rIndnbN0=; b=LdGmkxUvXuh4m8QHsVlzRvjDDA8N5sySxqFOxSxBlUwRt/Fkv1q7S8R2ceeUJhsMYjcls2EgEJ/R8Py4qOSF5STaooqZzNp3aelWZC0N7UiYkL+kyfi+vjLVlN+q9dAvDkuKP0HBximjxiBKwZOMJmNIJ9e8CuSm9CqSO7onjvQ= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658140387226532.8197591116523; Mon, 18 Jul 2022 03:33:07 -0700 (PDT) Received: from localhost ([::1]:54224 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDO3m-0003Ke-1e for importer@patchew.org; Mon, 18 Jul 2022 06:33:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO14-0000MS-LX for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:38604) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO10-0001OI-Ju for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:16 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-301-zwHxNkl5PaewDHQAqY-xbg-1; Mon, 18 Jul 2022 06:30:10 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3EE79101A54E; Mon, 18 Jul 2022 10:30:10 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE49A2166B2A; Mon, 18 Jul 2022 10:30:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658140214; 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=h3mO/9TxV/PKzNbYdTqanE3vzAOu/fz5OE4rIndnbN0=; b=MadsUFFH3cWQe85mWn9PzZUxS7HaZJZoa4+0+GkAQIP/FFiA1HvBx8NGhfwl42tE5k4ySm qEjFLLY5l9K2lJCrzsSPrTLuIOWn02SXerfbYzsR0MOq07yoHpQzBd4sETtJqmeYNBrtQc xa4M30tanGSsHzNfaKGTdshFIqzP2YQ= X-MC-Unique: zwHxNkl5PaewDHQAqY-xbg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Gautam Dawar , Cornelia Huck , Laurent Vivier , Paolo Bonzini , "Gonglei (Arei)" , Zhu Lingshan , Stefan Hajnoczi , Liuxiangdong , Jason Wang , Stefano Garzarella , Eli Cohen , Harpreet Singh Anand , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Parav Pandit Subject: [PATCH v4 03/19] virtio-net: Expose ctrl virtqueue logic Date: Mon, 18 Jul 2022 12:29:33 +0200 Message-Id: <20220718102949.2868267-4-eperezma@redhat.com> In-Reply-To: <20220718102949.2868267-1-eperezma@redhat.com> References: <20220718102949.2868267-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658140388279100001 This allows external vhost-net devices to modify the state of the VirtIO device model once the vhost-vdpa device has acknowledged the control commands. Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/virtio-net.h | 4 ++ hw/net/virtio-net.c | 84 ++++++++++++++++++++-------------- 2 files changed, 53 insertions(+), 35 deletions(-) diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index cce1c554f7..ef234ffe7e 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -221,6 +221,10 @@ struct VirtIONet { struct EBPFRSSContext ebpf_rss; }; =20 +size_t virtio_net_handle_ctrl_iov(VirtIODevice *vdev, + const struct iovec *in_sg, unsigned in_n= um, + const struct iovec *out_sg, + unsigned out_num); void virtio_net_set_netclient_name(VirtIONet *n, const char *name, const char *type); =20 diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index f83e96e4ce..dd0d056fde 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1433,57 +1433,71 @@ static int virtio_net_handle_mq(VirtIONet *n, uint8= _t cmd, return VIRTIO_NET_OK; } =20 -static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) +size_t virtio_net_handle_ctrl_iov(VirtIODevice *vdev, + const struct iovec *in_sg, unsigned in_n= um, + const struct iovec *out_sg, + unsigned out_num) { VirtIONet *n =3D VIRTIO_NET(vdev); struct virtio_net_ctrl_hdr ctrl; virtio_net_ctrl_ack status =3D VIRTIO_NET_ERR; - VirtQueueElement *elem; size_t s; struct iovec *iov, *iov2; - unsigned int iov_cnt; + + if (iov_size(in_sg, in_num) < sizeof(status) || + iov_size(out_sg, out_num) < sizeof(ctrl)) { + virtio_error(vdev, "virtio-net ctrl missing headers"); + return 0; + } + + iov2 =3D iov =3D g_memdup2(out_sg, sizeof(struct iovec) * out_num); + s =3D iov_to_buf(iov, out_num, 0, &ctrl, sizeof(ctrl)); + iov_discard_front(&iov, &out_num, sizeof(ctrl)); + if (s !=3D sizeof(ctrl)) { + status =3D VIRTIO_NET_ERR; + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_RX) { + status =3D virtio_net_handle_rx_mode(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_MAC) { + status =3D virtio_net_handle_mac(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_VLAN) { + status =3D virtio_net_handle_vlan_table(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_ANNOUNCE) { + status =3D virtio_net_handle_announce(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_MQ) { + status =3D virtio_net_handle_mq(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_GUEST_OFFLOADS) { + status =3D virtio_net_handle_offloads(n, ctrl.cmd, iov, out_num); + } + + s =3D iov_from_buf(in_sg, in_num, 0, &status, sizeof(status)); + assert(s =3D=3D sizeof(status)); + + g_free(iov2); + return sizeof(status); +} + +static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) +{ + VirtQueueElement *elem; =20 for (;;) { + size_t written; elem =3D virtqueue_pop(vq, sizeof(VirtQueueElement)); if (!elem) { break; } - if (iov_size(elem->in_sg, elem->in_num) < sizeof(status) || - iov_size(elem->out_sg, elem->out_num) < sizeof(ctrl)) { - virtio_error(vdev, "virtio-net ctrl missing headers"); + + written =3D virtio_net_handle_ctrl_iov(vdev, elem->in_sg, elem->in= _num, + elem->out_sg, elem->out_num); + if (written > 0) { + virtqueue_push(vq, elem, written); + virtio_notify(vdev, vq); + g_free(elem); + } else { virtqueue_detach_element(vq, elem, 0); g_free(elem); break; } - - iov_cnt =3D elem->out_num; - iov2 =3D iov =3D g_memdup2(elem->out_sg, - sizeof(struct iovec) * elem->out_num); - s =3D iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl)); - iov_discard_front(&iov, &iov_cnt, sizeof(ctrl)); - if (s !=3D sizeof(ctrl)) { - status =3D VIRTIO_NET_ERR; - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_RX) { - status =3D virtio_net_handle_rx_mode(n, ctrl.cmd, iov, iov_cnt= ); - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_MAC) { - status =3D virtio_net_handle_mac(n, ctrl.cmd, iov, iov_cnt); - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_VLAN) { - status =3D virtio_net_handle_vlan_table(n, ctrl.cmd, iov, iov_= cnt); - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_ANNOUNCE) { - status =3D virtio_net_handle_announce(n, ctrl.cmd, iov, iov_cn= t); - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_MQ) { - status =3D virtio_net_handle_mq(n, ctrl.cmd, iov, iov_cnt); - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_GUEST_OFFLOADS) { - status =3D virtio_net_handle_offloads(n, ctrl.cmd, iov, iov_cn= t); - } - - s =3D iov_from_buf(elem->in_sg, elem->in_num, 0, &status, sizeof(s= tatus)); - assert(s =3D=3D sizeof(status)); - - virtqueue_push(vq, elem, sizeof(status)); - virtio_notify(vdev, vq); - g_free(iov2); - g_free(elem); } } =20 --=20 2.31.1 From nobody Sun Feb 8 13:45:28 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658140543; cv=none; d=zohomail.com; s=zohoarc; b=jp20+uCuM+FyPeDrP70Jb2RvaA7fAAuiRvaUpgfeHnCkfhwDAbajlbN8JYxvxe14gYQC3K1Yh75r++oZK0OQpecXD88cHNSup3RApbwuNf2JngnvIimOLKv5UBni9pjkxIcNgU+PKKdY8YHa80DmvMwkNcxwEBb0p32QYspgUOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658140543; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+VFI7Qq3P0oJUhO9TZwdYJZr2TRLgQmgOa7NOJmaqao=; b=BQZQ+lPXaB52WlPehZKnMo0PwQ5a1h3cgJnvLDOwE+rtA7LqFaDgA4GRLX58tG+y/wLZ4vYqLnerQOE0cmXzU/lqiCoh+QhMcLb1VySJOoZyOLzbAMwVDFhjcBTzWhPDWKayZGWRYQqtdC6n1QJ/u6ePhJcz354cT83OkBdRM8g= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658140543942798.0292026541487; Mon, 18 Jul 2022 03:35:43 -0700 (PDT) Received: from localhost ([::1]:33624 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDO6I-0000Uv-Vf for importer@patchew.org; Mon, 18 Jul 2022 06:35:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1B-0000Mx-Om for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:41602) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO16-0001RV-JK for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:21 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-528-MOsQpZlePP2NnezBuPnjhw-1; Mon, 18 Jul 2022 06:30:16 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 19AE4800124; Mon, 18 Jul 2022 10:30:16 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 946812166B26; Mon, 18 Jul 2022 10:30:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658140220; 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=+VFI7Qq3P0oJUhO9TZwdYJZr2TRLgQmgOa7NOJmaqao=; b=VHkslR5CEipm4/GV1MZs6iUnRQQAtZT8Sn/9TYXz30af6AZwZXH9gpAl5bGQIeK7KB+FOH mgBN/zdEvSEzPKuSttwW3rfPpzZ/+qxWv4J2dxFKdJuOWqwy+dZbHaCPxigTdmXg853gSL 7OfLEh9P77vLFhFb/nX0NA3KRypSyYw= X-MC-Unique: MOsQpZlePP2NnezBuPnjhw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Gautam Dawar , Cornelia Huck , Laurent Vivier , Paolo Bonzini , "Gonglei (Arei)" , Zhu Lingshan , Stefan Hajnoczi , Liuxiangdong , Jason Wang , Stefano Garzarella , Eli Cohen , Harpreet Singh Anand , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Parav Pandit Subject: [PATCH v4 04/19] vhost: Reorder vhost_svq_kick Date: Mon, 18 Jul 2022 12:29:34 +0200 Message-Id: <20220718102949.2868267-5-eperezma@redhat.com> In-Reply-To: <20220718102949.2868267-1-eperezma@redhat.com> References: <20220718102949.2868267-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658140545077100003 Future code needs to call it from vhost_svq_add. No functional change intended. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index e2184a4481..fd1839cec5 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -215,6 +215,20 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *= svq, return true; } =20 +static void vhost_svq_kick(VhostShadowVirtqueue *svq) +{ + /* + * We need to expose the available array entries before checking the u= sed + * flags + */ + smp_mb(); + if (svq->vring.used->flags & VRING_USED_F_NO_NOTIFY) { + return; + } + + event_notifier_set(&svq->hdev_kick); +} + /** * Add an element to a SVQ. * @@ -235,20 +249,6 @@ static bool vhost_svq_add(VhostShadowVirtqueue *svq, V= irtQueueElement *elem) return true; } =20 -static void vhost_svq_kick(VhostShadowVirtqueue *svq) -{ - /* - * We need to expose the available array entries before checking the u= sed - * flags - */ - smp_mb(); - if (svq->vring.used->flags & VRING_USED_F_NO_NOTIFY) { - return; - } - - event_notifier_set(&svq->hdev_kick); -} - /** * Forward available buffers. * --=20 2.31.1 From nobody Sun Feb 8 13:45:28 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658140710; cv=none; d=zohomail.com; s=zohoarc; b=HU8j7tlxFXt/rDI+p3jpqxgNtFKPQS8IjnRjKlYbKnxSfzPj871rkX08M7MhIjNtNX2Y3s5RuLyBolCmS69w3N4yI7jCJ95+eM7iukO97MJRzVRo/zNeFVLVXyswEvrZOKGHfIA6zqadEFa9knanEW7UBDHC9VSi/57apPucFPM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658140710; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AH1DRAWSo4t+6SKOVbKYa3vPTjPK7Y8QfCcr5er7RkY=; b=khwQCxY5eLkirEqNLfT0vigAT6NIiAHdrVnsABBYPQYYDfV1GfEDWuImPqtmM8KyloVwXIaWpFVhmansdUkWva35Gtx/cR2SuJqks2Ovw4w7lkNxIL89y501rknkIuzLfAQ6NLQyyn0ykZRp3btGPxwKfu9UGl/50PrkV8szqi4= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658140710139149.89749806373493; Mon, 18 Jul 2022 03:38:30 -0700 (PDT) Received: from localhost ([::1]:41742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDO8z-0006H4-3g for importer@patchew.org; Mon, 18 Jul 2022 06:38:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54654) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1F-0000OL-IV for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:57070) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1B-0001UM-HV for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:27 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-592-4v_nluvyOQ-KLibaTFnRIQ-1; Mon, 18 Jul 2022 06:30:21 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 54E078037AC; Mon, 18 Jul 2022 10:30:21 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7FE832166B26; Mon, 18 Jul 2022 10:30:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658140224; 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=AH1DRAWSo4t+6SKOVbKYa3vPTjPK7Y8QfCcr5er7RkY=; b=fBelYHI1MKOtxvKjCPfl/h+YSDdSFEl+m1YcvNG/UL6zcMbCdM5wl4iXtdpzeb795hbh7w i5lBG13vlzZkFDqpgQ6tbmQAixAsB+aBOYlI+hz6SL0izf2JuDkGneIfSyUO2C5WL5Dtbq 7BHGoNXigCCXkhigSr8pQiL17fnDy6I= X-MC-Unique: 4v_nluvyOQ-KLibaTFnRIQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Gautam Dawar , Cornelia Huck , Laurent Vivier , Paolo Bonzini , "Gonglei (Arei)" , Zhu Lingshan , Stefan Hajnoczi , Liuxiangdong , Jason Wang , Stefano Garzarella , Eli Cohen , Harpreet Singh Anand , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Parav Pandit Subject: [PATCH v4 05/19] vhost: Move vhost_svq_kick call to vhost_svq_add Date: Mon, 18 Jul 2022 12:29:35 +0200 Message-Id: <20220718102949.2868267-6-eperezma@redhat.com> In-Reply-To: <20220718102949.2868267-1-eperezma@redhat.com> References: <20220718102949.2868267-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658140712034100003 The series needs to expose vhost_svq_add with full functionality, including kick Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index fd1839cec5..e5a4a62daa 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -246,6 +246,7 @@ static bool vhost_svq_add(VhostShadowVirtqueue *svq, Vi= rtQueueElement *elem) } =20 svq->ring_id_maps[qemu_head] =3D elem; + vhost_svq_kick(svq); return true; } =20 @@ -306,7 +307,6 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueu= e *svq) /* VQ is broken, just return and ignore any other kicks */ return; } - vhost_svq_kick(svq); } =20 virtio_queue_set_notification(svq->vq, true); --=20 2.31.1 From nobody Sun Feb 8 13:45:28 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658140558; cv=none; d=zohomail.com; s=zohoarc; b=DpO+9W2at03SxI61r67kY+4LX4RoBfJL42KRRX8u9p9rwImk64v/cpENBySU0398rvl2eQ+ktOANsV6V5J4psSm+uSg8+JuzJx2NvITCc85Rw/rguB00Y0PMWrvrGYdR6OMgHlGyagsCduV85Nkw7H5YvCTTgvsroM7qlTyn5So= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658140558; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3nkoou4Oxj4dhaj1rNXqI5e5LTCePj0MM4Qd4yCljRo=; b=O52iFGT5n1yTi/ncb1rnCV4OHBOK2isAnI+mFJo+7I1+BJlafBqKigKFe+BBs41RhZwGUtIufSZJ0c9p81s50i3bLrTzmAsShGKb1LM8X8wiH8z3StoAPvUpNUoAJoQeHOT1HxaFDtF85ZitBpDoU1XaBRaEemM1WmdXshbgGWk= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658140558400191.60034490707335; Mon, 18 Jul 2022 03:35:58 -0700 (PDT) Received: from localhost ([::1]:34284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDO6X-0000x1-Cu for importer@patchew.org; Mon, 18 Jul 2022 06:35:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54672) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1I-0000P8-VO for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26921) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1G-0001Ul-7p for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:31 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-608-iaa9i98mNBKtdbCxQkRIhQ-1; Mon, 18 Jul 2022 06:30:25 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DC72E3C0D187; Mon, 18 Jul 2022 10:30:24 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id A20912166B26; Mon, 18 Jul 2022 10:30:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658140229; 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=3nkoou4Oxj4dhaj1rNXqI5e5LTCePj0MM4Qd4yCljRo=; b=alIQfcqR71HmKVLwxi2U1QKkeCx4RIXCLOOUHXD3ID70mcpxn1o6H2+N4eNbzGgpOy1/bR M88mMsCGMLM2PU/Wp/yAVyXFpazUMdL5SezCu69EAAwCwLGqUQttaurj1vHWt9SPRIwvnn 3Vyh5YxymmpS/i1njgKN8mKrxguUkfA= X-MC-Unique: iaa9i98mNBKtdbCxQkRIhQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Gautam Dawar , Cornelia Huck , Laurent Vivier , Paolo Bonzini , "Gonglei (Arei)" , Zhu Lingshan , Stefan Hajnoczi , Liuxiangdong , Jason Wang , Stefano Garzarella , Eli Cohen , Harpreet Singh Anand , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Parav Pandit Subject: [PATCH v4 06/19] vhost: Check for queue full at vhost_svq_add Date: Mon, 18 Jul 2022 12:29:36 +0200 Message-Id: <20220718102949.2868267-7-eperezma@redhat.com> In-Reply-To: <20220718102949.2868267-1-eperezma@redhat.com> References: <20220718102949.2868267-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658140559164100001 The series need to expose vhost_svq_add with full functionality, including checking for full queue. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.c | 59 +++++++++++++++++------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index e5a4a62daa..aee9891a67 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -233,21 +233,29 @@ static void vhost_svq_kick(VhostShadowVirtqueue *svq) * Add an element to a SVQ. * * The caller must check that there is enough slots for the new element. It - * takes ownership of the element: In case of failure, it is free and the = SVQ - * is considered broken. + * takes ownership of the element: In case of failure not ENOSPC, it is fr= ee. + * + * Return -EINVAL if element is invalid, -ENOSPC if dev queue is full */ -static bool vhost_svq_add(VhostShadowVirtqueue *svq, VirtQueueElement *ele= m) +static int vhost_svq_add(VhostShadowVirtqueue *svq, VirtQueueElement *elem) { unsigned qemu_head; - bool ok =3D vhost_svq_add_split(svq, elem, &qemu_head); + unsigned ndescs =3D elem->in_num + elem->out_num; + bool ok; + + if (unlikely(ndescs > vhost_svq_available_slots(svq))) { + return -ENOSPC; + } + + ok =3D vhost_svq_add_split(svq, elem, &qemu_head); if (unlikely(!ok)) { g_free(elem); - return false; + return -EINVAL; } =20 svq->ring_id_maps[qemu_head] =3D elem; vhost_svq_kick(svq); - return true; + return 0; } =20 /** @@ -274,7 +282,7 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueu= e *svq) =20 while (true) { VirtQueueElement *elem; - bool ok; + int r; =20 if (svq->next_guest_avail_elem) { elem =3D g_steal_pointer(&svq->next_guest_avail_elem); @@ -286,25 +294,24 @@ static void vhost_handle_guest_kick(VhostShadowVirtqu= eue *svq) break; } =20 - if (elem->out_num + elem->in_num > vhost_svq_available_slots(s= vq)) { - /* - * This condition is possible since a contiguous buffer in= GPA - * does not imply a contiguous buffer in qemu's VA - * scatter-gather segments. If that happens, the buffer ex= posed - * to the device needs to be a chain of descriptors at this - * moment. - * - * SVQ cannot hold more available buffers if we are here: - * queue the current guest descriptor and ignore further k= icks - * until some elements are used. - */ - svq->next_guest_avail_elem =3D elem; - return; - } - - ok =3D vhost_svq_add(svq, elem); - if (unlikely(!ok)) { - /* VQ is broken, just return and ignore any other kicks */ + r =3D vhost_svq_add(svq, elem); + if (unlikely(r !=3D 0)) { + if (r =3D=3D -ENOSPC) { + /* + * This condition is possible since a contiguous buffe= r in + * GPA does not imply a contiguous buffer in qemu's VA + * scatter-gather segments. If that happens, the buffer + * exposed to the device needs to be a chain of descri= ptors + * at this moment. + * + * SVQ cannot hold more available buffers if we are he= re: + * queue the current guest descriptor and ignore kicks + * until some elements are used. + */ + svq->next_guest_avail_elem =3D elem; + } + + /* VQ is full or broken, just return and ignore kicks */ return; } } --=20 2.31.1 From nobody Sun Feb 8 13:45:28 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658140982; cv=none; d=zohomail.com; s=zohoarc; b=LTxUZNU0pWEn5Aiq8QeM6hLi6xcrM/jglt/ns0sznlJcUN5H/NL5oVKhQa+stMHBQ4XyL/pwGml9uHTmFxRotiCjm2kxcbD0zxvNTSlYcgXpRjMmdXY/MWkSSicZZ0a6ID9LjPYyDGMLvcMPjnO+Pyp6jWRkD7nEWlGkR1tIhB8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658140982; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=D1sjQXZ7pGh62ovINMUtfVB0I9xu7GNacygyfka+sgY=; b=fenRnhB5qHQdqMAwo8RnR69yZaBM+zvTcIohjG+k50jzO3t0hlNqSKIjRsEn/6NtLgrTtQnFTtSlg2u3YwV11L1w0bgkwHa++H2GvoohhZeNo3qGagBnAZNt3N4e3VEmpluYFcWvlni7QP2MMNvubXiK6skCO1r5mBbKmg0Uv+A= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658140982793565.4061730109311; Mon, 18 Jul 2022 03:43:02 -0700 (PDT) Received: from localhost ([::1]:55722 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDODN-0007s7-KZ for importer@patchew.org; Mon, 18 Jul 2022 06:43:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54816) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1T-0000Xq-Vq for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31520) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1S-0001VZ-BX for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:43 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-424-lFF28ODiNXe8m8NWQmUM6Q-1; Mon, 18 Jul 2022 06:30:28 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5858F8037AC; Mon, 18 Jul 2022 10:30:28 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38ABD2166B26; Mon, 18 Jul 2022 10:30:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658140240; 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=D1sjQXZ7pGh62ovINMUtfVB0I9xu7GNacygyfka+sgY=; b=c8ADumQj3Z0SDW++rk1833Wmy90m7Rf7NJkq8EPzHX1W+p3VZeAvfk7QCAdqwj8jDsVf/u MYAtjAmyzF0mVMfDsLb0Fxl/C/mV7jXAL8/oFMbRwAQffLQqQ2sK2OOb65e2SZc53vEFlU ynDAFowT/O9xHuA4jOI0qN026y2nJvs= X-MC-Unique: lFF28ODiNXe8m8NWQmUM6Q-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Gautam Dawar , Cornelia Huck , Laurent Vivier , Paolo Bonzini , "Gonglei (Arei)" , Zhu Lingshan , Stefan Hajnoczi , Liuxiangdong , Jason Wang , Stefano Garzarella , Eli Cohen , Harpreet Singh Anand , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Parav Pandit Subject: [PATCH v4 07/19] vhost: Decouple vhost_svq_add from VirtQueueElement Date: Mon, 18 Jul 2022 12:29:37 +0200 Message-Id: <20220718102949.2868267-8-eperezma@redhat.com> In-Reply-To: <20220718102949.2868267-1-eperezma@redhat.com> References: <20220718102949.2868267-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658140983647100001 VirtQueueElement comes from the guest, but we're heading SVQ to be able to modify the element presented to the device without the guest's knowledge. To do so, make SVQ accept sg buffers directly, instead of using VirtQueueElement. Add vhost_svq_add_element to maintain element convenience. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 33 ++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index aee9891a67..b005a457c6 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -172,30 +172,31 @@ static bool vhost_svq_vring_write_descs(VhostShadowVi= rtqueue *svq, hwaddr *sg, } =20 static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, - VirtQueueElement *elem, unsigned *head) + const struct iovec *out_sg, size_t out_num, + const struct iovec *in_sg, size_t in_num, + unsigned *head) { unsigned avail_idx; vring_avail_t *avail =3D svq->vring.avail; bool ok; - g_autofree hwaddr *sgs =3D g_new(hwaddr, MAX(elem->out_num, elem->in_n= um)); + g_autofree hwaddr *sgs =3D g_new(hwaddr, MAX(out_num, in_num)); =20 *head =3D svq->free_head; =20 /* We need some descriptors here */ - if (unlikely(!elem->out_num && !elem->in_num)) { + if (unlikely(!out_num && !in_num)) { qemu_log_mask(LOG_GUEST_ERROR, "Guest provided element with no descriptors"); return false; } =20 - ok =3D vhost_svq_vring_write_descs(svq, sgs, elem->out_sg, elem->out_n= um, - elem->in_num > 0, false); + ok =3D vhost_svq_vring_write_descs(svq, sgs, out_sg, out_num, in_num >= 0, + false); if (unlikely(!ok)) { return false; } =20 - ok =3D vhost_svq_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num= , false, - true); + ok =3D vhost_svq_vring_write_descs(svq, sgs, in_sg, in_num, false, tru= e); if (unlikely(!ok)) { return false; } @@ -237,17 +238,19 @@ static void vhost_svq_kick(VhostShadowVirtqueue *svq) * * Return -EINVAL if element is invalid, -ENOSPC if dev queue is full */ -static int vhost_svq_add(VhostShadowVirtqueue *svq, VirtQueueElement *elem) +static int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *ou= t_sg, + size_t out_num, const struct iovec *in_sg, + size_t in_num, VirtQueueElement *elem) { unsigned qemu_head; - unsigned ndescs =3D elem->in_num + elem->out_num; + unsigned ndescs =3D in_num + out_num; bool ok; =20 if (unlikely(ndescs > vhost_svq_available_slots(svq))) { return -ENOSPC; } =20 - ok =3D vhost_svq_add_split(svq, elem, &qemu_head); + ok =3D vhost_svq_add_split(svq, out_sg, out_num, in_sg, in_num, &qemu_= head); if (unlikely(!ok)) { g_free(elem); return -EINVAL; @@ -258,6 +261,14 @@ static int vhost_svq_add(VhostShadowVirtqueue *svq, Vi= rtQueueElement *elem) return 0; } =20 +/* Convenience wrapper to add a guest's element to SVQ */ +static int vhost_svq_add_element(VhostShadowVirtqueue *svq, + VirtQueueElement *elem) +{ + return vhost_svq_add(svq, elem->out_sg, elem->out_num, elem->in_sg, + elem->in_num, elem); +} + /** * Forward available buffers. * @@ -294,7 +305,7 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueu= e *svq) break; } =20 - r =3D vhost_svq_add(svq, elem); + r =3D vhost_svq_add_element(svq, elem); if (unlikely(r !=3D 0)) { if (r =3D=3D -ENOSPC) { /* --=20 2.31.1 From nobody Sun Feb 8 13:45:28 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658140708; cv=none; d=zohomail.com; s=zohoarc; b=WdJFKZXWZp3MdUxIJzsf+3cCPjkmpyrsn2Wm2QvHHBGQF0PAUybeE8uNBTp6gK/KeAPWppi2M7kpF5SfUVEWm4OB7qJiGCsejyjaou3NU+QsGFkzmKYv8/qJ+1e8eu6XN0FWb9IatyZeGI8DZ55MmeOD65Seoivumbk9iPqEQ24= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658140708; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Tq5ZOp4oFPUNGw/PfAIhXLL0S4qhqlNmbps1kNQIPjM=; b=R89hbUFTI2Gau0C4leGWVLojn7bZTnGaI3ApbxbBSrXlH8F4eGUZxkKOGq+PhZuXSoLvjcnZQJCl0hSPRniE7qXPFMqMwTOJnLbEzJ+pIHMPpyIizSmmdwopw3fh7MEe7xqYECaXGqRWM0au8IxCRpc28CsFHc6yyi8AwEVJVk8= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16581407089821023.1298983931342; Mon, 18 Jul 2022 03:38:28 -0700 (PDT) Received: from localhost ([::1]:41710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDO8x-0006Fp-MM for importer@patchew.org; Mon, 18 Jul 2022 06:38:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54750) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1P-0000Tl-RM for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:27536) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1M-0001VB-6M for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:38 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-537-ioaJpjGPM9uWEIA9a9MxsQ-1; Mon, 18 Jul 2022 06:30:32 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A313038041C2; Mon, 18 Jul 2022 10:30:31 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BB732166B29; Mon, 18 Jul 2022 10:30:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658140235; 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=Tq5ZOp4oFPUNGw/PfAIhXLL0S4qhqlNmbps1kNQIPjM=; b=Dba4IyFfJsicF8rXNSgJVVq66l5zGHOytGBKN3QWdxvEHiat2vs1VWM5jcegyH+9/UcvJg WBqp2EGnn6n3OCnBndH6t+3B3FRJ03IYpAw4LGIKyZjroBkPW8QHypaI9M2znd/qGiVBCY piwMFasmIGnD/WtVYZa6BiEgS9ClPlU= X-MC-Unique: ioaJpjGPM9uWEIA9a9MxsQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Gautam Dawar , Cornelia Huck , Laurent Vivier , Paolo Bonzini , "Gonglei (Arei)" , Zhu Lingshan , Stefan Hajnoczi , Liuxiangdong , Jason Wang , Stefano Garzarella , Eli Cohen , Harpreet Singh Anand , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Parav Pandit Subject: [PATCH v4 08/19] vhost: Add SVQDescState Date: Mon, 18 Jul 2022 12:29:38 +0200 Message-Id: <20220718102949.2868267-9-eperezma@redhat.com> In-Reply-To: <20220718102949.2868267-1-eperezma@redhat.com> References: <20220718102949.2868267-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658140710123100001 This will allow SVQ to add context to the different queue elements. This patch only store the actual element, no functional change intended. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 8 ++++++-- hw/virtio/vhost-shadow-virtqueue.c | 16 ++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index c132c994e9..d646c35054 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -15,6 +15,10 @@ #include "standard-headers/linux/vhost_types.h" #include "hw/virtio/vhost-iova-tree.h" =20 +typedef struct SVQDescState { + VirtQueueElement *elem; +} SVQDescState; + /* Shadow virtqueue to relay notifications */ typedef struct VhostShadowVirtqueue { /* Shadow vring */ @@ -47,8 +51,8 @@ typedef struct VhostShadowVirtqueue { /* IOVA mapping */ VhostIOVATree *iova_tree; =20 - /* Map for use the guest's descriptors */ - VirtQueueElement **ring_id_maps; + /* SVQ vring descriptors state */ + SVQDescState *desc_state; =20 /* Next VirtQueue element that guest made available */ VirtQueueElement *next_guest_avail_elem; diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index b005a457c6..d12f5afffb 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -256,7 +256,7 @@ static int vhost_svq_add(VhostShadowVirtqueue *svq, con= st struct iovec *out_sg, return -EINVAL; } =20 - svq->ring_id_maps[qemu_head] =3D elem; + svq->desc_state[qemu_head].elem =3D elem; vhost_svq_kick(svq); return 0; } @@ -410,21 +410,21 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShado= wVirtqueue *svq, return NULL; } =20 - if (unlikely(!svq->ring_id_maps[used_elem.id])) { + if (unlikely(!svq->desc_state[used_elem.id].elem)) { qemu_log_mask(LOG_GUEST_ERROR, "Device %s says index %u is used, but it was not available", svq->vdev->name, used_elem.id); return NULL; } =20 - num =3D svq->ring_id_maps[used_elem.id]->in_num + - svq->ring_id_maps[used_elem.id]->out_num; + num =3D svq->desc_state[used_elem.id].elem->in_num + + svq->desc_state[used_elem.id].elem->out_num; 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->free_head =3D used_elem.id; =20 *len =3D used_elem.len; - return g_steal_pointer(&svq->ring_id_maps[used_elem.id]); + return g_steal_pointer(&svq->desc_state[used_elem.id].elem); } =20 static void vhost_svq_flush(VhostShadowVirtqueue *svq, @@ -594,7 +594,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIOD= evice *vdev, memset(svq->vring.desc, 0, driver_size); svq->vring.used =3D qemu_memalign(qemu_real_host_page_size(), device_s= ize); memset(svq->vring.used, 0, device_size); - svq->ring_id_maps =3D g_new0(VirtQueueElement *, svq->vring.num); + 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 cpu_to_le16(i + 1); @@ -619,7 +619,7 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) =20 for (unsigned i =3D 0; i < svq->vring.num; ++i) { g_autofree VirtQueueElement *elem =3D NULL; - elem =3D g_steal_pointer(&svq->ring_id_maps[i]); + elem =3D g_steal_pointer(&svq->desc_state[i].elem); if (elem) { virtqueue_detach_element(svq->vq, elem, 0); } @@ -631,7 +631,7 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) } svq->vq =3D NULL; g_free(svq->desc_next); - g_free(svq->ring_id_maps); + g_free(svq->desc_state); qemu_vfree(svq->vring.desc); qemu_vfree(svq->vring.used); } --=20 2.31.1 From nobody Sun Feb 8 13:45:28 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658141150; cv=none; d=zohomail.com; s=zohoarc; b=AyjpFQ4Lc+E4yrRY9qd9UUlNi/UZX1khm4Xg1LjzE98hSMW2wAkuA9SkiBbZjGy3EeXBWDmXtJNm5pKSvcXZbrVt4E0yUxan714celmucefh1b/MBSh8OghH7k0Qw1OXzi4jGVhI4yTZQapa1wab4JrrhOGL4P64GIRZIG9sWcw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658141150; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eUj+IsouhY5Fm8JAI1LY9cCh0zDRy7WQa9mbuUixvV4=; b=OM3JgbZuYBxsbfejcBceGL+4TEp+fCwmfRD0n+q5HHIkeqNC3MFjiXaKhNN4d2yDAzXWijkBKyNX0w8AbZtf/6CYYZ10VUwOD0GMG44Qfs09R3w9/72mOpcKjyeDDa8Puh2pyA3FvRkc/voptIUcclLlWyqhOmRsIwfXzF5PuD8= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658141150379474.00002457826326; Mon, 18 Jul 2022 03:45:50 -0700 (PDT) Received: from localhost ([::1]:33724 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDOG4-0003f4-Ak for importer@patchew.org; Mon, 18 Jul 2022 06:45:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54932) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1d-0000Zm-Je for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:20336) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1c-0001Xc-3U for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:53 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-374-SaxM4Od6O8ua5ncblZqMZQ-1; Mon, 18 Jul 2022 06:30:36 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8C47F811E75; Mon, 18 Jul 2022 10:30:35 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id E69182166B26; Mon, 18 Jul 2022 10:30:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658140250; 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=eUj+IsouhY5Fm8JAI1LY9cCh0zDRy7WQa9mbuUixvV4=; b=ZzENZn4/0+Oqe3lQO1C23dngl0/0k6/UmbVSQKBMMdno8YAxsPTBKMwrA9tgcprfTWspGS WuswDAKSm/mtloZgZsTPeK8WqMVjzikdCZUrK58GCUEVEBqeiM2EaPxz4sXLD89pOyYnf2 yrzsVsLt9Z5L1pAM8GOXsKHxT0xjL1U= X-MC-Unique: SaxM4Od6O8ua5ncblZqMZQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Gautam Dawar , Cornelia Huck , Laurent Vivier , Paolo Bonzini , "Gonglei (Arei)" , Zhu Lingshan , Stefan Hajnoczi , Liuxiangdong , Jason Wang , Stefano Garzarella , Eli Cohen , Harpreet Singh Anand , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Parav Pandit Subject: [PATCH v4 09/19] vhost: Track number of descs in SVQDescState Date: Mon, 18 Jul 2022 12:29:39 +0200 Message-Id: <20220718102949.2868267-10-eperezma@redhat.com> In-Reply-To: <20220718102949.2868267-1-eperezma@redhat.com> References: <20220718102949.2868267-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658141151139100002 A guest's buffer continuos on GPA may need multiple descriptors on qemu's VA, so SVQ should track its length sepparatedly. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 6 ++++++ hw/virtio/vhost-shadow-virtqueue.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index d646c35054..5c7e7cbab6 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -17,6 +17,12 @@ =20 typedef struct SVQDescState { VirtQueueElement *elem; + + /* + * Number of descriptors exposed to the device. May or may not match + * guest's + */ + unsigned int ndescs; } SVQDescState; =20 /* Shadow virtqueue to relay notifications */ diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index d12f5afffb..ae5bd6efa8 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -257,6 +257,7 @@ static int vhost_svq_add(VhostShadowVirtqueue *svq, con= st struct iovec *out_sg, } =20 svq->desc_state[qemu_head].elem =3D elem; + svq->desc_state[qemu_head].ndescs =3D ndescs; vhost_svq_kick(svq); return 0; } @@ -417,8 +418,7 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadowV= irtqueue *svq, return NULL; } =20 - num =3D svq->desc_state[used_elem.id].elem->in_num + - svq->desc_state[used_elem.id].elem->out_num; + num =3D svq->desc_state[used_elem.id].ndescs; 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->free_head =3D used_elem.id; --=20 2.31.1 From nobody Sun Feb 8 13:45:28 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658140843; cv=none; d=zohomail.com; s=zohoarc; b=a4yuLZQJNTMZ6V471ZbQ6BFeCbk09rftc4UHtGFn+HBom3XIcVtq8s8FaMcz310hWQnlsAwkhCl6cTH61PsK7F5dR2fBynaTPq0LXmG2UN5/LxJ4YcWVbYIoMqmOJzfjuhMNtC4Ic2Z7uyTqfmyqTdHoHJP494d8kpN05eoDEtU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658140843; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dCFxbNxGvYH2p92JwjKOfvniNPsvU8wwPLaGpYNSXls=; b=MvLNCLA3ZJz5yRxIykWWBnu/sXIbp7krerbPRIMrBc4ksmWdRtqWSs33vl5/8X47iOUiZqjDhHOjKPeUXhfPAmnitjE6ZCNZ3CARif63A6O/HQ3nza8bIFWxxNdo/yhmCJysZWv2gjILTo+1rfemLyqo/L+KvCJwDVo1z7/yEpA= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658140843849723.3174823374543; Mon, 18 Jul 2022 03:40:43 -0700 (PDT) Received: from localhost ([::1]:49508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDOB8-0003OX-Tb for importer@patchew.org; Mon, 18 Jul 2022 06:40:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54866) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1Z-0000Xv-3O for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:28004) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1V-0001WN-JF for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:47 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-556-zH2NgtbDMZ6w3Mh2o4Xtug-1; Mon, 18 Jul 2022 06:30:40 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9FA5428084E3; Mon, 18 Jul 2022 10:30:39 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB6972166B26; Mon, 18 Jul 2022 10:30:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658140245; 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=dCFxbNxGvYH2p92JwjKOfvniNPsvU8wwPLaGpYNSXls=; b=Ga2MABg0of2POMKuGt1WhBKVK/0W9eiYhQFQOzno6wywvK4zt7LQtR0bzseA2afPWSOLy2 5tcbKMAwh05mKAxbhOceg6DoGJkrD+ybOfRmmnvb1gN1nNQws51R+hg+hClhSW/fRe5j3o 03HfQYVtIKrnVxAyIcK8ZB1HkDN/qwc= X-MC-Unique: zH2NgtbDMZ6w3Mh2o4Xtug-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Gautam Dawar , Cornelia Huck , Laurent Vivier , Paolo Bonzini , "Gonglei (Arei)" , Zhu Lingshan , Stefan Hajnoczi , Liuxiangdong , Jason Wang , Stefano Garzarella , Eli Cohen , Harpreet Singh Anand , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Parav Pandit Subject: [PATCH v4 10/19] vhost: add vhost_svq_push_elem Date: Mon, 18 Jul 2022 12:29:40 +0200 Message-Id: <20220718102949.2868267-11-eperezma@redhat.com> In-Reply-To: <20220718102949.2868267-1-eperezma@redhat.com> References: <20220718102949.2868267-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658140844843100001 This function allows external SVQ users to return guest's available buffers. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 3 +++ hw/virtio/vhost-shadow-virtqueue.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 5c7e7cbab6..d9fc1f1799 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -84,6 +84,9 @@ typedef struct VhostShadowVirtqueue { =20 bool vhost_svq_valid_features(uint64_t features, Error **errp); =20 +void vhost_svq_push_elem(VhostShadowVirtqueue *svq, + const VirtQueueElement *elem, uint32_t len); + void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd); void vhost_svq_get_vring_addr(const VhostShadowVirtqueue *svq, diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index ae5bd6efa8..b377e125e7 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -427,6 +427,22 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadow= Virtqueue *svq, return g_steal_pointer(&svq->desc_state[used_elem.id].elem); } =20 +/** + * Push an element to SVQ, returning it to the guest. + */ +void vhost_svq_push_elem(VhostShadowVirtqueue *svq, + const VirtQueueElement *elem, uint32_t len) +{ + virtqueue_push(svq->vq, elem, len); + if (svq->next_guest_avail_elem) { + /* + * Avail ring was full when vhost_svq_flush was called, so it's a + * good moment to make more descriptors available if possible. + */ + vhost_handle_guest_kick(svq); + } +} + static void vhost_svq_flush(VhostShadowVirtqueue *svq, bool check_for_avail_queue) { --=20 2.31.1 From nobody Sun Feb 8 13:45:28 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658140390; cv=none; d=zohomail.com; s=zohoarc; b=D/86BnM61nKq7bYbFLSI3DEF1NF57obfxaFy7B9A0nLwnVlrYwga4nB1bljFxKe6Dfz3c5a5Y1Jb7WzQ631Q3iPsqhEYpTLXAhDvoxZRIi+EC8R0BTzqNskByASEhBx1h6LdEEqReJnmrxs9r2o5lMzNBu7DteMk8lfTH6qfvoc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658140390; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VpkW94v7wO47YN0nfwYhYcnj2RiAZSrGtQRBvd974kg=; b=hmCFWflULk1WTJlYd9Gr4LANlesq6dm5080Tbi35wXFT0wZccrs1Qh+Xri73va+GFcrHpur/kLAFbXlBtCvjc8KvW0O04BuQltL0x2moY0O1bIKOcMbYJAtFmvcyYy/XKPM7Llfe5wUTcRQhAxgj5DWIuKrM6WTINa/2eJ1IEvw= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658140390706994.4473904290121; Mon, 18 Jul 2022 03:33:10 -0700 (PDT) Received: from localhost ([::1]:54538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDO3p-0003aL-MY for importer@patchew.org; Mon, 18 Jul 2022 06:33:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54898) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1b-0000YP-43 for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:49976) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1Y-0001Wi-Oq for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:50 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-441-Vpkmsr13Ooqb5hDxmOjvJg-1; Mon, 18 Jul 2022 06:30:44 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 178D038041C6; Mon, 18 Jul 2022 10:30:44 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id F14C12166B26; Mon, 18 Jul 2022 10:30:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658140247; 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=VpkW94v7wO47YN0nfwYhYcnj2RiAZSrGtQRBvd974kg=; b=No/H8Hq0SO4uDKY2xJP5l7Bq5MRobKwh3kW8cjZex0kDc2Lfl8yRdnhNVjAZzaNh7tQwIQ 4EscWG5PK6tIfv3VW+z09r2iVL/okufW/PWbz+mDNBq6oulz1QHXushcisCyDLgnrOX2c2 o6KLoGcf28DJT2RzeJqXaP0Mg1noArM= X-MC-Unique: Vpkmsr13Ooqb5hDxmOjvJg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Gautam Dawar , Cornelia Huck , Laurent Vivier , Paolo Bonzini , "Gonglei (Arei)" , Zhu Lingshan , Stefan Hajnoczi , Liuxiangdong , Jason Wang , Stefano Garzarella , Eli Cohen , Harpreet Singh Anand , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Parav Pandit Subject: [PATCH v4 11/19] vhost: Expose vhost_svq_add Date: Mon, 18 Jul 2022 12:29:41 +0200 Message-Id: <20220718102949.2868267-12-eperezma@redhat.com> In-Reply-To: <20220718102949.2868267-1-eperezma@redhat.com> References: <20220718102949.2868267-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658140392402100003 This allows external parts of SVQ to forward custom buffers to the device. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 3 +++ hw/virtio/vhost-shadow-virtqueue.c | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index d9fc1f1799..dd78f4bec2 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -86,6 +86,9 @@ bool vhost_svq_valid_features(uint64_t features, Error **= errp); =20 void vhost_svq_push_elem(VhostShadowVirtqueue *svq, const VirtQueueElement *elem, uint32_t len); +int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg, + size_t out_num, const struct iovec *in_sg, size_t in_num, + VirtQueueElement *elem); =20 void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd); diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index b377e125e7..406a823c81 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -238,9 +238,9 @@ static void vhost_svq_kick(VhostShadowVirtqueue *svq) * * Return -EINVAL if element is invalid, -ENOSPC if dev queue is full */ -static int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *ou= t_sg, - size_t out_num, const struct iovec *in_sg, - size_t in_num, VirtQueueElement *elem) +int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg, + size_t out_num, const struct iovec *in_sg, size_t in_num, + VirtQueueElement *elem) { unsigned qemu_head; unsigned ndescs =3D in_num + out_num; --=20 2.31.1 From nobody Sun Feb 8 13:45:28 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658140715; cv=none; d=zohomail.com; s=zohoarc; b=fE7tnif52lW9gRA2lRXVsFDbiBYdxjdZm7vmqaTsoTvszcGbnyHoKZhcU/gg7o8k9LAtEZX1S/i1UbIoGziXcMtcvWtfa/ct5WsO1xEkAmSX09T9E/Dj9NlAHj6MCr6aASmh1HclJ+gMwkdEAcVuYsyZnsoXx56oP5cJCZgUkt4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658140715; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=roriYvB7jydlhelrNTbNZuV1VqE2b+QJQWRvpgYiTfc=; b=H8Gxlt2viwt95svgOUhX3iWi2WgGhU2UrAKCFaqLpvZou5Po/qJjYrmf8R+i07//FxPWjsjtbINSKlgt6uwJk85338WezH8lk/zwXNFg9JYYUYmY5bLxswhv+CzCM+HlcKGp4B+F5gZYTx4gR4gf9D6sNt9GB0QE0qXpgkNC3Qo= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658140715974185.18446375443636; Mon, 18 Jul 2022 03:38:35 -0700 (PDT) Received: from localhost ([::1]:42360 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDO94-0006jL-S8 for importer@patchew.org; Mon, 18 Jul 2022 06:38:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54968) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1g-0000ak-7W for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:27305) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1c-0001Y4-UM for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:30:54 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-505-9srX2nDaOKGfef3jgeLs0w-1; Mon, 18 Jul 2022 06:30:48 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B472B85A587; Mon, 18 Jul 2022 10:30:47 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 765272166B26; Mon, 18 Jul 2022 10:30:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658140252; 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=roriYvB7jydlhelrNTbNZuV1VqE2b+QJQWRvpgYiTfc=; b=Hisz4KXpv9K9AnuQgW1iIJ5CDZsd78/DUUJiuvXImYEaXRoDrd7ZWHgohfxcdcS1/j8mQ5 EnrMSqgCzMCoBNrjoB6n38/C/IErGXgu+c2/Y3ftTnUhKfxlNa4nXIzPSXQ7MPSH/pIQjm ZyxR8oOWotuNhDEYbvwIbIdFYHEqn7E= X-MC-Unique: 9srX2nDaOKGfef3jgeLs0w-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Gautam Dawar , Cornelia Huck , Laurent Vivier , Paolo Bonzini , "Gonglei (Arei)" , Zhu Lingshan , Stefan Hajnoczi , Liuxiangdong , Jason Wang , Stefano Garzarella , Eli Cohen , Harpreet Singh Anand , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Parav Pandit Subject: [PATCH v4 12/19] vhost: add vhost_svq_poll Date: Mon, 18 Jul 2022 12:29:42 +0200 Message-Id: <20220718102949.2868267-13-eperezma@redhat.com> In-Reply-To: <20220718102949.2868267-1-eperezma@redhat.com> References: <20220718102949.2868267-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658140718046100001 It allows the Shadow Control VirtQueue to wait for the device to use the available buffers. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 1 + hw/virtio/vhost-shadow-virtqueue.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index dd78f4bec2..cf442f7dea 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -89,6 +89,7 @@ void vhost_svq_push_elem(VhostShadowVirtqueue *svq, int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg, size_t out_num, const struct iovec *in_sg, size_t in_num, VirtQueueElement *elem); +size_t vhost_svq_poll(VhostShadowVirtqueue *svq); =20 void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd); diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 406a823c81..3c26781cf7 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -484,6 +484,33 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq, } while (!vhost_svq_enable_notification(svq)); } =20 +/** + * Poll the SVQ for one device used buffer. + * + * This function race with main event loop SVQ polling, so extra + * synchronization is needed. + * + * Return the length written by the device. + */ +size_t vhost_svq_poll(VhostShadowVirtqueue *svq) +{ + int64_t start_us =3D g_get_monotonic_time(); + do { + uint32_t len; + VirtQueueElement *elem =3D vhost_svq_get_buf(svq, &len); + if (elem) { + return len; + } + + if (unlikely(g_get_monotonic_time() - start_us > 10e6)) { + return 0; + } + + /* Make sure we read new used_idx */ + smp_rmb(); + } while (true); +} + /** * Forward used buffers. * --=20 2.31.1 From nobody Sun Feb 8 13:45:28 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658140981; cv=none; d=zohomail.com; s=zohoarc; b=KBb0UZaPJXs0aZrWAwbgQSchBTyGW8buwfRqzkXOf3FlqCwdcHtnt9PW0WueKYb+wPjlq0q2hF8vLoxsOlUyO8I9uyx9gwTNV+2vEEl3sSmjVBdEl2SAxCeSg18gOPQKovYls2sq8D+1lyhP/VNLJ0SGl3fOcEXjZbhgvYBxMf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658140981; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/dzpfV41T861x4SNpFuIOpPDHJiZ/MoZ2nRHPChlSm8=; b=TER9IFztY7art0MFo+S3yLmswdU1gTHyPVs/xNt6P9ZpatgCv0LHAVG7hn9zl8OVmg/5GBuQBUkbOblbHnEk/i/KYAVM8Xzd51dkycb7tBIMQ0xudMSKjYfRHSney+w79OfRO0vt6JUgxBhlQT9SfvmZBgbZOgqeF0bdOHq4W0I= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658140981347140.92735121816827; Mon, 18 Jul 2022 03:43:01 -0700 (PDT) Received: from localhost ([::1]:55674 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDODM-0007qJ-Bg for importer@patchew.org; Mon, 18 Jul 2022 06:43:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55060) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1p-0000dg-Lu for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:31:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31308) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1n-0001ZJ-Br for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:31:04 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-526-cQ4h-jK1OUSa1Jc1OHkZhQ-1; Mon, 18 Jul 2022 06:30:51 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0D263802D2C; Mon, 18 Jul 2022 10:30:51 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 07A052166B26; Mon, 18 Jul 2022 10:30:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658140262; 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=/dzpfV41T861x4SNpFuIOpPDHJiZ/MoZ2nRHPChlSm8=; b=VqJdwhpUKk/cjU1vWyRpD+ZxME1BkcJtLHQ9pYC60NUNJ4fHYboUidM1koxwzOOeh3cxly l2l6WrwiynnBaGXO3YuJzfL/i3uXEf3bqwaqXAZwdaSPnF9V+miAIKsPuQSH0WCFmW9a53 UsBY+jBsZ2sEM88NXnkiZeKIJFVFmNQ= X-MC-Unique: cQ4h-jK1OUSa1Jc1OHkZhQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Gautam Dawar , Cornelia Huck , Laurent Vivier , Paolo Bonzini , "Gonglei (Arei)" , Zhu Lingshan , Stefan Hajnoczi , Liuxiangdong , Jason Wang , Stefano Garzarella , Eli Cohen , Harpreet Singh Anand , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Parav Pandit Subject: [PATCH v4 13/19] vhost: Add svq avail_handler callback Date: Mon, 18 Jul 2022 12:29:43 +0200 Message-Id: <20220718102949.2868267-14-eperezma@redhat.com> In-Reply-To: <20220718102949.2868267-1-eperezma@redhat.com> References: <20220718102949.2868267-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658140981598100001 This allows external handlers to be aware of new buffers that the guest places in the virtqueue. When this callback is defined the ownership of the guest's virtqueue element is transferred to the callback. This means that if the user wants to forward the descriptor it needs to manually inject it. The callback is also free to process the command by itself and use the element with svq_push. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 31 +++++++++++++++++++++++++++++- hw/virtio/vhost-shadow-virtqueue.c | 14 ++++++++++++-- hw/virtio/vhost-vdpa.c | 3 ++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index cf442f7dea..d04c34a589 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -25,6 +25,27 @@ typedef struct SVQDescState { unsigned int ndescs; } SVQDescState; =20 +typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; + +/** + * Callback to handle an avail buffer. + * + * @svq: Shadow virtqueue + * @elem: Element placed in the queue by the guest + * @vq_callback_opaque: Opaque + * + * Returns 0 if the vq is running as expected. + * + * Note that ownership of elem is transferred to the callback. + */ +typedef int (*VirtQueueAvailCallback)(VhostShadowVirtqueue *svq, + VirtQueueElement *elem, + void *vq_callback_opaque); + +typedef struct VhostShadowVirtqueueOps { + VirtQueueAvailCallback avail_handler; +} VhostShadowVirtqueueOps; + /* Shadow virtqueue to relay notifications */ typedef struct VhostShadowVirtqueue { /* Shadow vring */ @@ -69,6 +90,12 @@ typedef struct VhostShadowVirtqueue { */ uint16_t *desc_next; =20 + /* Caller callbacks */ + const VhostShadowVirtqueueOps *ops; + + /* Caller callbacks opaque */ + void *ops_opaque; + /* Next head to expose to the device */ uint16_t shadow_avail_idx; =20 @@ -102,7 +129,9 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIOD= evice *vdev, VirtQueue *vq); void vhost_svq_stop(VhostShadowVirtqueue *svq); =20 -VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree); +VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree, + const VhostShadowVirtqueueOps *ops, + void *ops_opaque); =20 void vhost_svq_free(gpointer vq); G_DEFINE_AUTOPTR_CLEANUP_FUNC(VhostShadowVirtqueue, vhost_svq_free); diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 3c26781cf7..1646d3cb40 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -306,7 +306,11 @@ static void vhost_handle_guest_kick(VhostShadowVirtque= ue *svq) break; } =20 - r =3D vhost_svq_add_element(svq, elem); + if (svq->ops) { + r =3D svq->ops->avail_handler(svq, elem, svq->ops_opaque); + } else { + r =3D vhost_svq_add_element(svq, elem); + } if (unlikely(r !=3D 0)) { if (r =3D=3D -ENOSPC) { /* @@ -684,12 +688,16 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) * shadow methods and file descriptors. * * @iova_tree: Tree to perform descriptors translations + * @ops: SVQ owner callbacks + * @ops_opaque: ops opaque pointer * * Returns the new virtqueue or NULL. * * In case of error, reason is reported through error_report. */ -VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree) +VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree, + const VhostShadowVirtqueueOps *ops, + void *ops_opaque) { g_autofree VhostShadowVirtqueue *svq =3D g_new0(VhostShadowVirtqueue, = 1); int r; @@ -711,6 +719,8 @@ VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova= _tree) event_notifier_init_fd(&svq->svq_kick, VHOST_FILE_UNBIND); event_notifier_set_handler(&svq->hdev_call, vhost_svq_handle_call); svq->iova_tree =3D iova_tree; + svq->ops =3D ops; + svq->ops_opaque =3D ops_opaque; return g_steal_pointer(&svq); =20 err_init_hdev_call: diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 66f054a12c..0b13e98471 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -418,8 +418,9 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, = struct vhost_vdpa *v, =20 shadow_vqs =3D g_ptr_array_new_full(hdev->nvqs, vhost_svq_free); for (unsigned n =3D 0; n < hdev->nvqs; ++n) { - g_autoptr(VhostShadowVirtqueue) svq =3D vhost_svq_new(v->iova_tree= ); + g_autoptr(VhostShadowVirtqueue) svq; =20 + svq =3D vhost_svq_new(v->iova_tree, NULL, NULL); if (unlikely(!svq)) { error_setg(errp, "Cannot create svq %u", n); return -1; --=20 2.31.1 From nobody Sun Feb 8 13:45:28 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658140846; cv=none; d=zohomail.com; s=zohoarc; b=LOPILH3tOaQGVG8u0uXB6p3YvPETMrUCd/zGqyyWTSjiO8JuYspcqoOhIIYF9cAkalPK7ulk6MQ2aQSoQ5Q3tcFn+GQFkVazC/Qo5la0LTwBynd2WRxT2YNzHnDoCWE0Zj3sPPsGP1ogn5wcNl3QbjzOZh/RS1UeuOZPhPk50Gc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658140846; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RjJRmUJkLnrcMXEuZxhOFeU55tveeZ6VarDizyp9kEA=; b=Q7wb9u6q9rgYE3ojvvO41OciQoI/Kk+MB0g3mZIlgdlUVDfaVU8mjhWUfz5S66tOrbRPs/q+2nk3J8DfLiMzPkwMRVDDsNMmOHra+Dg/Or1j5y/ETvur3pftC3CiMc9aeKzHaMigWaRfqZWFdzG2PWaiYPjvhHXLt9XHKMnZ9B8= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165814084642372.75402452678372; Mon, 18 Jul 2022 03:40:46 -0700 (PDT) Received: from localhost ([::1]:49598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDOBB-0003Ro-DC for importer@patchew.org; Mon, 18 Jul 2022 06:40:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55014) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1k-0000cW-Nl for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:31:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:60889) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1i-0001Yz-Rb for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:31:00 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-107-3dHDEVyLMFKqgomPXgrD0g-1; Mon, 18 Jul 2022 06:30:55 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7CE1038041C2; Mon, 18 Jul 2022 10:30:54 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 570192166B26; Mon, 18 Jul 2022 10:30:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658140258; 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=RjJRmUJkLnrcMXEuZxhOFeU55tveeZ6VarDizyp9kEA=; b=LkWPnsywvq5UkY0+yYiYSoUe+OcO4dspJlRQaWGi/CzBoYka7+ZNfc/XUgZ/naMz/F1hli QzoWNgjLsa/xXqs3OF9FhDHbyxkfS65ph12LaQRRi/VqATEvQZ2WVyDXsDMdCysYbhT/fM 8Hr99JcQmpU3dWvJR8bQPM4KCUrXAs0= X-MC-Unique: 3dHDEVyLMFKqgomPXgrD0g-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Gautam Dawar , Cornelia Huck , Laurent Vivier , Paolo Bonzini , "Gonglei (Arei)" , Zhu Lingshan , Stefan Hajnoczi , Liuxiangdong , Jason Wang , Stefano Garzarella , Eli Cohen , Harpreet Singh Anand , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Parav Pandit Subject: [PATCH v4 14/19] vdpa: Export vhost_vdpa_dma_map and unmap calls Date: Mon, 18 Jul 2022 12:29:44 +0200 Message-Id: <20220718102949.2868267-15-eperezma@redhat.com> In-Reply-To: <20220718102949.2868267-1-eperezma@redhat.com> References: <20220718102949.2868267-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658140846849100003 Shadow CVQ will copy buffers on qemu VA, so we avoid TOCTOU attacks from the guest that could set a different state in qemu device model and vdpa device. To do so, it needs to be able to map these new buffers to the device. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- include/hw/virtio/vhost-vdpa.h | 4 ++++ hw/virtio/vhost-vdpa.c | 7 +++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index a29dbb3f53..7214eb47dc 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -39,4 +39,8 @@ typedef struct vhost_vdpa { VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; } VhostVDPA; =20 +int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size, + void *vaddr, bool readonly); +int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova, hwaddr size); + #endif diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 0b13e98471..96997210be 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -71,8 +71,8 @@ static bool vhost_vdpa_listener_skipped_section(MemoryReg= ionSection *section, return false; } =20 -static int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr si= ze, - void *vaddr, bool readonly) +int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size, + void *vaddr, bool readonly) { struct vhost_msg_v2 msg =3D {}; int fd =3D v->device_fd; @@ -97,8 +97,7 @@ static int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwadd= r iova, hwaddr size, return ret; } =20 -static int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova, - hwaddr size) +int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova, hwaddr size) { struct vhost_msg_v2 msg =3D {}; int fd =3D v->device_fd; --=20 2.31.1 From nobody Sun Feb 8 13:45:28 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658140561; cv=none; d=zohomail.com; s=zohoarc; b=G7Bd1vQcVhNGD7L6iL/A7C7fj05J0knJKZ8VWXWvEQhur9yO9fSd4MRHR0chHF4OhYyAG2oabucIIFmnLVQ24akrNeNn+7nyuQkQdxU8GwPXjcwMnyHNqYtgp4MrREUxeKf08otCShRn+FWjEGdxoCtjOruBlvuN1ssaI7yrt0o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658140561; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rl4DaeBhR/sSwokXTgPWmNey8T91oXhF2IN2JtMrN/0=; b=addO+Yitc0DOnj3zUJ+DvCRlfEDs3aLrhE6pDtlkq7jc1SIE4nxUlU98wzb8Xlod0542XeEp23fkItRjqQzZ54ka89rhBkwpRtIAQSp62IPmyr+AENwD4lkB3acrz88kmIFjx+MqIxblFSgvxxNFbHhxRI14O/MGn88oyowbb7A= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658140561578635.6227754394238; Mon, 18 Jul 2022 03:36:01 -0700 (PDT) Received: from localhost ([::1]:34602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDO6Z-0001Ar-Lb for importer@patchew.org; Mon, 18 Jul 2022 06:35:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1t-0000mw-Vv for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:31:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24045) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1p-0001ZQ-1A for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:31:09 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-624-GVWc358CMTSxDTCAYPSJww-1; Mon, 18 Jul 2022 06:31:00 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EB07A8032E3; Mon, 18 Jul 2022 10:30:59 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF38C2166B26; Mon, 18 Jul 2022 10:30:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658140263; 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=rl4DaeBhR/sSwokXTgPWmNey8T91oXhF2IN2JtMrN/0=; b=Cw8WTqj/GuX/27XMaWNPDg9qxqOEAUYi2dwJJzAry1yPfsl3NsfOB2agLDCN55Y2mMYWrs C0RkvzhveI2lANnfrZ38liE3XhLEsch3ixWCl9Cg5+1dLfdSSf1kH6nOS7qyE9sIR1klHJ nadFkIcAVzDUlT1aEb6two7bOfPBP6A= X-MC-Unique: GVWc358CMTSxDTCAYPSJww-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Gautam Dawar , Cornelia Huck , Laurent Vivier , Paolo Bonzini , "Gonglei (Arei)" , Zhu Lingshan , Stefan Hajnoczi , Liuxiangdong , Jason Wang , Stefano Garzarella , Eli Cohen , Harpreet Singh Anand , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Parav Pandit Subject: [PATCH v4 15/19] vdpa: manual forward CVQ buffers Date: Mon, 18 Jul 2022 12:29:45 +0200 Message-Id: <20220718102949.2868267-16-eperezma@redhat.com> In-Reply-To: <20220718102949.2868267-1-eperezma@redhat.com> References: <20220718102949.2868267-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658140563180100007 Do a simple forwarding of CVQ buffers, the same work SVQ could do but through callbacks. No functional change intended. Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/vhost-vdpa.h | 3 ++ hw/virtio/vhost-vdpa.c | 3 +- net/vhost-vdpa.c | 58 ++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 7214eb47dc..1111d85643 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -15,6 +15,7 @@ #include =20 #include "hw/virtio/vhost-iova-tree.h" +#include "hw/virtio/vhost-shadow-virtqueue.h" #include "hw/virtio/virtio.h" #include "standard-headers/linux/vhost_types.h" =20 @@ -35,6 +36,8 @@ typedef struct vhost_vdpa { /* IOVA mapping used by the Shadow Virtqueue */ VhostIOVATree *iova_tree; GPtrArray *shadow_vqs; + const VhostShadowVirtqueueOps *shadow_vq_ops; + void *shadow_vq_ops_opaque; struct vhost_dev *dev; VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; } VhostVDPA; diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 96997210be..beaaa7049a 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -419,7 +419,8 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, = struct vhost_vdpa *v, for (unsigned n =3D 0; n < hdev->nvqs; ++n) { g_autoptr(VhostShadowVirtqueue) svq; =20 - svq =3D vhost_svq_new(v->iova_tree, NULL, NULL); + svq =3D vhost_svq_new(v->iova_tree, v->shadow_vq_ops, + v->shadow_vq_ops_opaque); if (unlikely(!svq)) { error_setg(errp, "Cannot create svq %u", n); return -1; diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index df1e69ee72..2e3b6b10d8 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -11,11 +11,14 @@ =20 #include "qemu/osdep.h" #include "clients.h" +#include "hw/virtio/virtio-net.h" #include "net/vhost_net.h" #include "net/vhost-vdpa.h" #include "hw/virtio/vhost-vdpa.h" #include "qemu/config-file.h" #include "qemu/error-report.h" +#include "qemu/log.h" +#include "qemu/memalign.h" #include "qemu/option.h" #include "qapi/error.h" #include @@ -187,6 +190,57 @@ static NetClientInfo net_vhost_vdpa_info =3D { .check_peer_type =3D vhost_vdpa_check_peer_type, }; =20 +/** + * Forward buffer for the moment. + */ +static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq, + VirtQueueElement *elem, + void *opaque) +{ + unsigned int n =3D elem->out_num + elem->in_num; + g_autofree struct iovec *dev_buffers =3D g_new(struct iovec, n); + size_t in_len, dev_written; + virtio_net_ctrl_ack status =3D VIRTIO_NET_ERR; + int r; + + memcpy(dev_buffers, elem->out_sg, elem->out_num); + memcpy(dev_buffers + elem->out_num, elem->in_sg, elem->in_num); + + r =3D vhost_svq_add(svq, &dev_buffers[0], elem->out_num, &dev_buffers[= 1], + elem->in_num, elem); + if (unlikely(r !=3D 0)) { + if (unlikely(r =3D=3D -ENOSPC)) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: No space on device queue\n= ", + __func__); + } + goto out; + } + + /* + * We can poll here since we've had BQL from the time we sent the + * descriptor. Also, we need to take the answer before SVQ pulls by it= self, + * when BQL is released + */ + dev_written =3D vhost_svq_poll(svq); + if (unlikely(dev_written < sizeof(status))) { + error_report("Insufficient written data (%zu)", dev_written); + } + +out: + in_len =3D iov_from_buf(elem->in_sg, elem->in_num, 0, &status, + sizeof(status)); + if (unlikely(in_len < sizeof(status))) { + error_report("Bad device CVQ written length"); + } + vhost_svq_push_elem(svq, elem, MIN(in_len, sizeof(status))); + g_free(elem); + return r; +} + +static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops =3D { + .avail_handler =3D vhost_vdpa_net_handle_ctrl_avail, +}; + static NetClientState *net_vhost_vdpa_init(NetClientState *peer, const char *device, const char *name, @@ -211,6 +265,10 @@ static NetClientState *net_vhost_vdpa_init(NetClientSt= ate *peer, =20 s->vhost_vdpa.device_fd =3D vdpa_device_fd; s->vhost_vdpa.index =3D queue_pair_index; + if (!is_datapath) { + s->vhost_vdpa.shadow_vq_ops =3D &vhost_vdpa_net_svq_ops; + s->vhost_vdpa.shadow_vq_ops_opaque =3D s; + } ret =3D vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, queue_pair_index, n= vqs); if (ret) { qemu_del_net_client(nc); --=20 2.31.1 From nobody Sun Feb 8 13:45:28 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658140721; cv=none; d=zohomail.com; s=zohoarc; b=NXpRS11vkUzB68Ss5a9cke/Qt+VPZfRBvpeEVkT/8bSJeOihDvMlFk/bMc1SDk+plHkrh9Gqwo89phuTAOHUDJEK3IpfgM2XLue4/v2hCsK0d/cpZEVgxcZIEK2Imxc6GP1d8PPKYheV1t9Igtyvua+juRK0erEtMPgH0mKzVKk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658140721; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hUMS8Ss2bLBWFkMg86cs0CTf8NmhtFszeCU06faAvQI=; b=A+FEuf2FLc+1w2qYkXEja5D21iMijAYcFaJBBAudPRAFVOd06lkYDpX96LvzTOntVYRheVe1qlLr7T9Nc85cVgYeRUd5QTJoj7jmk7tM1+18ExiZk8nvWAfs5wL+Kdc2CRMwu5MC9cuavd8rdjtYy1EnRueh/loU4BH8Lj+4S+8= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165814072145119.46301846193819; Mon, 18 Jul 2022 03:38:41 -0700 (PDT) Received: from localhost ([::1]:42772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDO9A-00072U-Bk for importer@patchew.org; Mon, 18 Jul 2022 06:38:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55174) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1w-0000qU-GA for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:31:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:37542) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1s-0001bS-RH for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:31:11 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-481-qDBsdpAyNs-6ysfP69gqWg-1; Mon, 18 Jul 2022 06:31:04 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 836221C04B49; Mon, 18 Jul 2022 10:31:03 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 443972166B26; Mon, 18 Jul 2022 10:31:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658140268; 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=hUMS8Ss2bLBWFkMg86cs0CTf8NmhtFszeCU06faAvQI=; b=KBSg0JDZSMNYUAUVk3j/qK1vgfTkmGhyNgoa21VcQFmky6Qvs40c8ok0HCBv3AeC7y43gR wi7VHv9F1nolcn8e5VEAeAPXwhcVLt1mkK80ycrMPlONYtFURDpjxp7769KjTVQCkEQwJF 2TR5TteHQhh92bmo58VyDFKh64CBzII= X-MC-Unique: qDBsdpAyNs-6ysfP69gqWg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Gautam Dawar , Cornelia Huck , Laurent Vivier , Paolo Bonzini , "Gonglei (Arei)" , Zhu Lingshan , Stefan Hajnoczi , Liuxiangdong , Jason Wang , Stefano Garzarella , Eli Cohen , Harpreet Singh Anand , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Parav Pandit Subject: [PATCH v4 16/19] vdpa: Buffer CVQ support on shadow virtqueue Date: Mon, 18 Jul 2022 12:29:46 +0200 Message-Id: <20220718102949.2868267-17-eperezma@redhat.com> In-Reply-To: <20220718102949.2868267-1-eperezma@redhat.com> References: <20220718102949.2868267-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658140722124100003 Introduce the control virtqueue support for vDPA shadow virtqueue. This is needed for advanced networking features like rx filtering. Virtio-net control VQ copies the descriptors to qemu's VA, so we avoid TOCTOU with the guest's or device's memory every time there is a device model change. Otherwise, the guest could change the memory content in the time between qemu and the device read it. To demonstrate command handling, VIRTIO_NET_F_CTRL_MACADDR is implemented. If the virtio-net driver changes MAC the virtio-net device model will be updated with the new one, and a rx filtering change event will be raised. More cvq commands could be added here straightforwardly but they have not been tested. Signed-off-by: Eugenio P=C3=A9rez --- net/vhost-vdpa.c | 211 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 204 insertions(+), 7 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 2e3b6b10d8..3915b148c4 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -33,6 +33,9 @@ typedef struct VhostVDPAState { NetClientState nc; struct vhost_vdpa vhost_vdpa; VHostNetState *vhost_net; + + /* Control commands shadow buffers */ + void *cvq_cmd_out_buffer, *cvq_cmd_in_buffer; bool started; } VhostVDPAState; =20 @@ -131,6 +134,8 @@ static void vhost_vdpa_cleanup(NetClientState *nc) { VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); =20 + qemu_vfree(s->cvq_cmd_out_buffer); + qemu_vfree(s->cvq_cmd_in_buffer); if (s->vhost_net) { vhost_net_cleanup(s->vhost_net); g_free(s->vhost_net); @@ -190,24 +195,191 @@ static NetClientInfo net_vhost_vdpa_info =3D { .check_peer_type =3D vhost_vdpa_check_peer_type, }; =20 +static void vhost_vdpa_cvq_unmap_buf(struct vhost_vdpa *v, void *addr) +{ + VhostIOVATree *tree =3D v->iova_tree; + DMAMap needle =3D { + /* + * No need to specify size or to look for more translations since + * this contiguous chunk was allocated by us. + */ + .translated_addr =3D (hwaddr)(uintptr_t)addr, + }; + const DMAMap *map =3D vhost_iova_tree_find_iova(tree, &needle); + int r; + + if (unlikely(!map)) { + error_report("Cannot locate expected map"); + return; + } + + r =3D vhost_vdpa_dma_unmap(v, map->iova, map->size + 1); + if (unlikely(r !=3D 0)) { + error_report("Device cannot unmap: %s(%d)", g_strerror(r), r); + } + + vhost_iova_tree_remove(tree, map); +} + +static size_t vhost_vdpa_net_cvq_cmd_len(void) +{ + /* + * MAC_TABLE_SET is the ctrl command that produces the longer out buff= er. + * In buffer is always 1 byte, so it should fit here + */ + return sizeof(struct virtio_net_ctrl_hdr) + + 2 * sizeof(struct virtio_net_ctrl_mac) + + MAC_TABLE_ENTRIES * ETH_ALEN; +} + +static size_t vhost_vdpa_net_cvq_cmd_page_len(void) +{ + return ROUND_UP(vhost_vdpa_net_cvq_cmd_len(), qemu_real_host_page_size= ()); +} + +/** Copy and map a guest buffer. */ +static bool vhost_vdpa_cvq_map_buf(struct vhost_vdpa *v, + const struct iovec *out_data, + size_t out_num, size_t data_len, void *= buf, + size_t *written, bool write) +{ + DMAMap map =3D {}; + int r; + + if (unlikely(!data_len)) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid legnth of %s buffer\n", + __func__, write ? "in" : "out"); + return false; + } + + *written =3D iov_to_buf(out_data, out_num, 0, buf, data_len); + map.translated_addr =3D (hwaddr)(uintptr_t)buf; + map.size =3D vhost_vdpa_net_cvq_cmd_page_len() - 1; + map.perm =3D write ? IOMMU_RW : IOMMU_RO, + r =3D vhost_iova_tree_map_alloc(v->iova_tree, &map); + if (unlikely(r !=3D IOVA_OK)) { + error_report("Cannot map injected element"); + return false; + } + + r =3D vhost_vdpa_dma_map(v, map.iova, vhost_vdpa_net_cvq_cmd_page_len(= ), buf, + !write); + if (unlikely(r < 0)) { + goto dma_map_err; + } + + return true; + +dma_map_err: + vhost_iova_tree_remove(v->iova_tree, &map); + return false; +} + /** - * Forward buffer for the moment. + * Copy the guest element into a dedicated buffer suitable to be sent to N= IC + * + * @iov: [0] is the out buffer, [1] is the in one + */ +static bool vhost_vdpa_net_cvq_map_elem(VhostVDPAState *s, + VirtQueueElement *elem, + struct iovec *iov) +{ + size_t in_copied; + bool ok; + + iov[0].iov_base =3D s->cvq_cmd_out_buffer; + ok =3D vhost_vdpa_cvq_map_buf(&s->vhost_vdpa, elem->out_sg, elem->out_= num, + vhost_vdpa_net_cvq_cmd_len(), iov[0].iov_b= ase, + &iov[0].iov_len, false); + if (unlikely(!ok)) { + return false; + } + + iov[1].iov_base =3D s->cvq_cmd_in_buffer; + ok =3D vhost_vdpa_cvq_map_buf(&s->vhost_vdpa, NULL, 0, + sizeof(virtio_net_ctrl_ack), iov[1].iov_ba= se, + &in_copied, true); + if (unlikely(!ok)) { + vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, s->cvq_cmd_out_buffer); + return false; + } + + iov[1].iov_len =3D sizeof(virtio_net_ctrl_ack); + return true; +} + +/** + * Do not forward commands not supported by SVQ. Otherwise, the device cou= ld + * accept it and qemu would not know how to update the device model. + */ +static bool vhost_vdpa_net_cvq_validate_cmd(const struct iovec *out, + size_t out_num) +{ + struct virtio_net_ctrl_hdr ctrl; + size_t n; + + n =3D iov_to_buf(out, out_num, 0, &ctrl, sizeof(ctrl)); + if (unlikely(n < sizeof(ctrl))) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid legnth of out buffer %zu\n", __func__, = n); + return false; + } + + switch (ctrl.class) { + case VIRTIO_NET_CTRL_MAC: + switch (ctrl.cmd) { + case VIRTIO_NET_CTRL_MAC_ADDR_SET: + return true; + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid mac cmd %u\n", + __func__, ctrl.cmd); + }; + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid control class %u\n", + __func__, ctrl.class); + }; + + return false; +} + +/** + * Validate and copy control virtqueue commands. + * + * Following QEMU guidelines, we offer a copy of the buffers to the device= to + * prevent TOCTOU bugs. */ static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq, VirtQueueElement *elem, void *opaque) { - unsigned int n =3D elem->out_num + elem->in_num; - g_autofree struct iovec *dev_buffers =3D g_new(struct iovec, n); + VhostVDPAState *s =3D opaque; size_t in_len, dev_written; virtio_net_ctrl_ack status =3D VIRTIO_NET_ERR; + /* out and in buffers sent to the device */ + struct iovec dev_buffers[2] =3D { + { .iov_base =3D s->cvq_cmd_out_buffer }, + { .iov_base =3D s->cvq_cmd_in_buffer }, + }; + /* in buffer used for device model */ + const struct iovec in =3D { + .iov_base =3D &status, + .iov_len =3D sizeof(status), + }; int r; + bool ok; =20 - memcpy(dev_buffers, elem->out_sg, elem->out_num); - memcpy(dev_buffers + elem->out_num, elem->in_sg, elem->in_num); + ok =3D vhost_vdpa_net_cvq_map_elem(s, elem, dev_buffers); + if (unlikely(!ok)) { + goto out; + } =20 - r =3D vhost_svq_add(svq, &dev_buffers[0], elem->out_num, &dev_buffers[= 1], - elem->in_num, elem); + ok =3D vhost_vdpa_net_cvq_validate_cmd(&dev_buffers[0], 1); + if (unlikely(!ok)) { + goto out; + } + + r =3D vhost_svq_add(svq, &dev_buffers[0], 1, &dev_buffers[1], 1, elem); if (unlikely(r !=3D 0)) { if (unlikely(r =3D=3D -ENOSPC)) { qemu_log_mask(LOG_GUEST_ERROR, "%s: No space on device queue\n= ", @@ -224,6 +396,18 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShado= wVirtqueue *svq, dev_written =3D vhost_svq_poll(svq); if (unlikely(dev_written < sizeof(status))) { error_report("Insufficient written data (%zu)", dev_written); + goto out; + } + + memcpy(&status, dev_buffers[1].iov_base, sizeof(status)); + if (status !=3D VIRTIO_NET_OK) { + goto out; + } + + status =3D VIRTIO_NET_ERR; + virtio_net_handle_ctrl_iov(svq->vdev, &in, 1, dev_buffers, 1); + if (status !=3D VIRTIO_NET_OK) { + error_report("Bad CVQ processing in model"); } =20 out: @@ -234,6 +418,12 @@ out: } vhost_svq_push_elem(svq, elem, MIN(in_len, sizeof(status))); g_free(elem); + if (dev_buffers[0].iov_base) { + vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, dev_buffers[0].iov_base); + } + if (dev_buffers[1].iov_base) { + vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, dev_buffers[1].iov_base); + } return r; } =20 @@ -266,6 +456,13 @@ static NetClientState *net_vhost_vdpa_init(NetClientSt= ate *peer, s->vhost_vdpa.device_fd =3D vdpa_device_fd; s->vhost_vdpa.index =3D queue_pair_index; if (!is_datapath) { + s->cvq_cmd_out_buffer =3D qemu_memalign(qemu_real_host_page_size(), + vhost_vdpa_net_cvq_cmd_page_le= n()); + memset(s->cvq_cmd_out_buffer, 0, vhost_vdpa_net_cvq_cmd_page_len()= ); + s->cvq_cmd_in_buffer =3D qemu_memalign(qemu_real_host_page_size(), + vhost_vdpa_net_cvq_cmd_page_le= n()); + memset(s->cvq_cmd_in_buffer, 0, vhost_vdpa_net_cvq_cmd_page_len()); + s->vhost_vdpa.shadow_vq_ops =3D &vhost_vdpa_net_svq_ops; s->vhost_vdpa.shadow_vq_ops_opaque =3D s; } --=20 2.31.1 From nobody Sun Feb 8 13:45:28 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658141149; cv=none; d=zohomail.com; s=zohoarc; b=CP1CjEwfiDLbZ/9SYJj3pJi8XNm/hNuqMzkRA+TnWBftUhRabE1U4lf7LdPdWtVYSyBfzvlZe/IXtl8L/rZOq5hsFLXA21ySL+TJmW4apRLfLSqvY/kioTAw1A+WR+GWCK0nr7CJbM5mYdW8rWNJcxWTSTzHyOh8sSTQeJujcfU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658141149; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NJd6rS0xsEmkJ2ZxEsGxFc+n30yMDcFSC79dY5yx1Lk=; b=cNf3BLpda6a3sfKPKlNZYqPLbxDWwkB/0iXEfS7X814vZNMjTBTb07o4BxBIRkMpHWiCQS085/BjPaqzjkNmAer+UlLeZctJ4Y90XXCix0aF7yNW7tOcKEf5uC95OgGm2qAD6WGOTeigP4lxs51osY3P6sWGQHuBKLmi0bjtSlA= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658141149357133.1681244418087; Mon, 18 Jul 2022 03:45:49 -0700 (PDT) Received: from localhost ([::1]:33808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDOG3-0003iq-Lc for importer@patchew.org; Mon, 18 Jul 2022 06:45:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55190) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1x-0000uw-KJ for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:31:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:60720) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1v-0001dA-UY for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:31:13 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-655-QiS3oNS7MiCceSyioHSJAQ-1; Mon, 18 Jul 2022 06:31:07 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9D730101A586; Mon, 18 Jul 2022 10:31:06 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id CCAE82166B29; Mon, 18 Jul 2022 10:31:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658140270; 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=NJd6rS0xsEmkJ2ZxEsGxFc+n30yMDcFSC79dY5yx1Lk=; b=N+wacW2WSwYAN+UMWa5aOdhhhmGS2EyWpVktG9P7AL/cUTdIGalgpppbYrgYqlXa+aC8KH fWb/xxEyJ+rLKCL+Y3TAqKh4fva/sRiLnU80SVS/ppWMlc9EfLtVIkQueGlMtnhHZ1j03k bvtXUCMG7ys5Y8thhS3xdq7mYAX/yQ0= X-MC-Unique: QiS3oNS7MiCceSyioHSJAQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Gautam Dawar , Cornelia Huck , Laurent Vivier , Paolo Bonzini , "Gonglei (Arei)" , Zhu Lingshan , Stefan Hajnoczi , Liuxiangdong , Jason Wang , Stefano Garzarella , Eli Cohen , Harpreet Singh Anand , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Parav Pandit Subject: [PATCH v4 17/19] vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs Date: Mon, 18 Jul 2022 12:29:47 +0200 Message-Id: <20220718102949.2868267-18-eperezma@redhat.com> In-Reply-To: <20220718102949.2868267-1-eperezma@redhat.com> References: <20220718102949.2868267-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658141151133100001 To know the device features is needed for CVQ SVQ, so SVQ knows if it can handle all commands or not. Extract from vhost_vdpa_get_max_queue_pairs so we can reuse it. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- net/vhost-vdpa.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 3915b148c4..0afa60bb51 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -474,20 +474,24 @@ static NetClientState *net_vhost_vdpa_init(NetClientS= tate *peer, return nc; } =20 -static int vhost_vdpa_get_max_queue_pairs(int fd, int *has_cvq, Error **er= rp) +static int vhost_vdpa_get_features(int fd, uint64_t *features, Error **err= p) +{ + int ret =3D ioctl(fd, VHOST_GET_FEATURES, features); + if (unlikely(ret < 0)) { + error_setg_errno(errp, errno, + "Fail to query features from vhost-vDPA device"); + } + return ret; +} + +static int vhost_vdpa_get_max_queue_pairs(int fd, uint64_t features, + int *has_cvq, Error **errp) { unsigned long config_size =3D offsetof(struct vhost_vdpa_config, buf); g_autofree struct vhost_vdpa_config *config =3D NULL; __virtio16 *max_queue_pairs; - uint64_t features; int ret; =20 - ret =3D ioctl(fd, VHOST_GET_FEATURES, &features); - if (ret) { - error_setg(errp, "Fail to query features from vhost-vDPA device"); - return ret; - } - if (features & (1 << VIRTIO_NET_F_CTRL_VQ)) { *has_cvq =3D 1; } else { @@ -517,10 +521,11 @@ int net_init_vhost_vdpa(const Netdev *netdev, const c= har *name, NetClientState *peer, Error **errp) { const NetdevVhostVDPAOptions *opts; + uint64_t features; int vdpa_device_fd; g_autofree NetClientState **ncs =3D NULL; NetClientState *nc; - int queue_pairs, i, has_cvq =3D 0; + int queue_pairs, r, i, has_cvq =3D 0; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); opts =3D &netdev->u.vhost_vdpa; @@ -534,7 +539,12 @@ int net_init_vhost_vdpa(const Netdev *netdev, const ch= ar *name, return -errno; } =20 - queue_pairs =3D vhost_vdpa_get_max_queue_pairs(vdpa_device_fd, + r =3D vhost_vdpa_get_features(vdpa_device_fd, &features, errp); + if (unlikely(r < 0)) { + return r; + } + + queue_pairs =3D vhost_vdpa_get_max_queue_pairs(vdpa_device_fd, feature= s, &has_cvq, errp); if (queue_pairs < 0) { qemu_close(vdpa_device_fd); --=20 2.31.1 From nobody Sun Feb 8 13:45:28 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658140857; cv=none; d=zohomail.com; s=zohoarc; b=JWZtn3kTpxGyIO3KmLlbmnYHqGIkcdm5KfDK4i5XsamVC9hoWq4ohwwACaxGI9BmfSl8zdysNW48qezbxGlPFjrVIO66BsfAd0xsBDMV6xNhaVGl3D4IO0xGUEpkB3BCP+11Dcml/relFL2PnjT0WT0jLl8xxdkp1ezZA0AM2lY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658140857; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oF55J2F/WdWJFH5uGX59cHC74FkBU6RmtMqfQyGsPgw=; b=Iccx8US9GSxtX5A8Jkit6+dD6S8DojOsowxcHVrD0uWdnnK4Fd1VCGv7XXoKj7c5SqU8OgLRtqnApr2JBMw91q4jsqK1nZ9FnrvGkBEHMlN/QJZB5QK1ktxT9f0d+YZYrCcXbQN4TdNZPysVqV4WNdZDbqhvpDDsIkeGGwhCRhA= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16581408572901002.475011123109; Mon, 18 Jul 2022 03:40:57 -0700 (PDT) Received: from localhost ([::1]:49968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDOBL-0003iQ-Qn for importer@patchew.org; Mon, 18 Jul 2022 06:40:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1z-000106-Fl for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:31:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:39178) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO1x-0001hD-Sn for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:31:15 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-142-pukAO7rIPvCsR_vuw2IPjA-1; Mon, 18 Jul 2022 06:31:10 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B2FDF38041C2; Mon, 18 Jul 2022 10:31:09 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE0F92166B29; Mon, 18 Jul 2022 10:31:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658140273; 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=oF55J2F/WdWJFH5uGX59cHC74FkBU6RmtMqfQyGsPgw=; b=JvkiL7/TBloeCIs+nXmdRwjBX2zTpLkEAXPlUfPeQ4K5G0aCf0+V/2UVZVQNAfdtJBaO0c E/SrNrSxGDnEh/UPGUczlOxeyQWr42JB36FZ5d6ImDL/IF1exTolPp82CN2skuR3KgT/af 481m049DzqeBti8PgG6C6+Mmwm/bR0I= X-MC-Unique: pukAO7rIPvCsR_vuw2IPjA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Gautam Dawar , Cornelia Huck , Laurent Vivier , Paolo Bonzini , "Gonglei (Arei)" , Zhu Lingshan , Stefan Hajnoczi , Liuxiangdong , Jason Wang , Stefano Garzarella , Eli Cohen , Harpreet Singh Anand , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Parav Pandit Subject: [PATCH v4 18/19] vdpa: Add device migration blocker Date: Mon, 18 Jul 2022 12:29:48 +0200 Message-Id: <20220718102949.2868267-19-eperezma@redhat.com> In-Reply-To: <20220718102949.2868267-1-eperezma@redhat.com> References: <20220718102949.2868267-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658140859055100001 Since the vhost-vdpa device is exposing _F_LOG, adding a migration blocker = if it uses CVQ. Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/vhost-vdpa.h | 1 + hw/virtio/vhost-vdpa.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 1111d85643..d10a89303e 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -35,6 +35,7 @@ typedef struct vhost_vdpa { bool shadow_vqs_enabled; /* IOVA mapping used by the Shadow Virtqueue */ VhostIOVATree *iova_tree; + Error *migration_blocker; GPtrArray *shadow_vqs; const VhostShadowVirtqueueOps *shadow_vq_ops; void *shadow_vq_ops_opaque; diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index beaaa7049a..795ed5a049 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -20,6 +20,7 @@ #include "hw/virtio/vhost-shadow-virtqueue.h" #include "hw/virtio/vhost-vdpa.h" #include "exec/address-spaces.h" +#include "migration/blocker.h" #include "qemu/cutils.h" #include "qemu/main-loop.h" #include "cpu.h" @@ -1022,6 +1023,13 @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *= dev) return true; } =20 + if (v->migration_blocker) { + int r =3D migrate_add_blocker(v->migration_blocker, &err); + if (unlikely(r < 0)) { + goto err_migration_blocker; + } + } + for (i =3D 0; i < v->shadow_vqs->len; ++i) { VirtQueue *vq =3D virtio_get_queue(dev->vdev, dev->vq_index + i); VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs, i); @@ -1064,6 +1072,9 @@ err: vhost_svq_stop(svq); } =20 +err_migration_blocker: + error_reportf_err(err, "Cannot setup SVQ %u: ", i); + return false; } =20 @@ -1083,6 +1094,9 @@ static bool vhost_vdpa_svqs_stop(struct vhost_dev *de= v) } } =20 + if (v->migration_blocker) { + migrate_del_blocker(v->migration_blocker); + } return true; } =20 --=20 2.31.1 From nobody Sun Feb 8 13:45:28 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658140986; cv=none; d=zohomail.com; s=zohoarc; b=kcFUNsRDLrMDGEsZ9VmrN+dBxnxM+pXSXV3zBm4ZdwaTe28YTHpabn83ek7T/6L943sokHIYFTkzoKjMLjyBmt3jHSya9/o0W3l39VHvbXsS6+y9PfSQeQnwxmTrwSvmCpdPUjFGTB0PzwifsTzG5jtPNumIJ0cURWkbbt0CAgU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658140986; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=06r+/t48jFzylbXxQOLPKRPSU/+Lfz00kuQvdmdjLrM=; b=DbXEXVlICIj9+dAkwLv6bKNSxBCnwx8qSOWd6mYUcmz3zF0l/q+oiruggoWXruynocVDG9yvgBGsjH3aIPsugKo+q8RXREtGJdYXtDtSG5/dIhXFt/sKJhyP9blie/EJ4A4tSNSfhtiT/XhFRCFgsqeh2tKb7L3KlRJ/lcAiTcY= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658140986098613.4553067030696; Mon, 18 Jul 2022 03:43:06 -0700 (PDT) Received: from localhost ([::1]:56040 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDODR-00085X-4U for importer@patchew.org; Mon, 18 Jul 2022 06:43:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55268) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO27-0001J4-Ch for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:31:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54869) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDO25-0001iL-Ik for qemu-devel@nongnu.org; Mon, 18 Jul 2022 06:31:22 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-644-wfDJD-h9NSmwekUDmpBG9w-1; Mon, 18 Jul 2022 06:31:15 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E63F2101A588; Mon, 18 Jul 2022 10:31:13 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 007882166B26; Mon, 18 Jul 2022 10:31:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658140281; 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=06r+/t48jFzylbXxQOLPKRPSU/+Lfz00kuQvdmdjLrM=; b=DFeMvwg+Wf3f0W7KfNUsRh82rjHPjHnVz7rBpGl9W8kqFERkhqcxAwGj0nujGi8ziMpCYj 2Vu972Ug3SikDQzm8yGacHKcLv8OV9C9uugqZT1LcfPFwLFbIP8vK1D8/NC5aPJRnyZmDB Jdj+dUrvkmv6acwbjygOXiDGjFv2DWA= X-MC-Unique: wfDJD-h9NSmwekUDmpBG9w-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Gautam Dawar , Cornelia Huck , Laurent Vivier , Paolo Bonzini , "Gonglei (Arei)" , Zhu Lingshan , Stefan Hajnoczi , Liuxiangdong , Jason Wang , Stefano Garzarella , Eli Cohen , Harpreet Singh Anand , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Parav Pandit Subject: [PATCH v4 19/19] vdpa: Add x-svq to NetdevVhostVDPAOptions Date: Mon, 18 Jul 2022 12:29:49 +0200 Message-Id: <20220718102949.2868267-20-eperezma@redhat.com> In-Reply-To: <20220718102949.2868267-1-eperezma@redhat.com> References: <20220718102949.2868267-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658140987610100001 Finally offering the possibility to enable SVQ from the command line. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Markus Armbruster --- qapi/net.json | 9 +++++- net/vhost-vdpa.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/qapi/net.json b/qapi/net.json index 9af11e9a3b..75ba2cb989 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -445,12 +445,19 @@ # @queues: number of queues to be created for multiqueue vhost-vdpa # (default: 1) # +# @x-svq: Start device with (experimental) shadow virtqueue. (Since 7.1) +# (default: false) +# +# Features: +# @unstable: Member @x-svq is experimental. +# # Since: 5.1 ## { 'struct': 'NetdevVhostVDPAOptions', 'data': { '*vhostdev': 'str', - '*queues': 'int' } } + '*queues': 'int', + '*x-svq': {'type': 'bool', 'features' : [ 'unstable'] } } } =20 ## # @NetdevVmnetHostOptions: diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 0afa60bb51..986e6414b4 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -75,6 +75,28 @@ const int vdpa_feature_bits[] =3D { VHOST_INVALID_FEATURE_BIT }; =20 +/** Supported device specific feature bits with SVQ */ +static const uint64_t vdpa_svq_device_features =3D + BIT_ULL(VIRTIO_NET_F_CSUM) | + BIT_ULL(VIRTIO_NET_F_GUEST_CSUM) | + BIT_ULL(VIRTIO_NET_F_MTU) | + BIT_ULL(VIRTIO_NET_F_MAC) | + BIT_ULL(VIRTIO_NET_F_GUEST_TSO4) | + BIT_ULL(VIRTIO_NET_F_GUEST_TSO6) | + BIT_ULL(VIRTIO_NET_F_GUEST_ECN) | + BIT_ULL(VIRTIO_NET_F_GUEST_UFO) | + BIT_ULL(VIRTIO_NET_F_HOST_TSO4) | + BIT_ULL(VIRTIO_NET_F_HOST_TSO6) | + BIT_ULL(VIRTIO_NET_F_HOST_ECN) | + BIT_ULL(VIRTIO_NET_F_HOST_UFO) | + BIT_ULL(VIRTIO_NET_F_MRG_RXBUF) | + BIT_ULL(VIRTIO_NET_F_STATUS) | + BIT_ULL(VIRTIO_NET_F_CTRL_VQ) | + BIT_ULL(VIRTIO_F_ANY_LAYOUT) | + BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR) | + BIT_ULL(VIRTIO_NET_F_RSC_EXT) | + BIT_ULL(VIRTIO_NET_F_STANDBY); + VHostNetState *vhost_vdpa_get_vhost_net(NetClientState *nc) { VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); @@ -133,9 +155,13 @@ err_init: static void vhost_vdpa_cleanup(NetClientState *nc) { VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); + struct vhost_dev *dev =3D &s->vhost_net->dev; =20 qemu_vfree(s->cvq_cmd_out_buffer); qemu_vfree(s->cvq_cmd_in_buffer); + if (dev->vq_index + dev->nvqs =3D=3D dev->vq_index_end) { + g_clear_pointer(&s->vhost_vdpa.iova_tree, vhost_iova_tree_delete); + } if (s->vhost_net) { vhost_net_cleanup(s->vhost_net); g_free(s->vhost_net); @@ -437,7 +463,9 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, int vdpa_device_fd, int queue_pair_index, int nvqs, - bool is_datapath) + bool is_datapath, + bool svq, + VhostIOVATree *iova_tree) { NetClientState *nc =3D NULL; VhostVDPAState *s; @@ -455,6 +483,8 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, =20 s->vhost_vdpa.device_fd =3D vdpa_device_fd; s->vhost_vdpa.index =3D queue_pair_index; + s->vhost_vdpa.shadow_vqs_enabled =3D svq; + s->vhost_vdpa.iova_tree =3D iova_tree; if (!is_datapath) { s->cvq_cmd_out_buffer =3D qemu_memalign(qemu_real_host_page_size(), vhost_vdpa_net_cvq_cmd_page_le= n()); @@ -465,6 +495,8 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, =20 s->vhost_vdpa.shadow_vq_ops =3D &vhost_vdpa_net_svq_ops; s->vhost_vdpa.shadow_vq_ops_opaque =3D s; + error_setg(&s->vhost_vdpa.migration_blocker, + "Migration disabled: vhost-vdpa uses CVQ."); } ret =3D vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, queue_pair_index, n= vqs); if (ret) { @@ -474,6 +506,14 @@ static NetClientState *net_vhost_vdpa_init(NetClientSt= ate *peer, return nc; } =20 +static int vhost_vdpa_get_iova_range(int fd, + struct vhost_vdpa_iova_range *iova_ra= nge) +{ + int ret =3D ioctl(fd, VHOST_VDPA_GET_IOVA_RANGE, iova_range); + + return ret < 0 ? -errno : 0; +} + static int vhost_vdpa_get_features(int fd, uint64_t *features, Error **err= p) { int ret =3D ioctl(fd, VHOST_GET_FEATURES, features); @@ -524,6 +564,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const cha= r *name, uint64_t features; int vdpa_device_fd; g_autofree NetClientState **ncs =3D NULL; + g_autoptr(VhostIOVATree) iova_tree =3D NULL; NetClientState *nc; int queue_pairs, r, i, has_cvq =3D 0; =20 @@ -551,22 +592,45 @@ int net_init_vhost_vdpa(const Netdev *netdev, const c= har *name, return queue_pairs; } =20 + if (opts->x_svq) { + struct vhost_vdpa_iova_range iova_range; + + uint64_t invalid_dev_features =3D + features & ~vdpa_svq_device_features & + /* Transport are all accepted at this point */ + ~MAKE_64BIT_MASK(VIRTIO_TRANSPORT_F_START, + VIRTIO_TRANSPORT_F_END - VIRTIO_TRANSPORT_F_S= TART); + + if (invalid_dev_features) { + error_setg(errp, "vdpa svq does not work with features 0x%" PR= Ix64, + invalid_dev_features); + goto err_svq; + } + + vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range); + iova_tree =3D vhost_iova_tree_new(iova_range.first, iova_range.las= t); + } + ncs =3D g_malloc0(sizeof(*ncs) * queue_pairs); =20 for (i =3D 0; i < queue_pairs; i++) { ncs[i] =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, - vdpa_device_fd, i, 2, true); + vdpa_device_fd, i, 2, true, opts->x_s= vq, + iova_tree); if (!ncs[i]) goto err; } =20 if (has_cvq) { nc =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, - vdpa_device_fd, i, 1, false); + vdpa_device_fd, i, 1, false, + opts->x_svq, iova_tree); if (!nc) goto err; } =20 + /* iova_tree ownership belongs to last NetClientState */ + g_steal_pointer(&iova_tree); return 0; =20 err: @@ -575,6 +639,8 @@ err: qemu_del_net_client(ncs[i]); } } + +err_svq: qemu_close(vdpa_device_fd); =20 return -1; --=20 2.31.1