Skip to content

Commit e382267

Browse files
w1ldptrdavem330
authored andcommitted
net: sched: update action implementations to support flags
Extend struct tc_action with new "tcfa_flags" field. Set the field in tcf_idr_create() function and provide new helper tcf_idr_create_from_flags() that derives 'cpustats' boolean from flags value. Update individual hardware-offloaded actions init() to pass their "flags" argument to new helper in order to skip percpu stats allocation when user requested it through flags. Signed-off-by: Vlad Buslov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent abbb0d3 commit e382267

21 files changed

+53
-27
lines changed

include/net/act_api.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct tc_action {
4141
struct gnet_stats_queue __percpu *cpu_qstats;
4242
struct tc_cookie __rcu *act_cookie;
4343
struct tcf_chain __rcu *goto_chain;
44+
u32 tcfa_flags;
4445
};
4546
#define tcf_index common.tcfa_index
4647
#define tcf_refcnt common.tcfa_refcnt
@@ -154,7 +155,11 @@ int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb,
154155
int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index);
155156
int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
156157
struct tc_action **a, const struct tc_action_ops *ops,
157-
int bind, bool cpustats);
158+
int bind, bool cpustats, u32 flags);
159+
int tcf_idr_create_from_flags(struct tc_action_net *tn, u32 index,
160+
struct nlattr *est, struct tc_action **a,
161+
const struct tc_action_ops *ops, int bind,
162+
u32 flags);
158163
void tcf_idr_insert(struct tc_action_net *tn, struct tc_action *a);
159164

160165
void tcf_idr_cleanup(struct tc_action_net *tn, u32 index);

net/sched/act_api.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ static int tcf_idr_delete_index(struct tcf_idrinfo *idrinfo, u32 index)
399399

400400
int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
401401
struct tc_action **a, const struct tc_action_ops *ops,
402-
int bind, bool cpustats)
402+
int bind, bool cpustats, u32 flags)
403403
{
404404
struct tc_action *p = kzalloc(ops->size, GFP_KERNEL);
405405
struct tcf_idrinfo *idrinfo = tn->idrinfo;
@@ -427,6 +427,7 @@ int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
427427
p->tcfa_tm.install = jiffies;
428428
p->tcfa_tm.lastuse = jiffies;
429429
p->tcfa_tm.firstuse = 0;
430+
p->tcfa_flags = flags;
430431
if (est) {
431432
err = gen_new_estimator(&p->tcfa_bstats, p->cpu_bstats,
432433
&p->tcfa_rate_est,
@@ -451,6 +452,17 @@ int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
451452
}
452453
EXPORT_SYMBOL(tcf_idr_create);
453454

455+
int tcf_idr_create_from_flags(struct tc_action_net *tn, u32 index,
456+
struct nlattr *est, struct tc_action **a,
457+
const struct tc_action_ops *ops, int bind,
458+
u32 flags)
459+
{
460+
/* Set cpustats according to actions flags. */
461+
return tcf_idr_create(tn, index, est, a, ops, bind,
462+
!(flags & TCA_ACT_FLAGS_NO_PERCPU_STATS), flags);
463+
}
464+
EXPORT_SYMBOL(tcf_idr_create_from_flags);
465+
454466
void tcf_idr_insert(struct tc_action_net *tn, struct tc_action *a)
455467
{
456468
struct tcf_idrinfo *idrinfo = tn->idrinfo;
@@ -773,6 +785,14 @@ tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
773785
}
774786
rcu_read_unlock();
775787

788+
if (a->tcfa_flags) {
789+
struct nla_bitfield32 flags = { a->tcfa_flags,
790+
a->tcfa_flags, };
791+
792+
if (nla_put(skb, TCA_ACT_FLAGS, sizeof(flags), &flags))
793+
goto nla_put_failure;
794+
}
795+
776796
nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
777797
if (nest == NULL)
778798
goto nla_put_failure;

net/sched/act_bpf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ static int tcf_bpf_init(struct net *net, struct nlattr *nla,
304304
ret = tcf_idr_check_alloc(tn, &index, act, bind);
305305
if (!ret) {
306306
ret = tcf_idr_create(tn, index, est, act,
307-
&act_bpf_ops, bind, true);
307+
&act_bpf_ops, bind, true, 0);
308308
if (ret < 0) {
309309
tcf_idr_cleanup(tn, index);
310310
return ret;

net/sched/act_connmark.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static int tcf_connmark_init(struct net *net, struct nlattr *nla,
121121
ret = tcf_idr_check_alloc(tn, &index, a, bind);
122122
if (!ret) {
123123
ret = tcf_idr_create(tn, index, est, a,
124-
&act_connmark_ops, bind, false);
124+
&act_connmark_ops, bind, false, 0);
125125
if (ret) {
126126
tcf_idr_cleanup(tn, index);
127127
return ret;

net/sched/act_csum.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ static int tcf_csum_init(struct net *net, struct nlattr *nla,
6868
index = parm->index;
6969
err = tcf_idr_check_alloc(tn, &index, a, bind);
7070
if (!err) {
71-
ret = tcf_idr_create(tn, index, est, a,
72-
&act_csum_ops, bind, true);
71+
ret = tcf_idr_create_from_flags(tn, index, est, a,
72+
&act_csum_ops, bind, flags);
7373
if (ret) {
7474
tcf_idr_cleanup(tn, index);
7575
return ret;

net/sched/act_ct.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,8 @@ static int tcf_ct_init(struct net *net, struct nlattr *nla,
688688
return err;
689689

690690
if (!err) {
691-
err = tcf_idr_create(tn, index, est, a,
692-
&act_ct_ops, bind, true);
691+
err = tcf_idr_create_from_flags(tn, index, est, a,
692+
&act_ct_ops, bind, flags);
693693
if (err) {
694694
tcf_idr_cleanup(tn, index);
695695
return err;

net/sched/act_ctinfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static int tcf_ctinfo_init(struct net *net, struct nlattr *nla,
210210
err = tcf_idr_check_alloc(tn, &index, a, bind);
211211
if (!err) {
212212
ret = tcf_idr_create(tn, index, est, a,
213-
&act_ctinfo_ops, bind, false);
213+
&act_ctinfo_ops, bind, false, 0);
214214
if (ret) {
215215
tcf_idr_cleanup(tn, index);
216216
return ret;

net/sched/act_gact.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ static int tcf_gact_init(struct net *net, struct nlattr *nla,
9999

100100
err = tcf_idr_check_alloc(tn, &index, a, bind);
101101
if (!err) {
102-
ret = tcf_idr_create(tn, index, est, a,
103-
&act_gact_ops, bind, true);
102+
ret = tcf_idr_create_from_flags(tn, index, est, a,
103+
&act_gact_ops, bind, flags);
104104
if (ret) {
105105
tcf_idr_cleanup(tn, index);
106106
return ret;

net/sched/act_ife.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ static int tcf_ife_init(struct net *net, struct nlattr *nla,
523523

524524
if (!exists) {
525525
ret = tcf_idr_create(tn, index, est, a, &act_ife_ops,
526-
bind, true);
526+
bind, true, 0);
527527
if (ret) {
528528
tcf_idr_cleanup(tn, index);
529529
kfree(p);

net/sched/act_ipt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static int __tcf_ipt_init(struct net *net, unsigned int id, struct nlattr *nla,
144144

145145
if (!exists) {
146146
ret = tcf_idr_create(tn, index, est, a, ops, bind,
147-
false);
147+
false, 0);
148148
if (ret) {
149149
tcf_idr_cleanup(tn, index);
150150
return ret;

net/sched/act_mirred.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
148148
NL_SET_ERR_MSG_MOD(extack, "Specified device does not exist");
149149
return -EINVAL;
150150
}
151-
ret = tcf_idr_create(tn, index, est, a,
152-
&act_mirred_ops, bind, true);
151+
ret = tcf_idr_create_from_flags(tn, index, est, a,
152+
&act_mirred_ops, bind, flags);
153153
if (ret) {
154154
tcf_idr_cleanup(tn, index);
155155
return ret;

net/sched/act_mpls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ static int tcf_mpls_init(struct net *net, struct nlattr *nla,
225225

226226
if (!exists) {
227227
ret = tcf_idr_create(tn, index, est, a,
228-
&act_mpls_ops, bind, true);
228+
&act_mpls_ops, bind, true, 0);
229229
if (ret) {
230230
tcf_idr_cleanup(tn, index);
231231
return ret;

net/sched/act_nat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static int tcf_nat_init(struct net *net, struct nlattr *nla, struct nlattr *est,
6161
err = tcf_idr_check_alloc(tn, &index, a, bind);
6262
if (!err) {
6363
ret = tcf_idr_create(tn, index, est, a,
64-
&act_nat_ops, bind, false);
64+
&act_nat_ops, bind, false, 0);
6565
if (ret) {
6666
tcf_idr_cleanup(tn, index);
6767
return ret;

net/sched/act_pedit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
191191
goto out_free;
192192
}
193193
ret = tcf_idr_create(tn, index, est, a,
194-
&act_pedit_ops, bind, false);
194+
&act_pedit_ops, bind, false, 0);
195195
if (ret) {
196196
tcf_idr_cleanup(tn, index);
197197
goto out_free;

net/sched/act_police.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static int tcf_police_init(struct net *net, struct nlattr *nla,
8787

8888
if (!exists) {
8989
ret = tcf_idr_create(tn, index, NULL, a,
90-
&act_police_ops, bind, true);
90+
&act_police_ops, bind, true, 0);
9191
if (ret) {
9292
tcf_idr_cleanup(tn, index);
9393
return ret;

net/sched/act_sample.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static int tcf_sample_init(struct net *net, struct nlattr *nla,
6969

7070
if (!exists) {
7171
ret = tcf_idr_create(tn, index, est, a,
72-
&act_sample_ops, bind, true);
72+
&act_sample_ops, bind, true, 0);
7373
if (ret) {
7474
tcf_idr_cleanup(tn, index);
7575
return ret;

net/sched/act_simple.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static int tcf_simp_init(struct net *net, struct nlattr *nla,
128128

129129
if (!exists) {
130130
ret = tcf_idr_create(tn, index, est, a,
131-
&act_simp_ops, bind, false);
131+
&act_simp_ops, bind, false, 0);
132132
if (ret) {
133133
tcf_idr_cleanup(tn, index);
134134
return ret;

net/sched/act_skbedit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static int tcf_skbedit_init(struct net *net, struct nlattr *nla,
165165

166166
if (!exists) {
167167
ret = tcf_idr_create(tn, index, est, a,
168-
&act_skbedit_ops, bind, true);
168+
&act_skbedit_ops, bind, true, 0);
169169
if (ret) {
170170
tcf_idr_cleanup(tn, index);
171171
return ret;

net/sched/act_skbmod.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ static int tcf_skbmod_init(struct net *net, struct nlattr *nla,
143143

144144
if (!exists) {
145145
ret = tcf_idr_create(tn, index, est, a,
146-
&act_skbmod_ops, bind, true);
146+
&act_skbmod_ops, bind, true, 0);
147147
if (ret) {
148148
tcf_idr_cleanup(tn, index);
149149
return ret;

net/sched/act_tunnel_key.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,9 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
347347
}
348348

349349
if (!exists) {
350-
ret = tcf_idr_create(tn, index, est, a,
351-
&act_tunnel_key_ops, bind, true);
350+
ret = tcf_idr_create_from_flags(tn, index, est, a,
351+
&act_tunnel_key_ops, bind,
352+
act_flags);
352353
if (ret) {
353354
NL_SET_ERR_MSG(extack, "Cannot create TC IDR");
354355
goto release_tun_meta;

net/sched/act_vlan.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla,
189189
action = parm->v_action;
190190

191191
if (!exists) {
192-
ret = tcf_idr_create(tn, index, est, a,
193-
&act_vlan_ops, bind, true);
192+
ret = tcf_idr_create_from_flags(tn, index, est, a,
193+
&act_vlan_ops, bind, flags);
194194
if (ret) {
195195
tcf_idr_cleanup(tn, index);
196196
return ret;

0 commit comments

Comments
 (0)