From nobody Sun May 19 09:23:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1588955693; cv=none; d=zohomail.com; s=zohoarc; b=Ot/p1kJq0s/MjbgsvbBjPx790KQzgH+9Gop94Aul8yTC6h5uvKYwrFNMJvPR0TowAEqLiu99GpmtgPbi9NuoNhreSs0uF5PTBPj71hM7+PaluJ/uTiuSADlSO+tUFM+pI/WMwcHNwPsGJA4bYqTeb0N97YbwsaX7oAwE0r6oRr0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588955693; 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=52firLbS5N65LDVCF108n3lH3o1t+XvS9Gj2k2LVUns=; b=f0ocEWUoWjbIxP8xne/0SdybcCysySwmup0JRf6oF+ToF4xcEC53w/Bw4ZKqITbo03xIXQ9UqPx0c7l3YOv+dR2I4ud9Bo9ZHWDDmZIgCEx5SEJSrbf/mvz7WPJ7fN2clKi+B6DSCs5/YlBvLGKe0gdF2xeXovuAEWB2FE9hGAo= 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 1588955693311537.4854661160384; Fri, 8 May 2020 09:34:53 -0700 (PDT) Received: from localhost ([::1]:36884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jX5xc-00087s-1m for importer@patchew.org; Fri, 08 May 2020 12:34:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60658) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jX5wR-0006ta-Hs for qemu-devel@nongnu.org; Fri, 08 May 2020 12:33:40 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:45539 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 1jX5wP-0005OG-Ej for qemu-devel@nongnu.org; Fri, 08 May 2020 12:33:39 -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-396-Kp8pYzeGNz-dwQ4msHg7_Q-1; Fri, 08 May 2020 12:33:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 73D40107ACCA; Fri, 8 May 2020 16:33:31 +0000 (UTC) Received: from laptop.redhat.com (ovpn-12-75.pek2.redhat.com [10.72.12.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 860B86C760; Fri, 8 May 2020 16:33:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588955616; 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=52firLbS5N65LDVCF108n3lH3o1t+XvS9Gj2k2LVUns=; b=FWP/v61ebcZmkvmecvuV4g1EU6S1AToBvDOwRQfiJLD8lEB6p0jHn5aKDuAeSP5RIyScB/ WlYOKZkfF9JgfJ1KDPuTCfvPoMcQ889+wJy36fqCuhBVa1VwrUzdAg+MtXaffV/oihRwea hnjzh4wRctnxoPro1VJ4q0hVC3F+M/Y= X-MC-Unique: Kp8pYzeGNz-dwQ4msHg7_Q-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [RFC v2 1/9] net: introduce qemu_get_peer Date: Sat, 9 May 2020 00:32:10 +0800 Message-Id: <20200508163218.22592-2-lulu@redhat.com> In-Reply-To: <20200508163218.22592-1-lulu@redhat.com> References: <20200508163218.22592-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/08 08:00:48 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] 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 e175ba9677..0a74324ccd 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -175,6 +175,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 84aa6d8d00..b3192deaf1 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 Sun May 19 09:23:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1588955777; cv=none; d=zohomail.com; s=zohoarc; b=FtUZ9Qfw1t7aJTyi4AfsbndS+RLlw+xaqLcgt/SV9eCduxSVbru1tdP2o5n7ylIRp6jS6QyJbWmtYAqn/3Ehx3ODkUmptCjj4pbHZRz1D6OzWPlaxAHCnZ/bGe7Lgl48r4NzbM9ny2kAp4IVHt1mVVqK9oPy7pbvjNcSCcDWvHU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588955777; 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=d0w16tGnlFFUPOb1qRtX3Q6mx4lUNCdPnguQrPhyO2aJTWCF32rNOhEyz/zKa7Sg8La9PNLLNSDFqpT1tttZoDIzd4/hMASniZ+YDUFO91+9I3Hap1grXLr5TnFuV2o1tNHiqwTg3aAergT/f+WoTHjqOcTikZzCnkX9QQBE0WQ= 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 1588955777626544.8294718668891; Fri, 8 May 2020 09:36:17 -0700 (PDT) Received: from localhost ([::1]:39798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jX5yy-000104-9T for importer@patchew.org; Fri, 08 May 2020 12:36:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jX5wl-0007Tw-PY for qemu-devel@nongnu.org; Fri, 08 May 2020 12:34:01 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:39017 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 1jX5wk-00065d-Gu for qemu-devel@nongnu.org; Fri, 08 May 2020 12:33: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-49-7ouM8NXwNZucpKj05OPm0g-1; Fri, 08 May 2020 12:33:55 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 31A8E107ACCA; Fri, 8 May 2020 16:33:53 +0000 (UTC) Received: from laptop.redhat.com (ovpn-12-75.pek2.redhat.com [10.72.12.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0FE436ACF5; Fri, 8 May 2020 16:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588955637; 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=CiQi9jbORetfn4kG6fUPgW5p4+BCYHjvvS77v7P0SNbEc7Shj9nrS5iWNZVsTSjHr8dnLF inM23pz++6RB9baBDRmPhZbOPxwCkCtqSiKaUwMAcLpG8u+sCDtzpKuaKgN3BoUtjTJLe2 ZihxoN8UgE8M2I84Ei8vYiNkNM1lhls= X-MC-Unique: 7ouM8NXwNZucpKj05OPm0g-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [RFC v2 2/9] net: use the function qemu_get_peer Date: Sat, 9 May 2020 00:32:11 +0800 Message-Id: <20200508163218.22592-3-lulu@redhat.com> In-Reply-To: <20200508163218.22592-1-lulu@redhat.com> References: <20200508163218.22592-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/08 01:34:54 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" 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 Sun May 19 09:23:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1588955888; cv=none; d=zohomail.com; s=zohoarc; b=jealW9QWiARe95ticPnYJYT4ttsg7NUkKE61D3EM4L4nwLar5agR/w4AwyXsMOmG7aCQTb2J8bsQuQoa/E0+vx/2uQ2xfqmMCtDDDDRHSPZv6uoywS4YnioRoZ1jSSesb6xXKbczBMbN4/bB2+PQ1uo0MwDZQkSghe+lWs0VoWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588955888; 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=W0nhH79L1o1AT2y6BnT9L+LpqnN5izFGzVarE8zoLWM=; b=Wg5RDAYWOj5/SFUW34ql3slGXHvApVkLnqwh6VKWrZp0v69sdPfg18kDAG9QJ7cW0C56U+upcBL+6QL34dj+9UwKfLa65wEyn2384FxlO0iHxBjbBobY7e/Da52xyrAZNBTrzQA2GGAz43jSkXCLedM8duYKcme6VqwUWSRREKI= 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 1588955888289551.7792376904903; Fri, 8 May 2020 09:38:08 -0700 (PDT) Received: from localhost ([::1]:45024 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jX60k-0003j8-Co for importer@patchew.org; Fri, 08 May 2020 12:38:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60978) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jX5x8-0007qC-5O for qemu-devel@nongnu.org; Fri, 08 May 2020 12:34:22 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:36766 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 1jX5x7-0007hE-6P for qemu-devel@nongnu.org; Fri, 08 May 2020 12:34: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-412-F90NuD-8NG-P-xGlaLTciQ-1; Fri, 08 May 2020 12:34:18 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 449B7872FE0; Fri, 8 May 2020 16:34:13 +0000 (UTC) Received: from laptop.redhat.com (ovpn-12-75.pek2.redhat.com [10.72.12.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 79FD96ACEF; Fri, 8 May 2020 16:33:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588955660; 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=W0nhH79L1o1AT2y6BnT9L+LpqnN5izFGzVarE8zoLWM=; b=RmUB1dsbndlukau4SR89GL5ob2f7EAIv6DMG7wkAa3EqOgbqWmCrqpPZahprCMix4R5pmK k71tFVYpa5rpfuT5Q6aicaYlqqBBt5LpUEcqj0LGgwjkwR4p7girTLasdeKpx9pa6/tu86 7g/HDwqgy4lv3ESTrrAsRDYoPPNP6oQ= X-MC-Unique: F90NuD-8NG-P-xGlaLTciQ-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [RFC v2 3/9] virtio_net: introduce vhost_set_state Date: Sat, 9 May 2020 00:32:12 +0800 Message-Id: <20200508163218.22592-4-lulu@redhat.com> In-Reply-To: <20200508163218.22592-1-lulu@redhat.com> References: <20200508163218.22592-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/08 08:00:48 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] 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" Introduce a function to set the state to the vhost driver. vDPA need to sync the driver's state to NIC Signed-off-by: Cindy Lu --- hw/net/vhost_net.c | 9 +++++++++ hw/net/virtio-net.c | 9 +++++++++ include/hw/virtio/vhost-backend.h | 2 ++ include/net/vhost_net.h | 2 +- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index d1d421e3d9..63b2a85d6e 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -465,3 +465,12 @@ int vhost_net_set_mtu(struct vhost_net *net, uint16_t = mtu) =20 return vhost_ops->vhost_net_set_mtu(&net->dev, mtu); } +int vhost_set_state(NetClientState *nc, uint8_t state) +{ + struct vhost_net *net =3D get_vhost_net(nc); + struct vhost_dev *hdev =3D &net->dev; + if (hdev->vhost_ops->vhost_set_state) { + return hdev->vhost_ops->vhost_set_state(hdev, state); + } + return 0; +} diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index db3d7c38e6..1bddb4b4af 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -206,6 +206,9 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8= _t status) VirtIODevice *vdev =3D VIRTIO_DEVICE(n); NetClientState *nc =3D qemu_get_queue(n->nic); int queues =3D n->multiqueue ? n->max_queues : 1; + NetClientState *peer =3D qemu_get_peer(nc, 0); + uint8_t status_set =3D vdev->status ; + uint8_t vhost_started_pre =3D n->vhost_started; =20 if (!get_vhost_net(nc->peer)) { return; @@ -245,6 +248,7 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8= _t status) return; } } + status_set =3D status_set | VIRTIO_CONFIG_S_DRIVER_OK; =20 n->vhost_started =3D 1; r =3D vhost_net_start(vdev, n->nic->ncs, queues); @@ -252,11 +256,16 @@ static void virtio_net_vhost_status(VirtIONet *n, uin= t8_t status) error_report("unable to start vhost net: %d: " "falling back on userspace virtio", -r); n->vhost_started =3D 0; + status_set =3D status_set & ~VIRTIO_CONFIG_S_DRIVER_OK; } } else { vhost_net_stop(vdev, n->nic->ncs, queues); + status_set =3D status_set & ~VIRTIO_CONFIG_S_DRIVER_OK; n->vhost_started =3D 0; } + if (vhost_started_pre !=3D n->vhost_started) { + vhost_set_state(peer, status_set); + } } =20 static int virtio_net_set_vnet_endian_one(VirtIODevice *vdev, diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-ba= ckend.h index 6f6670783f..f823055167 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -112,6 +112,7 @@ typedef int (*vhost_get_inflight_fd_op)(struct vhost_de= v *dev, typedef int (*vhost_set_inflight_fd_op)(struct vhost_dev *dev, struct vhost_inflight *inflight); =20 +typedef int (*vhost_set_state_op)(struct vhost_dev *dev, uint8_t state); typedef struct VhostOps { VhostBackendType backend_type; vhost_backend_init vhost_backend_init; @@ -152,6 +153,7 @@ typedef struct VhostOps { vhost_backend_mem_section_filter_op vhost_backend_mem_section_filter; vhost_get_inflight_fd_op vhost_get_inflight_fd; vhost_set_inflight_fd_op vhost_set_inflight_fd; + vhost_set_state_op vhost_set_state; } VhostOps; =20 extern const VhostOps user_ops; diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 77e47398c4..6548a5a105 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -39,5 +39,5 @@ int vhost_set_vring_enable(NetClientState * nc, int enabl= e); uint64_t vhost_net_get_acked_features(VHostNetState *net); =20 int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu); - +int vhost_set_state(NetClientState *nc, uint8_t state); #endif --=20 2.21.1 From nobody Sun May 19 09:23:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1588955811; cv=none; d=zohomail.com; s=zohoarc; b=jLK+Xqy9dJ/kh3F/DtTB/g7+Prsfb1mpb1v7zhQ2Chb3JKnNk+oiaOdD1UO+smWNNclIEviijkaSAgVS6OQWUfXBVeCimc7imBJoLSii4utXjS2OZo2UWsxSApkStT+RhzK2hYQRJeG353RgxuJlF+Zo+1UscVIBDVIHpnXwNB0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588955811; 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=IOdxFpubNx4HqBHaVMq3JgHRUEVdcrm0PEmzgGiLBlQ=; b=kuC/ZunEycwJCInTCfO1peAdiAtNJuqE0gUKqaukhavt6zrJhupiG8izSrnSoZw/lodAqavmvPMtJ021dqIwP+g2M9S7YTB/dJcyPVxy6inRdX0bf42k8sqbeZndVKzIvXFCRtP6ZSft1OJ67EtFye3RKRweuSlNqWw7cEKUbE8= 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 1588955811629422.2620954458479; Fri, 8 May 2020 09:36:51 -0700 (PDT) Received: from localhost ([::1]:41252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jX5zW-0001ad-7t for importer@patchew.org; Fri, 08 May 2020 12:36:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jX5xS-0008If-Ny for qemu-devel@nongnu.org; Fri, 08 May 2020 12:34:42 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:32182 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 1jX5xQ-0000eC-UX for qemu-devel@nongnu.org; Fri, 08 May 2020 12:34:42 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-185-Y1Ta4GlgMFObGkdsNSJtOg-1; Fri, 08 May 2020 12:34:35 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D87FE80183C; Fri, 8 May 2020 16:34:32 +0000 (UTC) Received: from laptop.redhat.com (ovpn-12-75.pek2.redhat.com [10.72.12.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2850A6AD17; Fri, 8 May 2020 16:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588955679; 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=IOdxFpubNx4HqBHaVMq3JgHRUEVdcrm0PEmzgGiLBlQ=; b=Ute9DqRf+hzV9APC5L+n6DUeyLTfg6QNRBgv6dhDMm1vNdDo48Rq8suDf4V4cUQzhR8kJL tHnnharNd0rwrsoB5cXk8FfTAhYNePSnCHWnw+rBLPgXhoUZjdDTID1ui6tFd31gOf6QbU 9OFVHAGLVXEUaiegSCnTE5OyHY0RFHg= X-MC-Unique: Y1Ta4GlgMFObGkdsNSJtOg-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [RFC v2 4/9] vhost-vdpa: introduce vhost-vdpa net client Date: Sat, 9 May 2020 00:32:13 +0800 Message-Id: <20200508163218.22592-5-lulu@redhat.com> In-Reply-To: <20200508163218.22592-1-lulu@redhat.com> References: <20200508163218.22592-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/08 01:34:54 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 --- configure | 21 ++++ include/net/vhost-vdpa.h | 19 ++++ include/net/vhost_net.h | 1 + net/Makefile.objs | 2 +- net/clients.h | 2 + net/net.c | 3 + net/vhost-vdpa.c | 227 +++++++++++++++++++++++++++++++++++++++ qapi/net.json | 22 +++- qemu-options.hx | 19 ++++ 9 files changed, 313 insertions(+), 3 deletions(-) create mode 100644 include/net/vhost-vdpa.h create mode 100644 net/vhost-vdpa.c diff --git a/configure b/configure index 6099be1d84..bdd732e3bb 100755 --- a/configure +++ b/configure @@ -1505,6 +1505,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" @@ -1780,6 +1784,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 backend support spice spice rbd rados block device (rbd) libiscsi iscsi support @@ -2241,6 +2246,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=3Dyes +if test "$vhost_vdpa" =3D "yes" && test "$mingw32" =3D "yes"; then + error_exit "vhost-vdpa isn't available on win32" +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" @@ -2269,6 +2278,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 @@ -6543,6 +6557,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-" @@ -7031,6 +7046,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 @@ -7043,6 +7061,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/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 6548a5a105..b47844bf29 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -40,4 +40,5 @@ uint64_t vhost_net_get_acked_features(VHostNetState *net); =20 int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu); int vhost_set_state(NetClientState *nc, uint8_t state); +int vhost_net_get_device_id(struct vhost_net *net, uint32_t *device_id); #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 b3192deaf1..9eff1ae982 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..c29678fdf1 --- /dev/null +++ b/net/vhost-vdpa.c @@ -0,0 +1,227 @@ +/* + * 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 +#include +#include "monitor/monitor.h" +#include "qemu/sockets.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 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; + + 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; + + 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 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 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; + + 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; + vhost_vdpa_add(nc, (void *)&s->vhost_vdpa); + assert(s->vhost_net); + /* check the device id for vdpa */ + return vhost_vdpa_check_device_id(nc); +} + +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 335295be50..0f4fa6fffc 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -441,6 +441,23 @@ '*queues': 'int' } } =20 ## +# @NetdevVhostVDPAOptions: +# +# Vhost-vdpa network backend +# +# @vhostdev: name of a vdpa dev path in sysfs +# +# @queues: number of queues to be created for multiqueue vhost-vdpa +# (default: 1) (Since 5.1) +# +# Since: 5.1 +## +{ 'struct': 'NetdevVhostVDPAOptions', + 'data': { + '*vhostdev': 'str', + '*fd': 'str', + '*queues': 'int' } } +## # @NetClientDriver: # # Available netdev drivers. @@ -451,7 +468,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: @@ -479,7 +496,8 @@ 'bridge': 'NetdevBridgeOptions', 'hubport': 'NetdevHubPortOptions', 'netmap': 'NetdevNetmapOptions', - 'vhost-user': 'NetdevVhostUserOptions' } } + 'vhost-user': 'NetdevVhostUserOptions', + 'vhost-vdpa': 'NetdevVhostVDPAOptions' } } =20 ## # @NetLegacy: diff --git a/qemu-options.hx b/qemu-options.hx index 65c9473b73..08256d9d4e 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2291,6 +2291,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, backed by a vhostdev = 'dev'\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) @@ -2310,6 +2314,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" @@ -2749,6 +2756,18 @@ qemu -m 512 -object memory-backend-file,id=3Dmem,siz= e=3D512M,mem-path=3D/hugetlbfs,sha -device virtio-net-pci,netdev=3Dnet0 @end example =20 +@item -netdev vhost-vdpa,vhostdev=3D/path/to/dev +Establish a vhost-vdpa netdev, backed by a vhostdev. The chardev should +be a unix domain socket backed one. The vhost-vdpa uses a specifically def= ined +protocol to pass vhost ioctl replacement messages to an application on the= other +end of the socket. +Example: +@example +qemu -m 512 -object memory-backend-file,id=3Dmem,size=3D512M,mem-path=3D/h= ugetlbfs,share=3Don \ + -numa node,memdev=3Dmem \ + -netdev type=3Dvhost-vdpa,id=3Dnet0,vhostdev=3D/path/to/dev \ + -device virtio-net-pci,netdev=3Dnet0 +@end example @item -netdev hubport,id=3D@var{id},hubid=3D@var{hubid}[,netdev=3D@var{nd}] =20 Create a hub port on the emulated hub with ID @var{hubid}. --=20 2.21.1 From nobody Sun May 19 09:23:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1588955999; cv=none; d=zohomail.com; s=zohoarc; b=QL/LMzFKm6vLBQnQNbDBR0rwxqSFweua1oKJGeuH4RM7e7uukb6MjEXuFcFGO9WDpHzz56BGIB2upa3FMgsApUAySLQvcAXf7RVxqNguq3bS8TD7uNoEscg08WUSygoeSSsqR1B0hEgvlqlZr6BGxoKqTro2c60b4h47+FMRz3k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588955999; 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=ShoSNGkght3TA1SBY90YsSNGS5QCtdwp6eKppwPWUS4=; b=VuH4HYttFfoDiIjHAkzdoV3+M4oMy+k78DZQxR4aOLRyMFBj2hSAMO+5nTAi/coef2XFROyMfKxudG454fhH+XYJlOBREwih4PZz9PGW/lZOzI+fCm+iljGcj1K62dkp0PS25tYbbwA/WTda9Y6wuDpSMXkdTYqcitALGmu/1U0= 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 1588955999307147.80924878385485; Fri, 8 May 2020 09:39:59 -0700 (PDT) Received: from localhost ([::1]:52684 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jX62X-000765-Rl for importer@patchew.org; Fri, 08 May 2020 12:39:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jX5yL-0000hV-QO for qemu-devel@nongnu.org; Fri, 08 May 2020 12:35:37 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:23711 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 1jX5yH-0003hR-P9 for qemu-devel@nongnu.org; Fri, 08 May 2020 12:35:37 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-288-YhxuxJTdMsmHY0pvOybZNA-1; Fri, 08 May 2020 12:35:15 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 426791800D42; Fri, 8 May 2020 16:35:13 +0000 (UTC) Received: from laptop.redhat.com (ovpn-12-75.pek2.redhat.com [10.72.12.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 35C496ACEF; Fri, 8 May 2020 16:34:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588955732; 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=ShoSNGkght3TA1SBY90YsSNGS5QCtdwp6eKppwPWUS4=; b=bypw9DnEok2bBwnzYZ6wdhc02PGrxNT566qJ35jcwf3/TdFe4oKrOYBbKFyNTqCzrM03RI 4j9oDTq7bhqb8j04VpRSRntCi4fi26kj9lq7YfzzeYMTa8VgcyKY0Y5/sktDqXplvsw2Vb K+o1hcmTcAnLIfuigDCHAc9sXQWbSWU= X-MC-Unique: YhxuxJTdMsmHY0pvOybZNA-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [RFC v2 5/9] vhost-vdpa: implement vhost-vdpa backend Date: Sat, 9 May 2020 00:32:14 +0800 Message-Id: <20200508163218.22592-6-lulu@redhat.com> In-Reply-To: <20200508163218.22592-1-lulu@redhat.com> References: <20200508163218.22592-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.120; envelope-from=lulu@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/08 02:25:09 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] 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, 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 --- hw/net/vhost_net.c | 39 ++- hw/virtio/Makefile.objs | 1 + hw/virtio/vhost-backend.c | 5 + hw/virtio/vhost-vdpa.c | 447 ++++++++++++++++++++++++++++++ hw/virtio/vhost.c | 14 + include/hw/virtio/vhost-backend.h | 8 +- include/hw/virtio/vhost-vdpa.h | 25 ++ include/hw/virtio/vhost.h | 1 + 8 files changed, 538 insertions(+), 2 deletions(-) create mode 100644 hw/virtio/vhost-vdpa.c create mode 100644 include/hw/virtio/vhost-vdpa.h diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 63b2a85d6e..1af39abaf3 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,29 @@ 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_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 +121,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 +138,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; @@ -433,6 +464,12 @@ VHostNetState *get_vhost_net(NetClientState *nc) vhost_net =3D vhost_user_get_vhost_net(nc); assert(vhost_net); break; +#endif +#ifdef CONFIG_VHOST_NET_VDPA + case NET_CLIENT_DRIVER_VHOST_VDPA: + vhost_net =3D vhost_vdpa_get_vhost_net(nc); + assert(vhost_net); + break; #endif default: break; diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index e2f70fbb89..e7c5d4a862 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -5,6 +5,7 @@ obj-y +=3D virtio.o obj-$(call lor,$(CONFIG_VHOST_USER),$(CONFIG_VHOST_KERNEL)) +=3D vhost.o v= host-backend.o common-obj-$(call lnot,$(call lor,$(CONFIG_VHOST_USER),$(CONFIG_VHOST_KERN= EL))) +=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 48905383f8..069ddb423d 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -285,6 +285,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..bac8a8aa2a --- /dev/null +++ b/hw/virtio/vhost-vdpa.c @@ -0,0 +1,447 @@ +/* + * 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); +} + +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 int vhost_vdpa_get_backend_features(struct vhost_dev *dev, + uint64_t *features) +{ + return vhost_vdpa_call(dev, VHOST_GET_BACKEND_FEATURES, features); +} + +static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque) +{ + struct vhost_vdpa *v; + uint64_t backend_features =3D 0; + int ret =3D 0; + + 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; + memory_listener_register(&v->listener, &address_space_memory); + + ret =3D vhost_vdpa_get_backend_features(dev, &backend_features); + /* + * In order to compatible with older version kernel, + * If the kernel not support this ioctl, + * set the msg_type for v2 by defeault + */ + if (ret) { + v->msg_type =3D VHOST_IOTLB_MSG_V2; + return 0; + } + if (backend_features & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2)) { + v->msg_type =3D VHOST_IOTLB_MSG_V2; + } else { + v->msg_type =3D VHOST_IOTLB_MSG; + } + 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) +{ + /*Using IOTLB API here,NOTE:please set the ulimit before using*/ + return INT_MAX; +} + +static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base, + struct vhost_log *log) +{ + return -1; +} + +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_vring_addr(struct vhost_dev *dev, + struct vhost_vring_addr *addr) +{ + return vhost_vdpa_call(dev, VHOST_SET_VRING_ADDR, addr); +} + +static int vhost_vdpa_set_vring_num(struct vhost_dev *dev, + struct vhost_vring_state *ring) +{ + return vhost_vdpa_call(dev, VHOST_SET_VRING_NUM, ring); +} + +static int vhost_vdpa_set_vring_base(struct vhost_dev *dev, + struct vhost_vring_state *ring) +{ + return vhost_vdpa_call(dev, VHOST_GET_VRING_BASE, ring); +} + +static int vhost_vdpa_get_vring_base(struct vhost_dev *dev, + struct vhost_vring_state *ring) +{ + + return vhost_vdpa_call(dev, VHOST_GET_VRING_BASE, ring); +} + +static int vhost_vdpa_set_vring_kick(struct vhost_dev *dev, + struct vhost_vring_file *file) +{ + return vhost_vdpa_call(dev, VHOST_SET_VRING_KICK, file); +} + +static int vhost_vdpa_set_vring_call(struct vhost_dev *dev, + struct vhost_vring_file *file) +{ + return vhost_vdpa_call(dev, VHOST_SET_VRING_CALL, file); +} + +static int vhost_vdpa_set_features(struct vhost_dev *dev, + uint64_t features) +{ + return vhost_vdpa_call(dev, VHOST_SET_FEATURES, &features); +} + +static int vhost_vdpa_get_features(struct vhost_dev *dev, + uint64_t *features) +{ + return vhost_vdpa_call(dev, VHOST_GET_FEATURES, features); +} + +static 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_set_owner(struct vhost_dev *dev) +{ + return vhost_vdpa_call(dev, VHOST_SET_OWNER, NULL); +} + +static int vhost_vdpa_reset_device(struct vhost_dev *dev) +{ + return vhost_vdpa_call(dev, VHOST_RESET_OWNER, NULL); +} + +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 *da= ta, + 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; + } + config =3D g_new0(struct vhost_vdpa_config, 1); + if (config =3D=3D NULL) { + return -EINVAL; + } + config->off =3D 0; + config->len =3D size; + memcpy(config->buf, data, size); + ret =3D vhost_vdpa_call(dev, VHOST_VDPA_SET_CONFIG, config); + g_free(config); + return ret; +} + + static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, + uint32_t config_len) +{ + struct vhost_vdpa_config *v_config =3D NULL; + int ret; + + if ((config_len > VHOST_VDPA_MAX_CONFIG_SIZE) || (config =3D=3D NULL)= ) { + return -1; + } + v_config =3D g_new0(struct vhost_vdpa_config, 1); + + if (v_config =3D=3D NULL) { + return -EINVAL; + } + ret =3D vhost_vdpa_call(dev, VHOST_VDPA_GET_CONFIG, v_config); + if ((v_config->len > config_len - v_config->off) || (v_config->len =3D= =3D 0)) { + g_free(v_config); + return -EINVAL; + } + + memcpy(config, v_config->buf + v_config->off, config_len); + g_free(v_config); + return ret; + } +static int vhost_vdpa_set_state(struct vhost_dev *dev, uint8_t state) +{ + return vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &state); +} + + +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_backend_memslots_limit =3D vhost_vdpa_memslots_limit, + .vhost_set_log_base =3D vhost_vdpa_set_log_base, + .vhost_set_mem_table =3D vhost_vdpa_set_mem_table, + .vhost_set_vring_addr =3D vhost_vdpa_set_vring_addr, + .vhost_set_vring_endian =3D NULL, + .vhost_set_vring_num =3D vhost_vdpa_set_vring_num, + .vhost_set_vring_base =3D vhost_vdpa_set_vring_base, + .vhost_get_vring_base =3D vhost_vdpa_get_vring_base, + .vhost_set_vring_kick =3D vhost_vdpa_set_vring_kick, + .vhost_set_vring_call =3D vhost_vdpa_set_vring_call, + .vhost_set_features =3D vhost_vdpa_set_features, + .vhost_get_features =3D vhost_vdpa_get_features, + .vhost_set_owner =3D vhost_vdpa_set_owner, + .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 4da0d5a6c5..6d2aa461d6 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -746,6 +746,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"); @@ -1493,6 +1499,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) { diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-ba= ckend.h index f823055167..8ac898a987 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); @@ -113,6 +115,7 @@ typedef int (*vhost_set_inflight_fd_op)(struct vhost_de= v *dev, struct vhost_inflight *inflight); =20 typedef int (*vhost_set_state_op)(struct vhost_dev *dev, uint8_t state); +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; @@ -139,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; @@ -154,9 +158,11 @@ typedef struct VhostOps { 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..9d64fbfea9 --- /dev/null +++ b/include/hw/virtio/vhost-vdpa.h @@ -0,0 +1,25 @@ +/* + * 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; + +#endif diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 085450c6f8..020956d5a9 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, --=20 2.21.1 From nobody Sun May 19 09:23:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1588955938; cv=none; d=zohomail.com; s=zohoarc; b=ZIRliEUOyHV8tejFhwiZgmfZHfY9Et23PQpHv0Yw6Qymm8U6udGytEqLpGnPKbfAiFg6ZWEGxxQC/79dutvvJhriH4EXAGC65PsUQgFeVOyInAGlZ4STjefav3GntcEEE2tpeGtqMZI0E0XkaNSQ8G6WekL162AqGffYGJU1NO0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588955938; 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=4NYMOlwHlixzzgRaLG76MCebSTu1Q6l9tvGPU/ZJbDs=; b=f2wKeRcSrduP1jAfSKegYPaTtYpKdOWykF2MTUoWLxcthU18s/oFDuydEvbKiEuaafLnbslIaapn9iIRGtr3i6olysUHRISe9odAGPEHnJ8pxsf5tWIml5Fp0S06mluzJPLO5XF8hyPbOnpcrteoB7+zT9DDE2OO+ecuDYTXwz4= 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 158895593867384.23609963471279; Fri, 8 May 2020 09:38:58 -0700 (PDT) Received: from localhost ([::1]:48020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jX61Z-0005Bu-CZ for importer@patchew.org; Fri, 08 May 2020 12:38:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jX5yU-0000sv-2D for qemu-devel@nongnu.org; Fri, 08 May 2020 12:35:46 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:41643 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 1jX5yT-0004Ld-3Z for qemu-devel@nongnu.org; Fri, 08 May 2020 12:35:45 -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-332-EzFbi5WyOHuuCKRoKEXgeg-1; Fri, 08 May 2020 12:35:38 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5C801800688; Fri, 8 May 2020 16:35:35 +0000 (UTC) Received: from laptop.redhat.com (ovpn-12-75.pek2.redhat.com [10.72.12.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6ACE26C760; Fri, 8 May 2020 16:35:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588955744; 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=4NYMOlwHlixzzgRaLG76MCebSTu1Q6l9tvGPU/ZJbDs=; b=DtmLKdNKeEqOWNmHOi0rINy4UVuihXJmZ+i7h0ScCxxSTutejnm5WcdYB/wxeG6eGbfHDO hOLYybTOjaLOsy0P3ijw5YWPTGdfLufjVTwBUkxjTpo6LMeXIiwXfUvdP5c8we7ylITVWp g9sWZuZ0W00xxOXFVcL8gd3MqMvRYbQ= X-MC-Unique: EzFbi5WyOHuuCKRoKEXgeg-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [RFC v2 6/9] virtio-bus: introduce queue_enabled method Date: Sat, 9 May 2020 00:32:15 +0800 Message-Id: <20200508163218.22592-7-lulu@redhat.com> In-Reply-To: <20200508163218.22592-1-lulu@redhat.com> References: <20200508163218.22592-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.120; envelope-from=lulu@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/08 02:25:09 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] 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 --- 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 04716b5f6c..09732a8836 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3169,6 +3169,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 Sun May 19 09:23:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1588956079; cv=none; d=zohomail.com; s=zohoarc; b=fMNjCJfbgiUiWh5Zd+AY0A2xpKHV2o4yKqjtd8scKyqPsFcOqfRHtiH3CAnAqrRuAkZ8DP2WjkRPYiEmuOh7Zs1/d2rP10ZsW9OEfhY4Z2DBto6tIZOAOgbvZ2fgPR8ExvmbFSVVcytHuDAa+olYJDwvJVb85PRrjTXY9mmMmU0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588956079; 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=flRErnfPL1KlEcs6edwYewnIX34j31+fMlIYn7HK+gM=; b=EOG/PF4+Vjx0YSMSFB5BDMouiXo2ulzOhsUJhuS8rByIJgajm94SFhMA6B27yfCmJAwGBoR6lquy+epdeMFEyR2Gxr+fIVF3gNKOUX28DCIDeOKtybtDkwzeYr9vvhAq9vhw7HsaxawfuJsj/m07UvgLxUH/za3feESVRuZU9iM= 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 1588956079969871.7286946902991; Fri, 8 May 2020 09:41:19 -0700 (PDT) Received: from localhost ([::1]:58110 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jX63q-00018Q-JD for importer@patchew.org; Fri, 08 May 2020 12:41:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33338) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jX5yk-0001AA-6M for qemu-devel@nongnu.org; Fri, 08 May 2020 12:36:02 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:55919 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 1jX5yj-0005HK-Cl for qemu-devel@nongnu.org; Fri, 08 May 2020 12:36: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-329-Xnj4ACN8PXu0d07DG6wHSQ-1; Fri, 08 May 2020 12:35:58 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2821E107ACCA; Fri, 8 May 2020 16:35:56 +0000 (UTC) Received: from laptop.redhat.com (ovpn-12-75.pek2.redhat.com [10.72.12.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55A636C760; Fri, 8 May 2020 16:35:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588955760; 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=flRErnfPL1KlEcs6edwYewnIX34j31+fMlIYn7HK+gM=; b=K9BVDrYN7QJJRE9JsFj3df0pMJkRVb7Ro1zvqam0bVi6dUUeTHxek9TT+RmHMxYfGzRiK1 z3TmHtiIqA3YC92u5UjWOslluhvXHC8F19kJpEPMWtm3gZznJMjf5xOcXMXPYEvI6B5E+u lk1LwmlNeT4dl+SbqAwbhekjmvTo+fM= X-MC-Unique: Xnj4ACN8PXu0d07DG6wHSQ-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [RFC v2 7/9] virito-pci: implement queue_enabled method Date: Sat, 9 May 2020 00:32:16 +0800 Message-Id: <20200508163218.22592-8-lulu@redhat.com> In-Reply-To: <20200508163218.22592-1-lulu@redhat.com> References: <20200508163218.22592-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/08 01:34:54 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" 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 c6b47a9c73..4aaf5d953e 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1103,6 +1103,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) { @@ -2053,6 +2065,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 Sun May 19 09:23:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1588956030; cv=none; d=zohomail.com; s=zohoarc; b=dr3WJTD1ajsJRuLw7JAZMjHdQqDzu0mF+th1F3nhHgABsCGL1oiR30k2cYybGXSbBYur2EykgZPjk4Xc4Hmllrub+DkcVpD2aySb8GiUrjzrYvryO9q7AVWfm/ZxkTHf+/udUNsm10jJPjmQiezGHPHtWlPgv+Wh6+deyB2ekL4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588956030; 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=tZuxKlrob2Ti4p/kqBbh1fKtv4u9PKjb4qN3Quxs17k=; b=RBMjsFOypYmfSL19+Q4RQSFnwsvOstouEiFiIsNpLVzd1rC2J55ucyq85xx4NszVwqi+CMYICQfqOB9SM1rSTmOhKF//fCR3HFhxnh/Uw9VBSSZFuayUa5dr36U2uvaBNEsE1ujMq1vxIcHfCchLYn4cVFBcYnbA3ca2PvpKpK4= 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 15889560306821023.864018225252; Fri, 8 May 2020 09:40:30 -0700 (PDT) Received: from localhost ([::1]:55222 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jX633-00088S-AD for importer@patchew.org; Fri, 08 May 2020 12:40:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33452) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jX5z6-0001XT-2Y for qemu-devel@nongnu.org; Fri, 08 May 2020 12:36:24 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:25420 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 1jX5z5-0006bC-BU for qemu-devel@nongnu.org; Fri, 08 May 2020 12:36:23 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-438-05nrjMPNMa-edHQoXuA1Yw-1; Fri, 08 May 2020 12:36:20 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EEDE8464; Fri, 8 May 2020 16:36:17 +0000 (UTC) Received: from laptop.redhat.com (ovpn-12-75.pek2.redhat.com [10.72.12.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF6F46AD18; Fri, 8 May 2020 16:35:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588955782; 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=tZuxKlrob2Ti4p/kqBbh1fKtv4u9PKjb4qN3Quxs17k=; b=JePckwcewv/K1ktTnJVNuH6LwKhNg8iLY0H7GphZ53316InRG67SjMKffAI9xljSUmtrsN a3mBAlBi5+/xd5CG9cH2VTKkY9lAqHwCB6ZJAg9UyWgbGE8MNjHrUM26GuWkNljkRehFlD yBl+cwYqH6GL1YyODeIDdn9rVyZYyjE= X-MC-Unique: 05nrjMPNMa-edHQoXuA1Yw-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [RFC v2 8/9] vhost_net: set vq ready during start if necessary Date: Sat, 9 May 2020 00:32:17 +0800 Message-Id: <20200508163218.22592-9-lulu@redhat.com> In-Reply-To: <20200508163218.22592-1-lulu@redhat.com> References: <20200508163218.22592-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.120; envelope-from=lulu@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/08 02:25:09 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] 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 Signed-off-by: Jason Wang --- hw/net/vhost_net.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 1af39abaf3..eff9ec9177 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -383,6 +383,10 @@ int vhost_net_start(VirtIODevice *dev, NetClientState = *ncs, goto err_start; } } + + if (virtio_queue_enabled(dev, i)) { + vhost_set_vring_ready(peer); + } } =20 return 0; --=20 2.21.1 From nobody Sun May 19 09:23:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1588955891; cv=none; d=zohomail.com; s=zohoarc; b=a/ETKyiXypopG4eLyMySb+LivYTII26ikoYGATAZ46BHbFs3mqZ4mDe5agntFsYI+6Q3HDhVnkbfVT69taVCEZb+leWtJnYVRdWoOktEU/y0j8V3SpV2WUNAF42pBJVJ94KxhIME026beRI7SxKEc3uyonlm195uVl+7b/3VzSg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588955891; 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=0+UijJbg4+qyAryZoZTlBXF6cXTGUPho1cE100TLt24=; b=BeMByIzoe80rOiuaMtoxzhlbPghWU1qYlidtwbk4qk6Lrzezz4uJ3qap1aL+ZGec2xwdNf7rRFCvfOC6arvdWn1lyDFJfTSP4Er0pIitQYyGOk4yJ7PjymEZtWyW0j29hi4CqWaBuZ/c7O0SFa9HEftUiAW8RsnZ7mCC3G7dV1M= 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 158895589161232.5989023421331; Fri, 8 May 2020 09:38:11 -0700 (PDT) Received: from localhost ([::1]:45124 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jX60o-0003mT-Ed for importer@patchew.org; Fri, 08 May 2020 12:38:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jX5zQ-0001xT-24 for qemu-devel@nongnu.org; Fri, 08 May 2020 12:36:44 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:60426 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 1jX5zO-0007nC-Vs for qemu-devel@nongnu.org; Fri, 08 May 2020 12:36:43 -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-187-8N2YBCf-Pimh3P9VqZQ1Zw-1; Fri, 08 May 2020 12:36:40 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 69E4C464; Fri, 8 May 2020 16:36:37 +0000 (UTC) Received: from laptop.redhat.com (ovpn-12-75.pek2.redhat.com [10.72.12.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id E9AF86AD0A; Fri, 8 May 2020 16:36:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588955802; 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=0+UijJbg4+qyAryZoZTlBXF6cXTGUPho1cE100TLt24=; b=TWesI5F3rEOv51+uX0l7Nu1dXm0l9BlIZpA0zz3gigGoFjTgqV3fKr5qFrcXNIa/mPvVxE uBwcpMj14LZYuGK+b9cHDXub65qMdqQB7pz8O01JAsLnFhNA44W6xDEDtNSB8jx6C0FXuH ALeJbOaDJpa1+mcFXJzy79f7BR+/GaA= X-MC-Unique: 8N2YBCf-Pimh3P9VqZQ1Zw-1 From: Cindy Lu To: mst@redhat.com, armbru@redhat.com, eblake@redhat.com, cohuck@redhat.com, jasowang@redhat.com Subject: [RFC v2 9/9] vhost: introduce vhost_set_vring_ready method Date: Sat, 9 May 2020 00:32:18 +0800 Message-Id: <20200508163218.22592-10-lulu@redhat.com> In-Reply-To: <20200508163218.22592-1-lulu@redhat.com> References: <20200508163218.22592-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/08 11:31:41 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 eff9ec9177..6911282a0a 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -375,7 +375,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 @@ -496,6 +496,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 b47844bf29..247432a3b2 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