Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752220AbdHPNRF (ORCPT ); Wed, 16 Aug 2017 09:17:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52682 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751638AbdHPNRD (ORCPT ); Wed, 16 Aug 2017 09:17:03 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6C1624D4AB Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jasowang@redhat.com Subject: Re: [PATCH net-next V2 1/3] tap: use build_skb() for small packet To: Eric Dumazet Cc: davem@davemloft.net, mst@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kubakici@wp.pl References: <1502451678-17358-1-git-send-email-jasowang@redhat.com> <1502451678-17358-2-git-send-email-jasowang@redhat.com> <1502855120.4936.89.camel@edumazet-glaptop3.roam.corp.google.com> <2ae570ab-01da-2ea2-0549-3e310158b817@redhat.com> <1502879084.4936.95.camel@edumazet-glaptop3.roam.corp.google.com> From: Jason Wang Message-ID: <208fa880-c0e5-36e5-3604-eb13fe1de3b9@redhat.com> Date: Wed, 16 Aug 2017 21:16:56 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <1502879084.4936.95.camel@edumazet-glaptop3.roam.corp.google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 16 Aug 2017 13:17:03 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2000 Lines: 64 On 2017年08月16日 18:24, Eric Dumazet wrote: > On Wed, 2017-08-16 at 11:55 +0800, Jason Wang wrote: >> On 2017年08月16日 11:45, Eric Dumazet wrote: >>> You do realize that tun_build_skb() is not thread safe ? >> Ok, I think the issue if skb_page_frag_refill(), need a spinlock >> probably. Will prepare a patch. > But since tun is used from process context, why don't you use the > per-thread generator (no lock involved) Haven't noticed this before. > > tcp_sendmsg() uses this for GFP_KERNEL allocations. > > Untested patch : > > diff --git a/drivers/net/tun.c b/drivers/net/tun.c > index 5892284eb8d05b0678d820bad3d0d2c61a879aeb..c38cd840cc0b7fecf182b23976e36f709cacca1f 100644 > --- a/drivers/net/tun.c > +++ b/drivers/net/tun.c > @@ -175,7 +175,6 @@ struct tun_file { > struct list_head next; > struct tun_struct *detached; > struct skb_array tx_array; > - struct page_frag alloc_frag; > }; > > struct tun_flow_entry { > @@ -578,8 +577,6 @@ static void __tun_detach(struct tun_file *tfile, bool clean) > } > if (tun) > skb_array_cleanup(&tfile->tx_array); > - if (tfile->alloc_frag.page) > - put_page(tfile->alloc_frag.page); > sock_put(&tfile->sk); > } > } > @@ -1272,7 +1269,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun, > struct virtio_net_hdr *hdr, > int len, int *generic_xdp) > { > - struct page_frag *alloc_frag = &tfile->alloc_frag; > + struct page_frag *alloc_frag = ¤t->task_frag; > struct sk_buff *skb; > struct bpf_prog *xdp_prog; > int buflen = SKB_DATA_ALIGN(len + TUN_RX_PAD) + > @@ -2580,8 +2577,6 @@ static int tun_chr_open(struct inode *inode, struct file * file) > tfile->sk.sk_write_space = tun_sock_write_space; > tfile->sk.sk_sndbuf = INT_MAX; > > - tfile->alloc_frag.page = NULL; > - > file->private_data = tfile; > INIT_LIST_HEAD(&tfile->next); > > > > > Tested-by: Jason Wang Acked-by: Jason Wang