Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 719F5C433FE for ; Wed, 2 Nov 2022 15:37:05 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oqFn3-0005TS-VL; Wed, 02 Nov 2022 11:36:29 -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 1oqFmz-0005SR-J7 for qemu-devel@nongnu.org; Wed, 02 Nov 2022 11:36:28 -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 1oqFmw-0004Jz-Us for qemu-devel@nongnu.org; Wed, 02 Nov 2022 11:36:25 -0400 HMM_SOURCE_IP: 172.18.0.218:60610.1489583080 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-182.138.180.88 (unknown [172.18.0.218]) by chinatelecom.cn (HERMES) with SMTP id B1B412800C6; Wed, 2 Nov 2022 23:36:13 +0800 (CST) X-189-SAVE-TO-SEND: huangy81@chinatelecom.cn Received: from ([182.138.180.88]) by app0025 with ESMTP id 8f4595658cd24a68bd300ec0ba4ebea0 for mst@redhat.com; Wed, 02 Nov 2022 23:36:17 CST X-Transaction-ID: 8f4595658cd24a68bd300ec0ba4ebea0 X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 182.138.180.88 X-MEDUSA-Status: 0 Message-ID: Date: Wed, 2 Nov 2022 23:36:19 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.13.1 Subject: Re: [PATCH RFC 1/4] net: Introduce qmp cmd "query-netdev" To: "Michael S. Tsirkin" , Jason Wang Cc: qemu-devel , Eric Blake , Markus Armbruster , "Dr. David Alan Gilbert" , Thomas Huth , Laurent Vivier , Paolo Bonzini , Stefano Garzarella , Raphael Norwitz References: <20221102024054-mutt-send-email-mst@kernel.org> From: Hyman In-Reply-To: <20221102024054-mutt-send-email-mst@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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, NICE_REPLY_A=-0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org 在 2022/11/2 14:41, Michael S. Tsirkin 写道: > On Wed, Nov 02, 2022 at 01:42:39PM +0800, Jason Wang wrote: >> On Tue, Nov 1, 2022 at 12:19 AM wrote: >>> >>> From: Hyman Huang(黄勇) >>> >>> 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(黄勇) >>> --- >>> 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" >>> >>> /* Net bridge is currently not supported for W32. */ >>> @@ -1224,6 +1225,49 @@ void qmp_netdev_del(const char *id, Error **errp) >>> } >>> } >>> >>> +static NetDevInfo *query_netdev(NetClientState *nc) >>> +{ >>> + NetDevInfo *info = NULL; >>> + >>> + if (!nc || !nc->is_netdev) { >>> + return NULL; >>> + } >>> + >>> + info = g_malloc0(sizeof(*info)); >>> + info->name = g_strdup(nc->name); >>> + info->type = nc->info->type; >>> + info->ufo = nc->info->has_ufo; >>> + info->vnet_hdr = nc->info->has_vnet_hdr; >>> + info->vnet_hdr_len = nc->info->has_vnet_hdr_len; >> >> So all the fields are virtio specific, I wonder if it's better to >> rename the command as query-vhost or query-virtio? >> >> Thanks > > We have info virtio already. Seems to fit there logically. Ok, it seems that 'x-query-virtio-netdev' is a good option. > > >>> + >>> + if (nc->info->type == NET_CLIENT_DRIVER_VHOST_USER) { >>> + info->has_acked_features = true; >>> + info->acked_features = vhost_user_get_acked_features(nc); >>> + } >>> + >>> + return info; >>> +} >>> + >>> +NetDevInfoList *qmp_query_netdev(Error **errp) >>> +{ >>> + NetClientState *nc; >>> + NetDevInfo *info = NULL; >>> + NetDevInfoList *head = NULL, **tail = &head; >>> + >>> + QTAILQ_FOREACH(nc, &net_clients, next) { >>> + if (nc->info->type == NET_CLIENT_DRIVER_NIC) { >>> + continue; >>> + } >>> + >>> + info = 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' } } } >>> >>> ## >>> +# @NetDevInfo: >>> +# >>> +# NetDev information. This structure describes a NetDev information, including >>> +# 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 support >>> +# 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 device. >>> +# >>> +# 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 >>> -- >>> 1.8.3.1 >>> >