lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Wed, 2 Oct 2019 10:59:33 +0200
From:   Lorenzo Bianconi <lorenzo@...nel.org>
To:     Ilias Apalodimas <ilias.apalodimas@...aro.org>
Cc:     netdev@...r.kernel.org, thomas.petazzoni@...tlin.com,
        brouer@...hat.com, mcroce@...hat.com
Subject: Re: [RFC 3/4] net: mvneta: add basic XDP support

> On Tue, Oct 01, 2019 at 11:24:43AM +0200, Lorenzo Bianconi wrote:
> > Add basic XDP support to mvneta driver for devices that rely on software
> > buffer management. Currently supported verdicts are:
> > - XDP_DROP
> > - XDP_PASS
> > - XDP_REDIRECT
> > 
> > Signed-off-by: Lorenzo Bianconi <lorenzo@...nel.org>
> > ---
> >  drivers/net/ethernet/marvell/mvneta.c | 145 ++++++++++++++++++++++++--
> >  1 file changed, 136 insertions(+), 9 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
> > index e842c744e4f3..f2d12556efa8 100644
> > --- a/drivers/net/ethernet/marvell/mvneta.c
> > +++ b/drivers/net/ethernet/marvell/mvneta.c
> [...]
> >  		.pool_size = size,
> >  		.nid = cpu_to_node(0),
> >  		.dev = pp->dev->dev.parent,
> > -		.dma_dir = DMA_FROM_DEVICE,
> > +		.dma_dir = xdp_prog ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE,
> >  	};
> > +	int err;
> >  
> >  	rxq->page_pool = page_pool_create(&pp_params);
> >  	if (IS_ERR(rxq->page_pool)) {
> > @@ -2851,7 +2920,22 @@ static int mvneta_create_page_pool(struct mvneta_port *pp,
> >  		return PTR_ERR(rxq->page_pool);
> >  	}
> >  
> > +	err = xdp_rxq_info_reg(&rxq->xdp_rxq, pp->dev, 0);
> > +	if (err < 0)
> > +		goto err_free_pp;
> > +
> > +	err = xdp_rxq_info_reg_mem_model(&rxq->xdp_rxq, MEM_TYPE_PAGE_POOL,
> > +					 rxq->page_pool);
> > +	if (err)
> > +		goto err_unregister_pp;
> 
> I think this should be part of patch [1/4], adding page pol support. 
> Jesper introduced the changes to track down inflight packets [1], so you need
> those changes in place when implementing page_pool

ack, will do in the next round.

Regards,
Lorenzo

> 
> > +
> >  	return 0;
> > +
> > +err_unregister_pp:
> > +	xdp_rxq_info_unreg(&rxq->xdp_rxq);
> > +err_free_pp:
> > +	page_pool_destroy(rxq->page_pool);
> > +	return err;
> >  }
> >  
> >  /* Handle rxq fill: allocates rxq skbs; called when initializing a port */
> > @@ -3291,6 +3375,11 @@ static int mvneta_change_mtu(struct net_device *dev, int mtu)
> >  		mtu = ALIGN(MVNETA_RX_PKT_SIZE(mtu), 8);
> >  	}
> >  
> > +	if (pp->xdp_prog && mtu > MVNETA_MAX_RX_BUF_SIZE) {
> > +		netdev_info(dev, "Illegal MTU value %d for XDP mode\n", mtu);
> > +		return -EINVAL;
> > +	}
> > +
> >  	dev->mtu = mtu;
> >  
> >  	if (!netif_running(dev)) {
> > @@ -3960,6 +4049,43 @@ 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;
> > +	}
> > +
> > +	mvneta_stop(dev);
> > +
> > +	old_prog = xchg(&pp->xdp_prog, prog);
> > +	if (old_prog)
> > +		bpf_prog_put(old_prog);
> > +
> > +	mvneta_open(dev);
> > +
> > +	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:
> > +		return -EINVAL;
> > +	}
> > +}
> > +
> >  /* Ethtool methods */
> >  
> >  /* Set link ksettings (phy address, speed) for ethtools */
> > @@ -4356,6 +4482,7 @@ static const struct net_device_ops mvneta_netdev_ops = {
> >  	.ndo_fix_features    = mvneta_fix_features,
> >  	.ndo_get_stats64     = mvneta_get_stats64,
> >  	.ndo_do_ioctl        = mvneta_ioctl,
> > +	.ndo_bpf	     = mvneta_xdp,
> >  };
> >  
> >  static const struct ethtool_ops mvneta_eth_tool_ops = {
> > @@ -4646,7 +4773,7 @@ static int mvneta_probe(struct platform_device *pdev)
> >  	SET_NETDEV_DEV(dev, &pdev->dev);
> >  
> >  	pp->id = global_port_id++;
> > -	pp->rx_offset_correction = NET_SKB_PAD;
> > +	pp->rx_offset_correction = MVNETA_SKB_HEADROOM;
> >  
> >  	/* Obtain access to BM resources if enabled and already initialized */
> >  	bm_node = of_parse_phandle(dn, "buffer-manager", 0);
> > -- 
> > 2.21.0
> > 
> 
> [1] https://lore.kernel.org/netdev/156086304827.27760.11339786046465638081.stgit@firesoul/
> 
> 
> Regards
> /Ilias

Download attachment "signature.asc" of type "application/pgp-signature" (229 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ