From patchwork Fri Apr 1 11:16:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 604734 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qbzbV35GCz9sC3 for ; Fri, 1 Apr 2016 22:26:14 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=pkztfWl1; dkim-atps=neutral Received: from localhost ([::1]:43595 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alxDQ-0004m0-3g for incoming@patchwork.ozlabs.org; Fri, 01 Apr 2016 07:26:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alx4i-00065t-54 for qemu-devel@nongnu.org; Fri, 01 Apr 2016 07:17:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1alx4g-0001q2-3p for qemu-devel@nongnu.org; Fri, 01 Apr 2016 07:17:12 -0400 Received: from mail-qg0-x235.google.com ([2607:f8b0:400d:c04::235]:35219) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alx4f-0001py-Uh for qemu-devel@nongnu.org; Fri, 01 Apr 2016 07:17:10 -0400 Received: by mail-qg0-x235.google.com with SMTP id y89so93623687qge.2 for ; Fri, 01 Apr 2016 04:17:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FQNACTRottszKp1EWFqmRb+y5ZI53WTkEIMQ/v38peI=; b=pkztfWl1MzXEAQc1u8a/uwrbuyldsIX3g84Mgzk9M4A/PfE/XZI3s/IdzB72uLLIJ4 J+5389ySj54GNcFPpF1GPxGviLXei60pnthRJdWwAFW3Z0Vwxqzy3+dMo2VCwJJ6YpZh Tc7jqyFeFQd9JNsXk3/v4Wh7WKBdOsNjwRV4QPPtOZaclSrnjwfAfLO2rqe1DuDsPDuO vdKFNlkYQ4atdfwLO5Xh7jKJgvgSJj++aru5DBYZQLYDWXguNSvUcVxX3QphsQIZsW6a UN5utoppX5pbutDrOVfCkl9/1NcT4dBl6hB69vF72zpNGBQdAc3zMC4OSPj+65EfuxJD grzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=FQNACTRottszKp1EWFqmRb+y5ZI53WTkEIMQ/v38peI=; b=DterCLqEv969Ui4PqMqVPdYP3n2v8qQqY/M6CcRKKyMbtIi1FuJsTPFnS1GXRk6LwM wZnsDkeprm+rBYyXs8UEe/Ik/ENVIt72QekVmrf1ByMa6HmmpPMp30z+1fkSTZwUw8ev wiGIOrii/jFQF0Il0aU8aMY7DYsHaSAXTnSdVC7jUOxJNdvHkN4feuwDl38GZx74eQEt uYqG4VJ0BMCEAz3CZKUajg4nX5EbwtGNZqx1u2d+XuBc78eetfKoB2qY8anR3UYPTEuH 93BQys6XRs8qVZp1bkkzBru1qTaXWu2mwftqPGBIjAhryeqS+V9KOu0nc4YcDn1tE9Kt +YUw== X-Gm-Message-State: AD7BkJL3NihpS0CRvbIAghIWkmsRhh+wD7PoIiaQOcYIjeTAJ7PQHhckKNSReLZqQNnjxw== X-Received: by 10.140.175.136 with SMTP id v130mr6359451qhv.74.1459509429633; Fri, 01 Apr 2016 04:17:09 -0700 (PDT) Received: from localhost (bne75-h02-31-39-163-232.dsl.sta.abo.bbox.fr. [31.39.163.232]) by smtp.gmail.com with ESMTPSA id a203sm5839951qha.31.2016.04.01.04.17.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Apr 2016 04:17:08 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Fri, 1 Apr 2016 13:16:24 +0200 Message-Id: <1459509388-6185-15-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1459509388-6185-1-git-send-email-marcandre.lureau@redhat.com> References: <1459509388-6185-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c04::235 Cc: Yuanhan Liu , "Michael S. Tsirkin" , Ilya Maximets , jonshin@cisco.com, Tetsuya Mukawa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [Qemu-devel] [PATCH 14/18] vhost-net: save & restore vhost-user acked features X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Marc-André 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é Lureau --- hw/net/vhost_net.c | 21 ++++++++++++++++++++- include/net/vhost-user.h | 1 + include/net/vhost_net.h | 3 +++ net/vhost-user.c | 10 ++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 6c40c4e..ee39e9c 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; } +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) { @@ -148,6 +153,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options) int r; bool backend_kernel = options->backend_type == VHOST_BACKEND_TYPE_KERNEL; struct vhost_net *net = g_malloc(sizeof *net); + uint64_t features = 0; if (!options->net_backend) { fprintf(stderr, "vhost-net requires net backend to be setup\n"); @@ -197,8 +203,21 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options) goto fail; } } + /* Set sane init value. Override when guest acks. */ - vhost_net_ack_features(net, 0); + if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER) { + features = 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); 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 @@ struct vhost_net; struct vhost_net *vhost_user_get_vhost_net(NetClientState *nc); +uint64_t vhost_user_get_acked_features(NetClientState *nc); #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); int vhost_set_vring_enable(NetClientState * nc, int enable); + +uint64_t vhost_net_get_acked_features(VHostNetState *net); + #endif diff --git a/net/vhost-user.c b/net/vhost-user.c index 54849e9..ae63e20 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; typedef struct VhostUserChardevProps { @@ -39,6 +40,13 @@ VHostNetState *vhost_user_get_vhost_net(NetClientState *nc) return s->vhost_net; } +uint64_t vhost_user_get_acked_features(NetClientState *nc) +{ + VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc); + assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER); + return s->acked_features; +} + static int vhost_user_running(VhostUserState *s) { return (s->vhost_net) ? 1 : 0; @@ -58,6 +66,8 @@ static void vhost_user_stop(int queues, NetClientState *ncs[]) } if (s->vhost_net) { + /* save acked features */ + s->acked_features = vhost_net_get_acked_features(s->vhost_net); vhost_net_cleanup(s->vhost_net); s->vhost_net = NULL; }