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 3117AA0C4A; Sat, 17 Jul 2021 04:04:34 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 98982413B0; Sat, 17 Jul 2021 04:03:58 +0200 (CEST) Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by mails.dpdk.org (Postfix) with ESMTP id 9EB2840151 for ; Sat, 17 Jul 2021 04:03:46 +0200 (CEST) Received: from dggeme756-chm.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4GRWTl3CyYz1CJ9V for ; Sat, 17 Jul 2021 09:58:03 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggeme756-chm.china.huawei.com (10.3.19.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Sat, 17 Jul 2021 10:03:44 +0800 From: "Min Hu (Connor)" To: CC: , Date: Sat, 17 Jul 2021 10:02:55 +0800 Message-ID: <1626487376-30038-8-git-send-email-humin29@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1626487376-30038-1-git-send-email-humin29@huawei.com> References: <1626487376-30038-1-git-send-email-humin29@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggeme756-chm.china.huawei.com (10.3.19.102) X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH 7/8] net/hns3: fix flow list separate management 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 Sender: "dev" From: Chengwen Feng Currently, hns3 driver saves rte flow list into the rte_eth_dev.process_private filed, it may cause following problem: The FDIR/RSS rules cannot be managed in a unified manner because the management structure is not visible between processes. This patch fixes it by moving rte flow list to struct hns3_hw which is visible between processes. Fixes: fcba820d9b9e ("net/hns3: support flow director") Fixes: c37ca66f2b27 ("net/hns3: support RSS") Cc: stable@dpdk.org Signed-off-by: Chengwen Feng Signed-off-by: Min Hu (Connor) --- drivers/net/hns3/hns3_ethdev.c | 24 ++------- drivers/net/hns3/hns3_ethdev.h | 3 ++ drivers/net/hns3/hns3_ethdev_vf.c | 24 ++------- drivers/net/hns3/hns3_fdir.h | 7 +-- drivers/net/hns3/hns3_flow.c | 101 +++++++++++++++++++------------------- 5 files changed, 60 insertions(+), 99 deletions(-) diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c index 4a302d2..a374fa7 100644 --- a/drivers/net/hns3/hns3_ethdev.c +++ b/drivers/net/hns3/hns3_ethdev.c @@ -5292,6 +5292,7 @@ hns3_uninit_pf(struct rte_eth_dev *eth_dev) hns3_rss_uninit(hns); (void)hns3_config_gro(hw, false); hns3_promisc_uninit(hw); + hns3_flow_uninit(eth_dev); hns3_fdir_filter_uninit(hns); hns3_uninit_umv_space(hw); hns3_tqp_stats_uninit(hw); @@ -5918,11 +5919,8 @@ hns3_dev_close(struct rte_eth_dev *eth_dev) struct hns3_hw *hw = &hns->hw; int ret = 0; - if (rte_eal_process_type() != RTE_PROC_PRIMARY) { - rte_free(eth_dev->process_private); - eth_dev->process_private = NULL; + if (rte_eal_process_type() != RTE_PROC_PRIMARY) return 0; - } if (hw->adapter_state == HNS3_NIC_STARTED) ret = hns3_dev_stop(eth_dev); @@ -5937,8 +5935,6 @@ hns3_dev_close(struct rte_eth_dev *eth_dev) hns3_uninit_pf(eth_dev); hns3_free_all_queues(eth_dev); rte_free(hw->reset.wait_data); - rte_free(eth_dev->process_private); - eth_dev->process_private = NULL; hns3_mp_uninit_primary(); hns3_warn(hw, "Close port %u finished", hw->data->port_id); @@ -7398,15 +7394,6 @@ hns3_dev_init(struct rte_eth_dev *eth_dev) PMD_INIT_FUNC_TRACE(); - eth_dev->process_private = (struct hns3_process_private *) - rte_zmalloc_socket("hns3_filter_list", - sizeof(struct hns3_process_private), - RTE_CACHE_LINE_SIZE, eth_dev->device->numa_node); - if (eth_dev->process_private == NULL) { - PMD_INIT_LOG(ERR, "Failed to alloc memory for process private"); - return -ENOMEM; - } - hns3_flow_init(eth_dev); hns3_set_rxtx_function(eth_dev); @@ -7510,8 +7497,6 @@ hns3_dev_init(struct rte_eth_dev *eth_dev) eth_dev->tx_pkt_burst = NULL; eth_dev->tx_pkt_prepare = NULL; eth_dev->tx_descriptor_status = NULL; - rte_free(eth_dev->process_private); - eth_dev->process_private = NULL; return ret; } @@ -7523,11 +7508,8 @@ hns3_dev_uninit(struct rte_eth_dev *eth_dev) PMD_INIT_FUNC_TRACE(); - if (rte_eal_process_type() != RTE_PROC_PRIMARY) { - rte_free(eth_dev->process_private); - eth_dev->process_private = NULL; + if (rte_eal_process_type() != RTE_PROC_PRIMARY) return 0; - } if (hw->adapter_state < HNS3_NIC_CLOSING) hns3_dev_close(eth_dev); diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h index 3485614..8e66d9f 100644 --- a/drivers/net/hns3/hns3_ethdev.h +++ b/drivers/net/hns3/hns3_ethdev.h @@ -630,6 +630,9 @@ struct hns3_hw { struct hns3_port_base_vlan_config port_base_vlan_cfg; pthread_mutex_t flows_lock; /* rte_flow ops lock */ + struct hns3_fdir_rule_list flow_fdir_list; /* flow fdir rule list */ + struct hns3_rss_filter_list flow_rss_list; /* flow RSS rule list */ + struct hns3_flow_mem_list flow_list; /* * PMD setup and configuration is not thread safe. Since it is not diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c index de659c0..8d9b797 100644 --- a/drivers/net/hns3/hns3_ethdev_vf.c +++ b/drivers/net/hns3/hns3_ethdev_vf.c @@ -2071,6 +2071,7 @@ hns3vf_uninit_vf(struct rte_eth_dev *eth_dev) (void)hns3_config_gro(hw, false); (void)hns3vf_set_alive(hw, false); (void)hns3vf_set_promisc_mode(hw, false, false, false); + hns3_flow_uninit(eth_dev); hns3_tqp_stats_uninit(hw); hns3vf_disable_irq0(hw); rte_intr_disable(&pci_dev->intr_handle); @@ -2186,11 +2187,8 @@ hns3vf_dev_close(struct rte_eth_dev *eth_dev) struct hns3_hw *hw = &hns->hw; int ret = 0; - if (rte_eal_process_type() != RTE_PROC_PRIMARY) { - rte_free(eth_dev->process_private); - eth_dev->process_private = NULL; + if (rte_eal_process_type() != RTE_PROC_PRIMARY) return 0; - } if (hw->adapter_state == HNS3_NIC_STARTED) ret = hns3vf_dev_stop(eth_dev); @@ -2204,8 +2202,6 @@ hns3vf_dev_close(struct rte_eth_dev *eth_dev) hns3vf_uninit_vf(eth_dev); hns3_free_all_queues(eth_dev); rte_free(hw->reset.wait_data); - rte_free(eth_dev->process_private); - eth_dev->process_private = NULL; hns3_mp_uninit_primary(); hns3_warn(hw, "Close port %u finished", hw->data->port_id); @@ -2962,15 +2958,6 @@ hns3vf_dev_init(struct rte_eth_dev *eth_dev) PMD_INIT_FUNC_TRACE(); - eth_dev->process_private = (struct hns3_process_private *) - rte_zmalloc_socket("hns3_filter_list", - sizeof(struct hns3_process_private), - RTE_CACHE_LINE_SIZE, eth_dev->device->numa_node); - if (eth_dev->process_private == NULL) { - PMD_INIT_LOG(ERR, "Failed to alloc memory for process private"); - return -ENOMEM; - } - hns3_flow_init(eth_dev); hns3_set_rxtx_function(eth_dev); @@ -3072,8 +3059,6 @@ hns3vf_dev_init(struct rte_eth_dev *eth_dev) eth_dev->tx_pkt_burst = NULL; eth_dev->tx_pkt_prepare = NULL; eth_dev->tx_descriptor_status = NULL; - rte_free(eth_dev->process_private); - eth_dev->process_private = NULL; return ret; } @@ -3086,11 +3071,8 @@ hns3vf_dev_uninit(struct rte_eth_dev *eth_dev) PMD_INIT_FUNC_TRACE(); - if (rte_eal_process_type() != RTE_PROC_PRIMARY) { - rte_free(eth_dev->process_private); - eth_dev->process_private = NULL; + if (rte_eal_process_type() != RTE_PROC_PRIMARY) return 0; - } if (hw->adapter_state < HNS3_NIC_CLOSING) hns3vf_dev_close(eth_dev); diff --git a/drivers/net/hns3/hns3_fdir.h b/drivers/net/hns3/hns3_fdir.h index fc62daa..3f610f7 100644 --- a/drivers/net/hns3/hns3_fdir.h +++ b/drivers/net/hns3/hns3_fdir.h @@ -189,12 +189,6 @@ TAILQ_HEAD(hns3_fdir_rule_list, hns3_fdir_rule_ele); TAILQ_HEAD(hns3_rss_filter_list, hns3_rss_conf_ele); TAILQ_HEAD(hns3_flow_mem_list, hns3_flow_mem); -struct hns3_process_private { - struct hns3_fdir_rule_list fdir_list; - struct hns3_rss_filter_list filter_rss_list; - struct hns3_flow_mem_list flow_list; -}; - /* * A structure used to define fields of a FDIR related info. */ @@ -220,6 +214,7 @@ int hns3_fdir_filter_program(struct hns3_adapter *hns, int hns3_clear_all_fdir_filter(struct hns3_adapter *hns); int hns3_get_count(struct hns3_hw *hw, uint32_t id, uint64_t *value); void hns3_flow_init(struct rte_eth_dev *dev); +void hns3_flow_uninit(struct rte_eth_dev *dev); int hns3_restore_all_fdir_filter(struct hns3_adapter *hns); #endif /* _HNS3_FDIR_H_ */ diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c index 755a6f2..fc77979 100644 --- a/drivers/net/hns3/hns3_flow.c +++ b/drivers/net/hns3/hns3_flow.c @@ -1202,54 +1202,34 @@ hns3_parse_fdir_filter(struct rte_eth_dev *dev, return hns3_handle_actions(dev, actions, rule, error); } -void -hns3_flow_init(struct rte_eth_dev *dev) -{ - struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private); - struct hns3_process_private *process_list = dev->process_private; - pthread_mutexattr_t attr; - - if (rte_eal_process_type() == RTE_PROC_PRIMARY) { - pthread_mutexattr_init(&attr); - pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); - pthread_mutex_init(&hw->flows_lock, &attr); - dev->data->dev_flags |= RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE; - } - - TAILQ_INIT(&process_list->fdir_list); - TAILQ_INIT(&process_list->filter_rss_list); - TAILQ_INIT(&process_list->flow_list); -} - static void hns3_filterlist_flush(struct rte_eth_dev *dev) { - struct hns3_process_private *process_list = dev->process_private; + struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private); struct hns3_fdir_rule_ele *fdir_rule_ptr; struct hns3_rss_conf_ele *rss_filter_ptr; struct hns3_flow_mem *flow_node; - fdir_rule_ptr = TAILQ_FIRST(&process_list->fdir_list); + fdir_rule_ptr = TAILQ_FIRST(&hw->flow_fdir_list); while (fdir_rule_ptr) { - TAILQ_REMOVE(&process_list->fdir_list, fdir_rule_ptr, entries); + TAILQ_REMOVE(&hw->flow_fdir_list, fdir_rule_ptr, entries); rte_free(fdir_rule_ptr); - fdir_rule_ptr = TAILQ_FIRST(&process_list->fdir_list); + fdir_rule_ptr = TAILQ_FIRST(&hw->flow_fdir_list); } - rss_filter_ptr = TAILQ_FIRST(&process_list->filter_rss_list); + rss_filter_ptr = TAILQ_FIRST(&hw->flow_rss_list); while (rss_filter_ptr) { - TAILQ_REMOVE(&process_list->filter_rss_list, rss_filter_ptr, - entries); + TAILQ_REMOVE(&hw->flow_rss_list, rss_filter_ptr, entries); rte_free(rss_filter_ptr); - rss_filter_ptr = TAILQ_FIRST(&process_list->filter_rss_list); + rss_filter_ptr = TAILQ_FIRST(&hw->flow_rss_list); } - flow_node = TAILQ_FIRST(&process_list->flow_list); + flow_node = TAILQ_FIRST(&hw->flow_list); while (flow_node) { - TAILQ_REMOVE(&process_list->flow_list, flow_node, entries); + TAILQ_REMOVE(&hw->flow_list, flow_node, entries); rte_free(flow_node->flow); rte_free(flow_node); - flow_node = TAILQ_FIRST(&process_list->flow_list); + flow_node = TAILQ_FIRST(&hw->flow_list); } } @@ -1519,7 +1499,6 @@ static int hns3_config_rss_filter(struct rte_eth_dev *dev, const struct hns3_rss_conf *conf, bool add) { - struct hns3_process_private *process_list = dev->process_private; struct hns3_adapter *hns = dev->data->dev_private; struct hns3_rss_conf_ele *rss_filter_ptr; struct hns3_hw *hw = &hns->hw; @@ -1604,7 +1583,7 @@ hns3_config_rss_filter(struct rte_eth_dev *dev, * When create a new RSS rule, the old rule will be overlaid and set * invalid. */ - TAILQ_FOREACH(rss_filter_ptr, &process_list->filter_rss_list, entries) + TAILQ_FOREACH(rss_filter_ptr, &hw->flow_rss_list, entries) rss_filter_ptr->filter_info.valid = false; rss_config_err: @@ -1616,7 +1595,6 @@ hns3_config_rss_filter(struct rte_eth_dev *dev, static int hns3_clear_rss_filter(struct rte_eth_dev *dev) { - struct hns3_process_private *process_list = dev->process_private; struct hns3_adapter *hns = dev->data->dev_private; struct hns3_rss_conf_ele *rss_filter_ptr; struct hns3_hw *hw = &hns->hw; @@ -1624,10 +1602,9 @@ hns3_clear_rss_filter(struct rte_eth_dev *dev) int rss_rule_fail_cnt = 0; /* count for failure of clearing RSS rules */ int ret = 0; - rss_filter_ptr = TAILQ_FIRST(&process_list->filter_rss_list); + rss_filter_ptr = TAILQ_FIRST(&hw->flow_rss_list); while (rss_filter_ptr) { - TAILQ_REMOVE(&process_list->filter_rss_list, rss_filter_ptr, - entries); + TAILQ_REMOVE(&hw->flow_rss_list, rss_filter_ptr, entries); ret = hns3_config_rss_filter(dev, &rss_filter_ptr->filter_info, false); if (ret) @@ -1635,7 +1612,7 @@ hns3_clear_rss_filter(struct rte_eth_dev *dev) else rss_rule_succ_cnt++; rte_free(rss_filter_ptr); - rss_filter_ptr = TAILQ_FIRST(&process_list->filter_rss_list); + rss_filter_ptr = TAILQ_FIRST(&hw->flow_rss_list); } if (rss_rule_fail_cnt) { @@ -1739,7 +1716,6 @@ hns3_flow_create(struct rte_eth_dev *dev, const struct rte_flow_attr *attr, const struct rte_flow_action actions[], struct rte_flow_error *error) { - struct hns3_process_private *process_list = dev->process_private; struct hns3_adapter *hns = dev->data->dev_private; struct hns3_hw *hw = &hns->hw; const struct hns3_rss_conf *rss_conf; @@ -1771,7 +1747,7 @@ hns3_flow_create(struct rte_eth_dev *dev, const struct rte_flow_attr *attr, } flow_node->flow = flow; - TAILQ_INSERT_TAIL(&process_list->flow_list, flow_node, entries); + TAILQ_INSERT_TAIL(&hw->flow_list, flow_node, entries); act = hns3_find_rss_general_action(pattern, actions); if (act) { @@ -1793,8 +1769,7 @@ hns3_flow_create(struct rte_eth_dev *dev, const struct rte_flow_attr *attr, hns3_rss_conf_copy(&rss_filter_ptr->filter_info, &rss_conf->conf); rss_filter_ptr->filter_info.valid = true; - TAILQ_INSERT_TAIL(&process_list->filter_rss_list, - rss_filter_ptr, entries); + TAILQ_INSERT_TAIL(&hw->flow_rss_list, rss_filter_ptr, entries); flow->rule = rss_filter_ptr; flow->filter_type = RTE_ETH_FILTER_HASH; @@ -1828,8 +1803,7 @@ hns3_flow_create(struct rte_eth_dev *dev, const struct rte_flow_attr *attr, if (!ret) { memcpy(&fdir_rule_ptr->fdir_conf, &fdir_rule, sizeof(struct hns3_fdir_rule)); - TAILQ_INSERT_TAIL(&process_list->fdir_list, - fdir_rule_ptr, entries); + TAILQ_INSERT_TAIL(&hw->flow_fdir_list, fdir_rule_ptr, entries); flow->rule = fdir_rule_ptr; flow->filter_type = RTE_ETH_FILTER_FDIR; @@ -1844,7 +1818,7 @@ hns3_flow_create(struct rte_eth_dev *dev, const struct rte_flow_attr *attr, rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_HANDLE, NULL, "Failed to create flow"); out: - TAILQ_REMOVE(&process_list->flow_list, flow_node, entries); + TAILQ_REMOVE(&hw->flow_list, flow_node, entries); rte_free(flow_node); rte_free(flow); return NULL; @@ -1855,13 +1829,13 @@ static int hns3_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow, struct rte_flow_error *error) { - struct hns3_process_private *process_list = dev->process_private; struct hns3_adapter *hns = dev->data->dev_private; struct hns3_fdir_rule_ele *fdir_rule_ptr; struct hns3_rss_conf_ele *rss_filter_ptr; struct hns3_flow_mem *flow_node; enum rte_filter_type filter_type; struct hns3_fdir_rule fdir_rule; + struct hns3_hw *hw = &hns->hw; int ret; if (flow == NULL) @@ -1884,7 +1858,7 @@ hns3_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow, "Destroy FDIR fail.Try again"); if (fdir_rule.flags & HNS3_RULE_FLAG_COUNTER) hns3_counter_release(dev, fdir_rule.act_cnt.id); - TAILQ_REMOVE(&process_list->fdir_list, fdir_rule_ptr, entries); + TAILQ_REMOVE(&hw->flow_fdir_list, fdir_rule_ptr, entries); rte_free(fdir_rule_ptr); fdir_rule_ptr = NULL; break; @@ -1897,8 +1871,7 @@ hns3_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow, RTE_FLOW_ERROR_TYPE_HANDLE, flow, "Destroy RSS fail.Try again"); - TAILQ_REMOVE(&process_list->filter_rss_list, rss_filter_ptr, - entries); + TAILQ_REMOVE(&hw->flow_rss_list, rss_filter_ptr, entries); rte_free(rss_filter_ptr); rss_filter_ptr = NULL; break; @@ -1908,10 +1881,9 @@ hns3_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow, "Unsupported filter type"); } - TAILQ_FOREACH(flow_node, &process_list->flow_list, entries) { + TAILQ_FOREACH(flow_node, &hw->flow_list, entries) { if (flow_node->flow == flow) { - TAILQ_REMOVE(&process_list->flow_list, flow_node, - entries); + TAILQ_REMOVE(&hw->flow_list, flow_node, entries); rte_free(flow_node); flow_node = NULL; break; @@ -2097,3 +2069,30 @@ hns3_dev_flow_ops_get(struct rte_eth_dev *dev, *ops = &hns3_flow_ops; return 0; } + +void +hns3_flow_init(struct rte_eth_dev *dev) +{ + struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private); + pthread_mutexattr_t attr; + + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return; + + pthread_mutexattr_init(&attr); + pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); + pthread_mutex_init(&hw->flows_lock, &attr); + dev->data->dev_flags |= RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE; + + TAILQ_INIT(&hw->flow_fdir_list); + TAILQ_INIT(&hw->flow_rss_list); + TAILQ_INIT(&hw->flow_list); +} + +void +hns3_flow_uninit(struct rte_eth_dev *dev) +{ + struct rte_flow_error error; + if (rte_eal_process_type() == RTE_PROC_PRIMARY) + hns3_flow_flush_wrap(dev, &error); +} -- 2.7.4