From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCuV6-00060Y-3F for qemu-devel@nongnu.org; Tue, 14 Jun 2016 15:59:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCuV0-0001SW-3R for qemu-devel@nongnu.org; Tue, 14 Jun 2016 15:59:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55108) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCuUz-0001SS-RG for qemu-devel@nongnu.org; Tue, 14 Jun 2016 15:59:46 -0400 Date: Tue, 14 Jun 2016 22:59:44 +0300 From: "Michael S. Tsirkin" Message-ID: <20160614225944-mutt-send-email-mst@redhat.com> References: <1465934227-16558-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1465934227-16558-1-git-send-email-mst@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL v2 08/32] vhost-net: save & restore vhost-user acked features List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , =?iso-8859-1?Q?Marc-Andr=E9?= Lureau , Yuanhan Liu , Victor Kaplansky , Jason Wang From: Marc-Andr=E9 Lureau The initial vhost-user connection sets the features to be negotiated with the driver. Renegotiation isn't possible without device reset. To handle reconnection of vhost-user backend, ensure the same set of features are provided, and reuse already acked features. Signed-off-by: Marc-Andr=E9 Lureau Tested-by: Yuanhan Liu Reviewed-by: Yuanhan Liu Reviewed-by: Victor Kaplansky Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/net/vhost-user.h | 1 + include/net/vhost_net.h | 3 +++ hw/net/vhost_net.c | 27 ++++++++++++++++++++++++++- net/vhost-user.c | 10 ++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/include/net/vhost-user.h b/include/net/vhost-user.h index 85109f6..efae35d 100644 --- a/include/net/vhost-user.h +++ b/include/net/vhost-user.h @@ -13,5 +13,6 @@ =20 struct vhost_net; struct vhost_net *vhost_user_get_vhost_net(NetClientState *nc); +uint64_t vhost_user_get_acked_features(NetClientState *nc); =20 #endif /* VHOST_USER_H_ */ diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 3389b41..0bd4877 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -31,4 +31,7 @@ int vhost_net_notify_migration_done(VHostNetState *net,= char* mac_addr); VHostNetState *get_vhost_net(NetClientState *nc); =20 int vhost_set_vring_enable(NetClientState * nc, int enable); + +uint64_t vhost_net_get_acked_features(VHostNetState *net); + #endif diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 805a0df..b28881f 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -120,6 +120,11 @@ uint64_t vhost_net_get_max_queues(VHostNetState *net= ) return net->dev.max_queues; } =20 +uint64_t vhost_net_get_acked_features(VHostNetState *net) +{ + return net->dev.acked_features; +} + static int vhost_net_get_fd(NetClientState *backend) { switch (backend->info->type) { @@ -136,6 +141,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *opt= ions) int r; bool backend_kernel =3D options->backend_type =3D=3D VHOST_BACKEND_T= YPE_KERNEL; struct vhost_net *net =3D g_malloc(sizeof *net); + uint64_t features =3D 0; =20 if (!options->net_backend) { fprintf(stderr, "vhost-net requires net backend to be setup\n"); @@ -183,8 +189,21 @@ struct vhost_net *vhost_net_init(VhostNetOptions *op= tions) goto fail; } } + /* Set sane init value. Override when guest acks. */ - vhost_net_ack_features(net, 0); + if (net->nc->info->type =3D=3D NET_CLIENT_OPTIONS_KIND_VHOST_USER) { + features =3D vhost_user_get_acked_features(net->nc); + if (~net->dev.features & features) { + fprintf(stderr, "vhost lacks feature mask %" PRIu64 + " for backend\n", + (uint64_t)(~net->dev.features & features)); + vhost_dev_cleanup(&net->dev); + goto fail; + } + } + + vhost_net_ack_features(net, features); + return net; fail: g_free(net); @@ -447,10 +466,16 @@ uint64_t vhost_net_get_features(struct vhost_net *n= et, uint64_t features) { return features; } + void vhost_net_ack_features(struct vhost_net *net, uint64_t features) { } =20 +uint64_t vhost_net_get_acked_features(VHostNetState *net) +{ + return 0; +} + bool vhost_net_virtqueue_pending(VHostNetState *net, int idx) { return false; diff --git a/net/vhost-user.c b/net/vhost-user.c index 41ddb4b..d72ce9b 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -23,6 +23,7 @@ typedef struct VhostUserState { CharDriverState *chr; VHostNetState *vhost_net; int watch; + uint64_t acked_features; } VhostUserState; =20 typedef struct VhostUserChardevProps { @@ -37,6 +38,13 @@ VHostNetState *vhost_user_get_vhost_net(NetClientState= *nc) return s->vhost_net; } =20 +uint64_t vhost_user_get_acked_features(NetClientState *nc) +{ + VhostUserState *s =3D DO_UPCAST(VhostUserState, nc, nc); + assert(nc->info->type =3D=3D NET_CLIENT_OPTIONS_KIND_VHOST_USER); + return s->acked_features; +} + static int vhost_user_running(VhostUserState *s) { return (s->vhost_net) ? 1 : 0; @@ -56,6 +64,8 @@ static void vhost_user_stop(int queues, NetClientState = *ncs[]) } =20 if (s->vhost_net) { + /* save acked features */ + s->acked_features =3D vhost_net_get_acked_features(s->vhost_= net); vhost_net_cleanup(s->vhost_net); s->vhost_net =3D NULL; } --=20 MST