diff options
Diffstat (limited to 'net/sched/sch_api.c')
| -rw-r--r-- | net/sched/sch_api.c | 139 |
1 files changed, 96 insertions, 43 deletions
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c index ba1d121f3127..1122c952aa99 100644 --- a/net/sched/sch_api.c +++ b/net/sched/sch_api.c | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | #include <linux/kmod.h> | 27 | #include <linux/kmod.h> |
| 28 | #include <linux/list.h> | 28 | #include <linux/list.h> |
| 29 | #include <linux/hrtimer.h> | 29 | #include <linux/hrtimer.h> |
| 30 | #include <linux/lockdep.h> | ||
| 30 | 31 | ||
| 31 | #include <net/net_namespace.h> | 32 | #include <net/net_namespace.h> |
| 32 | #include <net/sock.h> | 33 | #include <net/sock.h> |
| @@ -183,24 +184,68 @@ EXPORT_SYMBOL(unregister_qdisc); | |||
| 183 | (root qdisc, all its children, children of children etc.) | 184 | (root qdisc, all its children, children of children etc.) |
| 184 | */ | 185 | */ |
| 185 | 186 | ||
| 187 | struct Qdisc *qdisc_match_from_root(struct Qdisc *root, u32 handle) | ||
| 188 | { | ||
| 189 | struct Qdisc *q; | ||
| 190 | |||
| 191 | if (!(root->flags & TCQ_F_BUILTIN) && | ||
| 192 | root->handle == handle) | ||
| 193 | return root; | ||
| 194 | |||
| 195 | list_for_each_entry(q, &root->list, list) { | ||
| 196 | if (q->handle == handle) | ||
| 197 | return q; | ||
| 198 | } | ||
| 199 | return NULL; | ||
| 200 | } | ||
| 201 | |||
| 202 | /* | ||
| 203 | * This lock is needed until some qdiscs stop calling qdisc_tree_decrease_qlen() | ||
| 204 | * without rtnl_lock(); currently hfsc_dequeue(), netem_dequeue(), tbf_dequeue() | ||
| 205 | */ | ||
| 206 | static DEFINE_SPINLOCK(qdisc_list_lock); | ||
| 207 | |||
| 208 | static void qdisc_list_add(struct Qdisc *q) | ||
| 209 | { | ||
| 210 | if ((q->parent != TC_H_ROOT) && !(q->flags & TCQ_F_INGRESS)) { | ||
| 211 | spin_lock_bh(&qdisc_list_lock); | ||
| 212 | list_add_tail(&q->list, &qdisc_root_sleeping(q)->list); | ||
| 213 | spin_unlock_bh(&qdisc_list_lock); | ||
| 214 | } | ||
| 215 | } | ||
| 216 | |||
| 217 | void qdisc_list_del(struct Qdisc *q) | ||
| 218 | { | ||
| 219 | if ((q->parent != TC_H_ROOT) && !(q->flags & TCQ_F_INGRESS)) { | ||
| 220 | spin_lock_bh(&qdisc_list_lock); | ||
| 221 | list_del(&q->list); | ||
| 222 | spin_unlock_bh(&qdisc_list_lock); | ||
| 223 | } | ||
| 224 | } | ||
| 225 | EXPORT_SYMBOL(qdisc_list_del); | ||
| 226 | |||
| 186 | struct Qdisc *qdisc_lookup(struct net_device *dev, u32 handle) | 227 | struct Qdisc *qdisc_lookup(struct net_device *dev, u32 handle) |
| 187 | { | 228 | { |
| 188 | unsigned int i; | 229 | unsigned int i; |
| 230 | struct Qdisc *q; | ||
| 231 | |||
| 232 | spin_lock_bh(&qdisc_list_lock); | ||
| 189 | 233 | ||
| 190 | for (i = 0; i < dev->num_tx_queues; i++) { | 234 | for (i = 0; i < dev->num_tx_queues; i++) { |
| 191 | struct netdev_queue *txq = netdev_get_tx_queue(dev, i); | 235 | struct netdev_queue *txq = netdev_get_tx_queue(dev, i); |
| 192 | struct Qdisc *q, *txq_root = txq->qdisc_sleeping; | 236 | struct Qdisc *txq_root = txq->qdisc_sleeping; |
| 193 | |||
| 194 | if (!(txq_root->flags & TCQ_F_BUILTIN) && | ||
| 195 | txq_root->handle == handle) | ||
| 196 | return txq_root; | ||
| 197 | 237 | ||
| 198 | list_for_each_entry(q, &txq_root->list, list) { | 238 | q = qdisc_match_from_root(txq_root, handle); |
| 199 | if (q->handle == handle) | 239 | if (q) |
| 200 | return q; | 240 | goto unlock; |
| 201 | } | ||
| 202 | } | 241 | } |
| 203 | return NULL; | 242 | |
| 243 | q = qdisc_match_from_root(dev->rx_queue.qdisc_sleeping, handle); | ||
| 244 | |||
| 245 | unlock: | ||
| 246 | spin_unlock_bh(&qdisc_list_lock); | ||
| 247 | |||
| 248 | return q; | ||
| 204 | } | 249 | } |
| 205 | 250 | ||
| 206 | static struct Qdisc *qdisc_leaf(struct Qdisc *p, u32 classid) | 251 | static struct Qdisc *qdisc_leaf(struct Qdisc *p, u32 classid) |
| @@ -416,7 +461,7 @@ static enum hrtimer_restart qdisc_watchdog(struct hrtimer *timer) | |||
| 416 | 461 | ||
| 417 | wd->qdisc->flags &= ~TCQ_F_THROTTLED; | 462 | wd->qdisc->flags &= ~TCQ_F_THROTTLED; |
| 418 | smp_wmb(); | 463 | smp_wmb(); |
| 419 | __netif_schedule(wd->qdisc); | 464 | __netif_schedule(qdisc_root(wd->qdisc)); |
| 420 | 465 | ||
| 421 | return HRTIMER_NORESTART; | 466 | return HRTIMER_NORESTART; |
| 422 | } | 467 | } |
| @@ -433,6 +478,10 @@ void qdisc_watchdog_schedule(struct qdisc_watchdog *wd, psched_time_t expires) | |||
| 433 | { | 478 | { |
| 434 | ktime_t time; | 479 | ktime_t time; |
| 435 | 480 | ||
| 481 | if (test_bit(__QDISC_STATE_DEACTIVATED, | ||
| 482 | &qdisc_root_sleeping(wd->qdisc)->state)) | ||
| 483 | return; | ||
| 484 | |||
| 436 | wd->qdisc->flags |= TCQ_F_THROTTLED; | 485 | wd->qdisc->flags |= TCQ_F_THROTTLED; |
| 437 | time = ktime_set(0, 0); | 486 | time = ktime_set(0, 0); |
| 438 | time = ktime_add_ns(time, PSCHED_US2NS(expires)); | 487 | time = ktime_add_ns(time, PSCHED_US2NS(expires)); |
| @@ -575,7 +624,7 @@ static struct Qdisc *dev_graft_qdisc(struct netdev_queue *dev_queue, | |||
| 575 | struct Qdisc *oqdisc = dev_queue->qdisc_sleeping; | 624 | struct Qdisc *oqdisc = dev_queue->qdisc_sleeping; |
| 576 | spinlock_t *root_lock; | 625 | spinlock_t *root_lock; |
| 577 | 626 | ||
| 578 | root_lock = qdisc_root_lock(oqdisc); | 627 | root_lock = qdisc_lock(oqdisc); |
| 579 | spin_lock_bh(root_lock); | 628 | spin_lock_bh(root_lock); |
| 580 | 629 | ||
| 581 | /* Prune old scheduler */ | 630 | /* Prune old scheduler */ |
| @@ -586,7 +635,7 @@ static struct Qdisc *dev_graft_qdisc(struct netdev_queue *dev_queue, | |||
| 586 | if (qdisc == NULL) | 635 | if (qdisc == NULL) |
| 587 | qdisc = &noop_qdisc; | 636 | qdisc = &noop_qdisc; |
| 588 | dev_queue->qdisc_sleeping = qdisc; | 637 | dev_queue->qdisc_sleeping = qdisc; |
| 589 | dev_queue->qdisc = &noop_qdisc; | 638 | rcu_assign_pointer(dev_queue->qdisc, &noop_qdisc); |
| 590 | 639 | ||
| 591 | spin_unlock_bh(root_lock); | 640 | spin_unlock_bh(root_lock); |
| 592 | 641 | ||
| @@ -627,11 +676,8 @@ static void notify_and_destroy(struct sk_buff *skb, struct nlmsghdr *n, u32 clid | |||
| 627 | if (new || old) | 676 | if (new || old) |
| 628 | qdisc_notify(skb, n, clid, old, new); | 677 | qdisc_notify(skb, n, clid, old, new); |
| 629 | 678 | ||
| 630 | if (old) { | 679 | if (old) |
| 631 | spin_lock_bh(&old->q.lock); | ||
| 632 | qdisc_destroy(old); | 680 | qdisc_destroy(old); |
| 633 | spin_unlock_bh(&old->q.lock); | ||
| 634 | } | ||
| 635 | } | 681 | } |
| 636 | 682 | ||
| 637 | /* Graft qdisc "new" to class "classid" of qdisc "parent" or | 683 | /* Graft qdisc "new" to class "classid" of qdisc "parent" or |
| @@ -697,6 +743,10 @@ static int qdisc_graft(struct net_device *dev, struct Qdisc *parent, | |||
| 697 | return err; | 743 | return err; |
| 698 | } | 744 | } |
| 699 | 745 | ||
| 746 | /* lockdep annotation is needed for ingress; egress gets it only for name */ | ||
| 747 | static struct lock_class_key qdisc_tx_lock; | ||
| 748 | static struct lock_class_key qdisc_rx_lock; | ||
| 749 | |||
| 700 | /* | 750 | /* |
| 701 | Allocate and initialize new qdisc. | 751 | Allocate and initialize new qdisc. |
| 702 | 752 | ||
| @@ -757,6 +807,7 @@ qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue, | |||
| 757 | if (handle == TC_H_INGRESS) { | 807 | if (handle == TC_H_INGRESS) { |
| 758 | sch->flags |= TCQ_F_INGRESS; | 808 | sch->flags |= TCQ_F_INGRESS; |
| 759 | handle = TC_H_MAKE(TC_H_INGRESS, 0); | 809 | handle = TC_H_MAKE(TC_H_INGRESS, 0); |
| 810 | lockdep_set_class(qdisc_lock(sch), &qdisc_rx_lock); | ||
| 760 | } else { | 811 | } else { |
| 761 | if (handle == 0) { | 812 | if (handle == 0) { |
| 762 | handle = qdisc_alloc_handle(dev); | 813 | handle = qdisc_alloc_handle(dev); |
| @@ -764,6 +815,7 @@ qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue, | |||
| 764 | if (handle == 0) | 815 | if (handle == 0) |
| 765 | goto err_out3; | 816 | goto err_out3; |
| 766 | } | 817 | } |
| 818 | lockdep_set_class(qdisc_lock(sch), &qdisc_tx_lock); | ||
| 767 | } | 819 | } |
| 768 | 820 | ||
| 769 | sch->handle = handle; | 821 | sch->handle = handle; |
| @@ -778,9 +830,16 @@ qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue, | |||
| 778 | sch->stab = stab; | 830 | sch->stab = stab; |
| 779 | } | 831 | } |
| 780 | if (tca[TCA_RATE]) { | 832 | if (tca[TCA_RATE]) { |
| 833 | spinlock_t *root_lock; | ||
| 834 | |||
| 835 | if ((sch->parent != TC_H_ROOT) && | ||
| 836 | !(sch->flags & TCQ_F_INGRESS)) | ||
| 837 | root_lock = qdisc_root_sleeping_lock(sch); | ||
| 838 | else | ||
| 839 | root_lock = qdisc_lock(sch); | ||
| 840 | |||
| 781 | err = gen_new_estimator(&sch->bstats, &sch->rate_est, | 841 | err = gen_new_estimator(&sch->bstats, &sch->rate_est, |
| 782 | qdisc_root_lock(sch), | 842 | root_lock, tca[TCA_RATE]); |
| 783 | tca[TCA_RATE]); | ||
| 784 | if (err) { | 843 | if (err) { |
| 785 | /* | 844 | /* |
| 786 | * Any broken qdiscs that would require | 845 | * Any broken qdiscs that would require |
| @@ -792,8 +851,8 @@ qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue, | |||
| 792 | goto err_out3; | 851 | goto err_out3; |
| 793 | } | 852 | } |
| 794 | } | 853 | } |
| 795 | if ((parent != TC_H_ROOT) && !(sch->flags & TCQ_F_INGRESS)) | 854 | |
| 796 | list_add_tail(&sch->list, &dev_queue->qdisc_sleeping->list); | 855 | qdisc_list_add(sch); |
| 797 | 856 | ||
| 798 | return sch; | 857 | return sch; |
| 799 | } | 858 | } |
| @@ -832,7 +891,8 @@ static int qdisc_change(struct Qdisc *sch, struct nlattr **tca) | |||
| 832 | 891 | ||
| 833 | if (tca[TCA_RATE]) | 892 | if (tca[TCA_RATE]) |
| 834 | gen_replace_estimator(&sch->bstats, &sch->rate_est, | 893 | gen_replace_estimator(&sch->bstats, &sch->rate_est, |
| 835 | qdisc_root_lock(sch), tca[TCA_RATE]); | 894 | qdisc_root_sleeping_lock(sch), |
| 895 | tca[TCA_RATE]); | ||
| 836 | return 0; | 896 | return 0; |
| 837 | } | 897 | } |
| 838 | 898 | ||
| @@ -908,7 +968,7 @@ static int tc_get_qdisc(struct sk_buff *skb, struct nlmsghdr *n, void *arg) | |||
| 908 | return -ENOENT; | 968 | return -ENOENT; |
| 909 | q = qdisc_leaf(p, clid); | 969 | q = qdisc_leaf(p, clid); |
| 910 | } else { /* ingress */ | 970 | } else { /* ingress */ |
| 911 | q = dev->rx_queue.qdisc; | 971 | q = dev->rx_queue.qdisc_sleeping; |
| 912 | } | 972 | } |
| 913 | } else { | 973 | } else { |
| 914 | struct netdev_queue *dev_queue; | 974 | struct netdev_queue *dev_queue; |
| @@ -978,7 +1038,7 @@ replay: | |||
| 978 | return -ENOENT; | 1038 | return -ENOENT; |
| 979 | q = qdisc_leaf(p, clid); | 1039 | q = qdisc_leaf(p, clid); |
| 980 | } else { /*ingress */ | 1040 | } else { /*ingress */ |
| 981 | q = dev->rx_queue.qdisc; | 1041 | q = dev->rx_queue.qdisc_sleeping; |
| 982 | } | 1042 | } |
| 983 | } else { | 1043 | } else { |
| 984 | struct netdev_queue *dev_queue; | 1044 | struct netdev_queue *dev_queue; |
| @@ -1074,20 +1134,13 @@ create_n_graft: | |||
| 1074 | } | 1134 | } |
| 1075 | 1135 | ||
| 1076 | graft: | 1136 | graft: |
| 1077 | if (1) { | 1137 | err = qdisc_graft(dev, p, skb, n, clid, q, NULL); |
| 1078 | spinlock_t *root_lock; | 1138 | if (err) { |
| 1079 | 1139 | if (q) | |
| 1080 | err = qdisc_graft(dev, p, skb, n, clid, q, NULL); | 1140 | qdisc_destroy(q); |
| 1081 | if (err) { | 1141 | return err; |
| 1082 | if (q) { | ||
| 1083 | root_lock = qdisc_root_lock(q); | ||
| 1084 | spin_lock_bh(root_lock); | ||
| 1085 | qdisc_destroy(q); | ||
| 1086 | spin_unlock_bh(root_lock); | ||
| 1087 | } | ||
| 1088 | return err; | ||
| 1089 | } | ||
| 1090 | } | 1142 | } |
| 1143 | |||
| 1091 | return 0; | 1144 | return 0; |
| 1092 | } | 1145 | } |
| 1093 | 1146 | ||
| @@ -1116,8 +1169,8 @@ static int tc_fill_qdisc(struct sk_buff *skb, struct Qdisc *q, u32 clid, | |||
| 1116 | if (q->stab && qdisc_dump_stab(skb, q->stab) < 0) | 1169 | if (q->stab && qdisc_dump_stab(skb, q->stab) < 0) |
| 1117 | goto nla_put_failure; | 1170 | goto nla_put_failure; |
| 1118 | 1171 | ||
| 1119 | if (gnet_stats_start_copy_compat(skb, TCA_STATS2, TCA_STATS, | 1172 | if (gnet_stats_start_copy_compat(skb, TCA_STATS2, TCA_STATS, TCA_XSTATS, |
| 1120 | TCA_XSTATS, qdisc_root_lock(q), &d) < 0) | 1173 | qdisc_root_sleeping_lock(q), &d) < 0) |
| 1121 | goto nla_put_failure; | 1174 | goto nla_put_failure; |
| 1122 | 1175 | ||
| 1123 | if (q->ops->dump_stats && q->ops->dump_stats(q, &d) < 0) | 1176 | if (q->ops->dump_stats && q->ops->dump_stats(q, &d) < 0) |
| @@ -1408,8 +1461,8 @@ static int tc_fill_tclass(struct sk_buff *skb, struct Qdisc *q, | |||
| 1408 | if (cl_ops->dump && cl_ops->dump(q, cl, skb, tcm) < 0) | 1461 | if (cl_ops->dump && cl_ops->dump(q, cl, skb, tcm) < 0) |
| 1409 | goto nla_put_failure; | 1462 | goto nla_put_failure; |
| 1410 | 1463 | ||
| 1411 | if (gnet_stats_start_copy_compat(skb, TCA_STATS2, TCA_STATS, | 1464 | if (gnet_stats_start_copy_compat(skb, TCA_STATS2, TCA_STATS, TCA_XSTATS, |
| 1412 | TCA_XSTATS, qdisc_root_lock(q), &d) < 0) | 1465 | qdisc_root_sleeping_lock(q), &d) < 0) |
| 1413 | goto nla_put_failure; | 1466 | goto nla_put_failure; |
| 1414 | 1467 | ||
| 1415 | if (cl_ops->dump_stats && cl_ops->dump_stats(q, cl, &d) < 0) | 1468 | if (cl_ops->dump_stats && cl_ops->dump_stats(q, cl, &d) < 0) |
| @@ -1529,11 +1582,11 @@ static int tc_dump_tclass(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 1529 | t = 0; | 1582 | t = 0; |
| 1530 | 1583 | ||
| 1531 | dev_queue = netdev_get_tx_queue(dev, 0); | 1584 | dev_queue = netdev_get_tx_queue(dev, 0); |
| 1532 | if (tc_dump_tclass_root(dev_queue->qdisc, skb, tcm, cb, &t, s_t) < 0) | 1585 | if (tc_dump_tclass_root(dev_queue->qdisc_sleeping, skb, tcm, cb, &t, s_t) < 0) |
| 1533 | goto done; | 1586 | goto done; |
| 1534 | 1587 | ||
| 1535 | dev_queue = &dev->rx_queue; | 1588 | dev_queue = &dev->rx_queue; |
| 1536 | if (tc_dump_tclass_root(dev_queue->qdisc, skb, tcm, cb, &t, s_t) < 0) | 1589 | if (tc_dump_tclass_root(dev_queue->qdisc_sleeping, skb, tcm, cb, &t, s_t) < 0) |
| 1537 | goto done; | 1590 | goto done; |
| 1538 | 1591 | ||
| 1539 | done: | 1592 | done: |
