]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
gve: Prepare bpf_xdp_metadata_rx_timestamp support
authorTim Hostetler <thostet@google.com>
Fri, 14 Nov 2025 21:11:45 +0000 (13:11 -0800)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 18 Nov 2025 14:52:43 +0000 (15:52 +0100)
Support populating XDP RX metadata with hardware RX timestamps. This
patch utilizes the same underlying logic to calculate hardware
timestamps as the regular RX path.

xdp_metadata_ops is registered with the net_device in a future patch.

gve_rx_calculate_hwtstamp was pulled out so as to not duplicate logic
between gve_xdp_rx_timestamp and gve_rx_hwtstamp.

Signed-off-by: Tim Hostetler <thostet@google.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Reviewed-by: Harshitha Ramamurthy <hramamurthy@google.com>
Signed-off-by: Joshua Washington <joshwash@google.com>
Link: https://patch.msgid.link/20251114211146.292068-4-joshwash@google.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/google/gve/gve.h
drivers/net/ethernet/google/gve/gve_dqo.h
drivers/net/ethernet/google/gve/gve_rx_dqo.c

index a21e599cf710783551713300d6c83c2e4b8d2430..970d5ca8cddeec4907e525d26aee0b40582f8e80 100644 (file)
@@ -208,6 +208,8 @@ struct gve_rx_buf_state_dqo {
 /* Wrapper for XDP Rx metadata */
 struct gve_xdp_buff {
        struct xdp_buff xdp;
+       struct gve_priv *gve;
+       const struct gve_rx_compl_desc_dqo *compl_desc;
 };
 
 /* `head` and `tail` are indices into an array, or -1 if empty. */
index 6eb442096e02e1b70893750dbadc7a401437ea8c..5871f773f0c7066fc5e451766f5b90a6841ee951 100644 (file)
@@ -36,6 +36,7 @@ netdev_tx_t gve_tx_dqo(struct sk_buff *skb, struct net_device *dev);
 netdev_features_t gve_features_check_dqo(struct sk_buff *skb,
                                         struct net_device *dev,
                                         netdev_features_t features);
+int gve_xdp_rx_timestamp(const struct xdp_md *_ctx, u64 *timestamp);
 bool gve_tx_poll_dqo(struct gve_notify_block *block, bool do_clean);
 bool gve_xdp_poll_dqo(struct gve_notify_block *block);
 bool gve_xsk_tx_poll_dqo(struct gve_notify_block *block, int budget);
index 76b26896f5723fcbaba4965fbb04f0e15880f052..f20d1b1d06e681549a7008143801fb075c487832 100644 (file)
@@ -456,20 +456,38 @@ static void gve_rx_skb_hash(struct sk_buff *skb,
  * Note that this means if the time delta between packet reception and the last
  * clock read is greater than ~2 seconds, this will provide invalid results.
  */
+static ktime_t gve_rx_get_hwtstamp(struct gve_priv *gve, u32 hwts)
+{
+       u64 last_read = READ_ONCE(gve->last_sync_nic_counter);
+       u32 low = (u32)last_read;
+       s32 diff = hwts - low;
+
+       return ns_to_ktime(last_read + diff);
+}
+
 static void gve_rx_skb_hwtstamp(struct gve_rx_ring *rx,
                                const struct gve_rx_compl_desc_dqo *desc)
 {
-       u64 last_read = READ_ONCE(rx->gve->last_sync_nic_counter);
        struct sk_buff *skb = rx->ctx.skb_head;
-       u32 ts, low;
-       s32 diff;
-
-       if (desc->ts_sub_nsecs_low & GVE_DQO_RX_HWTSTAMP_VALID) {
-               ts = le32_to_cpu(desc->ts);
-               low = (u32)last_read;
-               diff = ts - low;
-               skb_hwtstamps(skb)->hwtstamp = ns_to_ktime(last_read + diff);
-       }
+
+       if (desc->ts_sub_nsecs_low & GVE_DQO_RX_HWTSTAMP_VALID)
+               skb_hwtstamps(skb)->hwtstamp =
+                       gve_rx_get_hwtstamp(rx->gve, le32_to_cpu(desc->ts));
+}
+
+int gve_xdp_rx_timestamp(const struct xdp_md *_ctx, u64 *timestamp)
+{
+       const struct gve_xdp_buff *ctx = (void *)_ctx;
+
+       if (!ctx->gve->nic_ts_report)
+               return -ENODATA;
+
+       if (!(ctx->compl_desc->ts_sub_nsecs_low & GVE_DQO_RX_HWTSTAMP_VALID))
+               return -ENODATA;
+
+       *timestamp = gve_rx_get_hwtstamp(ctx->gve,
+                                        le32_to_cpu(ctx->compl_desc->ts));
+       return 0;
 }
 
 static void gve_rx_free_skb(struct napi_struct *napi, struct gve_rx_ring *rx)
@@ -851,6 +869,9 @@ static int gve_rx_dqo(struct napi_struct *napi, struct gve_rx_ring *rx,
                                 buf_state->page_info.page_offset,
                                 buf_state->page_info.pad,
                                 buf_len, false);
+               gve_xdp.gve = priv;
+               gve_xdp.compl_desc = compl_desc;
+
                old_data = gve_xdp.xdp.data;
                xdp_act = bpf_prog_run_xdp(xprog, &gve_xdp.xdp);
                buf_state->page_info.pad += gve_xdp.xdp.data - old_data;