diff options
author | Jason Wang <jasowang@redhat.com> | 2018-09-11 23:17:02 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-09-13 12:25:40 -0400 |
commit | f7053b6ccb65a36fdfed6ad92b808464839f0eb6 (patch) | |
tree | 3e8a43962d210ca2d9499f12dc2dc693ade1d512 /drivers/net/tun.c | |
parent | 291aeb2b1dba0d0296673d994200824a7185585e (diff) |
tuntap: simplify error handling in tun_build_skb()
There's no need to duplicate page get logic in each action. So this
patch tries to get page and calculate the offset before processing XDP
actions (except for XDP_DROP), and undo them when meet errors (we
don't care the performance on errors). This will be used for factoring
out XDP logic.
Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/tun.c')
-rw-r--r-- | drivers/net/tun.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 372caf7d67d9..257cf7342d54 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c | |||
@@ -1701,17 +1701,13 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun, | |||
1701 | xdp_do_flush_map(); | 1701 | xdp_do_flush_map(); |
1702 | if (err) | 1702 | if (err) |
1703 | goto err_redirect; | 1703 | goto err_redirect; |
1704 | rcu_read_unlock(); | 1704 | goto out; |
1705 | local_bh_enable(); | ||
1706 | return NULL; | ||
1707 | case XDP_TX: | 1705 | case XDP_TX: |
1708 | get_page(alloc_frag->page); | 1706 | get_page(alloc_frag->page); |
1709 | alloc_frag->offset += buflen; | 1707 | alloc_frag->offset += buflen; |
1710 | if (tun_xdp_tx(tun->dev, &xdp) < 0) | 1708 | if (tun_xdp_tx(tun->dev, &xdp) < 0) |
1711 | goto err_redirect; | 1709 | goto err_redirect; |
1712 | rcu_read_unlock(); | 1710 | goto out; |
1713 | local_bh_enable(); | ||
1714 | return NULL; | ||
1715 | case XDP_PASS: | 1711 | case XDP_PASS: |
1716 | delta = orig_data - xdp.data; | 1712 | delta = orig_data - xdp.data; |
1717 | len = xdp.data_end - xdp.data; | 1713 | len = xdp.data_end - xdp.data; |
@@ -1742,7 +1738,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun, | |||
1742 | 1738 | ||
1743 | err_redirect: | 1739 | err_redirect: |
1744 | put_page(alloc_frag->page); | 1740 | put_page(alloc_frag->page); |
1745 | err_xdp: | 1741 | out: |
1746 | rcu_read_unlock(); | 1742 | rcu_read_unlock(); |
1747 | local_bh_enable(); | 1743 | local_bh_enable(); |
1748 | this_cpu_inc(tun->pcpu_stats->rx_dropped); | 1744 | this_cpu_inc(tun->pcpu_stats->rx_dropped); |