Skip to content

Commit 8f75222

Browse files
committed
Merge branch 'net-sched-summer-cleanup-part-1-mainly-in-exts-area'
Jiri Pirko says: ==================== net: sched: summer cleanup part 1, mainly in exts area This patchset is one of the couple cleanup patchsets I have in queue. The motivation aside the obvious need to "make things nicer" is also to prepare for shared filter blocks introduction. That requires tp->q removal, and therefore removal of all tp->q users. Patch 1 is just some small thing I spotted on the way Patch 2 removes one user of tp->q, namely tcf_em_tree_change Patches 3-8 do preparations for exts->nr_actions removal Patches 9-10 do simple renames of functions in cls* Patches 11-19 remove unnecessary calls of tcf_exts_change helper The last patch changes tcf_exts_change to don't take lock Tested by tools/testing/selftests/tc-testing v1->v2: - removed conversion of action array to list as noted by Cong - added the past patch instead - small rebases of patches 11-19 ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 967b2e2 + 9b0d444 commit 8f75222

File tree

22 files changed

+125
-268
lines changed

22 files changed

+125
-268
lines changed

drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static int fill_action_fields(struct adapter *adap,
9696
LIST_HEAD(actions);
9797

9898
exts = cls->knode.exts;
99-
if (tc_no_actions(exts))
99+
if (!tcf_exts_has_actions(exts))
100100
return -EINVAL;
101101

102102
tcf_exts_to_list(exts, &actions);

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8953,7 +8953,7 @@ static int parse_tc_actions(struct ixgbe_adapter *adapter,
89538953
LIST_HEAD(actions);
89548954
int err;
89558955

8956-
if (tc_no_actions(exts))
8956+
if (!tcf_exts_has_actions(exts))
89578957
return -EINVAL;
89588958

89598959
tcf_exts_to_list(exts, &actions);

drivers/net/ethernet/mellanox/mlx5/core/en_tc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ static int parse_tc_nic_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
13261326
LIST_HEAD(actions);
13271327
int err;
13281328

1329-
if (tc_no_actions(exts))
1329+
if (!tcf_exts_has_actions(exts))
13301330
return -EINVAL;
13311331

13321332
attr->flow_tag = MLX5_FS_DEFAULT_FLOW_TAG;
@@ -1839,7 +1839,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
18391839
bool encap = false;
18401840
int err = 0;
18411841

1842-
if (tc_no_actions(exts))
1842+
if (!tcf_exts_has_actions(exts))
18431843
return -EINVAL;
18441844

18451845
memset(attr, 0, sizeof(*attr));

drivers/net/ethernet/mellanox/mlxsw/spectrum.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1626,7 +1626,7 @@ static int mlxsw_sp_port_add_cls_matchall(struct mlxsw_sp_port *mlxsw_sp_port,
16261626
LIST_HEAD(actions);
16271627
int err;
16281628

1629-
if (!tc_single_action(cls->exts)) {
1629+
if (!tcf_exts_has_one_action(cls->exts)) {
16301630
netdev_err(mlxsw_sp_port->dev, "only singular actions are supported\n");
16311631
return -EOPNOTSUPP;
16321632
}

drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static int mlxsw_sp_flower_parse_actions(struct mlxsw_sp *mlxsw_sp,
5353
LIST_HEAD(actions);
5454
int err;
5555

56-
if (tc_no_actions(exts))
56+
if (!tcf_exts_has_actions(exts))
5757
return 0;
5858

5959
/* Count action is inserted first */

drivers/net/ethernet/netronome/nfp/bpf/offload.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@ nfp_net_bpf_get_act(struct nfp_net *nn, struct tc_cls_bpf_offload *cls_bpf)
115115

116116
/* TC direct action */
117117
if (cls_bpf->exts_integrated) {
118-
if (tc_no_actions(cls_bpf->exts))
118+
if (!tcf_exts_has_actions(cls_bpf->exts))
119119
return NN_ACT_DIRECT;
120120

121121
return -EOPNOTSUPP;
122122
}
123123

124124
/* TC legacy mode */
125-
if (!tc_single_action(cls_bpf->exts))
125+
if (!tcf_exts_has_one_action(cls_bpf->exts))
126126
return -EOPNOTSUPP;
127127

128128
tcf_exts_to_list(cls_bpf->exts, &actions);

include/net/pkt_cls.h

Lines changed: 35 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -113,36 +113,6 @@ static inline int tcf_exts_init(struct tcf_exts *exts, int action, int police)
113113
return 0;
114114
}
115115

116-
/**
117-
* tcf_exts_is_predicative - check if a predicative extension is present
118-
* @exts: tc filter extensions handle
119-
*
120-
* Returns 1 if a predicative extension is present, i.e. an extension which
121-
* might cause further actions and thus overrule the regular tcf_result.
122-
*/
123-
static inline int
124-
tcf_exts_is_predicative(struct tcf_exts *exts)
125-
{
126-
#ifdef CONFIG_NET_CLS_ACT
127-
return exts->nr_actions;
128-
#else
129-
return 0;
130-
#endif
131-
}
132-
133-
/**
134-
* tcf_exts_is_available - check if at least one extension is present
135-
* @exts: tc filter extensions handle
136-
*
137-
* Returns 1 if at least one extension is present.
138-
*/
139-
static inline int
140-
tcf_exts_is_available(struct tcf_exts *exts)
141-
{
142-
/* All non-predicative extensions must be added here. */
143-
return tcf_exts_is_predicative(exts);
144-
}
145-
146116
static inline void tcf_exts_to_list(const struct tcf_exts *exts,
147117
struct list_head *actions)
148118
{
@@ -176,47 +146,62 @@ tcf_exts_stats_update(const struct tcf_exts *exts,
176146
#endif
177147
}
178148

149+
/**
150+
* tcf_exts_has_actions - check if at least one action is present
151+
* @exts: tc filter extensions handle
152+
*
153+
* Returns true if at least one action is present.
154+
*/
155+
static inline bool tcf_exts_has_actions(struct tcf_exts *exts)
156+
{
157+
#ifdef CONFIG_NET_CLS_ACT
158+
return exts->nr_actions;
159+
#else
160+
return false;
161+
#endif
162+
}
163+
164+
/**
165+
* tcf_exts_has_one_action - check if exactly one action is present
166+
* @exts: tc filter extensions handle
167+
*
168+
* Returns true if exactly one action is present.
169+
*/
170+
static inline bool tcf_exts_has_one_action(struct tcf_exts *exts)
171+
{
172+
#ifdef CONFIG_NET_CLS_ACT
173+
return exts->nr_actions == 1;
174+
#else
175+
return false;
176+
#endif
177+
}
178+
179179
/**
180180
* tcf_exts_exec - execute tc filter extensions
181181
* @skb: socket buffer
182182
* @exts: tc filter extensions handle
183183
* @res: desired result
184184
*
185-
* Executes all configured extensions. Returns 0 on a normal execution,
185+
* Executes all configured extensions. Returns TC_ACT_OK on a normal execution,
186186
* a negative number if the filter must be considered unmatched or
187187
* a positive action code (TC_ACT_*) which must be returned to the
188188
* underlying layer.
189189
*/
190190
static inline int
191191
tcf_exts_exec(struct sk_buff *skb, struct tcf_exts *exts,
192-
struct tcf_result *res)
192+
struct tcf_result *res)
193193
{
194194
#ifdef CONFIG_NET_CLS_ACT
195-
if (exts->nr_actions)
196-
return tcf_action_exec(skb, exts->actions, exts->nr_actions,
197-
res);
195+
return tcf_action_exec(skb, exts->actions, exts->nr_actions, res);
198196
#endif
199-
return 0;
197+
return TC_ACT_OK;
200198
}
201199

202-
#ifdef CONFIG_NET_CLS_ACT
203-
204-
#define tc_no_actions(_exts) ((_exts)->nr_actions == 0)
205-
#define tc_single_action(_exts) ((_exts)->nr_actions == 1)
206-
207-
#else /* CONFIG_NET_CLS_ACT */
208-
209-
#define tc_no_actions(_exts) true
210-
#define tc_single_action(_exts) false
211-
212-
#endif /* CONFIG_NET_CLS_ACT */
213-
214200
int tcf_exts_validate(struct net *net, struct tcf_proto *tp,
215201
struct nlattr **tb, struct nlattr *rate_tlv,
216202
struct tcf_exts *exts, bool ovr);
217203
void tcf_exts_destroy(struct tcf_exts *exts);
218-
void tcf_exts_change(struct tcf_proto *tp, struct tcf_exts *dst,
219-
struct tcf_exts *src);
204+
void tcf_exts_change(struct tcf_exts *dst, struct tcf_exts *src);
220205
int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts);
221206
int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts);
222207
int tcf_exts_get_dev(struct net_device *dev, struct tcf_exts *exts,
@@ -332,26 +317,6 @@ int tcf_em_tree_dump(struct sk_buff *, struct tcf_ematch_tree *, int);
332317
int __tcf_em_tree_match(struct sk_buff *, struct tcf_ematch_tree *,
333318
struct tcf_pkt_info *);
334319

335-
/**
336-
* tcf_em_tree_change - replace ematch tree of a running classifier
337-
*
338-
* @tp: classifier kind handle
339-
* @dst: destination ematch tree variable
340-
* @src: source ematch tree (temporary tree from tcf_em_tree_validate)
341-
*
342-
* This functions replaces the ematch tree in @dst with the ematch
343-
* tree in @src. The classifier in charge of the ematch tree may be
344-
* running.
345-
*/
346-
static inline void tcf_em_tree_change(struct tcf_proto *tp,
347-
struct tcf_ematch_tree *dst,
348-
struct tcf_ematch_tree *src)
349-
{
350-
tcf_tree_lock(tp);
351-
memcpy(dst, src, sizeof(*dst));
352-
tcf_tree_unlock(tp);
353-
}
354-
355320
/**
356321
* tcf_em_tree_match - evaulate an ematch tree
357322
*
@@ -386,7 +351,6 @@ struct tcf_ematch_tree {
386351
#define tcf_em_tree_validate(tp, tb, t) ((void)(t), 0)
387352
#define tcf_em_tree_destroy(t) do { (void)(t); } while(0)
388353
#define tcf_em_tree_dump(skb, t, tlv) (0)
389-
#define tcf_em_tree_change(tp, dst, src) do { } while(0)
390354
#define tcf_em_tree_match(skb, t, info) ((void)(info), 1)
391355

392356
#endif /* CONFIG_NET_EMATCH */

net/dsa/slave.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ static int dsa_slave_add_cls_matchall(struct net_device *dev,
779779
if (!ds->ops->port_mirror_add)
780780
return err;
781781

782-
if (!tc_single_action(cls->exts))
782+
if (!tcf_exts_has_one_action(cls->exts))
783783
return err;
784784

785785
tcf_exts_to_list(cls->exts, &actions);

net/sched/act_api.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,10 @@ static struct tc_action_ops *tc_lookup_action(struct nlattr *kind)
473473
int tcf_action_exec(struct sk_buff *skb, struct tc_action **actions,
474474
int nr_actions, struct tcf_result *res)
475475
{
476-
int ret = -1, i;
477476
u32 jmp_prgcnt = 0;
478477
u32 jmp_ttl = TCA_ACT_MAX_PRIO; /*matches actions per filter */
478+
int i;
479+
int ret = TC_ACT_OK;
479480

480481
if (skb_skip_tc_classify(skb))
481482
return TC_ACT_OK;

net/sched/cls_api.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -883,18 +883,12 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
883883
}
884884
EXPORT_SYMBOL(tcf_exts_validate);
885885

886-
void tcf_exts_change(struct tcf_proto *tp, struct tcf_exts *dst,
887-
struct tcf_exts *src)
886+
void tcf_exts_change(struct tcf_exts *dst, struct tcf_exts *src)
888887
{
889888
#ifdef CONFIG_NET_CLS_ACT
890889
struct tcf_exts old = *dst;
891890

892-
tcf_tree_lock(tp);
893-
dst->nr_actions = src->nr_actions;
894-
dst->actions = src->actions;
895-
dst->type = src->type;
896-
tcf_tree_unlock(tp);
897-
891+
*dst = *src;
898892
tcf_exts_destroy(&old);
899893
#endif
900894
}
@@ -915,7 +909,7 @@ int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts)
915909
#ifdef CONFIG_NET_CLS_ACT
916910
struct nlattr *nest;
917911

918-
if (exts->action && exts->nr_actions) {
912+
if (exts->action && tcf_exts_has_actions(exts)) {
919913
/*
920914
* again for backward compatible mode - we want
921915
* to work with both old and new modes of entering
@@ -972,7 +966,7 @@ int tcf_exts_get_dev(struct net_device *dev, struct tcf_exts *exts,
972966
const struct tc_action *a;
973967
LIST_HEAD(actions);
974968

975-
if (tc_no_actions(exts))
969+
if (!tcf_exts_has_actions(exts))
976970
return -EINVAL;
977971

978972
tcf_exts_to_list(exts, &actions);

net/sched/cls_basic.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,33 +129,22 @@ static int basic_set_parms(struct net *net, struct tcf_proto *tp,
129129
struct nlattr *est, bool ovr)
130130
{
131131
int err;
132-
struct tcf_exts e;
133-
struct tcf_ematch_tree t;
134132

135-
err = tcf_exts_init(&e, TCA_BASIC_ACT, TCA_BASIC_POLICE);
133+
err = tcf_exts_validate(net, tp, tb, est, &f->exts, ovr);
136134
if (err < 0)
137135
return err;
138-
err = tcf_exts_validate(net, tp, tb, est, &e, ovr);
139-
if (err < 0)
140-
goto errout;
141136

142-
err = tcf_em_tree_validate(tp, tb[TCA_BASIC_EMATCHES], &t);
137+
err = tcf_em_tree_validate(tp, tb[TCA_BASIC_EMATCHES], &f->ematches);
143138
if (err < 0)
144-
goto errout;
139+
return err;
145140

146141
if (tb[TCA_BASIC_CLASSID]) {
147142
f->res.classid = nla_get_u32(tb[TCA_BASIC_CLASSID]);
148143
tcf_bind_filter(tp, &f->res, base);
149144
}
150145

151-
tcf_exts_change(tp, &f->exts, &e);
152-
tcf_em_tree_change(tp, &f->ematches, &t);
153146
f->tp = tp;
154-
155147
return 0;
156-
errout:
157-
tcf_exts_destroy(&e);
158-
return err;
159148
}
160149

161150
static int basic_change(struct net *net, struct sk_buff *in_skb,

0 commit comments

Comments
 (0)