aboutsummaryrefslogtreecommitdiffstats
path: root/net/sched/cls_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/sched/cls_api.c')
-rw-r--r--net/sched/cls_api.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index c6452e3bfc6a..3038a82f6591 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -477,9 +477,12 @@ static void __tcf_chain_put(struct tcf_chain *chain, bool by_act,
477 mutex_unlock(&block->lock); 477 mutex_unlock(&block->lock);
478 478
479 /* The last dropped non-action reference will trigger notification. */ 479 /* The last dropped non-action reference will trigger notification. */
480 if (is_last && !by_act) 480 if (is_last && !by_act) {
481 tc_chain_notify_delete(tmplt_ops, tmplt_priv, chain_index, 481 tc_chain_notify_delete(tmplt_ops, tmplt_priv, chain_index,
482 block, NULL, 0, 0, false); 482 block, NULL, 0, 0, false);
483 /* Last reference to chain, no need to lock. */
484 chain->flushing = false;
485 }
483 486
484 if (refcnt == 0) { 487 if (refcnt == 0) {
485 tc_chain_tmplt_del(tmplt_ops, tmplt_priv); 488 tc_chain_tmplt_del(tmplt_ops, tmplt_priv);
@@ -511,6 +514,7 @@ static void tcf_chain_flush(struct tcf_chain *chain)
511 tp = tcf_chain_dereference(chain->filter_chain, chain); 514 tp = tcf_chain_dereference(chain->filter_chain, chain);
512 RCU_INIT_POINTER(chain->filter_chain, NULL); 515 RCU_INIT_POINTER(chain->filter_chain, NULL);
513 tcf_chain0_head_change(chain, NULL); 516 tcf_chain0_head_change(chain, NULL);
517 chain->flushing = true;
514 mutex_unlock(&chain->filter_chain_lock); 518 mutex_unlock(&chain->filter_chain_lock);
515 519
516 while (tp) { 520 while (tp) {
@@ -1610,15 +1614,20 @@ static struct tcf_proto *tcf_chain_tp_prev(struct tcf_chain *chain,
1610 return tcf_chain_dereference(*chain_info->pprev, chain); 1614 return tcf_chain_dereference(*chain_info->pprev, chain);
1611} 1615}
1612 1616
1613static void tcf_chain_tp_insert(struct tcf_chain *chain, 1617static int tcf_chain_tp_insert(struct tcf_chain *chain,
1614 struct tcf_chain_info *chain_info, 1618 struct tcf_chain_info *chain_info,
1615 struct tcf_proto *tp) 1619 struct tcf_proto *tp)
1616{ 1620{
1621 if (chain->flushing)
1622 return -EAGAIN;
1623
1617 if (*chain_info->pprev == chain->filter_chain) 1624 if (*chain_info->pprev == chain->filter_chain)
1618 tcf_chain0_head_change(chain, tp); 1625 tcf_chain0_head_change(chain, tp);
1619 tcf_proto_get(tp); 1626 tcf_proto_get(tp);
1620 RCU_INIT_POINTER(tp->next, tcf_chain_tp_prev(chain, chain_info)); 1627 RCU_INIT_POINTER(tp->next, tcf_chain_tp_prev(chain, chain_info));
1621 rcu_assign_pointer(*chain_info->pprev, tp); 1628 rcu_assign_pointer(*chain_info->pprev, tp);
1629
1630 return 0;
1622} 1631}
1623 1632
1624static void tcf_chain_tp_remove(struct tcf_chain *chain, 1633static void tcf_chain_tp_remove(struct tcf_chain *chain,
@@ -1649,18 +1658,22 @@ static struct tcf_proto *tcf_chain_tp_insert_unique(struct tcf_chain *chain,
1649{ 1658{
1650 struct tcf_chain_info chain_info; 1659 struct tcf_chain_info chain_info;
1651 struct tcf_proto *tp; 1660 struct tcf_proto *tp;
1661 int err = 0;
1652 1662
1653 mutex_lock(&chain->filter_chain_lock); 1663 mutex_lock(&chain->filter_chain_lock);
1654 1664
1655 tp = tcf_chain_tp_find(chain, &chain_info, 1665 tp = tcf_chain_tp_find(chain, &chain_info,
1656 protocol, prio, false); 1666 protocol, prio, false);
1657 if (!tp) 1667 if (!tp)
1658 tcf_chain_tp_insert(chain, &chain_info, tp_new); 1668 err = tcf_chain_tp_insert(chain, &chain_info, tp_new);
1659 mutex_unlock(&chain->filter_chain_lock); 1669 mutex_unlock(&chain->filter_chain_lock);
1660 1670
1661 if (tp) { 1671 if (tp) {
1662 tcf_proto_destroy(tp_new, NULL); 1672 tcf_proto_destroy(tp_new, NULL);
1663 tp_new = tp; 1673 tp_new = tp;
1674 } else if (err) {
1675 tcf_proto_destroy(tp_new, NULL);
1676 tp_new = ERR_PTR(err);
1664 } 1677 }
1665 1678
1666 return tp_new; 1679 return tp_new;
@@ -1943,6 +1956,11 @@ replay:
1943 if (tp == NULL) { 1956 if (tp == NULL) {
1944 struct tcf_proto *tp_new = NULL; 1957 struct tcf_proto *tp_new = NULL;
1945 1958
1959 if (chain->flushing) {
1960 err = -EAGAIN;
1961 goto errout_locked;
1962 }
1963
1946 /* Proto-tcf does not exist, create new one */ 1964 /* Proto-tcf does not exist, create new one */
1947 1965
1948 if (tca[TCA_KIND] == NULL || !protocol) { 1966 if (tca[TCA_KIND] == NULL || !protocol) {
@@ -1966,11 +1984,15 @@ replay:
1966 protocol, prio, chain, extack); 1984 protocol, prio, chain, extack);
1967 if (IS_ERR(tp_new)) { 1985 if (IS_ERR(tp_new)) {
1968 err = PTR_ERR(tp_new); 1986 err = PTR_ERR(tp_new);
1969 goto errout; 1987 goto errout_tp;
1970 } 1988 }
1971 1989
1972 tp_created = 1; 1990 tp_created = 1;
1973 tp = tcf_chain_tp_insert_unique(chain, tp_new, protocol, prio); 1991 tp = tcf_chain_tp_insert_unique(chain, tp_new, protocol, prio);
1992 if (IS_ERR(tp)) {
1993 err = PTR_ERR(tp);
1994 goto errout_tp;
1995 }
1974 } else { 1996 } else {
1975 mutex_unlock(&chain->filter_chain_lock); 1997 mutex_unlock(&chain->filter_chain_lock);
1976 } 1998 }
@@ -2011,6 +2033,7 @@ replay:
2011errout: 2033errout:
2012 if (err && tp_created) 2034 if (err && tp_created)
2013 tcf_chain_tp_delete_empty(chain, tp, NULL); 2035 tcf_chain_tp_delete_empty(chain, tp, NULL);
2036errout_tp:
2014 if (chain) { 2037 if (chain) {
2015 if (tp && !IS_ERR(tp)) 2038 if (tp && !IS_ERR(tp))
2016 tcf_proto_put(tp, NULL); 2039 tcf_proto_put(tp, NULL);