From nobody Mon May 20 13:25:00 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 1664175201600511.48632171921804; Sun, 25 Sep 2022 23:53:21 -0700 (PDT) Received: from localhost ([::1]:56144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ochzU-0000Rp-0d for importer@patchew.org; Mon, 26 Sep 2022 02:53:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ochlR-0001Sy-PJ for qemu-devel@nongnu.org; Mon, 26 Sep 2022 02:38:49 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.220]:45522 helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ochlJ-0007ah-Q4 for qemu-devel@nongnu.org; Mon, 26 Sep 2022 02:38:47 -0400 Received: from clientip-36.111.64.85 (unknown [172.18.0.188]) by chinatelecom.cn (HERMES) with SMTP id 527C22800B2; Mon, 26 Sep 2022 14:38:31 +0800 (CST) Received: from ([36.111.64.85]) by app0023 with ESMTP id ea07289672984240b2be5a8c9efd8526 for qemu-devel@nongnu.org; Mon, 26 Sep 2022 14:38:32 CST HMM_SOURCE_IP: 172.18.0.188:40300.940860629 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: ea07289672984240b2be5a8c9efd8526 X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 36.111.64.85 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: qemu-devel Cc: "Michael S . Tsirkin" , Jason Wang , tugy@chinatelecom.cn, baiyw2@chinatelecom.cn, dengpc12@chinatelecom.cn, liuym16@chinatelecom.cn, yangchg@chinatelecom.cn, yuanmh12@chinatelecom.cn, zhoupx@chinatelecom.cn, huangy81@chinatelecom.cn, lic121@chinatelecom.cn Subject: [PATCH 1/2] vhost-user: Refactor vhost acked features saving Date: Mon, 26 Sep 2022 14:36:40 +0800 Message-Id: <20220926063641.25038-2-huangy81@chinatelecom.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220926063641.25038-1-huangy81@chinatelecom.cn> References: <20220926063641.25038-1-huangy81@chinatelecom.cn> 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1664175203844100001 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 5bcd8a6285..00d46613d3 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 b1a0247b59..c512cc9727 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 2.27.0 From nobody Mon May 20 13:25:00 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 1664174793105309.29985185089197; Sun, 25 Sep 2022 23:46:33 -0700 (PDT) Received: from localhost ([::1]:41110 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ochst-0005qV-EB for importer@patchew.org; Mon, 26 Sep 2022 02:46:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43168) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ochlR-0001T2-Pe for qemu-devel@nongnu.org; Mon, 26 Sep 2022 02:38:49 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.220]:45546 helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ochlJ-0007aj-Ps for qemu-devel@nongnu.org; Mon, 26 Sep 2022 02:38:46 -0400 Received: from clientip-36.111.64.85 (unknown [172.18.0.188]) by chinatelecom.cn (HERMES) with SMTP id 1AB332800BF; Mon, 26 Sep 2022 14:38:34 +0800 (CST) Received: from ([36.111.64.85]) by app0023 with ESMTP id 15b3ed7ecbe84c73ac207579295e03eb for qemu-devel@nongnu.org; Mon, 26 Sep 2022 14:38:34 CST HMM_SOURCE_IP: 172.18.0.188:40300.940860629 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: 15b3ed7ecbe84c73ac207579295e03eb X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 36.111.64.85 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: qemu-devel Cc: "Michael S . Tsirkin" , Jason Wang , tugy@chinatelecom.cn, baiyw2@chinatelecom.cn, dengpc12@chinatelecom.cn, liuym16@chinatelecom.cn, yangchg@chinatelecom.cn, yuanmh12@chinatelecom.cn, zhoupx@chinatelecom.cn, huangy81@chinatelecom.cn, lic121@chinatelecom.cn Subject: [PATCH 2/2] vhost-net: Fix the virito features negotiation flaw Date: Mon, 26 Sep 2022 14:36:41 +0800 Message-Id: <20220926063641.25038-3-huangy81@chinatelecom.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220926063641.25038-1-huangy81@chinatelecom.cn> References: <20220926063641.25038-1-huangy81@chinatelecom.cn> 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1664174797234100001 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 d28f8b974b..2bffc276b9 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 dd0d056fde..69c00b4e74 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -918,6 +918,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 387e913e4e..3a5579b075 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 2.27.0