Subject: Re: [PATCH net-next RFC] Generic XDP

From: Johannes Berg <[email-masked]>
Date: Sun, 09 Apr 2017 08:25:18 +0200

On Sat, 2017-04-08 at 20:07 -0700, David Miller wrote:

> +static int generic_xdp_install(struct net_device *dev, struct
> netdev_xdp *xdp)
> +{
> +       struct bpf_prog *new = xdp->prog;
> +       int ret = 0;
> +
> +       switch (xdp->command) {
> +       case XDP_SETUP_PROG: {
> +               struct bpf_prog *old;
> +
> +               old = xchg(&dev->xdp_prog, new);
> +               if (old)
> +                       bpf_prog_put(old);

I don't really see why you need the xchg() here - just fetching the old
program and setting the new one should be sufficient since you're under
RTNL here.
That would also let you use rcu_assign_pointer() which seems like the
right thing to do here, along with marking the xdp_prog pointer as
__rcu? That'd also let you use rcu_dereference() instead of READ_ONCE()
which seems like the better annotation?

johannes