mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-04 09:59:32 +00:00
tun: make tun_build_skb() thread safe
tun_build_skb() is not thread safe since it uses per queue page frag,
this will break things when multiple threads are sending through same
queue. Switch to use per-thread generator (no lock involved).
Fixes: 66ccbc9c87
("tap: use build_skb() for small packet")
Tested-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
ba5c4dac03
commit
0bbd7dad34
1 changed files with 1 additions and 6 deletions
|
@ -175,7 +175,6 @@ struct tun_file {
|
||||||
struct list_head next;
|
struct list_head next;
|
||||||
struct tun_struct *detached;
|
struct tun_struct *detached;
|
||||||
struct skb_array tx_array;
|
struct skb_array tx_array;
|
||||||
struct page_frag alloc_frag;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tun_flow_entry {
|
struct tun_flow_entry {
|
||||||
|
@ -578,8 +577,6 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
|
||||||
}
|
}
|
||||||
if (tun)
|
if (tun)
|
||||||
skb_array_cleanup(&tfile->tx_array);
|
skb_array_cleanup(&tfile->tx_array);
|
||||||
if (tfile->alloc_frag.page)
|
|
||||||
put_page(tfile->alloc_frag.page);
|
|
||||||
sock_put(&tfile->sk);
|
sock_put(&tfile->sk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1272,7 +1269,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
|
||||||
struct virtio_net_hdr *hdr,
|
struct virtio_net_hdr *hdr,
|
||||||
int len, int *generic_xdp)
|
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 sk_buff *skb;
|
||||||
struct bpf_prog *xdp_prog;
|
struct bpf_prog *xdp_prog;
|
||||||
int buflen = SKB_DATA_ALIGN(len + TUN_RX_PAD) +
|
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_write_space = tun_sock_write_space;
|
||||||
tfile->sk.sk_sndbuf = INT_MAX;
|
tfile->sk.sk_sndbuf = INT_MAX;
|
||||||
|
|
||||||
tfile->alloc_frag.page = NULL;
|
|
||||||
|
|
||||||
file->private_data = tfile;
|
file->private_data = tfile;
|
||||||
INIT_LIST_HEAD(&tfile->next);
|
INIT_LIST_HEAD(&tfile->next);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue