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 0484645E87; Thu, 12 Dec 2024 17:19:33 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B30A34060B; Thu, 12 Dec 2024 17:19:23 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) by mails.dpdk.org (Postfix) with ESMTP id 865234027D for ; Thu, 12 Dec 2024 17:19:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1734020361; x=1765556361; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=3Olq8Da3uPBPXouhPGT36P+bjjlgOzNHpbokhTDVXh8=; b=UMJdsJqF+eroldg9o1rrKu7ZUIab0EcmURXMDEuM2Wf7rJ5hhQ2w6JVh AS867m812Q8KmuvuEsZuzAmaqCPwMo+Jb1ecayKz0w/zcRoQnvEZvL0o8 99XPZFl2Puuc3Hkz1Yww7NaI1uSmgohxD3yVF1PGP9S+dvQAtsysjmi1j DLZObcfqm6wVd645XAiZjWfyZQPEYMRQWChhwgWrrG/dSRoZbyTtV7T6s mAh1pE3R4sBu9saZsRFcJndpfih7qbws9Mdkz1Xr5OpzyurcGWEoMouFL DFjmdWO+a0VIV9Zuf8twKAYvh33fF7Cnoncqk2uzA70QV20JGR0ZsKAGu Q==; X-CSE-ConnectionGUID: uEnNa00/Sy2lbaltlK1g3g== X-CSE-MsgGUID: P0l55BEiTVejyT6C1n2otA== X-IronPort-AV: E=McAfee;i="6700,10204,11284"; a="45135275" X-IronPort-AV: E=Sophos;i="6.12,229,1728975600"; d="scan'208";a="45135275" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Dec 2024 08:19:12 -0800 X-CSE-ConnectionGUID: x2EOeJZ+SIO6B02Q2oiiTQ== X-CSE-MsgGUID: T6RNRopfSfyKKrGZrBoHFw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="127269231" Received: from unknown (HELO silpixa00401119.ir.intel.com) ([10.55.129.167]) by fmviesa001.fm.intel.com with ESMTP; 12 Dec 2024 08:19:11 -0800 From: Anatoly Burakov To: dev@dpdk.org Subject: [PATCH v1 3/4] net/igc: prevent crashes in secondary processes Date: Thu, 12 Dec 2024 16:19:05 +0000 Message-ID: <04d7ca704462b3320f77de7373fabd6686bc317b.1734020337.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <3c323577ce36cf4425d2c2def85d0d6644b87dc8.1734020337.git.anatoly.burakov@intel.com> References: <3c323577ce36cf4425d2c2def85d0d6644b87dc8.1734020337.git.anatoly.burakov@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Currently, the architecture of the base driver is such that it uses function pointers internally. These are not guaranteed to be valid in secondary processes, which can lead to crashes. This patch prevents these functions from being executed in igc driver. Fixes: 4f09bc55ac3d ("net/igc: implement device base operations") Cc: stable@dpdk.org Signed-off-by: Anatoly Burakov --- doc/guides/nics/igc.rst | 23 +++++++++ drivers/net/igc/igc_ethdev.c | 97 ++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) diff --git a/doc/guides/nics/igc.rst b/doc/guides/nics/igc.rst index c5af806b7b..9d4fee4177 100644 --- a/doc/guides/nics/igc.rst +++ b/doc/guides/nics/igc.rst @@ -104,3 +104,26 @@ Add a rule to enable ipv4-udp RSS: .. code-block:: console testpmd> flow create 0 ingress pattern end actions rss types ipv4-udp end / end + +Secondary Process Support +------------------------- + +The following ethdev API's are currently not supported for use in secondary processes: + +* ``rte_eth_dev_set_link_up`` +* ``rte_eth_dev_set_link_down`` +* ``rte_eth_link_get`` +* ``rte_eth_dev_start`` +* ``rte_eth_dev_stop`` +* ``rte_eth_dev_fw_version_get`` +* ``rte_eth_dev_rx_intr_enable`` +* ``rte_eth_dev_rx_intr_disable`` +* ``rte_eth_dev_led_on`` +* ``rte_eth_dev_led_off`` +* ``rte_eth_dev_default_mac_addr_set`` +* ``rte_eth_dev_mac_addr_add`` +* ``rte_eth_dev_mac_addr_remove`` +* ``rte_eth_dev_set_mc_addr_list`` +* ``rte_eth_dev_flow_ctrl_set`` +* ``rte_eth_timesync_read_rx_timestamp`` +* ``rte_eth_timesync_read_tx_timestamp`` diff --git a/drivers/net/igc/igc_ethdev.c b/drivers/net/igc/igc_ethdev.c index 87d7f7caa0..bf9143ccd8 100644 --- a/drivers/net/igc/igc_ethdev.c +++ b/drivers/net/igc/igc_ethdev.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "igc_logs.h" #include "igc_txrx.h" @@ -393,6 +394,14 @@ eth_igc_set_link_up(struct rte_eth_dev *dev) { struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev); + /* + * This function calls into the base driver, which in turn will use + * function pointers, which are not guaranteed to be valid in secondary + * processes, so avoid using this function in secondary processes. + */ + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return -E_RTE_SECONDARY; + if (hw->phy.media_type == igc_media_type_copper) igc_power_up_phy(hw); else @@ -405,6 +414,14 @@ eth_igc_set_link_down(struct rte_eth_dev *dev) { struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev); + /* + * This function calls into the base driver, which in turn will use + * function pointers, which are not guaranteed to be valid in secondary + * processes, so avoid using this function in secondary processes. + */ + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return -E_RTE_SECONDARY; + if (hw->phy.media_type == igc_media_type_copper) igc_power_down_phy(hw); else @@ -478,6 +495,14 @@ eth_igc_link_update(struct rte_eth_dev *dev, int wait_to_complete) struct rte_eth_link link; int link_check, count; + /* + * This function calls into the base driver, which in turn will use + * function pointers, which are not guaranteed to be valid in secondary + * processes, so avoid using this function in secondary processes. + */ + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return -E_RTE_SECONDARY; + link_check = 0; hw->mac.get_link_status = 1; @@ -655,6 +680,14 @@ eth_igc_stop(struct rte_eth_dev *dev) struct rte_intr_handle *intr_handle = pci_dev->intr_handle; struct rte_eth_link link; + /* + * This function calls into the base driver, which in turn will use + * function pointers, which are not guaranteed to be valid in secondary + * processes, so avoid using this function in secondary processes. + */ + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return -E_RTE_SECONDARY; + dev->data->dev_started = 0; adapter->stopped = 1; @@ -966,6 +999,14 @@ eth_igc_start(struct rte_eth_dev *dev) PMD_INIT_FUNC_TRACE(); + /* + * This function calls into the base driver, which in turn will use + * function pointers, which are not guaranteed to be valid in secondary + * processes, so avoid using this function in secondary processes. + */ + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return -E_RTE_SECONDARY; + /* disable all MSI-X interrupts */ IGC_WRITE_REG(hw, IGC_EIMC, 0x1f); IGC_WRITE_FLUSH(hw); @@ -1549,6 +1590,14 @@ eth_igc_fw_version_get(struct rte_eth_dev *dev, char *fw_version, struct igc_fw_version fw; int ret; + /* + * This function calls into the base driver, which in turn will use + * function pointers, which are not guaranteed to be valid in secondary + * processes, so avoid using this function in secondary processes. + */ + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return -E_RTE_SECONDARY; + igc_get_fw_version(hw, &fw); /* if option rom is valid, display its version too */ @@ -1639,6 +1688,14 @@ eth_igc_led_on(struct rte_eth_dev *dev) { struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev); + /* + * This function calls into the base driver, which in turn will use + * function pointers, which are not guaranteed to be valid in secondary + * processes, so avoid using this function in secondary processes. + */ + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return -E_RTE_SECONDARY; + return igc_led_on(hw) == IGC_SUCCESS ? 0 : -ENOTSUP; } @@ -1647,6 +1704,14 @@ eth_igc_led_off(struct rte_eth_dev *dev) { struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev); + /* + * This function calls into the base driver, which in turn will use + * function pointers, which are not guaranteed to be valid in secondary + * processes, so avoid using this function in secondary processes. + */ + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return -E_RTE_SECONDARY; + return igc_led_off(hw) == IGC_SUCCESS ? 0 : -ENOTSUP; } @@ -2190,6 +2255,10 @@ eth_igc_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id) struct rte_intr_handle *intr_handle = pci_dev->intr_handle; uint32_t vec = IGC_MISC_VEC_ID; + /* device interrupts are only subscribed to in primary processes */ + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return -E_RTE_SECONDARY; + if (rte_intr_allow_others(intr_handle)) vec = IGC_RX_VEC_START; @@ -2209,6 +2278,10 @@ eth_igc_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id) struct rte_intr_handle *intr_handle = pci_dev->intr_handle; uint32_t vec = IGC_MISC_VEC_ID; + /* device interrupts are only subscribed to in primary processes */ + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return -E_RTE_SECONDARY; + if (rte_intr_allow_others(intr_handle)) vec = IGC_RX_VEC_START; @@ -2272,6 +2345,14 @@ eth_igc_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf) uint32_t rctl; int err; + /* + * This function calls into the base driver, which in turn will use + * function pointers, which are not guaranteed to be valid in secondary + * processes, so avoid using this function in secondary processes. + */ + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return -E_RTE_SECONDARY; + if (fc_conf->autoneg != hw->mac.autoneg) return -ENOTSUP; @@ -2773,6 +2854,14 @@ eth_igc_timesync_read_rx_timestamp(__rte_unused struct rte_eth_dev *dev, struct igc_rx_queue *rxq; uint64_t rx_timestamp; + /* + * This function calls into the base driver, which in turn will use + * function pointers, which are not guaranteed to be valid in secondary + * processes, so avoid using this function in secondary processes. + */ + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return -E_RTE_SECONDARY; + /* Get current link speed. */ eth_igc_link_update(dev, 1); rte_eth_linkstatus_get(dev, &link); @@ -2809,6 +2898,14 @@ eth_igc_timesync_read_tx_timestamp(struct rte_eth_dev *dev, uint64_t tx_timestamp; int adjust = 0; + /* + * This function calls into the base driver, which in turn will use + * function pointers, which are not guaranteed to be valid in secondary + * processes, so avoid using this function in secondary processes. + */ + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return -E_RTE_SECONDARY; + val = IGC_READ_REG(hw, IGC_TSYNCTXCTL); if (!(val & IGC_TSYNCTXCTL_VALID)) return -EINVAL; -- 2.43.5