public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Jesper Dangaard Brouer <brouer@redhat.com>
To: Charles McLachlan <cmclachlan@solarflare.com>
Cc: <davem@davemloft.net>, <netdev@vger.kernel.org>,
	<linux-net-drivers@solarflare.com>,
	brouer@redhat.com
Subject: Re: [PATCH net-next v3 5/6] sfc: handle XDP_TX outcomes of XDP eBPF programs
Date: Wed, 30 Oct 2019 12:34:06 +0100	[thread overview]
Message-ID: <20191030123406.762a51d3@carbon> (raw)
In-Reply-To: <40f6e6c0-843a-e43b-a136-8ec1979a32e3@solarflare.com>

On Wed, 30 Oct 2019 10:52:04 +0000
Charles McLachlan <cmclachlan@solarflare.com> wrote:

> +/* Transmit a packet from an XDP buffer
> + *
> + * Returns number of packets sent on success, error code otherwise.
> + * Runs in NAPI context, either in our poll (for XDP TX) or a different NIC
> + * (for XDP redirect).
> + */
> +int efx_xdp_tx_buffers(struct efx_nic *efx, int n, struct xdp_frame **xdpfs,
> +		       bool flush)
> +{
> +	struct efx_tx_buffer *tx_buffer;
> +	struct efx_tx_queue *tx_queue;
> +	struct xdp_frame *xdpf;
> +	dma_addr_t dma_addr;
> +	unsigned int len;
> +	int space;
> +	int cpu;
> +	int i;
> +
> +	cpu = raw_smp_processor_id();
> +
> +	if (!efx->xdp_tx_queue_count ||
> +	    unlikely(cpu >= efx->xdp_tx_queue_count))
> +		return -EINVAL;
> +
> +	tx_queue = efx->xdp_tx_queues[cpu];
> +	if (unlikely(!tx_queue))
> +		return -EINVAL;
> +

If you return a negative value, then it is the caller responsibility
to free *all* the xdp_frame's, e.g. see bq_xmit_all() in devmap.c.

BUT if you start to process packets, and return a positive value, then
this function MUST handle freeing the frames it couldn't send.

> +	if (n && xdpfs) {
> +		/* Check for available space. We should never need multiple
> +		 * descriptors per frame.
> +		 */
> +		space = efx->txq_entries +
> +			tx_queue->read_count - tx_queue->insert_count;
> +		n = min(n, space);

This looks broken.  In case 'space' is too small, there will be
xdp_frame's left in xdpfs[] that was not send.  As desc above, this
function have to free those.


> +		for (i = 0; i < n; i++) {
> +			xdpf = xdpfs[i];
> +
> +			/* We'll want a descriptor for this tx. */
> +			prefetchw(__efx_tx_queue_get_insert_buffer(tx_queue));
> +
> +			len = xdpf->len;
> +
> +			/* Map for DMA. */
> +			dma_addr = dma_map_single(&efx->pci_dev->dev,
> +						  xdpf->data, len,
> +						  DMA_TO_DEVICE);
> +			if (dma_mapping_error(&efx->pci_dev->dev, dma_addr))
> +				return -EIO;
> +
> +			/*  Create descriptor and set up for unmapping DMA. */
> +			tx_buffer = efx_tx_map_chunk(tx_queue, dma_addr, len);
> +			tx_buffer->xdpf = xdpf;
> +			tx_buffer->flags = EFX_TX_BUF_XDP |
> +					   EFX_TX_BUF_MAP_SINGLE;
> +			tx_buffer->dma_offset = 0;
> +			tx_buffer->unmap_len = len;
> +		}
> +	}
> +
> +	/* Pass to hardware. */
> +	if (flush)
> +		efx_nic_push_buffers(tx_queue);
> +
> +	tx_queue->tx_packets += n;
> +
> +	return n;
> +}
> +


-- 
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer


  reply	other threads:[~2019-10-30 11:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-30 10:48 [PATCH net-next v3 0/6] sfc: Add XDP support Charles McLachlan
2019-10-30 10:50 ` [PATCH net-next v3 1/6] sfc: support encapsulation of xdp_frames in efx_tx_buffer Charles McLachlan
2019-10-30 10:51 ` [PATCH net-next v3 2/6] sfc: perform XDP processing on received packets Charles McLachlan
2019-10-30 10:51 ` [PATCH net-next v3 3/6] sfc: Enable setting of xdp_prog Charles McLachlan
2019-10-30 10:51 ` [PATCH net-next v3 4/6] sfc: allocate channels for XDP tx queues Charles McLachlan
2019-10-30 10:52 ` [PATCH net-next v3 5/6] sfc: handle XDP_TX outcomes of XDP eBPF programs Charles McLachlan
2019-10-30 11:34   ` Jesper Dangaard Brouer [this message]
2019-10-30 10:52 ` [PATCH net-next v3 6/6] sfc: add XDP counters to ethtool stats Charles McLachlan

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=20191030123406.762a51d3@carbon \
    --to=brouer@redhat.com \
    --cc=cmclachlan@solarflare.com \
    --cc=davem@davemloft.net \
    --cc=linux-net-drivers@solarflare.com \
    --cc=netdev@vger.kernel.org \
    /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