From nobody Sun Feb 8 14:59:33 2026 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+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 1667233256014827.3016313098743; Mon, 31 Oct 2022 09:20:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opXVf-0006dB-LI; Mon, 31 Oct 2022 12:19:35 -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 1opXVZ-0006XA-23 for qemu-devel@nongnu.org; Mon, 31 Oct 2022 12:19:33 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.223] helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opXVR-0001MH-NF for qemu-devel@nongnu.org; Mon, 31 Oct 2022 12:19:24 -0400 Received: from clientip-182.138.180.88 (unknown [172.18.0.218]) by chinatelecom.cn (HERMES) with SMTP id 680422800C5; Tue, 1 Nov 2022 00:19:13 +0800 (CST) Received: from ([182.138.180.88]) by app0025 with ESMTP id 7f8eb476621d449fb18ac80b3619253f for qemu-devel@nongnu.org; Tue, 01 Nov 2022 00:19:15 CST HMM_SOURCE_IP: 172.18.0.218:50162.1127588867 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: 7f8eb476621d449fb18ac80b3619253f X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 182.138.180.88 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: qemu-devel Cc: "Michael S . Tsirkin" , Jason Wang , Eric Blake , Markus Armbruster , "Dr. David Alan Gilbert" , Thomas Huth , Laurent Vivier , Paolo Bonzini , Stefano Garzarella , Raphael Norwitz , =?UTF-8?q?Hyman=20Huang=28=E9=BB=84=E5=8B=87=29?= Subject: [PATCH RFC 1/4] net: Introduce qmp cmd "query-netdev" Date: Tue, 1 Nov 2022 00:18:59 +0800 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=42.123.76.223; 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+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1667233257128100006 From: Hyman Huang(=E9=BB=84=E5=8B=87) For netdev device that can offload virtio-net dataplane to slave, such as vhost-net, vhost-user and vhost-vdpa, exporting it's capability information and acked features would be more friendly for developers. These infomation can be analyzed and compare to slave capability provided by, eg dpdk or other slaves directly, helping to draw conclusions about if vm network interface works normally, if it vm can be migrated to another feature-compatible destination or whatever else. For developers who devote to offload virtio-net dataplane to DPU and make efforts to migrate vm lively from software-based source host to DPU-offload destination host smoothly, virtio-net feature compatibility is an serious issue, exporting the key capability and acked_features of netdev could also help to debug greatly. So we export out the key capabilities of netdev, which may affect the final negotiated virtio-net features, meanwhile, backed-up acked_features also exported, which is used to initialize or restore features negotiated between qemu and vhost slave when starting vhost_dev device. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) --- net/net.c | 44 +++++++++++++++++++++++++++++++++++++++ qapi/net.json | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 110 insertions(+) diff --git a/net/net.c b/net/net.c index 2db160e..5d11674 100644 --- a/net/net.c +++ b/net/net.c @@ -53,6 +53,7 @@ #include "sysemu/runstate.h" #include "net/colo-compare.h" #include "net/filter.h" +#include "net/vhost-user.h" #include "qapi/string-output-visitor.h" =20 /* Net bridge is currently not supported for W32. */ @@ -1224,6 +1225,49 @@ void qmp_netdev_del(const char *id, Error **errp) } } =20 +static NetDevInfo *query_netdev(NetClientState *nc) +{ + NetDevInfo *info =3D NULL; + + if (!nc || !nc->is_netdev) { + return NULL; + } + + info =3D g_malloc0(sizeof(*info)); + info->name =3D g_strdup(nc->name); + info->type =3D nc->info->type; + info->ufo =3D nc->info->has_ufo; + info->vnet_hdr =3D nc->info->has_vnet_hdr; + info->vnet_hdr_len =3D nc->info->has_vnet_hdr_len; + + if (nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_USER) { + info->has_acked_features =3D true; + info->acked_features =3D vhost_user_get_acked_features(nc); + } + + return info; +} + +NetDevInfoList *qmp_query_netdev(Error **errp) +{ + NetClientState *nc; + NetDevInfo *info =3D NULL; + NetDevInfoList *head =3D NULL, **tail =3D &head; + + QTAILQ_FOREACH(nc, &net_clients, next) { + if (nc->info->type =3D=3D NET_CLIENT_DRIVER_NIC) { + continue; + } + + info =3D query_netdev(nc); + if (info) { + QAPI_LIST_APPEND(tail, info); + } + } + + return head; +} + static void netfilter_print_info(Monitor *mon, NetFilterState *nf) { char *str; diff --git a/qapi/net.json b/qapi/net.json index dd088c0..76a6513 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -631,6 +631,72 @@ 'if': 'CONFIG_VMNET' } } } =20 ## +# @NetDevInfo: +# +# NetDev information. This structure describes a NetDev information, incl= uding +# capabilities and negotiated features. +# +# @name: The NetDev name. +# +# @type: Type of NetDev. +# +# @ufo: True if NetDev has ufo capability. +# +# @vnet-hdr: True if NetDev has vnet_hdr. +# +# @vnet-hdr-len: True if given length can be assigned to NetDev. +# +# @acked-features: Negotiated features with vhost slave device if device s= upport +# dataplane offload. +# +# Since: 7.1 +## +{'struct': 'NetDevInfo', + 'data': { + 'name': 'str', + 'type': 'NetClientDriver', + 'ufo':'bool', + 'vnet-hdr':'bool', + 'vnet-hdr-len':'bool', + '*acked-features': 'uint64' } } + +## +# @query-netdev: +# +# Get a list of NetDevInfo for all virtual netdev peer devices. +# +# Returns: a list of @NetDevInfo describing each virtual netdev peer devic= e. +# +# Since: 7.1 +# +# Example: +# +# -> { "execute": "query-netdev" } +# <- { +# "return":[ +# { +# "name":"hostnet0", +# "type":"vhost-user", +# "ufo":true, +# "vnet-hdr":true, +# "vnet-hdr-len":true, +# "acked-features":"5111807907", +# }, +# { +# "name":"hostnet1", +# "type":"vhost-user", +# "ufo":true, +# "vnet-hdr":true, +# "vnet-hdr-len":true, +# "acked-features":"5111807907", +# } +# ] +# } +# +## +{ 'command': 'query-netdev', 'returns': ['NetDevInfo'] } + +## # @RxState: # # Packets receiving state --=20 1.8.3.1 From nobody Sun Feb 8 14:59:33 2026 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+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 1667233235859772.1666675614425; Mon, 31 Oct 2022 09:20:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opXVe-0006cX-Pc; Mon, 31 Oct 2022 12:19:34 -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 1opXVU-0006Wj-Rb for qemu-devel@nongnu.org; Mon, 31 Oct 2022 12:19:24 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.223] helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opXVR-0001MK-R7 for qemu-devel@nongnu.org; Mon, 31 Oct 2022 12:19:24 -0400 Received: from clientip-182.138.180.88 (unknown [172.18.0.218]) by chinatelecom.cn (HERMES) with SMTP id 91AA32800E6; Tue, 1 Nov 2022 00:19:15 +0800 (CST) Received: from ([182.138.180.88]) by app0025 with ESMTP id c6c5b9944a28487683bb9b918a3c5b07 for qemu-devel@nongnu.org; Tue, 01 Nov 2022 00:19:17 CST HMM_SOURCE_IP: 172.18.0.218:50162.1127588867 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: c6c5b9944a28487683bb9b918a3c5b07 X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 182.138.180.88 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: qemu-devel Cc: "Michael S . Tsirkin" , Jason Wang , Eric Blake , Markus Armbruster , "Dr. David Alan Gilbert" , Thomas Huth , Laurent Vivier , Paolo Bonzini , Stefano Garzarella , Raphael Norwitz , =?UTF-8?q?Hyman=20Huang=28=E9=BB=84=E5=8B=87=29?= Subject: [PATCH RFC 2/4] hmp: Add "info netdev" cmd Date: Tue, 1 Nov 2022 00:19:00 +0800 Message-Id: <4e96b2beac69aa865777eb95330b9852a36353c7.1667232396.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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=42.123.76.223; 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+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1667233237743100003 From: Hyman Huang(=E9=BB=84=E5=8B=87) Introduce "info netdev" command so developers can play with it easier. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) --- hmp-commands-info.hx | 14 ++++++++++++++ include/monitor/hmp.h | 1 + net/net.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index 754b1e8..217843c 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -880,6 +880,20 @@ SRST Display the vcpu dirty page limit information. ERST =20 + { + .name =3D "netdev", + .args_type =3D "", + .params =3D "", + .help =3D "show information about netdev, guest acked featur= es are " + "also printed if supporting virtio-net dataplane off= loading", + .cmd =3D hmp_info_netdev, + }, + +SRST + ``info netdev`` + Display information about netdev. +ERST + #if defined(TARGET_I386) { .name =3D "sgx", diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index a9cf064..0bd496a 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -142,5 +142,6 @@ void hmp_info_vcpu_dirty_limit(Monitor *mon, const QDic= t *qdict); void hmp_human_readable_text_helper(Monitor *mon, HumanReadableText *(*qmp_handler)(Erro= r **)); void hmp_info_stats(Monitor *mon, const QDict *qdict); +void hmp_info_netdev(Monitor *mon, const QDict *qdict); =20 #endif diff --git a/net/net.c b/net/net.c index 5d11674..c27ebfa 100644 --- a/net/net.c +++ b/net/net.c @@ -55,6 +55,7 @@ #include "net/filter.h" #include "net/vhost-user.h" #include "qapi/string-output-visitor.h" +#include "monitor/hmp.h" =20 /* Net bridge is currently not supported for W32. */ #if !defined(_WIN32) @@ -1268,6 +1269,36 @@ NetDevInfoList *qmp_query_netdev(Error **errp) return head; } =20 +void hmp_info_netdev(Monitor *mon, const QDict *qdict) +{ + NetDevInfoList *info, *head, *info_list =3D NULL; + Error *err =3D NULL; + + info_list =3D qmp_query_netdev(&err); + if (err) { + hmp_handle_error(mon, err); + return; + } + + head =3D info_list; + for (info =3D head; info !=3D NULL; info =3D info->next) { + monitor_printf(mon, "%s: %s device, " + "ufo %s, vnet-hdr %s, vnet-hdr-len %s", + info->value->name, + NetClientDriver_str(info->value->type), + info->value->ufo ? "supported" : "unsupported", + info->value->vnet_hdr ? "supported" : "unsupported", + info->value->vnet_hdr_len ? "supported" : "unsupported"); + if (info->value->has_acked_features) { + monitor_printf(mon, ", acked-features 0x%" PRIx64, + info->value->acked_features); + } + monitor_printf(mon, "\n"); + } + + g_free(info_list); +} + static void netfilter_print_info(Monitor *mon, NetFilterState *nf) { char *str; --=20 1.8.3.1 From nobody Sun Feb 8 14:59:33 2026 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+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 1667233256773368.09878642673345; Mon, 31 Oct 2022 09:20:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opXVe-0006Wz-8p; Mon, 31 Oct 2022 12:19:34 -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 1opXVT-0006Vs-OX for qemu-devel@nongnu.org; Mon, 31 Oct 2022 12:19:23 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.223] helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opXVR-0001Me-NT for qemu-devel@nongnu.org; Mon, 31 Oct 2022 12:19:23 -0400 Received: from clientip-182.138.180.88 (unknown [172.18.0.218]) by chinatelecom.cn (HERMES) with SMTP id BF3CC2800E7; Tue, 1 Nov 2022 00:19:17 +0800 (CST) Received: from ([182.138.180.88]) by app0025 with ESMTP id 28fbe3e7e8e0489e838bb85805d792cc for qemu-devel@nongnu.org; Tue, 01 Nov 2022 00:19:19 CST HMM_SOURCE_IP: 172.18.0.218:50162.1127588867 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: 28fbe3e7e8e0489e838bb85805d792cc X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 182.138.180.88 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: qemu-devel Cc: "Michael S . Tsirkin" , Jason Wang , Eric Blake , Markus Armbruster , "Dr. David Alan Gilbert" , Thomas Huth , Laurent Vivier , Paolo Bonzini , Stefano Garzarella , Raphael Norwitz , =?UTF-8?q?Hyman=20Huang=28=E9=BB=84=E5=8B=87=29?= Subject: [PATCH RFC 3/4] hmp: Add netdev information into output of hmp cmd "info network" Date: Tue, 1 Nov 2022 00:19:01 +0800 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=42.123.76.223; 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+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1667233257122100004 From: Hyman Huang(=E9=BB=84=E5=8B=87) Add netdev information into output of hmp command hmp_info_network so developers can analyze interface capability more easily. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) --- net/net.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/net/net.c b/net/net.c index c27ebfa..9325628 100644 --- a/net/net.c +++ b/net/net.c @@ -1330,6 +1330,21 @@ void print_net_client(Monitor *mon, NetClientState *= nc) nc->queue_index, NetClientDriver_str(nc->info->type), nc->info_str); + if (nc->info->type !=3D NET_CLIENT_DRIVER_NIC) { + NetDevInfo *info =3D query_netdev(nc); + if (info) { + monitor_printf(mon, "netdev info: ufo=3D%s, vnet-hdr=3D%s, " + "vnet-hdr-len=3D%s", info->ufo ? "on" : "off", + info->vnet_hdr ? "on" : "off", + info->vnet_hdr_len ? "on" : "off"); + if (info->has_acked_features) { + monitor_printf(mon, ", acked-features=3D0x%" PRIx64, + info->acked_features); + } + monitor_printf(mon, "\n"); + g_free(info); + } + } if (!QTAILQ_EMPTY(&nc->filters)) { monitor_printf(mon, "filters:\n"); } --=20 1.8.3.1 From nobody Sun Feb 8 14:59:33 2026 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+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 166723323522967.58312374247146; Mon, 31 Oct 2022 09:20:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opXVg-0006dI-Lv; Mon, 31 Oct 2022 12:19: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 1opXVZ-0006X9-29 for qemu-devel@nongnu.org; Mon, 31 Oct 2022 12:19:33 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.223] helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opXVT-0001Mt-IK for qemu-devel@nongnu.org; Mon, 31 Oct 2022 12:19:25 -0400 Received: from clientip-182.138.180.88 (unknown [172.18.0.218]) by chinatelecom.cn (HERMES) with SMTP id F1C012800EB; Tue, 1 Nov 2022 00:19:19 +0800 (CST) Received: from ([182.138.180.88]) by app0025 with ESMTP id 12140b2b8d884782bed90ebce6c67986 for qemu-devel@nongnu.org; Tue, 01 Nov 2022 00:19:21 CST HMM_SOURCE_IP: 172.18.0.218:50162.1127588867 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: 12140b2b8d884782bed90ebce6c67986 X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 182.138.180.88 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: qemu-devel Cc: "Michael S . Tsirkin" , Jason Wang , Eric Blake , Markus Armbruster , "Dr. David Alan Gilbert" , Thomas Huth , Laurent Vivier , Paolo Bonzini , Stefano Garzarella , Raphael Norwitz , =?UTF-8?q?Hyman=20Huang=28=E9=BB=84=E5=8B=87=29?= Subject: [PATCH RFC 4/4] vhost-user-test: Add negotiated features check Date: Tue, 1 Nov 2022 00:19:02 +0800 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=42.123.76.223; 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+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1667233238039100010 From: Hyman Huang(=E9=BB=84=E5=8B=87) For vhost-user network device, Qemu backup the final features as acked_features internally after guest acknowledging features during virtio-net driver initialization, so the acked_features could be used as input of VHOST_USER_SET_FEATURES command when slave device restore from an unexpected failure. Negotiated features check just assert if the acked_features in Qemu is exactly the same as features in vhost slave device, which checks if features are negotiated correctly via vhost user protocol. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) --- tests/qtest/vhost-user-test.c | 67 +++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 67 insertions(+) diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c index bf9f7c4..f8bf2fa 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -29,6 +29,9 @@ #include "libqos/qgraph_internal.h" #include "hw/virtio/virtio-net.h" =20 +#include "migration-helpers.h" +#include "qapi/qmp/qlist.h" + #include "standard-headers/linux/vhost_types.h" #include "standard-headers/linux/virtio_ids.h" #include "standard-headers/linux/virtio_net.h" @@ -167,6 +170,7 @@ typedef struct TestServer { int test_flags; int queues; struct vhost_user_ops *vu_ops; + uint64_t features; } TestServer; =20 struct vhost_user_ops { @@ -796,6 +800,64 @@ static void test_read_guest_mem(void *obj, void *arg, = QGuestAllocator *alloc) read_guest_mem_server(global_qtest, server); } =20 +static QDict *query_netdev(QTestState *who) +{ + QDict *rsp; + + rsp =3D qtest_qmp(who, "{ 'execute': 'query-netdev' }"); + g_assert(!qdict_haskey(rsp, "error")); + g_assert(qdict_haskey(rsp, "return")); + + return rsp; +} + +static uint64_t get_acked_features(QTestState *who) +{ + QDict *rsp_return; + QList *info_list; + const QListEntry *entry; + QDict *info; + uint64_t acked_features; + + rsp_return =3D query_netdev(who); + g_assert(rsp_return); + + info_list =3D qdict_get_qlist(rsp_return, "return"); + g_assert(info_list && !qlist_empty(info_list)); + + entry =3D qlist_first(info_list); + g_assert(entry); + + info =3D qobject_to(QDict, qlist_entry_obj(entry)); + g_assert(info); + + acked_features =3D qdict_get_try_int(info, "acked-features", 0); + + qobject_unref(rsp_return); + return acked_features; +} + +static void read_acked_features(QTestState *qts, TestServer *s) +{ + uint64_t acked_features; + + acked_features =3D get_acked_features(qts); + g_assert_cmpint(acked_features, =3D=3D, s->features); +} + +static void test_read_acked_features(void *obj, + void *arg, + QGuestAllocator *alloc) +{ + TestServer *server =3D arg; + + if (!wait_for_fds(server)) { + return; + } + + read_acked_features(global_qtest, server); +} + static void test_migrate(void *obj, void *arg, QGuestAllocator *alloc) { TestServer *s =3D arg; @@ -1037,6 +1099,7 @@ static void vu_net_set_features(TestServer *s, CharBa= ckend *chr, qemu_chr_fe_disconnect(chr); s->test_flags =3D TEST_FLAGS_BAD; } + s->features =3D msg->payload.u64; } =20 static void vu_net_get_protocol_features(TestServer *s, CharBackend *chr, @@ -1078,6 +1141,10 @@ static void register_vhost_user_test(void) "virtio-net", test_read_guest_mem, &opts); =20 + qos_add_test("vhost-user/read_acked_features", + "virtio-net", + test_read_acked_features, &opts); + if (qemu_memfd_check(MFD_ALLOW_SEALING)) { opts.before =3D vhost_user_test_setup_memfd; qos_add_test("vhost-user/read-guest-mem/memfd", --=20 1.8.3.1