diff options
Diffstat (limited to 'net/sched/sch_api.c')
-rw-r--r-- | net/sched/sch_api.c | 113 |
1 files changed, 79 insertions, 34 deletions
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c index ba1d121f3127..e7fb9e0d21b4 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)); |
@@ -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; |
@@ -792,8 +844,8 @@ qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue, | |||
792 | goto err_out3; | 844 | goto err_out3; |
793 | } | 845 | } |
794 | } | 846 | } |
795 | if ((parent != TC_H_ROOT) && !(sch->flags & TCQ_F_INGRESS)) | 847 | |
796 | list_add_tail(&sch->list, &dev_queue->qdisc_sleeping->list); | 848 | qdisc_list_add(sch); |
797 | 849 | ||
798 | return sch; | 850 | return sch; |
799 | } | 851 | } |
@@ -908,7 +960,7 @@ static int tc_get_qdisc(struct sk_buff *skb, struct nlmsghdr *n, void *arg) | |||
908 | return -ENOENT; | 960 | return -ENOENT; |
909 | q = qdisc_leaf(p, clid); | 961 | q = qdisc_leaf(p, clid); |
910 | } else { /* ingress */ | 962 | } else { /* ingress */ |
911 | q = dev->rx_queue.qdisc; | 963 | q = dev->rx_queue.qdisc_sleeping; |
912 | } | 964 | } |
913 | } else { | 965 | } else { |
914 | struct netdev_queue *dev_queue; | 966 | struct netdev_queue *dev_queue; |
@@ -978,7 +1030,7 @@ replay: | |||
978 | return -ENOENT; | 1030 | return -ENOENT; |
979 | q = qdisc_leaf(p, clid); | 1031 | q = qdisc_leaf(p, clid); |
980 | } else { /*ingress */ | 1032 | } else { /*ingress */ |
981 | q = dev->rx_queue.qdisc; | 1033 | q = dev->rx_queue.qdisc_sleeping; |
982 | } | 1034 | } |
983 | } else { | 1035 | } else { |
984 | struct netdev_queue *dev_queue; | 1036 | struct netdev_queue *dev_queue; |
@@ -1074,20 +1126,13 @@ create_n_graft: | |||
1074 | } | 1126 | } |
1075 | 1127 | ||
1076 | graft: | 1128 | graft: |
1077 | if (1) { | 1129 | err = qdisc_graft(dev, p, skb, n, clid, q, NULL); |
1078 | spinlock_t *root_lock; | 1130 | if (err) { |
1079 | 1131 | if (q) | |
1080 | err = qdisc_graft(dev, p, skb, n, clid, q, NULL); | 1132 | qdisc_destroy(q); |
1081 | if (err) { | 1133 | 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 | } | 1134 | } |
1135 | |||
1091 | return 0; | 1136 | return 0; |
1092 | } | 1137 | } |
1093 | 1138 | ||
@@ -1529,11 +1574,11 @@ static int tc_dump_tclass(struct sk_buff *skb, struct netlink_callback *cb) | |||
1529 | t = 0; | 1574 | t = 0; |
1530 | 1575 | ||
1531 | dev_queue = netdev_get_tx_queue(dev, 0); | 1576 | dev_queue = netdev_get_tx_queue(dev, 0); |
1532 | if (tc_dump_tclass_root(dev_queue->qdisc, skb, tcm, cb, &t, s_t) < 0) | 1577 | if (tc_dump_tclass_root(dev_queue->qdisc_sleeping, skb, tcm, cb, &t, s_t) < 0) |
1533 | goto done; | 1578 | goto done; |
1534 | 1579 | ||
1535 | dev_queue = &dev->rx_queue; | 1580 | dev_queue = &dev->rx_queue; |
1536 | if (tc_dump_tclass_root(dev_queue->qdisc, skb, tcm, cb, &t, s_t) < 0) | 1581 | if (tc_dump_tclass_root(dev_queue->qdisc_sleeping, skb, tcm, cb, &t, s_t) < 0) |
1537 | goto done; | 1582 | goto done; |
1538 | 1583 | ||
1539 | done: | 1584 | done: |