]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
tuntap: disable preemption during XDP processing
authorJason Wang <jasowang@redhat.com>
Sat, 24 Feb 2018 03:32:25 +0000 (11:32 +0800)
committerSeth Forshee <seth.forshee@canonical.com>
Thu, 15 Mar 2018 13:28:17 +0000 (08:28 -0500)
BugLink: http://bugs.launchpad.net/bugs/1755179
[ Upstream commit 23e43f07f896f8578318cfcc9466f1e8b8ab21b6 ]

Except for tuntap, all other drivers' XDP was implemented at NAPI
poll() routine in a bh. This guarantees all XDP operation were done at
the same CPU which is required by e.g BFP_MAP_TYPE_PERCPU_ARRAY. But
for tuntap, we do it in process context and we try to protect XDP
processing by RCU reader lock. This is insufficient since
CONFIG_PREEMPT_RCU can preempt the RCU reader critical section which
breaks the assumption that all XDP were processed in the same CPU.

Fixing this by simply disabling preemption during XDP processing.

Fixes: 761876c857cb ("tap: XDP support")
Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
drivers/net/tun.c

index 5f04f784bc97fa45e7a02336e858cda0f0a74851..f50cf06c935398a0a66cf335519d89cabff3b884 100644 (file)
@@ -1471,6 +1471,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
        else
                *skb_xdp = 0;
 
+       preempt_disable();
        rcu_read_lock();
        xdp_prog = rcu_dereference(tun->xdp_prog);
        if (xdp_prog && !*skb_xdp) {
@@ -1494,6 +1495,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
                        if (err)
                                goto err_redirect;
                        rcu_read_unlock();
+                       preempt_enable();
                        return NULL;
                case XDP_TX:
                        xdp_xmit = true;
@@ -1515,6 +1517,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
        skb = build_skb(buf, buflen);
        if (!skb) {
                rcu_read_unlock();
+               preempt_enable();
                return ERR_PTR(-ENOMEM);
        }
 
@@ -1527,10 +1530,12 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
                skb->dev = tun->dev;
                generic_xdp_tx(skb, xdp_prog);
                rcu_read_unlock();
+               preempt_enable();
                return NULL;
        }
 
        rcu_read_unlock();
+       preempt_enable();
 
        return skb;
 
@@ -1538,6 +1543,7 @@ err_redirect:
        put_page(alloc_frag->page);
 err_xdp:
        rcu_read_unlock();
+       preempt_enable();
        this_cpu_inc(tun->pcpu_stats->rx_dropped);
        return NULL;
 }