Skip to content

Commit

Permalink
Merge branch 'net-sched-act_api-contiguous-action-arrays'
Browse files Browse the repository at this point in the history
Pedro Tammela says:

====================
net/sched: act_api: contiguous action arrays

When dealing with action arrays in act_api it's natural to ask if they
are always contiguous (no NULL pointers in between). Yes, they are in
all cases so far, so make use of the already present tcf_act_for_each_action
macro to explicitly document this assumption.

There was an instance where it was not, but it was refactorable (patch 2)
to make the array contiguous.

v1->v2:
- Respin
- Added Jamal's acked-by
====================

Link: https://lore.kernel.org/r/20231201175015.214214-1-pctammela@mojatatu.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
  • Loading branch information
Paolo Abeni committed Dec 5, 2023
2 parents 030033d + f9bfc8e commit 4aee43f
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions net/sched/act_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1118,8 +1118,7 @@ int tcf_action_destroy(struct tc_action *actions[], int bind)
struct tc_action *a;
int ret = 0, i;

for (i = 0; i < TCA_ACT_MAX_PRIO && actions[i]; i++) {
a = actions[i];
tcf_act_for_each_action(i, a, actions) {
actions[i] = NULL;
ops = a->ops;
ret = __tcf_idr_release(a, bind, true);
Expand All @@ -1136,18 +1135,29 @@ static int tcf_action_put(struct tc_action *p)
return __tcf_action_put(p, false);
}

/* Put all actions in this array, skip those NULL's. */
static void tcf_action_put_many(struct tc_action *actions[])
{
struct tc_action *a;
int i;

tcf_act_for_each_action(i, a, actions) {
const struct tc_action_ops *ops = a->ops;
if (tcf_action_put(a))
module_put(ops->owner);
}
}

static void tca_put_bound_many(struct tc_action *actions[], int init_res[])
{
struct tc_action *a;
int i;

for (i = 0; i < TCA_ACT_MAX_PRIO; i++) {
struct tc_action *a = actions[i];
const struct tc_action_ops *ops;
tcf_act_for_each_action(i, a, actions) {
const struct tc_action_ops *ops = a->ops;

if (!a)
if (init_res[i] == ACT_P_CREATED)
continue;
ops = a->ops;

if (tcf_action_put(a))
module_put(ops->owner);
}
Expand Down Expand Up @@ -1211,8 +1221,7 @@ int tcf_action_dump(struct sk_buff *skb, struct tc_action *actions[],
int err = -EINVAL, i;
struct nlattr *nest;

for (i = 0; i < TCA_ACT_MAX_PRIO && actions[i]; i++) {
a = actions[i];
tcf_act_for_each_action(i, a, actions) {
nest = nla_nest_start_noflag(skb, i + 1);
if (nest == NULL)
goto nla_put_failure;
Expand Down Expand Up @@ -1276,14 +1285,12 @@ static const struct nla_policy tcf_action_policy[TCA_ACT_MAX + 1] = {

void tcf_idr_insert_many(struct tc_action *actions[])
{
struct tc_action *a;
int i;

for (i = 0; i < TCA_ACT_MAX_PRIO; i++) {
struct tc_action *a = actions[i];
tcf_act_for_each_action(i, a, actions) {
struct tcf_idrinfo *idrinfo;

if (!a)
continue;
idrinfo = a->idrinfo;
mutex_lock(&idrinfo->lock);
/* Replace ERR_PTR(-EBUSY) allocated by tcf_idr_check_alloc if
Expand Down Expand Up @@ -1497,10 +1504,8 @@ int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla,
err:
tcf_action_destroy(actions, flags & TCA_ACT_FLAGS_BIND);
err_mod:
for (i = 0; i < TCA_ACT_MAX_PRIO; i++) {
if (ops[i])
module_put(ops[i]->owner);
}
for (i = 0; i < TCA_ACT_MAX_PRIO && ops[i]; i++)
module_put(ops[i]->owner);
return err;
}

Expand Down Expand Up @@ -1753,10 +1758,10 @@ static int tca_action_flush(struct net *net, struct nlattr *nla,

static int tcf_action_delete(struct net *net, struct tc_action *actions[])
{
struct tc_action *a;
int i;

for (i = 0; i < TCA_ACT_MAX_PRIO && actions[i]; i++) {
struct tc_action *a = actions[i];
tcf_act_for_each_action(i, a, actions) {
const struct tc_action_ops *ops = a->ops;
/* Actions can be deleted concurrently so we must save their
* type and id to search again after reference is released.
Expand All @@ -1768,7 +1773,7 @@ static int tcf_action_delete(struct net *net, struct tc_action *actions[])
if (tcf_action_put(a)) {
/* last reference, action was deleted concurrently */
module_put(ops->owner);
} else {
} else {
int ret;

/* now do the delete */
Expand Down Expand Up @@ -1977,7 +1982,7 @@ static int tcf_action_add(struct net *net, struct nlattr *nla,
struct netlink_ext_ack *extack)
{
size_t attr_size = 0;
int loop, ret, i;
int loop, ret;
struct tc_action *actions[TCA_ACT_MAX_PRIO] = {};
int init_res[TCA_ACT_MAX_PRIO] = {};

Expand All @@ -1990,13 +1995,11 @@ static int tcf_action_add(struct net *net, struct nlattr *nla,

if (ret < 0)
return ret;

ret = tcf_add_notify(net, n, actions, portid, attr_size, extack);

/* only put existing actions */
for (i = 0; i < TCA_ACT_MAX_PRIO; i++)
if (init_res[i] == ACT_P_CREATED)
actions[i] = NULL;
tcf_action_put_many(actions);
/* only put bound actions */
tca_put_bound_many(actions, init_res);

return ret;
}
Expand Down

0 comments on commit 4aee43f

Please sign in to comment.