From: John Fastabend <john.fastabend@gmail.com>
To: intel-wired-lan@osuosl.org
Subject: [Intel-wired-lan] [net-next PATCH v4 1/2] ixgbe: add XDP support for pass and drop actions
Date: Sat, 11 Mar 2017 08:48:18 -0800 [thread overview]
Message-ID: <58C42A52.10609@gmail.com> (raw)
In-Reply-To: <CALDO+SY4UH1_qc971_-y5Tn=1Kzy-a8AoxJdyzghm+-_=FnrHg@mail.gmail.com>
On 17-03-11 07:49 AM, William Tu wrote:
> On Fri, Mar 10, 2017 at 11:11 AM, John Fastabend
> <john.fastabend@gmail.com> wrote:
>> Basic XDP drop support for ixgbe. Uses READ_ONCE/xchg semantics on XDP
>> programs instead of rcu primitives as suggested by Daniel Borkmann and
>> Alex Duyck.
>>
>> Signed-off-by: John Fastabend <john.r.fastabend@intel.com>
>> ---
[...]
>> /**
>> * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
>> * @q_vector: structure containing interrupt and ring information
>> @@ -2184,6 +2230,7 @@ static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
>> union ixgbe_adv_rx_desc *rx_desc;
>> struct ixgbe_rx_buffer *rx_buffer;
>> struct sk_buff *skb;
>> + struct xdp_buff xdp;
>> unsigned int size;
>>
>> /* return some buffers to hardware, one at a time is too slow */
>> @@ -2205,15 +2252,29 @@ static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
>>
>> rx_buffer = ixgbe_get_rx_buffer(rx_ring, rx_desc, &skb, size);
>>
>> - /* retrieve a buffer from the ring */
>> - if (skb)
>> + if (!skb) {
>> + xdp.data = page_address(rx_buffer->page) +
>> + rx_buffer->page_offset;
>> + xdp.data_hard_start = xdp.data -
>> + ixgbe_rx_offset(rx_ring);
We have ixgbe_rx_offset(rx_ring) headroom to support adding headers.
>> + xdp.data_end = xdp.data + size;
>> +
>> + skb = ixgbe_run_xdp(rx_ring, &xdp);
>> + }
>> +
>> + if (IS_ERR(skb)) {
>> + total_rx_packets++;
>> + total_rx_bytes += size;
>> + rx_buffer->pagecnt_bias++;
>> + } else if (skb) {
>> ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, size);
>> - else if (ring_uses_build_skb(rx_ring))
>> + } else if (ring_uses_build_skb(rx_ring)) {
>> skb = ixgbe_build_skb(rx_ring, rx_buffer,
>> - rx_desc, size);
>> - else
>> + &xdp, rx_desc);
>> + } else {
>> skb = ixgbe_construct_skb(rx_ring, rx_buffer,
>> - rx_desc, size);
>> + &xdp, rx_desc);
>> + }
>>
>> /* exit if we failed to retrieve a buffer */
>> if (!skb) {
[...]
>> +static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog)
>> +{
>> + int i, frame_size = dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
>> + struct ixgbe_adapter *adapter = netdev_priv(dev);
>> + struct bpf_prog *old_prog;
>> +
>> + if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
>> + return -EINVAL;
>> +
>> + if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
>> + return -EINVAL;
>> +
>> + /* verify ixgbe ring attributes are sufficient for XDP */
>> + for (i = 0; i < adapter->num_rx_queues; i++) {
>> + struct ixgbe_ring *ring = adapter->rx_ring[i];
>> +
>> + if (ring_is_rsc_enabled(ring))
>> + return -EINVAL;
>> +
>> + if (frame_size > ixgbe_rx_bufsz(ring))
>> + return -EINVAL;
>> + }
>> +
>> + old_prog = xchg(&adapter->xdp_prog, prog);
>> + for (i = 0; i < adapter->num_rx_queues; i++)
>> + xchg(&adapter->rx_ring[i]->xdp_prog, adapter->xdp_prog);
>> +
>> + if (old_prog)
>> + bpf_prog_put(old_prog);
>> +
>> + return 0;
>> +}
>
> Since the patch does not support xdp_adjust_head() yet, should we
> detect and return -EOPNOTSUPP?
>
It actually should support xdp_adjust_head() :)
At least I tested the xdp tunnel program in ./bpf/samples/ and it worked.
Also I do a standard test where I push the packet up the stack after adding
headers and that appears to work although I wonder a bit about some of the
skb metadata. By working in this case I just use tshark and verify the pkt
is received with the new header by the stack.
> --William
next prev parent reply other threads:[~2017-03-11 16:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-10 19:11 [Intel-wired-lan] [net-next PATCH v4 1/2] ixgbe: add XDP support for pass and drop actions John Fastabend
2017-03-10 19:12 ` [Intel-wired-lan] [net-next PATCH v4 2/2] ixgbe: add support for XDP_TX action John Fastabend
2017-03-10 20:38 ` [Intel-wired-lan] [net-next PATCH v4 1/2] ixgbe: add XDP support for pass and drop actions Alexander Duyck
2017-03-11 5:39 ` John Fastabend
2017-03-11 15:49 ` William Tu
2017-03-11 16:48 ` John Fastabend [this message]
2017-03-11 20:05 ` William Tu
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=58C42A52.10609@gmail.com \
--to=john.fastabend@gmail.com \
--cc=intel-wired-lan@osuosl.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.