From nobody Fri May 17 01:43:40 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 16255604466471004.5412499539901; Tue, 6 Jul 2021 01:34:06 -0700 (PDT) Received: from localhost ([::1]:34340 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0gWr-0003KC-Br for importer@patchew.org; Tue, 06 Jul 2021 04:34:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gQg-0000HW-5J for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:27:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33773) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gQe-0002Gj-Ag for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:27:41 -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-363-rIV5--T8MZyxhrDNRrWz8A-1; Tue, 06 Jul 2021 04:27:36 -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 4EEAE800C78; Tue, 6 Jul 2021 08:27:35 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-227.pek2.redhat.com [10.72.13.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4816517A70; Tue, 6 Jul 2021 08:27:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625560059; 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=RYA+bLP1tB1tTVpsuCIJkBogfKNlEByEsYMNQdKmpdo=; b=SBTiw8TXwPV7neeKYAgPkGjIx9MStoDJX0DnEzhzIhv50yYf6qwoiyawVrqi4bofoDndpe zSV4r+OUHto/lLuKT4gmvfUghTB/FxQqdOixMF2HtxlObaxQQFyJUak0tVVsQ+f+TNwQUm Jje+dPSZby6dGsl7ycHowNpzfYGFNiQ= X-MC-Unique: rIV5--T8MZyxhrDNRrWz8A-1 From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH V2 01/18] vhost_net: remove the meaningless assignment in vhost_net_start_one() Date: Tue, 6 Jul 2021 16:27:00 +0800 Message-Id: <20210706082717.37730-2-jasowang@redhat.com> In-Reply-To: <20210706082717.37730-1-jasowang@redhat.com> References: <20210706082717.37730-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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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, 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: 1625560451709100001 Content-Type: text/plain; charset="utf-8" The nvqs and vqs have been initialized during vhost_net_init() and are not expected to change during the life cycle of vhost_net structure. So this patch removes the meaningless assignment. Reviewed-by: Eli Cohen Signed-off-by: Jason Wang --- hw/net/vhost_net.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 44c1ed92dc..6bd4184f96 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -238,9 +238,6 @@ static int vhost_net_start_one(struct vhost_net *net, struct vhost_vring_file file =3D { }; int r; =20 - net->dev.nvqs =3D 2; - net->dev.vqs =3D net->vqs; - r =3D vhost_dev_enable_notifiers(&net->dev, dev); if (r < 0) { goto fail_notifiers; --=20 2.25.1 From nobody Fri May 17 01:43:40 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 162556016440049.169598429926054; Tue, 6 Jul 2021 01:29:24 -0700 (PDT) Received: from localhost ([::1]:49532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0gSJ-00031z-CC for importer@patchew.org; Tue, 06 Jul 2021 04:29:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gQl-0000Qh-Mi for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:27:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58693) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gQk-0002L4-9x for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:27: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-320-y9RQryhtPC22t4efw9dsJQ-1; Tue, 06 Jul 2021 04:27:44 -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 5C7EA8042DE; Tue, 6 Jul 2021 08:27:43 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-227.pek2.redhat.com [10.72.13.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id E28EB17A70; Tue, 6 Jul 2021 08:27:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625560065; 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=gSTJBPr6UM63ioAD0oqAL25AThxT6oTpICl37X7DpL4=; b=GSrSsXY4x1uroiM24dv1U1YOqNbmUIdFC3YrekEeKXjdXNL3pKNN2m+nyYuikH10IHVBut onzx02YfH7qcDdmFcymaDylRTtbSWixI5V9jIo7vaijDrphNVHdynaPy94iImwGfSWN5u2 bMXrzL3f2rY4XrMR9FSdsOso9B9UOiw= X-MC-Unique: y9RQryhtPC22t4efw9dsJQ-1 From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH V2 02/18] vhost: use unsigned int for nvqs Date: Tue, 6 Jul 2021 16:27:01 +0800 Message-Id: <20210706082717.37730-3-jasowang@redhat.com> In-Reply-To: <20210706082717.37730-1-jasowang@redhat.com> References: <20210706082717.37730-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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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, 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: 1625560171153100001 Content-Type: text/plain; charset="utf-8" Switch to use unsigned int for nvqs since it's not expected to be negative. Reviewed-by: Eli Cohen Signed-off-by: Jason Wang --- include/hw/virtio/vhost.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 21a9a52088..ddd7d3d594 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -71,7 +71,7 @@ struct vhost_dev { int n_tmp_sections; MemoryRegionSection *tmp_sections; struct vhost_virtqueue *vqs; - int nvqs; + unsigned int nvqs; /* the first virtqueue which would be used by this vhost dev */ int vq_index; /* if non-zero, minimum required value for max_queues */ --=20 2.25.1 From nobody Fri May 17 01:43:40 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 1625560170193643.1492140947113; Tue, 6 Jul 2021 01:29:30 -0700 (PDT) Received: from localhost ([::1]:50034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0gSO-0003Mf-VK for importer@patchew.org; Tue, 06 Jul 2021 04:29:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51952) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gQv-0000b8-2d for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:27:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54544) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gQr-0002RX-Lz for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:27:56 -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-564-71U-o1T-NKaqtQv5tdbwHg-1; Tue, 06 Jul 2021 04:27:50 -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 1040E804140; Tue, 6 Jul 2021 08:27:50 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-227.pek2.redhat.com [10.72.13.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id DAEF217A70; Tue, 6 Jul 2021 08:27:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625560072; 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=Ek+SnP6fIW2ioRQvHeuFLz3SOU2GMt+tteBrExyNrEQ=; b=AbWfgdCqZKMre2RLonUR8fFjyjmMDVIdEjff86XRiMvo9MKi5otvK3yzgPQGHEDMSpxn1i itxITUkpYJqx5HkddqxwQJiC3TWHcW7t49SIZ+0BcE+X9sXWOBNXkpEfCoQoP5FhvtDf2Y 4Qh8yQBph4yVGcojGIXwGFssivn1lck= X-MC-Unique: 71U-o1T-NKaqtQv5tdbwHg-1 From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH V2 03/18] vhost_net: do not assume nvqs is always 2 Date: Tue, 6 Jul 2021 16:27:02 +0800 Message-Id: <20210706082717.37730-4-jasowang@redhat.com> In-Reply-To: <20210706082717.37730-1-jasowang@redhat.com> References: <20210706082717.37730-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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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, lingshan.zhu@intel.com, lulu@redhat.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: 1625560175289100001 Content-Type: text/plain; charset="utf-8" This patch switches to initialize dev.nvqs from the VhostNetOptions instead of assuming it was 2. This is useful for implementing control virtqueue support which will be a single vhost_net structure with a single cvq. Note that nvqs is still set to 2 for all users and this patch does not change functionality. Reviewed-by: Stefano Garzarella Reviewed-by: Eli Cohen Signed-off-by: Jason Wang --- hw/net/vhost_net.c | 2 +- include/net/vhost_net.h | 1 + net/tap.c | 1 + net/vhost-user.c | 1 + net/vhost-vdpa.c | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 6bd4184f96..ef1370bd92 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -163,9 +163,9 @@ struct vhost_net *vhost_net_init(VhostNetOptions *optio= ns) goto fail; } net->nc =3D options->net_backend; + net->dev.nvqs =3D options->nvqs; =20 net->dev.max_queues =3D 1; - net->dev.nvqs =3D 2; net->dev.vqs =3D net->vqs; =20 if (backend_kernel) { diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 172b0051d8..fba40cf695 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -14,6 +14,7 @@ typedef struct VhostNetOptions { VhostBackendType backend_type; NetClientState *net_backend; uint32_t busyloop_timeout; + unsigned int nvqs; void *opaque; } VhostNetOptions; =20 diff --git a/net/tap.c b/net/tap.c index f5686bbf77..f716be3e3f 100644 --- a/net/tap.c +++ b/net/tap.c @@ -749,6 +749,7 @@ static void net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, qemu_set_nonblock(vhostfd); } options.opaque =3D (void *)(uintptr_t)vhostfd; + options.nvqs =3D 2; =20 s->vhost_net =3D vhost_net_init(&options); if (!s->vhost_net) { diff --git a/net/vhost-user.c b/net/vhost-user.c index ffbd94d944..b93918c5a4 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -85,6 +85,7 @@ static int vhost_user_start(int queues, NetClientState *n= cs[], options.net_backend =3D ncs[i]; options.opaque =3D be; options.busyloop_timeout =3D 0; + options.nvqs =3D 2; net =3D vhost_net_init(&options); if (!net) { error_report("failed to init vhost_net for queue %d", i); diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 19187dce8c..18b45ad777 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -105,6 +105,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; =20 net =3D vhost_net_init(&options); if (!net) { --=20 2.25.1 From nobody Fri May 17 01:43:40 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 1625560171929935.348512192451; Tue, 6 Jul 2021 01:29:31 -0700 (PDT) Received: from localhost ([::1]:50094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0gSP-0003PQ-G1 for importer@patchew.org; Tue, 06 Jul 2021 04:29:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51956) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gQx-0000bw-Iy for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47236) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gQt-0002Sm-Ju for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:27:59 -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-264-NHc7orFBPJCRzEC4nZiUzA-1; Tue, 06 Jul 2021 04:27:53 -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 0B39310C1ADC; Tue, 6 Jul 2021 08:27:53 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-227.pek2.redhat.com [10.72.13.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 834E117A70; Tue, 6 Jul 2021 08:27:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625560075; 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=8E3Wd714SALkWip6jUvfGkGqyQli2l3JcU3kzo+ApwE=; b=d287I8WG5k/1/sZGtcaUQ2rGQEU2W5q6okvutfftUvJCdB7mKGmikxr33907gwoQPGE8gv nqhTTsndPg4kaLw5eA5RHHWGJa/LvRGqqcBXEoSw+eGed0zW4f9dpMA+vONo0q43svx+0s VyrDA6llvAEe4A5s+Qh9DLlYiViKeQY= X-MC-Unique: NHc7orFBPJCRzEC4nZiUzA-1 From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH V2 04/18] vhost-vdpa: remove the unnecessary check in vhost_vdpa_add() Date: Tue, 6 Jul 2021 16:27:03 +0800 Message-Id: <20210706082717.37730-5-jasowang@redhat.com> In-Reply-To: <20210706082717.37730-1-jasowang@redhat.com> References: <20210706082717.37730-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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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, 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: 1625560178970100001 Content-Type: text/plain; charset="utf-8" The VhostVDPAState is just allocated by qemu_new_net_client() via g_malloc0() in net_vhost_vdpa_init(). So s->vhost_net is NULL for sure, let's remove this unnecessary check in vhost_vdpa_add(). Signed-off-by: Jason Wang --- net/vhost-vdpa.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 18b45ad777..728e63ff54 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -112,10 +112,6 @@ static int vhost_vdpa_add(NetClientState *ncs, void *b= e) error_report("failed to init vhost_net for queue"); goto err; } - if (s->vhost_net) { - vhost_net_cleanup(s->vhost_net); - g_free(s->vhost_net); - } s->vhost_net =3D net; ret =3D vhost_vdpa_net_check_device_id(net); if (ret) { --=20 2.25.1 From nobody Fri May 17 01:43:40 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 162556038779960.21812268129486; Tue, 6 Jul 2021 01:33:07 -0700 (PDT) Received: from localhost ([::1]:58756 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0gVu-0000oB-LJ for importer@patchew.org; Tue, 06 Jul 2021 04:33:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52022) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gR8-0000hB-K9 for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52542) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gR5-0002Wv-8F for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:10 -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-83-1ZnYBLr-PpiJVPqyEyimcg-1; Tue, 06 Jul 2021 04:28:03 -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 502FA10C1ADC; Tue, 6 Jul 2021 08:27:56 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-227.pek2.redhat.com [10.72.13.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BC7317A70; Tue, 6 Jul 2021 08:27:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625560084; 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=cU9ZDMaXNVuHgqJBXyphTysFWQ+IRY5NTt7bdDrWhco=; b=SzxcMIwKujuGG3U8U1Jgh+37qJM94AsUlgVdkR2NWNbIBMXqH1WY7lG2p50ufEKTr0BkwA zxOb3wqvQ+wtfuXPmxcBhMSgk2zcEOCcWX1+YCIWivm/chVzndN1SiXX8SeqpjrU7pMqzg lZ8ce+dwfUNunGxrCcSOiHgS3tfxsEQ= X-MC-Unique: 1ZnYBLr-PpiJVPqyEyimcg-1 From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH V2 05/18] vhost-vdpa: don't cleanup twice in vhost_vdpa_add() Date: Tue, 6 Jul 2021 16:27:04 +0800 Message-Id: <20210706082717.37730-6-jasowang@redhat.com> In-Reply-To: <20210706082717.37730-1-jasowang@redhat.com> References: <20210706082717.37730-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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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, lingshan.zhu@intel.com, lulu@redhat.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: 1625560395460100001 Content-Type: text/plain; charset="utf-8" The previous vhost_net_cleanup is sufficient for freeing, calling vhost_vdpa_del() in this case will lead an extra round of free. Note that this kind of "double free" is safe since vhost_dev_cleanup() zero the whole structure. Reviewed-by: Stefano Garzarella Signed-off-by: Jason Wang --- net/vhost-vdpa.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 728e63ff54..f5689a7c32 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -82,16 +82,6 @@ static int vhost_vdpa_net_check_device_id(struct vhost_n= et *net) return ret; } =20 -static void vhost_vdpa_del(NetClientState *ncs) -{ - VhostVDPAState *s; - assert(ncs->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); - s =3D DO_UPCAST(VhostVDPAState, nc, ncs); - if (s->vhost_net) { - vhost_net_cleanup(s->vhost_net); - } -} - static int vhost_vdpa_add(NetClientState *ncs, void *be) { VhostNetOptions options; @@ -122,7 +112,6 @@ err: if (net) { vhost_net_cleanup(net); } - vhost_vdpa_del(ncs); return -1; } =20 --=20 2.25.1 From nobody Fri May 17 01:43:40 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 1625560376646493.0798473603933; Tue, 6 Jul 2021 01:32:56 -0700 (PDT) Received: from localhost ([::1]:57972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0gVi-0000H7-Nb for importer@patchew.org; Tue, 06 Jul 2021 04:32:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52000) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gR5-0000es-GP for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24663) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gR1-0002Vc-1l for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:07 -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-398-HoSrMN2QNyy9EGl_X2Dk4Q-1; Tue, 06 Jul 2021 04:28:00 -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 C1E5B804162; Tue, 6 Jul 2021 08:27:59 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-227.pek2.redhat.com [10.72.13.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF9332EB19; Tue, 6 Jul 2021 08:27:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625560082; 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=t8qVXCQUoBb2lESdhfA0O4cSFxIWgx1/OJM3QkPo2/k=; b=Bnj98sfc0Wa3MEZ6Xac1W9A5Q1f1CBx1F7rigSF8xc+vE6A6vlkCm+eqSu/hRHA5UgiGRn QOceYKL8/Gqtx5v8an04lxpvrnQhPJw7AOQsc8WOjh7O7KRdMol3g8t1+LAssJfNU25hrA EJLt6Clc9LCvSzMJW1VBoTdPclvxADE= X-MC-Unique: HoSrMN2QNyy9EGl_X2Dk4Q-1 From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH V2 06/18] vhost-vdpa: fix leaking of vhost_net in vhost_vdpa_add() Date: Tue, 6 Jul 2021 16:27:05 +0800 Message-Id: <20210706082717.37730-7-jasowang@redhat.com> In-Reply-To: <20210706082717.37730-1-jasowang@redhat.com> References: <20210706082717.37730-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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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, lingshan.zhu@intel.com, lulu@redhat.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: 1625560383410100001 Content-Type: text/plain; charset="utf-8" Fixes: 1e0a84ea49b68 ("vhost-vdpa: introduce vhost-vdpa net client") Reviewed-by: Stefano Garzarella Signed-off-by: Jason Wang --- net/vhost-vdpa.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index f5689a7c32..21f09c546f 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -111,6 +111,7 @@ static int vhost_vdpa_add(NetClientState *ncs, void *be) err: if (net) { vhost_net_cleanup(net); + g_free(net); } return -1; } --=20 2.25.1 From nobody Fri May 17 01:43:40 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 1625560505294903.0423391513601; Tue, 6 Jul 2021 01:35:05 -0700 (PDT) Received: from localhost ([::1]:38346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0gXo-0005xR-4v for importer@patchew.org; Tue, 06 Jul 2021 04:35:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52024) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRA-0000ji-1w for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58090) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gR6-0002YM-Nu for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:11 -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-5-9BwKFCczOZmtR_w9Qs_CCQ-1; Tue, 06 Jul 2021 04:28:04 -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 D4A981023F51; Tue, 6 Jul 2021 08:28:02 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-227.pek2.redhat.com [10.72.13.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FD9C17A70; Tue, 6 Jul 2021 08:28:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625560087; 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=vHHcPpl9D02xWNusNPR+J6jEeGdfuSuBQZqOzMXGjUc=; b=O1ZaAKND1W5LPhj9errCn0zEGquHv3SL9Kfu7L9iHLfonlOlRJtfDXYiQupwRbBCKHPHEP lxOnN0q+jvnRoflO713bTQOVMUwBLsKXo0XEGNez92h0/opEODeAwPNSjz5Y5ayxGZImXo R53fKakjvYNRpI+oYLa3hZdijVQNct8= X-MC-Unique: 9BwKFCczOZmtR_w9Qs_CCQ-1 From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH V2 07/18] vhost-vdpa: tweak the error label in vhost_vdpa_add() Date: Tue, 6 Jul 2021 16:27:06 +0800 Message-Id: <20210706082717.37730-8-jasowang@redhat.com> In-Reply-To: <20210706082717.37730-1-jasowang@redhat.com> References: <20210706082717.37730-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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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, 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: 1625560510062100001 Content-Type: text/plain; charset="utf-8" Introduce new error label to avoid the unnecessary checking of net pointer. Fixes: 1e0a84ea49b68 ("vhost-vdpa: introduce vhost-vdpa net client") Signed-off-by: Jason Wang --- net/vhost-vdpa.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 21f09c546f..0da7bc347a 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -100,19 +100,18 @@ static int vhost_vdpa_add(NetClientState *ncs, void *= be) net =3D vhost_net_init(&options); if (!net) { error_report("failed to init vhost_net for queue"); - goto err; + goto err_init; } s->vhost_net =3D net; ret =3D vhost_vdpa_net_check_device_id(net); if (ret) { - goto err; + goto err_check; } return 0; -err: - if (net) { - vhost_net_cleanup(net); - g_free(net); - } +err_check: + vhost_net_cleanup(net); + g_free(net); +err_init: return -1; } =20 --=20 2.25.1 From nobody Fri May 17 01:43:40 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 1625560523717737.0721030241596; Tue, 6 Jul 2021 01:35:23 -0700 (PDT) Received: from localhost ([::1]:39078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0gY6-0006Qa-BR for importer@patchew.org; Tue, 06 Jul 2021 04:35:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52036) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRD-0000u1-6X for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26533) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRB-0002bI-BO for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:14 -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-46-raDTfrfsMZWeprYyML2L_Q-1; Tue, 06 Jul 2021 04:28:11 -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 A0AF0CC625; Tue, 6 Jul 2021 08:28:10 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-227.pek2.redhat.com [10.72.13.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6060817A70; Tue, 6 Jul 2021 08:28:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625560092; 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=r9ltyuF4wPH6rf+C5SqLgdze6BpigoWp2wRQhta/zwc=; b=XyZCqevju4BpNOY/MmWYJxIQxf8g1KDk/Vq4pNap2AUHyko0O/CWDnSQxvFt0s5uoZuY4O IpjNuenMPlNZGrpfCGt0aZb+4YnQyY5rkaZxvV529QdrxJSCCPBADfK2Zak3Mee3E989sn qPINrKVp6ZIaucNn2xUaXMITj3J4wTk= X-MC-Unique: raDTfrfsMZWeprYyML2L_Q-1 From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH V2 08/18] vhost-vdpa: fix the wrong assertion in vhost_vdpa_init() Date: Tue, 6 Jul 2021 16:27:07 +0800 Message-Id: <20210706082717.37730-9-jasowang@redhat.com> In-Reply-To: <20210706082717.37730-1-jasowang@redhat.com> References: <20210706082717.37730-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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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, lingshan.zhu@intel.com, lulu@redhat.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: 1625560530839100001 Content-Type: text/plain; charset="utf-8" Vhost_vdpa_add() can fail for various reasons, so the assertion of the succeed is wrong. Instead, we should free the NetClientState and propagate the error to the caller Reviewed-by: Stefano Garzarella Signed-off-by: Jason Wang --- net/vhost-vdpa.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 0da7bc347a..87b181a74e 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -174,7 +174,10 @@ static int net_vhost_vdpa_init(NetClientState *peer, c= onst char *device, } s->vhost_vdpa.device_fd =3D vdpa_device_fd; ret =3D vhost_vdpa_add(nc, (void *)&s->vhost_vdpa); - assert(s->vhost_net); + if (ret) { + qemu_close(vdpa_device_fd); + qemu_del_net_client(nc); + } return ret; } =20 --=20 2.25.1 From nobody Fri May 17 01:43:40 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 1625560674062770.6087110063227; Tue, 6 Jul 2021 01:37:54 -0700 (PDT) Received: from localhost ([::1]:47632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0gaW-0003jh-SS for importer@patchew.org; Tue, 06 Jul 2021 04:37:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52068) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRJ-0001Hi-9b for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33758) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRG-0002ft-Qn for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:20 -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-530-3rtpNtObOVCIfk32aesemw-1; Tue, 06 Jul 2021 04:28:14 -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 E611B804141; Tue, 6 Jul 2021 08:28:13 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-227.pek2.redhat.com [10.72.13.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C4D317A70; Tue, 6 Jul 2021 08:28:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625560098; 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=0alzCyXG1elRphQJui8YQayNTs9sIH1CfucytQi7ON8=; b=EBaWVEQabFmHEdvqAWtEDakWfp1v+pIh7rqdjOiWQHozAjwflTAYpi+dYBr1pygqC1xHKf rTrWK6uuRgz/QqjbUfsEJ+NU0YthFMi6QdstRuwmuXS1LbK8nOdAvUCIaIyA/VkW0wr9SB E2GksJec1QcG4TpyYkqAqryCnUC9AD4= X-MC-Unique: 3rtpNtObOVCIfk32aesemw-1 From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH V2 09/18] vhost-vdpa: remove the unncessary queue_index assignment Date: Tue, 6 Jul 2021 16:27:08 +0800 Message-Id: <20210706082717.37730-10-jasowang@redhat.com> In-Reply-To: <20210706082717.37730-1-jasowang@redhat.com> References: <20210706082717.37730-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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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, lingshan.zhu@intel.com, lulu@redhat.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: 1625560680532100003 Content-Type: text/plain; charset="utf-8" The queue_index of NetClientState should be assigned in set_netdev() afterwards, so trying to net_vhost_vdpa_init() is meaningless. This patch removes this. Reviewed-by: Stefano Garzarella Signed-off-by: Jason Wang --- net/vhost-vdpa.c | 1 - 1 file changed, 1 deletion(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 87b181a74e..572aed4ca2 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -166,7 +166,6 @@ static int net_vhost_vdpa_init(NetClientState *peer, co= nst char *device, 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); - nc->queue_index =3D 0; s =3D DO_UPCAST(VhostVDPAState, nc, nc); vdpa_device_fd =3D qemu_open_old(vhostdev, O_RDWR); if (vdpa_device_fd =3D=3D -1) { --=20 2.25.1 From nobody Fri May 17 01:43:40 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 1625560387329477.99174834831445; Tue, 6 Jul 2021 01:33:07 -0700 (PDT) Received: from localhost ([::1]:58726 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0gVu-0000mk-5u for importer@patchew.org; Tue, 06 Jul 2021 04:33:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52082) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRL-0001Q9-Oq for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37497) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRK-0002iQ-00 for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:23 -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-306-CpFsk0CDO1ihMOYSKmfpnw-1; Tue, 06 Jul 2021 04:28:18 -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 3E7361023F40; Tue, 6 Jul 2021 08:28:17 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-227.pek2.redhat.com [10.72.13.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 781D417A70; Tue, 6 Jul 2021 08:28:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625560101; 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=3xZnHbGSoAVma3cP5YhNKvf/EE3Mcnyc9Hzjg/33XMQ=; b=gV8dQDXqRk95h9YpUKxGOiTKZgruDB/6WlKjDNQw8CVzLBRlBe0dg8dHH2qeXzFlA3kMJB xAh3wm+yo8ElFNgAubqvH/FvhtwPvKsg1GlXo62O0th610fW8T1BbhQUY+FSoZKTG/Byl6 5WiOJ6AGw04HxnEyvfeL5umPvShG9Vo= X-MC-Unique: CpFsk0CDO1ihMOYSKmfpnw-1 From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH V2 10/18] vhost-vdpa: open device fd in net_init_vhost_vdpa() Date: Tue, 6 Jul 2021 16:27:09 +0800 Message-Id: <20210706082717.37730-11-jasowang@redhat.com> In-Reply-To: <20210706082717.37730-1-jasowang@redhat.com> References: <20210706082717.37730-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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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, lingshan.zhu@intel.com, lulu@redhat.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: 1625560392070100001 Content-Type: text/plain; charset="utf-8" This path 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 --- 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 572aed4ca2..e63a54a938 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -157,24 +157,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; @@ -202,6 +197,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; @@ -210,5 +206,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 Fri May 17 01:43:40 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 1625560524966877.9592621137149; Tue, 6 Jul 2021 01:35:24 -0700 (PDT) Received: from localhost ([::1]:39166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0gY7-0006Ti-RZ for importer@patchew.org; Tue, 06 Jul 2021 04:35:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52096) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRO-0001YW-Qg for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:49160) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRM-0002kP-Jy for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:26 -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-560-W3P6qhxfN8O20oYOnePLhA-1; Tue, 06 Jul 2021 04:28: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 CAA6A80414B; Tue, 6 Jul 2021 08:28:21 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-227.pek2.redhat.com [10.72.13.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF0312EB02; Tue, 6 Jul 2021 08:28:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625560103; 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=shcEXG3gu+2T2oEHp3T22USBb3RsSFNwczPeKopqVKA=; b=Thb45a3FfFGEHlN5gmSVnO6WS3XS/luu1M/HwAzc3ETbR8ENTGwrXh6b4nH+e1IobkxPkE 0kon9T25YlF9Ja9wEf/pmAyDrwAIl8KgHqPw+Y0tD0EJJ/o3/YHalnQHMIlLjRq6UpKJui ibdMGtXblUlHOqYcjaJqS/+a5PgYx+k= X-MC-Unique: W3P6qhxfN8O20oYOnePLhA-1 From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH V2 11/18] vhost-vdpa: classify one time request Date: Tue, 6 Jul 2021 16:27:10 +0800 Message-Id: <20210706082717.37730-12-jasowang@redhat.com> In-Reply-To: <20210706082717.37730-1-jasowang@redhat.com> References: <20210706082717.37730-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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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, 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: 1625560531173100003 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 --- hw/virtio/vhost-vdpa.c | 51 ++++++++++++++++++++++++++++++++-- include/hw/virtio/vhost-vdpa.h | 1 + 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 61ba313331..397f47bc11 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -265,6 +265,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) { struct vhost_vdpa *v; @@ -277,6 +284,10 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void= *opaque) 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 @@ -387,6 +398,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)) { @@ -410,6 +425,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; @@ -429,6 +449,10 @@ static int vhost_vdpa_set_backend_cap(struct vhost_dev= *dev) 0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH; int r; =20 + if (vhost_vdpa_one_time_request(dev)) { + return 0; + } + if (vhost_vdpa_call(dev, VHOST_GET_BACKEND_FEATURES, &features)) { return 0; } @@ -458,6 +482,10 @@ static int vhost_vdpa_reset_device(struct vhost_dev *d= ev) int ret; uint8_t status =3D 0; =20 + if (vhost_vdpa_one_time_request(dev)) { + return 0; + } + ret =3D vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &status); trace_vhost_vdpa_reset_device(dev, status); return ret; @@ -545,11 +573,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 @@ -558,7 +596,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; @@ -568,6 +605,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); @@ -633,6 +674,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 9188226d8b..e98e327f12 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; MemoryListener listener; struct vhost_dev *dev; --=20 2.25.1 From nobody Fri May 17 01:43:40 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 162556067774443.25619376092459; Tue, 6 Jul 2021 01:37:57 -0700 (PDT) Received: from localhost ([::1]:47802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0gaa-0003qK-AQ for importer@patchew.org; Tue, 06 Jul 2021 04:37:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52144) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRe-00020n-Qf for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50327) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRX-0002rk-RM for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:42 -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-437-5F31vBA4Ony4FotUZ3j0hQ-1; Tue, 06 Jul 2021 04:28:32 -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 11582100C662; Tue, 6 Jul 2021 08:28:31 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-227.pek2.redhat.com [10.72.13.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 566C22EB19; Tue, 6 Jul 2021 08:28:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625560115; 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=pXP1/MRyj5zK9Lbvt0np3BrCA2yl/wy9Hdc/ALz4QWg=; b=Xfacgm2MYdScJltRsQ5oqw6SfR+4awMnKnC5E51DuUYhbz+7HrinjwyRQ19WB9Y5aIVFOk jhHvdPnoeQDic5PEMcy4vnI/rI6sjx0LRpLbr9++11kL7AnZMSGed+7GyHE01Pwqp0fM1C heTofQhCyA/Afu3ug9P0WSqQM8ddIlg= X-MC-Unique: 5F31vBA4Ony4FotUZ3j0hQ-1 From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH V2 12/18] vhost-vdpa: prepare for the multiqueue support Date: Tue, 6 Jul 2021 16:27:11 +0800 Message-Id: <20210706082717.37730-13-jasowang@redhat.com> In-Reply-To: <20210706082717.37730-1-jasowang@redhat.com> References: <20210706082717.37730-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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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, 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: 1625560684546100001 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 --- 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 397f47bc11..e7e6b23108 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -495,8 +495,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 Fri May 17 01:43:40 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 1625560657065304.4381463610458; Tue, 6 Jul 2021 01:37:37 -0700 (PDT) Received: from localhost ([::1]:45990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0gaF-0002db-Ac for importer@patchew.org; Tue, 06 Jul 2021 04:37:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52132) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRd-0001yO-0L for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46303) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRZ-0002sS-1g for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:40 -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-227-Emt7f2bcMiipq2PAC8RAZA-1; Tue, 06 Jul 2021 04:28:35 -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 3BACF10C1ADC; Tue, 6 Jul 2021 08:28:34 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-227.pek2.redhat.com [10.72.13.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 921E62EB02; Tue, 6 Jul 2021 08:28:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625560116; 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=2v/6cYoMfoCiTZYXMcg5SJpP6eFFfJCxNj89FOlxEFM=; b=H60vcRAxDxsWCwK15G9ECQvWzAQtpHWhX+wz8Q0+oCRjVvh3acC749UvrjmP+CTa54uf53 VYPaxqixoE4hKEvxgIKgGP57Y9V8ZlDkyxiZLthUDs9LBWa458vMqPVP2WqPMPpa69tnB5 1YbS85LbEe+EULNdpln23WXcGjQUi20= X-MC-Unique: Emt7f2bcMiipq2PAC8RAZA-1 From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH V2 13/18] vhost-vdpa: let net_vhost_vdpa_init() returns NetClientState * Date: Tue, 6 Jul 2021 16:27:12 +0800 Message-Id: <20210706082717.37730-14-jasowang@redhat.com> In-Reply-To: <20210706082717.37730-1-jasowang@redhat.com> References: <20210706082717.37730-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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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, 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: 1625560664253100001 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 --- 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 e63a54a938..cc11b2ec40 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -156,8 +156,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; @@ -171,8 +173,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) @@ -197,7 +200,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; @@ -212,10 +216,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 Fri May 17 01:43:40 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 1625560668284100.10666079810824; Tue, 6 Jul 2021 01:37:48 -0700 (PDT) Received: from localhost ([::1]:47016 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0gaR-0003JE-6Y for importer@patchew.org; Tue, 06 Jul 2021 04:37:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52142) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRe-00020j-JZ for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40497) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRc-0002uw-9J for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:42 -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-539-GEui85HQOpujjBcdyu71lA-1; Tue, 06 Jul 2021 04:28:38 -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 705A1804141; Tue, 6 Jul 2021 08:28:37 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-227.pek2.redhat.com [10.72.13.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3F4017A70; Tue, 6 Jul 2021 08:28:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625560119; 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=QhYJ/O6+gxLZFzIcP8Sncd7pWbd0DQGZu9BeD+UIvJU=; b=e3nQf42yPMDqeaK/NzmTYQZ3OxwmZjwbwuYHl0CDdgG+zS2Xvm/urxOEyVcaltNcz2Psfs Xf9ajP+QwXGFwF1aRYD4EuMUdnbnlspUMTrEKYeGuIe5r6p/jnE8lsPzRLZSSFomkU3EoY ZFLcge1E92SasCLVTDQ7dyj+X38kfuQ= X-MC-Unique: GEui85HQOpujjBcdyu71lA-1 From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH V2 14/18] net: introduce control client Date: Tue, 6 Jul 2021 16:27:13 +0800 Message-Id: <20210706082717.37730-15-jasowang@redhat.com> In-Reply-To: <20210706082717.37730-1-jasowang@redhat.com> References: <20210706082717.37730-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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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, 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: 1625560673265100001 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 --- 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 76bbb7c31b..fcaf9c7715 100644 --- a/net/net.c +++ b/net/net.c @@ -237,7 +237,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); @@ -256,6 +257,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 @@ -270,7 +272,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; } @@ -295,7 +313,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 Fri May 17 01:43:40 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 1625560806561688.239076930814; Tue, 6 Jul 2021 01:40:06 -0700 (PDT) Received: from localhost ([::1]:56188 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0gcf-0000vY-Av for importer@patchew.org; Tue, 06 Jul 2021 04:40:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52170) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRi-00028W-B6 for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24399) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRg-0002x6-4e for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:46 -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-518-qavr-eD3O0mgMLocFv8WaA-1; Tue, 06 Jul 2021 04:28:41 -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 84B23CC621; Tue, 6 Jul 2021 08:28:40 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-227.pek2.redhat.com [10.72.13.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id F06E1E2C0; Tue, 6 Jul 2021 08:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625560123; 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=/3/hczp8BppvusqQsFiKpipwkcWGSGfW8GclV7N4LTA=; b=e/rCvaqfeoQSZFMFn8PUXHcmFd03/jTZreaaUwkPvm1dvboGtjB5/U/EuLLFSEiT3fKD52 RO0I+ENg8ifruQ9s1Jj/RNcrwwxMolWkgaxVQd+MpbzU1q1AUA0BqZwAh4PAQES9nT1u1v pk+mK99tqqh8tfLJIMifok0PfTWTWWE= X-MC-Unique: qavr-eD3O0mgMLocFv8WaA-1 From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH V2 15/18] vhost-net: control virtqueue support Date: Tue, 6 Jul 2021 16:27:14 +0800 Message-Id: <20210706082717.37730-16-jasowang@redhat.com> In-Reply-To: <20210706082717.37730-1-jasowang@redhat.com> References: <20210706082717.37730-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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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, 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: 1625560810728100001 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 --- hw/net/vhost_net.c | 43 ++++++++++++++++++++++++++++++----------- hw/net/virtio-net.c | 4 ++-- include/net/vhost_net.h | 6 ++++-- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index ef1370bd92..4294fb9fc9 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -311,11 +311,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_qps, 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_qps * 2 + cvq; + VirtIONet *n =3D VIRTIO_NET(dev); + int nvhosts =3D data_qps + cvq; struct vhost_net *net; int r, e, i; NetClientState *peer; @@ -325,9 +328,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_qps) { + 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 @@ -340,14 +348,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_qps) { + 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) { @@ -371,7 +383,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); @@ -381,18 +393,27 @@ err: } =20 void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs, - int total_queues) + int data_qps, 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_qps * 2 + cvq; + int nvhosts =3D data_qps + 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_qps) { + 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 bd7958b9f0..614660274c 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..e656e38af9 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_qps, int cvq); +void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs, + int data_qps, int cvq); =20 void vhost_net_cleanup(VHostNetState *net); =20 --=20 2.25.1 From nobody Fri May 17 01:43:40 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 1625560921289356.2067440430659; Tue, 6 Jul 2021 01:42:01 -0700 (PDT) Received: from localhost ([::1]:32858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0geV-0004Fx-T4 for importer@patchew.org; Tue, 06 Jul 2021 04:41:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52204) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRq-0002c7-PE for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRk-0002zx-5G for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:54 -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-382-Q9JAlv--OSev53SY0sXsbg-1; Tue, 06 Jul 2021 04:28:44 -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 B0E4D804140; Tue, 6 Jul 2021 08:28:43 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-227.pek2.redhat.com [10.72.13.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 119541700F; Tue, 6 Jul 2021 08:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625560127; 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=HxnYRsuc19giuJb2dJvcsGHDCEzUXJLuE/Novp9Zpp8=; b=cXDDafA236BEMMWT5vt9KxQVrPVKjgCLjmcvVOhdtba7baiIFnzWlFfVjbFP7QLV6I8StU YlTJ1JHKrXO7hfhT0ImCXg750savbxsk4LpLx6PZDlogaMGtkOD7UrnoARbirjKMDRJbI/ KNH4/WlrbexWnpjBISqyLDWXS9fxK38= X-MC-Unique: Q9JAlv--OSev53SY0sXsbg-1 From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH V2 16/18] virito-net: use "qps" instead of "queues" when possible Date: Tue, 6 Jul 2021 16:27:15 +0800 Message-Id: <20210706082717.37730-17-jasowang@redhat.com> In-Reply-To: <20210706082717.37730-1-jasowang@redhat.com> References: <20210706082717.37730-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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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, 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: 1625560927764100001 Content-Type: text/plain; charset="utf-8" Most of the time, "queues" really means queue pairs. So this patch switch to use "qps" to avoid confusion. Signed-off-by: Jason Wang --- 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 4294fb9fc9..fe2fd7e3d5 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -333,7 +333,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *= ncs, if (i < data_qps) { 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_qps); } =20 net =3D get_vhost_net(peer); @@ -358,7 +358,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *= ncs, if (i < data_qps) { 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_qps); } r =3D vhost_net_start_one(get_vhost_net(peer), dev); =20 @@ -408,7 +408,7 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState *= ncs, if (i < data_qps) { 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_qps); } vhost_net_stop_one(get_vhost_net(peer), dev); } diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 614660274c..36bd197087 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 qps; with virtio-1, guest can downsize */ #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_qps); 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 qps =3D n->multiqueue ? n->max_qps : 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 < qps; 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, qps, 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, qps, 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 qps, bool enable) { int i; =20 - for (i =3D 0; i < queues; i++) { + for (i =3D 0; i < qps; 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 qps =3D n->multiqueue ? n->max_qps : 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); + qps, true); } 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, qps, 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_qps; 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_qps) { 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_qps =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_qps; 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_qps; 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_qps =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_qps(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_qps; i++) { + if (i < n->curr_qps) { 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_qps; 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 qps, 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_qps) { 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 qps"; 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; + qps =3D do_rss ? virtio_lduw_p(vdev, &temp.us) : n->curr_qps; + if (qps =3D=3D 0 || qps > n->max_qps) { + err_msg =3D "Invalid number of qps"; + err_value =3D qps; 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 qps; } 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 qps; 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 qps; =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; + qps =3D virtio_net_handle_rss(n, iov, iov_cnt, false); + return qps ? 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); + qps =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); + qps =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 (qps < VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN || + qps > VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX || + qps > n->max_qps || !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_qps =3D qps; + /* stop the backend before changing the number of qps to avoid handlin= g a * disabled queue */ virtio_net_set_status(vdev, vdev->status); - virtio_net_set_queues(n); + virtio_net_set_qps(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_qps) { return false; } =20 @@ -2753,11 +2753,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_qps(VirtIONet *n, int new_max_qps) { 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_qps * 2 + 1; int i; =20 assert(old_num_queues >=3D 3); @@ -2790,12 +2790,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_qps : 1; =20 n->multiqueue =3D multiqueue; - virtio_net_change_num_queues(n, max); + virtio_net_change_num_qps(n, max); =20 - virtio_net_set_queues(n); + virtio_net_set_qps(n); } =20 static int virtio_net_post_load_device(void *opaque, int version_id) @@ -2828,7 +2828,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_qps(n); =20 /* Find the first multicast entry in the saved MAC filter */ for (i =3D 0; i < n->mac_table.in_use; i++) { @@ -2841,7 +2841,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_qps; i++) { qemu_get_subqueue(n->nic, i)->link_down =3D link_down; } =20 @@ -2906,9 +2906,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_qps_gt_1(void *opaque, int version_id) { - return VIRTIO_NET(opaque)->max_queues > 1; + return VIRTIO_NET(opaque)->max_qps > 1; } =20 static bool has_ctrl_guest_offloads(void *opaque, int version_id) @@ -2933,13 +2933,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_qps_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 qps 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. */ @@ -2949,9 +2949,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_qps_1 =3D tmp->parent->curr_qps - 1; + if (tmp->parent->curr_qps =3D=3D 0) { + tmp->curr_qps_1 =3D 0; } =20 return 0; @@ -2964,9 +2964,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_qps > tmp->parent->max_qps) { + error_report("virtio-net: curr_qps %x > max_qps %x", + tmp->parent->curr_qps, tmp->parent->max_qps); =20 return -EINVAL; } @@ -2980,7 +2980,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_qps_1, vmstate_virtio_net_queue_tx_waiting, struct VirtIONetQueue), VMSTATE_END_OF_LIST() @@ -3122,9 +3122,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_qps, VirtIONet, max_qps_gt_1, 0, vmstate_info_uint16_equal, uint16_t), - VMSTATE_UINT16_TEST(curr_queues, VirtIONet, max_queues_gt_1), + VMSTATE_UINT16_TEST(curr_qps, VirtIONet, max_qps_gt_1), VMSTATE_WITH_TMP(VirtIONet, struct VirtIONetMigTmp, vmstate_virtio_net_tx_waiting), VMSTATE_UINT64_TEST(curr_guest_offloads, VirtIONet, @@ -3367,16 +3367,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_qps =3D MAX(n->nic_conf.peers.queues, 1); + if (n->max_qps * 2 + 1 > VIRTIO_QUEUE_MAX) { + error_setg(errp, "Invalid number of qps (=3D %" PRIu32 "), " "must be a positive integer less than %d.", - n->max_queues, (VIRTIO_QUEUE_MAX - 1) / 2); + n->max_qps, (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_qps); + n->curr_qps =3D 1; n->tx_timeout =3D n->net_conf.txtimer; =20 if (n->net_conf.tx && strcmp(n->net_conf.tx, "timer") @@ -3390,7 +3390,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_qps; i++) { virtio_net_add_queue(n, i); } =20 @@ -3414,13 +3414,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_qps; 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_qps; i++) { qemu_using_vnet_hdr(qemu_get_subqueue(n->nic, i)->peer, true); } n->host_hdr_len =3D sizeof(struct virtio_net_hdr); @@ -3462,7 +3462,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_qps; =20 if (virtio_has_feature(n->host_features, VIRTIO_NET_F_RSS)) { virtio_net_unload_ebpf(n); @@ -3484,12 +3484,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_qps =3D n->multiqueue ? n->max_qps : 1; + for (i =3D 0; i < max_qps; i++) { virtio_net_del_queue(n, i); } /* delete also control vq */ - virtio_del_queue(vdev, max_queues * 2); + virtio_del_queue(vdev, max_qps * 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..a9b6dc252e 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_qps; + uint16_t curr_qps; size_t config_size; char *netclient_name; char *netclient_type; --=20 2.25.1 From nobody Fri May 17 01:43:40 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 1625560770412184.1338468969334; Tue, 6 Jul 2021 01:39:30 -0700 (PDT) Received: from localhost ([::1]:54272 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0gc3-00085X-5W for importer@patchew.org; Tue, 06 Jul 2021 04:39:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52206) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRs-0002hg-5B for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53905) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRo-00033T-UN for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:55 -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-372-U0GiZGjANmG3ipoZLeD50g-1; Tue, 06 Jul 2021 04:28:51 -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 38CAA100C661; Tue, 6 Jul 2021 08:28:50 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-227.pek2.redhat.com [10.72.13.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C12A2EB19; Tue, 6 Jul 2021 08:28:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625560132; 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=oJKBKdAaOavCFEs8ktlHnyZoxvvuEkTCPfF8ZHgd/9s=; b=S5MhGB7VmObMJn/zzSB8/0hr6bUby3UA+PNbPbQc9JKv4PYdQwykJYyxiFcf0suKsrJE38 b5v5glHvzMiGAmiJgmEmz3jwYg7SHy8xLn4X+TDv8+L2l0RV0Ob+07t4BbihV/f7Obfem5 6XnHLj0/3sXSPH39LKfVQflxtlQOeoU= X-MC-Unique: U0GiZGjANmG3ipoZLeD50g-1 From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH V2 17/18] virtio-net: vhost control virtqueue support Date: Tue, 6 Jul 2021 16:27:16 +0800 Message-Id: <20210706082717.37730-18-jasowang@redhat.com> In-Reply-To: <20210706082717.37730-1-jasowang@redhat.com> References: <20210706082717.37730-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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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, 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: 1625560775763100001 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 --- hw/net/virtio-net.c | 21 ++++++++++++++++++--- include/hw/virtio/virtio-net.h | 1 + 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 36bd197087..f003687579 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 qps =3D n->multiqueue ? n->max_qps : 1; + int cvq =3D n->max_ncs - n->max_qps; =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, qps, 0); + r =3D vhost_net_start(vdev, n->nic->ncs, qps, 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, qps, 0); + vhost_net_stop(vdev, n->nic->ncs, qps, cvq); n->vhost_started =3D 0; } } @@ -3367,7 +3368,21 @@ static void virtio_net_device_realize(DeviceState *d= ev, Error **errp) return; } =20 - n->max_qps =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_qps; + } + } + } + n->max_qps =3D MAX(n->max_qps, 1); + if (n->max_qps * 2 + 1 > VIRTIO_QUEUE_MAX) { error_setg(errp, "Invalid number of qps (=3D %" PRIu32 "), " "must be a positive integer less than %d.", diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index a9b6dc252e..ed4659c189 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -194,6 +194,7 @@ struct VirtIONet { NICConf nic_conf; DeviceState *qdev; int multiqueue; + uint16_t max_ncs; uint16_t max_qps; uint16_t curr_qps; size_t config_size; --=20 2.25.1 From nobody Fri May 17 01:43:40 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 1625560787351427.3250455087407; Tue, 6 Jul 2021 01:39:47 -0700 (PDT) Received: from localhost ([::1]:55870 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0gcM-0000jN-8P for importer@patchew.org; Tue, 06 Jul 2021 04:39:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52222) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRz-00035d-I5 for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:29:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59429) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRx-00039z-9D for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04: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-542-AI4m0MGlNhOEyYAujsjpgw-1; Tue, 06 Jul 2021 04:28:54 -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 678D0804140; Tue, 6 Jul 2021 08:28:53 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-227.pek2.redhat.com [10.72.13.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id B97472EB19; Tue, 6 Jul 2021 08:28:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625560140; 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=+ysYdL7xkz/8dJdysAt7gkNLr9hPSEVhMUOR1B+TLlE=; b=R7qSMnSXXrrz7siZm4e28p85yxTb11vGC2o5ZG2FLoGl2sWFDngphDZdGZ4ikeCR/lXvIU 6vhgxWAZSg8bzZNSp2Ci4NX9pVU/OnppGKjrg9qtStHfvzZYWm7C5BManlbZim2WGT006J 8b9AzE2COj3gYyM2HjWN1tDpYicB6x4= X-MC-Unique: AI4m0MGlNhOEyYAujsjpgw-1 From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH V2 18/18] vhost-vdpa: multiqueue support Date: Tue, 6 Jul 2021 16:27:17 +0800 Message-Id: <20210706082717.37730-19-jasowang@redhat.com> In-Reply-To: <20210706082717.37730-1-jasowang@redhat.com> References: <20210706082717.37730-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: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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, 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: 1625560792137100001 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 --- net/vhost-vdpa.c | 104 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 95 insertions(+), 9 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index cc11b2ec40..01a667deb9 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" @@ -52,6 +53,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, @@ -82,7 +91,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 qp_index, + int nvqs) { VhostNetOptions options; struct vhost_net *net =3D NULL; @@ -95,7 +105,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) { @@ -159,18 +169,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 qp_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 qp_index; + ret =3D vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, qp_index, nvqs); if (ret) { qemu_del_net_client(nc); return NULL; @@ -196,12 +216,52 @@ static int net_vhost_check_net(void *opaque, QemuOpts= *opts, Error **errp) return 0; } =20 +static int vhost_vdpa_get_max_qps(int fd, int *has_cvq, Error **errp) +{ + unsigned long config_size =3D offsetof(struct vhost_vdpa_config, buf); + struct vhost_vdpa_config *config; + __virtio16 *max_qps; + 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_qps)); + config->off =3D offsetof(struct virtio_net_config, max_virtqueue_p= airs); + config->len =3D sizeof(*max_qps); + + 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_qps =3D (__virtio16 *)&config->buf; + + return lduw_le_p(max_qps); + } + + 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 qps, i, has_cvq =3D 0; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); opts =3D &netdev->u.vhost_vdpa; @@ -216,11 +276,37 @@ 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) { + qps =3D vhost_vdpa_get_max_qps(vdpa_device_fd, &has_cvq, errp); + if (qps < 0) { qemu_close(vdpa_device_fd); - return -1; + return qps; + } + + ncs =3D g_malloc0(sizeof(*ncs) * qps); + + for (i =3D 0; i < qps; 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