net/hns3: fix flow rule list in multi-process

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: fcba820d9b9e ("net/hns3: support flow director")
Fixes: c37ca66f2b27 ("net/hns3: support RSS")
Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
This commit is contained in:
Chengwen Feng 2021-07-17 10:02:55 +08:00 committed by Thomas Monjalon
parent 6dc90c7eb3
commit 9b290a3a63
5 changed files with 60 additions and 99 deletions

View File

@ -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 @@ err_mp_init_secondary:
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);

View File

@ -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

View File

@ -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 @@ err_mp_init_secondary:
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);

View File

@ -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_ */

View File

@ -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 @@ rss_config_err:
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 @@ err:
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);
}