From: Ido Schimmel <idosch@idosch.org>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, jiri@mellanox.com,
mlxsw@mellanox.com, Ido Schimmel <idosch@mellanox.com>
Subject: [PATCH net-next 6/9] mlxsw: spectrum_cnt: Move config validation along with resource register
Date: Wed, 18 Mar 2020 15:48:54 +0200 [thread overview]
Message-ID: <20200318134857.1003018-7-idosch@idosch.org> (raw)
In-Reply-To: <20200318134857.1003018-1-idosch@idosch.org>
From: Jiri Pirko <jiri@mellanox.com>
Move the validation of subpools configuration, to avoid possible over
commitment to resource registration. Add WARN_ON to indicate bug
in the code.
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
---
.../ethernet/mellanox/mlxsw/spectrum_cnt.c | 31 +++++--------------
1 file changed, 8 insertions(+), 23 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c
index 629355cf52a9..d36904143b10 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c
@@ -40,24 +40,6 @@ static const struct mlxsw_sp_counter_sub_pool mlxsw_sp_counter_sub_pools[] = {
}
};
-static int mlxsw_sp_counter_pool_validate(struct mlxsw_sp *mlxsw_sp)
-{
- struct mlxsw_sp_counter_pool *pool = mlxsw_sp->counter_pool;
- unsigned int total_bank_config = 0;
- unsigned int pool_size;
- unsigned int bank_size;
- int i;
-
- pool_size = MLXSW_CORE_RES_GET(mlxsw_sp->core, COUNTER_POOL_SIZE);
- bank_size = MLXSW_CORE_RES_GET(mlxsw_sp->core, COUNTER_BANK_SIZE);
- /* Check config is valid, no bank over subscription */
- for (i = 0; i < pool->sub_pools_count; i++)
- total_bank_config += pool->sub_pools[i].bank_count;
- if (total_bank_config > pool_size / bank_size + 1)
- return -EINVAL;
- return 0;
-}
-
static int mlxsw_sp_counter_sub_pools_prepare(struct mlxsw_sp *mlxsw_sp)
{
struct mlxsw_sp_counter_pool *pool = mlxsw_sp->counter_pool;
@@ -98,10 +80,6 @@ int mlxsw_sp_counter_pool_init(struct mlxsw_sp *mlxsw_sp)
pool->sub_pools_count = sub_pools_count;
spin_lock_init(&pool->counter_pool_lock);
- err = mlxsw_sp_counter_pool_validate(mlxsw_sp);
- if (err)
- goto err_pool_validate;
-
err = mlxsw_sp_counter_sub_pools_prepare(mlxsw_sp);
if (err)
goto err_sub_pools_prepare;
@@ -140,7 +118,6 @@ int mlxsw_sp_counter_pool_init(struct mlxsw_sp *mlxsw_sp)
err_usage_alloc:
err_pool_resource_size_get:
err_sub_pools_prepare:
-err_pool_validate:
kfree(pool);
return err;
}
@@ -216,6 +193,7 @@ int mlxsw_sp_counter_resources_register(struct mlxsw_core *mlxsw_core)
static struct devlink_resource_size_params size_params;
struct devlink *devlink = priv_to_devlink(mlxsw_core);
const struct mlxsw_sp_counter_sub_pool *sub_pool;
+ unsigned int total_bank_config;
u64 sub_pool_size;
u64 base_index;
u64 pool_size;
@@ -245,6 +223,7 @@ int mlxsw_sp_counter_resources_register(struct mlxsw_core *mlxsw_core)
/* Allocation is based on bank count which should be
* specified for each sub pool statically.
*/
+ total_bank_config = 0;
base_index = 0;
for (i = 0; i < ARRAY_SIZE(mlxsw_sp_counter_sub_pools); i++) {
sub_pool = &mlxsw_sp_counter_sub_pools[i];
@@ -265,6 +244,12 @@ int mlxsw_sp_counter_resources_register(struct mlxsw_core *mlxsw_core)
&size_params);
if (err)
return err;
+ total_bank_config += sub_pool->bank_count;
}
+
+ /* Check config is valid, no bank over subscription */
+ if (WARN_ON(total_bank_config > pool_size / bank_size + 1))
+ return -EINVAL;
+
return 0;
}
--
2.24.1
next prev parent reply other threads:[~2020-03-18 13:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-18 13:48 [PATCH net-next 0/9] mlxsw: spectrum_cnt: Expose counter resources Ido Schimmel
2020-03-18 13:48 ` [PATCH net-next 1/9] mlxsw: spectrum_cnt: Query bank size from FW resources Ido Schimmel
2020-03-18 13:48 ` [PATCH net-next 2/9] selftests: spectrum-2: Adjust tc_flower_scale limit according to current counter count Ido Schimmel
2020-03-18 13:48 ` [PATCH net-next 3/9] mlxsw: spectrum_cnt: Move sub_pools under per-instance pool struct Ido Schimmel
2020-03-18 13:48 ` [PATCH net-next 4/9] mlxsw: spectrum_cnt: Add entry_size_res_id for each subpool and use it to query entry size Ido Schimmel
2020-03-18 13:48 ` [PATCH net-next 5/9] mlxsw: spectrum_cnt: Expose subpool sizes over devlink resources Ido Schimmel
2020-03-18 13:48 ` Ido Schimmel [this message]
2020-03-18 13:48 ` [PATCH net-next 7/9] mlxsw: spectrum_cnt: Consolidate subpools initialization Ido Schimmel
2020-03-18 13:48 ` [PATCH net-next 8/9] mlxsw: spectrum_cnt: Expose devlink resource occupancy for counters Ido Schimmel
2020-03-18 13:48 ` [PATCH net-next 9/9] selftests: mlxsw: Add tc action hw_stats tests Ido Schimmel
2020-03-18 20:50 ` [PATCH net-next 0/9] mlxsw: spectrum_cnt: Expose counter resources Jakub Kicinski
2020-03-18 23:46 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200318134857.1003018-7-idosch@idosch.org \
--to=idosch@idosch.org \
--cc=davem@davemloft.net \
--cc=idosch@mellanox.com \
--cc=jiri@mellanox.com \
--cc=kuba@kernel.org \
--cc=mlxsw@mellanox.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).