diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h index cefe0c4bdae3..f9f99df037ed 100644 --- a/include/net/sch_generic.h +++ b/include/net/sch_generic.h @@ -125,6 +125,8 @@ struct Qdisc { spinlock_t busylock ____cacheline_aligned_in_smp; spinlock_t seqlock; + u16 __percpu *xmit_recursion; + struct rcu_head rcu; netdevice_tracker dev_tracker; /* private data */ diff --git a/net/core/dev.c b/net/core/dev.c index 9a67003e49db..2b712388c06f 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3789,6 +3789,13 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q, if (unlikely(contended)) spin_lock(&q->busylock); + if (__this_cpu_read(*q->xmit_recursion) > 0) { + __qdisc_drop(skb, &to_free); + rc = NET_XMIT_DROP; + goto free_skb_list; + } + + __this_cpu_inc(*q->xmit_recursion); spin_lock(root_lock); if (unlikely(test_bit(__QDISC_STATE_DEACTIVATED, &q->state))) { __qdisc_drop(skb, &to_free); @@ -3825,7 +3832,9 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q, } } spin_unlock(root_lock); + __this_cpu_dec(*q->xmit_recursion); if (unlikely(to_free)) +free_skb_list: kfree_skb_list_reason(to_free, tcf_get_drop_reason(to_free)); if (unlikely(contended)) diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c index 65e05b0c98e4..6c3bc1aff89a 100644 --- a/net/sched/sch_api.c +++ b/net/sched/sch_api.c @@ -1260,6 +1260,7 @@ static struct Qdisc *qdisc_create(struct net_device *dev, struct Qdisc *sch; struct Qdisc_ops *ops; struct qdisc_size_table *stab; + int cpu; ops = qdisc_lookup_ops(kind); #ifdef CONFIG_MODULES @@ -1376,11 +1377,22 @@ static struct Qdisc *qdisc_create(struct net_device *dev, } } + sch->xmit_recursion = alloc_percpu(u16); + if (!sch->xmit_recursion) { + err = -ENOMEM; + goto err_out5; + } + for_each_possible_cpu(cpu) + (*per_cpu_ptr(sch->xmit_recursion, cpu)) = 0; + qdisc_hash_add(sch, false); trace_qdisc_create(ops, dev, parent); return sch; +err_out5: + if (tca[TCA_RATE]) + gen_kill_estimator(&sch->rate_est); err_out4: /* Even if ops->init() failed, we call ops->destroy() * like qdisc_create_dflt(). diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c index ff5336493777..afbbd2e885a4 100644 --- a/net/sched/sch_generic.c +++ b/net/sched/sch_generic.c @@ -1070,6 +1070,8 @@ static void __qdisc_destroy(struct Qdisc *qdisc) module_put(ops->owner); netdev_put(dev, &qdisc->dev_tracker); + free_percpu(qdisc->xmit_recursion); + trace_qdisc_destroy(qdisc); call_rcu(&qdisc->rcu, qdisc_free_cb);