Commit cff99e20 authored by Petr Machata's avatar Petr Machata Committed by David S. Miller

mlxsw: spectrum_qdisc: Guard all qdisc accesses with a lock

The FIFO handler currently guards accesses to the future FIFO tracking by
asserting RTNL. In the future, the changes to the qdisc state will be more
thorough, so other qdiscs will need this guarding is as well. In order
to not further the RTNL infestation, instead convert to a custom lock that
will guard accesses to the qdisc state.
Signed-off-by: default avatarPetr Machata <petrm@nvidia.com>
Reviewed-by: default avatarIdo Schimmel <idosch@nvidia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 51d52ed9
...@@ -89,6 +89,7 @@ struct mlxsw_sp_qdisc_state { ...@@ -89,6 +89,7 @@ struct mlxsw_sp_qdisc_state {
*/ */
u32 future_handle; u32 future_handle;
bool future_fifos[IEEE_8021QAZ_MAX_TCS]; bool future_fifos[IEEE_8021QAZ_MAX_TCS];
struct mutex lock; /* Protects qdisc state. */
}; };
static bool static bool
...@@ -620,8 +621,8 @@ static struct mlxsw_sp_qdisc_ops mlxsw_sp_qdisc_ops_red = { ...@@ -620,8 +621,8 @@ static struct mlxsw_sp_qdisc_ops mlxsw_sp_qdisc_ops_red = {
.find_class = mlxsw_sp_qdisc_leaf_find_class, .find_class = mlxsw_sp_qdisc_leaf_find_class,
}; };
int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port, static int __mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port,
struct tc_red_qopt_offload *p) struct tc_red_qopt_offload *p)
{ {
struct mlxsw_sp_qdisc *mlxsw_sp_qdisc; struct mlxsw_sp_qdisc *mlxsw_sp_qdisc;
...@@ -652,6 +653,18 @@ int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -652,6 +653,18 @@ int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port,
} }
} }
int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port,
struct tc_red_qopt_offload *p)
{
int err;
mutex_lock(&mlxsw_sp_port->qdisc->lock);
err = __mlxsw_sp_setup_tc_red(mlxsw_sp_port, p);
mutex_unlock(&mlxsw_sp_port->qdisc->lock);
return err;
}
static void static void
mlxsw_sp_setup_tc_qdisc_leaf_clean_stats(struct mlxsw_sp_port *mlxsw_sp_port, mlxsw_sp_setup_tc_qdisc_leaf_clean_stats(struct mlxsw_sp_port *mlxsw_sp_port,
struct mlxsw_sp_qdisc *mlxsw_sp_qdisc) struct mlxsw_sp_qdisc *mlxsw_sp_qdisc)
...@@ -814,8 +827,8 @@ static struct mlxsw_sp_qdisc_ops mlxsw_sp_qdisc_ops_tbf = { ...@@ -814,8 +827,8 @@ static struct mlxsw_sp_qdisc_ops mlxsw_sp_qdisc_ops_tbf = {
.find_class = mlxsw_sp_qdisc_leaf_find_class, .find_class = mlxsw_sp_qdisc_leaf_find_class,
}; };
int mlxsw_sp_setup_tc_tbf(struct mlxsw_sp_port *mlxsw_sp_port, static int __mlxsw_sp_setup_tc_tbf(struct mlxsw_sp_port *mlxsw_sp_port,
struct tc_tbf_qopt_offload *p) struct tc_tbf_qopt_offload *p)
{ {
struct mlxsw_sp_qdisc *mlxsw_sp_qdisc; struct mlxsw_sp_qdisc *mlxsw_sp_qdisc;
...@@ -843,6 +856,18 @@ int mlxsw_sp_setup_tc_tbf(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -843,6 +856,18 @@ int mlxsw_sp_setup_tc_tbf(struct mlxsw_sp_port *mlxsw_sp_port,
} }
} }
int mlxsw_sp_setup_tc_tbf(struct mlxsw_sp_port *mlxsw_sp_port,
struct tc_tbf_qopt_offload *p)
{
int err;
mutex_lock(&mlxsw_sp_port->qdisc->lock);
err = __mlxsw_sp_setup_tc_tbf(mlxsw_sp_port, p);
mutex_unlock(&mlxsw_sp_port->qdisc->lock);
return err;
}
static int static int
mlxsw_sp_qdisc_fifo_check_params(struct mlxsw_sp_port *mlxsw_sp_port, mlxsw_sp_qdisc_fifo_check_params(struct mlxsw_sp_port *mlxsw_sp_port,
void *params) void *params)
...@@ -876,20 +901,14 @@ static struct mlxsw_sp_qdisc_ops mlxsw_sp_qdisc_ops_fifo = { ...@@ -876,20 +901,14 @@ static struct mlxsw_sp_qdisc_ops mlxsw_sp_qdisc_ops_fifo = {
.clean_stats = mlxsw_sp_setup_tc_qdisc_leaf_clean_stats, .clean_stats = mlxsw_sp_setup_tc_qdisc_leaf_clean_stats,
}; };
int mlxsw_sp_setup_tc_fifo(struct mlxsw_sp_port *mlxsw_sp_port, static int __mlxsw_sp_setup_tc_fifo(struct mlxsw_sp_port *mlxsw_sp_port,
struct tc_fifo_qopt_offload *p) struct tc_fifo_qopt_offload *p)
{ {
struct mlxsw_sp_qdisc_state *qdisc_state = mlxsw_sp_port->qdisc; struct mlxsw_sp_qdisc_state *qdisc_state = mlxsw_sp_port->qdisc;
struct mlxsw_sp_qdisc *mlxsw_sp_qdisc; struct mlxsw_sp_qdisc *mlxsw_sp_qdisc;
int tclass, child_index; int tclass, child_index;
u32 parent_handle; u32 parent_handle;
/* Invisible FIFOs are tracked in future_handle and future_fifos. Make
* sure that not more than one qdisc is created for a port at a time.
* RTNL is a simple proxy for that.
*/
ASSERT_RTNL();
mlxsw_sp_qdisc = mlxsw_sp_qdisc_find(mlxsw_sp_port, p->parent, false); mlxsw_sp_qdisc = mlxsw_sp_qdisc_find(mlxsw_sp_port, p->parent, false);
if (!mlxsw_sp_qdisc && p->handle == TC_H_UNSPEC) { if (!mlxsw_sp_qdisc && p->handle == TC_H_UNSPEC) {
parent_handle = TC_H_MAJ(p->parent); parent_handle = TC_H_MAJ(p->parent);
...@@ -936,6 +955,18 @@ int mlxsw_sp_setup_tc_fifo(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -936,6 +955,18 @@ int mlxsw_sp_setup_tc_fifo(struct mlxsw_sp_port *mlxsw_sp_port,
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
int mlxsw_sp_setup_tc_fifo(struct mlxsw_sp_port *mlxsw_sp_port,
struct tc_fifo_qopt_offload *p)
{
int err;
mutex_lock(&mlxsw_sp_port->qdisc->lock);
err = __mlxsw_sp_setup_tc_fifo(mlxsw_sp_port, p);
mutex_unlock(&mlxsw_sp_port->qdisc->lock);
return err;
}
static int __mlxsw_sp_qdisc_ets_destroy(struct mlxsw_sp_port *mlxsw_sp_port, static int __mlxsw_sp_qdisc_ets_destroy(struct mlxsw_sp_port *mlxsw_sp_port,
struct mlxsw_sp_qdisc *mlxsw_sp_qdisc) struct mlxsw_sp_qdisc *mlxsw_sp_qdisc)
{ {
...@@ -1277,8 +1308,8 @@ mlxsw_sp_qdisc_prio_graft(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -1277,8 +1308,8 @@ mlxsw_sp_qdisc_prio_graft(struct mlxsw_sp_port *mlxsw_sp_port,
p->band, p->child_handle); p->band, p->child_handle);
} }
int mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port, static int __mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port,
struct tc_prio_qopt_offload *p) struct tc_prio_qopt_offload *p)
{ {
struct mlxsw_sp_qdisc *mlxsw_sp_qdisc; struct mlxsw_sp_qdisc *mlxsw_sp_qdisc;
...@@ -1309,8 +1340,20 @@ int mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -1309,8 +1340,20 @@ int mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port,
} }
} }
int mlxsw_sp_setup_tc_ets(struct mlxsw_sp_port *mlxsw_sp_port, int mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port,
struct tc_ets_qopt_offload *p) struct tc_prio_qopt_offload *p)
{
int err;
mutex_lock(&mlxsw_sp_port->qdisc->lock);
err = __mlxsw_sp_setup_tc_prio(mlxsw_sp_port, p);
mutex_unlock(&mlxsw_sp_port->qdisc->lock);
return err;
}
static int __mlxsw_sp_setup_tc_ets(struct mlxsw_sp_port *mlxsw_sp_port,
struct tc_ets_qopt_offload *p)
{ {
struct mlxsw_sp_qdisc *mlxsw_sp_qdisc; struct mlxsw_sp_qdisc *mlxsw_sp_qdisc;
...@@ -1342,6 +1385,18 @@ int mlxsw_sp_setup_tc_ets(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -1342,6 +1385,18 @@ int mlxsw_sp_setup_tc_ets(struct mlxsw_sp_port *mlxsw_sp_port,
} }
} }
int mlxsw_sp_setup_tc_ets(struct mlxsw_sp_port *mlxsw_sp_port,
struct tc_ets_qopt_offload *p)
{
int err;
mutex_lock(&mlxsw_sp_port->qdisc->lock);
err = __mlxsw_sp_setup_tc_ets(mlxsw_sp_port, p);
mutex_unlock(&mlxsw_sp_port->qdisc->lock);
return err;
}
struct mlxsw_sp_qevent_block { struct mlxsw_sp_qevent_block {
struct list_head binding_list; struct list_head binding_list;
struct list_head mall_entry_list; struct list_head mall_entry_list;
...@@ -1877,6 +1932,7 @@ int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port) ...@@ -1877,6 +1932,7 @@ int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port)
if (!qdisc_state) if (!qdisc_state)
return -ENOMEM; return -ENOMEM;
mutex_init(&qdisc_state->lock);
qdisc_state->root_qdisc.prio_bitmap = 0xff; qdisc_state->root_qdisc.prio_bitmap = 0xff;
qdisc_state->root_qdisc.tclass_num = MLXSW_SP_PORT_DEFAULT_TCLASS; qdisc_state->root_qdisc.tclass_num = MLXSW_SP_PORT_DEFAULT_TCLASS;
qdisc_state->root_qdisc.qdiscs = qdisc_state->tclass_qdiscs; qdisc_state->root_qdisc.qdiscs = qdisc_state->tclass_qdiscs;
...@@ -1894,5 +1950,6 @@ int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port) ...@@ -1894,5 +1950,6 @@ int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port)
void mlxsw_sp_tc_qdisc_fini(struct mlxsw_sp_port *mlxsw_sp_port) void mlxsw_sp_tc_qdisc_fini(struct mlxsw_sp_port *mlxsw_sp_port)
{ {
mutex_destroy(&mlxsw_sp_port->qdisc->lock);
kfree(mlxsw_sp_port->qdisc); kfree(mlxsw_sp_port->qdisc);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment