Commit 165f0135 authored by Vlad Buslov's avatar Vlad Buslov Committed by David S. Miller

net: sched: protect block->chain0 with block->lock

In order to remove dependency on rtnl lock, use block->lock to protect
chain0 struct from concurrent modification. Rearrange code in chain0
callback add and del functions to only access chain0 when block->lock is
held.
Signed-off-by: default avatarVlad Buslov <vladbu@mellanox.com>
Acked-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2cbfab07
...@@ -244,8 +244,11 @@ static void tcf_chain0_head_change(struct tcf_chain *chain, ...@@ -244,8 +244,11 @@ static void tcf_chain0_head_change(struct tcf_chain *chain,
if (chain->index) if (chain->index)
return; return;
mutex_lock(&block->lock);
list_for_each_entry(item, &block->chain0.filter_chain_list, list) list_for_each_entry(item, &block->chain0.filter_chain_list, list)
tcf_chain_head_change_item(item, tp_head); tcf_chain_head_change_item(item, tp_head);
mutex_unlock(&block->lock);
} }
/* Returns true if block can be safely freed. */ /* Returns true if block can be safely freed. */
...@@ -756,8 +759,8 @@ tcf_chain0_head_change_cb_add(struct tcf_block *block, ...@@ -756,8 +759,8 @@ tcf_chain0_head_change_cb_add(struct tcf_block *block,
struct tcf_block_ext_info *ei, struct tcf_block_ext_info *ei,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct tcf_chain *chain0 = block->chain0.chain;
struct tcf_filter_chain_list_item *item; struct tcf_filter_chain_list_item *item;
struct tcf_chain *chain0;
item = kmalloc(sizeof(*item), GFP_KERNEL); item = kmalloc(sizeof(*item), GFP_KERNEL);
if (!item) { if (!item) {
...@@ -766,9 +769,14 @@ tcf_chain0_head_change_cb_add(struct tcf_block *block, ...@@ -766,9 +769,14 @@ tcf_chain0_head_change_cb_add(struct tcf_block *block,
} }
item->chain_head_change = ei->chain_head_change; item->chain_head_change = ei->chain_head_change;
item->chain_head_change_priv = ei->chain_head_change_priv; item->chain_head_change_priv = ei->chain_head_change_priv;
mutex_lock(&block->lock);
chain0 = block->chain0.chain;
if (chain0 && chain0->filter_chain) if (chain0 && chain0->filter_chain)
tcf_chain_head_change_item(item, chain0->filter_chain); tcf_chain_head_change_item(item, chain0->filter_chain);
list_add(&item->list, &block->chain0.filter_chain_list); list_add(&item->list, &block->chain0.filter_chain_list);
mutex_unlock(&block->lock);
return 0; return 0;
} }
...@@ -776,20 +784,23 @@ static void ...@@ -776,20 +784,23 @@ static void
tcf_chain0_head_change_cb_del(struct tcf_block *block, tcf_chain0_head_change_cb_del(struct tcf_block *block,
struct tcf_block_ext_info *ei) struct tcf_block_ext_info *ei)
{ {
struct tcf_chain *chain0 = block->chain0.chain;
struct tcf_filter_chain_list_item *item; struct tcf_filter_chain_list_item *item;
mutex_lock(&block->lock);
list_for_each_entry(item, &block->chain0.filter_chain_list, list) { list_for_each_entry(item, &block->chain0.filter_chain_list, list) {
if ((!ei->chain_head_change && !ei->chain_head_change_priv) || if ((!ei->chain_head_change && !ei->chain_head_change_priv) ||
(item->chain_head_change == ei->chain_head_change && (item->chain_head_change == ei->chain_head_change &&
item->chain_head_change_priv == ei->chain_head_change_priv)) { item->chain_head_change_priv == ei->chain_head_change_priv)) {
if (chain0) if (block->chain0.chain)
tcf_chain_head_change_item(item, NULL); tcf_chain_head_change_item(item, NULL);
list_del(&item->list); list_del(&item->list);
mutex_unlock(&block->lock);
kfree(item); kfree(item);
return; return;
} }
} }
mutex_unlock(&block->lock);
WARN_ON(1); WARN_ON(1);
} }
......
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