netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] tun: Use netif_receive_skb instead of netif_rx
@ 2016-12-01  9:34 Andrey Konovalov
  2016-12-01  9:39 ` Jason Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Andrey Konovalov @ 2016-12-01  9:34 UTC (permalink / raw)
  To: Herbert Xu, David S . Miller, Jason Wang, Eric Dumazet,
	Peter Klausler, Paolo Abeni, Michael S . Tsirkin,
	Soheil Hassas Yeganeh, Markus Elfring, Mike Rapoport, netdev,
	linux-kernel
  Cc: Dmitry Vyukov, Kostya Serebryany, syzkaller, Andrey Konovalov

This patch changes tun.c to call netif_receive_skb instead of netif_rx
when a packet is received (if CONFIG_4KSTACKS is not enabled to avoid
stack exhaustion). The difference between the two is that netif_rx queues
the packet into the backlog, and netif_receive_skb proccesses the packet
in the current context.

This patch is required for syzkaller [1] to collect coverage from packet
receive paths, when a packet being received through tun (syzkaller collects
coverage per process in the process context).

As mentioned by Eric this change also speeds up tun/tap. As measured by
Peter it speeds up his closed-loop single-stream tap/OVS benchmark by
about 23%, from 700k packets/second to 867k packets/second.

A similar patch was introduced back in 2010 [2, 3], but the author found
out that the patch doesn't help with the task he had in mind (for cgroups
to shape network traffic based on the original process) and decided not to
go further with it. The main concern back then was about possible stack
exhaustion with 4K stacks.

[1] https://github.com/google/syzkaller

[2] https://www.spinics.net/lists/netdev/thrd440.html#130570

[3] https://www.spinics.net/lists/netdev/msg130570.html

Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---

Changes since v1:
- incorporate Eric's note about speed improvements in commit description
- use netif_receive_skb CONFIG_4KSTACKS is not enabled

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

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 8093e39..d310b13 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1304,7 +1304,13 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
 	skb_probe_transport_header(skb, 0);
 
 	rxhash = skb_get_hash(skb);
+#ifndef CONFIG_4KSTACKS
+	local_bh_disable();
+	netif_receive_skb(skb);
+	local_bh_enable();
+#else
 	netif_rx_ni(skb);
+#endif
 
 	stats = get_cpu_ptr(tun->pcpu_stats);
 	u64_stats_update_begin(&stats->syncp);
-- 
2.8.0.rc3.226.g39d4020

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

* Re: [PATCH v2] tun: Use netif_receive_skb instead of netif_rx
  2016-12-01  9:34 [PATCH v2] tun: Use netif_receive_skb instead of netif_rx Andrey Konovalov
@ 2016-12-01  9:39 ` Jason Wang
  2016-12-01 13:05 ` Michael S. Tsirkin
  2016-12-01 19:43 ` David Miller
  2 siblings, 0 replies; 7+ messages in thread
From: Jason Wang @ 2016-12-01  9:39 UTC (permalink / raw)
  To: Andrey Konovalov, Herbert Xu, David S . Miller, Eric Dumazet,
	Peter Klausler, Paolo Abeni, Michael S . Tsirkin,
	Soheil Hassas Yeganeh, Markus Elfring, Mike Rapoport, netdev,
	linux-kernel
  Cc: Dmitry Vyukov, Kostya Serebryany, syzkaller



On 2016年12月01日 17:34, Andrey Konovalov wrote:
> This patch changes tun.c to call netif_receive_skb instead of netif_rx
> when a packet is received (if CONFIG_4KSTACKS is not enabled to avoid
> stack exhaustion). The difference between the two is that netif_rx queues
> the packet into the backlog, and netif_receive_skb proccesses the packet
> in the current context.
>
> This patch is required for syzkaller [1] to collect coverage from packet
> receive paths, when a packet being received through tun (syzkaller collects
> coverage per process in the process context).
>
> As mentioned by Eric this change also speeds up tun/tap. As measured by
> Peter it speeds up his closed-loop single-stream tap/OVS benchmark by
> about 23%, from 700k packets/second to 867k packets/second.
>
> A similar patch was introduced back in 2010 [2, 3], but the author found
> out that the patch doesn't help with the task he had in mind (for cgroups
> to shape network traffic based on the original process) and decided not to
> go further with it. The main concern back then was about possible stack
> exhaustion with 4K stacks.
>
> [1] https://github.com/google/syzkaller
>
> [2] https://www.spinics.net/lists/netdev/thrd440.html#130570
>
> [3] https://www.spinics.net/lists/netdev/msg130570.html
>
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
> ---
>
> Changes since v1:
> - incorporate Eric's note about speed improvements in commit description
> - use netif_receive_skb CONFIG_4KSTACKS is not enabled
>
>   drivers/net/tun.c | 6 ++++++
>   1 file changed, 6 insertions(+)
>
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index 8093e39..d310b13 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -1304,7 +1304,13 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
>   	skb_probe_transport_header(skb, 0);
>   
>   	rxhash = skb_get_hash(skb);
> +#ifndef CONFIG_4KSTACKS
> +	local_bh_disable();
> +	netif_receive_skb(skb);
> +	local_bh_enable();
> +#else
>   	netif_rx_ni(skb);
> +#endif
>   
>   	stats = get_cpu_ptr(tun->pcpu_stats);
>   	u64_stats_update_begin(&stats->syncp);

I get +20% tx pps from guest with this patch.

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

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

* Re: [PATCH v2] tun: Use netif_receive_skb instead of netif_rx
  2016-12-01  9:34 [PATCH v2] tun: Use netif_receive_skb instead of netif_rx Andrey Konovalov
  2016-12-01  9:39 ` Jason Wang
@ 2016-12-01 13:05 ` Michael S. Tsirkin
  2016-12-01 19:43 ` David Miller
  2 siblings, 0 replies; 7+ messages in thread
From: Michael S. Tsirkin @ 2016-12-01 13:05 UTC (permalink / raw)
  To: Andrey Konovalov
  Cc: Herbert Xu, David S . Miller, Jason Wang, Eric Dumazet,
	Peter Klausler, Paolo Abeni, Soheil Hassas Yeganeh,
	Markus Elfring, Mike Rapoport, netdev, linux-kernel,
	Dmitry Vyukov, Kostya Serebryany, syzkaller

On Thu, Dec 01, 2016 at 10:34:40AM +0100, Andrey Konovalov wrote:
> This patch changes tun.c to call netif_receive_skb instead of netif_rx
> when a packet is received (if CONFIG_4KSTACKS is not enabled to avoid
> stack exhaustion). The difference between the two is that netif_rx queues
> the packet into the backlog, and netif_receive_skb proccesses the packet
> in the current context.
> 
> This patch is required for syzkaller [1] to collect coverage from packet
> receive paths, when a packet being received through tun (syzkaller collects
> coverage per process in the process context).
> 
> As mentioned by Eric this change also speeds up tun/tap. As measured by
> Peter it speeds up his closed-loop single-stream tap/OVS benchmark by
> about 23%, from 700k packets/second to 867k packets/second.
> 
> A similar patch was introduced back in 2010 [2, 3], but the author found
> out that the patch doesn't help with the task he had in mind (for cgroups
> to shape network traffic based on the original process) and decided not to
> go further with it. The main concern back then was about possible stack
> exhaustion with 4K stacks.
> 
> [1] https://github.com/google/syzkaller
> 
> [2] https://www.spinics.net/lists/netdev/thrd440.html#130570
> 
> [3] https://www.spinics.net/lists/netdev/msg130570.html
> 
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>

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

> ---
> 
> Changes since v1:
> - incorporate Eric's note about speed improvements in commit description
> - use netif_receive_skb CONFIG_4KSTACKS is not enabled
> 
>  drivers/net/tun.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index 8093e39..d310b13 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -1304,7 +1304,13 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
>  	skb_probe_transport_header(skb, 0);
>  
>  	rxhash = skb_get_hash(skb);
> +#ifndef CONFIG_4KSTACKS
> +	local_bh_disable();
> +	netif_receive_skb(skb);
> +	local_bh_enable();
> +#else
>  	netif_rx_ni(skb);
> +#endif
>  
>  	stats = get_cpu_ptr(tun->pcpu_stats);
>  	u64_stats_update_begin(&stats->syncp);
> -- 
> 2.8.0.rc3.226.g39d4020

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

* Re: [PATCH v2] tun: Use netif_receive_skb instead of netif_rx
  2016-12-01  9:34 [PATCH v2] tun: Use netif_receive_skb instead of netif_rx Andrey Konovalov
  2016-12-01  9:39 ` Jason Wang
  2016-12-01 13:05 ` Michael S. Tsirkin
@ 2016-12-01 19:43 ` David Miller
  2016-12-07  3:21   ` Jason Wang
  2 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2016-12-01 19:43 UTC (permalink / raw)
  To: andreyknvl
  Cc: herbert, jasowang, edumazet, pmk, pabeni, mst, soheil, elfring,
	rppt, netdev, linux-kernel, dvyukov, kcc, syzkaller

From: Andrey Konovalov <andreyknvl@google.com>
Date: Thu,  1 Dec 2016 10:34:40 +0100

> This patch changes tun.c to call netif_receive_skb instead of netif_rx
> when a packet is received (if CONFIG_4KSTACKS is not enabled to avoid
> stack exhaustion). The difference between the two is that netif_rx queues
> the packet into the backlog, and netif_receive_skb proccesses the packet
> in the current context.
> 
> This patch is required for syzkaller [1] to collect coverage from packet
> receive paths, when a packet being received through tun (syzkaller collects
> coverage per process in the process context).
> 
> As mentioned by Eric this change also speeds up tun/tap. As measured by
> Peter it speeds up his closed-loop single-stream tap/OVS benchmark by
> about 23%, from 700k packets/second to 867k packets/second.
> 
> A similar patch was introduced back in 2010 [2, 3], but the author found
> out that the patch doesn't help with the task he had in mind (for cgroups
> to shape network traffic based on the original process) and decided not to
> go further with it. The main concern back then was about possible stack
> exhaustion with 4K stacks.
> 
> [1] https://github.com/google/syzkaller
> 
> [2] https://www.spinics.net/lists/netdev/thrd440.html#130570
> 
> [3] https://www.spinics.net/lists/netdev/msg130570.html
> 
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
> ---
> 
> Changes since v1:
> - incorporate Eric's note about speed improvements in commit description
> - use netif_receive_skb CONFIG_4KSTACKS is not enabled

Applied to net-next, thanks!

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

* Re: [PATCH v2] tun: Use netif_receive_skb instead of netif_rx
  2016-12-01 19:43 ` David Miller
@ 2016-12-07  3:21   ` Jason Wang
  2016-12-07  3:25     ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Jason Wang @ 2016-12-07  3:21 UTC (permalink / raw)
  To: David Miller, andreyknvl
  Cc: herbert, edumazet, pmk, pabeni, mst, soheil, elfring, rppt,
	netdev, linux-kernel, dvyukov, kcc, syzkaller



On 2016年12月02日 03:43, David Miller wrote:
> From: Andrey Konovalov <andreyknvl@google.com>
> Date: Thu,  1 Dec 2016 10:34:40 +0100
>
>> This patch changes tun.c to call netif_receive_skb instead of netif_rx
>> when a packet is received (if CONFIG_4KSTACKS is not enabled to avoid
>> stack exhaustion). The difference between the two is that netif_rx queues
>> the packet into the backlog, and netif_receive_skb proccesses the packet
>> in the current context.
>>
>> This patch is required for syzkaller [1] to collect coverage from packet
>> receive paths, when a packet being received through tun (syzkaller collects
>> coverage per process in the process context).
>>
>> As mentioned by Eric this change also speeds up tun/tap. As measured by
>> Peter it speeds up his closed-loop single-stream tap/OVS benchmark by
>> about 23%, from 700k packets/second to 867k packets/second.
>>
>> A similar patch was introduced back in 2010 [2, 3], but the author found
>> out that the patch doesn't help with the task he had in mind (for cgroups
>> to shape network traffic based on the original process) and decided not to
>> go further with it. The main concern back then was about possible stack
>> exhaustion with 4K stacks.
>>
>> [1] https://github.com/google/syzkaller
>>
>> [2] https://www.spinics.net/lists/netdev/thrd440.html#130570
>>
>> [3] https://www.spinics.net/lists/netdev/msg130570.html
>>
>> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
>> ---
>>
>> Changes since v1:
>> - incorporate Eric's note about speed improvements in commit description
>> - use netif_receive_skb CONFIG_4KSTACKS is not enabled
> Applied to net-next, thanks!

David, looks like this commit is not in net-next.git.

Please help to check.

Thanks

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

* Re: [PATCH v2] tun: Use netif_receive_skb instead of netif_rx
  2016-12-07  3:21   ` Jason Wang
@ 2016-12-07  3:25     ` David Miller
  2016-12-07  3:39       ` Jason Wang
  0 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2016-12-07  3:25 UTC (permalink / raw)
  To: jasowang
  Cc: andreyknvl, herbert, edumazet, pmk, pabeni, mst, soheil, elfring,
	rppt, netdev, linux-kernel, dvyukov, kcc, syzkaller

From: Jason Wang <jasowang@redhat.com>
Date: Wed, 7 Dec 2016 11:21:11 +0800

> David, looks like this commit is not in net-next.git.
> 
> Please help to check.

Take a look, it should be there now.

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

* Re: [PATCH v2] tun: Use netif_receive_skb instead of netif_rx
  2016-12-07  3:25     ` David Miller
@ 2016-12-07  3:39       ` Jason Wang
  0 siblings, 0 replies; 7+ messages in thread
From: Jason Wang @ 2016-12-07  3:39 UTC (permalink / raw)
  To: David Miller
  Cc: andreyknvl, herbert, edumazet, pmk, pabeni, mst, soheil, elfring,
	rppt, netdev, linux-kernel, dvyukov, kcc, syzkaller



On 2016年12月07日 11:25, David Miller wrote:
> From: Jason Wang <jasowang@redhat.com>
> Date: Wed, 7 Dec 2016 11:21:11 +0800
>
>> David, looks like this commit is not in net-next.git.
>>
>> Please help to check.
> Take a look, it should be there now.

Yes, thanks.

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

end of thread, other threads:[~2016-12-07  3:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-01  9:34 [PATCH v2] tun: Use netif_receive_skb instead of netif_rx Andrey Konovalov
2016-12-01  9:39 ` Jason Wang
2016-12-01 13:05 ` Michael S. Tsirkin
2016-12-01 19:43 ` David Miller
2016-12-07  3:21   ` Jason Wang
2016-12-07  3:25     ` David Miller
2016-12-07  3:39       ` Jason Wang

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