From nobody Thu May 16 12:58:34 2024 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 1633926663117409.6058386411546; Sun, 10 Oct 2021 21:31:03 -0700 (PDT) Received: from localhost ([::1]:58668 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZmxp-0002T3-Tu for importer@patchew.org; Mon, 11 Oct 2021 00:31:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44508) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZmvg-0000Q2-2B for qemu-devel@nongnu.org; Mon, 11 Oct 2021 00:28:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56100) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZmve-0001o4-Ks for qemu-devel@nongnu.org; Mon, 11 Oct 2021 00:28:47 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-32-MrT4LIDlMRqPq8rZaU-q1w-1; Mon, 11 Oct 2021 00:28:42 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C4BD9824FA6; Mon, 11 Oct 2021 04:28:41 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-160.pek2.redhat.com [10.72.13.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B76E19D9B; Mon, 11 Oct 2021 04:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633926526; 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=70WfaKju9jNai6qF1W4Wb5kstCqy2O7y+tIYdKX7bRs=; b=H9p0POMTQraU3NBwn7Bf4wTKopQO4JqL+7/f5fTEJYTKWSOVjb+Y39/D9ZyrECyl4creyC oWxRJjzziajNEwcJ7V0rzOGKBKuRoF1vsq2yDl0bBjvXIjUnm0NRktF8YdnQy8avQwjEuD 6cSEJFFG4hqgImMi210lX/wV853LZHw= X-MC-Unique: MrT4LIDlMRqPq8rZaU-q1w-1 From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH V4 01/10] vhost-vdpa: open device fd in net_init_vhost_vdpa() Date: Mon, 11 Oct 2021 12:28:20 +0800 Message-Id: <20211011042829.4159-2-jasowang@redhat.com> In-Reply-To: <20211011042829.4159-1-jasowang@redhat.com> References: <20211011042829.4159-1-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=jasowang@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.049, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lulu@redhat.com, gdawar@xilinx.com, eperezma@redhat.com, elic@nvidia.com, lingshan.zhu@intel.com, Stefano Garzarella 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: 1633926663733100003 Content-Type: text/plain; charset="utf-8" This patch switches to open device fd in net_init_vhost_vpda(). This is used to prepare for the multiqueue support. Reviewed-by: Stefano Garzarella Signed-off-by: Jason Wang Message-Id: <20210907090322.1756-2-jasowang@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- net/vhost-vdpa.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 912686457c..73d29a74ef 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -156,24 +156,19 @@ static NetClientInfo net_vhost_vdpa_info =3D { }; =20 static int net_vhost_vdpa_init(NetClientState *peer, const char *device, - const char *name, const char *vhostdev) + const char *name, int vdpa_device_fd) { NetClientState *nc =3D NULL; VhostVDPAState *s; - int vdpa_device_fd =3D -1; int ret =3D 0; assert(name); nc =3D qemu_new_net_client(&net_vhost_vdpa_info, peer, device, name); snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA); s =3D DO_UPCAST(VhostVDPAState, nc, nc); - vdpa_device_fd =3D qemu_open_old(vhostdev, O_RDWR); - if (vdpa_device_fd =3D=3D -1) { - return -errno; - } + s->vhost_vdpa.device_fd =3D vdpa_device_fd; ret =3D vhost_vdpa_add(nc, (void *)&s->vhost_vdpa); if (ret) { - qemu_close(vdpa_device_fd); qemu_del_net_client(nc); } return ret; @@ -201,6 +196,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const cha= r *name, NetClientState *peer, Error **errp) { const NetdevVhostVDPAOptions *opts; + int vdpa_device_fd, ret; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); opts =3D &netdev->u.vhost_vdpa; @@ -209,5 +205,16 @@ int net_init_vhost_vdpa(const Netdev *netdev, const ch= ar *name, (char *)name, errp)) { return -1; } - return net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, opts->vhostdev= ); + + vdpa_device_fd =3D qemu_open_old(opts->vhostdev, O_RDWR); + if (vdpa_device_fd =3D=3D -1) { + return -errno; + } + + ret =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, vdpa_device_f= d); + if (ret) { + qemu_close(vdpa_device_fd); + } + + return ret; } --=20 2.25.1 From nobody Thu May 16 12:58:34 2024 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 1633926816728275.86823991290635; Sun, 10 Oct 2021 21:33:36 -0700 (PDT) Received: from localhost ([::1]:38938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZn0J-0008Ct-Nb for importer@patchew.org; Mon, 11 Oct 2021 00:33:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZmvw-000114-Id for qemu-devel@nongnu.org; Mon, 11 Oct 2021 00:29:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:44104) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZmvi-0001pV-Jp for qemu-devel@nongnu.org; Mon, 11 Oct 2021 00:29:04 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-288-fGBEIjFRP8Gla_6h5aALvw-1; Mon, 11 Oct 2021 00:28:46 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 18DB8824FA6; Mon, 11 Oct 2021 04:28:45 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-160.pek2.redhat.com [10.72.13.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5207D1F6; Mon, 11 Oct 2021 04:28:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633926529; 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=lk9CvHGhGgW8L3wyMh+YlRL3s1tSy1NA4jrtTGgQx4I=; b=LbtsNLz4K4Ulspb3AEoqdWsCGTA5IDDlv+l26iHVG8LwzG3nfF/YUPfl4aYC4Wj49pPWui zNTHIc8O+GfihMEAGw+CSJE68AGxB9/0/V3KkCW4J6dPqLWN8wNQFgEjvIVB07mUqH7ZeN vaADXoby64o7HFxEOETK1uDxnAlNMPk= X-MC-Unique: fGBEIjFRP8Gla_6h5aALvw-1 From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH V4 02/10] vhost-vdpa: classify one time request Date: Mon, 11 Oct 2021 12:28:21 +0800 Message-Id: <20211011042829.4159-3-jasowang@redhat.com> In-Reply-To: <20211011042829.4159-1-jasowang@redhat.com> References: <20211011042829.4159-1-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.049, 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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eperezma@redhat.com, elic@nvidia.com, gdawar@xilinx.com, lingshan.zhu@intel.com, lulu@redhat.com 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: 1633926818479100001 Content-Type: text/plain; charset="utf-8" Vhost-vdpa uses one device multiqueue queue (pairs) model. So we need to classify the one time request (e.g SET_OWNER) and make sure those request were only called once per device. This is used for multiqueue support. Signed-off-by: Jason Wang Message-Id: <20210907090322.1756-3-jasowang@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-vdpa.c | 52 ++++++++++++++++++++++++++++++---- include/hw/virtio/vhost-vdpa.h | 1 + 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 47d7a5a23d..edac4017da 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -279,6 +279,13 @@ static void vhost_vdpa_add_status(struct vhost_dev *de= v, uint8_t status) vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &s); } =20 +static bool vhost_vdpa_one_time_request(struct vhost_dev *dev) +{ + struct vhost_vdpa *v =3D dev->opaque; + + return v->index !=3D 0; +} + static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **er= rp) { struct vhost_vdpa *v; @@ -291,6 +298,10 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void= *opaque, Error **errp) v->listener =3D vhost_vdpa_memory_listener; v->msg_type =3D VHOST_IOTLB_MSG_V2; =20 + if (vhost_vdpa_one_time_request(dev)) { + return 0; + } + vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER); =20 @@ -401,6 +412,10 @@ static int vhost_vdpa_memslots_limit(struct vhost_dev = *dev) static int vhost_vdpa_set_mem_table(struct vhost_dev *dev, struct vhost_memory *mem) { + if (vhost_vdpa_one_time_request(dev)) { + return 0; + } + trace_vhost_vdpa_set_mem_table(dev, mem->nregions, mem->padding); if (trace_event_get_state_backends(TRACE_VHOST_VDPA_SET_MEM_TABLE) && trace_event_get_state_backends(TRACE_VHOST_VDPA_DUMP_REGIONS)) { @@ -424,6 +439,11 @@ static int vhost_vdpa_set_features(struct vhost_dev *d= ev, uint64_t features) { int ret; + + if (vhost_vdpa_one_time_request(dev)) { + return 0; + } + trace_vhost_vdpa_set_features(dev, features); ret =3D vhost_vdpa_call(dev, VHOST_SET_FEATURES, &features); uint8_t status =3D 0; @@ -448,9 +468,12 @@ static int vhost_vdpa_set_backend_cap(struct vhost_dev= *dev) } =20 features &=3D f; - r =3D vhost_vdpa_call(dev, VHOST_SET_BACKEND_FEATURES, &features); - if (r) { - return -EFAULT; + + if (vhost_vdpa_one_time_request(dev)) { + r =3D vhost_vdpa_call(dev, VHOST_SET_BACKEND_FEATURES, &features); + if (r) { + return -EFAULT; + } } =20 dev->backend_cap =3D features; @@ -559,11 +582,21 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev= , bool started) { struct vhost_vdpa *v =3D dev->opaque; trace_vhost_vdpa_dev_start(dev, started); + if (started) { - uint8_t status =3D 0; - memory_listener_register(&v->listener, &address_space_memory); vhost_vdpa_host_notifiers_init(dev); vhost_vdpa_set_vring_ready(dev); + } else { + vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); + } + + if (vhost_vdpa_one_time_request(dev)) { + return 0; + } + + if (started) { + uint8_t status =3D 0; + memory_listener_register(&v->listener, &address_space_memory); vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK); vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status); =20 @@ -572,7 +605,6 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, = bool started) vhost_vdpa_reset_device(dev); vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER); - vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); memory_listener_unregister(&v->listener); =20 return 0; @@ -582,6 +614,10 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev,= bool started) static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base, struct vhost_log *log) { + if (vhost_vdpa_one_time_request(dev)) { + return 0; + } + trace_vhost_vdpa_set_log_base(dev, base, log->size, log->refcnt, log->= fd, log->log); return vhost_vdpa_call(dev, VHOST_SET_LOG_BASE, &base); @@ -647,6 +683,10 @@ static int vhost_vdpa_get_features(struct vhost_dev *d= ev, =20 static int vhost_vdpa_set_owner(struct vhost_dev *dev) { + if (vhost_vdpa_one_time_request(dev)) { + return 0; + } + trace_vhost_vdpa_set_owner(dev); return vhost_vdpa_call(dev, VHOST_SET_OWNER, NULL); } diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index a8963da2d9..6b9288fef8 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -21,6 +21,7 @@ typedef struct VhostVDPAHostNotifier { =20 typedef struct vhost_vdpa { int device_fd; + int index; uint32_t msg_type; bool iotlb_batch_begin_sent; MemoryListener listener; --=20 2.25.1 From nobody Thu May 16 12:58:34 2024 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 1633927030664859.3394896784624; Sun, 10 Oct 2021 21:37:10 -0700 (PDT) Received: from localhost ([::1]:47738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZn3l-0005jT-IE for importer@patchew.org; Mon, 11 Oct 2021 00:37:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZmw9-0001D4-PV for qemu-devel@nongnu.org; Mon, 11 Oct 2021 00:29:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57091) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZmw7-0002oh-VP for qemu-devel@nongnu.org; Mon, 11 Oct 2021 00:29:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-341-IrR2URv9Ox6NE8kfy2HCnA-1; Mon, 11 Oct 2021 00:28:49 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 79178362F8; Mon, 11 Oct 2021 04:28:48 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-160.pek2.redhat.com [10.72.13.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C3C61F6; Mon, 11 Oct 2021 04:28:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633926554; 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=77CyXPkRGpdqgUGnEPJUyHbcB1TOIDhyKh8jTVp9vnI=; b=YMGaQSJP5QXR/rlNyI6DzwEORIJ5QA4ARMtDLEBDjjXwfywZyvbNhmpvE8ib7B1M3WboVD 0T6P1X6/qn9L97naXeXp0ECctihQmQLE/DS6WyJjQAavnFymtYE7ga6ZALtzphz4Dl2OjD O6UiripwXn9VmhMnKiuNmfuONeWyZrg= X-MC-Unique: IrR2URv9Ox6NE8kfy2HCnA-1 From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH V4 03/10] vhost-vdpa: prepare for the multiqueue support Date: Mon, 11 Oct 2021 12:28:22 +0800 Message-Id: <20211011042829.4159-4-jasowang@redhat.com> In-Reply-To: <20211011042829.4159-1-jasowang@redhat.com> References: <20211011042829.4159-1-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=jasowang@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.049, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eperezma@redhat.com, elic@nvidia.com, gdawar@xilinx.com, lingshan.zhu@intel.com, lulu@redhat.com 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: 1633927031044100001 Content-Type: text/plain; charset="utf-8" Unlike vhost-kernel, vhost-vdpa adapts a single device multiqueue model. So we need to simply use virtqueue index as the vhost virtqueue index. This is a must for multiqueue to work for vhost-vdpa. Signed-off-by: Jason Wang Message-Id: <20210907090322.1756-4-jasowang@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-vdpa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index edac4017da..8587d30918 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -504,8 +504,8 @@ static int vhost_vdpa_get_vq_index(struct vhost_dev *de= v, int idx) { assert(idx >=3D dev->vq_index && idx < dev->vq_index + dev->nvqs); =20 - trace_vhost_vdpa_get_vq_index(dev, idx, idx - dev->vq_index); - return idx - dev->vq_index; + trace_vhost_vdpa_get_vq_index(dev, idx, idx); + return idx; } =20 static int vhost_vdpa_set_vring_ready(struct vhost_dev *dev) --=20 2.25.1 From nobody Thu May 16 12:58:34 2024 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 163392668439999.59134623625096; Sun, 10 Oct 2021 21:31:24 -0700 (PDT) Received: from localhost ([::1]:60482 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZmyB-0003hN-8V for importer@patchew.org; Mon, 11 Oct 2021 00:31:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44570) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZmvw-000103-4V for qemu-devel@nongnu.org; Mon, 11 Oct 2021 00:29:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24162) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZmvu-0001wD-Ki for qemu-devel@nongnu.org; Mon, 11 Oct 2021 00:29:03 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-98-2770FSUjMNCTM-Ei8dMoRw-1; Mon, 11 Oct 2021 00:28:58 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 80EEF1006AA2; Mon, 11 Oct 2021 04:28:57 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-160.pek2.redhat.com [10.72.13.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id ABACA19D9B; Mon, 11 Oct 2021 04:28:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633926542; 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=kH1UTptXVdaLI2EPFK8X4tEZ6jfUajhr7TEx+5kSbhM=; b=QTfR82bvfMBrMd42Np9LYPEvnqFfTyjsk8LGJA6e/joO98fTOkevmITekM+oZdhdOT0w0q xtbJoG/uHaNIRNscGqBEIQJobHrHAIGl6SKkeOghyaM+V+nEQuc5idFtPa/1fpJUJO+y4A SYAaVqpkdaMECI4Ds2bvI7ugN70+4zU= X-MC-Unique: 2770FSUjMNCTM-Ei8dMoRw-1 From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH V4 04/10] vhost-vdpa: let net_vhost_vdpa_init() returns NetClientState * Date: Mon, 11 Oct 2021 12:28:23 +0800 Message-Id: <20211011042829.4159-5-jasowang@redhat.com> In-Reply-To: <20211011042829.4159-1-jasowang@redhat.com> References: <20211011042829.4159-1-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=jasowang@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.049, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eperezma@redhat.com, elic@nvidia.com, gdawar@xilinx.com, lingshan.zhu@intel.com, lulu@redhat.com 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: 1633926685288100001 Content-Type: text/plain; charset="utf-8" This patch switches to let net_vhost_vdpa_init() to return NetClientState *. This is used for the callers to allocate multiqueue NetClientState for multiqueue support. Signed-off-by: Jason Wang Message-Id: <20210907090322.1756-5-jasowang@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- net/vhost-vdpa.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 73d29a74ef..834dab28dd 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -155,8 +155,10 @@ static NetClientInfo net_vhost_vdpa_info =3D { .has_ufo =3D vhost_vdpa_has_ufo, }; =20 -static int net_vhost_vdpa_init(NetClientState *peer, const char *device, - const char *name, int vdpa_device_fd) +static NetClientState *net_vhost_vdpa_init(NetClientState *peer, + const char *device, + const char *name, + int vdpa_device_fd) { NetClientState *nc =3D NULL; VhostVDPAState *s; @@ -170,8 +172,9 @@ static int net_vhost_vdpa_init(NetClientState *peer, co= nst char *device, ret =3D vhost_vdpa_add(nc, (void *)&s->vhost_vdpa); if (ret) { qemu_del_net_client(nc); + return NULL; } - return ret; + return nc; } =20 static int net_vhost_check_net(void *opaque, QemuOpts *opts, Error **errp) @@ -196,7 +199,8 @@ int net_init_vhost_vdpa(const Netdev *netdev, const cha= r *name, NetClientState *peer, Error **errp) { const NetdevVhostVDPAOptions *opts; - int vdpa_device_fd, ret; + int vdpa_device_fd; + NetClientState *nc; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); opts =3D &netdev->u.vhost_vdpa; @@ -211,10 +215,11 @@ int net_init_vhost_vdpa(const Netdev *netdev, const c= har *name, return -errno; } =20 - ret =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, vdpa_device_f= d); - if (ret) { + nc =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, vdpa_device_fd= ); + if (!nc) { qemu_close(vdpa_device_fd); + return -1; } =20 - return ret; + return 0; } --=20 2.25.1 From nobody Thu May 16 12:58:34 2024 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 1633927121788539.7268827132291; Sun, 10 Oct 2021 21:38:41 -0700 (PDT) Received: from localhost ([::1]:52484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZn5E-0000Vm-ME for importer@patchew.org; Mon, 11 Oct 2021 00:38:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44658) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZmwD-0001Ik-MH for qemu-devel@nongnu.org; Mon, 11 Oct 2021 00:29:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33799) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZmwA-000365-3p for qemu-devel@nongnu.org; Mon, 11 Oct 2021 00:29:21 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-160-xTjK2AN-NTq5rGLyi34XBQ-1; Mon, 11 Oct 2021 00:29:01 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EBDE9824FA6; Mon, 11 Oct 2021 04:29:00 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-160.pek2.redhat.com [10.72.13.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1830F19D9B; Mon, 11 Oct 2021 04:28:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633926557; 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=qrKIFwvO1KWD1hYthrofeVlarJwkjjhJoX4eFsAZ6m4=; b=Qz+Dxnlu440g8tGJFjV3SOywld9zimlO3lR2cgCgT+325jKETM7hHRoRWWM1lYUSCE8wPC apKm8n/gFf2Nu2rZBXKBzN67KhMMPzlft1v6E+6k6lJPICpmjzLH+b7eA/EHiVwFhRf6MX CLaLjF3lW0hV9VknaXh7z1qfTgulx9A= X-MC-Unique: xTjK2AN-NTq5rGLyi34XBQ-1 From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH V4 05/10] net: introduce control client Date: Mon, 11 Oct 2021 12:28:24 +0800 Message-Id: <20211011042829.4159-6-jasowang@redhat.com> In-Reply-To: <20211011042829.4159-1-jasowang@redhat.com> References: <20211011042829.4159-1-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) DKIMWL_WL_HIGH=-0.049, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eperezma@redhat.com, elic@nvidia.com, gdawar@xilinx.com, lingshan.zhu@intel.com, lulu@redhat.com 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: 1633927123616100001 Content-Type: text/plain; charset="utf-8" This patch introduces a boolean for the device has control queue which can accepts control command via network queue. The first user would be the control virtqueue support for vhost. Signed-off-by: Jason Wang Message-Id: <20210907090322.1756-6-jasowang@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/net/net.h | 5 +++++ net/net.c | 24 +++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/include/net/net.h b/include/net/net.h index 5d1508081f..4f400b8a09 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -103,6 +103,7 @@ struct NetClientState { int vnet_hdr_len; bool is_netdev; bool do_not_pad; /* do not pad to the minimum ethernet frame length */ + bool is_datapath; QTAILQ_HEAD(, NetFilterState) filters; }; =20 @@ -134,6 +135,10 @@ NetClientState *qemu_new_net_client(NetClientInfo *inf= o, NetClientState *peer, const char *model, const char *name); +NetClientState *qemu_new_net_control_client(NetClientInfo *info, + NetClientState *peer, + const char *model, + const char *name); NICState *qemu_new_nic(NetClientInfo *info, NICConf *conf, const char *model, diff --git a/net/net.c b/net/net.c index 52c99196c6..f0d14dbfc1 100644 --- a/net/net.c +++ b/net/net.c @@ -239,7 +239,8 @@ static void qemu_net_client_setup(NetClientState *nc, NetClientState *peer, const char *model, const char *name, - NetClientDestructor *destructor) + NetClientDestructor *destructor, + bool is_datapath) { nc->info =3D info; nc->model =3D g_strdup(model); @@ -258,6 +259,7 @@ static void qemu_net_client_setup(NetClientState *nc, =20 nc->incoming_queue =3D qemu_new_net_queue(qemu_deliver_packet_iov, nc); nc->destructor =3D destructor; + nc->is_datapath =3D is_datapath; QTAILQ_INIT(&nc->filters); } =20 @@ -272,7 +274,23 @@ NetClientState *qemu_new_net_client(NetClientInfo *inf= o, =20 nc =3D g_malloc0(info->size); qemu_net_client_setup(nc, info, peer, model, name, - qemu_net_client_destructor); + qemu_net_client_destructor, true); + + return nc; +} + +NetClientState *qemu_new_net_control_client(NetClientInfo *info, + NetClientState *peer, + const char *model, + const char *name) +{ + NetClientState *nc; + + assert(info->size >=3D sizeof(NetClientState)); + + nc =3D g_malloc0(info->size); + qemu_net_client_setup(nc, info, peer, model, name, + qemu_net_client_destructor, false); =20 return nc; } @@ -297,7 +315,7 @@ NICState *qemu_new_nic(NetClientInfo *info, =20 for (i =3D 0; i < queues; i++) { qemu_net_client_setup(&nic->ncs[i], info, peers[i], model, name, - NULL); + NULL, true); nic->ncs[i].queue_index =3D i; } =20 --=20 2.25.1 From nobody Thu May 16 12:58:34 2024 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 1633926836599180.96127265933785; Sun, 10 Oct 2021 21:33:56 -0700 (PDT) Received: from localhost ([::1]:40756 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZn0d-00010U-Kz for importer@patchew.org; Mon, 11 Oct 2021 00:33:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44584) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZmw4-000170-Ir for qemu-devel@nongnu.org; Mon, 11 Oct 2021 00:29:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30553) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZmw2-0002NB-Oi for qemu-devel@nongnu.org; Mon, 11 Oct 2021 00:29:12 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-318-v_j9jMh9MQ2VaGwIgEeutw-1; Mon, 11 Oct 2021 00:29:06 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9B8F3824FA7; Mon, 11 Oct 2021 04:29:05 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-160.pek2.redhat.com [10.72.13.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id 815D81F6; Mon, 11 Oct 2021 04:29:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633926550; 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=lTEe2V4rOl6EVTF92adXF17NFDv10xkwRTOey5196Ms=; b=goZWeaP1U9nMWcTbuGDUaqrDCjqCHfD3vs32z6LUr7/BgtNf/Z082ik514d1v+Z52StWs8 exbprMdWOpCcB6yzomnJzSZe0Fh0RMqc0sPljv0RXIhMLd5E5F1US2CXLAoZYS/zUhDhss jGC0cQCw07On+TBA9KflQxd2T7jOm0U= X-MC-Unique: v_j9jMh9MQ2VaGwIgEeutw-1 From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH V4 06/10] vhost-net: control virtqueue support Date: Mon, 11 Oct 2021 12:28:25 +0800 Message-Id: <20211011042829.4159-7-jasowang@redhat.com> In-Reply-To: <20211011042829.4159-1-jasowang@redhat.com> References: <20211011042829.4159-1-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=jasowang@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.049, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eperezma@redhat.com, elic@nvidia.com, gdawar@xilinx.com, lingshan.zhu@intel.com, lulu@redhat.com 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: 1633926837683100001 Content-Type: text/plain; charset="utf-8" We assume there's no cvq in the past, this is not true when we need control virtqueue support for vhost-user backends. So this patch implements the control virtqueue support for vhost-net. As datapath, the control virtqueue is also required to be coupled with the NetClientState. The vhost_net_start/stop() are tweaked to accept the number of datapath queue pairs plus the the number of control virtqueue for us to start and stop the vhost device. Signed-off-by: Jason Wang Message-Id: <20210907090322.1756-7-jasowang@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/net/vhost_net-stub.c | 4 ++-- hw/net/vhost_net.c | 43 ++++++++++++++++++++++++++++++----------- hw/net/virtio-net.c | 4 ++-- include/net/vhost_net.h | 6 ++++-- 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/hw/net/vhost_net-stub.c b/hw/net/vhost_net-stub.c index a7f4252630..89d71cfb8e 100644 --- a/hw/net/vhost_net-stub.c +++ b/hw/net/vhost_net-stub.c @@ -33,13 +33,13 @@ struct vhost_net *vhost_net_init(VhostNetOptions *optio= ns) =20 int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, - int total_queues) + int data_queue_pairs, int cvq) { return -ENOSYS; } void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs, - int total_queues) + int data_queue_pairs, int cvq) { } =20 diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 386ec2eaa2..e1e9d1ec89 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -315,11 +315,14 @@ static void vhost_net_stop_one(struct vhost_net *net, } =20 int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, - int total_queues) + int data_queue_pairs, int cvq) { BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(dev))); VirtioBusState *vbus =3D VIRTIO_BUS(qbus); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(vbus); + int total_notifiers =3D data_queue_pairs * 2 + cvq; + VirtIONet *n =3D VIRTIO_NET(dev); + int nvhosts =3D data_queue_pairs + cvq; struct vhost_net *net; int r, e, i; NetClientState *peer; @@ -329,9 +332,14 @@ int vhost_net_start(VirtIODevice *dev, NetClientState = *ncs, return -ENOSYS; } =20 - for (i =3D 0; i < total_queues; i++) { + for (i =3D 0; i < nvhosts; i++) { + + if (i < data_queue_pairs) { + peer =3D qemu_get_peer(ncs, i); + } else { /* Control Virtqueue */ + peer =3D qemu_get_peer(ncs, n->max_queues); + } =20 - peer =3D qemu_get_peer(ncs, i); net =3D get_vhost_net(peer); vhost_net_set_vq_index(net, i * 2); =20 @@ -344,14 +352,18 @@ int vhost_net_start(VirtIODevice *dev, NetClientState= *ncs, } } =20 - r =3D k->set_guest_notifiers(qbus->parent, total_queues * 2, true); + r =3D k->set_guest_notifiers(qbus->parent, total_notifiers, true); if (r < 0) { error_report("Error binding guest notifier: %d", -r); goto err; } =20 - for (i =3D 0; i < total_queues; i++) { - peer =3D qemu_get_peer(ncs, i); + for (i =3D 0; i < nvhosts; i++) { + if (i < data_queue_pairs) { + peer =3D qemu_get_peer(ncs, i); + } else { + peer =3D qemu_get_peer(ncs, n->max_queues); + } r =3D vhost_net_start_one(get_vhost_net(peer), dev); =20 if (r < 0) { @@ -375,7 +387,7 @@ err_start: peer =3D qemu_get_peer(ncs , i); vhost_net_stop_one(get_vhost_net(peer), dev); } - e =3D k->set_guest_notifiers(qbus->parent, total_queues * 2, false); + e =3D k->set_guest_notifiers(qbus->parent, total_notifiers, false); if (e < 0) { fprintf(stderr, "vhost guest notifier cleanup failed: %d\n", e); fflush(stderr); @@ -385,18 +397,27 @@ err: } =20 void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs, - int total_queues) + int data_queue_pairs, int cvq) { BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(dev))); VirtioBusState *vbus =3D VIRTIO_BUS(qbus); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(vbus); + VirtIONet *n =3D VIRTIO_NET(dev); + NetClientState *peer; + int total_notifiers =3D data_queue_pairs * 2 + cvq; + int nvhosts =3D data_queue_pairs + cvq; int i, r; =20 - for (i =3D 0; i < total_queues; i++) { - vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev); + for (i =3D 0; i < nvhosts; i++) { + if (i < data_queue_pairs) { + peer =3D qemu_get_peer(ncs, i); + } else { + peer =3D qemu_get_peer(ncs, n->max_queues); + } + vhost_net_stop_one(get_vhost_net(peer), dev); } =20 - r =3D k->set_guest_notifiers(qbus->parent, total_queues * 2, false); + r =3D k->set_guest_notifiers(qbus->parent, total_notifiers, false); if (r < 0) { fprintf(stderr, "vhost guest notifier cleanup failed: %d\n", r); fflush(stderr); diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index f205331dcf..f1119cf0ad 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -285,14 +285,14 @@ static void virtio_net_vhost_status(VirtIONet *n, uin= t8_t status) } =20 n->vhost_started =3D 1; - r =3D vhost_net_start(vdev, n->nic->ncs, queues); + r =3D vhost_net_start(vdev, n->nic->ncs, queues, 0); if (r < 0) { error_report("unable to start vhost net: %d: " "falling back on userspace virtio", -r); n->vhost_started =3D 0; } } else { - vhost_net_stop(vdev, n->nic->ncs, queues); + vhost_net_stop(vdev, n->nic->ncs, queues, 0); n->vhost_started =3D 0; } } diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index fba40cf695..387e913e4e 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -21,8 +21,10 @@ typedef struct VhostNetOptions { uint64_t vhost_net_get_max_queues(VHostNetState *net); struct vhost_net *vhost_net_init(VhostNetOptions *options); =20 -int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, int total_queu= es); -void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs, int total_queu= es); +int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, + int data_queue_pairs, int cvq); +void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs, + int data_queue_pairs, int cvq); =20 void vhost_net_cleanup(VHostNetState *net); =20 --=20 2.25.1 From nobody Thu May 16 12:58:34 2024 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 1633927152009127.78437710243452; Sun, 10 Oct 2021 21:39:12 -0700 (PDT) Received: from localhost ([::1]:53364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZn5j-0001B7-1e for importer@patchew.org; Mon, 11 Oct 2021 00:39:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44608) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZmw9-0001D2-IQ for qemu-devel@nongnu.org; Mon, 11 Oct 2021 00:29:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:50069) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZmw6-0002hZ-0S for qemu-devel@nongnu.org; Mon, 11 Oct 2021 00:29:16 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-562-3e01wamJN2ecvzYDfgRSug-1; Mon, 11 Oct 2021 00:29:09 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E94E010A8E01; Mon, 11 Oct 2021 04:29:08 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-160.pek2.redhat.com [10.72.13.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B3D93CC9; Mon, 11 Oct 2021 04:29:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633926553; 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=JvuafJJJJK0asBUceXgf8b/bXh9m+QmgQW/SFWJUETw=; b=Fw2dXgcQo0a1gYYFsetO3s8Ya1yK0ntN5z3uIHuZczEaxq0xrzrceKaSW/AjiSergQ1Gwe vCxlUD6bQfhZ5FtpPE3CorV4l/5f3VMAx9fxWMpzcfSEAAHXctdF2OtPREZRAHZYhk7DwR Gd1UrP+4RQ3MLkDLVpykfwecmxNPyj4= X-MC-Unique: 3e01wamJN2ecvzYDfgRSug-1 From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH V4 07/10] virtio-net: use "queue_pairs" instead of "queues" when possible Date: Mon, 11 Oct 2021 12:28:26 +0800 Message-Id: <20211011042829.4159-8-jasowang@redhat.com> In-Reply-To: <20211011042829.4159-1-jasowang@redhat.com> References: <20211011042829.4159-1-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=jasowang@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.049, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eperezma@redhat.com, elic@nvidia.com, gdawar@xilinx.com, lingshan.zhu@intel.com, lulu@redhat.com 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: 1633927153179100001 Content-Type: text/plain; charset="utf-8" Most of the time, "queues" really means queue pairs. So this patch switch to use "queue_pairs" to avoid confusion. Signed-off-by: Jason Wang Message-Id: <20210907090322.1756-8-jasowang@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/net/vhost_net.c | 6 +- hw/net/virtio-net.c | 150 ++++++++++++++++----------------- include/hw/virtio/virtio-net.h | 4 +- 3 files changed, 80 insertions(+), 80 deletions(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index e1e9d1ec89..2b594b4642 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -337,7 +337,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *= ncs, if (i < data_queue_pairs) { peer =3D qemu_get_peer(ncs, i); } else { /* Control Virtqueue */ - peer =3D qemu_get_peer(ncs, n->max_queues); + peer =3D qemu_get_peer(ncs, n->max_queue_pairs); } =20 net =3D get_vhost_net(peer); @@ -362,7 +362,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *= ncs, if (i < data_queue_pairs) { peer =3D qemu_get_peer(ncs, i); } else { - peer =3D qemu_get_peer(ncs, n->max_queues); + peer =3D qemu_get_peer(ncs, n->max_queue_pairs); } r =3D vhost_net_start_one(get_vhost_net(peer), dev); =20 @@ -412,7 +412,7 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState *= ncs, if (i < data_queue_pairs) { peer =3D qemu_get_peer(ncs, i); } else { - peer =3D qemu_get_peer(ncs, n->max_queues); + peer =3D qemu_get_peer(ncs, n->max_queue_pairs); } vhost_net_stop_one(get_vhost_net(peer), dev); } diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index f1119cf0ad..2ade019b22 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -54,7 +54,7 @@ #define VIRTIO_NET_RX_QUEUE_DEFAULT_SIZE 256 #define VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE 256 =20 -/* for now, only allow larger queues; with virtio-1, guest can downsize */ +/* for now, only allow larger queue_pairs; with virtio-1, guest can downsi= ze */ #define VIRTIO_NET_RX_QUEUE_MIN_SIZE VIRTIO_NET_RX_QUEUE_DEFAULT_SIZE #define VIRTIO_NET_TX_QUEUE_MIN_SIZE VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE =20 @@ -131,7 +131,7 @@ static void virtio_net_get_config(VirtIODevice *vdev, u= int8_t *config) int ret =3D 0; memset(&netcfg, 0 , sizeof(struct virtio_net_config)); virtio_stw_p(vdev, &netcfg.status, n->status); - virtio_stw_p(vdev, &netcfg.max_virtqueue_pairs, n->max_queues); + virtio_stw_p(vdev, &netcfg.max_virtqueue_pairs, n->max_queue_pairs); virtio_stw_p(vdev, &netcfg.mtu, n->net_conf.mtu); memcpy(netcfg.mac, n->mac, ETH_ALEN); virtio_stl_p(vdev, &netcfg.speed, n->net_conf.speed); @@ -243,7 +243,7 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8= _t status) { VirtIODevice *vdev =3D VIRTIO_DEVICE(n); NetClientState *nc =3D qemu_get_queue(n->nic); - int queues =3D n->multiqueue ? n->max_queues : 1; + int queue_pairs =3D n->multiqueue ? n->max_queue_pairs : 1; =20 if (!get_vhost_net(nc->peer)) { return; @@ -266,7 +266,7 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8= _t status) /* Any packets outstanding? Purge them to avoid touching rings * when vhost is running. */ - for (i =3D 0; i < queues; i++) { + for (i =3D 0; i < queue_pairs; i++) { NetClientState *qnc =3D qemu_get_subqueue(n->nic, i); =20 /* Purge both directions: TX and RX. */ @@ -285,14 +285,14 @@ static void virtio_net_vhost_status(VirtIONet *n, uin= t8_t status) } =20 n->vhost_started =3D 1; - r =3D vhost_net_start(vdev, n->nic->ncs, queues, 0); + r =3D vhost_net_start(vdev, n->nic->ncs, queue_pairs, 0); if (r < 0) { error_report("unable to start vhost net: %d: " "falling back on userspace virtio", -r); n->vhost_started =3D 0; } } else { - vhost_net_stop(vdev, n->nic->ncs, queues, 0); + vhost_net_stop(vdev, n->nic->ncs, queue_pairs, 0); n->vhost_started =3D 0; } } @@ -309,11 +309,11 @@ static int virtio_net_set_vnet_endian_one(VirtIODevic= e *vdev, } =20 static bool virtio_net_set_vnet_endian(VirtIODevice *vdev, NetClientState = *ncs, - int queues, bool enable) + int queue_pairs, bool enable) { int i; =20 - for (i =3D 0; i < queues; i++) { + for (i =3D 0; i < queue_pairs; i++) { if (virtio_net_set_vnet_endian_one(vdev, ncs[i].peer, enable) < 0 = && enable) { while (--i >=3D 0) { @@ -330,7 +330,7 @@ static bool virtio_net_set_vnet_endian(VirtIODevice *vd= ev, NetClientState *ncs, static void virtio_net_vnet_endian_status(VirtIONet *n, uint8_t status) { VirtIODevice *vdev =3D VIRTIO_DEVICE(n); - int queues =3D n->multiqueue ? n->max_queues : 1; + int queue_pairs =3D n->multiqueue ? n->max_queue_pairs : 1; =20 if (virtio_net_started(n, status)) { /* Before using the device, we tell the network backend about the @@ -339,14 +339,14 @@ static void virtio_net_vnet_endian_status(VirtIONet *= n, uint8_t status) * virtio-net code. */ n->needs_vnet_hdr_swap =3D virtio_net_set_vnet_endian(vdev, n->nic= ->ncs, - queues, true); + queue_pairs, t= rue); } else if (virtio_net_started(n, vdev->status)) { /* After using the device, we need to reset the network backend to * the default (guest native endianness), otherwise the guest may * lose network connectivity if it is rebooted into a different * endianness. */ - virtio_net_set_vnet_endian(vdev, n->nic->ncs, queues, false); + virtio_net_set_vnet_endian(vdev, n->nic->ncs, queue_pairs, false); } } =20 @@ -368,12 +368,12 @@ static void virtio_net_set_status(struct VirtIODevice= *vdev, uint8_t status) virtio_net_vnet_endian_status(n, status); virtio_net_vhost_status(n, status); =20 - for (i =3D 0; i < n->max_queues; i++) { + for (i =3D 0; i < n->max_queue_pairs; i++) { NetClientState *ncs =3D qemu_get_subqueue(n->nic, i); bool queue_started; q =3D &n->vqs[i]; =20 - if ((!n->multiqueue && i !=3D 0) || i >=3D n->curr_queues) { + if ((!n->multiqueue && i !=3D 0) || i >=3D n->curr_queue_pairs) { queue_status =3D 0; } else { queue_status =3D status; @@ -540,7 +540,7 @@ static void virtio_net_reset(VirtIODevice *vdev) n->nouni =3D 0; n->nobcast =3D 0; /* multiqueue is disabled by default */ - n->curr_queues =3D 1; + n->curr_queue_pairs =3D 1; timer_del(n->announce_timer.tm); n->announce_timer.round =3D 0; n->status &=3D ~VIRTIO_NET_S_ANNOUNCE; @@ -556,7 +556,7 @@ static void virtio_net_reset(VirtIODevice *vdev) memset(n->vlans, 0, MAX_VLAN >> 3); =20 /* Flush any async TX */ - for (i =3D 0; i < n->max_queues; i++) { + for (i =3D 0; i < n->max_queue_pairs; i++) { NetClientState *nc =3D qemu_get_subqueue(n->nic, i); =20 if (nc->peer) { @@ -610,7 +610,7 @@ static void virtio_net_set_mrg_rx_bufs(VirtIONet *n, in= t mergeable_rx_bufs, sizeof(struct virtio_net_hdr); } =20 - for (i =3D 0; i < n->max_queues; i++) { + for (i =3D 0; i < n->max_queue_pairs; i++) { nc =3D qemu_get_subqueue(n->nic, i); =20 if (peer_has_vnet_hdr(n) && @@ -655,7 +655,7 @@ static int peer_attach(VirtIONet *n, int index) return 0; } =20 - if (n->max_queues =3D=3D 1) { + if (n->max_queue_pairs =3D=3D 1) { return 0; } =20 @@ -681,7 +681,7 @@ static int peer_detach(VirtIONet *n, int index) return tap_disable(nc->peer); } =20 -static void virtio_net_set_queues(VirtIONet *n) +static void virtio_net_set_queue_pairs(VirtIONet *n) { int i; int r; @@ -690,8 +690,8 @@ static void virtio_net_set_queues(VirtIONet *n) return; } =20 - for (i =3D 0; i < n->max_queues; i++) { - if (i < n->curr_queues) { + for (i =3D 0; i < n->max_queue_pairs; i++) { + if (i < n->curr_queue_pairs) { r =3D peer_attach(n, i); assert(!r); } else { @@ -920,7 +920,7 @@ static void virtio_net_set_features(VirtIODevice *vdev,= uint64_t features) virtio_net_apply_guest_offloads(n); } =20 - for (i =3D 0; i < n->max_queues; i++) { + for (i =3D 0; i < n->max_queue_pairs; i++) { NetClientState *nc =3D qemu_get_subqueue(n->nic, i); =20 if (!get_vhost_net(nc->peer)) { @@ -1247,7 +1247,7 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, VirtIODevice *vdev =3D VIRTIO_DEVICE(n); struct virtio_net_rss_config cfg; size_t s, offset =3D 0, size_get; - uint16_t queues, i; + uint16_t queue_pairs, i; struct { uint16_t us; uint8_t b; @@ -1289,7 +1289,7 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, } n->rss_data.default_queue =3D do_rss ? virtio_lduw_p(vdev, &cfg.unclassified_queue) : 0; - if (n->rss_data.default_queue >=3D n->max_queues) { + if (n->rss_data.default_queue >=3D n->max_queue_pairs) { err_msg =3D "Invalid default queue"; err_value =3D n->rss_data.default_queue; goto error; @@ -1318,14 +1318,14 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, size_get =3D sizeof(temp); s =3D iov_to_buf(iov, iov_cnt, offset, &temp, size_get); if (s !=3D size_get) { - err_msg =3D "Can't get queues"; + err_msg =3D "Can't get queue_pairs"; err_value =3D (uint32_t)s; goto error; } - queues =3D do_rss ? virtio_lduw_p(vdev, &temp.us) : n->curr_queues; - if (queues =3D=3D 0 || queues > n->max_queues) { - err_msg =3D "Invalid number of queues"; - err_value =3D queues; + queue_pairs =3D do_rss ? virtio_lduw_p(vdev, &temp.us) : n->curr_queue= _pairs; + if (queue_pairs =3D=3D 0 || queue_pairs > n->max_queue_pairs) { + err_msg =3D "Invalid number of queue_pairs"; + err_value =3D queue_pairs; goto error; } if (temp.b > VIRTIO_NET_RSS_MAX_KEY_SIZE) { @@ -1340,7 +1340,7 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, } if (!temp.b && !n->rss_data.hash_types) { virtio_net_disable_rss(n); - return queues; + return queue_pairs; } offset +=3D size_get; size_get =3D temp.b; @@ -1373,7 +1373,7 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, trace_virtio_net_rss_enable(n->rss_data.hash_types, n->rss_data.indirections_len, temp.b); - return queues; + return queue_pairs; error: trace_virtio_net_rss_error(err_msg, err_value); virtio_net_disable_rss(n); @@ -1384,15 +1384,15 @@ static int virtio_net_handle_mq(VirtIONet *n, uint8= _t cmd, struct iovec *iov, unsigned int iov_cnt) { VirtIODevice *vdev =3D VIRTIO_DEVICE(n); - uint16_t queues; + uint16_t queue_pairs; =20 virtio_net_disable_rss(n); if (cmd =3D=3D VIRTIO_NET_CTRL_MQ_HASH_CONFIG) { - queues =3D virtio_net_handle_rss(n, iov, iov_cnt, false); - return queues ? VIRTIO_NET_OK : VIRTIO_NET_ERR; + queue_pairs =3D virtio_net_handle_rss(n, iov, iov_cnt, false); + return queue_pairs ? VIRTIO_NET_OK : VIRTIO_NET_ERR; } if (cmd =3D=3D VIRTIO_NET_CTRL_MQ_RSS_CONFIG) { - queues =3D virtio_net_handle_rss(n, iov, iov_cnt, true); + queue_pairs =3D virtio_net_handle_rss(n, iov, iov_cnt, true); } else if (cmd =3D=3D VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) { struct virtio_net_ctrl_mq mq; size_t s; @@ -1403,24 +1403,24 @@ static int virtio_net_handle_mq(VirtIONet *n, uint8= _t cmd, if (s !=3D sizeof(mq)) { return VIRTIO_NET_ERR; } - queues =3D virtio_lduw_p(vdev, &mq.virtqueue_pairs); + queue_pairs =3D virtio_lduw_p(vdev, &mq.virtqueue_pairs); =20 } else { return VIRTIO_NET_ERR; } =20 - if (queues < VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN || - queues > VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX || - queues > n->max_queues || + if (queue_pairs < VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN || + queue_pairs > VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX || + queue_pairs > n->max_queue_pairs || !n->multiqueue) { return VIRTIO_NET_ERR; } =20 - n->curr_queues =3D queues; - /* stop the backend before changing the number of queues to avoid hand= ling a + n->curr_queue_pairs =3D queue_pairs; + /* stop the backend before changing the number of queue_pairs to avoid= handling a * disabled queue */ virtio_net_set_status(vdev, vdev->status); - virtio_net_set_queues(n); + virtio_net_set_queue_pairs(n); =20 return VIRTIO_NET_OK; } @@ -1498,7 +1498,7 @@ static bool virtio_net_can_receive(NetClientState *nc) return false; } =20 - if (nc->queue_index >=3D n->curr_queues) { + if (nc->queue_index >=3D n->curr_queue_pairs) { return false; } =20 @@ -2778,11 +2778,11 @@ static void virtio_net_del_queue(VirtIONet *n, int = index) virtio_del_queue(vdev, index * 2 + 1); } =20 -static void virtio_net_change_num_queues(VirtIONet *n, int new_max_queues) +static void virtio_net_change_num_queue_pairs(VirtIONet *n, int new_max_qu= eue_pairs) { VirtIODevice *vdev =3D VIRTIO_DEVICE(n); int old_num_queues =3D virtio_get_num_queues(vdev); - int new_num_queues =3D new_max_queues * 2 + 1; + int new_num_queues =3D new_max_queue_pairs * 2 + 1; int i; =20 assert(old_num_queues >=3D 3); @@ -2815,12 +2815,12 @@ static void virtio_net_change_num_queues(VirtIONet = *n, int new_max_queues) =20 static void virtio_net_set_multiqueue(VirtIONet *n, int multiqueue) { - int max =3D multiqueue ? n->max_queues : 1; + int max =3D multiqueue ? n->max_queue_pairs : 1; =20 n->multiqueue =3D multiqueue; - virtio_net_change_num_queues(n, max); + virtio_net_change_num_queue_pairs(n, max); =20 - virtio_net_set_queues(n); + virtio_net_set_queue_pairs(n); } =20 static int virtio_net_post_load_device(void *opaque, int version_id) @@ -2853,7 +2853,7 @@ static int virtio_net_post_load_device(void *opaque, = int version_id) */ n->saved_guest_offloads =3D n->curr_guest_offloads; =20 - virtio_net_set_queues(n); + virtio_net_set_queue_pairs(n); =20 /* Find the first multicast entry in the saved MAC filter */ for (i =3D 0; i < n->mac_table.in_use; i++) { @@ -2866,7 +2866,7 @@ static int virtio_net_post_load_device(void *opaque, = int version_id) /* nc.link_down can't be migrated, so infer link_down according * to link status bit in n->status */ link_down =3D (n->status & VIRTIO_NET_S_LINK_UP) =3D=3D 0; - for (i =3D 0; i < n->max_queues; i++) { + for (i =3D 0; i < n->max_queue_pairs; i++) { qemu_get_subqueue(n->nic, i)->link_down =3D link_down; } =20 @@ -2931,9 +2931,9 @@ static const VMStateDescription vmstate_virtio_net_qu= eue_tx_waiting =3D { }, }; =20 -static bool max_queues_gt_1(void *opaque, int version_id) +static bool max_queue_pairs_gt_1(void *opaque, int version_id) { - return VIRTIO_NET(opaque)->max_queues > 1; + return VIRTIO_NET(opaque)->max_queue_pairs > 1; } =20 static bool has_ctrl_guest_offloads(void *opaque, int version_id) @@ -2958,13 +2958,13 @@ static bool mac_table_doesnt_fit(void *opaque, int = version_id) struct VirtIONetMigTmp { VirtIONet *parent; VirtIONetQueue *vqs_1; - uint16_t curr_queues_1; + uint16_t curr_queue_pairs_1; uint8_t has_ufo; uint32_t has_vnet_hdr; }; =20 /* The 2nd and subsequent tx_waiting flags are loaded later than - * the 1st entry in the queues and only if there's more than one + * the 1st entry in the queue_pairs and only if there's more than one * entry. We use the tmp mechanism to calculate a temporary * pointer and count and also validate the count. */ @@ -2974,9 +2974,9 @@ static int virtio_net_tx_waiting_pre_save(void *opaqu= e) struct VirtIONetMigTmp *tmp =3D opaque; =20 tmp->vqs_1 =3D tmp->parent->vqs + 1; - tmp->curr_queues_1 =3D tmp->parent->curr_queues - 1; - if (tmp->parent->curr_queues =3D=3D 0) { - tmp->curr_queues_1 =3D 0; + tmp->curr_queue_pairs_1 =3D tmp->parent->curr_queue_pairs - 1; + if (tmp->parent->curr_queue_pairs =3D=3D 0) { + tmp->curr_queue_pairs_1 =3D 0; } =20 return 0; @@ -2989,9 +2989,9 @@ static int virtio_net_tx_waiting_pre_load(void *opaqu= e) /* Reuse the pointer setup from save */ virtio_net_tx_waiting_pre_save(opaque); =20 - if (tmp->parent->curr_queues > tmp->parent->max_queues) { - error_report("virtio-net: curr_queues %x > max_queues %x", - tmp->parent->curr_queues, tmp->parent->max_queues); + if (tmp->parent->curr_queue_pairs > tmp->parent->max_queue_pairs) { + error_report("virtio-net: curr_queue_pairs %x > max_queue_pairs %x= ", + tmp->parent->curr_queue_pairs, tmp->parent->max_queue_pairs); =20 return -EINVAL; } @@ -3005,7 +3005,7 @@ static const VMStateDescription vmstate_virtio_net_tx= _waiting =3D { .pre_save =3D virtio_net_tx_waiting_pre_save, .fields =3D (VMStateField[]) { VMSTATE_STRUCT_VARRAY_POINTER_UINT16(vqs_1, struct VirtIONetMigTmp, - curr_queues_1, + curr_queue_pairs_1, vmstate_virtio_net_queue_tx_waiting, struct VirtIONetQueue), VMSTATE_END_OF_LIST() @@ -3147,9 +3147,9 @@ static const VMStateDescription vmstate_virtio_net_de= vice =3D { VMSTATE_UINT8(nobcast, VirtIONet), VMSTATE_WITH_TMP(VirtIONet, struct VirtIONetMigTmp, vmstate_virtio_net_has_ufo), - VMSTATE_SINGLE_TEST(max_queues, VirtIONet, max_queues_gt_1, 0, + VMSTATE_SINGLE_TEST(max_queue_pairs, VirtIONet, max_queue_pairs_gt= _1, 0, vmstate_info_uint16_equal, uint16_t), - VMSTATE_UINT16_TEST(curr_queues, VirtIONet, max_queues_gt_1), + VMSTATE_UINT16_TEST(curr_queue_pairs, VirtIONet, max_queue_pairs_g= t_1), VMSTATE_WITH_TMP(VirtIONet, struct VirtIONetMigTmp, vmstate_virtio_net_tx_waiting), VMSTATE_UINT64_TEST(curr_guest_offloads, VirtIONet, @@ -3393,16 +3393,16 @@ static void virtio_net_device_realize(DeviceState *= dev, Error **errp) return; } =20 - n->max_queues =3D MAX(n->nic_conf.peers.queues, 1); - if (n->max_queues * 2 + 1 > VIRTIO_QUEUE_MAX) { - error_setg(errp, "Invalid number of queues (=3D %" PRIu32 "), " + n->max_queue_pairs =3D MAX(n->nic_conf.peers.queues, 1); + if (n->max_queue_pairs * 2 + 1 > VIRTIO_QUEUE_MAX) { + error_setg(errp, "Invalid number of queue_pairs (=3D %" PRIu32 "),= " "must be a positive integer less than %d.", - n->max_queues, (VIRTIO_QUEUE_MAX - 1) / 2); + n->max_queue_pairs, (VIRTIO_QUEUE_MAX - 1) / 2); virtio_cleanup(vdev); return; } - n->vqs =3D g_malloc0(sizeof(VirtIONetQueue) * n->max_queues); - n->curr_queues =3D 1; + n->vqs =3D g_malloc0(sizeof(VirtIONetQueue) * n->max_queue_pairs); + n->curr_queue_pairs =3D 1; n->tx_timeout =3D n->net_conf.txtimer; =20 if (n->net_conf.tx && strcmp(n->net_conf.tx, "timer") @@ -3416,7 +3416,7 @@ static void virtio_net_device_realize(DeviceState *de= v, Error **errp) n->net_conf.tx_queue_size =3D MIN(virtio_net_max_tx_queue_size(n), n->net_conf.tx_queue_size); =20 - for (i =3D 0; i < n->max_queues; i++) { + for (i =3D 0; i < n->max_queue_pairs; i++) { virtio_net_add_queue(n, i); } =20 @@ -3440,13 +3440,13 @@ static void virtio_net_device_realize(DeviceState *= dev, Error **errp) object_get_typename(OBJECT(dev)), dev->id, n= ); } =20 - for (i =3D 0; i < n->max_queues; i++) { + for (i =3D 0; i < n->max_queue_pairs; i++) { n->nic->ncs[i].do_not_pad =3D true; } =20 peer_test_vnet_hdr(n); if (peer_has_vnet_hdr(n)) { - for (i =3D 0; i < n->max_queues; i++) { + for (i =3D 0; i < n->max_queue_pairs; i++) { qemu_using_vnet_hdr(qemu_get_subqueue(n->nic, i)->peer, true); } n->host_hdr_len =3D sizeof(struct virtio_net_hdr); @@ -3488,7 +3488,7 @@ static void virtio_net_device_unrealize(DeviceState *= dev) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VirtIONet *n =3D VIRTIO_NET(dev); - int i, max_queues; + int i, max_queue_pairs; =20 if (virtio_has_feature(n->host_features, VIRTIO_NET_F_RSS)) { virtio_net_unload_ebpf(n); @@ -3510,12 +3510,12 @@ static void virtio_net_device_unrealize(DeviceState= *dev) remove_migration_state_change_notifier(&n->migration_state); } =20 - max_queues =3D n->multiqueue ? n->max_queues : 1; - for (i =3D 0; i < max_queues; i++) { + max_queue_pairs =3D n->multiqueue ? n->max_queue_pairs : 1; + for (i =3D 0; i < max_queue_pairs; i++) { virtio_net_del_queue(n, i); } /* delete also control vq */ - virtio_del_queue(vdev, max_queues * 2); + virtio_del_queue(vdev, max_queue_pairs * 2); qemu_announce_timer_del(&n->announce_timer, false); g_free(n->vqs); qemu_del_nic(n->nic); diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 824a69c23f..71cbdc26d7 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -194,8 +194,8 @@ struct VirtIONet { NICConf nic_conf; DeviceState *qdev; int multiqueue; - uint16_t max_queues; - uint16_t curr_queues; + uint16_t max_queue_pairs; + uint16_t curr_queue_pairs; size_t config_size; char *netclient_name; char *netclient_type; --=20 2.25.1 From nobody Thu May 16 12:58:34 2024 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 163392701396983.35945325791761; Sun, 10 Oct 2021 21:36:53 -0700 (PDT) Received: from localhost ([::1]:46448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZn3U-0004qu-GE for importer@patchew.org; Mon, 11 Oct 2021 00:36:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZmwD-0001Hg-Bj for qemu-devel@nongnu.org; Mon, 11 Oct 2021 00:29:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:49082) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZmw9-00031P-E3 for qemu-devel@nongnu.org; Mon, 11 Oct 2021 00:29:21 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-590-mJzkDAe1Nc6bE3-OkMFT9Q-1; Mon, 11 Oct 2021 00:29:13 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4455510A8E01; Mon, 11 Oct 2021 04:29:12 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-160.pek2.redhat.com [10.72.13.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A79F19D9B; Mon, 11 Oct 2021 04:29:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633926556; 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=49oFEDRRFAI1Jgeo3jZFbjBXOYOkD32FxRzkgacxuMI=; b=JleWEPdV+/doqA9IGVDokb+QKPpUoz5k0BqpAx/BeUpq7HB9tzo1eWZMR02VQOk9TSWMBw 4lGoaTpOkdOmdN1USVBTMScaP7mEiWfWMpn8mkLCZbLE6/xqfxaxe8ep3tKoCn1zKOZJjw OHZqXjbXpG3IzJtXTdJpzspl92ukeDc= X-MC-Unique: mJzkDAe1Nc6bE3-OkMFT9Q-1 From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH V4 08/10] vhost: record the last virtqueue index for the virtio device Date: Mon, 11 Oct 2021 12:28:27 +0800 Message-Id: <20211011042829.4159-9-jasowang@redhat.com> In-Reply-To: <20211011042829.4159-1-jasowang@redhat.com> References: <20211011042829.4159-1-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=jasowang@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.049, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eperezma@redhat.com, elic@nvidia.com, gdawar@xilinx.com, lingshan.zhu@intel.com, lulu@redhat.com 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: 1633927014283100001 Content-Type: text/plain; charset="utf-8" This patch introduces a new field in the vhost_dev structure to record the last virtqueue index for the virtio device. This will be useful for the vhost backends with 1:N model to start or stop the device after all the vhost_dev structures were started or stopped. Signed-off-by: Jason Wang Message-Id: <20210907090322.1756-9-jasowang@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/net/vhost_net.c | 12 +++++++++--- include/hw/virtio/vhost.h | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 2b594b4642..3aabab06ea 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -231,9 +231,11 @@ fail: return NULL; } =20 -static void vhost_net_set_vq_index(struct vhost_net *net, int vq_index) +static void vhost_net_set_vq_index(struct vhost_net *net, int vq_index, + int last_index) { net->dev.vq_index =3D vq_index; + net->dev.last_index =3D last_index; } =20 static int vhost_net_start_one(struct vhost_net *net, @@ -324,9 +326,13 @@ int vhost_net_start(VirtIODevice *dev, NetClientState = *ncs, VirtIONet *n =3D VIRTIO_NET(dev); int nvhosts =3D data_queue_pairs + cvq; struct vhost_net *net; - int r, e, i; + int r, e, i, last_index =3D data_qps * 2; NetClientState *peer; =20 + if (!cvq) { + last_index -=3D 1; + } + if (!k->set_guest_notifiers) { error_report("binding does not support guest notifiers"); return -ENOSYS; @@ -341,7 +347,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *= ncs, } =20 net =3D get_vhost_net(peer); - vhost_net_set_vq_index(net, i * 2); + vhost_net_set_vq_index(net, i * 2, last_index); =20 /* Suppress the masking guest notifiers on vhost user * because vhost user doesn't interrupt masking/unmasking diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 1a9fc65089..3fa0b554ef 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -74,6 +74,8 @@ struct vhost_dev { unsigned int nvqs; /* the first virtqueue which would be used by this vhost dev */ int vq_index; + /* the last vq index for the virtio device (not vhost) */ + int last_index; /* if non-zero, minimum required value for max_queues */ int num_queues; uint64_t features; --=20 2.25.1 From nobody Thu May 16 12:58:34 2024 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 1633926810059335.53394988219566; Sun, 10 Oct 2021 21:33:30 -0700 (PDT) Received: from localhost ([::1]:38558 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZn0D-0007wN-0F for importer@patchew.org; Mon, 11 Oct 2021 00:33:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44674) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZmwH-0001Ma-AN for qemu-devel@nongnu.org; Mon, 11 Oct 2021 00:29:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:50840) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZmwF-0003vQ-Js for qemu-devel@nongnu.org; Mon, 11 Oct 2021 00:29:25 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-40-T1zNHA5kOPiAVMxvYYsCTg-1; Mon, 11 Oct 2021 00:29:19 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 562751006AAF; Mon, 11 Oct 2021 04:29:18 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-160.pek2.redhat.com [10.72.13.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id 78E3E399; Mon, 11 Oct 2021 04:29:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633926563; 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=ebizvWEx1TbZ28G6F4sTh2GocUNCYKO8lOxG98jij4c=; b=XsApGDkOR62Xz8mQCjoSr1M3Dm0EYx4hvCkPJOcliyoTnyZGgVJXxYYegYVo4hjmOnmz6i YBggDyo8O3TFkEHRjkPtmjgIc7HmVAqr4J1DsOn0y2UpARJH44IqZFUMD2ScA6wFetRVUh vkWzN8fgnX+CWRnC7/Q+5EAbdmAjDuI= X-MC-Unique: T1zNHA5kOPiAVMxvYYsCTg-1 From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH V4 09/10] virtio-net: vhost control virtqueue support Date: Mon, 11 Oct 2021 12:28:28 +0800 Message-Id: <20211011042829.4159-10-jasowang@redhat.com> In-Reply-To: <20211011042829.4159-1-jasowang@redhat.com> References: <20211011042829.4159-1-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=jasowang@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.049, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eperezma@redhat.com, elic@nvidia.com, gdawar@xilinx.com, lingshan.zhu@intel.com, lulu@redhat.com 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: 1633926812217100001 Content-Type: text/plain; charset="utf-8" This patch implements the control virtqueue support for vhost. This requires virtio-net to figure out the datapath queue pairs and control virtqueue via is_datapath and pass the number of those two types of virtqueues to vhost_net_start()/vhost_net_stop(). Signed-off-by: Jason Wang Message-Id: <20210907090322.1756-10-jasowang@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/net/vhost_net.c | 2 +- hw/net/virtio-net.c | 23 +++++++++++++++++++---- include/hw/virtio/virtio-net.h | 1 + 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 3aabab06ea..0d888f29a6 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -326,7 +326,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *= ncs, VirtIONet *n =3D VIRTIO_NET(dev); int nvhosts =3D data_queue_pairs + cvq; struct vhost_net *net; - int r, e, i, last_index =3D data_qps * 2; + int r, e, i, last_index =3D data_queue_pairs * 2; NetClientState *peer; =20 if (!cvq) { diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 2ade019b22..57a0cbc6cd 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -244,6 +244,7 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8= _t status) VirtIODevice *vdev =3D VIRTIO_DEVICE(n); NetClientState *nc =3D qemu_get_queue(n->nic); int queue_pairs =3D n->multiqueue ? n->max_queue_pairs : 1; + int cvq =3D n->max_ncs - n->max_queue_pairs; =20 if (!get_vhost_net(nc->peer)) { return; @@ -285,14 +286,14 @@ static void virtio_net_vhost_status(VirtIONet *n, uin= t8_t status) } =20 n->vhost_started =3D 1; - r =3D vhost_net_start(vdev, n->nic->ncs, queue_pairs, 0); + r =3D vhost_net_start(vdev, n->nic->ncs, queue_pairs, cvq); if (r < 0) { error_report("unable to start vhost net: %d: " "falling back on userspace virtio", -r); n->vhost_started =3D 0; } } else { - vhost_net_stop(vdev, n->nic->ncs, queue_pairs, 0); + vhost_net_stop(vdev, n->nic->ncs, queue_pairs, cvq); n->vhost_started =3D 0; } } @@ -3393,9 +3394,23 @@ static void virtio_net_device_realize(DeviceState *d= ev, Error **errp) return; } =20 - n->max_queue_pairs =3D MAX(n->nic_conf.peers.queues, 1); + n->max_ncs =3D MAX(n->nic_conf.peers.queues, 1); + + /* + * Figure out the datapath queue pairs since the backend could + * provide control queue via peers as well. + */ + if (n->nic_conf.peers.queues) { + for (i =3D 0; i < n->max_ncs; i++) { + if (n->nic_conf.peers.ncs[i]->is_datapath) { + ++n->max_queue_pairs; + } + } + } + n->max_queue_pairs =3D MAX(n->max_queue_pairs, 1); + if (n->max_queue_pairs * 2 + 1 > VIRTIO_QUEUE_MAX) { - error_setg(errp, "Invalid number of queue_pairs (=3D %" PRIu32 "),= " + error_setg(errp, "Invalid number of queue pairs (=3D %" PRIu32 "),= " "must be a positive integer less than %d.", n->max_queue_pairs, (VIRTIO_QUEUE_MAX - 1) / 2); virtio_cleanup(vdev); diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 71cbdc26d7..08ee6dea39 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -196,6 +196,7 @@ struct VirtIONet { int multiqueue; uint16_t max_queue_pairs; uint16_t curr_queue_pairs; + uint16_t max_ncs; size_t config_size; char *netclient_name; char *netclient_type; --=20 2.25.1 From nobody Thu May 16 12:58:34 2024 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 1633926703202504.80860065521483; Sun, 10 Oct 2021 21:31:43 -0700 (PDT) Received: from localhost ([::1]:32998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZmyU-0004Dk-6a for importer@patchew.org; Mon, 11 Oct 2021 00:31:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZmwK-0001Qk-UZ for qemu-devel@nongnu.org; Mon, 11 Oct 2021 00:29:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33425) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZmwJ-0004FX-6U for qemu-devel@nongnu.org; Mon, 11 Oct 2021 00:29:28 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-312-FgTfUTaJOtK39XafpBELmQ-1; Mon, 11 Oct 2021 00:29:22 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C23A910A8E08; Mon, 11 Oct 2021 04:29:21 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-160.pek2.redhat.com [10.72.13.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA1A41F6; Mon, 11 Oct 2021 04:29:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633926566; 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=6mEcYZce6yQ/6txHfoWBZebvqIm5VQSTiQU0zF5oJ/A=; b=Eec3SlzY3BohDq5VvsR1DjcTbxIaoqaddYO93OaA5zdvJNtRfjDTGpwFCg8ACtN8oYBPgF 9LdLvRPA2n+QockzjYy5+PyuKN98OxP7TXBH5ebovUrhJ/+Drqi/7ebJsNqmIeXO088jRI AwWwZUCsU4G4vwxG8RTrgMVOVYlDG1A= X-MC-Unique: FgTfUTaJOtK39XafpBELmQ-1 From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH V4 10/10] vhost-vdpa: multiqueue support Date: Mon, 11 Oct 2021 12:28:29 +0800 Message-Id: <20211011042829.4159-11-jasowang@redhat.com> In-Reply-To: <20211011042829.4159-1-jasowang@redhat.com> References: <20211011042829.4159-1-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=jasowang@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.049, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eperezma@redhat.com, elic@nvidia.com, gdawar@xilinx.com, lingshan.zhu@intel.com, lulu@redhat.com 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: 1633926704691100001 Content-Type: text/plain; charset="utf-8" This patch implements the multiqueue support for vhost-vdpa. This is done simply by reading the number of queue pairs from the config space and initialize the datapath and control path net client. Signed-off-by: Jason Wang Message-Id: <20210907090322.1756-11-jasowang@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-vdpa.c | 2 +- net/vhost-vdpa.c | 105 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 97 insertions(+), 10 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 8587d30918..f9acfe9bdb 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -590,7 +590,7 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, = bool started) vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); } =20 - if (vhost_vdpa_one_time_request(dev)) { + if (dev->vq_index + dev->nvqs !=3D dev->last_index) { return 0; } =20 diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 834dab28dd..533b15ae8c 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -18,6 +18,7 @@ #include "qemu/error-report.h" #include "qemu/option.h" #include "qapi/error.h" +#include #include #include #include "standard-headers/linux/virtio_net.h" @@ -51,6 +52,14 @@ const int vdpa_feature_bits[] =3D { VIRTIO_NET_F_HOST_UFO, VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_MTU, + VIRTIO_NET_F_CTRL_RX, + VIRTIO_NET_F_CTRL_RX_EXTRA, + VIRTIO_NET_F_CTRL_VLAN, + VIRTIO_NET_F_GUEST_ANNOUNCE, + VIRTIO_NET_F_CTRL_MAC_ADDR, + VIRTIO_NET_F_RSS, + VIRTIO_NET_F_MQ, + VIRTIO_NET_F_CTRL_VQ, VIRTIO_F_IOMMU_PLATFORM, VIRTIO_F_RING_PACKED, VIRTIO_NET_F_RSS, @@ -81,7 +90,8 @@ static int vhost_vdpa_net_check_device_id(struct vhost_ne= t *net) return ret; } =20 -static int vhost_vdpa_add(NetClientState *ncs, void *be) +static int vhost_vdpa_add(NetClientState *ncs, void *be, + int queue_pair_index, int nvqs) { VhostNetOptions options; struct vhost_net *net =3D NULL; @@ -94,7 +104,7 @@ static int vhost_vdpa_add(NetClientState *ncs, void *be) options.net_backend =3D ncs; options.opaque =3D be; options.busyloop_timeout =3D 0; - options.nvqs =3D 2; + options.nvqs =3D nvqs; =20 net =3D vhost_net_init(&options); if (!net) { @@ -158,18 +168,28 @@ static NetClientInfo net_vhost_vdpa_info =3D { static NetClientState *net_vhost_vdpa_init(NetClientState *peer, const char *device, const char *name, - int vdpa_device_fd) + int vdpa_device_fd, + int queue_pair_index, + int nvqs, + bool is_datapath) { NetClientState *nc =3D NULL; VhostVDPAState *s; int ret =3D 0; assert(name); - nc =3D qemu_new_net_client(&net_vhost_vdpa_info, peer, device, name); + if (is_datapath) { + nc =3D qemu_new_net_client(&net_vhost_vdpa_info, peer, device, + name); + } else { + nc =3D qemu_new_net_control_client(&net_vhost_vdpa_info, peer, + device, name); + } snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA); s =3D DO_UPCAST(VhostVDPAState, nc, nc); =20 s->vhost_vdpa.device_fd =3D vdpa_device_fd; - ret =3D vhost_vdpa_add(nc, (void *)&s->vhost_vdpa); + s->vhost_vdpa.index =3D queue_pair_index; + ret =3D vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, queue_pair_index, n= vqs); if (ret) { qemu_del_net_client(nc); return NULL; @@ -195,12 +215,52 @@ static int net_vhost_check_net(void *opaque, QemuOpts= *opts, Error **errp) return 0; } =20 +static int vhost_vdpa_get_max_queue_pairs(int fd, int *has_cvq, Error **er= rp) +{ + unsigned long config_size =3D offsetof(struct vhost_vdpa_config, buf); + struct vhost_vdpa_config *config; + __virtio16 *max_queue_pairs; + uint64_t features; + int ret; + + 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 { + *has_cvq =3D 0; + } + + if (features & (1 << VIRTIO_NET_F_MQ)) { + config =3D g_malloc0(config_size + sizeof(*max_queue_pairs)); + config->off =3D offsetof(struct virtio_net_config, max_virtqueue_p= airs); + config->len =3D sizeof(*max_queue_pairs); + + ret =3D ioctl(fd, VHOST_VDPA_GET_CONFIG, config); + if (ret) { + error_setg(errp, "Fail to get config from vhost-vDPA device"); + return -ret; + } + + max_queue_pairs =3D (__virtio16 *)&config->buf; + + return lduw_le_p(max_queue_pairs); + } + + return 1; +} + int net_init_vhost_vdpa(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { const NetdevVhostVDPAOptions *opts; int vdpa_device_fd; - NetClientState *nc; + NetClientState **ncs, *nc; + int queue_pairs, i, has_cvq =3D 0; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); opts =3D &netdev->u.vhost_vdpa; @@ -215,11 +275,38 @@ int net_init_vhost_vdpa(const Netdev *netdev, const c= har *name, return -errno; } =20 - nc =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, vdpa_device_fd= ); - if (!nc) { + queue_pairs =3D vhost_vdpa_get_max_queue_pairs(vdpa_device_fd, + &has_cvq, errp); + if (queue_pairs < 0) { qemu_close(vdpa_device_fd); - return -1; + return queue_pairs; + } + + ncs =3D g_malloc0(sizeof(*ncs) * queue_pairs); + + 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); + if (!ncs[i]) + goto err; + } + + if (has_cvq) { + nc =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, + vdpa_device_fd, i, 1, false); + if (!nc) + goto err; } =20 + g_free(ncs); return 0; + +err: + if (i) { + qemu_del_net_client(ncs[0]); + } + qemu_close(vdpa_device_fd); + g_free(ncs); + + return -1; } --=20 2.25.1