Commit 48d83325 authored by Herbert Xu's avatar Herbert Xu Committed by David S. Miller

[NET]: Prevent multiple qdisc runs

Having two or more qdisc_run's contend against each other is bad because
it can induce packet reordering if the packets have to be requeued.  It
appears that this is an unintended consequence of relinquinshing the queue
lock while transmitting.  That in turn is needed for devices that spend a
lot of time in their transmit routine.

There are no advantages to be had as devices with queues are inherently
single-threaded (the loopback device is not but then it doesn't have a
queue).

Even if you were to add a queue to a parallel virtual device (e.g., bolt
a tbf filter in front of an ipip tunnel device), you would still want to
process the queue in sequence to ensure that the packets are ordered
correctly.

The solution here is to steal a bit from net_device to prevent this.

BTW, as qdisc_restart is no longer used by anyone as a module inside the
kernel (IIRC it used to with netif_wake_queue), I have not exported the
new __qdisc_run function.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d6cc7f1a
...@@ -233,6 +233,7 @@ enum netdev_state_t ...@@ -233,6 +233,7 @@ enum netdev_state_t
__LINK_STATE_RX_SCHED, __LINK_STATE_RX_SCHED,
__LINK_STATE_LINKWATCH_PENDING, __LINK_STATE_LINKWATCH_PENDING,
__LINK_STATE_DORMANT, __LINK_STATE_DORMANT,
__LINK_STATE_QDISC_RUNNING,
}; };
......
...@@ -218,12 +218,13 @@ extern struct qdisc_rate_table *qdisc_get_rtab(struct tc_ratespec *r, ...@@ -218,12 +218,13 @@ extern struct qdisc_rate_table *qdisc_get_rtab(struct tc_ratespec *r,
struct rtattr *tab); struct rtattr *tab);
extern void qdisc_put_rtab(struct qdisc_rate_table *tab); extern void qdisc_put_rtab(struct qdisc_rate_table *tab);
extern int qdisc_restart(struct net_device *dev); extern void __qdisc_run(struct net_device *dev);
static inline void qdisc_run(struct net_device *dev) static inline void qdisc_run(struct net_device *dev)
{ {
while (!netif_queue_stopped(dev) && qdisc_restart(dev) < 0) if (!netif_queue_stopped(dev) &&
/* NOTHING */; !test_and_set_bit(__LINK_STATE_QDISC_RUNNING, &dev->state))
__qdisc_run(dev);
} }
extern int tc_classify(struct sk_buff *skb, struct tcf_proto *tp, extern int tc_classify(struct sk_buff *skb, struct tcf_proto *tp,
......
...@@ -90,7 +90,7 @@ void qdisc_unlock_tree(struct net_device *dev) ...@@ -90,7 +90,7 @@ void qdisc_unlock_tree(struct net_device *dev)
NOTE: Called under dev->queue_lock with locally disabled BH. NOTE: Called under dev->queue_lock with locally disabled BH.
*/ */
int qdisc_restart(struct net_device *dev) static inline int qdisc_restart(struct net_device *dev)
{ {
struct Qdisc *q = dev->qdisc; struct Qdisc *q = dev->qdisc;
struct sk_buff *skb; struct sk_buff *skb;
...@@ -179,6 +179,14 @@ int qdisc_restart(struct net_device *dev) ...@@ -179,6 +179,14 @@ int qdisc_restart(struct net_device *dev)
return q->q.qlen; return q->q.qlen;
} }
void __qdisc_run(struct net_device *dev)
{
while (qdisc_restart(dev) < 0 && !netif_queue_stopped(dev))
/* NOTHING */;
clear_bit(__LINK_STATE_QDISC_RUNNING, &dev->state);
}
static void dev_watchdog(unsigned long arg) static void dev_watchdog(unsigned long arg)
{ {
struct net_device *dev = (struct net_device *)arg; struct net_device *dev = (struct net_device *)arg;
...@@ -620,6 +628,5 @@ EXPORT_SYMBOL(qdisc_create_dflt); ...@@ -620,6 +628,5 @@ EXPORT_SYMBOL(qdisc_create_dflt);
EXPORT_SYMBOL(qdisc_alloc); EXPORT_SYMBOL(qdisc_alloc);
EXPORT_SYMBOL(qdisc_destroy); EXPORT_SYMBOL(qdisc_destroy);
EXPORT_SYMBOL(qdisc_reset); EXPORT_SYMBOL(qdisc_reset);
EXPORT_SYMBOL(qdisc_restart);
EXPORT_SYMBOL(qdisc_lock_tree); EXPORT_SYMBOL(qdisc_lock_tree);
EXPORT_SYMBOL(qdisc_unlock_tree); EXPORT_SYMBOL(qdisc_unlock_tree);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment