netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [PATCH net-next] tun: fix multiqueue rx
@ 2018-11-16  4:10 Matthew Cover
  2018-11-16  6:29 ` Jason Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Matthew Cover @ 2018-11-16  4:10 UTC (permalink / raw)
  To: davem, jasowang, brouer, mst, edumazet, sd, netdev, matthew.cover

When writing packets to a descriptor associated with a combined queue, the
packets should end up on that queue.

Before this change all packets written to any descriptor associated with a
tap interface end up on rx-0, even when the descriptor is associated with a
different queue.

The rx traffic can be generated by either of the following.
  1. a simple tap program which spins up multiple queues and writes packets
     to each of the file descriptors
  2. tx from a qemu vm with a tap multiqueue netdev

The queue for rx traffic can be observed by either of the following (done
on the hypervisor in the qemu case).
  1. a simple netmap program which opens and reads from per-queue
     descriptors
  2. configuring RPS and doing per-cpu captures with rxtxcpu

Alternatively, if you printk() the return value of skb_get_rx_queue() just
before each instance of netif_receive_skb() in tun.c, you will get 65535
for every skb.

Calling skb_record_rx_queue() to set the rx queue to the queue_index fixes
the association between descriptor and rx queue.

Signed-off-by: Matthew Cover <matthew.cover@stackpath.com>
---
 drivers/net/tun.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index a65779c6d72f..4e306ff3501c 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1536,6 +1536,7 @@ static void tun_rx_batched(struct tun_struct *tun, struct tun_file *tfile,
 
 	if (!rx_batched || (!more && skb_queue_empty(queue))) {
 		local_bh_disable();
+		skb_record_rx_queue(skb, tfile->queue_index);
 		netif_receive_skb(skb);
 		local_bh_enable();
 		return;
@@ -1555,8 +1556,11 @@ static void tun_rx_batched(struct tun_struct *tun, struct tun_file *tfile,
 		struct sk_buff *nskb;
 
 		local_bh_disable();
-		while ((nskb = __skb_dequeue(&process_queue)))
+		while ((nskb = __skb_dequeue(&process_queue))) {
+			skb_record_rx_queue(nskb, tfile->queue_index);
 			netif_receive_skb(nskb);
+		}
+		skb_record_rx_queue(skb, tfile->queue_index);
 		netif_receive_skb(skb);
 		local_bh_enable();
 	}
-- 
2.15.2 (Apple Git-101.1)

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

* Re: [PATCH] [PATCH net-next] tun: fix multiqueue rx
  2018-11-16  4:10 [PATCH] [PATCH net-next] tun: fix multiqueue rx Matthew Cover
@ 2018-11-16  6:29 ` Jason Wang
  2018-11-16  7:00 ` Matthew Cover
  2018-11-18  4:39 ` [PATCH] [PATCH net-next] tun: " David Miller
  2 siblings, 0 replies; 10+ messages in thread
From: Jason Wang @ 2018-11-16  6:29 UTC (permalink / raw)
  To: Matthew Cover, davem, brouer, mst, edumazet, sd, netdev,
	matthew.cover


On 2018/11/16 下午12:10, Matthew Cover wrote:
> When writing packets to a descriptor associated with a combined queue, the
> packets should end up on that queue.
>
> Before this change all packets written to any descriptor associated with a
> tap interface end up on rx-0, even when the descriptor is associated with a
> different queue.
>
> The rx traffic can be generated by either of the following.
>    1. a simple tap program which spins up multiple queues and writes packets
>       to each of the file descriptors
>    2. tx from a qemu vm with a tap multiqueue netdev
>
> The queue for rx traffic can be observed by either of the following (done
> on the hypervisor in the qemu case).
>    1. a simple netmap program which opens and reads from per-queue
>       descriptors
>    2. configuring RPS and doing per-cpu captures with rxtxcpu
>
> Alternatively, if you printk() the return value of skb_get_rx_queue() just
> before each instance of netif_receive_skb() in tun.c, you will get 65535
> for every skb.
>
> Calling skb_record_rx_queue() to set the rx queue to the queue_index fixes
> the association between descriptor and rx queue.
>
> Signed-off-by: Matthew Cover <matthew.cover@stackpath.com>
> ---
>   drivers/net/tun.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index a65779c6d72f..4e306ff3501c 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -1536,6 +1536,7 @@ static void tun_rx_batched(struct tun_struct *tun, struct tun_file *tfile,
>   
>   	if (!rx_batched || (!more && skb_queue_empty(queue))) {
>   		local_bh_disable();
> +		skb_record_rx_queue(skb, tfile->queue_index);
>   		netif_receive_skb(skb);
>   		local_bh_enable();
>   		return;
> @@ -1555,8 +1556,11 @@ static void tun_rx_batched(struct tun_struct *tun, struct tun_file *tfile,
>   		struct sk_buff *nskb;
>   
>   		local_bh_disable();
> -		while ((nskb = __skb_dequeue(&process_queue)))
> +		while ((nskb = __skb_dequeue(&process_queue))) {
> +			skb_record_rx_queue(nskb, tfile->queue_index);
>   			netif_receive_skb(nskb);
> +		}
> +		skb_record_rx_queue(skb, tfile->queue_index);
>   		netif_receive_skb(skb);
>   		local_bh_enable();
>   	}


Thanks for the fix. Actually, there's another path which needs to be 
fixed as well in tun_xdp_one(). This path is used for vhost to pass a 
batched of packets.

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

* [PATCH] [PATCH net-next] tun: fix multiqueue rx
  2018-11-16  4:10 [PATCH] [PATCH net-next] tun: fix multiqueue rx Matthew Cover
  2018-11-16  6:29 ` Jason Wang
@ 2018-11-16  7:00 ` Matthew Cover
  2018-11-16  7:11   ` Jason Wang
                     ` (2 more replies)
  2018-11-18  4:39 ` [PATCH] [PATCH net-next] tun: " David Miller
  2 siblings, 3 replies; 10+ messages in thread
From: Matthew Cover @ 2018-11-16  7:00 UTC (permalink / raw)
  To: davem, jasowang, brouer, mst, edumazet, sd, netdev, matthew.cover

When writing packets to a descriptor associated with a combined queue, the
packets should end up on that queue.

Before this change all packets written to any descriptor associated with a
tap interface end up on rx-0, even when the descriptor is associated with a
different queue.

The rx traffic can be generated by either of the following.
  1. a simple tap program which spins up multiple queues and writes packets
     to each of the file descriptors
  2. tx from a qemu vm with a tap multiqueue netdev

The queue for rx traffic can be observed by either of the following (done
on the hypervisor in the qemu case).
  1. a simple netmap program which opens and reads from per-queue
     descriptors
  2. configuring RPS and doing per-cpu captures with rxtxcpu

Alternatively, if you printk() the return value of skb_get_rx_queue() just
before each instance of netif_receive_skb() in tun.c, you will get 65535
for every skb.

Calling skb_record_rx_queue() to set the rx queue to the queue_index fixes
the association between descriptor and rx queue.

Signed-off-by: Matthew Cover <matthew.cover@stackpath.com>
---
 drivers/net/tun.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index a65779c6d72f..ce8620f3ea5e 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1536,6 +1536,7 @@ static void tun_rx_batched(struct tun_struct *tun, struct tun_file *tfile,
 
 	if (!rx_batched || (!more && skb_queue_empty(queue))) {
 		local_bh_disable();
+		skb_record_rx_queue(skb, tfile->queue_index);
 		netif_receive_skb(skb);
 		local_bh_enable();
 		return;
@@ -1555,8 +1556,11 @@ static void tun_rx_batched(struct tun_struct *tun, struct tun_file *tfile,
 		struct sk_buff *nskb;
 
 		local_bh_disable();
-		while ((nskb = __skb_dequeue(&process_queue)))
+		while ((nskb = __skb_dequeue(&process_queue))) {
+			skb_record_rx_queue(nskb, tfile->queue_index);
 			netif_receive_skb(nskb);
+		}
+		skb_record_rx_queue(skb, tfile->queue_index);
 		netif_receive_skb(skb);
 		local_bh_enable();
 	}
@@ -2452,6 +2456,7 @@ static int tun_xdp_one(struct tun_struct *tun,
 	    !tfile->detached)
 		rxhash = __skb_get_hash_symmetric(skb);
 
+	skb_record_rx_queue(skb, tfile->queue_index);
 	netif_receive_skb(skb);
 
 	stats = get_cpu_ptr(tun->pcpu_stats);
-- 
2.15.2 (Apple Git-101.1)

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

* Re: [PATCH] [PATCH net-next] tun: fix multiqueue rx
  2018-11-16  7:00 ` Matthew Cover
@ 2018-11-16  7:11   ` Jason Wang
  2018-11-16 20:10   ` Michael S. Tsirkin
  2018-11-18  5:11   ` David Miller
  2 siblings, 0 replies; 10+ messages in thread
From: Jason Wang @ 2018-11-16  7:11 UTC (permalink / raw)
  To: Matthew Cover, davem, brouer, mst, edumazet, sd, netdev,
	matthew.cover


On 2018/11/16 下午3:00, Matthew Cover wrote:
> When writing packets to a descriptor associated with a combined queue, the
> packets should end up on that queue.
>
> Before this change all packets written to any descriptor associated with a
> tap interface end up on rx-0, even when the descriptor is associated with a
> different queue.
>
> The rx traffic can be generated by either of the following.
>    1. a simple tap program which spins up multiple queues and writes packets
>       to each of the file descriptors
>    2. tx from a qemu vm with a tap multiqueue netdev
>
> The queue for rx traffic can be observed by either of the following (done
> on the hypervisor in the qemu case).
>    1. a simple netmap program which opens and reads from per-queue
>       descriptors
>    2. configuring RPS and doing per-cpu captures with rxtxcpu
>
> Alternatively, if you printk() the return value of skb_get_rx_queue() just
> before each instance of netif_receive_skb() in tun.c, you will get 65535
> for every skb.
>
> Calling skb_record_rx_queue() to set the rx queue to the queue_index fixes
> the association between descriptor and rx queue.
>
> Signed-off-by: Matthew Cover <matthew.cover@stackpath.com>
> ---
>   drivers/net/tun.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index a65779c6d72f..ce8620f3ea5e 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -1536,6 +1536,7 @@ static void tun_rx_batched(struct tun_struct *tun, struct tun_file *tfile,
>   
>   	if (!rx_batched || (!more && skb_queue_empty(queue))) {
>   		local_bh_disable();
> +		skb_record_rx_queue(skb, tfile->queue_index);
>   		netif_receive_skb(skb);
>   		local_bh_enable();
>   		return;
> @@ -1555,8 +1556,11 @@ static void tun_rx_batched(struct tun_struct *tun, struct tun_file *tfile,
>   		struct sk_buff *nskb;
>   
>   		local_bh_disable();
> -		while ((nskb = __skb_dequeue(&process_queue)))
> +		while ((nskb = __skb_dequeue(&process_queue))) {
> +			skb_record_rx_queue(nskb, tfile->queue_index);
>   			netif_receive_skb(nskb);
> +		}
> +		skb_record_rx_queue(skb, tfile->queue_index);
>   		netif_receive_skb(skb);
>   		local_bh_enable();
>   	}
> @@ -2452,6 +2456,7 @@ static int tun_xdp_one(struct tun_struct *tun,
>   	    !tfile->detached)
>   		rxhash = __skb_get_hash_symmetric(skb);
>   
> +	skb_record_rx_queue(skb, tfile->queue_index);
>   	netif_receive_skb(skb);
>   
>   	stats = get_cpu_ptr(tun->pcpu_stats);


Acked-by: Jason Wang <jasowang@redhat.com>

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

* Re: [PATCH] [PATCH net-next] tun: fix multiqueue rx
  2018-11-16  7:00 ` Matthew Cover
  2018-11-16  7:11   ` Jason Wang
@ 2018-11-16 20:10   ` Michael S. Tsirkin
  2018-11-16 20:45     ` Matt Cover
  2018-11-18  5:11   ` David Miller
  2 siblings, 1 reply; 10+ messages in thread
From: Michael S. Tsirkin @ 2018-11-16 20:10 UTC (permalink / raw)
  To: Matthew Cover
  Cc: davem, jasowang, brouer, edumazet, sd, netdev, matthew.cover

On Fri, Nov 16, 2018 at 12:00:15AM -0700, Matthew Cover wrote:
> When writing packets to a descriptor associated with a combined queue, the
> packets should end up on that queue.
> 
> Before this change all packets written to any descriptor associated with a
> tap interface end up on rx-0, even when the descriptor is associated with a
> different queue.
> 
> The rx traffic can be generated by either of the following.
>   1. a simple tap program which spins up multiple queues and writes packets
>      to each of the file descriptors
>   2. tx from a qemu vm with a tap multiqueue netdev
> 
> The queue for rx traffic can be observed by either of the following (done
> on the hypervisor in the qemu case).
>   1. a simple netmap program which opens and reads from per-queue
>      descriptors
>   2. configuring RPS and doing per-cpu captures with rxtxcpu
> 
> Alternatively, if you printk() the return value of skb_get_rx_queue() just
> before each instance of netif_receive_skb() in tun.c, you will get 65535
> for every skb.
> 
> Calling skb_record_rx_queue() to set the rx queue to the queue_index fixes
> the association between descriptor and rx queue.
> 
> Signed-off-by: Matthew Cover <matthew.cover@stackpath.com>

Acked-by: Michael S. Tsirkin <mst@redhat.com>

stable material?

> ---
>  drivers/net/tun.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index a65779c6d72f..ce8620f3ea5e 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -1536,6 +1536,7 @@ static void tun_rx_batched(struct tun_struct *tun, struct tun_file *tfile,
>  
>  	if (!rx_batched || (!more && skb_queue_empty(queue))) {
>  		local_bh_disable();
> +		skb_record_rx_queue(skb, tfile->queue_index);
>  		netif_receive_skb(skb);
>  		local_bh_enable();
>  		return;
> @@ -1555,8 +1556,11 @@ static void tun_rx_batched(struct tun_struct *tun, struct tun_file *tfile,
>  		struct sk_buff *nskb;
>  
>  		local_bh_disable();
> -		while ((nskb = __skb_dequeue(&process_queue)))
> +		while ((nskb = __skb_dequeue(&process_queue))) {
> +			skb_record_rx_queue(nskb, tfile->queue_index);
>  			netif_receive_skb(nskb);
> +		}
> +		skb_record_rx_queue(skb, tfile->queue_index);
>  		netif_receive_skb(skb);
>  		local_bh_enable();
>  	}
> @@ -2452,6 +2456,7 @@ static int tun_xdp_one(struct tun_struct *tun,
>  	    !tfile->detached)
>  		rxhash = __skb_get_hash_symmetric(skb);
>  
> +	skb_record_rx_queue(skb, tfile->queue_index);
>  	netif_receive_skb(skb);
>  
>  	stats = get_cpu_ptr(tun->pcpu_stats);
> -- 
> 2.15.2 (Apple Git-101.1)

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

* Re: [PATCH] [PATCH net-next] tun: fix multiqueue rx
  2018-11-16 20:10   ` Michael S. Tsirkin
@ 2018-11-16 20:45     ` Matt Cover
  0 siblings, 0 replies; 10+ messages in thread
From: Matt Cover @ 2018-11-16 20:45 UTC (permalink / raw)
  To: mst; +Cc: davem, jasowang, brouer, Eric Dumazet, sd, netdev, matthew.cover

On Fri, Nov 16, 2018 at 1:10 PM Michael S. Tsirkin <mst@redhat.com> wrote:
>
> On Fri, Nov 16, 2018 at 12:00:15AM -0700, Matthew Cover wrote:
> > When writing packets to a descriptor associated with a combined queue, the
> > packets should end up on that queue.
> >
> > Before this change all packets written to any descriptor associated with a
> > tap interface end up on rx-0, even when the descriptor is associated with a
> > different queue.
> >
> > The rx traffic can be generated by either of the following.
> >   1. a simple tap program which spins up multiple queues and writes packets
> >      to each of the file descriptors
> >   2. tx from a qemu vm with a tap multiqueue netdev
> >
> > The queue for rx traffic can be observed by either of the following (done
> > on the hypervisor in the qemu case).
> >   1. a simple netmap program which opens and reads from per-queue
> >      descriptors
> >   2. configuring RPS and doing per-cpu captures with rxtxcpu
> >
> > Alternatively, if you printk() the return value of skb_get_rx_queue() just
> > before each instance of netif_receive_skb() in tun.c, you will get 65535
> > for every skb.
> >
> > Calling skb_record_rx_queue() to set the rx queue to the queue_index fixes
> > the association between descriptor and rx queue.
> >
> > Signed-off-by: Matthew Cover <matthew.cover@stackpath.com>
>
> Acked-by: Michael S. Tsirkin <mst@redhat.com>
>
> stable material?
>

Yes, I believe so.

The documentation below I think justifies classifying this as a fix.
https://github.com/torvalds/linux/blob/v4.19/Documentation/networking/tuntap.txt#L111

> > ---
> >  drivers/net/tun.c | 7 ++++++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> > index a65779c6d72f..ce8620f3ea5e 100644
> > --- a/drivers/net/tun.c
> > +++ b/drivers/net/tun.c
> > @@ -1536,6 +1536,7 @@ static void tun_rx_batched(struct tun_struct *tun, struct tun_file *tfile,
> >
> >       if (!rx_batched || (!more && skb_queue_empty(queue))) {
> >               local_bh_disable();
> > +             skb_record_rx_queue(skb, tfile->queue_index);
> >               netif_receive_skb(skb);
> >               local_bh_enable();
> >               return;
> > @@ -1555,8 +1556,11 @@ static void tun_rx_batched(struct tun_struct *tun, struct tun_file *tfile,
> >               struct sk_buff *nskb;
> >
> >               local_bh_disable();
> > -             while ((nskb = __skb_dequeue(&process_queue)))
> > +             while ((nskb = __skb_dequeue(&process_queue))) {
> > +                     skb_record_rx_queue(nskb, tfile->queue_index);
> >                       netif_receive_skb(nskb);
> > +             }
> > +             skb_record_rx_queue(skb, tfile->queue_index);
> >               netif_receive_skb(skb);
> >               local_bh_enable();
> >       }
> > @@ -2452,6 +2456,7 @@ static int tun_xdp_one(struct tun_struct *tun,
> >           !tfile->detached)
> >               rxhash = __skb_get_hash_symmetric(skb);
> >
> > +     skb_record_rx_queue(skb, tfile->queue_index);
> >       netif_receive_skb(skb);
> >
> >       stats = get_cpu_ptr(tun->pcpu_stats);
> > --
> > 2.15.2 (Apple Git-101.1)

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

* Re: [PATCH] [PATCH net-next] tun: fix multiqueue rx
  2018-11-16  4:10 [PATCH] [PATCH net-next] tun: fix multiqueue rx Matthew Cover
  2018-11-16  6:29 ` Jason Wang
  2018-11-16  7:00 ` Matthew Cover
@ 2018-11-18  4:39 ` David Miller
  2 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2018-11-18  4:39 UTC (permalink / raw)
  To: werekraken; +Cc: jasowang, brouer, mst, edumazet, sd, netdev, matthew.cover

From: Matthew Cover <werekraken@gmail.com>
Date: Thu, 15 Nov 2018 21:10:16 -0700

> When writing packets to a descriptor associated with a combined queue, the
> packets should end up on that queue.
> 
> Before this change all packets written to any descriptor associated with a
> tap interface end up on rx-0, even when the descriptor is associated with a
> different queue.
> 
> The rx traffic can be generated by either of the following.
>   1. a simple tap program which spins up multiple queues and writes packets
>      to each of the file descriptors
>   2. tx from a qemu vm with a tap multiqueue netdev
> 
> The queue for rx traffic can be observed by either of the following (done
> on the hypervisor in the qemu case).
>   1. a simple netmap program which opens and reads from per-queue
>      descriptors
>   2. configuring RPS and doing per-cpu captures with rxtxcpu
> 
> Alternatively, if you printk() the return value of skb_get_rx_queue() just
> before each instance of netif_receive_skb() in tun.c, you will get 65535
> for every skb.
> 
> Calling skb_record_rx_queue() to set the rx queue to the queue_index fixes
> the association between descriptor and rx queue.
> 
> Signed-off-by: Matthew Cover <matthew.cover@stackpath.com>

As noted by Jason, tun_xdp_one() needs this fix too.

Can you please add that to your patch and resubmit?

Thanks.

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

* Re: [PATCH] [PATCH net-next] tun: fix multiqueue rx
  2018-11-16  7:00 ` Matthew Cover
  2018-11-16  7:11   ` Jason Wang
  2018-11-16 20:10   ` Michael S. Tsirkin
@ 2018-11-18  5:11   ` David Miller
  2018-11-18  7:46     ` [PATCH net] tuntap: " Matthew Cover
  2 siblings, 1 reply; 10+ messages in thread
From: David Miller @ 2018-11-18  5:11 UTC (permalink / raw)
  To: werekraken; +Cc: jasowang, brouer, mst, edumazet, sd, netdev, matthew.cover

From: Matthew Cover <werekraken@gmail.com>
Date: Fri, 16 Nov 2018 00:00:15 -0700

> When writing packets to a descriptor associated with a combined queue, the
> packets should end up on that queue.
> 
> Before this change all packets written to any descriptor associated with a
> tap interface end up on rx-0, even when the descriptor is associated with a
> different queue.
> 
> The rx traffic can be generated by either of the following.
>   1. a simple tap program which spins up multiple queues and writes packets
>      to each of the file descriptors
>   2. tx from a qemu vm with a tap multiqueue netdev
> 
> The queue for rx traffic can be observed by either of the following (done
> on the hypervisor in the qemu case).
>   1. a simple netmap program which opens and reads from per-queue
>      descriptors
>   2. configuring RPS and doing per-cpu captures with rxtxcpu
> 
> Alternatively, if you printk() the return value of skb_get_rx_queue() just
> before each instance of netif_receive_skb() in tun.c, you will get 65535
> for every skb.
> 
> Calling skb_record_rx_queue() to set the rx queue to the queue_index fixes
> the association between descriptor and rx queue.
> 
> Signed-off-by: Matthew Cover <matthew.cover@stackpath.com>

If this is intended to target -stable as well, which some responses seem to
indicate, you need to respin and submit this against 'net'.

Thanks.

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

* [PATCH net] tuntap: fix multiqueue rx
  2018-11-18  5:11   ` David Miller
@ 2018-11-18  7:46     ` Matthew Cover
  2018-11-19  3:06       ` David Miller
  0 siblings, 1 reply; 10+ messages in thread
From: Matthew Cover @ 2018-11-18  7:46 UTC (permalink / raw)
  To: davem, jasowang, brouer, mst, edumazet, sd, netdev, matthew.cover

When writing packets to a descriptor associated with a combined queue, the
packets should end up on that queue.

Before this change all packets written to any descriptor associated with a
tap interface end up on rx-0, even when the descriptor is associated with a
different queue.

The rx traffic can be generated by either of the following.
  1. a simple tap program which spins up multiple queues and writes packets
     to each of the file descriptors
  2. tx from a qemu vm with a tap multiqueue netdev

The queue for rx traffic can be observed by either of the following (done
on the hypervisor in the qemu case).
  1. a simple netmap program which opens and reads from per-queue
     descriptors
  2. configuring RPS and doing per-cpu captures with rxtxcpu

Alternatively, if you printk() the return value of skb_get_rx_queue() just
before each instance of netif_receive_skb() in tun.c, you will get 65535
for every skb.

Calling skb_record_rx_queue() to set the rx queue to the queue_index fixes
the association between descriptor and rx queue.

Signed-off-by: Matthew Cover <matthew.cover@stackpath.com>
---
 drivers/net/tun.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 060135ceaf0e..e244f5d7512a 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1536,6 +1536,7 @@ static void tun_rx_batched(struct tun_struct *tun, struct tun_file *tfile,
 
 	if (!rx_batched || (!more && skb_queue_empty(queue))) {
 		local_bh_disable();
+		skb_record_rx_queue(skb, tfile->queue_index);
 		netif_receive_skb(skb);
 		local_bh_enable();
 		return;
@@ -1555,8 +1556,11 @@ static void tun_rx_batched(struct tun_struct *tun, struct tun_file *tfile,
 		struct sk_buff *nskb;
 
 		local_bh_disable();
-		while ((nskb = __skb_dequeue(&process_queue)))
+		while ((nskb = __skb_dequeue(&process_queue))) {
+			skb_record_rx_queue(nskb, tfile->queue_index);
 			netif_receive_skb(nskb);
+		}
+		skb_record_rx_queue(skb, tfile->queue_index);
 		netif_receive_skb(skb);
 		local_bh_enable();
 	}
@@ -2451,6 +2455,7 @@ static int tun_xdp_one(struct tun_struct *tun,
 	if (!rcu_dereference(tun->steering_prog))
 		rxhash = __skb_get_hash_symmetric(skb);
 
+	skb_record_rx_queue(skb, tfile->queue_index);
 	netif_receive_skb(skb);
 
 	stats = get_cpu_ptr(tun->pcpu_stats);
-- 
2.15.2 (Apple Git-101.1)

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

* Re: [PATCH net] tuntap: fix multiqueue rx
  2018-11-18  7:46     ` [PATCH net] tuntap: " Matthew Cover
@ 2018-11-19  3:06       ` David Miller
  0 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2018-11-19  3:06 UTC (permalink / raw)
  To: werekraken; +Cc: jasowang, brouer, mst, edumazet, sd, netdev, matthew.cover

From: Matthew Cover <werekraken@gmail.com>
Date: Sun, 18 Nov 2018 00:46:00 -0700

> When writing packets to a descriptor associated with a combined queue, the
> packets should end up on that queue.
> 
> Before this change all packets written to any descriptor associated with a
> tap interface end up on rx-0, even when the descriptor is associated with a
> different queue.
> 
> The rx traffic can be generated by either of the following.
>   1. a simple tap program which spins up multiple queues and writes packets
>      to each of the file descriptors
>   2. tx from a qemu vm with a tap multiqueue netdev
> 
> The queue for rx traffic can be observed by either of the following (done
> on the hypervisor in the qemu case).
>   1. a simple netmap program which opens and reads from per-queue
>      descriptors
>   2. configuring RPS and doing per-cpu captures with rxtxcpu
> 
> Alternatively, if you printk() the return value of skb_get_rx_queue() just
> before each instance of netif_receive_skb() in tun.c, you will get 65535
> for every skb.
> 
> Calling skb_record_rx_queue() to set the rx queue to the queue_index fixes
> the association between descriptor and rx queue.
> 
> Signed-off-by: Matthew Cover <matthew.cover@stackpath.com>

Applied and queued up for -stable, thanks.

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

end of thread, other threads:[~2018-11-19 13:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-16  4:10 [PATCH] [PATCH net-next] tun: fix multiqueue rx Matthew Cover
2018-11-16  6:29 ` Jason Wang
2018-11-16  7:00 ` Matthew Cover
2018-11-16  7:11   ` Jason Wang
2018-11-16 20:10   ` Michael S. Tsirkin
2018-11-16 20:45     ` Matt Cover
2018-11-18  5:11   ` David Miller
2018-11-18  7:46     ` [PATCH net] tuntap: " Matthew Cover
2018-11-19  3:06       ` David Miller
2018-11-18  4:39 ` [PATCH] [PATCH net-next] tun: " David Miller

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).