| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * net/sched/sch_generic.c Generic packet scheduler routines. |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or |
|---|
| 5 | | - * modify it under the terms of the GNU General Public License |
|---|
| 6 | | - * as published by the Free Software Foundation; either version |
|---|
| 7 | | - * 2 of the License, or (at your option) any later version. |
|---|
| 8 | 4 | * |
|---|
| 9 | 5 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
|---|
| 10 | 6 | * Jamal Hadi Salim, <hadi@cyberus.ca> 990601 |
|---|
| .. | .. |
|---|
| 32 | 28 | #include <net/pkt_sched.h> |
|---|
| 33 | 29 | #include <net/dst.h> |
|---|
| 34 | 30 | #include <trace/events/qdisc.h> |
|---|
| 31 | +#include <trace/events/net.h> |
|---|
| 35 | 32 | #include <net/xfrm.h> |
|---|
| 36 | 33 | |
|---|
| 37 | 34 | /* Qdisc to use by default */ |
|---|
| 38 | 35 | const struct Qdisc_ops *default_qdisc_ops = &pfifo_fast_ops; |
|---|
| 39 | 36 | EXPORT_SYMBOL(default_qdisc_ops); |
|---|
| 37 | + |
|---|
| 38 | +static void qdisc_maybe_clear_missed(struct Qdisc *q, |
|---|
| 39 | + const struct netdev_queue *txq) |
|---|
| 40 | +{ |
|---|
| 41 | + clear_bit(__QDISC_STATE_MISSED, &q->state); |
|---|
| 42 | + |
|---|
| 43 | + /* Make sure the below netif_xmit_frozen_or_stopped() |
|---|
| 44 | + * checking happens after clearing STATE_MISSED. |
|---|
| 45 | + */ |
|---|
| 46 | + smp_mb__after_atomic(); |
|---|
| 47 | + |
|---|
| 48 | + /* Checking netif_xmit_frozen_or_stopped() again to |
|---|
| 49 | + * make sure STATE_MISSED is set if the STATE_MISSED |
|---|
| 50 | + * set by netif_tx_wake_queue()'s rescheduling of |
|---|
| 51 | + * net_tx_action() is cleared by the above clear_bit(). |
|---|
| 52 | + */ |
|---|
| 53 | + if (!netif_xmit_frozen_or_stopped(txq)) |
|---|
| 54 | + set_bit(__QDISC_STATE_MISSED, &q->state); |
|---|
| 55 | +} |
|---|
| 40 | 56 | |
|---|
| 41 | 57 | /* Main transmission queue. */ |
|---|
| 42 | 58 | |
|---|
| .. | .. |
|---|
| 70 | 86 | skb = __skb_dequeue(&q->skb_bad_txq); |
|---|
| 71 | 87 | if (qdisc_is_percpu_stats(q)) { |
|---|
| 72 | 88 | qdisc_qstats_cpu_backlog_dec(q, skb); |
|---|
| 73 | | - qdisc_qstats_atomic_qlen_dec(q); |
|---|
| 89 | + qdisc_qstats_cpu_qlen_dec(q); |
|---|
| 74 | 90 | } else { |
|---|
| 75 | 91 | qdisc_qstats_backlog_dec(q, skb); |
|---|
| 76 | 92 | q->q.qlen--; |
|---|
| 77 | 93 | } |
|---|
| 78 | 94 | } else { |
|---|
| 79 | 95 | skb = SKB_XOFF_MAGIC; |
|---|
| 96 | + qdisc_maybe_clear_missed(q, txq); |
|---|
| 80 | 97 | } |
|---|
| 81 | 98 | } |
|---|
| 82 | 99 | |
|---|
| .. | .. |
|---|
| 110 | 127 | |
|---|
| 111 | 128 | if (qdisc_is_percpu_stats(q)) { |
|---|
| 112 | 129 | qdisc_qstats_cpu_backlog_inc(q, skb); |
|---|
| 113 | | - qdisc_qstats_atomic_qlen_inc(q); |
|---|
| 130 | + qdisc_qstats_cpu_qlen_inc(q); |
|---|
| 114 | 131 | } else { |
|---|
| 115 | 132 | qdisc_qstats_backlog_inc(q, skb); |
|---|
| 116 | 133 | q->q.qlen++; |
|---|
| .. | .. |
|---|
| 120 | 137 | spin_unlock(lock); |
|---|
| 121 | 138 | } |
|---|
| 122 | 139 | |
|---|
| 123 | | -static inline int __dev_requeue_skb(struct sk_buff *skb, struct Qdisc *q) |
|---|
| 140 | +static inline void dev_requeue_skb(struct sk_buff *skb, struct Qdisc *q) |
|---|
| 124 | 141 | { |
|---|
| 125 | | - while (skb) { |
|---|
| 126 | | - struct sk_buff *next = skb->next; |
|---|
| 142 | + spinlock_t *lock = NULL; |
|---|
| 127 | 143 | |
|---|
| 128 | | - __skb_queue_tail(&q->gso_skb, skb); |
|---|
| 129 | | - q->qstats.requeues++; |
|---|
| 130 | | - qdisc_qstats_backlog_inc(q, skb); |
|---|
| 131 | | - q->q.qlen++; /* it's still part of the queue */ |
|---|
| 132 | | - |
|---|
| 133 | | - skb = next; |
|---|
| 144 | + if (q->flags & TCQ_F_NOLOCK) { |
|---|
| 145 | + lock = qdisc_lock(q); |
|---|
| 146 | + spin_lock(lock); |
|---|
| 134 | 147 | } |
|---|
| 135 | | - __netif_schedule(q); |
|---|
| 136 | 148 | |
|---|
| 137 | | - return 0; |
|---|
| 138 | | -} |
|---|
| 139 | | - |
|---|
| 140 | | -static inline int dev_requeue_skb_locked(struct sk_buff *skb, struct Qdisc *q) |
|---|
| 141 | | -{ |
|---|
| 142 | | - spinlock_t *lock = qdisc_lock(q); |
|---|
| 143 | | - |
|---|
| 144 | | - spin_lock(lock); |
|---|
| 145 | 149 | while (skb) { |
|---|
| 146 | 150 | struct sk_buff *next = skb->next; |
|---|
| 147 | 151 | |
|---|
| 148 | 152 | __skb_queue_tail(&q->gso_skb, skb); |
|---|
| 149 | 153 | |
|---|
| 150 | | - qdisc_qstats_cpu_requeues_inc(q); |
|---|
| 151 | | - qdisc_qstats_cpu_backlog_inc(q, skb); |
|---|
| 152 | | - qdisc_qstats_atomic_qlen_inc(q); |
|---|
| 154 | + /* it's still part of the queue */ |
|---|
| 155 | + if (qdisc_is_percpu_stats(q)) { |
|---|
| 156 | + qdisc_qstats_cpu_requeues_inc(q); |
|---|
| 157 | + qdisc_qstats_cpu_backlog_inc(q, skb); |
|---|
| 158 | + qdisc_qstats_cpu_qlen_inc(q); |
|---|
| 159 | + } else { |
|---|
| 160 | + q->qstats.requeues++; |
|---|
| 161 | + qdisc_qstats_backlog_inc(q, skb); |
|---|
| 162 | + q->q.qlen++; |
|---|
| 163 | + } |
|---|
| 153 | 164 | |
|---|
| 154 | 165 | skb = next; |
|---|
| 155 | 166 | } |
|---|
| 156 | | - spin_unlock(lock); |
|---|
| 157 | | - |
|---|
| 167 | + if (lock) |
|---|
| 168 | + spin_unlock(lock); |
|---|
| 158 | 169 | __netif_schedule(q); |
|---|
| 159 | | - |
|---|
| 160 | | - return 0; |
|---|
| 161 | | -} |
|---|
| 162 | | - |
|---|
| 163 | | -static inline int dev_requeue_skb(struct sk_buff *skb, struct Qdisc *q) |
|---|
| 164 | | -{ |
|---|
| 165 | | - if (q->flags & TCQ_F_NOLOCK) |
|---|
| 166 | | - return dev_requeue_skb_locked(skb, q); |
|---|
| 167 | | - else |
|---|
| 168 | | - return __dev_requeue_skb(skb, q); |
|---|
| 169 | 170 | } |
|---|
| 170 | 171 | |
|---|
| 171 | 172 | static void try_bulk_dequeue_skb(struct Qdisc *q, |
|---|
| .. | .. |
|---|
| 186 | 187 | skb = nskb; |
|---|
| 187 | 188 | (*packets)++; /* GSO counts as one pkt */ |
|---|
| 188 | 189 | } |
|---|
| 189 | | - skb->next = NULL; |
|---|
| 190 | + skb_mark_not_on_list(skb); |
|---|
| 190 | 191 | } |
|---|
| 191 | 192 | |
|---|
| 192 | 193 | /* This variant of try_bulk_dequeue_skb() makes sure |
|---|
| .. | .. |
|---|
| 212 | 213 | skb = nskb; |
|---|
| 213 | 214 | } while (++cnt < 8); |
|---|
| 214 | 215 | (*packets) += cnt; |
|---|
| 215 | | - skb->next = NULL; |
|---|
| 216 | + skb_mark_not_on_list(skb); |
|---|
| 216 | 217 | } |
|---|
| 217 | 218 | |
|---|
| 218 | 219 | /* Note that dequeue_skb can possibly return a SKB list (via skb->next). |
|---|
| .. | .. |
|---|
| 254 | 255 | skb = __skb_dequeue(&q->gso_skb); |
|---|
| 255 | 256 | if (qdisc_is_percpu_stats(q)) { |
|---|
| 256 | 257 | qdisc_qstats_cpu_backlog_dec(q, skb); |
|---|
| 257 | | - qdisc_qstats_atomic_qlen_dec(q); |
|---|
| 258 | + qdisc_qstats_cpu_qlen_dec(q); |
|---|
| 258 | 259 | } else { |
|---|
| 259 | 260 | qdisc_qstats_backlog_dec(q, skb); |
|---|
| 260 | 261 | q->q.qlen--; |
|---|
| 261 | 262 | } |
|---|
| 262 | 263 | } else { |
|---|
| 263 | 264 | skb = NULL; |
|---|
| 265 | + qdisc_maybe_clear_missed(q, txq); |
|---|
| 264 | 266 | } |
|---|
| 265 | 267 | if (lock) |
|---|
| 266 | 268 | spin_unlock(lock); |
|---|
| .. | .. |
|---|
| 270 | 272 | *validate = true; |
|---|
| 271 | 273 | |
|---|
| 272 | 274 | if ((q->flags & TCQ_F_ONETXQUEUE) && |
|---|
| 273 | | - netif_xmit_frozen_or_stopped(txq)) |
|---|
| 275 | + netif_xmit_frozen_or_stopped(txq)) { |
|---|
| 276 | + qdisc_maybe_clear_missed(q, txq); |
|---|
| 274 | 277 | return skb; |
|---|
| 278 | + } |
|---|
| 275 | 279 | |
|---|
| 276 | 280 | skb = qdisc_dequeue_skb_bad_txq(q); |
|---|
| 277 | 281 | if (unlikely(skb)) { |
|---|
| .. | .. |
|---|
| 330 | 334 | HARD_TX_LOCK(dev, txq, smp_processor_id()); |
|---|
| 331 | 335 | if (!netif_xmit_frozen_or_stopped(txq)) |
|---|
| 332 | 336 | skb = dev_hard_start_xmit(skb, dev, txq, &ret); |
|---|
| 337 | + else |
|---|
| 338 | + qdisc_maybe_clear_missed(q, txq); |
|---|
| 333 | 339 | |
|---|
| 334 | 340 | HARD_TX_UNLOCK(dev, txq); |
|---|
| 335 | 341 | } else { |
|---|
| .. | .. |
|---|
| 397 | 403 | |
|---|
| 398 | 404 | void __qdisc_run(struct Qdisc *q) |
|---|
| 399 | 405 | { |
|---|
| 400 | | - int quota = dev_tx_weight; |
|---|
| 406 | + int quota = READ_ONCE(dev_tx_weight); |
|---|
| 401 | 407 | int packets; |
|---|
| 402 | 408 | |
|---|
| 403 | 409 | while (qdisc_restart(q, &packets)) { |
|---|
| 404 | | - /* |
|---|
| 405 | | - * Ordered by possible occurrence: Postpone processing if |
|---|
| 406 | | - * 1. we've exceeded packet quota |
|---|
| 407 | | - * 2. another process needs the CPU; |
|---|
| 408 | | - */ |
|---|
| 409 | 410 | quota -= packets; |
|---|
| 410 | | - if (quota <= 0 || need_resched()) { |
|---|
| 411 | + if (quota <= 0) { |
|---|
| 411 | 412 | __netif_schedule(q); |
|---|
| 412 | 413 | break; |
|---|
| 413 | 414 | } |
|---|
| .. | .. |
|---|
| 462 | 463 | } |
|---|
| 463 | 464 | |
|---|
| 464 | 465 | if (some_queue_timedout) { |
|---|
| 466 | + trace_net_dev_xmit_timeout(dev, i); |
|---|
| 465 | 467 | WARN_ONCE(1, KERN_INFO "NETDEV WATCHDOG: %s (%s): transmit queue %u timed out\n", |
|---|
| 466 | 468 | dev->name, netdev_drivername(dev), i); |
|---|
| 467 | | - dev->netdev_ops->ndo_tx_timeout(dev); |
|---|
| 469 | + dev->netdev_ops->ndo_tx_timeout(dev, i); |
|---|
| 468 | 470 | } |
|---|
| 469 | 471 | if (!mod_timer(&dev->watchdog_timer, |
|---|
| 470 | 472 | round_jiffies(jiffies + |
|---|
| .. | .. |
|---|
| 506 | 508 | * netif_carrier_on - set carrier |
|---|
| 507 | 509 | * @dev: network device |
|---|
| 508 | 510 | * |
|---|
| 509 | | - * Device has detected that carrier. |
|---|
| 511 | + * Device has detected acquisition of carrier. |
|---|
| 510 | 512 | */ |
|---|
| 511 | 513 | void netif_carrier_on(struct net_device *dev) |
|---|
| 512 | 514 | { |
|---|
| .. | .. |
|---|
| 565 | 567 | }; |
|---|
| 566 | 568 | |
|---|
| 567 | 569 | static struct netdev_queue noop_netdev_queue = { |
|---|
| 568 | | - .qdisc = &noop_qdisc, |
|---|
| 570 | + RCU_POINTER_INITIALIZER(qdisc, &noop_qdisc), |
|---|
| 569 | 571 | .qdisc_sleeping = &noop_qdisc, |
|---|
| 570 | 572 | }; |
|---|
| 571 | 573 | |
|---|
| .. | .. |
|---|
| 648 | 650 | |
|---|
| 649 | 651 | err = skb_array_produce(q, skb); |
|---|
| 650 | 652 | |
|---|
| 651 | | - if (unlikely(err)) |
|---|
| 652 | | - return qdisc_drop_cpu(skb, qdisc, to_free); |
|---|
| 653 | + if (unlikely(err)) { |
|---|
| 654 | + if (qdisc_is_percpu_stats(qdisc)) |
|---|
| 655 | + return qdisc_drop_cpu(skb, qdisc, to_free); |
|---|
| 656 | + else |
|---|
| 657 | + return qdisc_drop(skb, qdisc, to_free); |
|---|
| 658 | + } |
|---|
| 653 | 659 | |
|---|
| 654 | | - qdisc_qstats_atomic_qlen_inc(qdisc); |
|---|
| 655 | | - /* Note: skb can not be used after skb_array_produce(), |
|---|
| 656 | | - * so we better not use qdisc_qstats_cpu_backlog_inc() |
|---|
| 657 | | - */ |
|---|
| 658 | | - this_cpu_add(qdisc->cpu_qstats->backlog, pkt_len); |
|---|
| 660 | + qdisc_update_stats_at_enqueue(qdisc, pkt_len); |
|---|
| 659 | 661 | return NET_XMIT_SUCCESS; |
|---|
| 660 | 662 | } |
|---|
| 661 | 663 | |
|---|
| .. | .. |
|---|
| 663 | 665 | { |
|---|
| 664 | 666 | struct pfifo_fast_priv *priv = qdisc_priv(qdisc); |
|---|
| 665 | 667 | struct sk_buff *skb = NULL; |
|---|
| 668 | + bool need_retry = true; |
|---|
| 666 | 669 | int band; |
|---|
| 667 | 670 | |
|---|
| 671 | +retry: |
|---|
| 668 | 672 | for (band = 0; band < PFIFO_FAST_BANDS && !skb; band++) { |
|---|
| 669 | 673 | struct skb_array *q = band2list(priv, band); |
|---|
| 670 | 674 | |
|---|
| .. | .. |
|---|
| 674 | 678 | skb = __skb_array_consume(q); |
|---|
| 675 | 679 | } |
|---|
| 676 | 680 | if (likely(skb)) { |
|---|
| 677 | | - qdisc_qstats_cpu_backlog_dec(qdisc, skb); |
|---|
| 678 | | - qdisc_bstats_cpu_update(qdisc, skb); |
|---|
| 679 | | - qdisc_qstats_atomic_qlen_dec(qdisc); |
|---|
| 681 | + qdisc_update_stats_at_dequeue(qdisc, skb); |
|---|
| 682 | + } else if (need_retry && |
|---|
| 683 | + test_bit(__QDISC_STATE_MISSED, &qdisc->state)) { |
|---|
| 684 | + /* Delay clearing the STATE_MISSED here to reduce |
|---|
| 685 | + * the overhead of the second spin_trylock() in |
|---|
| 686 | + * qdisc_run_begin() and __netif_schedule() calling |
|---|
| 687 | + * in qdisc_run_end(). |
|---|
| 688 | + */ |
|---|
| 689 | + clear_bit(__QDISC_STATE_MISSED, &qdisc->state); |
|---|
| 690 | + |
|---|
| 691 | + /* Make sure dequeuing happens after clearing |
|---|
| 692 | + * STATE_MISSED. |
|---|
| 693 | + */ |
|---|
| 694 | + smp_mb__after_atomic(); |
|---|
| 695 | + |
|---|
| 696 | + need_retry = false; |
|---|
| 697 | + |
|---|
| 698 | + goto retry; |
|---|
| 699 | + } else { |
|---|
| 700 | + WRITE_ONCE(qdisc->empty, true); |
|---|
| 680 | 701 | } |
|---|
| 681 | 702 | |
|---|
| 682 | 703 | return skb; |
|---|
| .. | .. |
|---|
| 716 | 737 | kfree_skb(skb); |
|---|
| 717 | 738 | } |
|---|
| 718 | 739 | |
|---|
| 719 | | - for_each_possible_cpu(i) { |
|---|
| 720 | | - struct gnet_stats_queue *q = per_cpu_ptr(qdisc->cpu_qstats, i); |
|---|
| 740 | + if (qdisc_is_percpu_stats(qdisc)) { |
|---|
| 741 | + for_each_possible_cpu(i) { |
|---|
| 742 | + struct gnet_stats_queue *q; |
|---|
| 721 | 743 | |
|---|
| 722 | | - q->backlog = 0; |
|---|
| 744 | + q = per_cpu_ptr(qdisc->cpu_qstats, i); |
|---|
| 745 | + q->backlog = 0; |
|---|
| 746 | + q->qlen = 0; |
|---|
| 747 | + } |
|---|
| 723 | 748 | } |
|---|
| 724 | 749 | } |
|---|
| 725 | 750 | |
|---|
| .. | .. |
|---|
| 821 | 846 | const struct Qdisc_ops *ops, |
|---|
| 822 | 847 | struct netlink_ext_ack *extack) |
|---|
| 823 | 848 | { |
|---|
| 824 | | - void *p; |
|---|
| 825 | 849 | struct Qdisc *sch; |
|---|
| 826 | | - unsigned int size = QDISC_ALIGN(sizeof(*sch)) + ops->priv_size; |
|---|
| 850 | + unsigned int size = sizeof(*sch) + ops->priv_size; |
|---|
| 827 | 851 | int err = -ENOBUFS; |
|---|
| 828 | 852 | struct net_device *dev; |
|---|
| 829 | 853 | |
|---|
| .. | .. |
|---|
| 834 | 858 | } |
|---|
| 835 | 859 | |
|---|
| 836 | 860 | dev = dev_queue->dev; |
|---|
| 837 | | - p = kzalloc_node(size, GFP_KERNEL, |
|---|
| 838 | | - netdev_queue_numa_node_read(dev_queue)); |
|---|
| 861 | + sch = kzalloc_node(size, GFP_KERNEL, netdev_queue_numa_node_read(dev_queue)); |
|---|
| 839 | 862 | |
|---|
| 840 | | - if (!p) |
|---|
| 863 | + if (!sch) |
|---|
| 841 | 864 | goto errout; |
|---|
| 842 | | - sch = (struct Qdisc *) QDISC_ALIGN((unsigned long) p); |
|---|
| 843 | | - /* if we got non aligned memory, ask more and do alignment ourself */ |
|---|
| 844 | | - if (sch != p) { |
|---|
| 845 | | - kfree(p); |
|---|
| 846 | | - p = kzalloc_node(size + QDISC_ALIGNTO - 1, GFP_KERNEL, |
|---|
| 847 | | - netdev_queue_numa_node_read(dev_queue)); |
|---|
| 848 | | - if (!p) |
|---|
| 849 | | - goto errout; |
|---|
| 850 | | - sch = (struct Qdisc *) QDISC_ALIGN((unsigned long) p); |
|---|
| 851 | | - sch->padded = (char *) sch - (char *) p; |
|---|
| 852 | | - } |
|---|
| 853 | 865 | __skb_queue_head_init(&sch->gso_skb); |
|---|
| 854 | 866 | __skb_queue_head_init(&sch->skb_bad_txq); |
|---|
| 855 | 867 | qdisc_skb_head_init(&sch->q); |
|---|
| .. | .. |
|---|
| 874 | 886 | |
|---|
| 875 | 887 | /* seqlock has the same scope of busylock, for NOLOCK qdisc */ |
|---|
| 876 | 888 | spin_lock_init(&sch->seqlock); |
|---|
| 877 | | - lockdep_set_class(&sch->busylock, |
|---|
| 889 | + lockdep_set_class(&sch->seqlock, |
|---|
| 878 | 890 | dev->qdisc_tx_busylock ?: &qdisc_tx_busylock); |
|---|
| 879 | 891 | |
|---|
| 880 | 892 | seqcount_init(&sch->running); |
|---|
| .. | .. |
|---|
| 886 | 898 | sch->enqueue = ops->enqueue; |
|---|
| 887 | 899 | sch->dequeue = ops->dequeue; |
|---|
| 888 | 900 | sch->dev_queue = dev_queue; |
|---|
| 901 | + sch->empty = true; |
|---|
| 889 | 902 | dev_hold(dev); |
|---|
| 890 | 903 | refcount_set(&sch->refcnt, 1); |
|---|
| 891 | 904 | |
|---|
| 892 | 905 | return sch; |
|---|
| 893 | 906 | errout1: |
|---|
| 894 | | - kfree(p); |
|---|
| 907 | + kfree(sch); |
|---|
| 895 | 908 | errout: |
|---|
| 896 | 909 | return ERR_PTR(err); |
|---|
| 897 | 910 | } |
|---|
| .. | .. |
|---|
| 915 | 928 | } |
|---|
| 916 | 929 | sch->parent = parentid; |
|---|
| 917 | 930 | |
|---|
| 918 | | - if (!ops->init || ops->init(sch, NULL, extack) == 0) |
|---|
| 931 | + if (!ops->init || ops->init(sch, NULL, extack) == 0) { |
|---|
| 932 | + trace_qdisc_create(ops, dev_queue->dev, parentid); |
|---|
| 919 | 933 | return sch; |
|---|
| 934 | + } |
|---|
| 920 | 935 | |
|---|
| 921 | 936 | qdisc_put(sch); |
|---|
| 922 | 937 | return NULL; |
|---|
| .. | .. |
|---|
| 929 | 944 | { |
|---|
| 930 | 945 | const struct Qdisc_ops *ops = qdisc->ops; |
|---|
| 931 | 946 | struct sk_buff *skb, *tmp; |
|---|
| 947 | + |
|---|
| 948 | + trace_qdisc_reset(qdisc); |
|---|
| 932 | 949 | |
|---|
| 933 | 950 | if (ops->reset) |
|---|
| 934 | 951 | ops->reset(qdisc); |
|---|
| .. | .. |
|---|
| 955 | 972 | free_percpu(qdisc->cpu_qstats); |
|---|
| 956 | 973 | } |
|---|
| 957 | 974 | |
|---|
| 958 | | - kfree((char *) qdisc - qdisc->padded); |
|---|
| 975 | + kfree(qdisc); |
|---|
| 959 | 976 | } |
|---|
| 960 | 977 | |
|---|
| 961 | 978 | static void qdisc_free_cb(struct rcu_head *head) |
|---|
| .. | .. |
|---|
| 967 | 984 | |
|---|
| 968 | 985 | static void qdisc_destroy(struct Qdisc *qdisc) |
|---|
| 969 | 986 | { |
|---|
| 970 | | - const struct Qdisc_ops *ops; |
|---|
| 971 | | - struct sk_buff *skb, *tmp; |
|---|
| 972 | | - |
|---|
| 973 | | - if (!qdisc) |
|---|
| 974 | | - return; |
|---|
| 975 | | - ops = qdisc->ops; |
|---|
| 987 | + const struct Qdisc_ops *ops = qdisc->ops; |
|---|
| 976 | 988 | |
|---|
| 977 | 989 | #ifdef CONFIG_NET_SCHED |
|---|
| 978 | 990 | qdisc_hash_del(qdisc); |
|---|
| .. | .. |
|---|
| 980 | 992 | qdisc_put_stab(rtnl_dereference(qdisc->stab)); |
|---|
| 981 | 993 | #endif |
|---|
| 982 | 994 | gen_kill_estimator(&qdisc->rate_est); |
|---|
| 983 | | - if (ops->reset) |
|---|
| 984 | | - ops->reset(qdisc); |
|---|
| 995 | + |
|---|
| 996 | + qdisc_reset(qdisc); |
|---|
| 997 | + |
|---|
| 985 | 998 | if (ops->destroy) |
|---|
| 986 | 999 | ops->destroy(qdisc); |
|---|
| 987 | 1000 | |
|---|
| 988 | 1001 | module_put(ops->owner); |
|---|
| 989 | 1002 | dev_put(qdisc_dev(qdisc)); |
|---|
| 990 | 1003 | |
|---|
| 991 | | - skb_queue_walk_safe(&qdisc->gso_skb, skb, tmp) { |
|---|
| 992 | | - __skb_unlink(skb, &qdisc->gso_skb); |
|---|
| 993 | | - kfree_skb_list(skb); |
|---|
| 994 | | - } |
|---|
| 995 | | - |
|---|
| 996 | | - skb_queue_walk_safe(&qdisc->skb_bad_txq, skb, tmp) { |
|---|
| 997 | | - __skb_unlink(skb, &qdisc->skb_bad_txq); |
|---|
| 998 | | - kfree_skb_list(skb); |
|---|
| 999 | | - } |
|---|
| 1004 | + trace_qdisc_destroy(qdisc); |
|---|
| 1000 | 1005 | |
|---|
| 1001 | 1006 | call_rcu(&qdisc->rcu, qdisc_free_cb); |
|---|
| 1002 | 1007 | } |
|---|
| 1003 | 1008 | |
|---|
| 1004 | 1009 | void qdisc_put(struct Qdisc *qdisc) |
|---|
| 1005 | 1010 | { |
|---|
| 1011 | + if (!qdisc) |
|---|
| 1012 | + return; |
|---|
| 1013 | + |
|---|
| 1006 | 1014 | if (qdisc->flags & TCQ_F_BUILTIN || |
|---|
| 1007 | 1015 | !refcount_dec_and_test(&qdisc->refcnt)) |
|---|
| 1008 | 1016 | return; |
|---|
| .. | .. |
|---|
| 1049 | 1057 | } |
|---|
| 1050 | 1058 | EXPORT_SYMBOL(dev_graft_qdisc); |
|---|
| 1051 | 1059 | |
|---|
| 1060 | +static void shutdown_scheduler_queue(struct net_device *dev, |
|---|
| 1061 | + struct netdev_queue *dev_queue, |
|---|
| 1062 | + void *_qdisc_default) |
|---|
| 1063 | +{ |
|---|
| 1064 | + struct Qdisc *qdisc = dev_queue->qdisc_sleeping; |
|---|
| 1065 | + struct Qdisc *qdisc_default = _qdisc_default; |
|---|
| 1066 | + |
|---|
| 1067 | + if (qdisc) { |
|---|
| 1068 | + rcu_assign_pointer(dev_queue->qdisc, qdisc_default); |
|---|
| 1069 | + dev_queue->qdisc_sleeping = qdisc_default; |
|---|
| 1070 | + |
|---|
| 1071 | + qdisc_put(qdisc); |
|---|
| 1072 | + } |
|---|
| 1073 | +} |
|---|
| 1074 | + |
|---|
| 1052 | 1075 | static void attach_one_default_qdisc(struct net_device *dev, |
|---|
| 1053 | 1076 | struct netdev_queue *dev_queue, |
|---|
| 1054 | 1077 | void *_unused) |
|---|
| .. | .. |
|---|
| 1058 | 1081 | |
|---|
| 1059 | 1082 | if (dev->priv_flags & IFF_NO_QUEUE) |
|---|
| 1060 | 1083 | ops = &noqueue_qdisc_ops; |
|---|
| 1084 | + else if(dev->type == ARPHRD_CAN) |
|---|
| 1085 | + ops = &pfifo_fast_ops; |
|---|
| 1061 | 1086 | |
|---|
| 1062 | 1087 | qdisc = qdisc_create_dflt(dev_queue, ops, TC_H_ROOT, NULL); |
|---|
| 1063 | | - if (!qdisc) { |
|---|
| 1064 | | - netdev_info(dev, "activation failed\n"); |
|---|
| 1088 | + if (!qdisc) |
|---|
| 1065 | 1089 | return; |
|---|
| 1066 | | - } |
|---|
| 1090 | + |
|---|
| 1067 | 1091 | if (!netif_is_multiqueue(dev)) |
|---|
| 1068 | 1092 | qdisc->flags |= TCQ_F_ONETXQUEUE | TCQ_F_NOPARENT; |
|---|
| 1069 | 1093 | dev_queue->qdisc_sleeping = qdisc; |
|---|
| .. | .. |
|---|
| 1079 | 1103 | if (!netif_is_multiqueue(dev) || |
|---|
| 1080 | 1104 | dev->priv_flags & IFF_NO_QUEUE) { |
|---|
| 1081 | 1105 | netdev_for_each_tx_queue(dev, attach_one_default_qdisc, NULL); |
|---|
| 1082 | | - dev->qdisc = txq->qdisc_sleeping; |
|---|
| 1083 | | - qdisc_refcount_inc(dev->qdisc); |
|---|
| 1106 | + qdisc = txq->qdisc_sleeping; |
|---|
| 1107 | + rcu_assign_pointer(dev->qdisc, qdisc); |
|---|
| 1108 | + qdisc_refcount_inc(qdisc); |
|---|
| 1084 | 1109 | } else { |
|---|
| 1085 | 1110 | qdisc = qdisc_create_dflt(txq, &mq_qdisc_ops, TC_H_ROOT, NULL); |
|---|
| 1086 | 1111 | if (qdisc) { |
|---|
| 1087 | | - dev->qdisc = qdisc; |
|---|
| 1112 | + rcu_assign_pointer(dev->qdisc, qdisc); |
|---|
| 1088 | 1113 | qdisc->ops->attach(qdisc); |
|---|
| 1089 | 1114 | } |
|---|
| 1090 | 1115 | } |
|---|
| 1116 | + qdisc = rtnl_dereference(dev->qdisc); |
|---|
| 1117 | + |
|---|
| 1118 | + /* Detect default qdisc setup/init failed and fallback to "noqueue" */ |
|---|
| 1119 | + if (qdisc == &noop_qdisc) { |
|---|
| 1120 | + netdev_warn(dev, "default qdisc (%s) fail, fallback to %s\n", |
|---|
| 1121 | + default_qdisc_ops->id, noqueue_qdisc_ops.id); |
|---|
| 1122 | + netdev_for_each_tx_queue(dev, shutdown_scheduler_queue, &noop_qdisc); |
|---|
| 1123 | + dev->priv_flags |= IFF_NO_QUEUE; |
|---|
| 1124 | + netdev_for_each_tx_queue(dev, attach_one_default_qdisc, NULL); |
|---|
| 1125 | + qdisc = txq->qdisc_sleeping; |
|---|
| 1126 | + rcu_assign_pointer(dev->qdisc, qdisc); |
|---|
| 1127 | + qdisc_refcount_inc(qdisc); |
|---|
| 1128 | + dev->priv_flags ^= IFF_NO_QUEUE; |
|---|
| 1129 | + } |
|---|
| 1130 | + |
|---|
| 1091 | 1131 | #ifdef CONFIG_NET_SCHED |
|---|
| 1092 | | - if (dev->qdisc != &noop_qdisc) |
|---|
| 1093 | | - qdisc_hash_add(dev->qdisc, false); |
|---|
| 1132 | + if (qdisc != &noop_qdisc) |
|---|
| 1133 | + qdisc_hash_add(qdisc, false); |
|---|
| 1094 | 1134 | #endif |
|---|
| 1095 | 1135 | } |
|---|
| 1096 | 1136 | |
|---|
| .. | .. |
|---|
| 1120 | 1160 | * and noqueue_qdisc for virtual interfaces |
|---|
| 1121 | 1161 | */ |
|---|
| 1122 | 1162 | |
|---|
| 1123 | | - if (dev->qdisc == &noop_qdisc) |
|---|
| 1163 | + if (rtnl_dereference(dev->qdisc) == &noop_qdisc) |
|---|
| 1124 | 1164 | attach_default_qdiscs(dev); |
|---|
| 1125 | 1165 | |
|---|
| 1126 | 1166 | if (!netif_carrier_ok(dev)) |
|---|
| .. | .. |
|---|
| 1139 | 1179 | } |
|---|
| 1140 | 1180 | EXPORT_SYMBOL(dev_activate); |
|---|
| 1141 | 1181 | |
|---|
| 1182 | +static void qdisc_deactivate(struct Qdisc *qdisc) |
|---|
| 1183 | +{ |
|---|
| 1184 | + if (qdisc->flags & TCQ_F_BUILTIN) |
|---|
| 1185 | + return; |
|---|
| 1186 | + |
|---|
| 1187 | + set_bit(__QDISC_STATE_DEACTIVATED, &qdisc->state); |
|---|
| 1188 | +} |
|---|
| 1189 | + |
|---|
| 1142 | 1190 | static void dev_deactivate_queue(struct net_device *dev, |
|---|
| 1143 | 1191 | struct netdev_queue *dev_queue, |
|---|
| 1144 | 1192 | void *_qdisc_default) |
|---|
| 1145 | 1193 | { |
|---|
| 1146 | | - struct Qdisc *qdisc = rtnl_dereference(dev_queue->qdisc); |
|---|
| 1147 | 1194 | struct Qdisc *qdisc_default = _qdisc_default; |
|---|
| 1195 | + struct Qdisc *qdisc; |
|---|
| 1148 | 1196 | |
|---|
| 1197 | + qdisc = rtnl_dereference(dev_queue->qdisc); |
|---|
| 1149 | 1198 | if (qdisc) { |
|---|
| 1150 | | - if (!(qdisc->flags & TCQ_F_BUILTIN)) |
|---|
| 1151 | | - set_bit(__QDISC_STATE_DEACTIVATED, &qdisc->state); |
|---|
| 1152 | | - |
|---|
| 1199 | + qdisc_deactivate(qdisc); |
|---|
| 1153 | 1200 | rcu_assign_pointer(dev_queue->qdisc, qdisc_default); |
|---|
| 1154 | 1201 | } |
|---|
| 1155 | 1202 | } |
|---|
| .. | .. |
|---|
| 1174 | 1221 | qdisc_reset(qdisc); |
|---|
| 1175 | 1222 | |
|---|
| 1176 | 1223 | spin_unlock_bh(qdisc_lock(qdisc)); |
|---|
| 1177 | | - if (nolock) |
|---|
| 1224 | + if (nolock) { |
|---|
| 1225 | + clear_bit(__QDISC_STATE_MISSED, &qdisc->state); |
|---|
| 1178 | 1226 | spin_unlock_bh(&qdisc->seqlock); |
|---|
| 1227 | + } |
|---|
| 1179 | 1228 | } |
|---|
| 1180 | 1229 | |
|---|
| 1181 | 1230 | static bool some_qdisc_is_busy(struct net_device *dev) |
|---|
| .. | .. |
|---|
| 1203 | 1252 | return true; |
|---|
| 1204 | 1253 | } |
|---|
| 1205 | 1254 | return false; |
|---|
| 1206 | | -} |
|---|
| 1207 | | - |
|---|
| 1208 | | -static void dev_qdisc_reset(struct net_device *dev, |
|---|
| 1209 | | - struct netdev_queue *dev_queue, |
|---|
| 1210 | | - void *none) |
|---|
| 1211 | | -{ |
|---|
| 1212 | | - struct Qdisc *qdisc = dev_queue->qdisc_sleeping; |
|---|
| 1213 | | - |
|---|
| 1214 | | - if (qdisc) |
|---|
| 1215 | | - qdisc_reset(qdisc); |
|---|
| 1216 | 1255 | } |
|---|
| 1217 | 1256 | |
|---|
| 1218 | 1257 | /** |
|---|
| .. | .. |
|---|
| 1252 | 1291 | |
|---|
| 1253 | 1292 | /* Wait for outstanding qdisc_run calls. */ |
|---|
| 1254 | 1293 | list_for_each_entry(dev, head, close_list) { |
|---|
| 1255 | | - while (some_qdisc_is_busy(dev)) |
|---|
| 1256 | | - yield(); |
|---|
| 1257 | | - /* The new qdisc is assigned at this point so we can safely |
|---|
| 1258 | | - * unwind stale skb lists and qdisc statistics |
|---|
| 1259 | | - */ |
|---|
| 1260 | | - netdev_for_each_tx_queue(dev, dev_qdisc_reset, NULL); |
|---|
| 1261 | | - if (dev_ingress_queue(dev)) |
|---|
| 1262 | | - dev_qdisc_reset(dev, dev_ingress_queue(dev), NULL); |
|---|
| 1294 | + while (some_qdisc_is_busy(dev)) { |
|---|
| 1295 | + /* wait_event() would avoid this sleep-loop but would |
|---|
| 1296 | + * require expensive checks in the fast paths of packet |
|---|
| 1297 | + * processing which isn't worth it. |
|---|
| 1298 | + */ |
|---|
| 1299 | + schedule_timeout_uninterruptible(1); |
|---|
| 1300 | + } |
|---|
| 1263 | 1301 | } |
|---|
| 1264 | 1302 | } |
|---|
| 1265 | 1303 | |
|---|
| .. | .. |
|---|
| 1318 | 1356 | |
|---|
| 1319 | 1357 | void dev_init_scheduler(struct net_device *dev) |
|---|
| 1320 | 1358 | { |
|---|
| 1321 | | - dev->qdisc = &noop_qdisc; |
|---|
| 1359 | + rcu_assign_pointer(dev->qdisc, &noop_qdisc); |
|---|
| 1322 | 1360 | netdev_for_each_tx_queue(dev, dev_init_scheduler_queue, &noop_qdisc); |
|---|
| 1323 | 1361 | if (dev_ingress_queue(dev)) |
|---|
| 1324 | 1362 | dev_init_scheduler_queue(dev, dev_ingress_queue(dev), &noop_qdisc); |
|---|
| .. | .. |
|---|
| 1326 | 1364 | timer_setup(&dev->watchdog_timer, dev_watchdog, 0); |
|---|
| 1327 | 1365 | } |
|---|
| 1328 | 1366 | |
|---|
| 1329 | | -static void shutdown_scheduler_queue(struct net_device *dev, |
|---|
| 1330 | | - struct netdev_queue *dev_queue, |
|---|
| 1331 | | - void *_qdisc_default) |
|---|
| 1332 | | -{ |
|---|
| 1333 | | - struct Qdisc *qdisc = dev_queue->qdisc_sleeping; |
|---|
| 1334 | | - struct Qdisc *qdisc_default = _qdisc_default; |
|---|
| 1335 | | - |
|---|
| 1336 | | - if (qdisc) { |
|---|
| 1337 | | - rcu_assign_pointer(dev_queue->qdisc, qdisc_default); |
|---|
| 1338 | | - dev_queue->qdisc_sleeping = qdisc_default; |
|---|
| 1339 | | - |
|---|
| 1340 | | - qdisc_put(qdisc); |
|---|
| 1341 | | - } |
|---|
| 1342 | | -} |
|---|
| 1343 | | - |
|---|
| 1344 | 1367 | void dev_shutdown(struct net_device *dev) |
|---|
| 1345 | 1368 | { |
|---|
| 1346 | 1369 | netdev_for_each_tx_queue(dev, shutdown_scheduler_queue, &noop_qdisc); |
|---|
| 1347 | 1370 | if (dev_ingress_queue(dev)) |
|---|
| 1348 | 1371 | shutdown_scheduler_queue(dev, dev_ingress_queue(dev), &noop_qdisc); |
|---|
| 1349 | | - qdisc_put(dev->qdisc); |
|---|
| 1350 | | - dev->qdisc = &noop_qdisc; |
|---|
| 1372 | + qdisc_put(rtnl_dereference(dev->qdisc)); |
|---|
| 1373 | + rcu_assign_pointer(dev->qdisc, &noop_qdisc); |
|---|
| 1351 | 1374 | |
|---|
| 1352 | 1375 | WARN_ON(timer_pending(&dev->watchdog_timer)); |
|---|
| 1353 | 1376 | } |
|---|
| .. | .. |
|---|
| 1396 | 1419 | void mini_qdisc_pair_swap(struct mini_Qdisc_pair *miniqp, |
|---|
| 1397 | 1420 | struct tcf_proto *tp_head) |
|---|
| 1398 | 1421 | { |
|---|
| 1399 | | - struct mini_Qdisc *miniq_old = rtnl_dereference(*miniqp->p_miniq); |
|---|
| 1422 | + /* Protected with chain0->filter_chain_lock. |
|---|
| 1423 | + * Can't access chain directly because tp_head can be NULL. |
|---|
| 1424 | + */ |
|---|
| 1425 | + struct mini_Qdisc *miniq_old = |
|---|
| 1426 | + rcu_dereference_protected(*miniqp->p_miniq, 1); |
|---|
| 1400 | 1427 | struct mini_Qdisc *miniq; |
|---|
| 1401 | 1428 | |
|---|
| 1402 | 1429 | if (!tp_head) { |
|---|
| 1403 | 1430 | RCU_INIT_POINTER(*miniqp->p_miniq, NULL); |
|---|
| 1404 | 1431 | /* Wait for flying RCU callback before it is freed. */ |
|---|
| 1405 | | - rcu_barrier_bh(); |
|---|
| 1432 | + rcu_barrier(); |
|---|
| 1406 | 1433 | return; |
|---|
| 1407 | 1434 | } |
|---|
| 1408 | 1435 | |
|---|
| .. | .. |
|---|
| 1410 | 1437 | &miniqp->miniq1 : &miniqp->miniq2; |
|---|
| 1411 | 1438 | |
|---|
| 1412 | 1439 | /* We need to make sure that readers won't see the miniq |
|---|
| 1413 | | - * we are about to modify. So wait until previous call_rcu_bh callback |
|---|
| 1440 | + * we are about to modify. So wait until previous call_rcu callback |
|---|
| 1414 | 1441 | * is done. |
|---|
| 1415 | 1442 | */ |
|---|
| 1416 | | - rcu_barrier_bh(); |
|---|
| 1443 | + rcu_barrier(); |
|---|
| 1417 | 1444 | miniq->filter_list = tp_head; |
|---|
| 1418 | 1445 | rcu_assign_pointer(*miniqp->p_miniq, miniq); |
|---|
| 1419 | 1446 | |
|---|
| .. | .. |
|---|
| 1422 | 1449 | * block potential new user of miniq_old until all readers |
|---|
| 1423 | 1450 | * are not seeing it. |
|---|
| 1424 | 1451 | */ |
|---|
| 1425 | | - call_rcu_bh(&miniq_old->rcu, mini_qdisc_rcu_func); |
|---|
| 1452 | + call_rcu(&miniq_old->rcu, mini_qdisc_rcu_func); |
|---|
| 1426 | 1453 | } |
|---|
| 1427 | 1454 | EXPORT_SYMBOL(mini_qdisc_pair_swap); |
|---|
| 1428 | 1455 | |
|---|
| 1456 | +void mini_qdisc_pair_block_init(struct mini_Qdisc_pair *miniqp, |
|---|
| 1457 | + struct tcf_block *block) |
|---|
| 1458 | +{ |
|---|
| 1459 | + miniqp->miniq1.block = block; |
|---|
| 1460 | + miniqp->miniq2.block = block; |
|---|
| 1461 | +} |
|---|
| 1462 | +EXPORT_SYMBOL(mini_qdisc_pair_block_init); |
|---|
| 1463 | + |
|---|
| 1429 | 1464 | void mini_qdisc_pair_init(struct mini_Qdisc_pair *miniqp, struct Qdisc *qdisc, |
|---|
| 1430 | 1465 | struct mini_Qdisc __rcu **p_miniq) |
|---|
| 1431 | 1466 | { |
|---|