Skip to contentSkip to conversation

igb: Fix XDP with PTP enabled

PATCH In review Kurt Kanzenbach 4 participants 6 messages May 3, 2021 – Jun 3, 2021

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

PATCH v4 1/1 igb: Fix XDP with PTP enabled

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

---

Changes since v3:

* Get rid of timestamp check in hot path (Maciej Fijalkowski)

Changes since v2:

* Check timestamp for validity (Nguyen, Anthony L)

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/20210422052617.17267-1-kurt at linutronix.de/
* https://lkml.kernel.org/netdev/20210419072332.7246-1-kurt at linutronix.de/
* https://lkml.kernel.org/netdev/20210415092145.27322-1-kurt at linutronix.de/
* https://lkml.kernel.org/netdev/20210412101713.15161-1-kurt at linutronix.de/

 drivers/net/ethernet/intel/igb/igb.h      |  2 +-
 drivers/net/ethernet/intel/igb/igb_main.c | 45 +++++++++++++----------
 drivers/net/ethernet/intel/igb/igb_ptp.c  | 23 +++++-------
 3 files changed, 37 insertions(+), 33 deletions(-)
drivers/net/ethernet/intel/igb/igb.h +1 -1
index 7bda8c5edea5..2d3daf022651 100644
@@ -749,7 +749,7 @@ 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 *timestamp);
 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);
drivers/net/ethernet/intel/igb/igb_main.c +26 -19

94 lines not on this page · raw message

drivers/net/ethernet/intel/igb/igb_ptp.c +10 -13
index ba61fe9bfaf4..d68cd4466a54 100644
@@ -856,30 +856,28 @@ 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
+ * @timestamp: Pointer where timestamp will be stored
  *
  * 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: The timestamp header length or 0 if not available
  **/
 int igb_ptp_rx_pktstamp(struct igb_q_vector *q_vector, void *va,
-			struct sk_buff *skb)
+			ktime_t *timestamp)
 {
 	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 +886,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 +904,10 @@ 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;
+	*timestamp = ktime_sub_ns(ts.hwtstamp, adjust);
+
+	return IGB_TS_HDR_LEN;
 }
 
 /**
Signature · 1 line
2.30.2
Acked-by on v4 1/1
#1 lore raw
Quoted 4 lines · On Mon, 3 May 2021 09:28:00 +0200 Kurt Kanzenbach <[email protected]> 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.

Quoted 8 lines

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

Thanks for fixing this!

I expect that we/I will (soon) play with getting this area that is stored in front of the packet (the XDP data_meta area) described via BTF. This way both xdp_frame and AF_XDP can get structured access (e.g. to the PTP timestamp in this case).

I'll be adding my notes on this project here:
https://github.com/xdp-project/xdp-project/blob/master/areas/tsn/

Looking forward to collaborate on this with you :-)

Signature · 4 lines
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer
#2 lore raw

Hi Maintainers,

What is the status on this patch?

I don't see this fix being applied on git-trees net or net-next.

[0] 20210503072800.79936-1-kurt at linutronix.de
[1] https://patchwork.kernel.org/project/netdevbpf/patch/20210503072800.79936-1-kurt at linutronix.de/
[2] https://lore.kernel.org/netdev/20210503072800.79936-1-kurt at linutronix.de/

Quoted 29 lines · On Tue, 4 May 2021 10:28:27 +0200 Jesper Dangaard Brouer <[email protected]>…
Quoted 4 lines · On Mon, 3 May 2021 09:28:00 +0200 Kurt Kanzenbach <[email protected]> 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.

Quoted 8 lines

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

Thanks for fixing this!

I expect that we/I will (soon) play with getting this area that is stored in front of the packet (the XDP data_meta area) described via BTF. This way both xdp_frame and AF_XDP can get structured access (e.g. to the PTP timestamp in this case).

I'll be adding my notes on this project here:
https://github.com/xdp-project/xdp-project/blob/master/areas/tsn/

Looking forward to collaborate on this with you :-)

Signature · 4 lines
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer
#3 lore raw
Quoted 3 lines · Jesper Dangaard Brouer

Hi Maintainers,

What is the status on this patch?

I'm awaiting testing from our validation. They expect to finish by the end of the week; I'll send out the patch as soon as they've completed.

Thanks,
Tony

Quoted 8 lines

I don't see this fix being applied on git-trees net or net-next.

[0] 20210503072800.79936-1-kurt at linutronix.de
[1]
https://patchwork.kernel.org/project/netdevbpf/patch/20210503072800.79936-1-kurt at linutronix.de/
[2]
https://lore.kernel.org/netdev/20210503072800.79936-1-kurt at linutronix.de/

#4 lore raw
Quoted 8 lines · Anthony L
Quoted 3 lines · Jesper Dangaard Brouer

Hi Maintainers,

What is the status on this patch?

I'm awaiting testing from our validation. They expect to finish by the end of the week; I'll send out the patch as soon as they've completed.

Thanks! I've got also a backport of this patch for v5.10.x, so that people can use the latest LTS e.g., with PREEMPT_RT and working PTP and XDP. Let me know if there's interest in it.

Thanks,
Kurt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 861 bytes
Desc: not available
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20210520/875206a0/attachment.asc>

Tested-by on v4 1/1
#5 lore raw
In reply to Kurt Kanzenbach
Quoted 60 lines

-----Original Message-----
From: Kurt Kanzenbach <[email protected]>
Sent: Monday, May 3, 2021 12:58 PM
To: Brandeburg, Jesse <[email protected]>; Nguyen, Anthony L <[email protected]>; David S. Miller <[email protected]>; Jakub Kicinski <[email protected]>
Cc: Alexei Starovoitov <[email protected]>; Daniel Borkmann <[email protected]>; Jesper Dangaard Brouer <[email protected]>; John Fastabend <[email protected]>; Sven Auhagen <[email protected]>; intel-wired-lan at lists.osuosl.org; netdev at vger.kernel.org; bpf at vger.kernel.org; Ilias Apalodimas <[email protected]>; Lorenzo Bianconi <[email protected]>; Sebastian Andrzej Siewior <[email protected]>; Richard Cochran <[email protected]>; Alexander Duyck <[email protected]>; Tyler S <[email protected]>; Fijalkowski, Maciej <[email protected]>; Kurt Kanzenbach <[email protected]>
Subject: [PATCH net v4] igb: Fix XDP with PTP enabled

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

---

Changes since v3:

* Get rid of timestamp check in hot path (Maciej Fijalkowski)

Changes since v2:

* Check timestamp for validity (Nguyen, Anthony L)

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/20210422052617.17267-1-
kurt at linutronix.de/
* https://lkml.kernel.org/netdev/20210419072332.7246-1-
kurt at linutronix.de/
* https://lkml.kernel.org/netdev/20210415092145.27322-1-
kurt at linutronix.de/
* https://lkml.kernel.org/netdev/20210412101713.15161-1-
kurt at linutronix.de/

Quoted 5 lines
drivers/net/ethernet/intel/igb/igb.h      |  2 +-
drivers/net/ethernet/intel/igb/igb_main.c | 45 +++++++++++++----------
drivers/net/ethernet/intel/igb/igb_ptp.c  | 23 +++++-------
3 files changed, 37 insertions(+), 33 deletions(-)