On Mon, 14 Oct 2019 12:49:52 +0200, Lorenzo Bianconi wrote:
> @@ -3983,6 +4071,46 @@ static int mvneta_ioctl(struct net_device *dev, struct
> ifreq *ifr, int cmd)
> return phylink_mii_ioctl(pp->phylink, ifr, cmd);
> }
>
> +static int mvneta_xdp_setup(struct net_device *dev, struct bpf_prog *prog,
> + struct netlink_ext_ack *extack)
> +{
> + struct mvneta_port *pp = netdev_priv(dev);
> + struct bpf_prog *old_prog;
> +
> + if (prog && dev->mtu > MVNETA_MAX_RX_BUF_SIZE) {
> + NL_SET_ERR_MSG_MOD(extack, "Jumbo frames not supported on XDP");
> + return -EOPNOTSUPP;
> + }
> +
> + if (netif_running(dev))
> + mvneta_stop(dev);
> +
> + old_prog = xchg(&pp->xdp_prog, prog);
> + if (old_prog)
> + bpf_prog_put(old_prog);
> +
> + if (netif_running(dev))
> + mvneta_open(dev);
Ah, the stopping and starting of the interface is sad. If start fails
the interface is left in a funky state until someone does a stop/start
cycle. Not that you introduced that.
> + return 0;
> +}
> +
> +static int mvneta_xdp(struct net_device *dev, struct netdev_bpf *xdp)
> +{
> + struct mvneta_port *pp = netdev_priv(dev);
> +
> + switch (xdp->command) {
> + case XDP_SETUP_PROG:
> + return mvneta_xdp_setup(dev, xdp->prog, xdp->extack);
> + case XDP_QUERY_PROG:
> + xdp->prog_id = pp->xdp_prog ? pp->xdp_prog->aux->id : 0;
> + return 0;
> + default:
> + NL_SET_ERR_MSG_MOD(xdp->extack, "unknown XDP command");
Please drop this message here, there are commands you legitimately
don't care about, just return -EINVAL, no need to risk leaking a
meaningless warning to the user space.
> + return -EINVAL;
> + }
> +}