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 D2DFB45B3B; Mon, 14 Oct 2024 21:32:58 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C16E14065A; Mon, 14 Oct 2024 21:32:58 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 082944064C for ; Mon, 14 Oct 2024 21:32:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728934374; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c8esxmxGMkHynxs23/oMlXAYJKt0DAEpLNO/aPa3Oqg=; b=R4qeCzWyu4rn0ymNjTCrtp9rwaL0IAXvBAIidU+g64yXuO1VxX6fLhNGAix1pdSFGiv3ZF qaX+tI+3aIf+BWMceTuvg4uIM+xKDpXGkirhf0GdPaIxC7b15UBUYTmRc3tWcvlHpLLL00 S88gGVpVo0dsELt/sw2slNcN+rCJh3w= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-284-S0eXxXHHO76oxUGW5sDMQA-1; Mon, 14 Oct 2024 15:32:49 -0400 X-MC-Unique: S0eXxXHHO76oxUGW5sDMQA-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 96EF919560A2; Mon, 14 Oct 2024 19:32:47 +0000 (UTC) Received: from ringo.home (unknown [10.39.208.8]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6FD8B1955F42; Mon, 14 Oct 2024 19:32:44 +0000 (UTC) From: Robin Jarry To: dev@dpdk.org, Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko , Ciara Power , Bruce Richardson , Keith Wiles Cc: stable@dpdk.org Subject: [PATCH dpdk v3 2/2] ethdev: fix potential race in telemetry endpoints Date: Mon, 14 Oct 2024 21:32:37 +0200 Message-ID: <20241014193237.1992382-3-rjarry@redhat.com> In-Reply-To: <20241014193237.1992382-1-rjarry@redhat.com> References: <20241002155709.2522273-1-david.marchand@redhat.com> <20241014193237.1992382-1-rjarry@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 initialized/uninitialised ethdev data. Reuse the ethdev lock that protects port allocation/destruction and the new telemetry callback register api that takes an additional private argument. Pass eth_dev_telemetry_do as the main callback and the actual endpoint callbacks as private argument. Fixes: c190daedb9b1 ("ethdev: add telemetry callbacks") Cc: stable@dpdk.org Signed-off-by: Robin Jarry Acked-by: Bruce Richardson --- lib/ethdev/rte_ethdev_telemetry.c | 66 ++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/lib/ethdev/rte_ethdev_telemetry.c b/lib/ethdev/rte_ethdev_telemetry.c index 6b873e7abe68..7599fa2852b6 100644 --- a/lib/ethdev/rte_ethdev_telemetry.c +++ b/lib/ethdev/rte_ethdev_telemetry.c @@ -1395,45 +1395,73 @@ eth_dev_handle_port_tm_node_caps(const char *cmd __rte_unused, return ret; } +static int eth_dev_telemetry_do(const char *cmd, const char *params, + void *arg, struct rte_tel_data *d) +{ + int ret; + telemetry_cb fn = arg; + rte_spinlock_lock(rte_mcfg_ethdev_get_lock()); + ret = fn(cmd, params, d); + rte_spinlock_unlock(rte_mcfg_ethdev_get_lock()); + return ret; +} + RTE_INIT(ethdev_init_telemetry) { - rte_telemetry_register_cmd("/ethdev/list", eth_dev_handle_port_list, + rte_telemetry_register_cmd_arg("/ethdev/list", + eth_dev_telemetry_do, 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, + rte_telemetry_register_cmd_arg("/ethdev/stats", + eth_dev_telemetry_do, 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, + rte_telemetry_register_cmd_arg("/ethdev/xstats", + eth_dev_telemetry_do, 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)"); #ifndef RTE_EXEC_ENV_WINDOWS - rte_telemetry_register_cmd("/ethdev/dump_priv", eth_dev_handle_port_dump_priv, + rte_telemetry_register_cmd_arg("/ethdev/dump_priv", + eth_dev_telemetry_do, eth_dev_handle_port_dump_priv, "Returns dump private information for a port. Parameters: int port_id"); #endif - rte_telemetry_register_cmd("/ethdev/link_status", - eth_dev_handle_port_link_status, + rte_telemetry_register_cmd_arg("/ethdev/link_status", + eth_dev_telemetry_do, 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, + rte_telemetry_register_cmd_arg("/ethdev/info", + eth_dev_telemetry_do, 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, + rte_telemetry_register_cmd_arg("/ethdev/module_eeprom", + eth_dev_telemetry_do, 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, + rte_telemetry_register_cmd_arg("/ethdev/macs", + eth_dev_telemetry_do, 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, + rte_telemetry_register_cmd_arg("/ethdev/flow_ctrl", + eth_dev_telemetry_do, 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, + rte_telemetry_register_cmd_arg("/ethdev/rx_queue", + eth_dev_telemetry_do, 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, + rte_telemetry_register_cmd_arg("/ethdev/tx_queue", + eth_dev_telemetry_do, 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, + rte_telemetry_register_cmd_arg("/ethdev/dcb", + eth_dev_telemetry_do, 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, + rte_telemetry_register_cmd_arg("/ethdev/rss_info", + eth_dev_telemetry_do, 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, + rte_telemetry_register_cmd_arg("/ethdev/fec", + eth_dev_telemetry_do, 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, + rte_telemetry_register_cmd_arg("/ethdev/vlan", + eth_dev_telemetry_do, 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, + rte_telemetry_register_cmd_arg("/ethdev/tm_capability", + eth_dev_telemetry_do, 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, + rte_telemetry_register_cmd_arg("/ethdev/tm_level_capability", + eth_dev_telemetry_do, 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, + rte_telemetry_register_cmd_arg("/ethdev/tm_node_capability", + eth_dev_telemetry_do, 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)"); } -- 2.46.2