From nobody Tue May 14 18:25:52 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 1671449915397779.4753203587005; Mon, 19 Dec 2022 03:38:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7ES7-0002AF-Cw; Mon, 19 Dec 2022 06:37:03 -0500 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 1p7ES5-00029J-Vx for qemu-devel@nongnu.org; Mon, 19 Dec 2022 06:37:02 -0500 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 1p7ES3-00046R-KS for qemu-devel@nongnu.org; Mon, 19 Dec 2022 06:37:01 -0500 Received: from clientip-171.223.98.159 (unknown [172.18.0.188]) by chinatelecom.cn (HERMES) with SMTP id 90B4E280090; Mon, 19 Dec 2022 19:36:48 +0800 (CST) Received: from ([171.223.98.159]) by app0023 with ESMTP id 85bf7cffbb2943379d530262211b3d2e for qemu-devel@nongnu.org; Mon, 19 Dec 2022 19:36:50 CST HMM_SOURCE_IP: 172.18.0.188:50724.913608764 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: 85bf7cffbb2943379d530262211b3d2e X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 171.223.98.159 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: qemu-devel Cc: armbru@redhat.com, dgilbert@redhat.com, eblake@redhat.com, jasowang@redhat.com, lvivier@redhat.com, mst@redhat.com, Liuxiangdong , =?UTF-8?q?Hyman=20Huang=28=E9=BB=84=E5=8B=87=29?= , Guoyi Tu Subject: [PATCH v5 1/3] vhost-user: Refactor vhost acked features saving Date: Mon, 19 Dec 2022 06:36:40 -0500 Message-Id: <014fb6ea4baed1cb209e0ba2fb723a357bc4f259.1671449732.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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1671449915933100001 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 | 1 + net/vhost-user.c | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/include/net/vhost-user.h b/include/net/vhost-user.h index 5bcd8a6..35bf619 100644 --- a/include/net/vhost-user.h +++ b/include/net/vhost-user.h @@ -14,5 +14,6 @@ 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); =20 #endif /* VHOST_USER_H */ diff --git a/net/vhost-user.c b/net/vhost-user.c index b1a0247..40a2fe8 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -45,10 +45,23 @@ 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) { 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; + } + } +} + +static void vhost_user_stop(int queues, NetClientState *ncs[]) +{ int i; + NetVhostUserState *s; =20 for (i =3D 0; i < queues; i++) { assert(ncs[i]->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_USER); @@ -56,11 +69,7 @@ static void vhost_user_stop(int queues, NetClientState *= ncs[]) s =3D DO_UPCAST(NetVhostUserState, nc, ncs[i]); =20 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_user_save_acked_features(ncs[i]); vhost_net_cleanup(s->vhost_net); } } --=20 1.8.3.1 From nobody Tue May 14 18:25:52 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 1671449873699518.2290498594298; Mon, 19 Dec 2022 03:37:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7ES7-0002AE-Qn; Mon, 19 Dec 2022 06:37:03 -0500 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 1p7ES5-00028J-E1 for qemu-devel@nongnu.org; Mon, 19 Dec 2022 06:37:01 -0500 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 1p7ES3-00046T-52 for qemu-devel@nongnu.org; Mon, 19 Dec 2022 06:37:01 -0500 Received: from clientip-171.223.98.159 (unknown [172.18.0.188]) by chinatelecom.cn (HERMES) with SMTP id 6E0C3280098; Mon, 19 Dec 2022 19:36:50 +0800 (CST) Received: from ([171.223.98.159]) by app0023 with ESMTP id a516aba8b3384b2d922292000d76d05c for qemu-devel@nongnu.org; Mon, 19 Dec 2022 19:36:52 CST HMM_SOURCE_IP: 172.18.0.188:50724.913608764 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: a516aba8b3384b2d922292000d76d05c X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 171.223.98.159 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: qemu-devel Cc: armbru@redhat.com, dgilbert@redhat.com, eblake@redhat.com, jasowang@redhat.com, lvivier@redhat.com, mst@redhat.com, Liuxiangdong , =?UTF-8?q?Hyman=20Huang=28=E9=BB=84=E5=8B=87=29?= , Guoyi Tu Subject: [PATCH v5 2/3] vhost-user: Refactor the chr_closed_bh Date: Mon, 19 Dec 2022 06:36:41 -0500 Message-Id: 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1671449875991100003 From: Hyman Huang(=E9=BB=84=E5=8B=87) Use vhost_user_save_acked_features to implemente acked features saving. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) Signed-off-by: Guoyi Tu --- net/vhost-user.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/net/vhost-user.c b/net/vhost-user.c index 40a2fe8..4185cfa 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -260,11 +260,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]); } =20 qmp_set_link(name, false, &err); --=20 1.8.3.1 From nobody Tue May 14 18:25:52 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 1671449892099510.9063500071669; Mon, 19 Dec 2022 03:38:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7ESA-0002DI-PG; Mon, 19 Dec 2022 06:37:06 -0500 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 1p7ES5-000297-Sw for qemu-devel@nongnu.org; Mon, 19 Dec 2022 06:37:01 -0500 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 1p7ES3-00046h-53 for qemu-devel@nongnu.org; Mon, 19 Dec 2022 06:37:01 -0500 Received: from clientip-171.223.98.159 (unknown [172.18.0.188]) by chinatelecom.cn (HERMES) with SMTP id 49439280099; Mon, 19 Dec 2022 19:36:52 +0800 (CST) Received: from ([171.223.98.159]) by app0023 with ESMTP id daf4cdbd92474b0bb20da6ddb1908011 for qemu-devel@nongnu.org; Mon, 19 Dec 2022 19:36:54 CST HMM_SOURCE_IP: 172.18.0.188:50724.913608764 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: daf4cdbd92474b0bb20da6ddb1908011 X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 171.223.98.159 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: qemu-devel Cc: armbru@redhat.com, dgilbert@redhat.com, eblake@redhat.com, jasowang@redhat.com, lvivier@redhat.com, mst@redhat.com, Liuxiangdong , =?UTF-8?q?Hyman=20Huang=28=E9=BB=84=E5=8B=87=29?= , Guoyi Tu Subject: [PATCH v5 3/3] vhost-user: Fix the virtio features negotiation flaw Date: Mon, 19 Dec 2022 06:36:42 -0500 Message-Id: <45db7dc203e14676741e05bf4c877a51a3ec2b48.1671449732.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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1671449893907100003 From: Hyman Huang(=E9=BB=84=E5=8B=87) This patch aims to fix unexpected negotiation features for vhost-user netdev interface. When openvswitch reconnect Qemu after an unexpected disconnection and Qemu therefore start the vhost_dev, acked_features field in vhost_dev is initialized with value fetched from acked_features field in NetVhostUserState, which should be up-to-date at that moment but Qemu could not make it actually during the time window of virtio features negotiation. So we save the acked_features right after being configured by guest virtio driver so it can be used to restore acked_features field in vhost_dev correctly. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) Signed-off-by: Guoyi Tu Signed-off-by: Liuxiangdong --- hw/net/vhost_net-stub.c | 5 +++++ hw/net/vhost_net.c | 7 +++++++ hw/net/virtio-net.c | 6 ++++++ include/net/vhost_net.h | 1 + 4 files changed, 19 insertions(+) diff --git a/hw/net/vhost_net-stub.c b/hw/net/vhost_net-stub.c index 89d71cf..199b099 100644 --- a/hw/net/vhost_net-stub.c +++ b/hw/net/vhost_net-stub.c @@ -101,3 +101,8 @@ int vhost_net_set_mtu(struct vhost_net *net, uint16_t m= tu) { return 0; } + +void vhost_net_save_acked_features(NetClientState *nc) +{ + +} diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 30379d2..4c2698d 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -141,6 +141,13 @@ 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=3D NET_CLIENT_DRIVER_VHOST_USER) { + vhost_user_save_acked_features(nc); + } +} + 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 1067e72..5f22865 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -917,6 +917,12 @@ 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..7bdbf48 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -48,4 +48,5 @@ uint64_t vhost_net_get_acked_features(VHostNetState *net); =20 int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu); =20 +void vhost_net_save_acked_features(NetClientState *nc); #endif --=20 1.8.3.1