Skip to content

Commit 82a470f

Browse files
jrfastabdavem330
authored andcommitted
net: sched: remove tcf_proto from ematch calls
This removes the tcf_proto argument from the ematch code paths that only need it to reference the net namespace. This allows simplifying qdisc code paths especially when we need to tear down the ematch from an RCU callback. In this case we can not guarentee that the tcf_proto structure is still valid. Signed-off-by: John Fastabend <[email protected]> Acked-by: Cong Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent fcbeb97 commit 82a470f

File tree

10 files changed

+26
-25
lines changed

10 files changed

+26
-25
lines changed

include/net/pkt_cls.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ struct tcf_ematch {
166166
unsigned int datalen;
167167
u16 matchid;
168168
u16 flags;
169+
struct net *net;
169170
};
170171

171172
static inline int tcf_em_is_container(struct tcf_ematch *em)
@@ -229,12 +230,11 @@ struct tcf_ematch_tree {
229230
struct tcf_ematch_ops {
230231
int kind;
231232
int datalen;
232-
int (*change)(struct tcf_proto *, void *,
233+
int (*change)(struct net *net, void *,
233234
int, struct tcf_ematch *);
234235
int (*match)(struct sk_buff *, struct tcf_ematch *,
235236
struct tcf_pkt_info *);
236-
void (*destroy)(struct tcf_proto *,
237-
struct tcf_ematch *);
237+
void (*destroy)(struct tcf_ematch *);
238238
int (*dump)(struct sk_buff *, struct tcf_ematch *);
239239
struct module *owner;
240240
struct list_head link;
@@ -244,7 +244,7 @@ int tcf_em_register(struct tcf_ematch_ops *);
244244
void tcf_em_unregister(struct tcf_ematch_ops *);
245245
int tcf_em_tree_validate(struct tcf_proto *, struct nlattr *,
246246
struct tcf_ematch_tree *);
247-
void tcf_em_tree_destroy(struct tcf_proto *, struct tcf_ematch_tree *);
247+
void tcf_em_tree_destroy(struct tcf_ematch_tree *);
248248
int tcf_em_tree_dump(struct sk_buff *, struct tcf_ematch_tree *, int);
249249
int __tcf_em_tree_match(struct sk_buff *, struct tcf_ematch_tree *,
250250
struct tcf_pkt_info *);
@@ -301,7 +301,7 @@ struct tcf_ematch_tree {
301301
};
302302

303303
#define tcf_em_tree_validate(tp, tb, t) ((void)(t), 0)
304-
#define tcf_em_tree_destroy(tp, t) do { (void)(t); } while(0)
304+
#define tcf_em_tree_destroy(t) do { (void)(t); } while(0)
305305
#define tcf_em_tree_dump(skb, t, tlv) (0)
306306
#define tcf_em_tree_change(tp, dst, src) do { } while(0)
307307
#define tcf_em_tree_match(skb, t, info) ((void)(info), 1)

net/sched/cls_basic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void basic_delete_filter(struct rcu_head *head)
9595

9696
tcf_unbind_filter(tp, &f->res);
9797
tcf_exts_destroy(&f->exts);
98-
tcf_em_tree_destroy(tp, &f->ematches);
98+
tcf_em_tree_destroy(&f->ematches);
9999
kfree(f);
100100
}
101101

net/sched/cls_cgroup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static void cls_cgroup_destroy_rcu(struct rcu_head *root)
8787
rcu);
8888

8989
tcf_exts_destroy(&head->exts);
90-
tcf_em_tree_destroy(head->tp, &head->ematches);
90+
tcf_em_tree_destroy(&head->ematches);
9191
kfree(head);
9292
}
9393

@@ -157,7 +157,7 @@ static void cls_cgroup_destroy(struct tcf_proto *tp)
157157

158158
if (head) {
159159
tcf_exts_destroy(&head->exts);
160-
tcf_em_tree_destroy(tp, &head->ematches);
160+
tcf_em_tree_destroy(&head->ematches);
161161
RCU_INIT_POINTER(tp->root, NULL);
162162
kfree_rcu(head, rcu);
163163
}

net/sched/cls_flow.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ static void flow_destroy_filter(struct rcu_head *head)
355355

356356
del_timer_sync(&f->perturb_timer);
357357
tcf_exts_destroy(&f->exts);
358-
tcf_em_tree_destroy(f->tp, &f->ematches);
358+
tcf_em_tree_destroy(&f->ematches);
359359
kfree(f);
360360
}
361361

@@ -530,7 +530,7 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,
530530
return 0;
531531

532532
err2:
533-
tcf_em_tree_destroy(tp, &t);
533+
tcf_em_tree_destroy(&t);
534534
kfree(fnew);
535535
err1:
536536
tcf_exts_destroy(&e);

net/sched/em_canid.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static int em_canid_match(struct sk_buff *skb, struct tcf_ematch *m,
120120
return match;
121121
}
122122

123-
static int em_canid_change(struct tcf_proto *tp, void *data, int len,
123+
static int em_canid_change(struct net *net, void *data, int len,
124124
struct tcf_ematch *m)
125125
{
126126
struct can_filter *conf = data; /* Array with rules */
@@ -183,7 +183,7 @@ static int em_canid_change(struct tcf_proto *tp, void *data, int len,
183183
return 0;
184184
}
185185

186-
static void em_canid_destroy(struct tcf_proto *tp, struct tcf_ematch *m)
186+
static void em_canid_destroy(struct tcf_ematch *m)
187187
{
188188
struct canid_match *cm = em_canid_priv(m);
189189

net/sched/em_ipset.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
#include <net/ip.h>
2020
#include <net/pkt_cls.h>
2121

22-
static int em_ipset_change(struct tcf_proto *tp, void *data, int data_len,
22+
static int em_ipset_change(struct net *net, void *data, int data_len,
2323
struct tcf_ematch *em)
2424
{
2525
struct xt_set_info *set = data;
2626
ip_set_id_t index;
27-
struct net *net = dev_net(qdisc_dev(tp->q));
2827

2928
if (data_len != sizeof(*set))
3029
return -EINVAL;
@@ -42,11 +41,11 @@ static int em_ipset_change(struct tcf_proto *tp, void *data, int data_len,
4241
return -ENOMEM;
4342
}
4443

45-
static void em_ipset_destroy(struct tcf_proto *p, struct tcf_ematch *em)
44+
static void em_ipset_destroy(struct tcf_ematch *em)
4645
{
4746
const struct xt_set_info *set = (const void *) em->data;
4847
if (set) {
49-
ip_set_nfnl_put(dev_net(qdisc_dev(p->q)), set->index);
48+
ip_set_nfnl_put(em->net, set->index);
5049
kfree((void *) em->data);
5150
}
5251
}

net/sched/em_meta.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ static const struct nla_policy meta_policy[TCA_EM_META_MAX + 1] = {
856856
[TCA_EM_META_HDR] = { .len = sizeof(struct tcf_meta_hdr) },
857857
};
858858

859-
static int em_meta_change(struct tcf_proto *tp, void *data, int len,
859+
static int em_meta_change(struct net *net, void *data, int len,
860860
struct tcf_ematch *m)
861861
{
862862
int err;
@@ -908,7 +908,7 @@ static int em_meta_change(struct tcf_proto *tp, void *data, int len,
908908
return err;
909909
}
910910

911-
static void em_meta_destroy(struct tcf_proto *tp, struct tcf_ematch *m)
911+
static void em_meta_destroy(struct tcf_ematch *m)
912912
{
913913
if (m)
914914
meta_delete((struct meta_match *) m->data);

net/sched/em_nbyte.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct nbyte_data {
2323
char pattern[0];
2424
};
2525

26-
static int em_nbyte_change(struct tcf_proto *tp, void *data, int data_len,
26+
static int em_nbyte_change(struct net *net, void *data, int data_len,
2727
struct tcf_ematch *em)
2828
{
2929
struct tcf_em_nbyte *nbyte = data;

net/sched/em_text.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static int em_text_match(struct sk_buff *skb, struct tcf_ematch *m,
4545
return skb_find_text(skb, from, to, tm->config, &state) != UINT_MAX;
4646
}
4747

48-
static int em_text_change(struct tcf_proto *tp, void *data, int len,
48+
static int em_text_change(struct net *net, void *data, int len,
4949
struct tcf_ematch *m)
5050
{
5151
struct text_match *tm;
@@ -100,7 +100,7 @@ static int em_text_change(struct tcf_proto *tp, void *data, int len,
100100
return 0;
101101
}
102102

103-
static void em_text_destroy(struct tcf_proto *tp, struct tcf_ematch *m)
103+
static void em_text_destroy(struct tcf_ematch *m)
104104
{
105105
if (EM_TEXT_PRIV(m) && EM_TEXT_PRIV(m)->config)
106106
textsearch_destroy(EM_TEXT_PRIV(m)->config);

net/sched/ematch.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ static int tcf_em_validate(struct tcf_proto *tp,
178178
struct tcf_ematch_hdr *em_hdr = nla_data(nla);
179179
int data_len = nla_len(nla) - sizeof(*em_hdr);
180180
void *data = (void *) em_hdr + sizeof(*em_hdr);
181+
struct net *net = dev_net(qdisc_dev(tp->q));
181182

182183
if (!TCF_EM_REL_VALID(em_hdr->flags))
183184
goto errout;
@@ -240,7 +241,7 @@ static int tcf_em_validate(struct tcf_proto *tp,
240241
goto errout;
241242

242243
if (em->ops->change) {
243-
err = em->ops->change(tp, data, data_len, em);
244+
err = em->ops->change(net, data, data_len, em);
244245
if (err < 0)
245246
goto errout;
246247
} else if (data_len > 0) {
@@ -271,6 +272,7 @@ static int tcf_em_validate(struct tcf_proto *tp,
271272
em->matchid = em_hdr->matchid;
272273
em->flags = em_hdr->flags;
273274
em->datalen = data_len;
275+
em->net = net;
274276

275277
err = 0;
276278
errout:
@@ -378,7 +380,7 @@ int tcf_em_tree_validate(struct tcf_proto *tp, struct nlattr *nla,
378380
return err;
379381

380382
errout_abort:
381-
tcf_em_tree_destroy(tp, tree);
383+
tcf_em_tree_destroy(tree);
382384
return err;
383385
}
384386
EXPORT_SYMBOL(tcf_em_tree_validate);
@@ -393,7 +395,7 @@ EXPORT_SYMBOL(tcf_em_tree_validate);
393395
* tcf_em_tree_validate()/tcf_em_tree_change(). You must ensure that
394396
* the ematch tree is not in use before calling this function.
395397
*/
396-
void tcf_em_tree_destroy(struct tcf_proto *tp, struct tcf_ematch_tree *tree)
398+
void tcf_em_tree_destroy(struct tcf_ematch_tree *tree)
397399
{
398400
int i;
399401

@@ -405,7 +407,7 @@ void tcf_em_tree_destroy(struct tcf_proto *tp, struct tcf_ematch_tree *tree)
405407

406408
if (em->ops) {
407409
if (em->ops->destroy)
408-
em->ops->destroy(tp, em);
410+
em->ops->destroy(em);
409411
else if (!tcf_em_is_simple(em))
410412
kfree((void *) em->data);
411413
module_put(em->ops->owner);

0 commit comments

Comments
 (0)