netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] tuntap: Fix for a race in accessing numqueue
@ 2014-01-18  0:26 Dominic Curran
  2014-01-18  1:30 ` Eric Dumazet
  2014-01-18 17:43 ` Sergei Shtylyov
  0 siblings, 2 replies; 3+ messages in thread
From: Dominic Curran @ 2014-01-18  0:26 UTC (permalink / raw)
  To: netdev; +Cc: Dominic Curran, Jason Wang, Maxim Krasnyansky

A patch for fixing a race between queue selection and changing queues
was introduced in commit 92bb73ea2c434618a68a5.

The fix was to prevent the driver from re-reading the tun->numqueues
more than once within tun_select_queue().

We have been experiancing  'Divide-by-zero' errors in 
tun_net_xmit() since we moved from 3.6 to 3.10, and believe that they 
come from a simular source where the value of tun->numqueues changes 
to zero between the first and second read of tun->numqueues.

Signed-off-by: Dominic Curran <dominic.curran@citrix.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Maxim Krasnyansky <maxk@qualcomm.com>

---
 drivers/net/tun.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Index: net-next/drivers/net/tun.c
===================================================================
--- net-next.orig/drivers/net/tun.c	2014-01-17 23:41:54.000000000 +0000
+++ net-next/drivers/net/tun.c	2014-01-17 23:51:55.000000000 +0000
@@ -738,12 +738,14 @@ static netdev_tx_t tun_net_xmit(struct s
 	struct tun_struct *tun = netdev_priv(dev);
 	int txq = skb->queue_mapping;
 	struct tun_file *tfile;
+	u32 numqueues = 0;
 
 	rcu_read_lock();
 	tfile = rcu_dereference(tun->tfiles[txq]);
+	numqueues = ACCESS_ONCE(tun->numqueues);
 
 	/* Drop packet if interface is not attached */
-	if (txq >= tun->numqueues)
+	if (txq >= numqueues)
 		goto drop;
 
 	if (tun->numqueues == 1) {
@@ -780,7 +782,7 @@ static netdev_tx_t tun_net_xmit(struct s
 	 * number of queues.
 	 */
 	if (skb_queue_len(&tfile->socket.sk->sk_receive_queue)
-			  >= dev->tx_queue_len / tun->numqueues)
+			  >= dev->tx_queue_len / numqueues)
 		goto drop;
 
 	if (unlikely(skb_orphan_frags(skb, GFP_ATOMIC)))

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH] tuntap: Fix for a race in accessing numqueue
  2014-01-18  0:26 [RFC PATCH] tuntap: Fix for a race in accessing numqueue Dominic Curran
@ 2014-01-18  1:30 ` Eric Dumazet
  2014-01-18 17:43 ` Sergei Shtylyov
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2014-01-18  1:30 UTC (permalink / raw)
  To: Dominic Curran; +Cc: netdev, Jason Wang, Maxim Krasnyansky

On Sat, 2014-01-18 at 00:26 +0000, Dominic Curran wrote:
> A patch for fixing a race between queue selection and changing queues
> was introduced in commit 92bb73ea2c434618a68a5.
> 
> The fix was to prevent the driver from re-reading the tun->numqueues
> more than once within tun_select_queue().
> 
> We have been experiancing  'Divide-by-zero' errors in 
> tun_net_xmit() since we moved from 3.6 to 3.10, and believe that they 
> come from a simular source where the value of tun->numqueues changes 
> to zero between the first and second read of tun->numqueues.
> 
> Signed-off-by: Dominic Curran <dominic.curran@citrix.com>
> Cc: Jason Wang <jasowang@redhat.com>
> Cc: Maxim Krasnyansky <maxk@qualcomm.com>
> 
> ---
>  drivers/net/tun.c |    6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> Index: net-next/drivers/net/tun.c
> ===================================================================
> --- net-next.orig/drivers/net/tun.c	2014-01-17 23:41:54.000000000 +0000
> +++ net-next/drivers/net/tun.c	2014-01-17 23:51:55.000000000 +0000
> @@ -738,12 +738,14 @@ static netdev_tx_t tun_net_xmit(struct s
>  	struct tun_struct *tun = netdev_priv(dev);
>  	int txq = skb->queue_mapping;
>  	struct tun_file *tfile;
> +	u32 numqueues = 0;
>  
>  	rcu_read_lock();
>  	tfile = rcu_dereference(tun->tfiles[txq]);
> +	numqueues = ACCESS_ONCE(tun->numqueues);
>  
>  	/* Drop packet if interface is not attached */
> -	if (txq >= tun->numqueues)
> +	if (txq >= numqueues)
>  		goto drop;
>  
>  	if (tun->numqueues == 1) {

This is net-next tree, not net tree

(This part was added in commit 9bc8893937c83)

You might change this "tun->numqueues" as well.

> @@ -780,7 +782,7 @@ static netdev_tx_t tun_net_xmit(struct s
>  	 * number of queues.
>  	 */
>  	if (skb_queue_len(&tfile->socket.sk->sk_receive_queue)
> -			  >= dev->tx_queue_len / tun->numqueues)
> +			  >= dev->tx_queue_len / numqueues)
>  		goto drop;

Could use a multiply instead....

if (skb_queue_len(&tfile->socket.sk->sk_receive_queue) * numqueues >=
dev->tx_queue_len )


Please submit this patch on net tree, since its a bug fix.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH] tuntap: Fix for a race in accessing numqueue
  2014-01-18  0:26 [RFC PATCH] tuntap: Fix for a race in accessing numqueue Dominic Curran
  2014-01-18  1:30 ` Eric Dumazet
@ 2014-01-18 17:43 ` Sergei Shtylyov
  1 sibling, 0 replies; 3+ messages in thread
From: Sergei Shtylyov @ 2014-01-18 17:43 UTC (permalink / raw)
  To: Dominic Curran, netdev; +Cc: Jason Wang, Maxim Krasnyansky

Hello.

On 18-01-2014 4:26, Dominic Curran wrote:

> A patch for fixing a race between queue selection and changing queues
> was introduced in commit 92bb73ea2c434618a68a5.

    Please also specify that commit's summary line in parens.

> The fix was to prevent the driver from re-reading the tun->numqueues
> more than once within tun_select_queue().

> We have been experiancing  'Divide-by-zero' errors in
> tun_net_xmit() since we moved from 3.6 to 3.10, and believe that they
> come from a simular source where the value of tun->numqueues changes
> to zero between the first and second read of tun->numqueues.

> Signed-off-by: Dominic Curran <dominic.curran@citrix.com>
> Cc: Jason Wang <jasowang@redhat.com>
> Cc: Maxim Krasnyansky <maxk@qualcomm.com>

WBR, Sergei

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-01-18 17:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-18  0:26 [RFC PATCH] tuntap: Fix for a race in accessing numqueue Dominic Curran
2014-01-18  1:30 ` Eric Dumazet
2014-01-18 17:43 ` Sergei Shtylyov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).