Skip to content

Commit 1d4150c

Browse files
congwangdavem330
authored andcommitted
net_sched: prepare tcf_hashinfo_destroy() for netns support
We only release the memory of the hashtable itself, not its entries inside. This is not a problem yet since we only call it in module release path, and module is refcount'ed by actions. This would be a problem after we move the per module hinfo into per netns in the latter patch. Cc: Jamal Hadi Salim <[email protected]> Signed-off-by: Cong Wang <[email protected]> Acked-by: Jamal Hadi Salim <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 555d5b7 commit 1d4150c

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

include/net/act_api.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ static inline int tcf_hashinfo_init(struct tcf_hashinfo *hf, unsigned int mask)
6565
return 0;
6666
}
6767

68-
static inline void tcf_hashinfo_destroy(struct tcf_hashinfo *hf)
69-
{
70-
kfree(hf->htab);
71-
}
72-
7368
/* Update lastuse only if needed, to avoid dirtying a cache line.
7469
* We use a temp variable to avoid fetching jiffies twice.
7570
*/

net/sched/act_api.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int __tcf_hash_release(struct tc_action *a, bool bind, bool strict)
6969
if (a->ops->cleanup)
7070
a->ops->cleanup(a, bind);
7171
tcf_hash_destroy(a);
72-
ret = 1;
72+
ret = ACT_P_DELETED;
7373
}
7474
}
7575

@@ -302,6 +302,32 @@ void tcf_hash_insert(struct tc_action *a)
302302
}
303303
EXPORT_SYMBOL(tcf_hash_insert);
304304

305+
static void tcf_hashinfo_destroy(const struct tc_action_ops *ops)
306+
{
307+
struct tcf_hashinfo *hinfo = ops->hinfo;
308+
struct tc_action a = {
309+
.ops = ops,
310+
};
311+
int i;
312+
313+
for (i = 0; i < hinfo->hmask + 1; i++) {
314+
struct tcf_common *p;
315+
struct hlist_node *n;
316+
317+
hlist_for_each_entry_safe(p, n, &hinfo->htab[i], tcfc_head) {
318+
int ret;
319+
320+
a.priv = p;
321+
ret = __tcf_hash_release(&a, false, true);
322+
if (ret == ACT_P_DELETED)
323+
module_put(ops->owner);
324+
else if (ret < 0)
325+
return;
326+
}
327+
}
328+
kfree(hinfo->htab);
329+
}
330+
305331
static LIST_HEAD(act_base);
306332
static DEFINE_RWLOCK(act_mod_lock);
307333

@@ -333,7 +359,7 @@ int tcf_register_action(struct tc_action_ops *act, unsigned int mask)
333359
list_for_each_entry(a, &act_base, head) {
334360
if (act->type == a->type || (strcmp(act->kind, a->kind) == 0)) {
335361
write_unlock(&act_mod_lock);
336-
tcf_hashinfo_destroy(act->hinfo);
362+
tcf_hashinfo_destroy(act);
337363
kfree(act->hinfo);
338364
return -EEXIST;
339365
}
@@ -353,7 +379,7 @@ int tcf_unregister_action(struct tc_action_ops *act)
353379
list_for_each_entry(a, &act_base, head) {
354380
if (a == act) {
355381
list_del(&act->head);
356-
tcf_hashinfo_destroy(act->hinfo);
382+
tcf_hashinfo_destroy(act);
357383
kfree(act->hinfo);
358384
err = 0;
359385
break;

0 commit comments

Comments
 (0)