Skip to content

Commit bfdd741

Browse files
tdh911kuba-moo
authored andcommitted
gve: Check valid ts bit on RX descriptor before hw timestamping
The device returns a valid bit in the LSB of the low timestamp byte in the completion descriptor that the driver should check before setting the SKB's hardware timestamp. If the timestamp is not valid, do not hardware timestamp the SKB. Cc: stable@vger.kernel.org Fixes: b2c7aeb ("gve: Implement ndo_hwtstamp_get/set for RX timestamping") Reviewed-by: Joshua Washington <joshwash@google.com> Signed-off-by: Tim Hostetler <thostet@google.com> Signed-off-by: Harshitha Ramamurthy <hramamurthy@google.com> Reviewed-by: Simon Horman <horms@kernel.org> Reviewed-by: Willem de Bruijn <willemb@google.com> Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev> Link: https://patch.msgid.link/20251014004740.2775957-1-hramamurthy@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 7f0fddd commit bfdd741

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

drivers/net/ethernet/google/gve/gve.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@
100100
*/
101101
#define GVE_DQO_QPL_ONDEMAND_ALLOC_THRESHOLD 96
102102

103+
#define GVE_DQO_RX_HWTSTAMP_VALID 0x1
104+
103105
/* Each slot in the desc ring has a 1:1 mapping to a slot in the data ring */
104106
struct gve_rx_desc_queue {
105107
struct gve_rx_desc *desc_ring; /* the descriptor ring */

drivers/net/ethernet/google/gve/gve_desc_dqo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ struct gve_rx_compl_desc_dqo {
236236

237237
u8 status_error1;
238238

239-
__le16 reserved5;
239+
u8 reserved5;
240+
u8 ts_sub_nsecs_low;
240241
__le16 buf_id; /* Buffer ID which was sent on the buffer queue. */
241242

242243
union {

drivers/net/ethernet/google/gve/gve_rx_dqo.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,14 +456,20 @@ static void gve_rx_skb_hash(struct sk_buff *skb,
456456
* Note that this means if the time delta between packet reception and the last
457457
* clock read is greater than ~2 seconds, this will provide invalid results.
458458
*/
459-
static void gve_rx_skb_hwtstamp(struct gve_rx_ring *rx, u32 hwts)
459+
static void gve_rx_skb_hwtstamp(struct gve_rx_ring *rx,
460+
const struct gve_rx_compl_desc_dqo *desc)
460461
{
461462
u64 last_read = READ_ONCE(rx->gve->last_sync_nic_counter);
462463
struct sk_buff *skb = rx->ctx.skb_head;
463-
u32 low = (u32)last_read;
464-
s32 diff = hwts - low;
465-
466-
skb_hwtstamps(skb)->hwtstamp = ns_to_ktime(last_read + diff);
464+
u32 ts, low;
465+
s32 diff;
466+
467+
if (desc->ts_sub_nsecs_low & GVE_DQO_RX_HWTSTAMP_VALID) {
468+
ts = le32_to_cpu(desc->ts);
469+
low = (u32)last_read;
470+
diff = ts - low;
471+
skb_hwtstamps(skb)->hwtstamp = ns_to_ktime(last_read + diff);
472+
}
467473
}
468474

469475
static void gve_rx_free_skb(struct napi_struct *napi, struct gve_rx_ring *rx)
@@ -944,7 +950,7 @@ static int gve_rx_complete_skb(struct gve_rx_ring *rx, struct napi_struct *napi,
944950
gve_rx_skb_csum(rx->ctx.skb_head, desc, ptype);
945951

946952
if (rx->gve->ts_config.rx_filter == HWTSTAMP_FILTER_ALL)
947-
gve_rx_skb_hwtstamp(rx, le32_to_cpu(desc->ts));
953+
gve_rx_skb_hwtstamp(rx, desc);
948954

949955
/* RSC packets must set gso_size otherwise the TCP stack will complain
950956
* that packets are larger than MTU.

0 commit comments

Comments
 (0)