From nobody Sun Feb 8 17:42:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644867861533411.8411716295585; Mon, 14 Feb 2022 11:44:21 -0800 (PST) Received: from localhost ([::1]:42444 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nJhGm-0006NB-Hz for importer@patchew.org; Mon, 14 Feb 2022 14:44:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJgqI-0002dy-RK for qemu-devel@nongnu.org; Mon, 14 Feb 2022 14:16:59 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33289) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJgqG-0001Cq-Mx for qemu-devel@nongnu.org; Mon, 14 Feb 2022 14:16:58 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-120-1uwT9f6eOTm1kwiaBJ2aPg-1; Mon, 14 Feb 2022 14:16:52 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AF4EC100C662; Mon, 14 Feb 2022 19:16:50 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF8425C22B; Mon, 14 Feb 2022 19:16:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644866215; 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=y7Elc4mWMixGdGSkYMfwRZ2DSvxjccf19y5bT0QA/iI=; b=D0jQflQE8XLx/GlUPW4G8WIGcQIyw6cHPtKeucui2csX9ptIjwJH2d3BpPrsdIEBCzGLV3 jj/xIaLTiNeOpEZ08oXMjJXq4IJZisFkH7vABSYoJnHTimqf5vqlj6bdqXA97NPB5D5t1R pxU7xJ32LNIUGEl6SP13T4GVkkVzR+o= X-MC-Unique: 1uwT9f6eOTm1kwiaBJ2aPg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 1/9] virtio-net: Expose ctrl virtqueue logic Date: Mon, 14 Feb 2022 20:16:27 +0100 Message-Id: <20220214191635.1604932-2-eperezma@redhat.com> In-Reply-To: <20220214191635.1604932-1-eperezma@redhat.com> References: <20220214191635.1604932-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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: -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.083, 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Harpreet Singh Anand , Eli Cohen , Zhu Lingshan Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644867862546100001 This allows external vhost-net devices to modify the state of the VirtIO device model once vhost-vdpa device has acknowledge the control commands. Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/virtio-net.h | 3 ++ hw/net/virtio-net.c | 83 ++++++++++++++++++++-------------- 2 files changed, 52 insertions(+), 34 deletions(-) diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index eb87032627..e62f9e227f 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -218,6 +218,9 @@ struct VirtIONet { struct EBPFRSSContext ebpf_rss; }; =20 +unsigned virtio_net_handle_ctrl_iov(VirtIODevice *vdev, + const struct iovec *in_sg, size_t in_n= um, + 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 49cd13314a..a9027b3373 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1417,56 +1417,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) +unsigned virtio_net_handle_ctrl_iov(VirtIODevice *vdev, + const struct iovec *in_sg, size_t in_n= um, + 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_memdup(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 (;;) { + unsigned 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; - } =20 - iov_cnt =3D elem->out_num; - iov2 =3D iov =3D g_memdup(elem->out_sg, sizeof(struct iovec) * ele= m->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.27.0 From nobody Sun Feb 8 17:42:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644866826924773.117268979696; Mon, 14 Feb 2022 11:27:06 -0800 (PST) Received: from localhost ([::1]:44048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nJh05-0004b9-90 for importer@patchew.org; Mon, 14 Feb 2022 14:27:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50030) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJgqJ-0002dm-8O for qemu-devel@nongnu.org; Mon, 14 Feb 2022 14:16:59 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:38693) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJgqG-0001Cu-N5 for qemu-devel@nongnu.org; Mon, 14 Feb 2022 14:16:57 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-582-RC2E6uP6N5ajyaFlHUnhLw-1; Mon, 14 Feb 2022 14:16:54 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 809841091DA0; Mon, 14 Feb 2022 19:16:53 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 19AC15C22B; Mon, 14 Feb 2022 19:16:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644866215; 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=UaGHnLz8E816ryT4XXzpJjwLPqRClNUuWRSFbDTm/Uo=; b=FF/NFgOwln9KIaOlnTOEB0ciXI4T9N8a/g/DiVfTV3REB+bJE/Xe2CmjsHljMmw9eyYaec 60Knds4k5MrpyC6TdCKbXY2fZ+HU108tbmMawD+d+e0/z1eY0VTmL4QElUXtz7YxpXELSi jQAY9T/77FrumR6fjKHwqXTlsi9fEwg= X-MC-Unique: RC2E6uP6N5ajyaFlHUnhLw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 2/9] vdpa: Extract get geatures part from vhost_vdpa_get_max_queue_pairs Date: Mon, 14 Feb 2022 20:16:28 +0100 Message-Id: <20220214191635.1604932-3-eperezma@redhat.com> In-Reply-To: <20220214191635.1604932-1-eperezma@redhat.com> References: <20220214191635.1604932-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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: -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.083, 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Harpreet Singh Anand , Eli Cohen , Zhu Lingshan Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644866828524100001 To know the device features is also needed for CVQ SVQ. Extract from vhost_vdpa_get_max_queue_pairs so we can reuse it. Report errno in case of failure getting them while we're at it. Signed-off-by: Eugenio P=C3=A9rez --- 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 420614d590..fc844a7ce6 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -241,20 +241,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 (ret) { + error_setg_errno(errp, errno, + "Fail to query features from vhost-vDPA devi= ce"); + } + 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 { @@ -285,10 +289,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; g_autoptr(VhostIOVATree) iova_tree =3D NULL; struct vhost_vdpa_iova_range iova_range; =20 @@ -304,7 +309,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 (r) { + 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.27.0 From nobody Sun Feb 8 17:42:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 164486803430926.452568744710447; Mon, 14 Feb 2022 11:47:14 -0800 (PST) Received: from localhost ([::1]:48076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nJhJZ-0001rz-1P for importer@patchew.org; Mon, 14 Feb 2022 14:47:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50082) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJgqN-0002k1-Ux for qemu-devel@nongnu.org; Mon, 14 Feb 2022 14:17:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:54587) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJgqM-0001Dk-Es for qemu-devel@nongnu.org; Mon, 14 Feb 2022 14:17:03 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-201-PQ9BFi5IN-ygWeqoIEQ5eg-1; Mon, 14 Feb 2022 14:16:58 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A103F1091DA0; Mon, 14 Feb 2022 19:16:56 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA01D5FC08; Mon, 14 Feb 2022 19:16:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644866221; 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=rzdsNE9UetoKhKJybQR3QEP62uOL2rcWg/v3BeqUYCI=; b=HMaAOPFGM6HrV40UpOncezjEoNrdFL7ZHNjvwLvG/630kLLzyuiZ0V1TCeZX3AAxnG+IiJ NHkEmyHcfibxgCRNIdkJ0eiXvBgu92se8zZTKMVY0Kuh7md60i+Uclj4RIr9Es5MMLkbrR rzmr74OuZkPxAuCqo7fVhKO68t8iVhc= X-MC-Unique: PQ9BFi5IN-ygWeqoIEQ5eg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 3/9] virtio: Make virtqueue_alloc_element non-static Date: Mon, 14 Feb 2022 20:16:29 +0100 Message-Id: <20220214191635.1604932-4-eperezma@redhat.com> In-Reply-To: <20220214191635.1604932-1-eperezma@redhat.com> References: <20220214191635.1604932-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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.083, 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Harpreet Singh Anand , Eli Cohen , Zhu Lingshan Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644868034999100001 So SVQ can allocate elements using it Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/virtio.h | 1 + hw/virtio/virtio.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index f095637058..6f4cccfd42 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -195,6 +195,7 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueEleme= nt *elem, unsigned int len, unsigned int idx); =20 void virtqueue_map(VirtIODevice *vdev, VirtQueueElement *elem); +void *virtqueue_alloc_element(size_t sz, unsigned out_num, unsigned in_num= ); void *virtqueue_pop(VirtQueue *vq, size_t sz); unsigned int virtqueue_drop_all(VirtQueue *vq); void *qemu_get_virtqueue_element(VirtIODevice *vdev, QEMUFile *f, size_t s= z); diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index aae72fb8b7..ca7d1f0613 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1376,7 +1376,7 @@ void virtqueue_map(VirtIODevice *vdev, VirtQueueEleme= nt *elem) fa= lse); } =20 -static void *virtqueue_alloc_element(size_t sz, unsigned out_num, unsigned= in_num) +void *virtqueue_alloc_element(size_t sz, unsigned out_num, unsigned in_num) { VirtQueueElement *elem; size_t in_addr_ofs =3D QEMU_ALIGN_UP(sz, __alignof__(elem->in_addr[0])= ); --=20 2.27.0 From nobody Sun Feb 8 17:42:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644867350537433.9110451473923; Mon, 14 Feb 2022 11:35:50 -0800 (PST) Received: from localhost ([::1]:52712 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nJh8X-0002U9-CI for importer@patchew.org; Mon, 14 Feb 2022 14:35:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50116) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJgqV-0002wR-PH for qemu-devel@nongnu.org; Mon, 14 Feb 2022 14:17:12 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:47317) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJgqT-0001FW-Kr for qemu-devel@nongnu.org; Mon, 14 Feb 2022 14:17:11 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-83-JCpfY3zkN8etghK73UaSaw-1; Mon, 14 Feb 2022 14:17:05 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 49D4F18397A7; Mon, 14 Feb 2022 19:17:04 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 056C25F9B0; Mon, 14 Feb 2022 19:16:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644866229; 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=4eHPTaikCQbJVrEmx1ahQ35mWO0n70e57bZoijuIK14=; b=A2Nfd0oVMbc32ojtSZDFW+4V6VSzzFZ6n1Ayqz+BFUnP7EfkQt8f0OSLRWiSc72F/6wRxr 1vMc5V8pyyqzx26svLTFjyw0mQFQuuSHtbKjiX685ywTVZoB3QZkLm7aBWU/wx1i0SbzdR 6AH329op6ju+y8UlFCBN9Q1Fag2Mq7Y= X-MC-Unique: JCpfY3zkN8etghK73UaSaw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 4/9] vhost: Add SVQElement Date: Mon, 14 Feb 2022 20:16:30 +0100 Message-Id: <20220214191635.1604932-5-eperezma@redhat.com> In-Reply-To: <20220214191635.1604932-1-eperezma@redhat.com> References: <20220214191635.1604932-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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.083, 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Harpreet Singh Anand , Eli Cohen , Zhu Lingshan Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644867352512100001 This allows SVQ to add metadata to the different queue elements Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.c | 52 ++++++++++++++++++------------ 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 873e39e9cf..ea32b7ae7f 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -17,6 +17,10 @@ #include "qemu/error-report.h" #include "qemu/main-loop.h" =20 +typedef struct SVQElement { + VirtQueueElement elem; +} SVQElement; + /* Shadow virtqueue to relay notifications */ struct VhostShadowVirtqueue { /* Shadow vring */ @@ -50,10 +54,10 @@ struct VhostShadowVirtqueue { VhostIOVATree *iova_tree; =20 /* Map for returning guest's descriptors */ - VirtQueueElement **ring_id_maps; + SVQElement **ring_id_maps; =20 /* Next VirtQueue element that guest made available */ - VirtQueueElement *next_guest_avail_elem; + SVQElement *next_guest_avail_elem; =20 /* Next head to expose to device */ uint16_t avail_idx_shadow; @@ -281,9 +285,10 @@ static void vhost_vring_write_descs(VhostShadowVirtque= ue *svq, } =20 static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, - VirtQueueElement *elem, + SVQElement *svq_elem, unsigned *head) { + const VirtQueueElement *elem =3D &svq_elem->elem; unsigned avail_idx; vring_avail_t *avail =3D svq->vring.avail; bool ok; @@ -324,7 +329,7 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *s= vq, return true; } =20 -static bool vhost_svq_add(VhostShadowVirtqueue *svq, VirtQueueElement *ele= m) +static bool vhost_svq_add(VhostShadowVirtqueue *svq, SVQElement *elem) { unsigned qemu_head; bool ok =3D vhost_svq_add_split(svq, elem, &qemu_head); @@ -372,19 +377,21 @@ static void vhost_handle_guest_kick(VhostShadowVirtqu= eue *svq) } =20 while (true) { + SVQElement *svq_elem; VirtQueueElement *elem; bool ok; =20 if (svq->next_guest_avail_elem) { - elem =3D g_steal_pointer(&svq->next_guest_avail_elem); + svq_elem =3D g_steal_pointer(&svq->next_guest_avail_elem); } else { - elem =3D virtqueue_pop(svq->vq, sizeof(*elem)); + svq_elem =3D virtqueue_pop(svq->vq, sizeof(*elem)); } =20 - if (!elem) { + if (!svq_elem) { break; } =20 + elem =3D &svq_elem->elem; if (elem->out_num + elem->in_num > vhost_svq_available_slots(svq)) { /* @@ -398,11 +405,11 @@ static void vhost_handle_guest_kick(VhostShadowVirtqu= eue *svq) * queue the current guest descriptor and ignore further k= icks * until some elements are used. */ - svq->next_guest_avail_elem =3D elem; + svq->next_guest_avail_elem =3D svq_elem; return; } =20 - ok =3D vhost_svq_add(svq, elem); + ok =3D vhost_svq_add(svq, svq_elem); if (unlikely(!ok)) { /* VQ is broken, just return and ignore any other kicks */ return; @@ -437,7 +444,7 @@ static bool vhost_svq_more_used(VhostShadowVirtqueue *s= vq) return svq->last_used_idx !=3D svq->shadow_used_idx; } =20 -static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq) +static SVQElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq) { vring_desc_t *descs =3D svq->vring.desc; const vring_used_t *used =3D svq->vring.used; @@ -471,7 +478,7 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadowV= irtqueue *svq) descs[used_elem.id].next =3D svq->free_head; svq->free_head =3D used_elem.id; =20 - svq->ring_id_maps[used_elem.id]->len =3D used_elem.len; + svq->ring_id_maps[used_elem.id]->elem.len =3D used_elem.len; return g_steal_pointer(&svq->ring_id_maps[used_elem.id]); } =20 @@ -486,11 +493,13 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq, =20 vhost_svq_set_notification(svq, false); while (true) { - g_autofree VirtQueueElement *elem =3D vhost_svq_get_buf(svq); - if (!elem) { + g_autofree SVQElement *svq_elem =3D vhost_svq_get_buf(svq); + VirtQueueElement *elem; + if (!svq_elem) { break; } =20 + elem =3D &svq_elem->elem; if (unlikely(i >=3D svq->vring.num)) { virtio_error(svq->vdev, "More than %u used buffers obtained in a %u size = SVQ", @@ -667,7 +676,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIOD= evice *vdev, void vhost_svq_stop(VhostShadowVirtqueue *svq) { event_notifier_set_handler(&svq->svq_kick, NULL); - g_autofree VirtQueueElement *next_avail_elem =3D NULL; + g_autofree SVQElement *next_avail_elem =3D NULL; =20 if (!svq->vq) { return; @@ -677,17 +686,18 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) vhost_svq_flush(svq, false); =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]); - if (elem) { - virtqueue_detach_element(svq->vq, elem, elem->len); + g_autofree SVQElement *svq_elem =3D NULL; + svq_elem =3D g_steal_pointer(&svq->ring_id_maps[i]); + if (svq_elem) { + virtqueue_detach_element(svq->vq, &svq_elem->elem, + svq_elem->elem.len); } } =20 next_avail_elem =3D g_steal_pointer(&svq->next_guest_avail_elem); if (next_avail_elem) { - virtqueue_detach_element(svq->vq, next_avail_elem, - next_avail_elem->len); + virtqueue_detach_element(svq->vq, &next_avail_elem->elem, + next_avail_elem->elem.len); } } =20 @@ -735,7 +745,7 @@ VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize, Vho= stIOVATree *iova_tree) svq->vring.used =3D qemu_memalign(qemu_real_host_page_size, device_siz= e); memset(svq->vring.used, 0, device_size); svq->iova_tree =3D iova_tree; - svq->ring_id_maps =3D g_new0(VirtQueueElement *, qsize); + svq->ring_id_maps =3D g_new0(SVQElement *, qsize); event_notifier_set_handler(&svq->hdev_call, vhost_svq_handle_call); return g_steal_pointer(&svq); =20 --=20 2.27.0 From nobody Sun Feb 8 17:42:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644867643625146.48872923055706; Mon, 14 Feb 2022 11:40:43 -0800 (PST) Received: from localhost ([::1]:33252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nJhDG-00006L-0J for importer@patchew.org; Mon, 14 Feb 2022 14:40:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50140) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJgqa-00030D-6R for qemu-devel@nongnu.org; Mon, 14 Feb 2022 14:17:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32030) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJgqX-0001Fp-Gh for qemu-devel@nongnu.org; Mon, 14 Feb 2022 14:17:15 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-386-0_tYXlXHPPSU2bTZM3p-Xw-1; Mon, 14 Feb 2022 14:17:08 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4B06F1091DA1; Mon, 14 Feb 2022 19:17:07 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0F114BC45; Mon, 14 Feb 2022 19:17:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644866231; 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=tjxJgOxnjRa+v8NoOmbIpBO0uh0wXGghit6m6dUS0Po=; b=TTBqhWd1YVfWzn2anlMqIS9nco2ernFxoiZA3JXmGmlS/NmbN44auuUVKz9xV1/qjPCHs3 PzWbFdZCi5LxLQrFnjmcq2JXEY5imBqvmK9JxZQD47hE4NeUWhBmLlNaaLE1k0vmoPNYth HSi3NfYQELkr55v9jTETAVUyjGwWdK4= X-MC-Unique: 0_tYXlXHPPSU2bTZM3p-Xw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 5/9] vhost: Add custom used buffer callback Date: Mon, 14 Feb 2022 20:16:31 +0100 Message-Id: <20220214191635.1604932-6-eperezma@redhat.com> In-Reply-To: <20220214191635.1604932-1-eperezma@redhat.com> References: <20220214191635.1604932-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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: -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.083, 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Harpreet Singh Anand , Eli Cohen , Zhu Lingshan Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644867645756100001 The callback allows SVQ users to know the VirtQueue requests and responses. QEMU can use this to synchronize virtio device model state, allowing to migrate it with minimum changes to the migration code. In the case of networking, this will be used to inspect control virtqueue messages. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 10 +++++++++- include/hw/virtio/vhost-vdpa.h | 2 ++ hw/virtio/vhost-shadow-virtqueue.c | 15 ++++++++++++++- hw/virtio/vhost-vdpa.c | 4 ++-- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index a2b0c6434d..f23fb93c20 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -16,6 +16,13 @@ =20 typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; =20 +typedef void (*VirtQueueElementCallback)(VirtIODevice *vdev, + const VirtQueueElement *elem); + +typedef struct VhostShadowVirtqueueOps { + VirtQueueElementCallback used_elem_handler; +} VhostShadowVirtqueueOps; + bool vhost_svq_valid_device_features(uint64_t *features); bool vhost_svq_valid_guest_features(uint64_t *features); bool vhost_svq_ack_guest_features(uint64_t dev_features, @@ -39,7 +46,8 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODev= ice *vdev, VirtQueue *vq); void vhost_svq_stop(VhostShadowVirtqueue *svq); =20 -VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize, VhostIOVATree *iova_ma= p); +VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize, VhostIOVATree *iova_ma= p, + const VhostShadowVirtqueueOps *ops); =20 void vhost_svq_free(VhostShadowVirtqueue *vq); =20 diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index cd2388b3be..a0271534e6 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -17,6 +17,7 @@ #include "hw/virtio/vhost-iova-tree.h" #include "hw/virtio/virtio.h" #include "standard-headers/linux/vhost_types.h" +#include "hw/virtio/vhost-shadow-virtqueue.h" =20 typedef struct VhostVDPAHostNotifier { MemoryRegion mr; @@ -34,6 +35,7 @@ typedef struct vhost_vdpa { /* IOVA mapping used by Shadow Virtqueue */ VhostIOVATree *iova_tree; GPtrArray *shadow_vqs; + const VhostShadowVirtqueueOps *shadow_vq_ops; struct vhost_dev *dev; VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; } VhostVDPA; diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index ea32b7ae7f..5665947d1a 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -59,6 +59,12 @@ struct VhostShadowVirtqueue { /* Next VirtQueue element that guest made available */ SVQElement *next_guest_avail_elem; =20 + /* Optional callbacks */ + const VhostShadowVirtqueueOps *ops; + + /* Optional custom used virtqueue element handler */ + VirtQueueElementCallback used_elem_cb; + /* Next head to expose to device */ uint16_t avail_idx_shadow; =20 @@ -509,6 +515,10 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq, i =3D 0; } virtqueue_fill(vq, elem, elem->len, i++); + + if (svq->ops && svq->ops->used_elem_handler) { + svq->ops->used_elem_handler(svq->vdev, elem); + } } =20 virtqueue_flush(vq, i); @@ -707,12 +717,14 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) * * @qsize Shadow VirtQueue size * @iova_tree Tree to perform descriptors translations + * @used_cb Optional callback for each device's used buffer * * Returns the new virtqueue or NULL. * * In case of error, reason is reported through error_report. */ -VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize, VhostIOVATree *iova_tr= ee) +VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize, VhostIOVATree *iova_tr= ee, + const VhostShadowVirtqueueOps *ops) { size_t desc_size =3D sizeof(vring_desc_t) * qsize; size_t device_size, driver_size; @@ -747,6 +759,7 @@ VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize, Vho= stIOVATree *iova_tree) svq->iova_tree =3D iova_tree; svq->ring_id_maps =3D g_new0(SVQElement *, qsize); event_notifier_set_handler(&svq->hdev_call, vhost_svq_handle_call); + svq->ops =3D ops; 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 c64a6802b7..5707b1952d 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -17,7 +17,6 @@ #include "hw/virtio/vhost.h" #include "hw/virtio/vhost-backend.h" #include "hw/virtio/virtio-net.h" -#include "hw/virtio/vhost-shadow-virtqueue.h" #include "hw/virtio/vhost-vdpa.h" #include "exec/address-spaces.h" #include "qemu/main-loop.h" @@ -1219,7 +1218,8 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev= , struct vhost_vdpa *v, for (unsigned n =3D 0; n < hdev->nvqs; ++n) { DMAMap device_region, driver_region; struct vhost_vring_addr addr; - VhostShadowVirtqueue *svq =3D vhost_svq_new(qsize, v->iova_tree); + VhostShadowVirtqueue *svq =3D vhost_svq_new(qsize, v->iova_tree, + v->shadow_vq_ops); if (unlikely(!svq)) { error_setg(errp, "Cannot create svq %u", n); return -1; --=20 2.27.0 From nobody Sun Feb 8 17:42:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644868131167853.8498402615418; Mon, 14 Feb 2022 11:48:51 -0800 (PST) Received: from localhost ([::1]:52348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nJhL7-0004o6-Ga for importer@patchew.org; Mon, 14 Feb 2022 14:48:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50146) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJgqb-00030F-6C for qemu-devel@nongnu.org; Mon, 14 Feb 2022 14:17:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:51517) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJgqZ-0001G1-8q for qemu-devel@nongnu.org; Mon, 14 Feb 2022 14:17:16 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-403-gBBsceClO3yvKNCqTEmlpQ-1; Mon, 14 Feb 2022 14:17:11 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3F808814243; Mon, 14 Feb 2022 19:17:10 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id A61545FC08; Mon, 14 Feb 2022 19:17:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644866234; 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=4nC/+Y70sZV5Uy/nObARUYpq/gu5ySxHHcr4Yrw/TaI=; b=fpT2302X5Kcd8uO4Zb26D5bFiXuEm40c0CQ0lLCJ1pVu4vMsewzp16bKovtX9zbQ2TS+QY nrI/RGAAa+teU9VaUel+BaJXhuIJCj0eQ8DqoKTPe8JFMx63jxBSlW9IMw3BTaKg6JzdoC OP9GcQGMPI01cegU/FfQetslidbhewg= X-MC-Unique: gBBsceClO3yvKNCqTEmlpQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 6/9] vdpa: Add map/unmap operation callback to SVQ Date: Mon, 14 Feb 2022 20:16:32 +0100 Message-Id: <20220214191635.1604932-7-eperezma@redhat.com> In-Reply-To: <20220214191635.1604932-1-eperezma@redhat.com> References: <20220214191635.1604932-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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.083, 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Harpreet Singh Anand , Eli Cohen , Zhu Lingshan Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644868131874100001 Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 13 ++++++++++++- hw/virtio/vhost-shadow-virtqueue.c | 12 +++++++++++- hw/virtio/vhost-vdpa.c | 20 +++++++++++++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index f23fb93c20..bf3b658889 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -23,6 +23,15 @@ typedef struct VhostShadowVirtqueueOps { VirtQueueElementCallback used_elem_handler; } VhostShadowVirtqueueOps; =20 +typedef int (*vhost_svq_map_op)(hwaddr iova, hwaddr size, void *vaddr, + bool readonly, void *opaque); +typedef int (*vhost_svq_unmap_op)(hwaddr iova, hwaddr size, void *opaque); + +typedef struct VhostShadowVirtqueueMapOps { + vhost_svq_map_op map; + vhost_svq_unmap_op unmap; +} VhostShadowVirtqueueMapOps; + bool vhost_svq_valid_device_features(uint64_t *features); bool vhost_svq_valid_guest_features(uint64_t *features); bool vhost_svq_ack_guest_features(uint64_t dev_features, @@ -47,7 +56,9 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODev= ice *vdev, void vhost_svq_stop(VhostShadowVirtqueue *svq); =20 VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize, VhostIOVATree *iova_ma= p, - const VhostShadowVirtqueueOps *ops); + const VhostShadowVirtqueueOps *ops, + const VhostShadowVirtqueueMapOps *map_= ops, + void *map_ops_opaque); =20 void vhost_svq_free(VhostShadowVirtqueue *vq); =20 diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 5665947d1a..2ba3c2966a 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -62,6 +62,12 @@ struct VhostShadowVirtqueue { /* Optional callbacks */ const VhostShadowVirtqueueOps *ops; =20 + /* Device memory mapping callbacks */ + const VhostShadowVirtqueueMapOps *map_ops; + + /* Device memory mapping callbacks opaque */ + void *map_ops_opaque; + /* Optional custom used virtqueue element handler */ VirtQueueElementCallback used_elem_cb; =20 @@ -724,7 +730,9 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) * In case of error, reason is reported through error_report. */ VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize, VhostIOVATree *iova_tr= ee, - const VhostShadowVirtqueueOps *ops) + const VhostShadowVirtqueueOps *ops, + const VhostShadowVirtqueueMapOps *map_= ops, + void *map_ops_opaque) { size_t desc_size =3D sizeof(vring_desc_t) * qsize; size_t device_size, driver_size; @@ -760,6 +768,8 @@ VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize, Vho= stIOVATree *iova_tree, svq->ring_id_maps =3D g_new0(SVQElement *, qsize); event_notifier_set_handler(&svq->hdev_call, vhost_svq_handle_call); svq->ops =3D ops; + svq->map_ops =3D map_ops; + svq->map_ops_opaque =3D map_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 5707b1952d..4142a1ce5d 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -1178,6 +1178,22 @@ static int vhost_vdpa_get_max_queue_size(struct vhos= t_dev *dev, return vhost_vdpa_call(dev, VHOST_VDPA_GET_VRING_NUM, qsize); } =20 +static int vhost_vdpa_svq_map(hwaddr iova, hwaddr size, void *vaddr, + bool readonly, void *opaque) +{ + return vhost_vdpa_dma_map(opaque, iova, size, vaddr, readonly); +} + +static int vhost_vdpa_svq_unmap(hwaddr iova, hwaddr size, void *opaque) +{ + return vhost_vdpa_dma_unmap(opaque, iova, size); +} + +static const VhostShadowVirtqueueMapOps vhost_vdpa_svq_map_ops =3D { + .map =3D vhost_vdpa_svq_map, + .unmap =3D vhost_vdpa_svq_unmap, +}; + static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *= v, Error **errp) { @@ -1219,7 +1235,9 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev= , struct vhost_vdpa *v, DMAMap device_region, driver_region; struct vhost_vring_addr addr; VhostShadowVirtqueue *svq =3D vhost_svq_new(qsize, v->iova_tree, - v->shadow_vq_ops); + v->shadow_vq_ops, + &vhost_vdpa_svq_map_ops, + v); if (unlikely(!svq)) { error_setg(errp, "Cannot create svq %u", n); return -1; --=20 2.27.0 From nobody Sun Feb 8 17:42:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644867226315884.2923138601012; Mon, 14 Feb 2022 11:33:46 -0800 (PST) Received: from localhost ([::1]:48980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nJh6V-00087u-Gy for importer@patchew.org; Mon, 14 Feb 2022 14:33:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50238) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJgqx-0003Qa-Vw for qemu-devel@nongnu.org; Mon, 14 Feb 2022 14:17:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:26635) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJgqw-0001He-3p for qemu-devel@nongnu.org; Mon, 14 Feb 2022 14:17:39 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-31-OtrFytqOOh69Xwmf6qpzbQ-1; Mon, 14 Feb 2022 14:17:33 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 46CA2801B0E; Mon, 14 Feb 2022 19:17:32 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id A22524BC45; Mon, 14 Feb 2022 19:17:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644866256; 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=tQ8hPeVchH2aT6nlPl35E32wEaoIsr8R6UjyIin+qrU=; b=KI3rowqmezbKPsL1hwgdbDq0DLYm2k+ptAREUPxddTx1PNAnB2DtbebbPIdqdhXLUJ2/Zt Rxmj97N+Q2cA3wu3TnaPZgXFS9AteAMDUzab8RCTdyIFrlxQexVhARbw//IWfNjiyex0OS siGkGLP66uYnlWamAK0YqX++8SOS8B8= X-MC-Unique: OtrFytqOOh69Xwmf6qpzbQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 7/9] vhost: Add vhost_svq_inject Date: Mon, 14 Feb 2022 20:16:33 +0100 Message-Id: <20220214191635.1604932-8-eperezma@redhat.com> In-Reply-To: <20220214191635.1604932-1-eperezma@redhat.com> References: <20220214191635.1604932-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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.083, 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Harpreet Singh Anand , Eli Cohen , Zhu Lingshan Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644867229192100001 This allows qemu to inject packets to the device without guest's notice. This will be use to inject net CVQ messages to restore status in the destin= ation Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 2 + hw/virtio/vhost-shadow-virtqueue.c | 142 ++++++++++++++++++++++++----- 2 files changed, 123 insertions(+), 21 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index bf3b658889..767b0a82ba 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -38,6 +38,8 @@ bool vhost_svq_ack_guest_features(uint64_t dev_features, uint64_t guest_features, uint64_t *acked_features); =20 +bool vhost_svq_inject(VhostShadowVirtqueue *svq, const struct iovec *iov, + size_t out_num, size_t in_num); void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); void vhost_svq_set_guest_call_notifier(VhostShadowVirtqueue *svq, int call= _fd); const EventNotifier *vhost_svq_get_dev_kick_notifier( diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 2ba3c2966a..26938b059c 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -16,9 +16,11 @@ =20 #include "qemu/error-report.h" #include "qemu/main-loop.h" +#include "qemu/iov.h" =20 typedef struct SVQElement { VirtQueueElement elem; + bool not_from_guest; } SVQElement; =20 /* Shadow virtqueue to relay notifications */ @@ -311,19 +313,53 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue = *svq, /* We need some descriptors here */ assert(elem->out_num || elem->in_num); =20 - ok =3D vhost_svq_translate_addr(svq, sgs, elem->out_sg, elem->out_num); - if (unlikely(!ok)) { - return false; + if (elem->out_sg && svq_elem->not_from_guest) { + DMAMap map =3D { + .translated_addr =3D (hwaddr)svq_elem->elem.out_sg->iov_base, + .size =3D ROUND_UP(elem->out_sg->iov_len, 4096) - 1, + .perm =3D IOMMU_RO, + }; + int r =3D vhost_iova_tree_map_alloc(svq->iova_tree, &map); + + elem->out_addr[0] =3D map.iova; + assert(elem->out_num =3D=3D 1); + assert(r =3D=3D IOVA_OK); + + r =3D svq->map_ops->map(map.iova, map.size, (void *)map.translated= _addr, + true, svq->map_ops_opaque); + assert(r =3D=3D 0); + sgs[0] =3D (void *)map.iova; + } else { + ok =3D vhost_svq_translate_addr(svq, sgs, elem->out_sg, elem->out_= num); + if (unlikely(!ok)) { + return false; + } } vhost_vring_write_descs(svq, sgs, elem->out_sg, elem->out_num, elem->in_num > 0, false); =20 + if (elem->in_sg && svq_elem->not_from_guest) { + DMAMap map =3D { + .translated_addr =3D (hwaddr)svq_elem->elem.in_sg->iov_base, + .size =3D ROUND_UP(elem->in_sg->iov_len, 4096) - 1, + .perm =3D IOMMU_RW, + }; + int r =3D vhost_iova_tree_map_alloc(svq->iova_tree, &map); =20 - ok =3D vhost_svq_translate_addr(svq, sgs, elem->in_sg, elem->in_num); - if (unlikely(!ok)) { - return false; - } + elem->in_addr[0] =3D map.iova; + assert(elem->out_num =3D=3D 1); + assert(r =3D=3D IOVA_OK); =20 + r =3D svq->map_ops->map(map.iova, map.size, (void *)map.translated= _addr, + false, svq->map_ops_opaque); + assert(r =3D=3D 0); + sgs[0] =3D (void *)map.iova; + } else { + ok =3D vhost_svq_translate_addr(svq, sgs, elem->in_sg, elem->in_nu= m); + if (unlikely(!ok)) { + return false; + } + } vhost_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num, false, tr= ue); =20 /* @@ -364,6 +400,43 @@ static void vhost_svq_kick(VhostShadowVirtqueue *svq) event_notifier_set(&svq->hdev_kick); } =20 +bool vhost_svq_inject(VhostShadowVirtqueue *svq, const struct iovec *iov, + size_t out_num, size_t in_num) +{ + size_t out_size =3D iov_size(iov, out_num); + size_t out_buf_size =3D ROUND_UP(out_size, 4096); + size_t in_size =3D iov_size(iov + out_num, in_num); + size_t in_buf_size =3D ROUND_UP(in_size, 4096); + SVQElement *svq_elem; + uint16_t num_slots =3D (in_num ? 1 : 0) + (out_num ? 1 : 0); + + if (unlikely(num_slots =3D=3D 0 || svq->next_guest_avail_elem || + vhost_svq_available_slots(svq) < num_slots)) { + return false; + } + + svq_elem =3D virtqueue_alloc_element(sizeof(SVQElement), 1, 1); + if (out_num) { + void *out =3D qemu_memalign(4096, out_buf_size); + svq_elem->elem.out_sg[0].iov_base =3D out; + svq_elem->elem.out_sg[0].iov_len =3D out_size; + iov_to_buf(iov, out_num, 0, out, out_size); + memset(out + out_size, 0, out_buf_size - out_size); + } + if (in_num) { + void *in =3D qemu_memalign(4096, in_buf_size); + svq_elem->elem.in_sg[0].iov_base =3D in; + svq_elem->elem.in_sg[0].iov_len =3D in_size; + memset(in, 0, in_buf_size); + } + + svq_elem->not_from_guest =3D true; + vhost_svq_add(svq, svq_elem); + vhost_svq_kick(svq); + + return true; +} + /** * Forward available buffers. * @@ -512,23 +585,50 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq, } =20 elem =3D &svq_elem->elem; - if (unlikely(i >=3D svq->vring.num)) { - virtio_error(svq->vdev, - "More than %u used buffers obtained in a %u size = SVQ", - i, svq->vring.num); - virtqueue_fill(vq, elem, elem->len, i); - virtqueue_flush(vq, i); - i =3D 0; - } - virtqueue_fill(vq, elem, elem->len, i++); - if (svq->ops && svq->ops->used_elem_handler) { svq->ops->used_elem_handler(svq->vdev, elem); } + + if (svq_elem->not_from_guest) { + const DMAMap out_map =3D { + .iova =3D elem->out_addr[0], + .translated_addr =3D (hwaddr)elem->out_sg[0].iov_base, + .size =3D elem->out_sg[0].iov_len, + }; + const DMAMap in_map =3D { + .iova =3D elem->in_addr[0], + .translated_addr =3D (hwaddr)elem->in_sg[0].iov_base, + .size =3D elem->in_sg[0].iov_len, + }; + vhost_iova_tree_remove(svq->iova_tree, &out_map); + if (svq->map_ops->unmap) { + svq->map_ops->unmap(out_map.iova, in_map.size, + svq->map_ops_opaque); + } + qemu_vfree(elem->out_sg[0].iov_base); + vhost_iova_tree_remove(svq->iova_tree, &in_map); + if (svq->map_ops->unmap) { + svq->map_ops->unmap(out_map.iova, out_map.size, + svq->map_ops_opaque); + } + qemu_vfree(elem->in_sg[0].iov_base); + } else { + if (unlikely(i >=3D svq->vring.num)) { + virtio_error(svq->vdev, + "More than %u used buffers obtained in a %u size S= VQ", + i, svq->vring.num); + virtqueue_fill(vq, elem, elem->len, i); + virtqueue_flush(vq, i); + i =3D 0; + } + virtqueue_fill(vq, elem, elem->len, i++); + } } =20 - virtqueue_flush(vq, i); - event_notifier_set(&svq->svq_call); + if (i > 0) { + virtqueue_flush(vq, i); + event_notifier_set(&svq->svq_call); + } =20 if (check_for_avail_queue && svq->next_guest_avail_elem) { /* @@ -704,14 +804,14 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) for (unsigned i =3D 0; i < svq->vring.num; ++i) { g_autofree SVQElement *svq_elem =3D NULL; svq_elem =3D g_steal_pointer(&svq->ring_id_maps[i]); - if (svq_elem) { + if (svq_elem && !svq_elem->not_from_guest) { virtqueue_detach_element(svq->vq, &svq_elem->elem, svq_elem->elem.len); } } =20 next_avail_elem =3D g_steal_pointer(&svq->next_guest_avail_elem); - if (next_avail_elem) { + if (next_avail_elem && !next_avail_elem->not_from_guest) { virtqueue_detach_element(svq->vq, &next_avail_elem->elem, next_avail_elem->elem.len); } --=20 2.27.0 From nobody Sun Feb 8 17:42:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644868488298192.15876371122408; Mon, 14 Feb 2022 11:54:48 -0800 (PST) Received: from localhost ([::1]:33772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nJhQs-00031V-O6 for importer@patchew.org; Mon, 14 Feb 2022 14:54:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJgr6-0003Xa-2n for qemu-devel@nongnu.org; Mon, 14 Feb 2022 14:17:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:57893) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJgr3-0001IH-O0 for qemu-devel@nongnu.org; Mon, 14 Feb 2022 14:17:46 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-600-wmcmhC3uNQGIvCn9SfpCXA-1; Mon, 14 Feb 2022 14:17:42 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8FC96100C661; Mon, 14 Feb 2022 19:17:40 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id A26725FC08; Mon, 14 Feb 2022 19:17:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644866264; 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=ttVEo/+ZROmIGEL207zZe/LUPDUmfNooymurI+X1u9g=; b=YChrs8csW9kCxw6Lm4C37V3mu4XdSWTNYyPssRzwO1VOWQLg29uMZwl5psoEtmbTHALgPY ArdoM7rSimYdZ+obMYgJEQS8o/4LXWh3sn52v26QMiuFfp1TPiOnPUCy+mUtpfV3yTBpxX exV0bagAHlHEj0KaIPZgHV7lcMHRcn8= X-MC-Unique: wmcmhC3uNQGIvCn9SfpCXA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 8/9] vhost: Add vhost_svq_start_op Date: Mon, 14 Feb 2022 20:16:34 +0100 Message-Id: <20220214191635.1604932-9-eperezma@redhat.com> In-Reply-To: <20220214191635.1604932-1-eperezma@redhat.com> References: <20220214191635.1604932-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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: -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.083, 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Harpreet Singh Anand , Eli Cohen , Zhu Lingshan Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644868489291100001 Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 4 +++- hw/virtio/vhost-shadow-virtqueue.c | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 767b0a82ba..8f2377bbc4 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -15,11 +15,13 @@ #include "hw/virtio/vhost-iova-tree.h" =20 typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; - +typedef bool (*vhost_svq_start_op)(VhostShadowVirtqueue *svq, + VirtIODevice *vdev); typedef void (*VirtQueueElementCallback)(VirtIODevice *vdev, const VirtQueueElement *elem); =20 typedef struct VhostShadowVirtqueueOps { + vhost_svq_start_op start; VirtQueueElementCallback used_elem_handler; } VhostShadowVirtqueueOps; =20 diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 26938b059c..18cdb35ea3 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -783,6 +783,10 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIO= Device *vdev, for (unsigned i =3D 0; i < svq->vring.num - 1; i++) { svq->vring.desc[i].next =3D cpu_to_le16(i + 1); } + + if (svq->ops && svq->ops->start) { + svq->ops->start(svq, vdev); + } } =20 /** --=20 2.27.0 From nobody Sun Feb 8 17:42:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 164486864083738.52195218015254; Mon, 14 Feb 2022 11:57:20 -0800 (PST) Received: from localhost ([::1]:41294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nJhTL-0007Ye-RA for importer@patchew.org; Mon, 14 Feb 2022 14:57:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50360) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJgrP-0003wj-W8 for qemu-devel@nongnu.org; Mon, 14 Feb 2022 14:18:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:49579) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJgrB-0001JM-3g for qemu-devel@nongnu.org; Mon, 14 Feb 2022 14:17:54 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-85-VQVpq5XoMtK4ZLKzoouOrg-1; Mon, 14 Feb 2022 14:17:48 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3431018397BE; Mon, 14 Feb 2022 19:17:47 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id EDCA15F9B0; Mon, 14 Feb 2022 19:17:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644866272; 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=qxt4bKH70M6S4V71+R1R40IcKs14iIETamtfBhNL80o=; b=TASYMbucq5GrpQ2zZFxUBs14tg7Tw8JMM2rA3gZjtpVLZFSzcBbk/k0Umnzh4SZFpZtwdW rH1LnmK+hrn7HKrzsgJbfLTAIomvw1kowOgMan68dEWJmwhrhiUeIeDjtT5MN4zd/EqF0a ymakEQbF2fGCZlP4uhqHiYFtlibAF4I= X-MC-Unique: VQVpq5XoMtK4ZLKzoouOrg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 9/9] vdpa: control virtqueue support on shadow virtqueue Date: Mon, 14 Feb 2022 20:16:35 +0100 Message-Id: <20220214191635.1604932-10-eperezma@redhat.com> In-Reply-To: <20220214191635.1604932-1-eperezma@redhat.com> References: <20220214191635.1604932-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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.083, 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Gautam Dawar , Harpreet Singh Anand , Eli Cohen , Zhu Lingshan Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644868641503100001 Introduce the control virtqueue support for vDPA shadow virtqueue. This is needed for advanced networking features like multiqueue. To demonstrate command handling, VIRTIO_NET_F_CTROL_MACADDR is implemented. If vDPA device is started with SVQ support, and MAC changes in the source VM, it will be transfered with the rest of properties in the emulated virtio-net device model. A new CVQ command will be reproduced at destination so that NIC is aware of the changed MAC. Signed-off-by: Eugenio P=C3=A9rez --- net/vhost-vdpa.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 2 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index fc844a7ce6..ea4e489070 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -11,6 +11,7 @@ =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" @@ -70,6 +71,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_CTRL_GUEST_OFFLOADS) | + 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_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); @@ -203,6 +226,79 @@ static void vhost_vdpa_get_iova_range(int fd, } } =20 +static bool vhost_vdpa_start_control_svq(VhostShadowVirtqueue *svq, + VirtIODevice *vdev) +{ + VirtIONet *n =3D VIRTIO_NET(vdev); + NetClientState *nc =3D qemu_get_subqueue(n->nic, n->max_queue_pairs); + VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc->peer); + uint64_t features =3D vdev->host_features; + assert(s->nc.info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); + + if (features & BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR)) { + const struct virtio_net_ctrl_hdr ctrl =3D { + .class =3D VIRTIO_NET_CTRL_MAC, + .cmd =3D VIRTIO_NET_CTRL_MAC_ADDR_SET, + }; + uint8_t mac[6]; + const struct iovec data[] =3D { + { + .iov_base =3D (void *)&ctrl, + .iov_len =3D sizeof(ctrl), + },{ + .iov_base =3D mac, + .iov_len =3D sizeof(mac), + },{ + .iov_base =3D NULL, + .iov_len =3D sizeof(virtio_net_ctrl_ack), + } + }; + bool ret; + + /* TODO: Only best effort? */ + memcpy(mac, n->mac, sizeof(mac)); + ret =3D vhost_svq_inject(svq, data, 2, 1); + if (!ret) { + return false; + } + } + + return true; +} + +static void vhost_vdpa_net_handle_ctrl(VirtIODevice *vdev, + const VirtQueueElement *elem) +{ + struct virtio_net_ctrl_hdr ctrl; + virtio_net_ctrl_ack status =3D VIRTIO_NET_ERR; + size_t s; + struct iovec in =3D { + .iov_base =3D &status, + .iov_len =3D sizeof(status), + }; + + s =3D iov_to_buf(elem->out_sg, elem->out_num, 0, &ctrl, sizeof(ctrl.cl= ass)); + if (s !=3D sizeof(ctrl.class) || + ctrl.class !=3D VIRTIO_NET_CTRL_MAC_ADDR_SET) { + return; + } + s =3D iov_to_buf(elem->in_sg, elem->in_num, 0, &status, sizeof(status)= ); + if (s !=3D sizeof(status) || status !=3D VIRTIO_NET_OK) { + return; + } + + status =3D VIRTIO_NET_ERR; + virtio_net_handle_ctrl_iov(vdev, &in, 1, elem->out_sg, elem->out_num); + if (status !=3D VIRTIO_NET_OK) { + error_report("Bad CVQ processing in model"); + } +} + +static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops =3D { + .start =3D vhost_vdpa_start_control_svq, + .used_elem_handler =3D vhost_vdpa_net_handle_ctrl, +}; + static NetClientState *net_vhost_vdpa_init(NetClientState *peer, const char *device, const char *name, @@ -232,6 +328,9 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, s->vhost_vdpa.index =3D queue_pair_index; s->vhost_vdpa.iova_range =3D iova_range; s->vhost_vdpa.shadow_vqs_enabled =3D svq; + if (!is_datapath) { + s->vhost_vdpa.shadow_vq_ops =3D &vhost_vdpa_net_svq_ops; + } s->vhost_vdpa.iova_tree =3D iova_tree; ret =3D vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, queue_pair_index, n= vqs); if (ret) { @@ -322,8 +421,15 @@ int net_init_vhost_vdpa(const Netdev *netdev, const ch= ar *name, } vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range); if (opts->x_svq) { - if (has_cvq) { - error_setg(errp, "vdpa svq does not work with cvq"); + 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_ST= ART); + + if (invalid_dev_features) { + error_setg(errp, "vdpa svq does not work with features 0x%" PR= Ix64, + invalid_dev_features); goto err_svq; } iova_tree =3D vhost_iova_tree_new(iova_range.first, iova_range.las= t); --=20 2.27.0