net/mlx5/hws: fix direct index insert on dep wqe
PATCH 1/4 net/mlx5/hws: fix direct index insert on dep wqe
From: Alex Vesker <[email protected]>
In case a depend WQE was required and direct index was needed we would not set the direct index on the dep_wqe. This leads to incorrect insertion to index zero.
--- drivers/net/mlx5/hws/mlx5dr_rule.c | 15 ++++++++------- drivers/net/mlx5/hws/mlx5dr_send.c | 1 + drivers/net/mlx5/hws/mlx5dr_send.h | 1 + 3 files changed, 10 insertions(+), 7 deletions(-)
drivers/net/mlx5/hws/mlx5dr_rule.c +8 -7
@@ -58,14 +58,16 @@ static void mlx5dr_rule_init_dep_wqe(struct mlx5dr_send_ring_dep_wqe *dep_wqe,struct mlx5dr_rule *rule, const struct rte_flow_item *items, struct mlx5dr_match_template *mt, - void *user_data) + struct mlx5dr_rule_attr *attr) { struct mlx5dr_matcher *matcher = rule->matcher;struct mlx5dr_table *tbl = matcher->tbl;bool skip_rx, skip_tx; dep_wqe->rule = rule; - dep_wqe->user_data = user_data; + dep_wqe->user_data = attr->user_data; + dep_wqe->direct_index =mlx5dr_matcher_is_insert_by_idx (matcher) ? + attr->rule_idx :0 ;if (!items) {/* rule update */ dep_wqe->rtc_0 = rule->rtc_0;
@@ -374,8 +376,8 @@ static int mlx5dr_rule_create_hws_fw_wqe(struct mlx5dr_rule *rule, }mlx5dr_rule_create_init (rule, &ste_attr, &apply, false); -mlx5dr_rule_init_dep_wqe (&match_wqe, rule, items, mt, attr->user_data); -mlx5dr_rule_init_dep_wqe (&range_wqe, rule, items, mt, attr->user_data); +mlx5dr_rule_init_dep_wqe (&match_wqe, rule, items, mt, attr); +mlx5dr_rule_init_dep_wqe (&range_wqe, rule, items, mt, attr); ste_attr.direct_index =0 ; ste_attr.rtc_0 = match_wqe.rtc_0;
@@ -482,7 +484,7 @@ static int mlx5dr_rule_create_hws(struct mlx5dr_rule *rule,* dep_wqe buffers (ctrl, data) are also reused for all STE writes. */ dep_wqe =mlx5dr_send_add_new_dep_wqe (queue); -mlx5dr_rule_init_dep_wqe (dep_wqe, rule, items, mt, attr->user_data); +mlx5dr_rule_init_dep_wqe (dep_wqe, rule, items, mt, attr); ste_attr.wqe_ctrl = &dep_wqe->wqe_ctrl; ste_attr.wqe_data = &dep_wqe->wqe_data;
@@ -544,8 +546,7 @@ static int mlx5dr_rule_create_hws(struct mlx5dr_rule *rule, ste_attr.used_id_rtc_1 = &rule->rtc_1; ste_attr.retry_rtc_0 = dep_wqe->retry_rtc_0; ste_attr.retry_rtc_1 = dep_wqe->retry_rtc_1; - ste_attr.direct_index =mlx5dr_matcher_is_insert_by_idx (matcher) ? - attr->rule_idx :0 ; + ste_attr.direct_index = dep_wqe->direct_index; }else { apply.next_direct_idx = --ste_attr.direct_index; }
drivers/net/mlx5/hws/mlx5dr_send.c +1 -0
@@ -50,6 +50,7 @@ void mlx5dr_send_all_dep_wqe(struct mlx5dr_send_engine *queue) ste_attr.used_id_rtc_1 = &dep_wqe->rule->rtc_1; ste_attr.wqe_ctrl = &dep_wqe->wqe_ctrl; ste_attr.wqe_data = &dep_wqe->wqe_data; + ste_attr.direct_index = dep_wqe->direct_index;mlx5dr_send_ste (queue, &ste_attr);
drivers/net/mlx5/hws/mlx5dr_send.h +1 -0
@@ -106,6 +106,7 @@ struct mlx5dr_send_ring_dep_wqe {uint32_t rtc_1;uint32_t retry_rtc_0;uint32_t retry_rtc_1; +uint32_t direct_index;void *user_data; };
Signature · 1 line
2.39.2
PATCH 2/4 net/mlx5: fix templates clean up of FDB control flow rules
This patch refactors the creation and clean up of templates used for FDB control flow rules, when HWS is enabled.
All pattern and actions templates, and template tables are stored in a separate structure, mlx5_flow_hw_ctrl_fdb. It is allocated if and only if E-Switch is enabled.
During HWS clean up, all of these templates are explicitly destroyed, instead of relying on templates general templates clean up.
--- drivers/net/mlx5/mlx5.h | 6 +- drivers/net/mlx5/mlx5_flow.h | 19 +++ drivers/net/mlx5/mlx5_flow_hw.c | 255 ++++++++++++++++++-------------- 3 files changed, 166 insertions(+), 114 deletions(-)
drivers/net/mlx5/mlx5.h +1 -5
@@ -1894,11 +1894,7 @@ struct mlx5_priv {rte_spinlock_t hw_ctrl_lock; LIST_HEAD(hw_ctrl_flow, mlx5_hw_ctrl_flow) hw_ctrl_flows; LIST_HEAD(hw_ext_ctrl_flow, mlx5_hw_ctrl_flow) hw_ext_ctrl_flows; -struct rte_flow_template_table *hw_esw_sq_miss_root_tbl; -struct rte_flow_template_table *hw_esw_sq_miss_tbl; -struct rte_flow_template_table *hw_esw_zero_tbl; -struct rte_flow_template_table *hw_tx_meta_cpy_tbl; -struct rte_flow_template_table *hw_lacp_rx_tbl; +struct mlx5_flow_hw_ctrl_fdb *hw_ctrl_fdb;struct rte_flow_pattern_template *hw_tx_repr_tagging_pt;struct rte_flow_actions_template *hw_tx_repr_tagging_at;struct rte_flow_template_table *hw_tx_repr_tagging_tbl;
drivers/net/mlx5/mlx5_flow.h +19 -0
@@ -2775,6 +2775,25 @@ struct mlx5_flow_hw_ctrl_rx { [MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX ]; }; +/* Contains all templates required for control flow rules in FDB with HWS. */ +struct mlx5_flow_hw_ctrl_fdb { +struct rte_flow_pattern_template *esw_mgr_items_tmpl; +struct rte_flow_actions_template *regc_jump_actions_tmpl; +struct rte_flow_template_table *hw_esw_sq_miss_root_tbl; +struct rte_flow_pattern_template *regc_sq_items_tmpl; +struct rte_flow_actions_template *port_actions_tmpl; +struct rte_flow_template_table *hw_esw_sq_miss_tbl; +struct rte_flow_pattern_template *port_items_tmpl; +struct rte_flow_actions_template *jump_one_actions_tmpl; +struct rte_flow_template_table *hw_esw_zero_tbl; +struct rte_flow_pattern_template *tx_meta_items_tmpl; +struct rte_flow_actions_template *tx_meta_actions_tmpl; +struct rte_flow_template_table *hw_tx_meta_cpy_tbl; +struct rte_flow_pattern_template *lacp_rx_items_tmpl; +struct rte_flow_actions_template *lacp_rx_actions_tmpl; +struct rte_flow_template_table *hw_lacp_rx_tbl; +}; +#define MLX5_CTRL_PROMISCUOUS (RTE_BIT32(0))#define MLX5_CTRL_ALL_MULTICAST (RTE_BIT32(1))#define MLX5_CTRL_BROADCAST (RTE_BIT32(2))
drivers/net/mlx5/mlx5_flow_hw.c +146 -109
409 lines not on this page · raw message
Signature · 1 line
2.39.2
PATCH 3/4 net/mlx5: fix rollback on failed flow configure
In reply to Dariusz SosnowskiIf rte_flow_configure() failed, then some port resources were either not freed, nor reset to the default state. As a result, assumptions in other places in PMD were invalidated and that lead to segmentation faults during release of HW Steering resources when port was closed.
This patch adds missing resource release to rollback procedure in mlx5 PMD implementation of rte_flow_configure(). Whole rollback procedure is reordered for clarity, to resemble reverse order of resource allocation.
--- drivers/net/mlx5/mlx5_flow_hw.c | 65 ++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 25 deletions(-)
drivers/net/mlx5/mlx5_flow_hw.c +40 -25
@@ -10188,7 +10188,7 @@ flow_hw_compare_config(const struct mlx5_flow_hw_attr *hw_attr,* mlx5_dev_close -> flow_hw_resource_release -> flow_hw_actions_template_destroy */ static void -action_template_drop_release (struct rte_eth_dev *dev) +flow_hw_action_template_drop_release (struct rte_eth_dev *dev) {int i;struct mlx5_priv *priv = dev->data->dev_private;
@@ -10204,7 +10204,7 @@ action_template_drop_release(struct rte_eth_dev *dev) }static int -action_template_drop_init (struct rte_eth_dev *dev, +flow_hw_action_template_drop_init (struct rte_eth_dev *dev,struct rte_flow_error *error) {const struct rte_flow_action drop[2 ] = {
@@ -10466,7 +10466,7 @@ flow_hw_configure(struct rte_eth_dev *dev,rte_spinlock_init (&priv->hw_ctrl_lock);LIST_INIT (&priv->hw_ctrl_flows);LIST_INIT (&priv->hw_ext_ctrl_flows); - ret =action_template_drop_init (dev, error); + ret =flow_hw_action_template_drop_init (dev, error);if (ret) goto err; ret =flow_hw_create_ctrl_rx_tables (dev);
@@ -10594,6 +10594,15 @@ flow_hw_configure(struct rte_eth_dev *dev, dev->flow_fp_ops = &mlx5_flow_hw_fp_ops;return 0 ; err: + priv->hws_strict_queue =0 ; +flow_hw_destroy_nat64_actions (priv); +flow_hw_destroy_vlan (dev); +if (priv->hws_age_req) +mlx5_hws_age_pool_destroy (priv); +if (priv->hws_cpool) { +mlx5_hws_cnt_pool_destroy (priv->sh, priv->hws_cpool); + priv->hws_cpool =NULL ; + }if (priv->hws_ctpool) {flow_hw_ct_pool_destroy (dev, priv->hws_ctpool); priv->hws_ctpool =NULL ;
@@ -10602,29 +10611,38 @@ flow_hw_configure(struct rte_eth_dev *dev,flow_hw_ct_mng_destroy (dev, priv->ct_mng); priv->ct_mng =NULL ; } -if (priv->hws_age_req) -mlx5_hws_age_pool_destroy (priv); -if (priv->hws_cpool) { -mlx5_hws_cnt_pool_destroy (priv->sh, priv->hws_cpool); - priv->hws_cpool =NULL ; - } -action_template_drop_release (dev); -mlx5_flow_quota_destroy (dev);flow_hw_destroy_send_to_kernel_action (priv);flow_hw_cleanup_ctrl_fdb_tables (dev);flow_hw_free_vport_actions (priv); +if (priv->hw_def_miss) { +mlx5dr_action_destroy (priv->hw_def_miss); + priv->hw_def_miss =NULL ; + } +flow_hw_cleanup_tx_repr_tagging (dev);for (i =0 ; i <MLX5_HW_ACTION_FLAG_MAX ; i++) { -if (priv->hw_drop[i]) +if (priv->hw_drop[i]) {mlx5dr_action_destroy (priv->hw_drop[i]); -if (priv->hw_tag[i]) + priv->hw_drop[i] =NULL ; + } +if (priv->hw_tag[i]) {mlx5dr_action_destroy (priv->hw_tag[i]); + priv->hw_tag[i] =NULL ; + } } -if (priv->hw_def_miss) -mlx5dr_action_destroy (priv->hw_def_miss); -flow_hw_destroy_nat64_actions (priv); -flow_hw_destroy_vlan (dev); -if (dr_ctx) +mlx5_flow_meter_uninit (dev); +mlx5_flow_quota_destroy (dev); +flow_hw_cleanup_ctrl_rx_tables (dev); +flow_hw_action_template_drop_release (dev); +if (dr_ctx) {claim_zero (mlx5dr_context_close (dr_ctx)); + priv->dr_ctx =NULL ; + } +if (priv->shared_host) { +struct mlx5_priv *host_priv = priv->shared_host->data->dev_private; + +__atomic_fetch_sub (&host_priv->shared_refcnt,1 , __ATOMIC_RELAXED); + priv->shared_host =NULL ; + }for (i =0 ; i < nb_q_updated; i++) {rte_ring_free (priv->hw_q[i].indir_iq);rte_ring_free (priv->hw_q[i].indir_cq);
@@ -10637,14 +10655,11 @@ flow_hw_configure(struct rte_eth_dev *dev,mlx5_ipool_destroy (priv->acts_ipool); priv->acts_ipool =NULL ; } -if (_queue_attr) -mlx5_free (_queue_attr); -if (priv->shared_host) { -__atomic_fetch_sub (&host_priv->shared_refcnt,1 , __ATOMIC_RELAXED); - priv->shared_host =NULL ; - }mlx5_free (priv->hw_attr); priv->hw_attr =NULL ; + priv->nb_queue =0 ; +if (_queue_attr) +mlx5_free (_queue_attr);/* Do not overwrite the internal errno information. */ if (ret)return ret;
@@ -10677,7 +10692,7 @@ flow_hw_resource_release(struct rte_eth_dev *dev)flow_hw_cleanup_ctrl_fdb_tables (dev);flow_hw_cleanup_tx_repr_tagging (dev);flow_hw_cleanup_ctrl_rx_tables (dev); -action_template_drop_release (dev); +flow_hw_action_template_drop_release (dev);while (!LIST_EMPTY (&priv->flow_hw_grp)) { grp =LIST_FIRST (&priv->flow_hw_grp);flow_hw_group_unset_miss_group (dev, grp,NULL );
Signature · 1 line
2.39.2
PATCH 4/4 net/mlx5: fix flow configure validation
In reply to Dariusz SosnowskiThere's an existing limitation in mlx5 PMD, that all configured flow queues must have the same size. Even though this condition is checked, some allocations are done before that. This lead to segmentation fault during rollback on error in rte_flow_configure() implementation.
This patch fixes that by reorganizing validation, so that configuration options are validated before any allocations are done and necessary checks for NULL are added to error rollback.
Bugzilla ID: 1199
--- drivers/net/mlx5/mlx5_flow_hw.c | 62 +++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 19 deletions(-)
drivers/net/mlx5/mlx5_flow_hw.c +43 -19
@@ -10253,6 +10253,38 @@ mlx5_hwq_ring_create(uint16_t port_id, uint32_t queue, uint32_t size, const char RING_F_SP_ENQ | RING_F_SC_DEQ | RING_F_EXACT_SZ); } +static int +flow_hw_validate_attributes (const struct rte_flow_port_attr *port_attr, +uint16_t nb_queue, +const struct rte_flow_queue_attr *queue_attr[], +struct rte_flow_error *error) +{ +uint32_t size; +unsigned int i; + +if (port_attr ==NULL ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL , +"Port attributes must be non-NULL" ); + +if (nb_queue ==0 ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL , +"At least one flow queue is required" ); + +if (queue_attr ==NULL ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL , +"Queue attributes must be non-NULL" ); + + size = queue_attr[0 ]->size; +for (i =1 ; i < nb_queue; ++i) { +if (queue_attr[i]->size != size) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL , +"All flow queues must have the same size" ); + } + +return 0 ; +} +/** * Configure port HWS resources. *
@@ -10304,10 +10336,8 @@ flow_hw_configure(struct rte_eth_dev *dev,int ret =0 ;uint32_t action_flags; -if (!port_attr || !nb_queue || !queue_attr) { - rte_errno =EINVAL ; - goto err; - } +if (flow_hw_validate_attributes (port_attr, nb_queue, queue_attr, error)) +return -rte_errno;/* * Calling rte_flow_configure() again is allowed if and only if * provided configuration matches the initially provided one.
@@ -10354,14 +10384,6 @@ flow_hw_configure(struct rte_eth_dev *dev,/* Allocate the queue job descriptor LIFO. */ mem_size =sizeof (priv->hw_q[0 ]) * nb_q_updated;for (i =0 ; i < nb_q_updated; i++) { -/* -* Check if the queues' size are all the same as the -* limitation from HWS layer. -*/ -if (_queue_attr[i]->size != _queue_attr[0 ]->size) { - rte_errno =EINVAL ; - goto err; - } mem_size += (sizeof (struct mlx5_hw_q_job *) +sizeof (struct mlx5_hw_q_job )) * _queue_attr[i]->size; }
@@ -10643,14 +10665,16 @@ flow_hw_configure(struct rte_eth_dev *dev,__atomic_fetch_sub (&host_priv->shared_refcnt,1 , __ATOMIC_RELAXED); priv->shared_host =NULL ; } -for (i =0 ; i < nb_q_updated; i++) { -rte_ring_free (priv->hw_q[i].indir_iq); -rte_ring_free (priv->hw_q[i].indir_cq); -rte_ring_free (priv->hw_q[i].flow_transfer_pending); -rte_ring_free (priv->hw_q[i].flow_transfer_completed); +if (priv->hw_q) { +for (i =0 ; i < nb_q_updated; i++) { +rte_ring_free (priv->hw_q[i].indir_iq); +rte_ring_free (priv->hw_q[i].indir_cq); +rte_ring_free (priv->hw_q[i].flow_transfer_pending); +rte_ring_free (priv->hw_q[i].flow_transfer_completed); + } +mlx5_free (priv->hw_q); + priv->hw_q =NULL ; } -mlx5_free (priv->hw_q); - priv->hw_q =NULL ;if (priv->acts_ipool) {mlx5_ipool_destroy (priv->acts_ipool); priv->acts_ipool =NULL ;
Signature · 1 line
2.39.2
Hi,
Quoted 15 lines
-----Original Message-----
From: Dariusz Sosnowski <[email protected]>
Sent: Wednesday, March 6, 2024 10:22 PM
To: Slava Ovsiienko <[email protected]>; Ori Kam <[email protected]>; Suanming Mou <[email protected]>; Matan Azrad <[email protected]>; Yevgeny Kliteynik <[email protected]>
Cc: [email protected]; Alex Vesker <[email protected]>; [email protected]
Subject: [PATCH 1/4]net/mlx5/hws: fix direct index insert on dep wqeFrom: Alex Vesker <[email protected]>
In case a depend WQE was required and direct index was needed we would not set the direct index on the
dep_wqe.
This leads to incorrect insertion to index zero.
Quoted 6 lines
Fixes 38b5bf6452a6 ("net/mlx5/hws: support insert/distribute RTCproperties")
Cc: [email protected]Signed-off-by Alex Vesker <[email protected]>
Series applied to next-net-mlx,
Kindest regards
Raslan Darawsheh