bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH net v2] igb: Fix XDP with PTP enabled
@ 2021-04-25 23:09 Tyler S
  2021-04-26 14:15 ` Kurt Kanzenbach
  0 siblings, 1 reply; 7+ messages in thread
From: Tyler S @ 2021-04-25 23:09 UTC (permalink / raw)
  To: kurt
  Cc: alexander.duyck, anthony.l.nguyen, ast, bigeasy, bpf, daniel,
	davem, hawk, ilias.apalodimas, intel-wired-lan, jesse.brandeburg,
	john.fastabend, kuba, lorenzo, netdev, richardcochran,
	sven.auhagen

Thanks for this work; I was having trouble using XDP on my I354 NIC until this.

Hopefully I have not err'd backporting it to 5.10 -- but I'm seeing
jumbo frames dropped after applying this (though as previously
mentioned, non-skb/full driver XDP programs do now work).

Looking at the code, I'm not sure why that is.

- Tyler

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net v2] igb: Fix XDP with PTP enabled
  2021-04-25 23:09 [PATCH net v2] igb: Fix XDP with PTP enabled Tyler S
@ 2021-04-26 14:15 ` Kurt Kanzenbach
  2021-04-27 23:11   ` Tyler S
  0 siblings, 1 reply; 7+ messages in thread
From: Kurt Kanzenbach @ 2021-04-26 14:15 UTC (permalink / raw)
  To: Tyler S
  Cc: alexander.duyck, anthony.l.nguyen, ast, bigeasy, bpf, daniel,
	davem, hawk, ilias.apalodimas, intel-wired-lan, jesse.brandeburg,
	john.fastabend, kuba, lorenzo, netdev, richardcochran,
	sven.auhagen, Maciej Fijalkowski

[-- Attachment #1: Type: text/plain, Size: 635 bytes --]

On Sun Apr 25 2021, Tyler S wrote:
> Thanks for this work; I was having trouble using XDP on my I354 NIC until this.
>
> Hopefully I have not err'd backporting it to 5.10 -- but I'm seeing
> jumbo frames dropped after applying this (though as previously
> mentioned, non-skb/full driver XDP programs do now work).
>
> Looking at the code, I'm not sure why that is.

I'm also not sure, yet.

Can you try with version 3 of this patch [1] and see if there are still
issues with jumbo frames? Can you also share the backported patch for
v5.10?

Thanks,
Kurt

[1] - https://lkml.kernel.org/netdev/20210422052617.17267-1-kurt@linutronix.de/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net v2] igb: Fix XDP with PTP enabled
  2021-04-26 14:15 ` Kurt Kanzenbach
@ 2021-04-27 23:11   ` Tyler S
  2021-05-03  7:31     ` Kurt Kanzenbach
  0 siblings, 1 reply; 7+ messages in thread
From: Tyler S @ 2021-04-27 23:11 UTC (permalink / raw)
  To: Kurt Kanzenbach
  Cc: alexander.duyck, anthony.l.nguyen, ast, bigeasy, bpf, daniel,
	davem, hawk, ilias.apalodimas, intel-wired-lan, jesse.brandeburg,
	john.fastabend, kuba, lorenzo, netdev, richardcochran,
	sven.auhagen, Maciej Fijalkowski

On Mon, Apr 26, 2021 at 10:15 AM Kurt Kanzenbach <kurt@linutronix.de> wrote:
>
> On Sun Apr 25 2021, Tyler S wrote:
> > Thanks for this work; I was having trouble using XDP on my I354 NIC until this.
> >
> > Hopefully I have not err'd backporting it to 5.10 -- but I'm seeing
> > jumbo frames dropped after applying this (though as previously
> > mentioned, non-skb/full driver XDP programs do now work).
> >
> > Looking at the code, I'm not sure why that is.
>
> I'm also not sure, yet.
>
> Can you try with version 3 of this patch [1] and see if there are still
> issues with jumbo frames? Can you also share the backported patch for
> v5.10?
>
> Thanks,
> Kurt
>
> [1] - https://lkml.kernel.org/netdev/20210422052617.17267-1-kurt@linutronix.de/

Sorry, I didn't see v3.  I can confirm that v3 fixes the issue I was
seeing with jumbo frames.

The only part of the patch that differs for 5.10 is the hunk I'll
include inline.  Thanks again for your work!

Cheers,
Tyler
@@ -8720,11 +8716,22 @@ static int igb_clean_rx_irq(struct
igb_q_vector *q_vector, const int budget)
                dma_rmb();

                rx_buffer = igb_get_rx_buffer(rx_ring, size, &rx_buf_pgcnt);
+               pktbuf = page_address(rx_buffer->page) + rx_buffer->page_offset;
+
+               /* pull rx packet timestamp if available and valid */
+               if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
+                       timestamp = igb_ptp_rx_pktstamp(rx_ring->q_vector,
+                                                       pktbuf);
+
+                       if (timestamp) {
+                               pkt_offset += IGB_TS_HDR_LEN;
+                               size -= IGB_TS_HDR_LEN;
+                       }
+               }

                /* retrieve a buffer from the ring */
                if (!skb) {
-                       xdp.data = page_address(rx_buffer->page) +
-                                  rx_buffer->page_offset;
+                       xdp.data = pktbuf + pkt_offset;
                        xdp.data_meta = xdp.data;
                        xdp.data_hard_start = xdp.data -
                                              igb_rx_offset(rx_ring);

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net v2] igb: Fix XDP with PTP enabled
  2021-04-27 23:11   ` Tyler S
@ 2021-05-03  7:31     ` Kurt Kanzenbach
  0 siblings, 0 replies; 7+ messages in thread
From: Kurt Kanzenbach @ 2021-05-03  7:31 UTC (permalink / raw)
  To: Tyler S
  Cc: alexander.duyck, anthony.l.nguyen, ast, bigeasy, bpf, daniel,
	davem, hawk, ilias.apalodimas, intel-wired-lan, jesse.brandeburg,
	john.fastabend, kuba, lorenzo, netdev, richardcochran,
	sven.auhagen, Maciej Fijalkowski

[-- Attachment #1: Type: text/plain, Size: 195 bytes --]

On Tue Apr 27 2021, Tyler S wrote:
> Sorry, I didn't see v3.  I can confirm that v3 fixes the issue I was
> seeing with jumbo frames.

Great :). I just sent v4 and added you to Cc.

Thanks,
Kurt

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net v2] igb: Fix XDP with PTP enabled
  2021-04-20 16:33 ` Nguyen, Anthony L
@ 2021-04-21  6:35   ` Kurt Kanzenbach
  0 siblings, 0 replies; 7+ messages in thread
From: Kurt Kanzenbach @ 2021-04-21  6:35 UTC (permalink / raw)
  To: Nguyen, Anthony L, davem, kuba, Brandeburg, Jesse
  Cc: bigeasy, daniel, bpf, ast, hawk, lorenzo, john.fastabend,
	alexander.duyck, ilias.apalodimas, richardcochran, netdev,
	sven.auhagen, intel-wired-lan

[-- Attachment #1: Type: text/plain, Size: 341 bytes --]

>> +		/* pull rx packet timestamp if available */
>> +		if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP))
>> {
>> +			timestamp = igb_ptp_rx_pktstamp(rx_ring-
>> >q_vector,
>> +							pktbuf);
>
> The timestamp should be checked for failure and not adjust these values
> if the timestamp was invalid.

OK. I'll adjust it.

Thanks,
Kurt

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net v2] igb: Fix XDP with PTP enabled
  2021-04-19  7:23 Kurt Kanzenbach
@ 2021-04-20 16:33 ` Nguyen, Anthony L
  2021-04-21  6:35   ` Kurt Kanzenbach
  0 siblings, 1 reply; 7+ messages in thread
From: Nguyen, Anthony L @ 2021-04-20 16:33 UTC (permalink / raw)
  To: davem, kuba, Brandeburg, Jesse, kurt
  Cc: bigeasy, daniel, bpf, ast, hawk, lorenzo, john.fastabend,
	alexander.duyck, ilias.apalodimas, richardcochran, netdev,
	sven.auhagen, intel-wired-lan

On Mon, 2021-04-19 at 09:23 +0200, Kurt Kanzenbach wrote:
> When using native XDP with the igb driver, the XDP frame data doesn't
> point to
> the beginning of the packet. It's off by 16 bytes. Everything works
> as expected
> with XDP skb mode.
> 
> Actually these 16 bytes are used to store the packet timestamps.
> Therefore, pull
> the timestamp before executing any XDP operations and adjust all
> other code
> accordingly. The igc driver does it like that as well.
> 
> Tested with Intel i210 card and AF_XDP sockets.
> 
> Fixes: 9cbc948b5a20 ("igb: add XDP support")
> Signed-off-by: Kurt Kanzenbach <kurt@linutronix.de>
> ---

<snip>

> @@ -8683,7 +8676,10 @@ static int igb_clean_rx_irq(struct
> igb_q_vector *q_vector, const int budget)
>  	while (likely(total_packets < budget)) {
>  		union e1000_adv_rx_desc *rx_desc;
>  		struct igb_rx_buffer *rx_buffer;
> +		ktime_t timestamp = 0;
> +		int pkt_offset = 0;
>  		unsigned int size;
> +		void *pktbuf;
>  
>  		/* return some buffers to hardware, one at a time is
> too slow */
>  		if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
> @@ -8703,14 +8699,21 @@ static int igb_clean_rx_irq(struct
> igb_q_vector *q_vector, const int budget)
>  		dma_rmb();
>  
>  		rx_buffer = igb_get_rx_buffer(rx_ring, size,
> &rx_buf_pgcnt);
> +		pktbuf = page_address(rx_buffer->page) + rx_buffer-
> >page_offset;
> +
> +		/* pull rx packet timestamp if available */
> +		if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP))
> {
> +			timestamp = igb_ptp_rx_pktstamp(rx_ring-
> >q_vector,
> +							pktbuf);

The timestamp should be checked for failure and not adjust these values
if the timestamp was invalid.
 
> +			pkt_offset += IGB_TS_HDR_LEN;
> +			size -= IGB_TS_HDR_LEN;
> +		}


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net v2] igb: Fix XDP with PTP enabled
@ 2021-04-19  7:23 Kurt Kanzenbach
  2021-04-20 16:33 ` Nguyen, Anthony L
  0 siblings, 1 reply; 7+ messages in thread
From: Kurt Kanzenbach @ 2021-04-19  7:23 UTC (permalink / raw)
  To: Jesse Brandeburg, Tony Nguyen, David S. Miller, Jakub Kicinski
  Cc: Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, Sven Auhagen, intel-wired-lan, netdev, bpf,
	Ilias Apalodimas, Lorenzo Bianconi, Sebastian Andrzej Siewior,
	Richard Cochran, Alexander Duyck, Kurt Kanzenbach

When using native XDP with the igb driver, the XDP frame data doesn't point to
the beginning of the packet. It's off by 16 bytes. Everything works as expected
with XDP skb mode.

Actually these 16 bytes are used to store the packet timestamps. Therefore, pull
the timestamp before executing any XDP operations and adjust all other code
accordingly. The igc driver does it like that as well.

Tested with Intel i210 card and AF_XDP sockets.

Fixes: 9cbc948b5a20 ("igb: add XDP support")
Signed-off-by: Kurt Kanzenbach <kurt@linutronix.de>
---

Changes since v1:

 * Use xdp_prepare_buff() (Lorenzo Bianconi)

Changes since RFC:

 * Removed unused return value definitions (Alexander Duyck)

Previous versions:

 * https://lkml.kernel.org/netdev/20210415092145.27322-1-kurt@linutronix.de/
 * https://lkml.kernel.org/netdev/20210412101713.15161-1-kurt@linutronix.de/

 drivers/net/ethernet/intel/igb/igb.h      |  3 +-
 drivers/net/ethernet/intel/igb/igb_main.c | 42 +++++++++++++----------
 drivers/net/ethernet/intel/igb/igb_ptp.c  | 21 ++++--------
 3 files changed, 31 insertions(+), 35 deletions(-)

diff --git a/drivers/net/ethernet/intel/igb/igb.h b/drivers/net/ethernet/intel/igb/igb.h
index 7bda8c5edea5..72cf967c1a00 100644
--- a/drivers/net/ethernet/intel/igb/igb.h
+++ b/drivers/net/ethernet/intel/igb/igb.h
@@ -748,8 +748,7 @@ void igb_ptp_suspend(struct igb_adapter *adapter);
 void igb_ptp_rx_hang(struct igb_adapter *adapter);
 void igb_ptp_tx_hang(struct igb_adapter *adapter);
 void igb_ptp_rx_rgtstamp(struct igb_q_vector *q_vector, struct sk_buff *skb);
-int igb_ptp_rx_pktstamp(struct igb_q_vector *q_vector, void *va,
-			struct sk_buff *skb);
+ktime_t igb_ptp_rx_pktstamp(struct igb_q_vector *q_vector, void *va);
 int igb_ptp_set_ts_config(struct net_device *netdev, struct ifreq *ifr);
 int igb_ptp_get_ts_config(struct net_device *netdev, struct ifreq *ifr);
 void igb_set_flag_queue_pairs(struct igb_adapter *, const u32);
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index a45cd2b416c8..49873a5eaeaa 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -8281,7 +8281,7 @@ static void igb_add_rx_frag(struct igb_ring *rx_ring,
 static struct sk_buff *igb_construct_skb(struct igb_ring *rx_ring,
 					 struct igb_rx_buffer *rx_buffer,
 					 struct xdp_buff *xdp,
-					 union e1000_adv_rx_desc *rx_desc)
+					 ktime_t timestamp)
 {
 #if (PAGE_SIZE < 8192)
 	unsigned int truesize = igb_rx_pg_size(rx_ring) / 2;
@@ -8301,12 +8301,8 @@ static struct sk_buff *igb_construct_skb(struct igb_ring *rx_ring,
 	if (unlikely(!skb))
 		return NULL;
 
-	if (unlikely(igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP))) {
-		if (!igb_ptp_rx_pktstamp(rx_ring->q_vector, xdp->data, skb)) {
-			xdp->data += IGB_TS_HDR_LEN;
-			size -= IGB_TS_HDR_LEN;
-		}
-	}
+	if (timestamp)
+		skb_hwtstamps(skb)->hwtstamp = timestamp;
 
 	/* Determine available headroom for copy */
 	headlen = size;
@@ -8337,7 +8333,7 @@ static struct sk_buff *igb_construct_skb(struct igb_ring *rx_ring,
 static struct sk_buff *igb_build_skb(struct igb_ring *rx_ring,
 				     struct igb_rx_buffer *rx_buffer,
 				     struct xdp_buff *xdp,
-				     union e1000_adv_rx_desc *rx_desc)
+				     ktime_t timestamp)
 {
 #if (PAGE_SIZE < 8192)
 	unsigned int truesize = igb_rx_pg_size(rx_ring) / 2;
@@ -8364,11 +8360,8 @@ static struct sk_buff *igb_build_skb(struct igb_ring *rx_ring,
 	if (metasize)
 		skb_metadata_set(skb, metasize);
 
-	/* pull timestamp out of packet data */
-	if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
-		if (!igb_ptp_rx_pktstamp(rx_ring->q_vector, skb->data, skb))
-			__skb_pull(skb, IGB_TS_HDR_LEN);
-	}
+	if (timestamp)
+		skb_hwtstamps(skb)->hwtstamp = timestamp;
 
 	/* update buffer offset */
 #if (PAGE_SIZE < 8192)
@@ -8683,7 +8676,10 @@ static int igb_clean_rx_irq(struct igb_q_vector *q_vector, const int budget)
 	while (likely(total_packets < budget)) {
 		union e1000_adv_rx_desc *rx_desc;
 		struct igb_rx_buffer *rx_buffer;
+		ktime_t timestamp = 0;
+		int pkt_offset = 0;
 		unsigned int size;
+		void *pktbuf;
 
 		/* return some buffers to hardware, one at a time is too slow */
 		if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
@@ -8703,14 +8699,21 @@ static int igb_clean_rx_irq(struct igb_q_vector *q_vector, const int budget)
 		dma_rmb();
 
 		rx_buffer = igb_get_rx_buffer(rx_ring, size, &rx_buf_pgcnt);
+		pktbuf = page_address(rx_buffer->page) + rx_buffer->page_offset;
+
+		/* pull rx packet timestamp if available */
+		if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
+			timestamp = igb_ptp_rx_pktstamp(rx_ring->q_vector,
+							pktbuf);
+			pkt_offset += IGB_TS_HDR_LEN;
+			size -= IGB_TS_HDR_LEN;
+		}
 
 		/* retrieve a buffer from the ring */
 		if (!skb) {
-			unsigned int offset = igb_rx_offset(rx_ring);
-			unsigned char *hard_start;
+			unsigned char *hard_start = pktbuf - igb_rx_offset(rx_ring);
+			unsigned int offset = pkt_offset + igb_rx_offset(rx_ring);
 
-			hard_start = page_address(rx_buffer->page) +
-				     rx_buffer->page_offset - offset;
 			xdp_prepare_buff(&xdp, hard_start, offset, size, true);
 #if (PAGE_SIZE > 4096)
 			/* At larger PAGE_SIZE, frame_sz depend on len size */
@@ -8733,10 +8736,11 @@ static int igb_clean_rx_irq(struct igb_q_vector *q_vector, const int budget)
 		} else if (skb)
 			igb_add_rx_frag(rx_ring, rx_buffer, skb, size);
 		else if (ring_uses_build_skb(rx_ring))
-			skb = igb_build_skb(rx_ring, rx_buffer, &xdp, rx_desc);
+			skb = igb_build_skb(rx_ring, rx_buffer, &xdp,
+					    timestamp);
 		else
 			skb = igb_construct_skb(rx_ring, rx_buffer,
-						&xdp, rx_desc);
+						&xdp, timestamp);
 
 		/* exit if we failed to retrieve a buffer */
 		if (!skb) {
diff --git a/drivers/net/ethernet/intel/igb/igb_ptp.c b/drivers/net/ethernet/intel/igb/igb_ptp.c
index 86a576201f5f..8e23df7da641 100644
--- a/drivers/net/ethernet/intel/igb/igb_ptp.c
+++ b/drivers/net/ethernet/intel/igb/igb_ptp.c
@@ -856,30 +856,26 @@ static void igb_ptp_tx_hwtstamp(struct igb_adapter *adapter)
 	dev_kfree_skb_any(skb);
 }
 
-#define IGB_RET_PTP_DISABLED 1
-#define IGB_RET_PTP_INVALID 2
-
 /**
  * igb_ptp_rx_pktstamp - retrieve Rx per packet timestamp
  * @q_vector: Pointer to interrupt specific structure
  * @va: Pointer to address containing Rx buffer
- * @skb: Buffer containing timestamp and packet
  *
  * This function is meant to retrieve a timestamp from the first buffer of an
  * incoming frame.  The value is stored in little endian format starting on
  * byte 8
  *
- * Returns: 0 if success, nonzero if failure
+ * Returns: 0 on failure, timestamp on success
  **/
-int igb_ptp_rx_pktstamp(struct igb_q_vector *q_vector, void *va,
-			struct sk_buff *skb)
+ktime_t igb_ptp_rx_pktstamp(struct igb_q_vector *q_vector, void *va)
 {
 	struct igb_adapter *adapter = q_vector->adapter;
+	struct skb_shared_hwtstamps ts;
 	__le64 *regval = (__le64 *)va;
 	int adjust = 0;
 
 	if (!(adapter->ptp_flags & IGB_PTP_ENABLED))
-		return IGB_RET_PTP_DISABLED;
+		return 0;
 
 	/* The timestamp is recorded in little endian format.
 	 * DWORD: 0        1        2        3
@@ -888,10 +884,9 @@ int igb_ptp_rx_pktstamp(struct igb_q_vector *q_vector, void *va,
 
 	/* check reserved dwords are zero, be/le doesn't matter for zero */
 	if (regval[0])
-		return IGB_RET_PTP_INVALID;
+		return 0;
 
-	igb_ptp_systim_to_hwtstamp(adapter, skb_hwtstamps(skb),
-				   le64_to_cpu(regval[1]));
+	igb_ptp_systim_to_hwtstamp(adapter, &ts, le64_to_cpu(regval[1]));
 
 	/* adjust timestamp for the RX latency based on link speed */
 	if (adapter->hw.mac.type == e1000_i210) {
@@ -907,10 +902,8 @@ int igb_ptp_rx_pktstamp(struct igb_q_vector *q_vector, void *va,
 			break;
 		}
 	}
-	skb_hwtstamps(skb)->hwtstamp =
-		ktime_sub_ns(skb_hwtstamps(skb)->hwtstamp, adjust);
 
-	return 0;
+	return ktime_sub_ns(ts.hwtstamp, adjust);
 }
 
 /**
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-05-03  7:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-25 23:09 [PATCH net v2] igb: Fix XDP with PTP enabled Tyler S
2021-04-26 14:15 ` Kurt Kanzenbach
2021-04-27 23:11   ` Tyler S
2021-05-03  7:31     ` Kurt Kanzenbach
  -- strict thread matches above, loose matches on Subject: below --
2021-04-19  7:23 Kurt Kanzenbach
2021-04-20 16:33 ` Nguyen, Anthony L
2021-04-21  6:35   ` Kurt Kanzenbach

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).