Skip to content

Commit 73af53d

Browse files
ferrieuxkuba-moo
authored andcommitted
net: sched: cls_u32: Fix u32's systematic failure to free IDR entries for hnodes.
To generate hnode handles (in gen_new_htid()), u32 uses IDR and encodes the returned small integer into a structured 32-bit word. Unfortunately, at disposal time, the needed decoding is not done. As a result, idr_remove() fails, and the IDR fills up. Since its size is 2048, the following script ends up with "Filter already exists": tc filter add dev myve $FILTER1 tc filter add dev myve $FILTER2 for i in {1..2048} do echo $i tc filter del dev myve $FILTER2 tc filter add dev myve $FILTER2 done This patch adds the missing decoding logic for handles that deserve it. Fixes: e761437 ("net_sched: use idr to allocate u32 filter handles") Reviewed-by: Eric Dumazet <[email protected]> Acked-by: Jamal Hadi Salim <[email protected]> Signed-off-by: Alexandre Ferrieux <[email protected]> Tested-by: Victor Nogueira <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 2b99b25 commit 73af53d

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

net/sched/cls_u32.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ struct tc_u_common {
9292
long knodes;
9393
};
9494

95+
static u32 handle2id(u32 h)
96+
{
97+
return ((h & 0x80000000) ? ((h >> 20) & 0x7FF) : h);
98+
}
99+
100+
static u32 id2handle(u32 id)
101+
{
102+
return (id | 0x800U) << 20;
103+
}
104+
95105
static inline unsigned int u32_hash_fold(__be32 key,
96106
const struct tc_u32_sel *sel,
97107
u8 fshift)
@@ -310,7 +320,7 @@ static u32 gen_new_htid(struct tc_u_common *tp_c, struct tc_u_hnode *ptr)
310320
int id = idr_alloc_cyclic(&tp_c->handle_idr, ptr, 1, 0x7FF, GFP_KERNEL);
311321
if (id < 0)
312322
return 0;
313-
return (id | 0x800U) << 20;
323+
return id2handle(id);
314324
}
315325

316326
static struct hlist_head *tc_u_common_hash;
@@ -360,7 +370,7 @@ static int u32_init(struct tcf_proto *tp)
360370
return -ENOBUFS;
361371

362372
refcount_set(&root_ht->refcnt, 1);
363-
root_ht->handle = tp_c ? gen_new_htid(tp_c, root_ht) : 0x80000000;
373+
root_ht->handle = tp_c ? gen_new_htid(tp_c, root_ht) : id2handle(0);
364374
root_ht->prio = tp->prio;
365375
root_ht->is_root = true;
366376
idr_init(&root_ht->handle_idr);
@@ -612,7 +622,7 @@ static int u32_destroy_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht,
612622
if (phn == ht) {
613623
u32_clear_hw_hnode(tp, ht, extack);
614624
idr_destroy(&ht->handle_idr);
615-
idr_remove(&tp_c->handle_idr, ht->handle);
625+
idr_remove(&tp_c->handle_idr, handle2id(ht->handle));
616626
RCU_INIT_POINTER(*hn, ht->next);
617627
kfree_rcu(ht, rcu);
618628
return 0;
@@ -989,7 +999,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
989999

9901000
err = u32_replace_hw_hnode(tp, ht, userflags, extack);
9911001
if (err) {
992-
idr_remove(&tp_c->handle_idr, handle);
1002+
idr_remove(&tp_c->handle_idr, handle2id(handle));
9931003
kfree(ht);
9941004
return err;
9951005
}

0 commit comments

Comments
 (0)