From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E1FCE45ADC for ; Tue, 8 Oct 2024 04:07:56 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DBD12402E8; Tue, 8 Oct 2024 04:07:56 +0200 (CEST) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by mails.dpdk.org (Postfix) with ESMTP id 7055A402E8; Tue, 8 Oct 2024 04:07:55 +0200 (CEST) Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4XMzsk14Yyz1j9VZ; Tue, 8 Oct 2024 10:06:50 +0800 (CST) Received: from kwepemm600004.china.huawei.com (unknown [7.193.23.242]) by mail.maildlp.com (Postfix) with ESMTPS id 776F11A016C; Tue, 8 Oct 2024 10:07:53 +0800 (CST) Received: from [10.67.121.59] (10.67.121.59) by kwepemm600004.china.huawei.com (7.193.23.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 8 Oct 2024 10:07:52 +0800 Message-ID: <1f0865f8-a76a-caf1-2ec0-9a3d86525d9e@huawei.com> Date: Tue, 8 Oct 2024 10:07:47 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [PATCH 2/2] ethdev: fix race on ports for telemetry commands To: David Marchand , CC: , , , , Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko , Keith Wiles , Ciara Power References: <20241002155709.2522273-1-david.marchand@redhat.com> <20241002155709.2522273-3-david.marchand@redhat.com> From: "lihuisong (C)" In-Reply-To: <20241002155709.2522273-3-david.marchand@redhat.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.121.59] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600004.china.huawei.com (7.193.23.242) X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org 在 2024/10/2 23:57, David Marchand 写道: > While invoking telemetry commands (which may happen at any time, > out of control of the application), an application thread may > concurrently add/remove ports. > The telemetry callbacks may then access partially > initialised/uninitialised ethdev data. > > Reuse the ethdev lock that protects port allocation/destruction. Agree to lock for telemetry. > > Fixes: c190daedb9b1 ("ethdev: add telemetry callbacks") > Cc: stable@dpdk.org > > Signed-off-by: David Marchand > --- > lib/ethdev/rte_ethdev_telemetry.c | 93 +++++++++++++++++++------------ > 1 file changed, 56 insertions(+), 37 deletions(-) > > diff --git a/lib/ethdev/rte_ethdev_telemetry.c b/lib/ethdev/rte_ethdev_telemetry.c > index 8031a58595..7f9c924209 100644 > --- a/lib/ethdev/rte_ethdev_telemetry.c > +++ b/lib/ethdev/rte_ethdev_telemetry.c > @@ -6,6 +6,7 @@ > #include > > #include > +#include > #include > > #include "rte_ethdev.h" > @@ -1403,43 +1404,61 @@ eth_dev_handle_port_tm_node_caps(const char *cmd __rte_unused, > return ret; > } > > +#define ETHDEV_TELEMETRY_HANDLERS \ > + ETHDEV_TELEMETRY_HANDLER("/ethdev/list", eth_dev_handle_port_list, \ > + "Returns list of available ethdev ports. Takes no parameters") \ > + ETHDEV_TELEMETRY_HANDLER("/ethdev/stats", eth_dev_handle_port_stats, \ > + "Returns the common stats for a port. Parameters: int port_id") \ > + ETHDEV_TELEMETRY_HANDLER("/ethdev/xstats", eth_dev_handle_port_xstats, \ > + "Returns the extended stats for a port. Parameters: int port_id,hide_zero=true|false(Optional for indicates hide zero xstats)") \ > + ETHDEV_TELEMETRY_HANDLER("/ethdev/dump_priv", eth_dev_handle_port_dump_priv, \ > + "Returns dump private information for a port. Parameters: int port_id") \ > + ETHDEV_TELEMETRY_HANDLER("/ethdev/link_status", eth_dev_handle_port_link_status, \ > + "Returns the link status for a port. Parameters: int port_id") \ > + ETHDEV_TELEMETRY_HANDLER("/ethdev/info", eth_dev_handle_port_info, \ > + "Returns the device info for a port. Parameters: int port_id") \ > + ETHDEV_TELEMETRY_HANDLER("/ethdev/module_eeprom", eth_dev_handle_port_module_eeprom, \ > + "Returns module EEPROM info with SFF specs. Parameters: int port_id") \ > + ETHDEV_TELEMETRY_HANDLER("/ethdev/macs", eth_dev_handle_port_macs, \ > + "Returns the MAC addresses for a port. Parameters: int port_id") \ > + ETHDEV_TELEMETRY_HANDLER("/ethdev/flow_ctrl", eth_dev_handle_port_flow_ctrl, \ > + "Returns flow ctrl info for a port. Parameters: int port_id") \ > + ETHDEV_TELEMETRY_HANDLER("/ethdev/rx_queue", eth_dev_handle_port_rxq, \ > + "Returns Rx queue info for a port. Parameters: int port_id, int queue_id (Optional if only one queue)") \ > + ETHDEV_TELEMETRY_HANDLER("/ethdev/tx_queue", eth_dev_handle_port_txq, \ > + "Returns Tx queue info for a port. Parameters: int port_id, int queue_id (Optional if only one queue)") \ > + ETHDEV_TELEMETRY_HANDLER("/ethdev/dcb", eth_dev_handle_port_dcb, \ > + "Returns DCB info for a port. Parameters: int port_id") \ > + ETHDEV_TELEMETRY_HANDLER("/ethdev/rss_info", eth_dev_handle_port_rss_info, \ > + "Returns RSS info for a port. Parameters: int port_id") \ > + ETHDEV_TELEMETRY_HANDLER("/ethdev/fec", eth_dev_handle_port_fec, \ > + "Returns FEC info for a port. Parameters: int port_id") \ > + ETHDEV_TELEMETRY_HANDLER("/ethdev/vlan", eth_dev_handle_port_vlan, \ > + "Returns VLAN info for a port. Parameters: int port_id") \ > + ETHDEV_TELEMETRY_HANDLER("/ethdev/tm_capability", eth_dev_handle_port_tm_caps, \ > + "Returns TM Capabilities info for a port. Parameters: int port_id") \ > + ETHDEV_TELEMETRY_HANDLER("/ethdev/tm_level_capability", eth_dev_handle_port_tm_level_caps, \ > + "Returns TM Level Capabilities info for a port. Parameters: int port_id, int level_id (see tm_capability for the max)") \ > + ETHDEV_TELEMETRY_HANDLER("/ethdev/tm_node_capability", eth_dev_handle_port_tm_node_caps, \ > + "Returns TM Node Capabilities info for a port. Parameters: int port_id, int node_id (see tm_capability for the max)") > + > +#define ETHDEV_TELEMETRY_HANDLER(command, func, usage) \ In addition, the "command" and "usage" are unuseful in this definition. This is confused to me. Can the first macro definition just use 'func' as input parameter? The name of this macro define is the same as the below one. I prefer to use two different macros to do this. > +static int func ## _locked(const char *cmd __rte_unused, const char *params, \ > + struct rte_tel_data *d) \ > +{ \ > + int ret; \ > + rte_spinlock_lock(rte_mcfg_ethdev_get_lock()); \ > + ret = func(cmd, params, d); \ > + rte_spinlock_unlock(rte_mcfg_ethdev_get_lock()); \ > + return ret; \ > +} > +ETHDEV_TELEMETRY_HANDLERS > +#undef ETHDEV_TELEMETRY_HANDLER > + > RTE_INIT(ethdev_init_telemetry) > { > - rte_telemetry_register_cmd("/ethdev/list", eth_dev_handle_port_list, > - "Returns list of available ethdev ports. Takes no parameters"); > - rte_telemetry_register_cmd("/ethdev/stats", eth_dev_handle_port_stats, > - "Returns the common stats for a port. Parameters: int port_id"); > - rte_telemetry_register_cmd("/ethdev/xstats", eth_dev_handle_port_xstats, > - "Returns the extended stats for a port. Parameters: int port_id,hide_zero=true|false(Optional for indicates hide zero xstats)"); > - rte_telemetry_register_cmd("/ethdev/dump_priv", eth_dev_handle_port_dump_priv, > - "Returns dump private information for a port. Parameters: int port_id"); > - rte_telemetry_register_cmd("/ethdev/link_status", > - eth_dev_handle_port_link_status, > - "Returns the link status for a port. Parameters: int port_id"); > - rte_telemetry_register_cmd("/ethdev/info", eth_dev_handle_port_info, > - "Returns the device info for a port. Parameters: int port_id"); > - rte_telemetry_register_cmd("/ethdev/module_eeprom", eth_dev_handle_port_module_eeprom, > - "Returns module EEPROM info with SFF specs. Parameters: int port_id"); > - rte_telemetry_register_cmd("/ethdev/macs", eth_dev_handle_port_macs, > - "Returns the MAC addresses for a port. Parameters: int port_id"); > - rte_telemetry_register_cmd("/ethdev/flow_ctrl", eth_dev_handle_port_flow_ctrl, > - "Returns flow ctrl info for a port. Parameters: int port_id"); > - rte_telemetry_register_cmd("/ethdev/rx_queue", eth_dev_handle_port_rxq, > - "Returns Rx queue info for a port. Parameters: int port_id, int queue_id (Optional if only one queue)"); > - rte_telemetry_register_cmd("/ethdev/tx_queue", eth_dev_handle_port_txq, > - "Returns Tx queue info for a port. Parameters: int port_id, int queue_id (Optional if only one queue)"); > - rte_telemetry_register_cmd("/ethdev/dcb", eth_dev_handle_port_dcb, > - "Returns DCB info for a port. Parameters: int port_id"); > - rte_telemetry_register_cmd("/ethdev/rss_info", eth_dev_handle_port_rss_info, > - "Returns RSS info for a port. Parameters: int port_id"); > - rte_telemetry_register_cmd("/ethdev/fec", eth_dev_handle_port_fec, > - "Returns FEC info for a port. Parameters: int port_id"); > - rte_telemetry_register_cmd("/ethdev/vlan", eth_dev_handle_port_vlan, > - "Returns VLAN info for a port. Parameters: int port_id"); > - rte_telemetry_register_cmd("/ethdev/tm_capability", eth_dev_handle_port_tm_caps, > - "Returns TM Capabilities info for a port. Parameters: int port_id"); > - rte_telemetry_register_cmd("/ethdev/tm_level_capability", eth_dev_handle_port_tm_level_caps, > - "Returns TM Level Capabilities info for a port. Parameters: int port_id, int level_id (see tm_capability for the max)"); > - rte_telemetry_register_cmd("/ethdev/tm_node_capability", eth_dev_handle_port_tm_node_caps, > - "Returns TM Node Capabilities info for a port. Parameters: int port_id, int node_id (see tm_capability for the max)"); > +#define ETHDEV_TELEMETRY_HANDLER(command, func, usage) \ > + rte_telemetry_register_cmd(command, func ## _locked, usage); > + ETHDEV_TELEMETRY_HANDLERS > +#undef ETHDEV_TELEMETRY_HANDLER > }