Skip to content

Commit

Permalink
net/hns3: fix flow rule list in multi-process
Browse files Browse the repository at this point in the history
[ upstream commit 9b290a3 ]

Currently, hns3 driver saves rte_flow list into the
rte_eth_dev.process_private field, 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: fcba820 ("net/hns3: support flow director")
Fixes: c37ca66 ("net/hns3: support RSS")

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
  • Loading branch information
fengchengwen authored and bluca committed Jul 26, 2021
1 parent fc0e7a4 commit 28a94ee
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 99 deletions.
24 changes: 3 additions & 21 deletions drivers/net/hns3/hns3_ethdev.c
Expand Up @@ -4852,6 +4852,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);
(void)hns3_firmware_compat_config(hw, false);
hns3_uninit_umv_space(hw);
Expand Down Expand Up @@ -5188,11 +5189,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);
Expand All @@ -5207,8 +5205,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);

Expand Down Expand Up @@ -6269,15 +6265,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);
Expand Down Expand Up @@ -6379,8 +6366,6 @@ hns3_dev_init(struct rte_eth_dev *eth_dev)
eth_dev->rx_pkt_burst = NULL;
eth_dev->tx_pkt_burst = NULL;
eth_dev->tx_pkt_prepare = NULL;
rte_free(eth_dev->process_private);
eth_dev->process_private = NULL;
return ret;
}

Expand All @@ -6392,11 +6377,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);
Expand Down
3 changes: 3 additions & 0 deletions drivers/net/hns3/hns3_ethdev.h
Expand Up @@ -556,6 +556,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
Expand Down
24 changes: 3 additions & 21 deletions drivers/net/hns3/hns3_ethdev_vf.c
Expand Up @@ -1876,6 +1876,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);
Expand Down Expand Up @@ -1990,11 +1991,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);
Expand All @@ -2008,8 +2006,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);

Expand Down Expand Up @@ -2756,15 +2752,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);
Expand Down Expand Up @@ -2864,8 +2851,6 @@ hns3vf_dev_init(struct rte_eth_dev *eth_dev)
eth_dev->rx_pkt_burst = NULL;
eth_dev->tx_pkt_burst = NULL;
eth_dev->tx_pkt_prepare = NULL;
rte_free(eth_dev->process_private);
eth_dev->process_private = NULL;

return ret;
}
Expand All @@ -2878,11 +2863,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);
Expand Down
7 changes: 1 addition & 6 deletions drivers/net/hns3/hns3_fdir.h
Expand Up @@ -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.
*/
Expand All @@ -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_ */

0 comments on commit 28a94ee

Please sign in to comment.