From nobody Sat May 18 13:16:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 166697769501088.47140177823621; Fri, 28 Oct 2022 10:21:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooT27-0005Ra-LJ; Fri, 28 Oct 2022 13:20:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooT24-0005Pr-Ve for qemu-devel@nongnu.org; Fri, 28 Oct 2022 13:20:36 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.220] helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooT22-00025M-Jg for qemu-devel@nongnu.org; Fri, 28 Oct 2022 13:20:36 -0400 Received: from clientip-125.69.42.35 (unknown [172.18.0.188]) by chinatelecom.cn (HERMES) with SMTP id 1ADCE28009E; Sat, 29 Oct 2022 01:20:26 +0800 (CST) Received: from ([125.69.42.35]) by app0023 with ESMTP id 166215442b51445c9e42481fe7a9d374 for qemu-devel@nongnu.org; Sat, 29 Oct 2022 01:20:28 CST HMM_SOURCE_IP: 172.18.0.188:47282.275842701 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: 166215442b51445c9e42481fe7a9d374 X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 125.69.42.35 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: qemu-devel Cc: "Michael S . Tsirkin" , Jason Wang , Stefano Garzarella , Raphael Norwitz , =?UTF-8?q?Hyman=20Huang=28=E9=BB=84=E5=8B=87=29?= , Guoyi Tu Subject: [PATCH v1 1/2] vhost-user: Refactor vhost acked features saving Date: Sat, 29 Oct 2022 01:20:18 +0800 Message-Id: <8f537f6a484cfdac236fd6307f796660ae562226.1666974839.git.huangy81@chinatelecom.cn> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=42.123.76.220; envelope-from=huangy81@chinatelecom.cn; helo=chinatelecom.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1666977697019100011 From: Hyman Huang(=E9=BB=84=E5=8B=87) Abstract vhost acked features saving into vhost_user_save_acked_features, export it as util function. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) Signed-off-by: Guoyi Tu --- include/net/vhost-user.h | 2 ++ net/vhost-user.c | 35 +++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/include/net/vhost-user.h b/include/net/vhost-user.h index 5bcd8a6..00d4661 100644 --- a/include/net/vhost-user.h +++ b/include/net/vhost-user.h @@ -14,5 +14,7 @@ struct vhost_net; struct vhost_net *vhost_user_get_vhost_net(NetClientState *nc); uint64_t vhost_user_get_acked_features(NetClientState *nc); +void vhost_user_save_acked_features(NetClientState *nc, + bool cleanup); =20 #endif /* VHOST_USER_H */ diff --git a/net/vhost-user.c b/net/vhost-user.c index b1a0247..c512cc9 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -45,24 +45,31 @@ uint64_t vhost_user_get_acked_features(NetClientState *= nc) return s->acked_features; } =20 -static void vhost_user_stop(int queues, NetClientState *ncs[]) +void vhost_user_save_acked_features(NetClientState *nc, bool cleanup) { NetVhostUserState *s; + + s =3D DO_UPCAST(NetVhostUserState, nc, nc); + if (s->vhost_net) { + uint64_t features =3D vhost_net_get_acked_features(s->vhost_net); + if (features) { + s->acked_features =3D features; + } + + if (cleanup) { + vhost_net_cleanup(s->vhost_net); + } + } +} + +static void vhost_user_stop(int queues, NetClientState *ncs[]) +{ int i; =20 for (i =3D 0; i < queues; i++) { assert(ncs[i]->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_USER); =20 - s =3D DO_UPCAST(NetVhostUserState, nc, ncs[i]); - - if (s->vhost_net) { - /* save acked features */ - uint64_t features =3D vhost_net_get_acked_features(s->vhost_ne= t); - if (features) { - s->acked_features =3D features; - } - vhost_net_cleanup(s->vhost_net); - } + vhost_user_save_acked_features(ncs[i], true); } } =20 @@ -251,11 +258,7 @@ static void chr_closed_bh(void *opaque) s =3D DO_UPCAST(NetVhostUserState, nc, ncs[0]); =20 for (i =3D queues -1; i >=3D 0; i--) { - s =3D DO_UPCAST(NetVhostUserState, nc, ncs[i]); - - if (s->vhost_net) { - s->acked_features =3D vhost_net_get_acked_features(s->vhost_ne= t); - } + vhost_user_save_acked_features(ncs[i], false); } =20 qmp_set_link(name, false, &err); --=20 1.8.3.1 From nobody Sat May 18 13:16:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666977693709930.2523005465584; Fri, 28 Oct 2022 10:21:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooT28-0005S0-Ex; Fri, 28 Oct 2022 13:20:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooT24-0005Pq-Uq for qemu-devel@nongnu.org; Fri, 28 Oct 2022 13:20:36 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.220] helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooT22-00025N-JM for qemu-devel@nongnu.org; Fri, 28 Oct 2022 13:20:36 -0400 Received: from clientip-125.69.42.35 (unknown [172.18.0.188]) by chinatelecom.cn (HERMES) with SMTP id DE5C32800AB; Sat, 29 Oct 2022 01:20:28 +0800 (CST) Received: from ([125.69.42.35]) by app0023 with ESMTP id dfb19039c1cb43429ae8a270a055d071 for qemu-devel@nongnu.org; Sat, 29 Oct 2022 01:20:29 CST HMM_SOURCE_IP: 172.18.0.188:47282.275842701 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: dfb19039c1cb43429ae8a270a055d071 X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 125.69.42.35 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: qemu-devel Cc: "Michael S . Tsirkin" , Jason Wang , Stefano Garzarella , Raphael Norwitz , =?UTF-8?q?Hyman=20Huang=28=E9=BB=84=E5=8B=87=29?= , Guoyi Tu Subject: [PATCH v1 2/2] vhost-net: Fix the virito features negotiation flaw Date: Sat, 29 Oct 2022 01:20:19 +0800 Message-Id: <8eebb62661f0cc58b1f2fe644491068c8d9ec9c9.1666974839.git.huangy81@chinatelecom.cn> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=42.123.76.220; envelope-from=huangy81@chinatelecom.cn; helo=chinatelecom.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1666977695547100001 From: Hyman Huang(=E9=BB=84=E5=8B=87) Save the acked_features once it be configured by guest virtio driver so it can't miss any features. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) Signed-off-by: Guoyi Tu --- hw/net/vhost_net.c | 9 +++++++++ hw/net/virtio-net.c | 5 +++++ include/net/vhost_net.h | 2 ++ 3 files changed, 16 insertions(+) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index d28f8b9..2bffc27 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -141,6 +141,15 @@ uint64_t vhost_net_get_acked_features(VHostNetState *n= et) return net->dev.acked_features; } =20 +void vhost_net_save_acked_features(NetClientState *nc) +{ + if (nc->info->type !=3D NET_CLIENT_DRIVER_VHOST_USER) { + return; + } + + vhost_user_save_acked_features(nc, false); +} + static int vhost_net_get_fd(NetClientState *backend) { switch (backend->info->type) { diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index e9f696b..5f8f788 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -924,6 +924,11 @@ static void virtio_net_set_features(VirtIODevice *vdev= , uint64_t features) continue; } vhost_net_ack_features(get_vhost_net(nc->peer), features); + /* + * keep acked_features in NetVhostUserState up-to-date so it + * can't miss any features configured by guest virtio driver. + */ + vhost_net_save_acked_features(nc->peer); } =20 if (virtio_has_feature(features, VIRTIO_NET_F_CTRL_VLAN)) { diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 387e913..3a5579b 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -46,6 +46,8 @@ int vhost_set_vring_enable(NetClientState * nc, int enabl= e); =20 uint64_t vhost_net_get_acked_features(VHostNetState *net); =20 +void vhost_net_save_acked_features(NetClientState *nc); + int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu); =20 #endif --=20 1.8.3.1