Skip to contentSkip to conversation

i40e: tweak page counting for XDP_REDIRECT

PATCH New Björn Töpel 2 participants 4 messages Mar 22, 2018 – Mar 23, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 i40e: tweak page counting for XDP_REDIRECT

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

This commit tweaks the page counting for XDP_REDIRECT to function properly. XDP_REDIRECT support will be added in a future commit.

The current page counting scheme assumes that the reference count cannot decrease until the received frame is sent to the upper layers of the networking stack. This assumption does not hold for the XDP_REDIRECT action, since a page (pointed out by xdp_buff) can have its reference count decreased via the xdp_do_redirect call.

To work around that, we now start off by a large page count and then don't allow a refcount less than two.

---
 drivers/net/ethernet/intel/i40e/i40e_txrx.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_txrx.c +4 -5
index e8eef9a56b6b..2f817d1466eb 100644
@@ -1588,9 +1588,8 @@ static bool i40e_alloc_mapped_page(struct i40e_ring *rx_ring,
 	bi->dma = dma;
 	bi->page = page;
 	bi->page_offset = i40e_rx_offset(rx_ring);
-
-	/* initialize pagecnt_bias to 1 representing we fully own page */
-	bi->pagecnt_bias = 1;
+	page_ref_add(page, USHRT_MAX - 1);
+	bi->pagecnt_bias = USHRT_MAX;
 
 	return true;
 }
@@ -1956,8 +1955,8 @@ static bool i40e_can_reuse_rx_page(struct i40e_rx_buffer *rx_buffer)
 	 * the pagecnt_bias and page count so that we fully restock the
 	 * number of references the driver holds.
 	 */
-	if (unlikely(!pagecnt_bias)) {
-		page_ref_add(page, USHRT_MAX);
+	if (unlikely(pagecnt_bias == 1)) {
+		page_ref_add(page, USHRT_MAX - 1);
 		rx_buffer->pagecnt_bias = USHRT_MAX;
 	}
 
Signature · 1 line
2.7.4
#1 lore raw

PATCH v3 2/2 i40e: add support for XDP_REDIRECT

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

The driver now acts upon the XDP_REDIRECT return action. Two new ndos are implemented, ndo_xdp_xmit and ndo_xdp_flush.

XDP_REDIRECT action enables XDP program to redirect frames to other netdevs.

---
 drivers/net/ethernet/intel/i40e/i40e_main.c |  2 +
 drivers/net/ethernet/intel/i40e/i40e_txrx.c | 74 +++++++++++++++++++++++++----
 drivers/net/ethernet/intel/i40e/i40e_txrx.h |  2 +
 3 files changed, 68 insertions(+), 10 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_main.c +2 -0
index 79ab52276d12..2fb4261b4fd9 100644
@@ -11815,6 +11815,8 @@ static const struct net_device_ops i40e_netdev_ops = {
 	.ndo_bridge_getlink	= i40e_ndo_bridge_getlink,
 	.ndo_bridge_setlink	= i40e_ndo_bridge_setlink,
 	.ndo_bpf		= i40e_xdp,
+	.ndo_xdp_xmit		= i40e_xdp_xmit,
+	.ndo_xdp_flush		= i40e_xdp_flush,
 };
 
 /**
drivers/net/ethernet/intel/i40e/i40e_txrx.c +64 -10

102 lines not on this page · raw message

drivers/net/ethernet/intel/i40e/i40e_txrx.h +2 -0
index 2444f338bb0c..a97e59721393 100644
@@ -510,6 +510,8 @@ u32 i40e_get_tx_pending(struct i40e_ring *ring, bool in_sw);
 void i40e_detect_recover_hung(struct i40e_vsi *vsi);
 int __i40e_maybe_stop_tx(struct i40e_ring *tx_ring, int size);
 bool __i40e_chk_linearize(struct sk_buff *skb);
+int i40e_xdp_xmit(struct net_device *dev, struct xdp_buff *xdp);
+void i40e_xdp_flush(struct net_device *dev);
 
 /**
  * i40e_get_head - Retrieve head from head writeback
Signature · 1 line
2.7.4
#2 lore raw

PATCH v3 2/2 i40e: add support for XDP_REDIRECT

Quoted 19 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Bj?rn T?pel
Sent: Thursday, March 22, 2018 8:15 AM
To: Kirsher, Jeffrey T <[email protected]>; intel-wired- lan at lists.osuosl.org
Cc: netdev at vger.kernel.org; Topel, Bjorn <[email protected]>; Karlsson, Magnus <[email protected]>
Subject: [Intel-wired-lan] [PATCH v3 2/2] i40e: add support for XDP_REDIRECT

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

The driver now acts upon the XDP_REDIRECT return action. Two new ndos are implemented, ndo_xdp_xmit and ndo_xdp_flush.

XDP_REDIRECT action enables XDP program to redirect frames to other netdevs.

Quoted 7 lines
---
 drivers/net/ethernet/intel/i40e/i40e_main.c |  2 +
drivers/net/ethernet/intel/i40e/i40e_txrx.c | 74
+++++++++++++++++++++++++----
drivers/net/ethernet/intel/i40e/i40e_txrx.h |  2 +
 3 files changed, 68 insertions(+), 10 deletions(-)
#3 lore raw

PATCH v3 1/2 i40e: tweak page counting for XDP_REDIRECT

In reply to Björn Töpel
Quoted 22 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Bj?rn T?pel
Sent: Thursday, March 22, 2018 8:15 AM
To: Kirsher, Jeffrey T <[email protected]>; intel-wired- lan at lists.osuosl.org
Cc: netdev at vger.kernel.org; Topel, Bjorn <[email protected]>; Karlsson, Magnus <[email protected]>
Subject: [Intel-wired-lan] [PATCH v3 1/2] i40e: tweak page counting for XDP_REDIRECT

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

This commit tweaks the page counting for XDP_REDIRECT to function properly. XDP_REDIRECT support will be added in a future commit.

The current page counting scheme assumes that the reference count cannot decrease until the received frame is sent to the upper layers of the networking stack. This assumption does not hold for the XDP_REDIRECT action, since a page (pointed out by xdp_buff) can have its reference count decreased via the xdp_do_redirect call.

Quoted 7 lines

To work around that, we now start off by a large page count and then don't allow a refcount less than two.

---
 drivers/net/ethernet/intel/i40e/i40e_txrx.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)