Skip to contentSkip to conversation

i40e: support for XDP

PATCH Superseded Björn Töpel 3 participants 7 messages May 23, 2017

Subsystems (2)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 cover i40e: support for XDP

From: Bj?rn T?pel <[email protected]>

This series adds XDP support for i40e-based NICs.

The first patch wires up ndo_xdp and implements XDP_DROP semantics for all actions. The second patch adds egress support via the XDP_TX action.

Performance numbers (40GbE port, 64B packets) for xdp1 and xdp2 programs, from samples/bpf/:

IOMMU | xdp1 | xdp2
---------------------------+-----------+-----------

 iommu=off                  | 29.7 Mpps | 17.1 Mpps
 iommu=pt intel_iommu=on    | 29.7 Mpps | 11.6 Mpps
 iommu=on intel_iommu=on    | 21.8 Mpps |  3.7 Mpps

Future improvements, not covered by the patches:
* Proper debugfs support.
* i40evf support.

Thanks to Alex, Daniel, John and Scott for all feedback!

v6:
* Addressed various cosmetic issues (reverse xmas tree formatting on local variables, preserve function parameter ordering, qvector mapping).
* Placed XDP Tx rings directly after Tx rings. This opened up to various simplications in the code, since we can now treat the XDP Tx rings as an extension of existing Tx ring space. E.g., i40e_set_ringparam now has smaller changeset.
* Ring allocation and setup was simplified (i40e_alloc_rings,

    i40e_vsi_alloc_arrays).

v5:
* Aligned the implementation to ixgbe's XDP support: naming, favor xchg instead of RCU semantics
* Support for XDP headroom (piggybacking on Alex' build_skb work)
* Added xdp tracepoints for exception states (as suggested by Daniel)

v4:
* Removed unused i40e_page_is_reserved function
* Prior running the XDP program, set the struct xdp_buff data_hard_start member

v3:
* Rebased patch set on Jeff's dev-queue branch
* MSI-X is no longer a prerequisite for XDP
* RCU locking for the XDP program and XDP_RX support is introduced in the same patch
* Rx bytes is now bumped for XDP
* Removed pointer-to-pointer clunkiness
* Added comments to XDP preconditions in ndo_xdp
* When a non-EOF is received, log once, and drop the frame

v2:
* Fixed kbuild error for PAGE_SIZE >= 8192.
* Renamed i40e_try_flip_rx_page to i40e_can_reuse_rx_page, which is more in line to the other Intel Ethernet drivers (igb/fm10k).
* Validate xdp_adjust_head support in ndo_xdp/XDP_SETUP_PROG.

Bj?rn T?pel (2):
i40e: add XDP support for pass and drop actions
i40e: add support for XDP_TX action

 drivers/net/ethernet/intel/i40e/i40e.h         |   8 +
 drivers/net/ethernet/intel/i40e/i40e_ethtool.c |  42 ++-
 drivers/net/ethernet/intel/i40e/i40e_main.c    | 352 ++++++++++++++++++++-----
 drivers/net/ethernet/intel/i40e/i40e_txrx.c    | 244 ++++++++++++++---
 drivers/net/ethernet/intel/i40e/i40e_txrx.h    |  12 +
 5 files changed, 553 insertions(+), 105 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH v6 1/2 i40e: add XDP support for pass and drop actions

From: Bj?rn T?pel <[email protected]>

This commit adds basic XDP support for i40e derived NICs. All XDP actions will end up in XDP_DROP.

---
 drivers/net/ethernet/intel/i40e/i40e.h      |   7 ++
 drivers/net/ethernet/intel/i40e/i40e_main.c |  75 ++++++++++++++++
 drivers/net/ethernet/intel/i40e/i40e_txrx.c | 130 +++++++++++++++++++++-------
 drivers/net/ethernet/intel/i40e/i40e_txrx.h |   1 +
 4 files changed, 182 insertions(+), 31 deletions(-)
drivers/net/ethernet/intel/i40e/i40e.h +7 -0
index 395ca94faf80..d3195b29d53c 100644
@@ -645,6 +645,8 @@ struct i40e_vsi {
 	u16 max_frame;
 	u16 rx_buf_len;
 
+	struct bpf_prog *xdp_prog;
+
 	/* List of q_vectors allocated to this VSI */
 	struct i40e_q_vector **q_vectors;
 	int num_q_vectors;
@@ -972,4 +974,9 @@ i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf);
 i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf);
 i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf);
 void i40e_print_link_message(struct i40e_vsi *vsi, bool isup);
+
+static inline bool i40e_enabled_xdp_vsi(struct i40e_vsi *vsi)
+{
+	return !!vsi->xdp_prog;
+}
 #endif /* _I40E_H_ */
drivers/net/ethernet/intel/i40e/i40e_main.c +75 -0

99 lines not on this page · raw message

drivers/net/ethernet/intel/i40e/i40e_txrx.c +99 -31

236 lines not on this page · raw message

drivers/net/ethernet/intel/i40e/i40e_txrx.h +1 -0
index f5de51124cae..31f0b162996f 100644
@@ -360,6 +360,7 @@ struct i40e_ring {
 	void *desc;			/* Descriptor ring memory */
 	struct device *dev;		/* Used for DMA mapping */
 	struct net_device *netdev;	/* netdev ring maps to */
+	struct bpf_prog *xdp_prog;
 	union {
 		struct i40e_tx_buffer *tx_bi;
 		struct i40e_rx_buffer *rx_bi;
Signature · 1 line
2.11.0
#6 lore raw

PATCH v6 2/2 i40e: add support for XDP_TX action

In reply to Björn Töpel

From: Bj?rn T?pel <[email protected]>

This patch adds proper XDP_TX action support. For each Tx ring, an additional XDP Tx ring is allocated and setup. This version does the DMA mapping in the fast-path, which will penalize performance for IOMMU enabled systems. Further, debugfs support is not wired up for the XDP Tx rings.

---
 drivers/net/ethernet/intel/i40e/i40e.h         |   1 +
 drivers/net/ethernet/intel/i40e/i40e_ethtool.c |  42 +++-
 drivers/net/ethernet/intel/i40e/i40e_main.c    | 277 +++++++++++++++++++------
 drivers/net/ethernet/intel/i40e/i40e_txrx.c    | 118 ++++++++++-
 drivers/net/ethernet/intel/i40e/i40e_txrx.h    |  11 +
 5 files changed, 373 insertions(+), 76 deletions(-)
drivers/net/ethernet/intel/i40e/i40e.h +1 -0
index d3195b29d53c..4250ab55a9f1 100644
@@ -629,6 +629,7 @@ struct i40e_vsi {
 	/* These are containers of ring pointers, allocated at run-time */
 	struct i40e_ring **rx_rings;
 	struct i40e_ring **tx_rings;
+	struct i40e_ring **xdp_rings; /* XDP Tx rings */
 
 	u32  active_filters;
 	u32  promisc_threshold;
drivers/net/ethernet/intel/i40e/i40e_ethtool.c +33 -9

94 lines not on this page · raw message

drivers/net/ethernet/intel/i40e/i40e_main.c +215 -62

459 lines not on this page · raw message

drivers/net/ethernet/intel/i40e/i40e_txrx.c +113 -5

188 lines not on this page · raw message

drivers/net/ethernet/intel/i40e/i40e_txrx.h +11 -0
index 31f0b162996f..b288d58313a6 100644
@@ -396,6 +396,7 @@ struct i40e_ring {
 	u16 flags;
 #define I40E_TXR_FLAGS_WB_ON_ITR		BIT(0)
 #define I40E_RXR_FLAGS_BUILD_SKB_ENABLED	BIT(1)
+#define I40E_TXR_FLAGS_XDP			BIT(2)
 
 	/* stats structs */
 	struct i40e_queue_stats	stats;
@@ -438,6 +439,16 @@ static inline void clear_ring_build_skb_enabled(struct i40e_ring *ring)
 	ring->flags &= ~I40E_RXR_FLAGS_BUILD_SKB_ENABLED;
 }
 
+static inline bool ring_is_xdp(struct i40e_ring *ring)
+{
+	return !!(ring->flags & I40E_TXR_FLAGS_XDP);
+}
+
+static inline void set_ring_xdp(struct i40e_ring *ring)
+{
+	ring->flags |= I40E_TXR_FLAGS_XDP;
+}
+
 enum i40e_latency_range {
 	I40E_LOWEST_LATENCY = 0,
 	I40E_LOW_LATENCY = 1,
Signature · 1 line
2.11.0
#2 lore raw

PATCH v6 1/2 i40e: add XDP support for pass and drop actions

In reply to Björn Töpel
Quoted 6 lines · Bj?rn T?pel

From: Bj?rn T?pel <[email protected]>

This commit adds basic XDP support for i40e derived NICs. All XDP actions will end up in XDP_DROP.

So I only really see one issue which I pointed out earlier. Basically the i40e_change_mtu call can't really be dependent on vsi->rx_buf_len since rx_buf_len is changed as a result of changing the MTU.

Quoted 7 lines
---
 drivers/net/ethernet/intel/i40e/i40e.h      |   7 ++
 drivers/net/ethernet/intel/i40e/i40e_main.c |  75 ++++++++++++++++
 drivers/net/ethernet/intel/i40e/i40e_txrx.c | 130 +++++++++++++++++++++-------
 drivers/net/ethernet/intel/i40e/i40e_txrx.h |   1 +
 4 files changed, 182 insertions(+), 31 deletions(-)

[...]

Quoted 13 lines
drivers/net/ethernet/intel/i40e/i40e_main.c +1 -0
index 8d1d3b859af7..c8b1db0ebb9e 100644
@@ -27,6 +27,7 @@
 #include <linux/etherdevice.h>
 #include <linux/of_net.h>
 #include <linux/pci.h>
+#include <linux/bpf.h>
 
 /* Local includes */
 #include "i40e.h"

drivers/net/ethernet/intel/i40e/i40e_main.c static int i40e_change_mtu(struct net_device *netdev, int new_mtu) · line 2418

Quoted 10 lines
drivers/net/ethernet/intel/i40e/i40e_main.c +7 -0
@@ -2408,6 +2409,13 @@ static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
        struct i40e_vsi *vsi = np->vsi;
        struct i40e_pf *pf = vsi->back;
 
+       if (i40e_enabled_xdp_vsi(vsi)) {
+               int frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
+
+               if (frame_size > vsi->rx_buf_len)
+                       return -EINVAL;
+       }
+

So this code suffers from the same issue that John's ixgbe code did. You might be better off implementing something like we did with i40e_vsi_configure_rx. Basically the upper limit can be either 3K or 2K if the page size greater than 4K or the LEGACY_RX flag is set. You might look at adding a check here for that instead of just comparing it to vsi->rx_buf_len since rx_buf_len can change depending on the MTU size.

- Alex

#3 lore raw

PATCH v6 1/2 i40e: add XDP support for pass and drop actions

2017-05-23 18:51 GMT+02:00 Alexander Duyck <[email protected]>:

Quoted 38 lines · Bj?rn T?pel
Quoted 6 lines

From: Bj?rn T?pel <[email protected]>

This commit adds basic XDP support for i40e derived NICs. All XDP actions will end up in XDP_DROP.

So I only really see one issue which I pointed out earlier. Basically the i40e_change_mtu call can't really be dependent on vsi->rx_buf_len since rx_buf_len is changed as a result of changing the MTU.

Quoted 7 lines
---
 drivers/net/ethernet/intel/i40e/i40e.h      |   7 ++
 drivers/net/ethernet/intel/i40e/i40e_main.c |  75 ++++++++++++++++
 drivers/net/ethernet/intel/i40e/i40e_txrx.c | 130 +++++++++++++++++++++-------
 drivers/net/ethernet/intel/i40e/i40e_txrx.h |   1 +
 4 files changed, 182 insertions(+), 31 deletions(-)

[...]

Quoted 16 lines
drivers/net/ethernet/intel/i40e/i40e_main.c +1 -0
index 8d1d3b859af7..c8b1db0ebb9e 100644
@@ -27,6 +27,7 @@
 #include <linux/etherdevice.h>
 #include <linux/of_net.h>
 #include <linux/pci.h>
+#include <linux/bpf.h>
 
 /* Local includes */
 #include "i40e.h"
@@ -2408,6 +2409,13 @@ static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
        struct i40e_vsi *vsi = np->vsi;
        struct i40e_pf *pf = vsi->back;
 
Quoted 16 lines

drivers/net/ethernet/intel/i40e/i40e_main.c static int i40e_change_mtu(struct net_device *netdev, int new_mtu) · line 2418

Quoted 7 lines
drivers/net/ethernet/intel/i40e/i40e_main.c +7 -0
+       if (i40e_enabled_xdp_vsi(vsi)) {
+               int frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
+
+               if (frame_size > vsi->rx_buf_len)
+                       return -EINVAL;
+       }
+

So this code suffers from the same issue that John's ixgbe code did. You might be better off implementing something like we did with i40e_vsi_configure_rx. Basically the upper limit can be either 3K or 2K if the page size greater than 4K or the LEGACY_RX flag is set. You might look at adding a check here for that instead of just comparing it to vsi->rx_buf_len since rx_buf_len can change depending on the MTU size.

You pointed this out in our private conversation, but obviously I didn't get it... :-(

So, something in lines of:

@@ -2396,6 +2397,18 @@ static void i40e_sync_filters_subtask(struct i40e_pf *pf)
}

/**
+ * i40e_max_xdp_frame_size - returns the maximum allowed frame size for XDP
+ * @vsi: the vsi
+ **/
+static int i40e_max_xdp_frame_size(struct i40e_vsi *vsi)
+{
+ if (PAGE_SIZE >= 8192 || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
+ return I40E_RXBUFFER_2048;
+ else
+ return I40E_RXBUFFER_3072;
+}
+
+/**
* i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
* @netdev: network interface device structure
* @new_mtu: new value for maximum frame size
@@ -2408,6 +2421,13 @@ static int i40e_change_mtu(struct net_device *netdev, int new_mtu)

        struct i40e_vsi *vsi = np->vsi;
        struct i40e_pf *pf = vsi->back;

+ if (i40e_enabled_xdp_vsi(vsi)) {
+ int frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
+
+ if (frame_size > i40e_max_xdp_frame_size(vsi))
+ return -EINVAL;
+ }
+

        netdev_info(netdev, "changing MTU from %d to %d\n",
                    netdev->mtu, new_mtu);
        netdev->mtu = new_mtu;

Bj?rn

Quoted 1 line

- Alex

#4 lore raw

PATCH v6 1/2 i40e: add XDP support for pass and drop actions

Quoted 102 lines · Bj?rn T?pel

2017-05-23 18:51 GMT+02:00 Alexander Duyck <[email protected]>:

Quoted 42 lines · Bj?rn T?pel
Quoted 7 lines

From: Bj?rn T?pel <[email protected]>

This commit adds basic XDP support for i40e derived NICs. All XDP actions will end up in XDP_DROP.

So I only really see one issue which I pointed out earlier. Basically the i40e_change_mtu call can't really be dependent on vsi->rx_buf_len since rx_buf_len is changed as a result of changing the MTU.

Quoted 8 lines
---
 drivers/net/ethernet/intel/i40e/i40e.h      |   7 ++
 drivers/net/ethernet/intel/i40e/i40e_main.c |  75 ++++++++++++++++
 drivers/net/ethernet/intel/i40e/i40e_txrx.c | 130 +++++++++++++++++++++-------
 drivers/net/ethernet/intel/i40e/i40e_txrx.h |   1 +
 4 files changed, 182 insertions(+), 31 deletions(-)

[...]

Quoted 17 lines
drivers/net/ethernet/intel/i40e/i40e_main.c +1 -0
index 8d1d3b859af7..c8b1db0ebb9e 100644
@@ -27,6 +27,7 @@
 #include <linux/etherdevice.h>
 #include <linux/of_net.h>
 #include <linux/pci.h>
+#include <linux/bpf.h>
 
 /* Local includes */
 #include "i40e.h"
@@ -2408,6 +2409,13 @@ static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
        struct i40e_vsi *vsi = np->vsi;
        struct i40e_pf *pf = vsi->back;
 
Quoted 16 lines

drivers/net/ethernet/intel/i40e/i40e_main.c static int i40e_change_mtu(struct net_device *netdev, int new_mtu) · line 2418

Quoted 7 lines
drivers/net/ethernet/intel/i40e/i40e_main.c +7 -0
+       if (i40e_enabled_xdp_vsi(vsi)) {
+               int frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
+
+               if (frame_size > vsi->rx_buf_len)
+                       return -EINVAL;
+       }
+

So this code suffers from the same issue that John's ixgbe code did. You might be better off implementing something like we did with i40e_vsi_configure_rx. Basically the upper limit can be either 3K or 2K if the page size greater than 4K or the LEGACY_RX flag is set. You might look at adding a check here for that instead of just comparing it to vsi->rx_buf_len since rx_buf_len can change depending on the MTU size.

You pointed this out in our private conversation, but obviously I didn't get it... :-(

So, something in lines of:

drivers/net/ethernet/intel/i40e/i40e_main.c +19 -0
@@ -2396,6 +2397,18 @@ static void i40e_sync_filters_subtask(struct i40e_pf *pf)
 }
 
 /**
+ * i40e_max_xdp_frame_size - returns the maximum allowed frame size for XDP
+ * @vsi: the vsi
+ **/
+static int i40e_max_xdp_frame_size(struct i40e_vsi *vsi)
+{
+       if (PAGE_SIZE >= 8192 || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
+               return I40E_RXBUFFER_2048;
+       else
+               return I40E_RXBUFFER_3072;
+}
+
+/**
  * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
  * @netdev: network interface device structure
  * @new_mtu: new value for maximum frame size
@@ -2408,6 +2421,13 @@ static int i40e_change_mtu(struct net_device
 *netdev, int new_mtu)
        struct i40e_vsi *vsi = np->vsi;
        struct i40e_pf *pf = vsi->back;
 
+       if (i40e_enabled_xdp_vsi(vsi)) {
+               int frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
+
+               if (frame_size > i40e_max_xdp_frame_size(vsi))
+                       return -EINVAL;
+       }
+
        netdev_info(netdev, "changing MTU from %d to %d\n",
                    netdev->mtu, new_mtu);
        netdev->mtu = new_mtu;
Quoted 1 line

Bj?rn

Yes this is exactly what I had in mind. If you can fold this into your patch then I would say we pretty much have this all wrapped up (at least until we find something in testing :-)).

Thanks.

- Alex

#5 lore raw

PATCH v6 1/2 i40e: add XDP support for pass and drop actions

2017-05-23 22:00 GMT+02:00 Duyck, Alexander H <[email protected]>:

Quoted 103 lines · Bj?rn T?pel
Quoted 102 lines

2017-05-23 18:51 GMT+02:00 Alexander Duyck <[email protected]>:

Quoted 42 lines · Bj?rn T?pel
Quoted 7 lines

From: Bj?rn T?pel <[email protected]>

This commit adds basic XDP support for i40e derived NICs. All XDP actions will end up in XDP_DROP.

So I only really see one issue which I pointed out earlier. Basically the i40e_change_mtu call can't really be dependent on vsi->rx_buf_len since rx_buf_len is changed as a result of changing the MTU.

Quoted 8 lines
---
 drivers/net/ethernet/intel/i40e/i40e.h      |   7 ++
 drivers/net/ethernet/intel/i40e/i40e_main.c |  75 ++++++++++++++++
 drivers/net/ethernet/intel/i40e/i40e_txrx.c | 130 +++++++++++++++++++++-------
 drivers/net/ethernet/intel/i40e/i40e_txrx.h |   1 +
 4 files changed, 182 insertions(+), 31 deletions(-)

[...]

Quoted 17 lines
drivers/net/ethernet/intel/i40e/i40e_main.c +1 -0
index 8d1d3b859af7..c8b1db0ebb9e 100644
@@ -27,6 +27,7 @@
 #include <linux/etherdevice.h>
 #include <linux/of_net.h>
 #include <linux/pci.h>
+#include <linux/bpf.h>
 
 /* Local includes */
 #include "i40e.h"
@@ -2408,6 +2409,13 @@ static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
        struct i40e_vsi *vsi = np->vsi;
        struct i40e_pf *pf = vsi->back;
 
Quoted 16 lines

drivers/net/ethernet/intel/i40e/i40e_main.c static int i40e_change_mtu(struct net_device *netdev, int new_mtu) · line 2418

Quoted 7 lines
drivers/net/ethernet/intel/i40e/i40e_main.c +7 -0
+       if (i40e_enabled_xdp_vsi(vsi)) {
+               int frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
+
+               if (frame_size > vsi->rx_buf_len)
+                       return -EINVAL;
+       }
+

So this code suffers from the same issue that John's ixgbe code did. You might be better off implementing something like we did with i40e_vsi_configure_rx. Basically the upper limit can be either 3K or 2K if the page size greater than 4K or the LEGACY_RX flag is set. You might look at adding a check here for that instead of just comparing it to vsi->rx_buf_len since rx_buf_len can change depending on the MTU size.

You pointed this out in our private conversation, but obviously I didn't get it... :-(

So, something in lines of:

drivers/net/ethernet/intel/i40e/i40e_main.c +19 -0
@@ -2396,6 +2397,18 @@ static void i40e_sync_filters_subtask(struct i40e_pf *pf)
 }
 
 /**
+ * i40e_max_xdp_frame_size - returns the maximum allowed frame size for XDP
+ * @vsi: the vsi
+ **/
+static int i40e_max_xdp_frame_size(struct i40e_vsi *vsi)
+{
+       if (PAGE_SIZE >= 8192 || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
+               return I40E_RXBUFFER_2048;
+       else
+               return I40E_RXBUFFER_3072;
+}
+
+/**
  * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
  * @netdev: network interface device structure
  * @new_mtu: new value for maximum frame size
@@ -2408,6 +2421,13 @@ static int i40e_change_mtu(struct net_device
 *netdev, int new_mtu)
        struct i40e_vsi *vsi = np->vsi;
        struct i40e_pf *pf = vsi->back;
 
+       if (i40e_enabled_xdp_vsi(vsi)) {
+               int frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
+
+               if (frame_size > i40e_max_xdp_frame_size(vsi))
+                       return -EINVAL;
+       }
+
        netdev_info(netdev, "changing MTU from %d to %d\n",
                    netdev->mtu, new_mtu);
        netdev->mtu = new_mtu;
Quoted 5 lines
Quoted 1 line

Bj?rn

Yes this is exactly what I had in mind. If you can fold this into your patch then I would say we pretty much have this all wrapped up (at least until we find something in testing :-)).

Yay! Getting closer... ;-)

I'll spin a v7.

Bj?rn

Quoted 4 lines

Thanks.

- Alex