Skip to content

Commit

Permalink
net/mlx5: fix port shared data reference count
Browse files Browse the repository at this point in the history
[ upstream commit 16dbba2 ]

When probe a representor, tag cache hash table and modification cache
hash table allocated memory upon each port, overwrote previous existing
cache in shared context data.

This patch moves reference check of shared data prior to hash table
allocation to avoid such issue.

Fixes: 6801116 ("net/mlx5: fix multiple flow table hash list")
Fixes: 1ef4cde ("net/mlx5: fix flow tag hash list conversion")

Acked-by: Matan Azrad <matan@nvidia.com>
Signed-off-by: Xueming Li <xuemingl@nvidia.com>
  • Loading branch information
steevenlee authored and bluca committed Nov 9, 2020
1 parent d0f1f4b commit 54a9785
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
30 changes: 8 additions & 22 deletions drivers/net/mlx5/mlx5.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,13 +951,12 @@ mlx5_alloc_shared_dr(struct mlx5_priv *priv)
{
struct mlx5_ibv_shared *sh = priv->sh;
char s[MLX5_HLIST_NAMESIZE];
int err = 0;
int err;

if (!sh->flow_tbls)
err = mlx5_alloc_table_hash_list(priv);
else
DRV_LOG(DEBUG, "sh->flow_tbls[%p] already created, reuse",
(void *)sh->flow_tbls);
assert(sh && sh->refcnt);
if (sh->refcnt > 1)
return 0;
err = mlx5_alloc_table_hash_list(priv);
if (err)
return err;
/* Create tags hash list table. */
Expand All @@ -971,12 +970,6 @@ mlx5_alloc_shared_dr(struct mlx5_priv *priv)
#ifdef HAVE_MLX5DV_DR
void *domain;

if (sh->dv_refcnt) {
/* Shared DV/DR structures is already initialized. */
sh->dv_refcnt++;
priv->dr_shared = 1;
return 0;
}
/* Reference counter is zero, we should initialize structures. */
domain = mlx5_glue->dr_create_domain(sh->ctx,
MLX5DV_DR_DOMAIN_TYPE_NIC_RX);
Expand Down Expand Up @@ -1010,8 +1003,6 @@ mlx5_alloc_shared_dr(struct mlx5_priv *priv)
#endif
sh->pop_vlan_action = mlx5_glue->dr_create_flow_action_pop_vlan();
#endif /* HAVE_MLX5DV_DR */
sh->dv_refcnt++;
priv->dr_shared = 1;
return 0;
error:
/* Rollback the created objects. */
Expand Down Expand Up @@ -1053,17 +1044,12 @@ mlx5_alloc_shared_dr(struct mlx5_priv *priv)
static void
mlx5_free_shared_dr(struct mlx5_priv *priv)
{
struct mlx5_ibv_shared *sh;
struct mlx5_ibv_shared *sh = priv->sh;

if (!priv->dr_shared)
assert(sh && sh->dv_refcnt);
if (sh->refcnt > 1)
return;
priv->dr_shared = 0;
sh = priv->sh;
assert(sh);
#ifdef HAVE_MLX5DV_DR
assert(sh->dv_refcnt);
if (sh->dv_refcnt && --sh->dv_refcnt)
return;
if (sh->rx_domain) {
mlx5_glue->dr_destroy_domain(sh->rx_domain);
sh->rx_domain = NULL;
Expand Down
2 changes: 0 additions & 2 deletions drivers/net/mlx5/mlx5.h
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,6 @@ struct mlx5_ibv_shared {
uint32_t dv_meta_mask; /* flow META metadata supported mask. */
uint32_t dv_mark_mask; /* flow MARK metadata supported mask. */
uint32_t dv_regc0_mask; /* available bits of metatada reg_c[0]. */
uint32_t dv_refcnt; /* DV/DR data reference counter. */
void *fdb_domain; /* FDB Direct Rules name space handle. */
void *rx_domain; /* RX Direct Rules name space handle. */
void *tx_domain; /* TX Direct Rules name space handle. */
Expand Down Expand Up @@ -731,7 +730,6 @@ struct mlx5_priv {
unsigned int isolated:1; /* Whether isolated mode is enabled. */
unsigned int representor:1; /* Device is a port representor. */
unsigned int master:1; /* Device is a E-Switch master. */
unsigned int dr_shared:1; /* DV/DR data is shared. */
unsigned int counter_fallback:1; /* Use counter fallback management. */
unsigned int mtr_en:1; /* Whether support meter. */
unsigned int mtr_reg_share:1; /* Whether support meter REG_C share. */
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/mlx5/mlx5_flow_dv.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ flow_dv_shared_lock(struct rte_eth_dev *dev)
struct mlx5_priv *priv = dev->data->dev_private;
struct mlx5_ibv_shared *sh = priv->sh;

if (sh->dv_refcnt > 1) {
if (sh->refcnt > 1) {
int ret;

ret = pthread_mutex_lock(&sh->dv_mutex);
Expand All @@ -295,7 +295,7 @@ flow_dv_shared_unlock(struct rte_eth_dev *dev)
struct mlx5_priv *priv = dev->data->dev_private;
struct mlx5_ibv_shared *sh = priv->sh;

if (sh->dv_refcnt > 1) {
if (sh->refcnt > 1) {
int ret;

ret = pthread_mutex_unlock(&sh->dv_mutex);
Expand Down

0 comments on commit 54a9785

Please sign in to comment.