Commit 23e43f07 authored by Jason Wang's avatar Jason Wang Committed by David S. Miller

tuntap: disable preemption during XDP processing

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: 761876c8 ("tap: XDP support")
Signed-off-by: default avatarJason Wang <jasowang@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f249be4d
...@@ -1642,6 +1642,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun, ...@@ -1642,6 +1642,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
else else
*skb_xdp = 0; *skb_xdp = 0;
preempt_disable();
rcu_read_lock(); rcu_read_lock();
xdp_prog = rcu_dereference(tun->xdp_prog); xdp_prog = rcu_dereference(tun->xdp_prog);
if (xdp_prog && !*skb_xdp) { if (xdp_prog && !*skb_xdp) {
...@@ -1665,6 +1666,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun, ...@@ -1665,6 +1666,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
if (err) if (err)
goto err_redirect; goto err_redirect;
rcu_read_unlock(); rcu_read_unlock();
preempt_enable();
return NULL; return NULL;
case XDP_TX: case XDP_TX:
xdp_xmit = true; xdp_xmit = true;
...@@ -1686,6 +1688,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun, ...@@ -1686,6 +1688,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
skb = build_skb(buf, buflen); skb = build_skb(buf, buflen);
if (!skb) { if (!skb) {
rcu_read_unlock(); rcu_read_unlock();
preempt_enable();
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
...@@ -1698,10 +1701,12 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun, ...@@ -1698,10 +1701,12 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
skb->dev = tun->dev; skb->dev = tun->dev;
generic_xdp_tx(skb, xdp_prog); generic_xdp_tx(skb, xdp_prog);
rcu_read_unlock(); rcu_read_unlock();
preempt_enable();
return NULL; return NULL;
} }
rcu_read_unlock(); rcu_read_unlock();
preempt_enable();
return skb; return skb;
...@@ -1709,6 +1714,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun, ...@@ -1709,6 +1714,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
put_page(alloc_frag->page); put_page(alloc_frag->page);
err_xdp: err_xdp:
rcu_read_unlock(); rcu_read_unlock();
preempt_enable();
this_cpu_inc(tun->pcpu_stats->rx_dropped); this_cpu_inc(tun->pcpu_stats->rx_dropped);
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment