netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Shenwei Wang <shenwei.wang@nxp.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	imx@lists.linux.dev, kernel test robot <lkp@intel.com>
Subject: Re: [PATCH v2 1/1] net: fec: add initial XDP support
Date: Mon, 31 Oct 2022 18:10:07 +0100	[thread overview]
Message-ID: <Y2ABb+G+ykcUd413@lunn.ch> (raw)
In-Reply-To: <20221031162200.1997788-1-shenwei.wang@nxp.com>

> +static int fec_enet_bpf(struct net_device *dev, struct netdev_bpf *bpf)
> +{
> +	struct fec_enet_private *fep = netdev_priv(dev);
> +	bool is_run = netif_running(dev);
> +	struct bpf_prog *old_prog;
> +	unsigned int dsize;
> +	int i;
> +
> +	switch (bpf->command) {
> +	case XDP_SETUP_PROG:
> +		if (is_run) {
> +			napi_disable(&fep->napi);
> +			netif_tx_disable(dev);
> +		}
> +
> +		old_prog = xchg(&fep->xdp_prog, bpf->prog);
> +
> +		/* Update RX ring size */
> +		dsize = fep->bufdesc_ex ? sizeof(struct bufdesc_ex) :
> +			sizeof(struct bufdesc);
> +		for (i = 0; i < fep->num_rx_queues; i++) {
> +			struct fec_enet_priv_rx_q *rxq = fep->rx_queue[i];
> +			struct bufdesc *cbd_base;
> +			unsigned int size;
> +
> +			cbd_base = rxq->bd.base;
> +			if (bpf->prog)
> +				rxq->bd.ring_size = XDP_RX_RING_SIZE;
> +			else
> +				rxq->bd.ring_size = RX_RING_SIZE;
> +			size = dsize * rxq->bd.ring_size;
> +			cbd_base = (struct bufdesc *)(((void *)cbd_base) + size);
> +			rxq->bd.last = (struct bufdesc *)(((void *)cbd_base) - dsize);

This does not look safe. netif_tx_disable(dev) will stop new
transmissions, but the hardware can be busy receiving, DMAing frames,
using the descriptors, etc. Modifying rxq->bd.last in particular seems
risky. I think you need to disable the receiver, wait for it to
indicate it really has stopped, and only then make these
modifications.

	Andrew

  reply	other threads:[~2022-10-31 17:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-31 16:22 [PATCH v2 1/1] net: fec: add initial XDP support Shenwei Wang
2022-10-31 17:10 ` Andrew Lunn [this message]
2022-10-31 18:34   ` [EXT] " Shenwei Wang
2022-10-31 20:17     ` Andrew Lunn
2022-10-31 21:17       ` Shenwei Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y2ABb+G+ykcUd413@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shenwei.wang@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).