From nobody Mon Apr 29 11:45:46 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 ARC-Seal: i=1; a=rsa-sha256; t=1592840395; cv=none; d=zohomail.com; s=zohoarc; b=dykhY0Tesf9QDztmynmVs/PikZGmX/bbNvUuAaJPH2yhMuL9W8BTX1s+pkE5wCBtMn3895PcUzl2O99HU433ePiVHx2I5j1bJNem0Zo4qrSfMQzgX/stinBbhWwOD4KSQQ5W60U8DRo1WoiZhC5HZKts9+SEcSihi9bQK65sl10= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592840395; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eEEu8ZsgVlYGREV/j3JuSlFoXTqZsrW+vsaLU2+dMmA=; b=nb5axAF3xHOyXYwnZ6lS3HIHV37FbdyKKKVQmiwPHAEj9lQa3mZCZPLWNaelv0aa2Nd/UuSNM30DfCjDgfNa0GxcX+eSEnHRefnDlNnCAMLRWZYS/TG+AUfYobaFnuVpZZkS7q/SoodhcKIXCmT8bByf1/k0Qv72s3QQfmdb7Og= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159284039538379.04122522644843; Mon, 22 Jun 2020 08:39:55 -0700 (PDT) Received: from localhost ([::1]:41940 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jnOY6-00068X-63 for importer@patchew.org; Mon, 22 Jun 2020 11:39:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58726) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jnOX4-0004s9-7G for qemu-devel@nongnu.org; Mon, 22 Jun 2020 11:38:50 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:55958 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jnOX2-0003Lc-6G for qemu-devel@nongnu.org; Mon, 22 Jun 2020 11:38:49 -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-174-L62nIV-gN7m1TjqrdHx0lw-1; Mon, 22 Jun 2020 11:38:45 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 05228805724; Mon, 22 Jun 2020 15:38:43 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-110.pek2.redhat.com [10.72.13.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E15A71679; Mon, 22 Jun 2020 15:38:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592840327; 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=eEEu8ZsgVlYGREV/j3JuSlFoXTqZsrW+vsaLU2+dMmA=; b=B5WfoBJmMRuE7zvD2FaFwlOYWVniC3f6FrIF142fDRCQEkgsV5mcuQVhyWfj/Qtq9TNcjt cxuyMHura24mDW2edH00XVaNaxEn0CqPZk0N1LF44nO1e6wrkXjuO/sHIgrc6DaLWta9nT TkAIvbGbexrTzJqiwJ3KXQwXowt3gHE= X-MC-Unique: L62nIV-gN7m1TjqrdHx0lw-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [PATCH v1 01/10] net: introduce qemu_get_peer Date: Mon, 22 Jun 2020 23:37:47 +0800 Message-Id: <20200622153756.19189-2-lulu@redhat.com> In-Reply-To: <20200622153756.19189-1-lulu@redhat.com> References: <20200622153756.19189-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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=205.139.110.61; envelope-from=lulu@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/22 03:17:49 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: mhabets@solarflare.com, qemu-devel@nongnu.org, rob.miller@broadcom.com, saugatm@xilinx.com, lulu@redhat.com, hanand@xilinx.com, hch@infradead.org, eperezma@redhat.com, jgg@mellanox.com, shahafs@mellanox.com, kevin.tian@intel.com, parav@mellanox.com, vmireyno@marvell.com, cunming.liang@intel.com, gdawar@xilinx.com, jiri@mellanox.com, xiao.w.wang@intel.com, stefanha@redhat.com, zhihong.wang@intel.com, aadam@redhat.com, rdunlap@infradead.org, maxime.coquelin@redhat.com, lingshan.zhu@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This is a small function that can get the peer from given NetClientState and queue_index Signed-off-by: Cindy Lu --- include/net/net.h | 1 + net/net.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 39085d9444..e7ef42d62b 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -176,6 +176,7 @@ void hmp_info_network(Monitor *mon, const QDict *qdict); void net_socket_rs_init(SocketReadState *rs, SocketReadStateFinalize *finalize, bool vnet_hdr); +NetClientState *qemu_get_peer(NetClientState *nc, int queue_index); =20 /* NIC info */ =20 diff --git a/net/net.c b/net/net.c index 38778e831d..599fb61028 100644 --- a/net/net.c +++ b/net/net.c @@ -324,6 +324,12 @@ void *qemu_get_nic_opaque(NetClientState *nc) =20 return nic->opaque; } +NetClientState *qemu_get_peer(NetClientState *nc, int queue_index) +{ + assert(nc !=3D NULL); + NetClientState *ncs =3D nc + queue_index; + return ncs->peer; +} =20 static void qemu_cleanup_net_client(NetClientState *nc) { --=20 2.21.1 From nobody Mon Apr 29 11:45:46 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 ARC-Seal: i=1; a=rsa-sha256; t=1592840457; cv=none; d=zohomail.com; s=zohoarc; b=brcB/D6Sdo4lmjZ4UrzxStQCd3WrRT6wGUBD20sVSR5I2p+6+ruJ9SFDbP/ZuVjRnC2CjWT5ZNL0uoq+8G6iordBS3ge7EdczA8C4SqugqRbOqVdIhwO5xqjYcbNudPwy/WJ/aSVkBtFqeLo4VstYeR7CsQlzFmHZgZ450carqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592840457; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6j1pA8flFXxKFgGD7KGcZegLUTAz9cG1BpLNQLqPNk0=; b=nq9vRewKDTwiyv+GdqWZksGh0KdFNwPcny8QKflYWONvaiKP2ngkMT3wqXD/nx9smuVV97DnLQv4NZhMd72gQBUGQHAvZHlB/KARoRjTVinFgXhWQI9JrVRDsIR09DZwozXKKIP8q0BVFFQRSGxDPCed9JkSsoU1I1Xh9zBtipk= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1592840457765636.2593947599885; Mon, 22 Jun 2020 08:40:57 -0700 (PDT) Received: from localhost ([::1]:46348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jnOZ6-00082o-6C for importer@patchew.org; Mon, 22 Jun 2020 11:40:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58884) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jnOXS-0005Xx-Iu for qemu-devel@nongnu.org; Mon, 22 Jun 2020 11:39:14 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:43203 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jnOXR-0003PU-0b for qemu-devel@nongnu.org; Mon, 22 Jun 2020 11:39: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-264-j4mNxZEmNR2FIK0oYu3SfA-1; Mon, 22 Jun 2020 11:39:10 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C20AF1883607; Mon, 22 Jun 2020 15:39:07 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-110.pek2.redhat.com [10.72.13.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55C6171679; Mon, 22 Jun 2020 15:38:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592840352; 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=6j1pA8flFXxKFgGD7KGcZegLUTAz9cG1BpLNQLqPNk0=; b=FT8eoR4BZCQ6kVFhqvMUSn/xuF3DO2G9o1PELzTp6Je7ZXhX6M9lmGenrPW128aH+SWBeb Lsxj4QIklWlYCsvWEdIRQyv0K3hGrXsqDpQwCEptJanUXcDzCYlpZv1O5+8JpQWmxhAN/f 7C2G2qt2ds9kn2DGOO0qx+dSUaQ5Qzo= X-MC-Unique: j4mNxZEmNR2FIK0oYu3SfA-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [PATCH v1 02/10] vhost_net: use the function qemu_get_peer Date: Mon, 22 Jun 2020 23:37:48 +0800 Message-Id: <20200622153756.19189-3-lulu@redhat.com> In-Reply-To: <20200622153756.19189-1-lulu@redhat.com> References: <20200622153756.19189-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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=205.139.110.120; envelope-from=lulu@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/22 01:27:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: mhabets@solarflare.com, qemu-devel@nongnu.org, rob.miller@broadcom.com, saugatm@xilinx.com, lulu@redhat.com, hanand@xilinx.com, hch@infradead.org, eperezma@redhat.com, jgg@mellanox.com, shahafs@mellanox.com, kevin.tian@intel.com, parav@mellanox.com, vmireyno@marvell.com, cunming.liang@intel.com, gdawar@xilinx.com, jiri@mellanox.com, xiao.w.wang@intel.com, stefanha@redhat.com, zhihong.wang@intel.com, aadam@redhat.com, rdunlap@infradead.org, maxime.coquelin@redhat.com, lingshan.zhu@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" user the qemu_get_peer to replace the old process Signed-off-by: Cindy Lu Reviewed-by: Laurent Vivier --- hw/net/vhost_net.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 6b82803fa7..4096d64aaf 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -306,7 +306,9 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *= ncs, BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(dev))); VirtioBusState *vbus =3D VIRTIO_BUS(qbus); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(vbus); + struct vhost_net *net; int r, e, i; + NetClientState *peer; =20 if (!k->set_guest_notifiers) { error_report("binding does not support guest notifiers"); @@ -314,9 +316,9 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *= ncs, } =20 for (i =3D 0; i < total_queues; i++) { - struct vhost_net *net; =20 - net =3D get_vhost_net(ncs[i].peer); + peer =3D qemu_get_peer(ncs, i); + net =3D get_vhost_net(peer); vhost_net_set_vq_index(net, i * 2); =20 /* Suppress the masking guest notifiers on vhost user @@ -335,15 +337,16 @@ int vhost_net_start(VirtIODevice *dev, NetClientState= *ncs, } =20 for (i =3D 0; i < total_queues; i++) { - r =3D vhost_net_start_one(get_vhost_net(ncs[i].peer), dev); + peer =3D qemu_get_peer(ncs, i); + r =3D vhost_net_start_one(get_vhost_net(peer), dev); =20 if (r < 0) { goto err_start; } =20 - if (ncs[i].peer->vring_enable) { + if (peer->vring_enable) { /* restore vring enable state */ - r =3D vhost_set_vring_enable(ncs[i].peer, ncs[i].peer->vring_e= nable); + r =3D vhost_set_vring_enable(peer, peer->vring_enable); =20 if (r < 0) { goto err_start; @@ -355,7 +358,8 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *= ncs, =20 err_start: while (--i >=3D 0) { - vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev); + 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); if (e < 0) { --=20 2.21.1 From nobody Mon Apr 29 11:45:46 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 ARC-Seal: i=1; a=rsa-sha256; t=1592840501; cv=none; d=zohomail.com; s=zohoarc; b=KxFzsdECmNLVqRowMC4H6j2M5LURbeS/PhPEhZWhKnn+SRSKlnPnJ9y/9OmIq84KO49NLb1pdzJjuBHWsNgdNe7Q6A+sKQwys0MjMzwcK4rjsnhhq1L8Qvnz1Gc3cBozCs5/hOL13BKrqBoqX6V+Ykmdx4LX7IeFCJ8ffu5WOAc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592840501; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=p5bXbIxy8s0ryaEaU97GsZ4HqDYJlmv5BJfcBBmiTCQ=; b=k/k6GzrqvQfBw6htCg4G9s49bHICZhqXY5eS3jWay5YmQZtM4iUGsXJrtH/cLsRY+tSZfhXGMqkrCv2Ra2w8dGvPC+8VVkfGqZXNiAotuyryLN9VBj3EpxyvI3xXAaPFyZqS7ZQn4bH9HmqljNfqvUFft0dSCGmJD42PzbMp6P4= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1592840501405476.9867823457188; Mon, 22 Jun 2020 08:41:41 -0700 (PDT) Received: from localhost ([::1]:49026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jnOZo-0000kB-7S for importer@patchew.org; Mon, 22 Jun 2020 11:41:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jnOXm-0006Dx-06 for qemu-devel@nongnu.org; Mon, 22 Jun 2020 11:39:34 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:42729 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jnOXk-0003SH-DC for qemu-devel@nongnu.org; Mon, 22 Jun 2020 11:39:33 -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-491-fu_UieGbMIqvppj2YMrbRg-1; Mon, 22 Jun 2020 11:39:29 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3D30C184D144; Mon, 22 Jun 2020 15:39:27 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-110.pek2.redhat.com [10.72.13.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD3B371664; Mon, 22 Jun 2020 15:39:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592840371; 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=p5bXbIxy8s0ryaEaU97GsZ4HqDYJlmv5BJfcBBmiTCQ=; b=Sp/gJ0NQ6XkXi06bjounsoSmwqGhpFxrd/xbwl6gwxMdRxEVBUjSW+N0hAUaFyzaNjn11/ KaCcUvXeyqU3injqF1uNbHIt3ByLfxSK0AAuxdq3Xe3XGkaRcO3ZLfZ+vBFgwX8yqu2g/J 8+58f9tdXCLeaa0ErEX28wfTOHYPYrY= X-MC-Unique: fu_UieGbMIqvppj2YMrbRg-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [PATCH v1 03/10] virtio-bus: introduce queue_enabled method Date: Mon, 22 Jun 2020 23:37:49 +0800 Message-Id: <20200622153756.19189-4-lulu@redhat.com> In-Reply-To: <20200622153756.19189-1-lulu@redhat.com> References: <20200622153756.19189-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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=207.211.31.120; envelope-from=lulu@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/22 02:57:26 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: mhabets@solarflare.com, qemu-devel@nongnu.org, rob.miller@broadcom.com, saugatm@xilinx.com, lulu@redhat.com, hanand@xilinx.com, hch@infradead.org, eperezma@redhat.com, jgg@mellanox.com, shahafs@mellanox.com, kevin.tian@intel.com, parav@mellanox.com, vmireyno@marvell.com, cunming.liang@intel.com, gdawar@xilinx.com, jiri@mellanox.com, xiao.w.wang@intel.com, stefanha@redhat.com, zhihong.wang@intel.com, aadam@redhat.com, rdunlap@infradead.org, maxime.coquelin@redhat.com, lingshan.zhu@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Jason Wang This patch introduces queue_enabled() method which allows the transport to implement its own way to report whether or not a queue is enabled. Signed-off-by: Jason Wang Signed-off-by: Cindy Lu --- hw/virtio/virtio.c | 6 ++++++ include/hw/virtio/virtio-bus.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index b6c8ef5bc0..445a4ed760 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3285,6 +3285,12 @@ hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev= , int n) =20 bool virtio_queue_enabled(VirtIODevice *vdev, int n) { + BusState *qbus =3D qdev_get_parent_bus(DEVICE(vdev)); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + + if (k->queue_enabled) { + return k->queue_enabled(qbus->parent, n); + } return virtio_queue_get_desc_addr(vdev, n) !=3D 0; } =20 diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h index 38c9399cd4..0f6f215925 100644 --- a/include/hw/virtio/virtio-bus.h +++ b/include/hw/virtio/virtio-bus.h @@ -83,6 +83,10 @@ typedef struct VirtioBusClass { */ int (*ioeventfd_assign)(DeviceState *d, EventNotifier *notifier, int n, bool assign); + /* + * Whether queue number n is enabled. + */ + bool (*queue_enabled)(DeviceState *d, int n); /* * Does the transport have variable vring alignment? * (ie can it ever call virtio_queue_set_align()?) --=20 2.21.1 From nobody Mon Apr 29 11:45:46 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 ARC-Seal: i=1; a=rsa-sha256; t=1592840621; cv=none; d=zohomail.com; s=zohoarc; b=UBlzm2Kwkh/IfAgUPPAygFg76wtm7/Zc8Ptseuuz1iLOiYhL8Cku4kaJx+UROyftjVXPdzAy4FUN2s+ayvb8cfsSgUzWpSMWCPgFqZtQ6UhXx/25aWOswcUW7jyCjgmc19eFFQ23KBgyFibw3+eT42xeZXa7SnPHHjdV692dUV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592840621; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mCMXojiD1+Nn3lnQMP2IDGa3qVqpRilydZorQ7YFUPE=; b=Kux0Ie0mfQc4SHuLKhhagW8ZBexONnwCR6YW6obiwKsGNs9o84DRIU44/7tK2RsCFOjB7vD7hvqykCnFi9mQDwBi47gO8KCrFl0mCBh4UYtCYoF8QU83iEmv3667D+4aoth0sLJwaPMqi3UUu+DNkMCIoeaw4XQZ6OTpluqmzOc= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1592840621768920.4090251919762; Mon, 22 Jun 2020 08:43:41 -0700 (PDT) Received: from localhost ([::1]:55772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jnObk-0003Ya-Er for importer@patchew.org; Mon, 22 Jun 2020 11:43:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59036) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jnOY7-0006jp-TX for qemu-devel@nongnu.org; Mon, 22 Jun 2020 11:39:55 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:29464 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jnOY6-0003Uu-8k for qemu-devel@nongnu.org; Mon, 22 Jun 2020 11:39: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-431-WaB1oGlGNraeSDCwhYcJ3g-1; Mon, 22 Jun 2020 11:39:49 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C5AC78018A5; Mon, 22 Jun 2020 15:39:46 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-110.pek2.redhat.com [10.72.13.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF74771677; Mon, 22 Jun 2020 15:39:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592840393; 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=mCMXojiD1+Nn3lnQMP2IDGa3qVqpRilydZorQ7YFUPE=; b=PaL3unSDewwE7Lxwqqox78fpkxTeVSH5fNsDdPCA6V2WO/+MOj0cJDHC4DZ+0DaWPEpLmv 4irVGczR8N27jzryTPanV9UgHCiQKUDTK7ep1O/5UqdfVqLJXTYkX7IvMG2aRMorUr7+ZE 6TMrrHgCF5R/wCLa54Bad4ZQQOzFg/E= X-MC-Unique: WaB1oGlGNraeSDCwhYcJ3g-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [PATCH v1 04/10] virtio-pci: implement queue_enabled method Date: Mon, 22 Jun 2020 23:37:50 +0800 Message-Id: <20200622153756.19189-5-lulu@redhat.com> In-Reply-To: <20200622153756.19189-1-lulu@redhat.com> References: <20200622153756.19189-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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=207.211.31.81; envelope-from=lulu@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/22 02:57:26 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: mhabets@solarflare.com, qemu-devel@nongnu.org, rob.miller@broadcom.com, saugatm@xilinx.com, lulu@redhat.com, hanand@xilinx.com, hch@infradead.org, eperezma@redhat.com, jgg@mellanox.com, shahafs@mellanox.com, kevin.tian@intel.com, parav@mellanox.com, vmireyno@marvell.com, cunming.liang@intel.com, gdawar@xilinx.com, jiri@mellanox.com, xiao.w.wang@intel.com, stefanha@redhat.com, zhihong.wang@intel.com, aadam@redhat.com, rdunlap@infradead.org, maxime.coquelin@redhat.com, lingshan.zhu@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Jason Wang With version 1, we can detect whether a queue is enabled via queue_enabled. Signed-off-by: Jason Wang Signed-off-by: Cindy Lu --- hw/virtio/virtio-pci.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 4cb784389c..3918aa9f6c 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1107,6 +1107,23 @@ static AddressSpace *virtio_pci_get_dma_as(DeviceSta= te *d) return pci_get_address_space(dev); } =20 +static bool virtio_queue_check_enabled(VirtIODevice *vdev, int n) +{ + return virtio_queue_get_desc_addr(vdev, n) !=3D 0; +} + +static bool virtio_pci_queue_enabled(DeviceState *d, int n) +{ + VirtIOPCIProxy *proxy =3D VIRTIO_PCI(d); + VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); + + if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { + return proxy->vqs[vdev->queue_sel].enabled; + } + + return virtio_queue_check_enabled(vdev, n); +} + static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy, struct virtio_pci_cap *cap) { @@ -2059,6 +2076,7 @@ static void virtio_pci_bus_class_init(ObjectClass *kl= ass, void *data) k->ioeventfd_enabled =3D virtio_pci_ioeventfd_enabled; k->ioeventfd_assign =3D virtio_pci_ioeventfd_assign; k->get_dma_as =3D virtio_pci_get_dma_as; + k->queue_enabled =3D virtio_pci_queue_enabled; } =20 static const TypeInfo virtio_pci_bus_info =3D { --=20 2.21.1 From nobody Mon Apr 29 11:45:46 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 ARC-Seal: i=1; a=rsa-sha256; t=1592840492; cv=none; d=zohomail.com; s=zohoarc; b=Pik3/KGlhtnOHAFnk+41R+3pqC7Lt6nfIPClZ9uOKkSgeTd0+O8VUkHfAqBpEnIfqbP9C3FCgMstKZYmjHPWUlsyv6fRX/RbdTgjKjvcOiIr575i0EnfXGGhkKXo3MBUway4vCTuCtPiKDlG/RIqVWwawV8ABnrcYdk3zE5huqo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592840492; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=w7ONpZZjErZHFUYN7YfFgaMMb15Ej0bi5uA6s5ZasrY=; b=S0Ba6tGd+wUx0us3NcA+x09rweXKycNyXTlsnlkuIWJplPq/vqmV0xdlzC+XAh28fD/3d8TlpDgR6rszt84dS2Yn3GQTr0GdEGmrCgNzFwhWNoKUcWrc+FwcQUYtY88qqyl7trVgz+s5AwEb6jRwagcwgeO/3JZMnQ0sQExqyf8= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1592840492945900.2902806902429; Mon, 22 Jun 2020 08:41:32 -0700 (PDT) Received: from localhost ([::1]:48220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jnOZf-0000OG-Im for importer@patchew.org; Mon, 22 Jun 2020 11:41:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59122) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jnOYW-0007Pu-5I for qemu-devel@nongnu.org; Mon, 22 Jun 2020 11:40:20 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:46812 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jnOYU-0003ZN-6F for qemu-devel@nongnu.org; Mon, 22 Jun 2020 11:40:19 -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-446-wOAhls_zNha9fqcms68PcA-1; Mon, 22 Jun 2020 11:40:12 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5F787184D147; Mon, 22 Jun 2020 15:40:10 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-110.pek2.redhat.com [10.72.13.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8731A71679; Mon, 22 Jun 2020 15:39:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592840417; 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=w7ONpZZjErZHFUYN7YfFgaMMb15Ej0bi5uA6s5ZasrY=; b=D9PJbjsreLOIEedqsyurz+Ru+2jOBVFRSDZf/7SlKZ7GbF+EH1zA0aPqNlCOCvIUheVpJM 94ui+BzNM4fhx4fAcatVG3do1L0AgGL7DNl5YwttcPPRhV3ENSYPTUMbnrBC5Cx/ECwyf1 X3zEEMhX17GzjeiHVgUdkuWTZfGEqTI= X-MC-Unique: wOAhls_zNha9fqcms68PcA-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [PATCH v1 05/10] vhost-backend: export the vhost backend helper Date: Mon, 22 Jun 2020 23:37:51 +0800 Message-Id: <20200622153756.19189-6-lulu@redhat.com> In-Reply-To: <20200622153756.19189-1-lulu@redhat.com> References: <20200622153756.19189-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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=205.139.110.61; envelope-from=lulu@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/22 03:17:49 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: mhabets@solarflare.com, qemu-devel@nongnu.org, rob.miller@broadcom.com, saugatm@xilinx.com, lulu@redhat.com, hanand@xilinx.com, hch@infradead.org, eperezma@redhat.com, jgg@mellanox.com, shahafs@mellanox.com, kevin.tian@intel.com, parav@mellanox.com, vmireyno@marvell.com, cunming.liang@intel.com, gdawar@xilinx.com, jiri@mellanox.com, xiao.w.wang@intel.com, stefanha@redhat.com, zhihong.wang@intel.com, aadam@redhat.com, rdunlap@infradead.org, maxime.coquelin@redhat.com, lingshan.zhu@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" export the helper then we can reuse them in other backend Signed-off-by: Cindy Lu --- hw/virtio/vhost-backend.c | 18 +++++++++--------- include/hw/virtio/vhost-backend.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index 48905383f8..660e9e8588 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -89,7 +89,7 @@ static int vhost_kernel_scsi_get_abi_version(struct vhost= _dev *dev, int *version return vhost_kernel_call(dev, VHOST_SCSI_GET_ABI_VERSION, version); } =20 -static int vhost_kernel_set_log_base(struct vhost_dev *dev, uint64_t base, +int vhost_kernel_set_log_base(struct vhost_dev *dev, uint64_t base, struct vhost_log *log) { return vhost_kernel_call(dev, VHOST_SET_LOG_BASE, &base); @@ -101,7 +101,7 @@ static int vhost_kernel_set_mem_table(struct vhost_dev = *dev, return vhost_kernel_call(dev, VHOST_SET_MEM_TABLE, mem); } =20 -static int vhost_kernel_set_vring_addr(struct vhost_dev *dev, +int vhost_kernel_set_vring_addr(struct vhost_dev *dev, struct vhost_vring_addr *addr) { return vhost_kernel_call(dev, VHOST_SET_VRING_ADDR, addr); @@ -113,31 +113,31 @@ static int vhost_kernel_set_vring_endian(struct vhost= _dev *dev, return vhost_kernel_call(dev, VHOST_SET_VRING_ENDIAN, ring); } =20 -static int vhost_kernel_set_vring_num(struct vhost_dev *dev, +int vhost_kernel_set_vring_num(struct vhost_dev *dev, struct vhost_vring_state *ring) { return vhost_kernel_call(dev, VHOST_SET_VRING_NUM, ring); } =20 -static int vhost_kernel_set_vring_base(struct vhost_dev *dev, +int vhost_kernel_set_vring_base(struct vhost_dev *dev, struct vhost_vring_state *ring) { return vhost_kernel_call(dev, VHOST_SET_VRING_BASE, ring); } =20 -static int vhost_kernel_get_vring_base(struct vhost_dev *dev, +int vhost_kernel_get_vring_base(struct vhost_dev *dev, struct vhost_vring_state *ring) { return vhost_kernel_call(dev, VHOST_GET_VRING_BASE, ring); } =20 -static int vhost_kernel_set_vring_kick(struct vhost_dev *dev, +int vhost_kernel_set_vring_kick(struct vhost_dev *dev, struct vhost_vring_file *file) { return vhost_kernel_call(dev, VHOST_SET_VRING_KICK, file); } =20 -static int vhost_kernel_set_vring_call(struct vhost_dev *dev, +int vhost_kernel_set_vring_call(struct vhost_dev *dev, struct vhost_vring_file *file) { return vhost_kernel_call(dev, VHOST_SET_VRING_CALL, file); @@ -155,13 +155,13 @@ static int vhost_kernel_set_features(struct vhost_dev= *dev, return vhost_kernel_call(dev, VHOST_SET_FEATURES, &features); } =20 -static int vhost_kernel_get_features(struct vhost_dev *dev, +int vhost_kernel_get_features(struct vhost_dev *dev, uint64_t *features) { return vhost_kernel_call(dev, VHOST_GET_FEATURES, features); } =20 -static int vhost_kernel_set_owner(struct vhost_dev *dev) +int vhost_kernel_set_owner(struct vhost_dev *dev) { return vhost_kernel_call(dev, VHOST_SET_OWNER, NULL); } diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-ba= ckend.h index 6f6670783f..300b59c172 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -172,4 +172,32 @@ int vhost_backend_handle_iotlb_msg(struct vhost_dev *d= ev, =20 int vhost_user_gpu_set_socket(struct vhost_dev *dev, int fd); =20 + +int vhost_kernel_set_log_base(struct vhost_dev *dev, uint64_t base, + struct vhost_log *log); + +int vhost_kernel_set_vring_addr(struct vhost_dev *dev, + struct vhost_vring_addr *addr); + +int vhost_kernel_set_vring_num(struct vhost_dev *dev, + struct vhost_vring_state *ring); + +int vhost_kernel_set_vring_base(struct vhost_dev *dev, + struct vhost_vring_state *ring); + +int vhost_kernel_get_vring_base(struct vhost_dev *dev, + struct vhost_vring_state *ring); + +int vhost_kernel_set_vring_kick(struct vhost_dev *dev, + struct vhost_vring_file *file); + +int vhost_kernel_set_vring_call(struct vhost_dev *dev, + struct vhost_vring_file *file); + +int vhost_kernel_set_owner(struct vhost_dev *dev); + +int vhost_kernel_get_features(struct vhost_dev *dev, + uint64_t *features); + + #endif /* VHOST_BACKEND_H */ --=20 2.21.1 From nobody Mon Apr 29 11:45:46 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 ARC-Seal: i=1; a=rsa-sha256; t=1592840717; cv=none; d=zohomail.com; s=zohoarc; b=JDyIICWLJdsAh7UuNXaclPh4ICnhEhWQtcI7BInli3tSMG4e0XAP/+UMbCpsTQzwHXLu67vpJ4LplgnyXVZ24DjITL+JnS/ofZLuv+vDjj7mFYK+lBxRZahjElA/xROw200cMNQ5qKDKQfYjoteQYTtpqpZnEP/FyWHU2KboN0A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592840717; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DepnZlL/bm0hHGf+dW+67jhLOZh9XVMNcbyUYjOici8=; b=ajleo454IjTxhfPHHum3qUgOhFId2dYpZwWkMbO+HY+pG1N+L26y9kX3CpQmpw4cSGWWSZASHFbKRUFJgBh48DpLNGqoMrM1gl1GAF/d3FU7BqUlSK2ymg7nfGYcNJXRWHfMWMHHcfAF4+2nSFzBq3KKtzfRv7Dz+nWLryy9UxY= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1592840717453973.9090533131692; Mon, 22 Jun 2020 08:45:17 -0700 (PDT) Received: from localhost ([::1]:33438 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jnOdI-0005yY-1y for importer@patchew.org; Mon, 22 Jun 2020 11:45:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59178) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jnOYn-0007zL-58 for qemu-devel@nongnu.org; Mon, 22 Jun 2020 11:40:37 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:44727 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jnOYl-0003hO-6w for qemu-devel@nongnu.org; Mon, 22 Jun 2020 11:40:36 -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-74-w1ngTPbiMDyteOj9Le-B4Q-1; Mon, 22 Jun 2020 11:40:32 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 379A28064D8; Mon, 22 Jun 2020 15:40:30 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-110.pek2.redhat.com [10.72.13.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 249FE7167B; Mon, 22 Jun 2020 15:40:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592840434; 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=DepnZlL/bm0hHGf+dW+67jhLOZh9XVMNcbyUYjOici8=; b=dx4wjxuFZ6XSpa6OeMzSsNlK8Ukwa6ROk/e1O1dOc75iXBuoTZAJ9UlWVn2NOJeYJfcv7S 8ZUrA9Uf5y2gv9NLranJs1TMICpycPxmprQkQ3thTay+eAWKBakNAMXBAFXPGUo5zhUMjR +055hvFI5aiBXeVMxMpOTKCY7RTl1NQ= X-MC-Unique: w1ngTPbiMDyteOj9Le-B4Q-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [PATCH v1 06/10] vhsot_net: introduce set_config & get_config function Date: Mon, 22 Jun 2020 23:37:52 +0800 Message-Id: <20200622153756.19189-7-lulu@redhat.com> In-Reply-To: <20200622153756.19189-1-lulu@redhat.com> References: <20200622153756.19189-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lulu@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=205.139.110.120; envelope-from=lulu@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/22 01:27:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: mhabets@solarflare.com, qemu-devel@nongnu.org, rob.miller@broadcom.com, saugatm@xilinx.com, lulu@redhat.com, hanand@xilinx.com, hch@infradead.org, eperezma@redhat.com, jgg@mellanox.com, shahafs@mellanox.com, kevin.tian@intel.com, parav@mellanox.com, vmireyno@marvell.com, cunming.liang@intel.com, gdawar@xilinx.com, jiri@mellanox.com, xiao.w.wang@intel.com, stefanha@redhat.com, zhihong.wang@intel.com, aadam@redhat.com, rdunlap@infradead.org, maxime.coquelin@redhat.com, lingshan.zhu@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This patch introduces set_config & get_config method which allows vhost_net set/get the config to backend Signed-off-by: Cindy Lu --- hw/net/vhost_net.c | 11 +++++++++++ include/net/vhost_net.h | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 4096d64aaf..04cc3db264 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -111,6 +111,17 @@ uint64_t vhost_net_get_features(struct vhost_net *net,= uint64_t features) features); } =20 +int vhost_net_get_config(struct vhost_net *net, uint8_t *config, + uint32_t config_len) +{ + return vhost_dev_get_config(&net->dev, config, config_len); +} +int vhost_net_set_config(struct vhost_net *net, const uint8_t *data, + uint32_t offset, uint32_t size, uint32_t flags) +{ + return vhost_dev_set_config(&net->dev, data, offset, size, flags); +} + void vhost_net_ack_features(struct vhost_net *net, uint64_t features) { net->dev.acked_features =3D net->dev.backend_features; diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 77e47398c4..abfb0e8e68 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -27,6 +27,11 @@ void vhost_net_cleanup(VHostNetState *net); =20 uint64_t vhost_net_get_features(VHostNetState *net, uint64_t features); void vhost_net_ack_features(VHostNetState *net, uint64_t features); +int vhost_net_get_config(struct vhost_net *net, uint8_t *config, + uint32_t config_len); + +int vhost_net_set_config(struct vhost_net *net, const uint8_t *data, + uint32_t offset, uint32_t size, uint32_t flags); =20 bool vhost_net_virtqueue_pending(VHostNetState *net, int n); void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev, --=20 2.21.1 From nobody Mon Apr 29 11:45:46 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 ARC-Seal: i=1; a=rsa-sha256; t=1592840613; cv=none; d=zohomail.com; s=zohoarc; b=fU3B+sd/RRBby6GC8cRqQBmLgdEVfIx7iLh3vCbKBot5q3vGeBf9gg4a3HSYt6l/Jbj/cmvG3YW6Fg08W9Mf492vN2Rl2nn42iXIzHRTAcaOXupjitFynaGNIN2kcBfGAUM/t7MWBH72XFGSbtiOerydDE0P+yaqMg2bLerSzTk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592840613; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wK539b8L9KGSMUUl51u0L4rD94+4BNPjLgUZK8k90XE=; b=dVSgE05eY/YcpsJQFH8fQLOnGqQCrqx6ItHeMqLya+UkHa4PIWme9uidqlg2B8mM4RsRdHXMoElgoF19KPgIXLK4THSELSJ2rl1VHwVgbeDQmU41iedSLIkps4gKK7o8Z7Gw2zE24fzuhVGKPvAflY0NWkourxlok5PQNCUFdV0= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1592840613538365.29678438893484; Mon, 22 Jun 2020 08:43:33 -0700 (PDT) Received: from localhost ([::1]:54810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jnObc-0003Ao-3O for importer@patchew.org; Mon, 22 Jun 2020 11:43:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59302) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jnOZN-0000NK-CW for qemu-devel@nongnu.org; Mon, 22 Jun 2020 11:41:13 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:51677 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jnOZL-0003xp-4E for qemu-devel@nongnu.org; Mon, 22 Jun 2020 11:41:13 -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-231-ZV2vttPeNAS5DjXe1Ejnxw-1; Mon, 22 Jun 2020 11:41:08 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 936FFEC1C1; Mon, 22 Jun 2020 15:41:00 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-110.pek2.redhat.com [10.72.13.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 375507168B; Mon, 22 Jun 2020 15:40:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592840470; 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=wK539b8L9KGSMUUl51u0L4rD94+4BNPjLgUZK8k90XE=; b=gbWtGmxoNhoFosMoPHo+On4UBoabt2JZeoUY+5TXlCTKFW0ObclWZv3u11zRIT9S83IEzW NH9jrEozzn4xNkpHUXBakVZlTyOvNIqPwBwiI5p7Jepzn5vPI8c2b6dsvdbZ3yNtsdQFqp MiLJEMBNeZdP4RxfXKT/LzZi2QIgZyE= X-MC-Unique: ZV2vttPeNAS5DjXe1Ejnxw-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [PATCH v1 07/10] vhost: introduce new VhostOps vhost_dev_start Date: Mon, 22 Jun 2020 23:37:53 +0800 Message-Id: <20200622153756.19189-8-lulu@redhat.com> In-Reply-To: <20200622153756.19189-1-lulu@redhat.com> References: <20200622153756.19189-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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=207.211.31.120; envelope-from=lulu@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/22 02:57:26 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: mhabets@solarflare.com, qemu-devel@nongnu.org, rob.miller@broadcom.com, saugatm@xilinx.com, lulu@redhat.com, hanand@xilinx.com, hch@infradead.org, eperezma@redhat.com, jgg@mellanox.com, shahafs@mellanox.com, kevin.tian@intel.com, parav@mellanox.com, vmireyno@marvell.com, cunming.liang@intel.com, gdawar@xilinx.com, jiri@mellanox.com, xiao.w.wang@intel.com, stefanha@redhat.com, zhihong.wang@intel.com, aadam@redhat.com, rdunlap@infradead.org, maxime.coquelin@redhat.com, lingshan.zhu@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This patch introduces vhost_dev_start() callback which allows the vhost_net set the start/stop status to backend Signed-off-by: Cindy Lu --- include/hw/virtio/vhost-backend.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-ba= ckend.h index 300b59c172..c1384bd2c7 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -112,6 +112,7 @@ typedef int (*vhost_get_inflight_fd_op)(struct vhost_de= v *dev, typedef int (*vhost_set_inflight_fd_op)(struct vhost_dev *dev, struct vhost_inflight *inflight); =20 +typedef int (*vhost_dev_start_op)(struct vhost_dev *dev, bool started); typedef struct VhostOps { VhostBackendType backend_type; vhost_backend_init vhost_backend_init; @@ -152,6 +153,7 @@ typedef struct VhostOps { vhost_backend_mem_section_filter_op vhost_backend_mem_section_filter; vhost_get_inflight_fd_op vhost_get_inflight_fd; vhost_set_inflight_fd_op vhost_set_inflight_fd; + vhost_dev_start_op vhost_dev_start; } VhostOps; =20 extern const VhostOps user_ops; --=20 2.21.1 From nobody Mon Apr 29 11:45:46 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 ARC-Seal: i=1; a=rsa-sha256; t=1592840615; cv=none; d=zohomail.com; s=zohoarc; b=SDy8mb3KPMdRtbRCKxInnBVmMchNGVkV/bxbvgfRVGVknoncN9f4AtmUEE9VhXlM1iBDztrHjeT9nXkLpRczShQYohUSr+6aT4CzQ5vDW62dlqgX0qHU9JqrILXGVruKJh2ik57WWYZmwyJKU1X+7y/C9ClihkhliX401s5oAko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592840615; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8ai1PmYpRauheJ6qtnyBbvWoo5KgsiIHoZlm60i9SQU=; b=Cd2y/8xhyHigpTKCKbK1MKO2PLF7GaTAe6YSmBKSEM1hsqc0o5058guejTP02oVDzdrBgFfL26U5QOLz9QYhKHRMSNZNG7taH34D4z4UhlSvBHU1emwFXZzX0P6cp0ACp/nWvzE7MOUJjBG8qfTeKiM9lJjFlboHWkaOs6LNUPM= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1592840615692760.5238319746124; Mon, 22 Jun 2020 08:43:35 -0700 (PDT) Received: from localhost ([::1]:55110 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jnObe-0003I9-Dh for importer@patchew.org; Mon, 22 Jun 2020 11:43:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jnOa8-0001bp-Eb for qemu-devel@nongnu.org; Mon, 22 Jun 2020 11:42:00 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:54798 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jnOa5-00043P-P0 for qemu-devel@nongnu.org; Mon, 22 Jun 2020 11:42:00 -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-296-kaWWLbqINTi9gRh3vvGLgA-1; Mon, 22 Jun 2020 11:41:52 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 23BC610230C1; Mon, 22 Jun 2020 15:41:39 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-110.pek2.redhat.com [10.72.13.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D47C82026; Mon, 22 Jun 2020 15:41:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592840516; 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=8ai1PmYpRauheJ6qtnyBbvWoo5KgsiIHoZlm60i9SQU=; b=GjV5/X5u5ZjmQPOHUoHx00CdkPFPkWEv0gIpUnIK3Ibtb4oZvBtte8B2o905ubNaVTCzaw EzqKN+cT59qkG3gT9AabLiAK4wa4XXkhOkUPEvjnYXQIPVvZj6jHyMrXYHyr84XNDqBbEN S/IxfzmKvfVHUqLgoVrp71UwCMqyZlI= X-MC-Unique: kaWWLbqINTi9gRh3vvGLgA-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [PATCH v1 08/10] vhost: implement vhost_dev_start method Date: Mon, 22 Jun 2020 23:37:54 +0800 Message-Id: <20200622153756.19189-9-lulu@redhat.com> In-Reply-To: <20200622153756.19189-1-lulu@redhat.com> References: <20200622153756.19189-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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=205.139.110.120; envelope-from=lulu@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/22 01:27:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: mhabets@solarflare.com, qemu-devel@nongnu.org, rob.miller@broadcom.com, saugatm@xilinx.com, lulu@redhat.com, hanand@xilinx.com, hch@infradead.org, eperezma@redhat.com, jgg@mellanox.com, shahafs@mellanox.com, kevin.tian@intel.com, parav@mellanox.com, vmireyno@marvell.com, cunming.liang@intel.com, gdawar@xilinx.com, jiri@mellanox.com, xiao.w.wang@intel.com, stefanha@redhat.com, zhihong.wang@intel.com, aadam@redhat.com, rdunlap@infradead.org, maxime.coquelin@redhat.com, lingshan.zhu@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" use the vhost_dev_start callback to send the status to backend Signed-off-by: Cindy Lu --- hw/virtio/vhost.c | 17 +++++++++++++++++ include/hw/virtio/vhost.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 01ebe12f28..bfd7f9ce1f 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -744,6 +744,7 @@ static void vhost_iommu_region_del(MemoryListener *list= ener, } } =20 + static int vhost_virtqueue_set_addr(struct vhost_dev *dev, struct vhost_virtqueue *vq, unsigned idx, bool enable_log) @@ -1661,6 +1662,11 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODe= vice *vdev) } } =20 + r =3D vhost_set_start(hdev, true); + if (r) { + goto fail_log; + } + if (vhost_dev_has_iommu(hdev)) { hdev->vhost_ops->vhost_set_iotlb_callback(hdev, true); =20 @@ -1697,6 +1703,8 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODev= ice *vdev) /* should only be called after backend is connected */ assert(hdev->vhost_ops); =20 + vhost_set_start(hdev, false); + for (i =3D 0; i < hdev->nvqs; ++i) { vhost_virtqueue_stop(hdev, vdev, @@ -1722,3 +1730,12 @@ int vhost_net_set_backend(struct vhost_dev *hdev, =20 return -1; } + +int vhost_set_start(struct vhost_dev *hdev, bool started) +{ + + if (hdev->vhost_ops->vhost_dev_start) { + hdev->vhost_ops->vhost_dev_start(hdev, started); + } + return 0; +} diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 085450c6f8..59ea53f8c2 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -92,6 +92,7 @@ struct vhost_dev { const VhostDevConfigOps *config_ops; }; =20 + int vhost_dev_init(struct vhost_dev *hdev, void *opaque, VhostBackendType backend_type, uint32_t busyloop_timeout); @@ -137,4 +138,5 @@ int vhost_dev_set_inflight(struct vhost_dev *dev, struct vhost_inflight *inflight); int vhost_dev_get_inflight(struct vhost_dev *dev, uint16_t queue_size, struct vhost_inflight *inflight); +int vhost_set_start(struct vhost_dev *dev, bool started); #endif --=20 2.21.1 From nobody Mon Apr 29 11:45:46 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 ARC-Seal: i=1; a=rsa-sha256; t=1592840652; cv=none; d=zohomail.com; s=zohoarc; b=Nu0RUet0ZCOQXE1gFfGCk2VyCt1AwFWrmx5oCEwPCnDWyH8hNMVrkjbwHbL6hFD5JQqG3Wge2AHG1Rmgw02s11nSvqtwDmvELlErG83Rnkqg2UEVR4sqQ9TBXSvzEXgIZdqO1TGc2Ss/ZnAj0CmvLf9m6/cYVhfu0p7TmuKH21Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592840652; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=C6qRhV7AM4+u3CNEo4zXEJju4rXIoFHxxGqIzh47iLA=; b=kMc/+7QHGNRzmzLQylPrlqXbZx2AGJfZHR8z7RVLyck8UWETopQtCZNgTvrZqduyqY09peYsq0KzRsPuRzluQ/+O5GsOYmQJS1A+817oeBhaJK0608j9ymJswmjscXOZ2l8BUaBW4y4ckiJrIfnzorQC8oSuuujyjGMTNLT/TQE= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1592840652565697.2437032780327; Mon, 22 Jun 2020 08:44:12 -0700 (PDT) Received: from localhost ([::1]:58392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jnOcF-0004eP-7l for importer@patchew.org; Mon, 22 Jun 2020 11:44:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59508) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jnOaK-0001nr-Hd for qemu-devel@nongnu.org; Mon, 22 Jun 2020 11:42:12 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:30884 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jnOaH-00044z-05 for qemu-devel@nongnu.org; Mon, 22 Jun 2020 11:42:12 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-63-InVsGOJNN-Sx45QVZe9xNQ-1; Mon, 22 Jun 2020 11:42:04 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 53AFE8730AC; Mon, 22 Jun 2020 15:42:00 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-110.pek2.redhat.com [10.72.13.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id C23DE1DC; Mon, 22 Jun 2020 15:41:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592840528; 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=C6qRhV7AM4+u3CNEo4zXEJju4rXIoFHxxGqIzh47iLA=; b=T9tznRbWMLLC7R15OD/8GkXtM20m+Rab/7kvabd4HWM719s5KiAZoYrKjNL+SLOQu+pSVZ ihz2Ys0sL8dPfkb6U/GqEyNWoWsxXeaC2WvWRlM0Slm1ckher1bddWkQSxGhlqpr0Om2EB vyu758/45x1NV+HWjoDAoLmULRd/QzA= X-MC-Unique: InVsGOJNN-Sx45QVZe9xNQ-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [PATCH v1 09/10] vhost-vdpa: introduce vhost-vdpa backend Date: Mon, 22 Jun 2020 23:37:55 +0800 Message-Id: <20200622153756.19189-10-lulu@redhat.com> In-Reply-To: <20200622153756.19189-1-lulu@redhat.com> References: <20200622153756.19189-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lulu@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=207.211.31.120; envelope-from=lulu@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/22 02:57:26 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: mhabets@solarflare.com, qemu-devel@nongnu.org, rob.miller@broadcom.com, saugatm@xilinx.com, lulu@redhat.com, hanand@xilinx.com, hch@infradead.org, eperezma@redhat.com, jgg@mellanox.com, shahafs@mellanox.com, kevin.tian@intel.com, parav@mellanox.com, vmireyno@marvell.com, cunming.liang@intel.com, gdawar@xilinx.com, jiri@mellanox.com, xiao.w.wang@intel.com, stefanha@redhat.com, zhihong.wang@intel.com, Tiwei Bie , aadam@redhat.com, rdunlap@infradead.org, maxime.coquelin@redhat.com, lingshan.zhu@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Currently we have 2 types of vhost backends in QEMU: vhost kernel and vhost-user. The above patch provides a generic device for vDPA purpose, this vDPA device exposes to user space a non-vendor-specific configuration interface for setting up a vhost HW accelerator, this patch set introduces a third vhost backend called vhost-vdpa based on the vDPA interface. Vhost-vdpa usage: qemu-system-x86_64 -cpu host -enable-kvm \ ...... -netdev type=3Dvhost-vdpa,vhostdev=3D/dev/vhost-vdpa-id,id=3Dvhost-vdpa= 0 \ -device virtio-net-pci,netdev=3Dvhost-vdpa0,page-per-vq=3Don \ Signed-off-by: Lingshan zhu Signed-off-by: Tiwei Bie Signed-off-by: Cindy Lu --- configure | 21 ++ hw/net/vhost_net.c | 19 +- hw/net/virtio-net.c | 19 +- hw/virtio/Makefile.objs | 1 + hw/virtio/vhost-backend.c | 22 +- hw/virtio/vhost-vdpa.c | 406 ++++++++++++++++++++++++++++++ hw/virtio/vhost.c | 42 +++- include/hw/virtio/vhost-backend.h | 6 +- include/hw/virtio/vhost-vdpa.h | 26 ++ include/hw/virtio/vhost.h | 6 + qemu-options.hx | 12 + 11 files changed, 555 insertions(+), 25 deletions(-) create mode 100644 hw/virtio/vhost-vdpa.c create mode 100644 include/hw/virtio/vhost-vdpa.h diff --git a/configure b/configure index 23b5e93752..53679ee57f 100755 --- a/configure +++ b/configure @@ -1557,6 +1557,10 @@ for opt do ;; --enable-vhost-user) vhost_user=3D"yes" ;; + --disable-vhost-vdpa) vhost_vdpa=3D"no" + ;; + --enable-vhost-vdpa) vhost_vdpa=3D"yes" + ;; --disable-vhost-kernel) vhost_kernel=3D"no" ;; --enable-vhost-kernel) vhost_kernel=3D"yes" @@ -1846,6 +1850,7 @@ disabled with --disable-FEATURE, default is enabled i= f available: vhost-crypto vhost-user-crypto backend support vhost-kernel vhost kernel backend support vhost-user vhost-user backend support + vhost-vdpa vhost-vdpa kernel backend support spice spice rbd rados block device (rbd) libiscsi iscsi support @@ -2336,6 +2341,10 @@ test "$vhost_user" =3D "" && vhost_user=3Dyes if test "$vhost_user" =3D "yes" && test "$mingw32" =3D "yes"; then error_exit "vhost-user isn't available on win32" fi +test "$vhost_vdpa" =3D "" && vhost_vdpa=3D$linux +if test "$vhost_vdpa" =3D "yes" && test "$linux" !=3D "yes"; then + error_exit "vhost-vdpa is only available on Linux" +fi test "$vhost_kernel" =3D "" && vhost_kernel=3D$linux if test "$vhost_kernel" =3D "yes" && test "$linux" !=3D "yes"; then error_exit "vhost-kernel is only available on Linux" @@ -2364,6 +2373,11 @@ test "$vhost_user_fs" =3D "" && vhost_user_fs=3D$vho= st_user if test "$vhost_user_fs" =3D "yes" && test "$vhost_user" =3D "no"; then error_exit "--enable-vhost-user-fs requires --enable-vhost-user" fi +#vhost-vdpa backends +test "$vhost_net_vdpa" =3D "" && vhost_net_vdpa=3D$vhost_vdpa +if test "$vhost_net_vdpa" =3D "yes" && test "$vhost_vdpa" =3D "no"; then + error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa" +fi =20 # OR the vhost-kernel and vhost-user values for simplicity if test "$vhost_net" =3D ""; then @@ -6673,6 +6687,7 @@ echo "vhost-scsi support $vhost_scsi" echo "vhost-vsock support $vhost_vsock" echo "vhost-user support $vhost_user" echo "vhost-user-fs support $vhost_user_fs" +echo "vhost-vdpa support $vhost_vdpa" echo "Trace backends $trace_backends" if have_backend "simple"; then echo "Trace output file $trace_file-" @@ -7170,6 +7185,9 @@ fi if test "$vhost_net_user" =3D "yes" ; then echo "CONFIG_VHOST_NET_USER=3Dy" >> $config_host_mak fi +if test "$vhost_net_vdpa" =3D "yes" ; then + echo "CONFIG_VHOST_NET_VDPA=3Dy" >> $config_host_mak +fi if test "$vhost_crypto" =3D "yes" ; then echo "CONFIG_VHOST_CRYPTO=3Dy" >> $config_host_mak fi @@ -7182,6 +7200,9 @@ fi if test "$vhost_user" =3D "yes" ; then echo "CONFIG_VHOST_USER=3Dy" >> $config_host_mak fi +if test "$vhost_vdpa" =3D "yes" ; then + echo "CONFIG_VHOST_VDPA=3Dy" >> $config_host_mak +fi if test "$vhost_user_fs" =3D "yes" ; then echo "CONFIG_VHOST_USER_FS=3Dy" >> $config_host_mak fi diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 04cc3db264..cc259e571d 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -17,8 +17,10 @@ #include "net/net.h" #include "net/tap.h" #include "net/vhost-user.h" +#include "net/vhost-vdpa.h" =20 #include "standard-headers/linux/vhost_types.h" +#include "linux-headers/linux/vhost.h" #include "hw/virtio/virtio-net.h" #include "net/vhost_net.h" #include "qemu/error-report.h" @@ -33,12 +35,6 @@ #include "hw/virtio/vhost.h" #include "hw/virtio/virtio-bus.h" =20 -struct vhost_net { - struct vhost_dev dev; - struct vhost_virtqueue vqs[2]; - int backend; - NetClientState *nc; -}; =20 /* Features supported by host kernel. */ static const int kernel_feature_bits[] =3D { @@ -84,7 +80,6 @@ static const int user_feature_bits[] =3D { =20 VHOST_INVALID_FEATURE_BIT }; - static const int *vhost_net_get_feature_bits(struct vhost_net *net) { const int *feature_bits =3D 0; @@ -96,6 +91,9 @@ static const int *vhost_net_get_feature_bits(struct vhost= _net *net) case NET_CLIENT_DRIVER_VHOST_USER: feature_bits =3D user_feature_bits; break; + case NET_CLIENT_DRIVER_VHOST_VDPA: + feature_bits =3D vdpa_feature_bits; + break; default: error_report("Feature bits not defined for this type: %d", net->nc->info->type); @@ -348,6 +346,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *= ncs, } =20 for (i =3D 0; i < total_queues; i++) { + peer =3D qemu_get_peer(ncs, i); r =3D vhost_net_start_one(get_vhost_net(peer), dev); =20 @@ -444,6 +443,12 @@ VHostNetState *get_vhost_net(NetClientState *nc) vhost_net =3D vhost_user_get_vhost_net(nc); assert(vhost_net); break; +#endif +#ifdef CONFIG_VHOST_NET_VDPA + case NET_CLIENT_DRIVER_VHOST_VDPA: + vhost_net =3D vhost_vdpa_get_vhost_net(nc); + assert(vhost_net); + break; #endif default: break; diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index a46e3b37a7..8c85e2e1e1 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -42,6 +42,7 @@ #include "trace.h" #include "monitor/qdev.h" #include "hw/pci/pci.h" +#include "hw/virtio/vhost.h" =20 #define VIRTIO_NET_VM_VERSION 11 =20 @@ -131,6 +132,8 @@ static void virtio_net_get_config(VirtIODevice *vdev, u= int8_t *config) { VirtIONet *n =3D VIRTIO_NET(vdev); struct virtio_net_config netcfg; + int ret =3D 0; + memset(&netcfg, 0 , sizeof(struct virtio_net_config)); =20 virtio_stw_p(vdev, &netcfg.status, n->status); virtio_stw_p(vdev, &netcfg.max_virtqueue_pairs, n->max_queues); @@ -139,13 +142,21 @@ static void virtio_net_get_config(VirtIODevice *vdev,= uint8_t *config) virtio_stl_p(vdev, &netcfg.speed, n->net_conf.speed); netcfg.duplex =3D n->net_conf.duplex; memcpy(config, &netcfg, n->config_size); + NetClientState *nc =3D qemu_get_queue(n->nic); + if (nc->peer->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA) { + ret =3D vhost_net_get_config(get_vhost_net(nc->peer), (uint8_t *)&= netcfg, + n->config_size); + if (ret !=3D -1) { + memcpy(config, &netcfg, n->config_size); + } + } } =20 static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *confi= g) { VirtIONet *n =3D VIRTIO_NET(vdev); + NetClientState *nc =3D qemu_get_queue(n->nic); struct virtio_net_config netcfg =3D {}; - memcpy(&netcfg, config, n->config_size); =20 if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_MAC_ADDR) && @@ -154,6 +165,11 @@ static void virtio_net_set_config(VirtIODevice *vdev, = const uint8_t *config) memcpy(n->mac, netcfg.mac, ETH_ALEN); qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac); } + if (nc->peer->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA) { + vhost_net_set_config(get_vhost_net(nc->peer), (uint8_t *)&netcfg, + 0, n->config_size, + VHOST_SET_CONFIG_TYPE_MASTER); + } } =20 static bool virtio_net_started(VirtIONet *n, uint8_t status) @@ -2958,7 +2974,6 @@ static void virtio_net_device_realize(DeviceState *de= v, Error **errp) } else if (n->net_conf.speed >=3D 0) { n->host_features |=3D (1ULL << VIRTIO_NET_F_SPEED_DUPLEX); } - if (n->failover) { n->primary_listener.should_be_hidden =3D virtio_net_primary_should_be_hidden; diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index 4e4d39a0a4..6b1b1a5fce 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -5,6 +5,7 @@ obj-y +=3D virtio.o obj-$(CONFIG_VHOST) +=3D vhost.o vhost-backend.o common-obj-$(call lnot,$(CONFIG_VHOST)) +=3D vhost-stub.o obj-$(CONFIG_VHOST_USER) +=3D vhost-user.o +obj-$(CONFIG_VHOST_VDPA) +=3D vhost-vdpa.o =20 common-obj-$(CONFIG_VIRTIO_RNG) +=3D virtio-rng.o common-obj-$(CONFIG_VIRTIO_PCI) +=3D virtio-pci.o diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index 660e9e8588..84e5b1a833 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -14,7 +14,7 @@ #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "standard-headers/linux/vhost_types.h" - +#include "hw/virtio/vhost-vdpa.h" #ifdef CONFIG_VHOST_KERNEL #include #include @@ -22,10 +22,19 @@ static int vhost_kernel_call(struct vhost_dev *dev, unsigned long int requ= est, void *arg) { - int fd =3D (uintptr_t) dev->opaque; - - assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_KERNEL); + int fd =3D -1; + switch (dev->vhost_ops->backend_type) { + case VHOST_BACKEND_TYPE_KERNEL: + fd =3D (uintptr_t)dev->opaque; + break; + case VHOST_BACKEND_TYPE_VDPA: + fd =3D ((struct vhost_vdpa *)dev->opaque)->device_fd; + break; + default: + g_assert_not_reached(); + } =20 + assert(fd !=3D -1); return ioctl(fd, request, arg); } =20 @@ -285,6 +294,11 @@ int vhost_set_backend_type(struct vhost_dev *dev, Vhos= tBackendType backend_type) case VHOST_BACKEND_TYPE_USER: dev->vhost_ops =3D &user_ops; break; +#endif +#ifdef CONFIG_VHOST_VDPA + case VHOST_BACKEND_TYPE_VDPA: + dev->vhost_ops =3D &vdpa_ops; + break; #endif default: error_report("Unknown vhost backend type"); diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c new file mode 100644 index 0000000000..1724d404ce --- /dev/null +++ b/hw/virtio/vhost-vdpa.c @@ -0,0 +1,406 @@ +/* + * vhost-vdpa + * + * Copyright(c) 2017-2018 Intel Corporation. + * Copyright(c) 2020 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include +#include +#include +#include +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-backend.h" +#include "hw/virtio/virtio-net.h" +#include "hw/virtio/vhost-vdpa.h" +#include "qemu/main-loop.h" +#include +#include "sysemu/kvm.h" + + +static bool vhost_vdpa_listener_skipped_section(MemoryRegionSection *secti= on) +{ + return (!memory_region_is_ram(section->mr) && + !memory_region_is_iommu(section->mr)) || + /* + * Sizing an enabled 64-bit BAR can cause spurious mappings to + * addresses in the upper part of the 64-bit address space. Th= ese + * are never accessed by the CPU and beyond the address width of + * some IOMMU hardware. TODO: VDPA should tell us the IOMMU wi= dth. + */ + section->offset_within_address_space & (1ULL << 63); +} + +static int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr si= ze, + void *vaddr, bool readonly) +{ + struct vhost_msg_v2 msg; + int fd =3D v->device_fd; + int ret =3D 0; + + msg.type =3D v->msg_type; + msg.iotlb.iova =3D iova; + msg.iotlb.size =3D size; + msg.iotlb.uaddr =3D (uint64_t)vaddr; + msg.iotlb.perm =3D readonly ? VHOST_ACCESS_RO : VHOST_ACCESS_RW; + msg.iotlb.type =3D VHOST_IOTLB_UPDATE; + + if (write(fd, &msg, sizeof(msg)) !=3D sizeof(msg)) { + error_report("failed to write, fd=3D%d, errno=3D%d (%s)", + fd, errno, strerror(errno)); + return -EIO ; + } + + return ret; +} + +static int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova, + hwaddr size) +{ + struct vhost_msg_v2 msg; + int fd =3D v->device_fd; + int ret =3D 0; + + msg.type =3D v->msg_type; + msg.iotlb.iova =3D iova; + msg.iotlb.size =3D size; + msg.iotlb.type =3D VHOST_IOTLB_INVALIDATE; + + if (write(fd, &msg, sizeof(msg)) !=3D sizeof(msg)) { + error_report("failed to write, fd=3D%d, errno=3D%d (%s)", + fd, errno, strerror(errno)); + return -EIO ; + } + + return ret; +} + +static void vhost_vdpa_listener_region_add(MemoryListener *listener, + MemoryRegionSection *section) +{ + struct vhost_vdpa *v =3D container_of(listener, struct vhost_vdpa, lis= tener); + hwaddr iova; + Int128 llend, llsize; + void *vaddr; + int ret; + + if (vhost_vdpa_listener_skipped_section(section)) { + return; + } + + if (unlikely((section->offset_within_address_space & ~TARGET_PAGE_MASK= ) !=3D + (section->offset_within_region & ~TARGET_PAGE_MASK))) { + error_report("%s received unaligned region", __func__); + return; + } + + iova =3D TARGET_PAGE_ALIGN(section->offset_within_address_space); + llend =3D int128_make64(section->offset_within_address_space); + llend =3D int128_add(llend, section->size); + llend =3D int128_and(llend, int128_exts64(TARGET_PAGE_MASK)); + + if (int128_ge(int128_make64(iova), llend)) { + return; + } + + memory_region_ref(section->mr); + + /* Here we assume that memory_region_is_ram(section->mr)=3D=3Dtrue */ + + vaddr =3D memory_region_get_ram_ptr(section->mr) + + section->offset_within_region + + (iova - section->offset_within_address_space); + + llsize =3D int128_sub(llend, int128_make64(iova)); + + ret =3D vhost_vdpa_dma_map(v, iova, int128_get64(llsize), + vaddr, section->readonly); + if (ret) { + error_report("vhost vdpa map fail!"); + if (memory_region_is_ram_device(section->mr)) { + /* Allow unexpected mappings not to be fatal for RAM devices */ + error_report("map ram fail!"); + return ; + } + goto fail; + } + + return; + +fail: + if (memory_region_is_ram_device(section->mr)) { + error_report("failed to vdpa_dma_map. pci p2p may not work"); + return; + + } + /* + * On the initfn path, store the first error in the container so we + * can gracefully fail. Runtime, there's not much we can do other + * than throw a hardware error. + */ + error_report("vhost-vdpa: DMA mapping failed, unable to continue"); + return; + +} + +static void vhost_vdpa_listener_region_del(MemoryListener *listener, + MemoryRegionSection *section) +{ + struct vhost_vdpa *v =3D container_of(listener, struct vhost_vdpa, lis= tener); + hwaddr iova; + Int128 llend, llsize; + int ret; + bool try_unmap =3D true; + + if (vhost_vdpa_listener_skipped_section(section)) { + return; + } + + if (unlikely((section->offset_within_address_space & ~TARGET_PAGE_MASK= ) !=3D + (section->offset_within_region & ~TARGET_PAGE_MASK))) { + error_report("%s received unaligned region", __func__); + return; + } + + iova =3D TARGET_PAGE_ALIGN(section->offset_within_address_space); + llend =3D int128_make64(section->offset_within_address_space); + llend =3D int128_add(llend, section->size); + llend =3D int128_and(llend, int128_exts64(TARGET_PAGE_MASK)); + + if (int128_ge(int128_make64(iova), llend)) { + return; + } + + llsize =3D int128_sub(llend, int128_make64(iova)); + + if (try_unmap) { + ret =3D vhost_vdpa_dma_unmap(v, iova, int128_get64(llsize)); + if (ret) { + error_report("vhost_vdpa dma unmap error!"); + } + } + + memory_region_unref(section->mr); +} +/* + * IOTLB API is used by vhost-vpda which requires incremental updating + * of the mapping. So we can not use generic vhost memory listener which + * depends on the addnop(). + */ +static const MemoryListener vhost_vdpa_memory_listener =3D { + .region_add =3D vhost_vdpa_listener_region_add, + .region_del =3D vhost_vdpa_listener_region_del, +}; + +static int vhost_vdpa_call(struct vhost_dev *dev, unsigned long int reques= t, + void *arg) +{ + struct vhost_vdpa *v =3D dev->opaque; + int fd =3D v->device_fd; + + assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA); + + return ioctl(fd, request, arg); +} + +static void vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status) +{ + uint8_t s; + + if (vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &s)) { + return; + } + + s |=3D status; + + vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &s); +} + +static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque) +{ + struct vhost_vdpa *v; + uint64_t features; + assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA); + + v =3D opaque; + dev->opaque =3D opaque ; + vhost_vdpa_call(dev, VHOST_GET_FEATURES, &features); + dev->backend_features =3D features; + v->listener =3D vhost_vdpa_memory_listener; + v->msg_type =3D VHOST_IOTLB_MSG_V2; + + vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | + VIRTIO_CONFIG_S_DRIVER); + + return 0; +} + +static int vhost_vdpa_cleanup(struct vhost_dev *dev) +{ + struct vhost_vdpa *v; + assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA); + v =3D dev->opaque; + memory_listener_unregister(&v->listener); + + dev->opaque =3D NULL; + return 0; +} + +static int vhost_vdpa_memslots_limit(struct vhost_dev *dev) +{ + return INT_MAX; +} + +static int vhost_vdpa_set_mem_table(struct vhost_dev *dev, + struct vhost_memory *mem) +{ + + if (mem->padding) { + return -1; + } + + return 0; +} + +static int vhost_vdpa_set_features(struct vhost_dev *dev, + uint64_t features) +{ + int ret; + ret =3D vhost_vdpa_call(dev, VHOST_SET_FEATURES, &features); + uint8_t status =3D 0; + if (ret) { + return ret; + } + vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK); + vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status); + + return !(status & VIRTIO_CONFIG_S_FEATURES_OK); +} + +int vhost_vdpa_get_device_id(struct vhost_dev *dev, + uint32_t *device_id) +{ + return vhost_vdpa_call(dev, VHOST_VDPA_GET_DEVICE_ID, device_id); +} + +static int vhost_vdpa_reset_device(struct vhost_dev *dev) +{ + uint8_t status =3D 0; + + return vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &status); +} + +static int vhost_vdpa_get_vq_index(struct vhost_dev *dev, int idx) +{ + assert(idx >=3D dev->vq_index && idx < dev->vq_index + dev->nvqs); + + return idx - dev->vq_index; +} + +static int vhost_vdpa_set_vring_ready(struct vhost_dev *dev) +{ + int i; + for (i =3D 0; i < dev->nvqs; ++i) { + struct vhost_vring_state state =3D { + .index =3D dev->vq_index + i, + .num =3D 1, + }; + vhost_vdpa_call(dev, VHOST_VDPA_SET_VRING_ENABLE, &state); + } + return 0; +} + +static int vhost_vdpa_set_config(struct vhost_dev *dev, const uint8_t *dat= a, + uint32_t offset, uint32_t size, + uint32_t flags) +{ + struct vhost_vdpa_config *config; + int ret; + unsigned long config_size =3D offsetof(struct vhost_vdpa_config, buf); + config =3D g_malloc(size + config_size); + if (config =3D=3D NULL) { + return -1; + } + config->off =3D offset; + config->len =3D size; + memcpy(config->buf, data, size); + ret =3D vhost_vdpa_call(dev, VHOST_VDPA_SET_CONFIG, config); + g_free(config); + return ret; +} + +static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, + uint32_t config_len) +{ + struct vhost_vdpa_config *v_config; + unsigned long config_size =3D offsetof(struct vhost_vdpa_config, buf); + int ret; + + v_config =3D g_malloc(config_len + config_size); + if (v_config =3D=3D NULL) { + return -1; + } + v_config->len =3D config_len; + v_config->off =3D 0; + ret =3D vhost_vdpa_call(dev, VHOST_VDPA_GET_CONFIG, v_config); + memcpy(config, v_config->buf, config_len); + g_free(v_config); + return ret; + } + +static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) +{ + struct vhost_vdpa *v =3D dev->opaque; + if (started) { + uint8_t status =3D 0; + memory_listener_register(&v->listener, &address_space_memory); + vhost_vdpa_set_vring_ready(dev); + vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK); + vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status); + + return !(status & VIRTIO_CONFIG_S_DRIVER_OK); + } else { + vhost_vdpa_reset_device(dev); + vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | + VIRTIO_CONFIG_S_DRIVER); + memory_listener_unregister(&v->listener); + + return 0; + } +} + +const VhostOps vdpa_ops =3D { + .backend_type =3D VHOST_BACKEND_TYPE_VDPA, + .vhost_backend_init =3D vhost_vdpa_init, + .vhost_backend_cleanup =3D vhost_vdpa_cleanup, + .vhost_set_log_base =3D vhost_kernel_set_log_base, + .vhost_set_vring_addr =3D vhost_kernel_set_vring_addr, + .vhost_set_vring_num =3D vhost_kernel_set_vring_num, + .vhost_set_vring_base =3D vhost_kernel_set_vring_base, + .vhost_get_vring_base =3D vhost_kernel_get_vring_base, + .vhost_set_vring_kick =3D vhost_kernel_set_vring_kick, + .vhost_set_vring_call =3D vhost_kernel_set_vring_call, + .vhost_get_features =3D vhost_kernel_get_features, + .vhost_set_owner =3D vhost_kernel_set_owner, + .vhost_set_vring_endian =3D NULL, + .vhost_backend_memslots_limit =3D vhost_vdpa_memslots_limit, + .vhost_set_mem_table =3D vhost_vdpa_set_mem_table, + .vhost_set_features =3D vhost_vdpa_set_features, + .vhost_reset_device =3D vhost_vdpa_reset_device, + .vhost_get_vq_index =3D vhost_vdpa_get_vq_index, + .vhost_get_config =3D vhost_vdpa_get_config, + .vhost_set_config =3D vhost_vdpa_set_config, + .vhost_requires_shm_log =3D NULL, + .vhost_migration_done =3D NULL, + .vhost_backend_can_merge =3D NULL, + .vhost_net_set_mtu =3D NULL, + .vhost_set_iotlb_callback =3D NULL, + .vhost_send_device_iotlb_msg =3D NULL, + .vhost_dev_start =3D vhost_vdpa_dev_start, + .vhost_get_device_id =3D vhost_vdpa_get_device_id, +}; diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index bfd7f9ce1f..a75be7216b 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -744,19 +744,34 @@ static void vhost_iommu_region_del(MemoryListener *li= stener, } } =20 +static void vhost_virtqueue_get_addr(struct vhost_dev *dev, + struct vhost_vring_addr *addr, + struct vhost_virtqueue *vq) +{ + /*vDPA need to use the IOVA here to set to hardware*/ + if (dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA) { + addr->desc_user_addr =3D (uint64_t)(unsigned long)vq->desc_phys; + addr->avail_user_addr =3D (uint64_t)(unsigned long)vq->avail_phys; + addr->used_user_addr =3D (uint64_t)(unsigned long)vq->used_phys; + } else { + addr->desc_user_addr =3D (uint64_t)(unsigned long)vq->desc; + addr->avail_user_addr =3D (uint64_t)(unsigned long)vq->avail; + addr->used_user_addr =3D (uint64_t)(unsigned long)vq->used; + } +} =20 static int vhost_virtqueue_set_addr(struct vhost_dev *dev, struct vhost_virtqueue *vq, unsigned idx, bool enable_log) { - struct vhost_vring_addr addr =3D { - .index =3D idx, - .desc_user_addr =3D (uint64_t)(unsigned long)vq->desc, - .avail_user_addr =3D (uint64_t)(unsigned long)vq->avail, - .used_user_addr =3D (uint64_t)(unsigned long)vq->used, - .log_guest_addr =3D vq->used_phys, - .flags =3D enable_log ? (1 << VHOST_VRING_F_LOG) : 0, - }; + struct vhost_vring_addr addr; + memset(&addr, 0, sizeof(struct vhost_vring_addr)); + + vhost_virtqueue_get_addr(dev, &addr, vq); + addr.index =3D idx; + addr .log_guest_addr =3D vq->used_phys; + addr .flags =3D enable_log ? (1 << VHOST_VRING_F_LOG) : 0; + int r =3D dev->vhost_ops->vhost_set_vring_addr(dev, &addr); if (r < 0) { VHOST_OPS_DEBUG("vhost_set_vring_addr failed"); @@ -774,7 +789,9 @@ static int vhost_dev_set_features(struct vhost_dev *dev, features |=3D 0x1ULL << VHOST_F_LOG_ALL; } if (!vhost_dev_has_iommu(dev)) { - features &=3D ~(0x1ULL << VIRTIO_F_IOMMU_PLATFORM); + if (dev->vhost_ops->backend_type !=3D VHOST_BACKEND_TYPE_VDPA) { + features &=3D ~(0x1ULL << VIRTIO_F_IOMMU_PLATFORM); + } } r =3D dev->vhost_ops->vhost_set_features(dev, features); if (r < 0) { @@ -1667,7 +1684,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODev= ice *vdev) goto fail_log; } =20 - if (vhost_dev_has_iommu(hdev)) { + if (vhost_dev_has_iommu(hdev) && + hdev->vhost_ops->vhost_set_iotlb_callback) { hdev->vhost_ops->vhost_set_iotlb_callback(hdev, true); =20 /* Update used ring information for IOTLB to work correctly, @@ -1713,7 +1731,9 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODev= ice *vdev) } =20 if (vhost_dev_has_iommu(hdev)) { - hdev->vhost_ops->vhost_set_iotlb_callback(hdev, false); + if (hdev->vhost_ops->vhost_set_iotlb_callback) { + hdev->vhost_ops->vhost_set_iotlb_callback(hdev, false); + } memory_listener_unregister(&hdev->iommu_listener); } vhost_log_put(hdev, true); diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-ba= ckend.h index c1384bd2c7..c418c2fa0e 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -17,7 +17,8 @@ typedef enum VhostBackendType { VHOST_BACKEND_TYPE_NONE =3D 0, VHOST_BACKEND_TYPE_KERNEL =3D 1, VHOST_BACKEND_TYPE_USER =3D 2, - VHOST_BACKEND_TYPE_MAX =3D 3, + VHOST_BACKEND_TYPE_VDPA =3D 3, + VHOST_BACKEND_TYPE_MAX =3D 4, } VhostBackendType; =20 typedef enum VhostSetConfigType { @@ -113,6 +114,7 @@ typedef int (*vhost_set_inflight_fd_op)(struct vhost_de= v *dev, struct vhost_inflight *inflight); =20 typedef int (*vhost_dev_start_op)(struct vhost_dev *dev, bool started); +typedef int (*vhost_get_device_id_op)(struct vhost_dev *dev, uint32_t *dev= _id); typedef struct VhostOps { VhostBackendType backend_type; vhost_backend_init vhost_backend_init; @@ -154,9 +156,11 @@ typedef struct VhostOps { vhost_get_inflight_fd_op vhost_get_inflight_fd; vhost_set_inflight_fd_op vhost_set_inflight_fd; vhost_dev_start_op vhost_dev_start; + vhost_get_device_id_op vhost_get_device_id; } VhostOps; =20 extern const VhostOps user_ops; +extern const VhostOps vdpa_ops; =20 int vhost_set_backend_type(struct vhost_dev *dev, VhostBackendType backend_type); diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h new file mode 100644 index 0000000000..6455663388 --- /dev/null +++ b/include/hw/virtio/vhost-vdpa.h @@ -0,0 +1,26 @@ +/* + * vhost-vdpa.h + * + * Copyright(c) 2017-2018 Intel Corporation. + * Copyright(c) 2020 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef HW_VIRTIO_VHOST_VDPA_H +#define HW_VIRTIO_VHOST_VDPA_H + +#include "hw/virtio/virtio.h" + +typedef struct vhost_vdpa { + int device_fd; + uint32_t msg_type; + MemoryListener listener; +} VhostVDPA; + +extern AddressSpace address_space_memory; +extern int vhost_vdpa_get_device_id(struct vhost_dev *dev, + uint32_t *device_id); +#endif diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 59ea53f8c2..f69b5e4a02 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -92,6 +92,12 @@ struct vhost_dev { const VhostDevConfigOps *config_ops; }; =20 +struct vhost_net { + struct vhost_dev dev; + struct vhost_virtqueue vqs[2]; + int backend; + NetClientState *nc; +}; =20 int vhost_dev_init(struct vhost_dev *hdev, void *opaque, VhostBackendType backend_type, diff --git a/qemu-options.hx b/qemu-options.hx index 292d4e7c0c..d7d0daaa0e 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2409,6 +2409,10 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, #ifdef CONFIG_POSIX "-netdev vhost-user,id=3Dstr,chardev=3Ddev[,vhostforce=3Don|off]\n" " configure a vhost-user network, backed by a chardev '= dev'\n" +#endif +#ifdef __linux__ + "-netdev vhost-vdpa,id=3Dstr,vhostdev=3D/path/to/dev\n" + " configure a vhost-vdpa network,Establish a vhost-vdpa= netdev\n" #endif "-netdev hubport,id=3Dstr,hubid=3Dn[,netdev=3Dnd]\n" " configure a hub port on the hub with ID 'n'\n", QEMU_= ARCH_ALL) @@ -2888,6 +2892,14 @@ SRST -netdev type=3Dvhost-user,id=3Dnet0,chardev=3Dchr0 \ -device virtio-net-pci,netdev=3Dnet0 =20 +``-netdev vhost-vdpa,vhostdev=3D/path/to/dev`` + Establish a vhost-vdpa netdev. + + vDPA device is a device that uses a datapath which complies with + the virtio specifications with a vendor specific control path. + vDPA devices can be both physically located on the hardware or + emulated by software. + ``-netdev hubport,id=3Did,hubid=3Dhubid[,netdev=3Dnd]`` Create a hub port on the emulated hub with ID hubid. =20 --=20 2.21.1 From nobody Mon Apr 29 11:45:46 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 ARC-Seal: i=1; a=rsa-sha256; t=1592840776; cv=none; d=zohomail.com; s=zohoarc; b=ZnskktS4Ha8qlIzYQ30n6EutqajwmIx9egbi8ciUwmC6A5DgOh+kSTRt8r1YZ52oK4L1/SEsfh+0UmvNgGzdeM+8WK1uj4dmtTNq9Q0PAxfriH1mqDec8vkhfO5oaJnDg+H0ZMIFQxZi1yqOKBRu7lUHcWiSAboZQLqqznEYwlE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592840776; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ed5cRZQpVXqodRrRXUHt8nUg0Ktblv13hJI5gLz52HM=; b=R++j2YeVlzigIhphAv/3/ss01lSzGSSZyacxewJYVyfDXyiO8noyyQikJZtLYh97rKZi329TFEEREa3PuvPEsI+QI4s/1aJdaAvQ9NdbrSUyFlbqioAgXJ6y7X92yLrUdH6N4oSgXMIKF23GWDKaLc/wZ1KshO9+yCptHbLFk4Q= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1592840776573977.1497670228698; Mon, 22 Jun 2020 08:46:16 -0700 (PDT) Received: from localhost ([::1]:35470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jnOeE-0006wG-UW for importer@patchew.org; Mon, 22 Jun 2020 11:46:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jnOaZ-00027a-H1 for qemu-devel@nongnu.org; Mon, 22 Jun 2020 11:42:27 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:20373 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jnOaX-00049P-9p for qemu-devel@nongnu.org; Mon, 22 Jun 2020 11:42:27 -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-12-MUEGPSteOKOfsIXN8LjDbw-1; Mon, 22 Jun 2020 11:42:22 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A2539872FF0; Mon, 22 Jun 2020 15:42:19 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-110.pek2.redhat.com [10.72.13.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22DE971677; Mon, 22 Jun 2020 15:42:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592840544; 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=ed5cRZQpVXqodRrRXUHt8nUg0Ktblv13hJI5gLz52HM=; b=ivdOrHc4f09cmXFba7yCeHUiCyCThSRFxIpc79QfUm+6jOqwPMvkU0P5SIhcCnp98k/JNy cA7xwMzbg64JHxfPXU8dXhzL6N5kBiHF17lYlqLKpbJppPP43stJ4FXYjhZe9rwRJeLMyW I/9pwXfRiqlzkNy8C7Zvvr7EWat7x4I= X-MC-Unique: MUEGPSteOKOfsIXN8LjDbw-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [PATCH v1 10/10] vhost-vdpa: introduce vhost-vdpa net client Date: Mon, 22 Jun 2020 23:37:56 +0800 Message-Id: <20200622153756.19189-11-lulu@redhat.com> In-Reply-To: <20200622153756.19189-1-lulu@redhat.com> References: <20200622153756.19189-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lulu@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=205.139.110.61; envelope-from=lulu@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/22 03:17:49 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: mhabets@solarflare.com, qemu-devel@nongnu.org, rob.miller@broadcom.com, saugatm@xilinx.com, lulu@redhat.com, hanand@xilinx.com, hch@infradead.org, eperezma@redhat.com, jgg@mellanox.com, shahafs@mellanox.com, kevin.tian@intel.com, parav@mellanox.com, vmireyno@marvell.com, cunming.liang@intel.com, gdawar@xilinx.com, jiri@mellanox.com, xiao.w.wang@intel.com, stefanha@redhat.com, zhihong.wang@intel.com, Tiwei Bie , aadam@redhat.com, rdunlap@infradead.org, maxime.coquelin@redhat.com, lingshan.zhu@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This patch set introduces a new net client type: vhost-vdpa. vhost-vdpa net client will set up a vDPA device which is specified by a "vhostdev" parameter. Signed-off-by: Lingshan Zhu Signed-off-by: Tiwei Bie Signed-off-by: Cindy Lu --- include/net/vhost-vdpa.h | 21 ++++ include/net/vhost_net.h | 1 - net/Makefile.objs | 2 +- net/clients.h | 2 + net/net.c | 3 + net/vhost-vdpa.c | 230 +++++++++++++++++++++++++++++++++++++++ qapi/net.json | 23 +++- 7 files changed, 278 insertions(+), 4 deletions(-) create mode 100644 include/net/vhost-vdpa.h create mode 100644 net/vhost-vdpa.c diff --git a/include/net/vhost-vdpa.h b/include/net/vhost-vdpa.h new file mode 100644 index 0000000000..725c8b1c81 --- /dev/null +++ b/include/net/vhost-vdpa.h @@ -0,0 +1,21 @@ +/* + * vhost-vdpa.h + * + * Copyright(c) 2017-2018 Intel Corporation. + * Copyright(c) 2020 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef VHOST_VDPA_H +#define VHOST_VDPA_H + +struct vhost_net; +struct vhost_net *vhost_vdpa_get_vhost_net(NetClientState *nc); +uint64_t vhost_vdpa_get_acked_features(NetClientState *nc); + +extern const int vdpa_feature_bits[]; + +#endif /* VHOST_VDPA_H */ diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index abfb0e8e68..4843cdb36f 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -44,5 +44,4 @@ int vhost_set_vring_enable(NetClientState * nc, int enabl= e); uint64_t vhost_net_get_acked_features(VHostNetState *net); =20 int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu); - #endif diff --git a/net/Makefile.objs b/net/Makefile.objs index c5d076d19c..5ab45545db 100644 --- a/net/Makefile.objs +++ b/net/Makefile.objs @@ -26,7 +26,7 @@ tap-obj-$(CONFIG_SOLARIS) =3D tap-solaris.o tap-obj-y ?=3D tap-stub.o common-obj-$(CONFIG_POSIX) +=3D tap.o $(tap-obj-y) common-obj-$(CONFIG_WIN32) +=3D tap-win32.o - +common-obj-$(CONFIG_VHOST_NET_VDPA) +=3D vhost-vdpa.o vde.o-libs =3D $(VDE_LIBS) =20 common-obj-$(CONFIG_CAN_BUS) +=3D can/ diff --git a/net/clients.h b/net/clients.h index a6ef267e19..92f9b59aed 100644 --- a/net/clients.h +++ b/net/clients.h @@ -61,4 +61,6 @@ int net_init_netmap(const Netdev *netdev, const char *nam= e, int net_init_vhost_user(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp); =20 +int net_init_vhost_vdpa(const Netdev *netdev, const char *name, + NetClientState *peer, Error **errp); #endif /* QEMU_NET_CLIENTS_H */ diff --git a/net/net.c b/net/net.c index 599fb61028..82624ea9ac 100644 --- a/net/net.c +++ b/net/net.c @@ -965,6 +965,9 @@ static int (* const net_client_init_fun[NET_CLIENT_DRIV= ER__MAX])( #ifdef CONFIG_VHOST_NET_USER [NET_CLIENT_DRIVER_VHOST_USER] =3D net_init_vhost_user, #endif +#ifdef CONFIG_VHOST_NET_VDPA + [NET_CLIENT_DRIVER_VHOST_VDPA] =3D net_init_vhost_vdpa, +#endif #ifdef CONFIG_L2TPV3 [NET_CLIENT_DRIVER_L2TPV3] =3D net_init_l2tpv3, #endif diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c new file mode 100644 index 0000000000..34858a6ea3 --- /dev/null +++ b/net/vhost-vdpa.c @@ -0,0 +1,230 @@ +/* + * vhost-vdpa.c + * + * Copyright(c) 2017-2018 Intel Corporation. + * Copyright(c) 2020 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "clients.h" +#include "net/vhost_net.h" +#include "net/vhost-vdpa.h" +#include "hw/virtio/vhost-vdpa.h" +#include "qemu/config-file.h" +#include "qemu/error-report.h" +#include "qemu/option.h" +#include "qapi/error.h" +#include +#include +#include "standard-headers/linux/virtio_net.h" +#include "monitor/monitor.h" +#include "hw/virtio/vhost.h" + +/* Todo:need to add the multiqueue support here */ +typedef struct VhostVDPAState { + NetClientState nc; + struct vhost_vdpa vhost_vdpa; + VHostNetState *vhost_net; + uint64_t acked_features; + bool started; +} VhostVDPAState; + +const int vdpa_feature_bits[] =3D { + VIRTIO_F_NOTIFY_ON_EMPTY, + VIRTIO_RING_F_INDIRECT_DESC, + VIRTIO_RING_F_EVENT_IDX, + VIRTIO_F_ANY_LAYOUT, + VIRTIO_F_VERSION_1, + VIRTIO_NET_F_CSUM, + VIRTIO_NET_F_GUEST_CSUM, + VIRTIO_NET_F_GSO, + VIRTIO_NET_F_GUEST_TSO4, + VIRTIO_NET_F_GUEST_TSO6, + VIRTIO_NET_F_GUEST_ECN, + VIRTIO_NET_F_GUEST_UFO, + VIRTIO_NET_F_HOST_TSO4, + VIRTIO_NET_F_HOST_TSO6, + VIRTIO_NET_F_HOST_ECN, + VIRTIO_NET_F_HOST_UFO, + VIRTIO_NET_F_MRG_RXBUF, + VIRTIO_NET_F_MTU, + VIRTIO_F_IOMMU_PLATFORM, + VIRTIO_F_RING_PACKED, + VIRTIO_NET_F_GUEST_ANNOUNCE, + VHOST_INVALID_FEATURE_BIT +}; + +VHostNetState *vhost_vdpa_get_vhost_net(NetClientState *nc) +{ + VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); + assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); + return s->vhost_net; +} + +uint64_t vhost_vdpa_get_acked_features(NetClientState *nc) +{ + VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); + assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); + s->acked_features =3D vhost_net_get_acked_features(s->vhost_net); + + return s->acked_features; +} + +static int vhost_vdpa_net_check_device_id(NetClientState *nc) +{ + uint32_t device_id; + int ret; + struct vhost_net *net; + struct vhost_dev *hdev; + assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); + VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); + net =3D s->vhost_net; + hdev =3D (struct vhost_dev *)&net->dev; + ret =3D hdev->vhost_ops->vhost_get_device_id(hdev, &device_id); + if (device_id !=3D VIRTIO_ID_NET) { + return -ENOTSUP; + } + return ret; +} + +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; + struct vhost_net *net =3D NULL; + VhostVDPAState *s; + int ret; + + options.backend_type =3D VHOST_BACKEND_TYPE_VDPA; + assert(ncs->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); + s =3D DO_UPCAST(VhostVDPAState, nc, ncs); + options.net_backend =3D ncs; + options.opaque =3D be; + options.busyloop_timeout =3D 0; + net =3D vhost_net_init(&options); + if (!net) { + 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(ncs); + if (ret) { + goto err; + } + return 0; +err: + if (net) { + vhost_net_cleanup(net); + } + vhost_vdpa_del(ncs); + return -1; +} + +static void vhost_vdpa_cleanup(NetClientState *nc) +{ + VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); + + if (s->vhost_net) { + vhost_net_cleanup(s->vhost_net); + g_free(s->vhost_net); + s->vhost_net =3D NULL; + } +} + +static bool vhost_vdpa_has_vnet_hdr(NetClientState *nc) +{ + assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); + + return true; +} + +static bool vhost_vdpa_has_ufo(NetClientState *nc) +{ + assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); + VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); + uint64_t features =3D 0; + features |=3D (1ULL << VIRTIO_NET_F_HOST_UFO); + features =3D vhost_net_get_features(s->vhost_net, features); + return !!(features & (1ULL << VIRTIO_NET_F_HOST_UFO)); + +} + +static NetClientInfo net_vhost_vdpa_info =3D { + .type =3D NET_CLIENT_DRIVER_VHOST_VDPA, + .size =3D sizeof(VhostVDPAState), + .cleanup =3D vhost_vdpa_cleanup, + .has_vnet_hdr =3D vhost_vdpa_has_vnet_hdr, + .has_ufo =3D vhost_vdpa_has_ufo, +}; + +static int net_vhost_vdpa_init(NetClientState *peer, const char *device, + const char *name, const char *vhostdev) +{ + 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), "vhost-vdpa"); + nc->queue_index =3D 0; + s =3D DO_UPCAST(VhostVDPAState, nc, nc); + vdpa_device_fd =3D qemu_open(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); + assert(s->vhost_net); + return ret; +} + +static int net_vhost_check_net(void *opaque, QemuOpts *opts, Error **errp) +{ + const char *name =3D opaque; + const char *driver, *netdev; + + driver =3D qemu_opt_get(opts, "driver"); + netdev =3D qemu_opt_get(opts, "netdev"); + if (!driver || !netdev) { + return 0; + } + if (strcmp(netdev, name) =3D=3D 0 && + !g_str_has_prefix(driver, "virtio-net-")) { + error_setg(errp, "vhost-vdpa requires frontend driver virtio-net-*= "); + return -1; + } + return 0; +} + +int net_init_vhost_vdpa(const Netdev *netdev, const char *name, + NetClientState *peer, Error **errp) +{ + const NetdevVhostVDPAOptions *opts; + + assert(netdev->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); + opts =3D &netdev->u.vhost_vdpa; + /* verify net frontend */ + if (qemu_opts_foreach(qemu_find_opts("device"), net_vhost_check_net, + (char *)name, errp)) { + return -1; + } + return net_vhost_vdpa_init(peer, "vhost_vdpa", name, opts->vhostdev); +} diff --git a/qapi/net.json b/qapi/net.json index cebb1b52e3..03aad67693 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -428,6 +428,24 @@ '*vhostforce': 'bool', '*queues': 'int' } } =20 +## +# @NetdevVhostVDPAOptions: +# +# Vhost-vdpa network backend +# +# @vhostdev: name of a vdpa dev path in sysfs +# (default path:/dev/vhost-vdpa-$ID) +# +# @queues: number of queues to be created for multiqueue vhost-vdpa +# (default: 1) +# +# Since: 5.1 +## +{ 'struct': 'NetdevVhostVDPAOptions', + 'data': { + '*vhostdev': 'str', + '*queues': 'int' } } + ## # @NetClientDriver: # @@ -437,7 +455,7 @@ ## { 'enum': 'NetClientDriver', 'data': [ 'none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'vde', - 'bridge', 'hubport', 'netmap', 'vhost-user' ] } + 'bridge', 'hubport', 'netmap', 'vhost-user', 'vhost-vdpa' ] } =20 ## # @Netdev: @@ -465,7 +483,8 @@ 'bridge': 'NetdevBridgeOptions', 'hubport': 'NetdevHubPortOptions', 'netmap': 'NetdevNetmapOptions', - 'vhost-user': 'NetdevVhostUserOptions' } } + 'vhost-user': 'NetdevVhostUserOptions', + 'vhost-vdpa': 'NetdevVhostVDPAOptions' } } =20 ## # @NetLegacy: --=20 2.21.1