From nobody Thu May 16 22:47:16 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=1590762253; cv=none; d=zohomail.com; s=zohoarc; b=A2YaRIcu+azc9K3LGrAnGVdm/F/fgJJsFPWu9+Oy0HEj/PJlx/vZE91wvY2Bz/7sye2l7kqZsx6oTGEDIhiykM4IPfC3iHh5ah6NSvAdTtlRbOGcB4VpTPtRPxo/UjcuidebhJrbCzw/ZSHeheFlvAvDWez4GtWJ+f3yE9Gua80= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590762253; 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=w/4lWWoOx6SYpHTQts4+3vcbP05xAWkBtChOqL3YfJs=; b=HkVxUyaGTDsKXzGCBH8VFDy4ZgfdTEgHcnGFpb/dPpviCn0mSGs9n6/oYl5ha12J9yAK1qXzkWOqygL9Mdeyb5KNuiKW9fMUABXAC3xs9XxWTMPlRwIILhPKV3ZZ3pZEpVxGCHzQZiGn7MrDGdJTAnV6sCfXuRfZnWO112+wmFY= 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 15907622536501007.8959340609589; Fri, 29 May 2020 07:24:13 -0700 (PDT) Received: from localhost ([::1]:57762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jefvg-0008UB-2X for importer@patchew.org; Fri, 29 May 2020 10:24:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jefg0-0000Za-Dn for qemu-devel@nongnu.org; Fri, 29 May 2020 10:08:00 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:25319 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 1jeffz-0004RR-GP for qemu-devel@nongnu.org; Fri, 29 May 2020 10:07:59 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-326-Z08-24pmO_qIGdIqQ-6eww-1; Fri, 29 May 2020 10:07:56 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EDF178014D4; Fri, 29 May 2020 14:07:53 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-84.pek2.redhat.com [10.72.13.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BD495D9F5; Fri, 29 May 2020 14:07:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590761278; 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=w/4lWWoOx6SYpHTQts4+3vcbP05xAWkBtChOqL3YfJs=; b=Z4LwR1wed4kWmfuDSIDFjMfTX742ISGx912XUdwvOojay4EOO+oXNGMHbMzVj47FmrxYzR elRrjhs69yno5heqc8SbQVXTCrcvGZjReTVdpeACQn2su/duxPy9j4vZ0KWbJxduTzHn67 7e/cCQbh0mifGrQ1RU9XM7vhvyzUjic= X-MC-Unique: Z08-24pmO_qIGdIqQ-6eww-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [RFC v3 1/8] net: introduce qemu_get_peer Date: Fri, 29 May 2020 22:06:13 +0800 Message-Id: <20200529140620.28759-2-lulu@redhat.com> In-Reply-To: <20200529140620.28759-1-lulu@redhat.com> References: <20200529140620.28759-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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/05/29 03:05:19 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-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 an= d 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 Thu May 16 22:47:16 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=1590762335; cv=none; d=zohomail.com; s=zohoarc; b=IlMlc0cePgSsns1fUxNE9KAAoe0HEszmKmlzzPEe0aLu2m/1AzMYmA67EktmqrnO2QI6rwNKOABgIY7/yXnNjTK8qI/jzGcbA5TfYgW1ACULIykPP8hhlwEf0CngFGEYerfSK6uHxUNcQ2NmeM/6loJOgNVKjdcd2d+tSbczSCA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590762335; 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=skuyGgsJUoIoU9Um/NUc1NTgtGUTH2qtntoWXyeA5eA=; b=nj9MLr7fh9vBN2oCCnbKQrj9ftyvGYL4TAMDHFWH8wFqfpusrzx/nA7qzB8y+u5oTiVaphQZjeJyv3pVwI1LZvMOaggcqLbZrUqy3lHgBfmxvvOWrSvIi0nsPRfqly0jMFVpU5+0nQ2wairppWQSe1p7LUCG5urF0zdPNo58VN0= 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 1590762335242684.3325775594615; Fri, 29 May 2020 07:25:35 -0700 (PDT) Received: from localhost ([::1]:35038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jefwz-0003Tt-PR for importer@patchew.org; Fri, 29 May 2020 10:25:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jefgX-0001eq-Li for qemu-devel@nongnu.org; Fri, 29 May 2020 10:08:33 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:37275 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 1jefgW-0004xu-Nw for qemu-devel@nongnu.org; Fri, 29 May 2020 10:08: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-186-CtKF3W6YM5Gzesq_o0oerw-1; Fri, 29 May 2020 10:08:30 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1EFD3876EE2; Fri, 29 May 2020 14:08:28 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-84.pek2.redhat.com [10.72.13.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E3E05D9F3; Fri, 29 May 2020 14:08:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590761312; 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=skuyGgsJUoIoU9Um/NUc1NTgtGUTH2qtntoWXyeA5eA=; b=PExvKm8nTBzDqSJa4QHvYLEGl9IRe0wl71aIm6sO0xzbmeeCkty0J9K1qWQLTFuoAld6bu OO8X9gw/zfC36D9rzmoYQZRDM+RGvNfY17hi5dWE4EdpUsdu7Iu3zgoQek5q6Tzdo/cpCI s/mXw6guH05Zbfewssfd5rVtG/wYrzE= X-MC-Unique: CtKF3W6YM5Gzesq_o0oerw-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [RFC v3 2/8] vhost_net: use the function qemu_get_peer Date: Fri, 29 May 2020 22:06:14 +0800 Message-Id: <20200529140620.28759-3-lulu@redhat.com> In-Reply-To: <20200529140620.28759-1-lulu@redhat.com> References: <20200529140620.28759-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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/05/29 03:05:19 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-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 --- hw/net/vhost_net.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 6b82803fa7..d1d421e3d9 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,7 +337,8 @@ 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; @@ -343,7 +346,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *= ncs, =20 if (ncs[i].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 Thu May 16 22:47:16 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=1590762480; cv=none; d=zohomail.com; s=zohoarc; b=UlqYMOoTrViDD5RfnJoZqCq1fpTkBfb5nIVBEOhZUmy+SXowOhqxlICEztmjOJA///XNlYaxGZhpOm49FadLjhSingNAwYAF4f4ttCwMMczA+uIyTT+YGcgwLiGWz4XtDhoyl9FrVl4nzTj0CRSSIHdXdoyejDKbdhltKGXWg6o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590762480; 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=3shp0XrYaKpb9hMzB2A57hUh8YA904iG+XnZeberkms=; b=XIU8KcT/g+GdktDA9AbrqRvk6q4rXpFjYrcjsXSb1+B5xoyTz8rF4Uj1Bdu8h+EMmaUC/YGlkdKBN8YMkmerJUV4Clt9bBb56zgelA+6x0UMSdoIadRKFtqS4FJbvbeuj35HKZsSJv2dEHY8DwIa+3A6j6i4UqvInuiUH6CJhmA= 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 1590762480235294.0471508453786; Fri, 29 May 2020 07:28:00 -0700 (PDT) Received: from localhost ([::1]:41414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jefzK-0006oF-P3 for importer@patchew.org; Fri, 29 May 2020 10:27:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55270) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jefhJ-0002xa-Ut for qemu-devel@nongnu.org; Fri, 29 May 2020 10:09:21 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:43331 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 1jefhJ-0005PI-2y for qemu-devel@nongnu.org; Fri, 29 May 2020 10:09:21 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-40-6vqfYBHnMPSWwvwsBr3REw-1; Fri, 29 May 2020 10:09:18 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C60E1052512; Fri, 29 May 2020 14:09:15 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-84.pek2.redhat.com [10.72.13.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id D46A55DA30; Fri, 29 May 2020 14:08:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590761360; 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=3shp0XrYaKpb9hMzB2A57hUh8YA904iG+XnZeberkms=; b=F8Tc+b8553pZkBazlPSFgW1x3miW/6whVtkdHwpMgVQbclpcENGfCK+YPafbvE+U26MMI4 JD4YEE51MwEFIxPr+WOm1pDMsQYWn66iN+b7hTZ+Czpv107PEcDnnxydXXww1SDpuFaauI YxArhK53LyLewrYsSysmKemy+mk6NGo= X-MC-Unique: 6vqfYBHnMPSWwvwsBr3REw-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [RFC v3 3/8] virtio-bus: introduce queue_enabled method Date: Fri, 29 May 2020 22:06:15 +0800 Message-Id: <20200529140620.28759-4-lulu@redhat.com> In-Reply-To: <20200529140620.28759-1-lulu@redhat.com> References: <20200529140620.28759-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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/05/29 03:05:19 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-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 0005-virtio-bus-introduce-queue_enabled-method.patch --- 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 Thu May 16 22:47:16 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=1590762538; cv=none; d=zohomail.com; s=zohoarc; b=MBcbtQTO6Jx5JDuJws58m4eyUpUTgnfEoFDPqz4oI/W0mhd4XMkrhO9m8yAGatjxBbsnUDdb5RvtjHWzYuz3DaH0X3ikkvCi7P8jYUOEvhH8yJ5J/gPScJ0F25isMTJV/9R4C3UkaCUT9WF3Jv2idZw7/dJrXcVZMDuIliPWeSs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590762538; 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=dJjJ94MGArmyKMEbsDELwfiFe6wLlepSgX5hwGdr9I0=; b=C+uYygABNEfAC7AiMICDR4EMSQX3a7yPVjYMh/iv3oyabGuSoNXZLklNUU4TfYJM9PBsDXlWzegFT9wu8uWwH/5a5cn//SM7VIgOhK+Rdw+e5216l1306trACq8Rc221k9MagsQScKn/covEwxUZboPLP14YrK9Ol6W0yzm0Qyc= 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 1590762538545206.70445263668807; Fri, 29 May 2020 07:28:58 -0700 (PDT) Received: from localhost ([::1]:44232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeg0H-0008ME-AZ for importer@patchew.org; Fri, 29 May 2020 10:28:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55534) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jefht-0004HF-QN for qemu-devel@nongnu.org; Fri, 29 May 2020 10:09:57 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:27882 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 1jefhs-0005ci-Sq for qemu-devel@nongnu.org; Fri, 29 May 2020 10:09:57 -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-300-W9jau5NiPqOq6QYkb9g-wg-1; Fri, 29 May 2020 10:09:53 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 427467A4A7; Fri, 29 May 2020 14:09:42 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-84.pek2.redhat.com [10.72.13.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C6EC5D9D5; Fri, 29 May 2020 14:09:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590761395; 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=dJjJ94MGArmyKMEbsDELwfiFe6wLlepSgX5hwGdr9I0=; b=emQErETWrtKIpkHE7C/AvTcI292zHl2J5k1fD6xhOsnNUy3/SIj58QQ72LBtRcmHokqP0z yIK2DVcMtpIJwu7Enf6eolIAvnGimK7SwAkFb8MzvmoAd1CmN5Re2dgEib7mjVTPgO9oG3 MwKTr+LNVQ0BpgGn5MowasgKOfHjObg= X-MC-Unique: W9jau5NiPqOq6QYkb9g-wg-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [RFC v3 4/8] virtio-pci: implement queue_enabled method Date: Fri, 29 May 2020 22:06:16 +0800 Message-Id: <20200529140620.28759-5-lulu@redhat.com> In-Reply-To: <20200529140620.28759-1-lulu@redhat.com> References: <20200529140620.28759-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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/05/29 03:05:19 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-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 --- hw/virtio/virtio-pci.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 4cb784389c..2c82ed5246 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1107,6 +1107,18 @@ static AddressSpace *virtio_pci_get_dma_as(DeviceSta= te *d) return pci_get_address_space(dev); } =20 +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_get_desc_addr(vdev, n) !=3D 0; +} + static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy, struct virtio_pci_cap *cap) { @@ -2059,6 +2071,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 Thu May 16 22:47:16 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=1590762610; cv=none; d=zohomail.com; s=zohoarc; b=WT0Jg5SS2Riln+ZCzveoydxf9PbLxLgErnTY80/xC45lmjLjZJcbxDIJP1s6egN7pv+HfKq8EmUYdIMvnKKpdCIi89sp5giU8CE/ITf4BT4Z/AbTPy9gqO6FbfCEh9n9iKN36bKe2wVWs2PIWPjR0+N6pP3cI405zmtoplwlxgI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590762610; 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=JLuZSoaS7Bp6RBxB/Y5YH+sIMS4ZomLIm+8NA1SmnyY=; b=M2+j2Mnv8hP4tSNjPS0M/YYS2ECpbLFqOe7F8ysEUDdg6//BC7D+QuUpVJGkD+Awt4+VmSDIjwhivF7Jy9XnZ+FXUVBtQO69pDPyfaVyifWeHmFTB/dJotopYqdlv9ex3sdV9KB/n1BWHfaor9QkrUvM6xkluXRbcu3KR4DiQjM= 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 1590762610607446.7656706680825; Fri, 29 May 2020 07:30:10 -0700 (PDT) Received: from localhost ([::1]:46494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeg1R-00012T-3e for importer@patchew.org; Fri, 29 May 2020 10:30:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55640) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jefi5-0004cq-Eu for qemu-devel@nongnu.org; Fri, 29 May 2020 10:10:09 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:55962 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 1jefi4-0005mJ-Ff for qemu-devel@nongnu.org; Fri, 29 May 2020 10:10:09 -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-144-0s0ghNJFO_yIo--ompjaaw-1; Fri, 29 May 2020 10:10:05 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EC9CD80B700; Fri, 29 May 2020 14:10:02 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-84.pek2.redhat.com [10.72.13.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C4565D9D5; Fri, 29 May 2020 14:09:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590761407; 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=JLuZSoaS7Bp6RBxB/Y5YH+sIMS4ZomLIm+8NA1SmnyY=; b=DfKrkok2lxqUlUO7BQsqmLZ9bHrdOJGoKDzB3/t/4cjq2V5gWUiAisFrd/CjkG6FmNQL7v rvT56KsQkELEoFivTMIGeryEGb4EaHfGz8LL0FYR/On+7VBDFsFo08NxgWoCBlIWtgX632 efyX1rr8JWBVxfJ3FYXBQp5ARe8odac= X-MC-Unique: 0s0ghNJFO_yIo--ompjaaw-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [RFC v3 5/8] vhost: introduce vhost_set_vring_ready method Date: Fri, 29 May 2020 22:06:17 +0800 Message-Id: <20200529140620.28759-6-lulu@redhat.com> In-Reply-To: <20200529140620.28759-1-lulu@redhat.com> References: <20200529140620.28759-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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/05/29 03:05:19 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-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 Vhost-vdpa introduces VHOST_VDPA_SET_VRING_ENABLE which complies the semantic of queue_enable defined in virtio spec. This method can be used for preventing device from executing request for a specific virtqueue. This patch introduces the vhost_ops for this. Note that, we've already had vhost_set_vring_enable which has different semantic which allows to enable or disable a specific virtqueue for some kinds of vhost backends. E.g vhost-user use this to changes the number of active queue pairs. Signed-off-by: Jason Wang --- hw/net/vhost_net-stub.c | 4 ++++ hw/net/vhost_net.c | 11 ++++++++++- include/net/vhost_net.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/hw/net/vhost_net-stub.c b/hw/net/vhost_net-stub.c index aac0e98228..43e93e1a9a 100644 --- a/hw/net/vhost_net-stub.c +++ b/hw/net/vhost_net-stub.c @@ -86,6 +86,10 @@ int vhost_set_vring_enable(NetClientState *nc, int enabl= e) return 0; } =20 +int vhost_set_vring_ready(NetClientState *nc) +{ + return 0; +} int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu) { return 0; diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index d1d421e3d9..e2bc7de2eb 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -344,7 +344,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *= ncs, goto err_start; } =20 - if (ncs[i].peer->vring_enable) { + if (peer->vring_enable) { /* restore vring enable state */ r =3D vhost_set_vring_enable(peer, peer->vring_enable); =20 @@ -455,6 +455,15 @@ int vhost_set_vring_enable(NetClientState *nc, int ena= ble) return 0; } =20 +int vhost_set_vring_ready(NetClientState *nc) +{ + VHostNetState *net =3D get_vhost_net(nc); + const VhostOps *vhost_ops =3D net->dev.vhost_ops; + if (vhost_ops && vhost_ops->vhost_set_vring_ready) { + return vhost_ops->vhost_set_vring_ready(&net->dev); + } + return 0; +} int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu) { const VhostOps *vhost_ops =3D net->dev.vhost_ops; diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 77e47398c4..8a6f208189 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -35,6 +35,7 @@ int vhost_net_notify_migration_done(VHostNetState *net, c= har* mac_addr); VHostNetState *get_vhost_net(NetClientState *nc); =20 int vhost_set_vring_enable(NetClientState * nc, int enable); +int vhost_set_vring_ready(NetClientState *nc); =20 uint64_t vhost_net_get_acked_features(VHostNetState *net); =20 --=20 2.21.1 From nobody Thu May 16 22:47:16 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=1590762051; cv=none; d=zohomail.com; s=zohoarc; b=HRWL/pIkpXRx15Pyj25PRIC1ox7xRynQ7kUbLX3hAaFP2g4GlGJasyDFge3tl4MSdWyflWI81ENc2JU8dCp58NQUwz5WD1td3TcvKzVU1m46WwJqT1FGikr585zGIylN5QYU2qbXzC2MND+6N85whRYx7fo/gXXBOuOmOGEsKa0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590762051; 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=Opb4ICj/RJNY7bhW1ya4SaMYB/sKjJiaXY0i6jq720A=; b=cPM1vk0DykUthnRReXNEf5CBVFW51y4ISJaOjecArA/FALUce6hniDTvIRC1uWrB8+Ex17Li103TcLC6gEAwqLTrjD/JLQZx6Zv3HgE+K2YkeE4YU7k6gN8eH556Lpr5RunA+lm05WK0D1s/L7n23fGZCft1yHZqdsXgvtPT+a4= 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 1590762051263919.4036371922942; Fri, 29 May 2020 07:20:51 -0700 (PDT) Received: from localhost ([::1]:45390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jefsP-00038n-UA for importer@patchew.org; Fri, 29 May 2020 10:20:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jefiT-0005BP-0N for qemu-devel@nongnu.org; Fri, 29 May 2020 10:10:33 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:37087 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 1jefiQ-0006B5-PF for qemu-devel@nongnu.org; Fri, 29 May 2020 10:10:31 -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-469-1dgEwCNxMVecpWGz7q4VMg-1; Fri, 29 May 2020 10:10:28 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 79E5518A8223; Fri, 29 May 2020 14:10:25 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-84.pek2.redhat.com [10.72.13.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E4905D9D5; Fri, 29 May 2020 14:10:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590761429; 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=Opb4ICj/RJNY7bhW1ya4SaMYB/sKjJiaXY0i6jq720A=; b=h2Pb2wbXKWtITJ1DVOPJrUo8mUryTxXccbcLUv+gMY3WtKeumBEVP+rFkxdldalDLvqsUh do2pLIjtt4RRRLPX/N8/vzXCyojoO44LvtdVNNZV7yllRFCPsM2yXhOTbtBLuQmNXs3PL2 jq0cRmmK3UAZWv9kE21r8kYFHMU+0NI= X-MC-Unique: 1dgEwCNxMVecpWGz7q4VMg-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [RFC v3 6/8] vhost-backend: export the vhost backend helper Date: Fri, 29 May 2020 22:06:18 +0800 Message-Id: <20200529140620.28759-7-lulu@redhat.com> In-Reply-To: <20200529140620.28759-1-lulu@redhat.com> References: <20200529140620.28759-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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/05/29 01:34:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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.001, RCVD_IN_MSPIKE_WL=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 some of them in vhost-vdpa Signed-off-by: Cindy Lu --- hw/virtio/vhost-backend.c | 34 ++++++++++++++++++------------- include/hw/virtio/vhost-backend.h | 28 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index 48905383f8..42efb4967b 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,16 @@ 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; + struct vhost_vdpa *v =3D NULL; + if (dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_KERNEL) { + fd =3D (uintptr_t) dev->opaque; + } + if (dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA) { + v =3D dev->opaque; + fd =3D v->device_fd; + } + assert(fd !=3D -1); return ioctl(fd, request, arg); } =20 @@ -89,7 +95,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 +107,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 +119,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 +161,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 Thu May 16 22:47:16 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=1590762713; cv=none; d=zohomail.com; s=zohoarc; b=U+RpUVlTzjB6L1XXY+HE5BPwIIdG1cXbYblq3BU5qOF1ryS+PdUpZzGdt1PbctXsz4Y0bhAK2phXOf07sy1jjBjcJvYVXhsA/8jhAQ0tgb+aUejdc/2tzHmRDZQPPkCfzu8F8/UO4ZpuE/wWRPnaL9XDdZkXLt5qfebdsx5sY9M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590762713; 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=Bz9b5juc7V9v2vJKnzXvYtlE5iOj/g+oFZdIycEig90=; b=RdHpzUNiwKbPaaUemGv+81SryZkUYp2INl/uBRkhv5Pog9iL8nNT9/HxKw+/njvWj0iofNSneLpjO+QNMJ8sWiYBiJT5o0JW3YYnGietcJZ6xJuB5Ja+DlE5hhPMarSlpXqRwOGaI1TgP1LH4wMG1VUSH3Jf95NoVwqZ0ZfIMmU= 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 1590762713589225.04737498796953; Fri, 29 May 2020 07:31:53 -0700 (PDT) Received: from localhost ([::1]:50794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeg36-0004sX-BY for importer@patchew.org; Fri, 29 May 2020 10:31:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55874) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jefiv-00068B-Sm for qemu-devel@nongnu.org; Fri, 29 May 2020 10:11:01 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:43269 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 1jefit-0006Xb-DF for qemu-devel@nongnu.org; Fri, 29 May 2020 10:11:01 -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-277-IDJvz7tWPxWE7D3lJmeU2g-1; Fri, 29 May 2020 10:10:51 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7EE7918A8231; Fri, 29 May 2020 14:10:48 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-84.pek2.redhat.com [10.72.13.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DF385D9D5; Fri, 29 May 2020 14:10:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590761458; 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=Bz9b5juc7V9v2vJKnzXvYtlE5iOj/g+oFZdIycEig90=; b=iZntzHWT4PTh4cnolk3mNKjAy6dtv8PstqgUtfHF3URuMoloUjpHLHP3Iv0tbGdyVpo0/v QGYdkaYlcDq3suq965nNCIvHg92ntqzd/bDd9vr8i5E6OCHs4x/JlqHHYXqYA/9N90+u0i aN9oKUDzbgRtIGdmEuVY1PuYD8XXyow= X-MC-Unique: IDJvz7tWPxWE7D3lJmeU2g-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [RFC v3 7/8] vhost-vdpa: introduce vhost-vdpa backend Date: Fri, 29 May 2020 22:06:19 +0800 Message-Id: <20200529140620.28759-8-lulu@redhat.com> In-Reply-To: <20200529140620.28759-1-lulu@redhat.com> References: <20200529140620.28759-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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/05/29 01:27:49 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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" From: Tiwei Bie 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-vdpa0 \ -device virtio-net-pci,netdev=3Dvhost-vdpa0,page-per-vq=3Don \ Co-Authored-By: Lingshan zhu Signed-off-by: Cindy Lu --- configure | 21 ++ hw/net/vhost_net-stub.c | 5 + hw/net/vhost_net.c | 47 +++- hw/virtio/Makefile.objs | 1 + hw/virtio/vhost-backend.c | 5 + hw/virtio/vhost-vdpa.c | 399 ++++++++++++++++++++++++++++++ hw/virtio/vhost.c | 37 ++- include/hw/virtio/vhost-backend.h | 10 +- include/hw/virtio/vhost-vdpa.h | 26 ++ include/hw/virtio/vhost.h | 2 + include/net/vhost_net.h | 4 +- qemu-options.hx | 15 ++ 12 files changed, 566 insertions(+), 6 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-stub.c b/hw/net/vhost_net-stub.c index 43e93e1a9a..ab77a92a7d 100644 --- a/hw/net/vhost_net-stub.c +++ b/hw/net/vhost_net-stub.c @@ -94,3 +94,8 @@ int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu) { return 0; } +int vhost_net_get_device_id(struct vhost_net *net, uint32_t * device_id) +{ + return 0; +} + diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index e2bc7de2eb..25045cff59 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" @@ -85,6 +87,30 @@ static const int user_feature_bits[] =3D { VHOST_INVALID_FEATURE_BIT }; =20 +static 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 +}; static const int *vhost_net_get_feature_bits(struct vhost_net *net) { const int *feature_bits =3D 0; @@ -96,6 +122,9 @@ static const int *vhost_net_get_feature_bits(struct vhos= t_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); @@ -110,7 +139,10 @@ uint64_t vhost_net_get_features(struct vhost_net *net,= uint64_t features) return vhost_get_features(&net->dev, vhost_net_get_feature_bits(net), features); } - +int vhost_net_get_device_id(struct vhost_net *net, uint32_t * device_id) +{ + return vhost_dev_get_device_id(&net->dev, device_id); +} void vhost_net_ack_features(struct vhost_net *net, uint64_t features) { net->dev.acked_features =3D net->dev.backend_features; @@ -337,6 +369,11 @@ int vhost_net_start(VirtIODevice *dev, NetClientState = *ncs, } =20 for (i =3D 0; i < total_queues; i++) { + + if (virtio_queue_enabled(dev, i)) { + vhost_set_vring_ready(peer); + } + peer =3D qemu_get_peer(ncs, i); r =3D vhost_net_start_one(get_vhost_net(peer), dev); =20 @@ -433,6 +470,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; @@ -474,3 +517,5 @@ int vhost_net_set_mtu(struct vhost_net *net, uint16_t m= tu) =20 return vhost_ops->vhost_net_set_mtu(&net->dev, mtu); } + + 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 42efb4967b..420341e8c5 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -291,6 +291,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..2d136a8565 --- /dev/null +++ b/hw/virtio/vhost-vdpa.c @@ -0,0 +1,399 @@ +/* + * 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); +} +/* Register a new memory listener, only to get diffs from qemu, + * this help to reduce the tricky codes in vhost + * (e.g generating diffs of two rbtree as usnic did).*/ +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; + + assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA); + + v =3D opaque; + dev->opaque =3D opaque ; + + v->listener =3D vhost_vdpa_memory_listener; + v->msg_type =3D VHOST_IOTLB_MSG_V2; + memory_listener_register(&v->listener, &address_space_memory); + + 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 =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; + if ((size > VHOST_VDPA_MAX_CONFIG_SIZE) || (data =3D=3D NULL)) { + return -1; + } + memset(&config, 0, sizeof(struct vhost_vdpa_config)); + config.off =3D 0; + config.len =3D size; + memcpy(&config.buf, data, size); + ret =3D vhost_vdpa_call(dev, VHOST_VDPA_SET_CONFIG, &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; + int ret; + + memset(&v_config, 0, sizeof(struct vhost_vdpa_config)); + if (config =3D=3D NULL) { + return -1; + } + ret =3D vhost_vdpa_call(dev, VHOST_VDPA_GET_CONFIG, &v_config); + if ((v_config.len > config_len) || (v_config.len =3D=3D 0)) { + return -EINVAL; + } + memcpy(config, &v_config.buf, config_len); + return ret; + } + +static int vhost_vdpa_set_state(struct vhost_dev *dev, bool started) +{ + if (started) { + uint8_t status =3D 0; + + 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); + 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_set_vring_ready =3D vhost_vdpa_set_vring_ready, + .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_set_state =3D vhost_vdpa_set_state, + .vhost_get_device_id =3D vhost_vdpa_get_device_id, +}; diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 01ebe12f28..b97aa02a4c 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -756,6 +756,12 @@ static int vhost_virtqueue_set_addr(struct vhost_dev *= dev, .log_guest_addr =3D vq->used_phys, .flags =3D enable_log ? (1 << VHOST_VRING_F_LOG) : 0, }; + /*vDPA need to use the phys address 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; + } int r =3D dev->vhost_ops->vhost_set_vring_addr(dev, &addr); if (r < 0) { VHOST_OPS_DEBUG("vhost_set_vring_addr failed"); @@ -1506,6 +1512,14 @@ int vhost_dev_set_config(struct vhost_dev *hdev, con= st uint8_t *data, return -1; } =20 +int vhost_dev_get_device_id(struct vhost_dev *hdev, uint32_t *device_id) +{ + assert(hdev->vhost_ops); + if (hdev->vhost_ops->vhost_get_device_id) { + return hdev->vhost_ops->vhost_get_device_id(hdev, device_id); + } + return -1; +} void vhost_dev_set_config_notifier(struct vhost_dev *hdev, const VhostDevConfigOps *ops) { @@ -1661,7 +1675,13 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODe= vice *vdev) } } =20 - if (vhost_dev_has_iommu(hdev)) { + r =3D vhost_set_state(hdev, true); + if (r) { + goto fail_log; + } + + 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, @@ -1697,6 +1717,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_state(hdev, false); + for (i =3D 0; i < hdev->nvqs; ++i) { vhost_virtqueue_stop(hdev, vdev, @@ -1705,7 +1727,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); @@ -1722,3 +1746,12 @@ int vhost_net_set_backend(struct vhost_dev *hdev, =20 return -1; } + +int vhost_set_state(struct vhost_dev *hdev, bool started) +{ + if (hdev->vhost_ops->vhost_set_state) { + return hdev->vhost_ops->vhost_set_state(hdev, started); + } + + return 0; +} diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-ba= ckend.h index 300b59c172..1ebe3785cf 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 { @@ -77,6 +78,7 @@ typedef int (*vhost_reset_device_op)(struct vhost_dev *de= v); typedef int (*vhost_get_vq_index_op)(struct vhost_dev *dev, int idx); typedef int (*vhost_set_vring_enable_op)(struct vhost_dev *dev, int enable); +typedef int (*vhost_set_vring_ready_op)(struct vhost_dev *dev); typedef bool (*vhost_requires_shm_log_op)(struct vhost_dev *dev); typedef int (*vhost_migration_done_op)(struct vhost_dev *dev, char *mac_addr); @@ -112,6 +114,8 @@ 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_set_state_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; @@ -138,6 +142,7 @@ typedef struct VhostOps { vhost_reset_device_op vhost_reset_device; vhost_get_vq_index_op vhost_get_vq_index; vhost_set_vring_enable_op vhost_set_vring_enable; + vhost_set_vring_ready_op vhost_set_vring_ready; vhost_requires_shm_log_op vhost_requires_shm_log; vhost_migration_done_op vhost_migration_done; vhost_backend_can_merge_op vhost_backend_can_merge; @@ -152,9 +157,12 @@ 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_set_state_op vhost_set_state; + 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 085450c6f8..b682545f51 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -124,6 +124,7 @@ int vhost_dev_get_config(struct vhost_dev *dev, uint8_t= *config, uint32_t config_len); int vhost_dev_set_config(struct vhost_dev *dev, const uint8_t *data, uint32_t offset, uint32_t size, uint32_t flags); +int vhost_dev_get_device_id(struct vhost_dev *hdev, uint32_t *device_id); /* notifier callback in case vhost device config space changed */ void vhost_dev_set_config_notifier(struct vhost_dev *dev, @@ -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_state(struct vhost_dev *dev, bool started); #endif diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 8a6f208189..56e67fe164 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -40,5 +40,5 @@ int vhost_set_vring_ready(NetClientState *nc); uint64_t vhost_net_get_acked_features(VHostNetState *net); =20 int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu); - -#endif +int vhost_net_get_device_id(struct vhost_net *net, uint32_t *device_id); +endif diff --git a/qemu-options.hx b/qemu-options.hx index 292d4e7c0c..c19e10ce9c 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 CONFIG_POSIX + "-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) @@ -2428,6 +2432,9 @@ DEF("nic", HAS_ARG, QEMU_OPTION_nic, #endif #ifdef CONFIG_POSIX "vhost-user|" +#endif +#ifdef CONFIG_POSIX + "vhost-vdpa|" #endif "socket][,option][,...][mac=3Dmacaddr]\n" " initialize an on-board / default host NIC (using MAC = address\n" @@ -2896,6 +2903,14 @@ SRST hubport to another netdev with ID nd by using the ``netdev=3Dnd`` option. =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. + ``-net nic[,netdev=3Dnd][,macaddr=3Dmac][,model=3Dtype] [,name=3Dname][,ad= dr=3Daddr][,vectors=3Dv]`` Legacy option to configure or create an on-board (or machine default) Network Interface Card(NIC) and connect it either to the --=20 2.21.1 From nobody Thu May 16 22:47:16 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=1590762805; cv=none; d=zohomail.com; s=zohoarc; b=GRc90q6HJ1SYUGqDAj4VReiYb/FyMVuKR4S0PaWGkrkvE26UCTOLm+6u9lT1sjIZIkECMuFc/cUt13MwChp8qgi9qLtALaH7M/lWOUxySIRzmDDI1kGQWNpV/aujacHpfX3il63gF9XmGeeikVd8SwyJO1uZWuCdxIMhd4zQzK4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590762805; 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=wCflfqrrR6gmFCMKbYRm5BpEmAm6JtXxYfaEMe8E5gQ=; b=Jbrtr+g2zefIcwlT+abgK7KTh4PXqdIhyM2Dc2enm3CX96GNQ+CYUQIVeJwg2RG3t+jLANxdSRyLFahgiteynTa+AJAQ9C9/I0xFt40WvqyTxsxGHv0bWEuMzmj9BjG8dV1uWMCNHCivMJ+Ii3shPsiPaebZ6JXDxURixM90h7c= 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 1590762805913216.9465012185335; Fri, 29 May 2020 07:33:25 -0700 (PDT) Received: from localhost ([::1]:54450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeg4a-0006MY-JT for importer@patchew.org; Fri, 29 May 2020 10:33:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55934) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jefjC-0006aE-0B for qemu-devel@nongnu.org; Fri, 29 May 2020 10:11:18 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:56674 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 1jefjA-0006jb-LU for qemu-devel@nongnu.org; Fri, 29 May 2020 10:11:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-47-tTpuiPanOEKll8v6eduRtg-1; Fri, 29 May 2020 10:11:11 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7D146108BD09; Fri, 29 May 2020 14:11:08 +0000 (UTC) Received: from laptop.redhat.com (ovpn-13-84.pek2.redhat.com [10.72.13.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 066D25D9D5; Fri, 29 May 2020 14:10:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590761476; 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=wCflfqrrR6gmFCMKbYRm5BpEmAm6JtXxYfaEMe8E5gQ=; b=M3/gGM1U0v1IXt8YWsXHMa1N1KVMhWtdR8+8KR/xRqXXrbip2PoUlDECkTW18oftfYoKhW VFKfaP+wsbjjqLZ77M2awIHY82zNF7chBQDcHR7n7yj6FOxc9dSe0PE3ZVej6Sc1Mbgzkk rEwaULAPZPyQMnYZYhFrs/kDuU151Zk= X-MC-Unique: tTpuiPanOEKll8v6eduRtg-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [RFC v3 8/8] vhost-vdpa: introduce vhost-vdpa net client Date: Fri, 29 May 2020 22:06:20 +0800 Message-Id: <20200529140620.28759-9-lulu@redhat.com> In-Reply-To: <20200529140620.28759-1-lulu@redhat.com> References: <20200529140620.28759-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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/05/29 01:34:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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" From: Tiwei Bie 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. Co-authored-by: Lingshan Zhu Signed-off-by: Cindy Lu --- include/net/vhost-vdpa.h | 19 ++++ include/net/vhost_net.h | 2 +- net/Makefile.objs | 2 +- net/clients.h | 2 + net/net.c | 3 + net/vhost-vdpa.c | 235 +++++++++++++++++++++++++++++++++++++++ qapi/net.json | 26 ++++- 7 files changed, 285 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..6ce0d04f72 --- /dev/null +++ b/include/net/vhost-vdpa.h @@ -0,0 +1,19 @@ +/* + * 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); + +#endif /* VHOST_VDPA_H */ diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 56e67fe164..0b87d3c6e9 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -41,4 +41,4 @@ uint64_t vhost_net_get_acked_features(VHostNetState *net); =20 int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu); int vhost_net_get_device_id(struct vhost_net *net, uint32_t *device_id); -endif +#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..7b98c142b5 --- /dev/null +++ b/net/vhost-vdpa.c @@ -0,0 +1,235 @@ +/* + * 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; + +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); + return s->acked_features; +} + +static int vhost_vdpa_check_device_id(NetClientState *nc) +{ + uint32_t device_id; + int ret; + assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); + VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); + /* Get the device id from hw*/ + ret =3D vhost_net_get_device_id(s->vhost_net, &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) { + /* save acked features */ + uint64_t features =3D vhost_net_get_acked_features(s->vhost_net); + if (features) { + s->acked_features =3D features; + } + 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; + /* check the device id for vdpa */ + ret =3D vhost_vdpa_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; + } + + qemu_purge_queued_packets(nc); +} + +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, + bool has_fd, char *fd) +{ + NetClientState *nc =3D NULL; + VhostVDPAState *s; + int vdpa_device_fd =3D -1; + Error *err =3D NULL; + 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); + + if (has_fd) { + vdpa_device_fd =3D monitor_fd_param(cur_mon, fd, &err); + } else{ + vdpa_device_fd =3D 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); + + if (ret) { + if (has_fd) { + close(vdpa_device_fd); + } + } + 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, + opts->has_fd, opts->fd); +} diff --git a/qapi/net.json b/qapi/net.json index cebb1b52e3..37507ce9ba 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -428,6 +428,27 @@ '*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) +# +# @fd: file descriptor of an already opened vdpa device +# +# @queues: number of queues to be created for multiqueue vhost-vdpa +# (default: 1) +# +# Since: 5.1 +## +{ 'struct': 'NetdevVhostVDPAOptions', + 'data': { + '*vhostdev': 'str', + '*fd': 'str', + '*queues': 'int' } } + ## # @NetClientDriver: # @@ -437,7 +458,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 +486,8 @@ 'bridge': 'NetdevBridgeOptions', 'hubport': 'NetdevHubPortOptions', 'netmap': 'NetdevNetmapOptions', - 'vhost-user': 'NetdevVhostUserOptions' } } + 'vhost-user': 'NetdevVhostUserOptions', + 'vhost-vdpa': 'NetdevVhostVDPAOptions' } } =20 ## # @NetLegacy: --=20 2.21.1