From patchwork Mon Jun 6 16:45:05 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: 9158921 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1D8A160572 for ; Mon, 6 Jun 2016 17:18:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D5A428335 for ; Mon, 6 Jun 2016 17:18:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 021D72834F; Mon, 6 Jun 2016 17:18:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DBDBC28335 for ; Mon, 6 Jun 2016 17:18:36 +0000 (UTC) Received: from localhost ([::1]:44052 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9yAb-0004y5-Tz for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 Jun 2016 13:18:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49621) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9xel-0004Q6-7D for qemu-devel@nongnu.org; Mon, 06 Jun 2016 12:45:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b9xej-0005by-NZ for qemu-devel@nongnu.org; Mon, 06 Jun 2016 12:45:39 -0400 Received: from mail-qg0-x244.google.com ([2607:f8b0:400d:c04::244]:35531) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9xej-0005bu-IG for qemu-devel@nongnu.org; Mon, 06 Jun 2016 12:45:37 -0400 Received: by mail-qg0-x244.google.com with SMTP id t106so7149286qgt.2 for ; Mon, 06 Jun 2016 09:45:37 -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=d/eT7NzskUU1S89UCKeqJn/Bk7317ACAzvcMxGvbCjg=; b=i8JNpQbEbQTaltRFhavh96NJ3cAK2/oyvJe4Pix/YmBWHR5tbhPajXy2vDnfvB6Bke Seg52RUNorTVNFORPl0BIPxQuetDBSYsJ10zvH5SQ1pv/AZu9A0z/1CPMRhPBCmNwo3S vydcMqMvgoFbTOCf6geNKTanySOfEkx++yzLebGyEmmd6Y/wNA51ycUoqO91spKojBk1 siX/gvbKnWtiXhYSXsAqicIk8T7hMdgRVLGdTThuCN9j8+9dJML6hmuVwWPNCQ3AE70m 5lbPdZZ91wiYv1Mi9Xok6oxw37nwF1uaiihkkU2XYQhNNcARNjbl9be7B8RJEADshsJp BWLw== 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=d/eT7NzskUU1S89UCKeqJn/Bk7317ACAzvcMxGvbCjg=; b=i3COCZNzqDM/w7GR89Q/PV4KayMj/u+DorFbscyNeNAz8dD5D8fwQS9/Y/HnguL0fS TSeohvrADEzPas1KEb5p97sLp2vQf1ChLMYa/H5OP33SW/qxt6elBHdrJ8gZ+Br57N0U Gfi66derF4KOgnB/Y6lujD2dGvJ7WkfUp6EMX59mUV60JTEqVfWHD0bI9rhQRbJxcHBH mtEAfIedwKZCUdfvhYaCFfZmOPSet7IVp7MyTXsvK4oaF9CdxhmCvD/7A6two8d0aXwA W4v63VVbsLkSGwwij0VZ+sV+rLVm6X4B8S2VnCHi/74hKGrcfnR8sJXHWIRbgvhcMoa0 LWlw== X-Gm-Message-State: ALyK8tJrSR9yNYw+QzrbnlKdSSOWyxsBQbw9dXmyPQXUPO6YrCbNrMykllxHF8QVT3+69g== X-Received: by 10.140.19.231 with SMTP id 94mr10234551qgh.39.1465231537155; Mon, 06 Jun 2016 09:45:37 -0700 (PDT) Received: from localhost (APoitiers-110-1-1-130.w193-248.abo.wanadoo.fr. [193.248.103.130]) by smtp.gmail.com with ESMTPSA id w48sm5367225qgd.42.2016.06.06.09.45.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jun 2016 09:45:36 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Mon, 6 Jun 2016 18:45:05 +0200 Message-Id: <1465231508-30183-8-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1465231508-30183-1-git-send-email-marcandre.lureau@redhat.com> References: <1465231508-30183-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::244 Subject: [Qemu-devel] [PATCH 07/10] vhost-net: save & restore vhost-user acked features X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yuanhan Liu , "Michael S . Tsirkin" , Ilya Maximets , jonshin@cisco.com, Tetsuya Mukawa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Tested-by: Yuanhan Liu Reviewed-by: Yuanhan Liu --- hw/net/vhost_net.c | 27 ++++++++++++++++++++++++++- include/net/vhost-user.h | 1 + include/net/vhost_net.h | 3 +++ net/vhost-user.c | 10 ++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) 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; } +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 *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"); @@ -183,8 +189,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); @@ -447,10 +466,16 @@ uint64_t vhost_net_get_features(struct vhost_net *net, uint64_t features) { return features; } + void vhost_net_ack_features(struct vhost_net *net, uint64_t features) { } +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/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 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; typedef struct VhostUserChardevProps { @@ -37,6 +38,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; @@ -56,6 +64,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; }