Changeset 31312


Ignore:
Timestamp:
2012-04-16T17:04:44+02:00 (6 years ago)
Author:
jow
Message:

Update ppp TX restart patch to avoid race condition

Signed-off-by: David Woodhouse <David.Woodhouse@…>

Location:
trunk/target/linux/generic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/target/linux/generic/patches-3.2/120-ppp_txqueue_restart.patch

    r31158 r31312  
    1 For every transmitted packet, ppp_start_xmit() will stop the netdev 
    2 queue and then, if appropriate, restart it. This causes the TX softirq 
    3 to run, entirely gratuitously. 
     1commit 9a5d2bd99e0dfe9a31b3c160073ac445ba3d773f 
     2Author: David Woodhouse <dwmw2@infradead.org> 
     3Date:   Sun Apr 8 10:01:44 2012 +0000 
    44 
    5 This is "only" a waste of CPU time in the normal case, but it's actively 
    6 harmful when the PPP device is a TEQL slave — the wakeup will cause the 
    7 offending device to receive the next TX packet from the TEQL queue, when 
    8 it *should* have gone to the next slave in the list. We end up seeing 
    9 large bursts of packets on just *one* slave device, rather than using 
    10 the full available bandwidth over all slaves. 
     5    ppp: Fix race condition with queue start/stop 
     6     
     7    Commit e675f0cc9a872fd152edc0c77acfed19bf28b81e ("ppp: Don't stop and 
     8    restart queue on every TX packet") introduced a race condition which 
     9    could leave the net queue stopped even when the channel is no longer 
     10    busy. By calling netif_stop_queue() from ppp_start_xmit(), based on the 
     11    return value from ppp_xmit_process() but *after* all the locks have been 
     12    dropped, we could potentially do so *after* the channel has actually 
     13    finished transmitting and attempted to re-wake the queue. 
     14     
     15    Fix this by moving the netif_stop_queue() into ppp_xmit_process() under 
     16    the xmit lock. I hadn't done this previously, because it gets called 
     17    from other places than ppp_start_xmit(). But I now think it's the better 
     18    option. The net queue *should* be stopped if the channel becomes 
     19    congested due to writes from pppd, anyway. 
     20     
     21    Signed-off-by: David Woodhouse <David.Woodhouse@intel.com> 
     22    Signed-off-by: David S. Miller <davem@davemloft.net> 
    1123 
    12 This patch fixes the problem by *not* unconditionally stopping the queue 
    13 in ppp_start_xmit(). It adds a return value from ppp_xmit_process() 
    14 which indicates whether the queue should be stopped or not. 
     24commit e675f0cc9a872fd152edc0c77acfed19bf28b81e 
     25Author: David Woodhouse <dwmw2@infradead.org> 
     26Date:   Mon Mar 26 00:03:42 2012 +0000 
    1527 
    16 It *doesn't* remove the call to netif_wake_queue() from 
    17 ppp_xmit_process(), because other code paths (especially from 
    18 ppp_output_wakeup()) need it there and it's messy to push it out to the 
    19 other callers to do it based on the return value. So we leave it in 
    20 place — it's a no-op in the case where the queue wasn't stopped, so it's 
    21 harmless in the TX path. 
     28    ppp: Don't stop and restart queue on every TX packet 
     29     
     30    For every transmitted packet, ppp_start_xmit() will stop the netdev 
     31    queue and then, if appropriate, restart it. This causes the TX softirq 
     32    to run, entirely gratuitously. 
     33     
     34    This is "only" a waste of CPU time in the normal case, but it's actively 
     35    harmful when the PPP device is a TEQL slave — the wakeup will cause the 
     36    offending device to receive the next TX packet from the TEQL queue, when 
     37    it *should* have gone to the next slave in the list. We end up seeing 
     38    large bursts of packets on just *one* slave device, rather than using 
     39    the full available bandwidth over all slaves. 
     40     
     41    This patch fixes the problem by *not* unconditionally stopping the queue 
     42    in ppp_start_xmit(). It adds a return value from ppp_xmit_process() 
     43    which indicates whether the queue should be stopped or not. 
     44     
     45    It *doesn't* remove the call to netif_wake_queue() from 
     46    ppp_xmit_process(), because other code paths (especially from 
     47    ppp_output_wakeup()) need it there and it's messy to push it out to the 
     48    other callers to do it based on the return value. So we leave it in 
     49    place — it's a no-op in the case where the queue wasn't stopped, so it's 
     50    harmless in the TX path. 
     51     
     52    Signed-off-by: David Woodhouse <David.Woodhouse@intel.com> 
     53    Signed-off-by: David S. Miller <davem@davemloft.net> 
    2254 
    23 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com> 
    2455 
     56 
     57diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c 
     58index 159da29..21d7151 100644 
    2559--- a/drivers/net/ppp/ppp_generic.c 
    2660+++ b/drivers/net/ppp/ppp_generic.c 
    27 @@ -235,7 +235,7 @@ struct ppp_net { 
    28  /* Prototypes. */ 
    29  static int ppp_unattached_ioctl(struct net *net, struct ppp_file *pf, 
    30                         struct file *file, unsigned int cmd, unsigned long arg); 
    31 -static void ppp_xmit_process(struct ppp *ppp); 
    32 +static int ppp_xmit_process(struct ppp *ppp); 
    33  static void ppp_send_frame(struct ppp *ppp, struct sk_buff *skb); 
    34  static void ppp_push(struct ppp *ppp); 
    35  static void ppp_channel_push(struct channel *pch); 
    36 @@ -968,9 +968,9 @@ ppp_start_xmit(struct sk_buff *skb, stru 
     61@@ -968,7 +968,6 @@ ppp_start_xmit(struct sk_buff *skb, struct net_device *dev) 
    3762        proto = npindex_to_proto[npi]; 
    3863        put_unaligned_be16(proto, pp); 
     
    4065-       netif_stop_queue(dev); 
    4166        skb_queue_tail(&ppp->file.xq, skb); 
    42 -       ppp_xmit_process(ppp); 
    43 +       if (!ppp_xmit_process(ppp)) 
    44 +               netif_stop_queue(dev); 
     67        ppp_xmit_process(ppp); 
    4568        return NETDEV_TX_OK; 
    46   
    47   outf: 
    48 @@ -1048,10 +1048,11 @@ static void ppp_setup(struct net_device 
    49   * Called to do any work queued up on the transmit side 
    50   * that can now be done. 
    51   */ 
    52 -static void 
    53 +static int 
    54  ppp_xmit_process(struct ppp *ppp) 
    55  { 
    56         struct sk_buff *skb; 
    57 +       int ret = 0; 
    58   
    59         ppp_xmit_lock(ppp); 
    60         if (!ppp->closing) { 
    61 @@ -1061,10 +1062,13 @@ ppp_xmit_process(struct ppp *ppp) 
    62                         ppp_send_frame(ppp, skb); 
    63                 /* If there's no work left to do, tell the core net 
     69@@ -1063,6 +1062,8 @@ ppp_xmit_process(struct ppp *ppp) 
    6470                   code that we can accept some more. */ 
    65 -               if (!ppp->xmit_pending && !skb_peek(&ppp->file.xq)) 
    66 +               if (!ppp->xmit_pending && !skb_peek(&ppp->file.xq)) { 
     71                if (!ppp->xmit_pending && !skb_peek(&ppp->file.xq)) 
    6772                        netif_wake_queue(ppp->dev); 
    68 +                       ret = 1; 
    69 +               } 
     73+               else 
     74+                       netif_stop_queue(ppp->dev); 
    7075        } 
    7176        ppp_xmit_unlock(ppp); 
    72 +       return ret; 
    7377 } 
    74   
    75  static inline struct sk_buff * 
  • trunk/target/linux/generic/patches-3.3/120-ppp_txqueue_restart.patch

    r31223 r31312  
    1 For every transmitted packet, ppp_start_xmit() will stop the netdev 
    2 queue and then, if appropriate, restart it. This causes the TX softirq 
    3 to run, entirely gratuitously. 
     1commit 9a5d2bd99e0dfe9a31b3c160073ac445ba3d773f 
     2Author: David Woodhouse <dwmw2@infradead.org> 
     3Date:   Sun Apr 8 10:01:44 2012 +0000 
    44 
    5 This is "only" a waste of CPU time in the normal case, but it's actively 
    6 harmful when the PPP device is a TEQL slave — the wakeup will cause the 
    7 offending device to receive the next TX packet from the TEQL queue, when 
    8 it *should* have gone to the next slave in the list. We end up seeing 
    9 large bursts of packets on just *one* slave device, rather than using 
    10 the full available bandwidth over all slaves. 
     5    ppp: Fix race condition with queue start/stop 
     6     
     7    Commit e675f0cc9a872fd152edc0c77acfed19bf28b81e ("ppp: Don't stop and 
     8    restart queue on every TX packet") introduced a race condition which 
     9    could leave the net queue stopped even when the channel is no longer 
     10    busy. By calling netif_stop_queue() from ppp_start_xmit(), based on the 
     11    return value from ppp_xmit_process() but *after* all the locks have been 
     12    dropped, we could potentially do so *after* the channel has actually 
     13    finished transmitting and attempted to re-wake the queue. 
     14     
     15    Fix this by moving the netif_stop_queue() into ppp_xmit_process() under 
     16    the xmit lock. I hadn't done this previously, because it gets called 
     17    from other places than ppp_start_xmit(). But I now think it's the better 
     18    option. The net queue *should* be stopped if the channel becomes 
     19    congested due to writes from pppd, anyway. 
     20     
     21    Signed-off-by: David Woodhouse <David.Woodhouse@intel.com> 
     22    Signed-off-by: David S. Miller <davem@davemloft.net> 
    1123 
    12 This patch fixes the problem by *not* unconditionally stopping the queue 
    13 in ppp_start_xmit(). It adds a return value from ppp_xmit_process() 
    14 which indicates whether the queue should be stopped or not. 
     24commit e675f0cc9a872fd152edc0c77acfed19bf28b81e 
     25Author: David Woodhouse <dwmw2@infradead.org> 
     26Date:   Mon Mar 26 00:03:42 2012 +0000 
    1527 
    16 It *doesn't* remove the call to netif_wake_queue() from 
    17 ppp_xmit_process(), because other code paths (especially from 
    18 ppp_output_wakeup()) need it there and it's messy to push it out to the 
    19 other callers to do it based on the return value. So we leave it in 
    20 place — it's a no-op in the case where the queue wasn't stopped, so it's 
    21 harmless in the TX path. 
     28    ppp: Don't stop and restart queue on every TX packet 
     29     
     30    For every transmitted packet, ppp_start_xmit() will stop the netdev 
     31    queue and then, if appropriate, restart it. This causes the TX softirq 
     32    to run, entirely gratuitously. 
     33     
     34    This is "only" a waste of CPU time in the normal case, but it's actively 
     35    harmful when the PPP device is a TEQL slave — the wakeup will cause the 
     36    offending device to receive the next TX packet from the TEQL queue, when 
     37    it *should* have gone to the next slave in the list. We end up seeing 
     38    large bursts of packets on just *one* slave device, rather than using 
     39    the full available bandwidth over all slaves. 
     40     
     41    This patch fixes the problem by *not* unconditionally stopping the queue 
     42    in ppp_start_xmit(). It adds a return value from ppp_xmit_process() 
     43    which indicates whether the queue should be stopped or not. 
     44     
     45    It *doesn't* remove the call to netif_wake_queue() from 
     46    ppp_xmit_process(), because other code paths (especially from 
     47    ppp_output_wakeup()) need it there and it's messy to push it out to the 
     48    other callers to do it based on the return value. So we leave it in 
     49    place — it's a no-op in the case where the queue wasn't stopped, so it's 
     50    harmless in the TX path. 
     51     
     52    Signed-off-by: David Woodhouse <David.Woodhouse@intel.com> 
     53    Signed-off-by: David S. Miller <davem@davemloft.net> 
    2254 
    23 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com> 
    2455 
     56 
     57diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c 
     58index 159da29..21d7151 100644 
    2559--- a/drivers/net/ppp/ppp_generic.c 
    2660+++ b/drivers/net/ppp/ppp_generic.c 
    27 @@ -235,7 +235,7 @@ struct ppp_net { 
    28  /* Prototypes. */ 
    29  static int ppp_unattached_ioctl(struct net *net, struct ppp_file *pf, 
    30                         struct file *file, unsigned int cmd, unsigned long arg); 
    31 -static void ppp_xmit_process(struct ppp *ppp); 
    32 +static int ppp_xmit_process(struct ppp *ppp); 
    33  static void ppp_send_frame(struct ppp *ppp, struct sk_buff *skb); 
    34  static void ppp_push(struct ppp *ppp); 
    35  static void ppp_channel_push(struct channel *pch); 
    36 @@ -968,9 +968,9 @@ ppp_start_xmit(struct sk_buff *skb, stru 
     61@@ -968,7 +968,6 @@ ppp_start_xmit(struct sk_buff *skb, struct net_device *dev) 
    3762        proto = npindex_to_proto[npi]; 
    3863        put_unaligned_be16(proto, pp); 
     
    4065-       netif_stop_queue(dev); 
    4166        skb_queue_tail(&ppp->file.xq, skb); 
    42 -       ppp_xmit_process(ppp); 
    43 +       if (!ppp_xmit_process(ppp)) 
    44 +               netif_stop_queue(dev); 
     67        ppp_xmit_process(ppp); 
    4568        return NETDEV_TX_OK; 
    46   
    47   outf: 
    48 @@ -1048,10 +1048,11 @@ static void ppp_setup(struct net_device 
    49   * Called to do any work queued up on the transmit side 
    50   * that can now be done. 
    51   */ 
    52 -static void 
    53 +static int 
    54  ppp_xmit_process(struct ppp *ppp) 
    55  { 
    56         struct sk_buff *skb; 
    57 +       int ret = 0; 
    58   
    59         ppp_xmit_lock(ppp); 
    60         if (!ppp->closing) { 
    61 @@ -1061,10 +1062,13 @@ ppp_xmit_process(struct ppp *ppp) 
    62                         ppp_send_frame(ppp, skb); 
    63                 /* If there's no work left to do, tell the core net 
     69@@ -1063,6 +1062,8 @@ ppp_xmit_process(struct ppp *ppp) 
    6470                   code that we can accept some more. */ 
    65 -               if (!ppp->xmit_pending && !skb_peek(&ppp->file.xq)) 
    66 +               if (!ppp->xmit_pending && !skb_peek(&ppp->file.xq)) { 
     71                if (!ppp->xmit_pending && !skb_peek(&ppp->file.xq)) 
    6772                        netif_wake_queue(ppp->dev); 
    68 +                       ret = 1; 
    69 +               } 
     73+               else 
     74+                       netif_stop_queue(ppp->dev); 
    7075        } 
    7176        ppp_xmit_unlock(ppp); 
    72 +       return ret; 
    7377 } 
    74   
    75  static inline struct sk_buff * 
Note: See TracChangeset for help on using the changeset viewer.