Skip to content

Commit

Permalink
tun: implement flush flag for ndo_xdp_xmit
Browse files Browse the repository at this point in the history
When passed the XDP_XMIT_FLUSH flag tun_xdp_xmit now performs the same
kind of socket wake up as in tun_xdp_flush(). The wake up code from
tun_xdp_flush is generalized and shared with tun_xdp_xmit.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Jesper Dangaard Brouer authored and Alexei Starovoitov committed Jun 3, 2018
1 parent 5e2e609 commit 0c9d917
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions drivers/net/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,14 @@ static const struct net_device_ops tun_netdev_ops = {
.ndo_get_stats64 = tun_net_get_stats64,
};

static void __tun_xdp_flush_tfile(struct tun_file *tfile)
{
/* Notify and wake up reader process */
if (tfile->flags & TUN_FASYNC)
kill_fasync(&tfile->fasync, SIGIO, POLL_IN);
tfile->socket.sk->sk_data_ready(tfile->socket.sk);
}

static int tun_xdp_xmit(struct net_device *dev, int n,
struct xdp_frame **frames, u32 flags)
{
Expand All @@ -1295,7 +1303,7 @@ static int tun_xdp_xmit(struct net_device *dev, int n,
int cnt = n;
int i;

if (unlikely(flags & ~XDP_XMIT_FLAGS_NONE))
if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
return -EINVAL;

rcu_read_lock();
Expand Down Expand Up @@ -1325,6 +1333,9 @@ static int tun_xdp_xmit(struct net_device *dev, int n,
}
spin_unlock(&tfile->tx_ring.producer_lock);

if (flags & XDP_XMIT_FLUSH)
__tun_xdp_flush_tfile(tfile);

rcu_read_unlock();
return cnt - drops;
}
Expand Down Expand Up @@ -1353,11 +1364,7 @@ static void tun_xdp_flush(struct net_device *dev)

tfile = rcu_dereference(tun->tfiles[smp_processor_id() %
numqueues]);
/* Notify and wake up reader process */
if (tfile->flags & TUN_FASYNC)
kill_fasync(&tfile->fasync, SIGIO, POLL_IN);
tfile->socket.sk->sk_data_ready(tfile->socket.sk);

__tun_xdp_flush_tfile(tfile);
out:
rcu_read_unlock();
}
Expand Down

0 comments on commit 0c9d917

Please sign in to comment.