Commit 339c21d7 authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

net: sched: fix tc_u_common lookup

The offending commit wrongly assumes 1:1 mapping between block and q.
However, there are multiple blocks for a single q for classful qdiscs.
Since the obscure tc_u_common sharing mechanism expects it to be shared
among a qdisc, fix it by storing q pointer in case the block is not
shared.
Reported-by: default avatarPaweł Staszewski <pstaszewski@itcare.pl>
Reported-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
Fixes: 7fa9d974 ("net: sched: cls_u32: use block instead of q in tc_u_common")
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent bb047ddd
...@@ -96,7 +96,7 @@ struct tc_u_hnode { ...@@ -96,7 +96,7 @@ struct tc_u_hnode {
struct tc_u_common { struct tc_u_common {
struct tc_u_hnode __rcu *hlist; struct tc_u_hnode __rcu *hlist;
struct tcf_block *block; void *ptr;
int refcnt; int refcnt;
struct idr handle_idr; struct idr handle_idr;
struct hlist_node hnode; struct hlist_node hnode;
...@@ -330,9 +330,25 @@ static struct hlist_head *tc_u_common_hash; ...@@ -330,9 +330,25 @@ static struct hlist_head *tc_u_common_hash;
#define U32_HASH_SHIFT 10 #define U32_HASH_SHIFT 10
#define U32_HASH_SIZE (1 << U32_HASH_SHIFT) #define U32_HASH_SIZE (1 << U32_HASH_SHIFT)
static void *tc_u_common_ptr(const struct tcf_proto *tp)
{
struct tcf_block *block = tp->chain->block;
/* The block sharing is currently supported only
* for classless qdiscs. In that case we use block
* for tc_u_common identification. In case the
* block is not shared, block->q is a valid pointer
* and we can use that. That works for classful qdiscs.
*/
if (tcf_block_shared(block))
return block;
else
return block->q;
}
static unsigned int tc_u_hash(const struct tcf_proto *tp) static unsigned int tc_u_hash(const struct tcf_proto *tp)
{ {
return hash_ptr(tp->chain->block, U32_HASH_SHIFT); return hash_ptr(tc_u_common_ptr(tp), U32_HASH_SHIFT);
} }
static struct tc_u_common *tc_u_common_find(const struct tcf_proto *tp) static struct tc_u_common *tc_u_common_find(const struct tcf_proto *tp)
...@@ -342,7 +358,7 @@ static struct tc_u_common *tc_u_common_find(const struct tcf_proto *tp) ...@@ -342,7 +358,7 @@ static struct tc_u_common *tc_u_common_find(const struct tcf_proto *tp)
h = tc_u_hash(tp); h = tc_u_hash(tp);
hlist_for_each_entry(tc, &tc_u_common_hash[h], hnode) { hlist_for_each_entry(tc, &tc_u_common_hash[h], hnode) {
if (tc->block == tp->chain->block) if (tc->ptr == tc_u_common_ptr(tp))
return tc; return tc;
} }
return NULL; return NULL;
...@@ -371,7 +387,7 @@ static int u32_init(struct tcf_proto *tp) ...@@ -371,7 +387,7 @@ static int u32_init(struct tcf_proto *tp)
kfree(root_ht); kfree(root_ht);
return -ENOBUFS; return -ENOBUFS;
} }
tp_c->block = tp->chain->block; tp_c->ptr = tc_u_common_ptr(tp);
INIT_HLIST_NODE(&tp_c->hnode); INIT_HLIST_NODE(&tp_c->hnode);
idr_init(&tp_c->handle_idr); idr_init(&tp_c->handle_idr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment