Skip to content

Commit

Permalink
net/mlx5e: CT: Add ct driver counters
Browse files Browse the repository at this point in the history
Connection offload is translated to multiple rules over several
hardware flow tables. Unhandled end-cases may cause a hardware
resource leak causing multiple system symptoms such as a host
memory leak, decreased performance and other scale related issues.

Export the current number of firmware FTEs related to the CT table
as a debugfs counter. Also add a dropped packets counter to help
debug packets dropped on restore failure.

To show the offloaded count:
cat /sys/kernel/debug/mlx5/<PCI>/ct_nic/offloaded

To show the dropped count:
cat /sys/kernel/debug/mlx5/<PCI>/ct_nic/rx_dropped

Signed-off-by: Paul Blakey <paulb@mellanox.com>
Signed-off-by: Roi Dayan <paulb@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
Reviewed-by: Oz Shlomo <ozsh@nvidia.com>
Reviewed-by: Paul Blakey <paulb@nvidia.com>
  • Loading branch information
Saeed Mahameed committed May 18, 2022
1 parent f05ec8d commit 77422a8
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <linux/refcount.h>
#include <linux/xarray.h>
#include <linux/if_macvlan.h>
#include <linux/debugfs.h>

#include "lib/fs_chains.h"
#include "en/tc_ct.h"
Expand Down Expand Up @@ -47,6 +48,15 @@
#define ct_dbg(fmt, args...)\
netdev_dbg(ct_priv->netdev, "ct_debug: " fmt "\n", ##args)

struct mlx5_tc_ct_debugfs {
struct {
atomic_t offloaded;
atomic_t rx_dropped;
} stats;

struct dentry *root;
};

struct mlx5_tc_ct_priv {
struct mlx5_core_dev *dev;
const struct net_device *netdev;
Expand All @@ -66,6 +76,8 @@ struct mlx5_tc_ct_priv {
struct mlx5_ct_fs *fs;
struct mlx5_ct_fs_ops *fs_ops;
spinlock_t ht_lock; /* protects ft entries */

struct mlx5_tc_ct_debugfs debugfs;
};

struct mlx5_ct_flow {
Expand Down Expand Up @@ -520,6 +532,8 @@ mlx5_tc_ct_entry_del_rules(struct mlx5_tc_ct_priv *ct_priv,
{
mlx5_tc_ct_entry_del_rule(ct_priv, entry, true);
mlx5_tc_ct_entry_del_rule(ct_priv, entry, false);

atomic_dec(&ct_priv->debugfs.stats.offloaded);
}

static struct flow_action_entry *
Expand Down Expand Up @@ -1040,6 +1054,7 @@ mlx5_tc_ct_entry_add_rules(struct mlx5_tc_ct_priv *ct_priv,
if (err)
goto err_nat;

atomic_inc(&ct_priv->debugfs.stats.offloaded);
return 0;

err_nat:
Expand Down Expand Up @@ -2064,6 +2079,29 @@ mlx5_tc_ct_init_check_support(struct mlx5e_priv *priv,
return err;
}

static void
mlx5_ct_tc_create_dbgfs(struct mlx5_tc_ct_priv *ct_priv)
{
bool is_fdb = ct_priv->ns_type == MLX5_FLOW_NAMESPACE_FDB;
struct mlx5_tc_ct_debugfs *ct_dbgfs = &ct_priv->debugfs;
char dirname[16] = {};

if (sscanf(dirname, "ct_%s", is_fdb ? "fdb" : "nic") < 0)
return;

ct_dbgfs->root = debugfs_create_dir(dirname, mlx5_debugfs_get_dev_root(ct_priv->dev));
debugfs_create_atomic_t("offloaded", 0400, ct_dbgfs->root,
&ct_dbgfs->stats.offloaded);
debugfs_create_atomic_t("rx_dropped", 0400, ct_dbgfs->root,
&ct_dbgfs->stats.rx_dropped);
}

static void
mlx5_ct_tc_remove_dbgfs(struct mlx5_tc_ct_priv *ct_priv)
{
debugfs_remove_recursive(ct_priv->debugfs.root);
}

#define INIT_ERR_PREFIX "tc ct offload init failed"

struct mlx5_tc_ct_priv *
Expand Down Expand Up @@ -2139,6 +2177,7 @@ mlx5_tc_ct_init(struct mlx5e_priv *priv, struct mlx5_fs_chains *chains,
if (err)
goto err_init_fs;

mlx5_ct_tc_create_dbgfs(ct_priv);
return ct_priv;

err_init_fs:
Expand Down Expand Up @@ -2171,6 +2210,7 @@ mlx5_tc_ct_clean(struct mlx5_tc_ct_priv *ct_priv)
if (!ct_priv)
return;

mlx5_ct_tc_remove_dbgfs(ct_priv);
chains = ct_priv->chains;

ct_priv->fs_ops->destroy(ct_priv->fs);
Expand Down Expand Up @@ -2200,27 +2240,31 @@ mlx5e_tc_ct_restore_flow(struct mlx5_tc_ct_priv *ct_priv,
return true;

if (mapping_find(ct_priv->zone_mapping, zone_restore_id, &zone))
return false;
goto out_inc_drop;

if (!mlx5_tc_ct_skb_to_tuple(skb, &tuple, zone))
return false;
goto out_inc_drop;

spin_lock(&ct_priv->ht_lock);

entry = mlx5_tc_ct_entry_get(ct_priv, &tuple);
if (!entry) {
spin_unlock(&ct_priv->ht_lock);
return false;
goto out_inc_drop;
}

if (IS_ERR(entry)) {
spin_unlock(&ct_priv->ht_lock);
return false;
goto out_inc_drop;
}
spin_unlock(&ct_priv->ht_lock);

tcf_ct_flow_table_restore_skb(skb, entry->restore_cookie);
__mlx5_tc_ct_entry_put(entry);

return true;

out_inc_drop:
atomic_inc(&ct_priv->debugfs.stats.rx_dropped);
return false;
}

0 comments on commit 77422a8

Please sign in to comment.