* [PATCH RFC v2 0/2] virtio-net: add flow filter for receive timestamps
@ 2026-01-29 8:06 Steffen Trumtrar
2026-01-29 8:06 ` [PATCH RFC v2 1/2] tun: support rx-tstamp Steffen Trumtrar
` (3 more replies)
0 siblings, 4 replies; 17+ messages in thread
From: Steffen Trumtrar @ 2026-01-29 8:06 UTC (permalink / raw)
To: Michael S. Tsirkin, Jason Wang, Xuan Zhuo, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Willem de Bruijn, Andrew Lunn, Eugenio Pérez
Cc: virtualization, netdev, linux-kernel, Steffen Trumtrar
This series tries to pick up the work on the virtio-net timestamping
feature from Willem de Bruijn.
Original series
Message-Id: 20210208185558.995292-1-willemdebruijn.kernel@gmail.com
Subject: [PATCH RFC v2 0/4] virtio-net: add tx-hash, rx-tstamp,
tx-tstamp and tx-time
From: Willem de Bruijn <willemb@google.com>
RFC for four new features to the virtio network device:
1. pass tx flow state to host, for routing + telemetry
2. pass rx tstamp to guest, for better RTT estimation
3. pass tx tstamp to guest, idem
3. pass tx delivery time to host, for accurate pacing
All would introduce an extension to the virtio spec.
The changes in this series are to the driver side. For the changes to qemu see:
https://github.com/strumtrar/qemu/tree/v10.2.0/virtio-rx-stamps
Currently only virtio-net is supported. Performance was tested with
pktgen which doesn't show a decrease in transfer speeds.
As these patches are now mostly different from the initial patchset, I removed
the Signed-off-bys from Willem, so he mustn't be ashamed of what his work evolved to ;)
Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
Changes in v2:
- rework patches to use flow filter instead of feature flag
- Link to v1: https://lore.kernel.org/r/20231218-v6-7-topic-virtio-net-ptp-v1-0-cac92b2d8532@pengutronix.de
---
Steffen Trumtrar (2):
tun: support rx-tstamp
virtio-net: support receive timestamp
drivers/net/tun.c | 30 +++++----
drivers/net/virtio_net.c | 136 ++++++++++++++++++++++++++++++++++++----
include/uapi/linux/virtio_net.h | 9 +++
3 files changed, 151 insertions(+), 24 deletions(-)
---
base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
change-id: 20231218-v6-7-topic-virtio-net-ptp-3df023bc4f4d
Best regards,
--
Steffen Trumtrar <s.trumtrar@pengutronix.de>
^ permalink raw reply [flat|nested] 17+ messages in thread* [PATCH RFC v2 1/2] tun: support rx-tstamp 2026-01-29 8:06 [PATCH RFC v2 0/2] virtio-net: add flow filter for receive timestamps Steffen Trumtrar @ 2026-01-29 8:06 ` Steffen Trumtrar 2026-02-01 21:00 ` Willem de Bruijn 2026-01-29 8:06 ` [PATCH RFC v2 2/2] virtio-net: support receive timestamp Steffen Trumtrar ` (2 subsequent siblings) 3 siblings, 1 reply; 17+ messages in thread From: Steffen Trumtrar @ 2026-01-29 8:06 UTC (permalink / raw) To: Michael S. Tsirkin, Jason Wang, Xuan Zhuo, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran, Willem de Bruijn, Andrew Lunn, Eugenio Pérez Cc: virtualization, netdev, linux-kernel, Steffen Trumtrar Demonstrate support for new virtio-net features VIRTIO_NET_HDR_F_TSTAMP This is not intended to be merged. A full feature test also requires a patched qemu binary that knows these features and negotiates correct vnet_hdr_sz in virtio_net_set_mrg_rx_bufs. See https://github.com/strumtrar/qemu/tree/v10.2.0/virtio-rx-stamps Not-yet-signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> --- drivers/net/tun.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 8192740357a09..aa988a9c4bc99 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -2065,23 +2065,29 @@ static ssize_t tun_put_user(struct tun_struct *tun, } if (vnet_hdr_sz) { - struct virtio_net_hdr_v1_hash_tunnel hdr; - struct virtio_net_hdr *gso; + struct virtio_net_hdr_v1_hash_tunnel_ts hdr; + + memset(&hdr, 0, sizeof(hdr)); ret = tun_vnet_hdr_tnl_from_skb(tun->flags, tun->dev, skb, - &hdr); + (struct virtio_net_hdr_v1_hash_tunnel *)&hdr); if (ret) return ret; - /* - * Drop the packet if the configured header size is too small - * WRT the enabled offloads. - */ - gso = (struct virtio_net_hdr *)&hdr; - ret = __tun_vnet_hdr_put(vnet_hdr_sz, tun->dev->features, - iter, gso); - if (ret) - return ret; + if (vnet_hdr_sz >= sizeof(struct virtio_net_hdr_v1_hash_tunnel_ts)) { + __le64 tstamp = cpu_to_le64(ktime_get_ns()); + + hdr.tstamp_0 = (tstamp & 0x000000000000ffffULL) >> 0; + hdr.tstamp_1 = (tstamp & 0x00000000ffff0000ULL) >> 16; + hdr.tstamp_2 = (tstamp & 0x0000ffff00000000ULL) >> 32; + hdr.tstamp_3 = (tstamp & 0xffff000000000000ULL) >> 48; + } + + if (unlikely(iov_iter_count(iter) < vnet_hdr_sz)) + return -EINVAL; + + if (unlikely(copy_to_iter(&hdr, vnet_hdr_sz, iter) != vnet_hdr_sz)) + return -EFAULT; } if (vlan_hlen) { -- 2.52.0 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v2 1/2] tun: support rx-tstamp 2026-01-29 8:06 ` [PATCH RFC v2 1/2] tun: support rx-tstamp Steffen Trumtrar @ 2026-02-01 21:00 ` Willem de Bruijn 0 siblings, 0 replies; 17+ messages in thread From: Willem de Bruijn @ 2026-02-01 21:00 UTC (permalink / raw) To: Steffen Trumtrar, Michael S. Tsirkin, Jason Wang, Xuan Zhuo, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran, Willem de Bruijn, Andrew Lunn, Eugenio Pérez Cc: virtualization, netdev, linux-kernel, Steffen Trumtrar Steffen Trumtrar wrote: > Demonstrate support for new virtio-net features > > VIRTIO_NET_HDR_F_TSTAMP > > This is not intended to be merged. > > A full feature test also requires a patched qemu binary that knows > these features and negotiates correct vnet_hdr_sz in > virtio_net_set_mrg_rx_bufs. See > https://github.com/strumtrar/qemu/tree/v10.2.0/virtio-rx-stamps > > Not-yet-signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> > --- > drivers/net/tun.c | 30 ++++++++++++++++++------------ > 1 file changed, 18 insertions(+), 12 deletions(-) > > diff --git a/drivers/net/tun.c b/drivers/net/tun.c > index 8192740357a09..aa988a9c4bc99 100644 > --- a/drivers/net/tun.c > +++ b/drivers/net/tun.c > @@ -2065,23 +2065,29 @@ static ssize_t tun_put_user(struct tun_struct *tun, > } > > if (vnet_hdr_sz) { > - struct virtio_net_hdr_v1_hash_tunnel hdr; > - struct virtio_net_hdr *gso; > + struct virtio_net_hdr_v1_hash_tunnel_ts hdr; This patch refers to a struct that does not exist yet, so this cannot compile? > + > + memset(&hdr, 0, sizeof(hdr)); > > ret = tun_vnet_hdr_tnl_from_skb(tun->flags, tun->dev, skb, > - &hdr); > + (struct virtio_net_hdr_v1_hash_tunnel *)&hdr); > if (ret) > return ret; > > - /* > - * Drop the packet if the configured header size is too small > - * WRT the enabled offloads. > - */ > - gso = (struct virtio_net_hdr *)&hdr; > - ret = __tun_vnet_hdr_put(vnet_hdr_sz, tun->dev->features, > - iter, gso); > - if (ret) > - return ret; > + if (vnet_hdr_sz >= sizeof(struct virtio_net_hdr_v1_hash_tunnel_ts)) { > + __le64 tstamp = cpu_to_le64(ktime_get_ns()); > + > + hdr.tstamp_0 = (tstamp & 0x000000000000ffffULL) >> 0; > + hdr.tstamp_1 = (tstamp & 0x00000000ffff0000ULL) >> 16; > + hdr.tstamp_2 = (tstamp & 0x0000ffff00000000ULL) >> 32; > + hdr.tstamp_3 = (tstamp & 0xffff000000000000ULL) >> 48; > + } > + > + if (unlikely(iov_iter_count(iter) < vnet_hdr_sz)) > + return -EINVAL; > + > + if (unlikely(copy_to_iter(&hdr, vnet_hdr_sz, iter) != vnet_hdr_sz)) > + return -EFAULT; > } > > if (vlan_hlen) { > > -- > 2.52.0 > ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH RFC v2 2/2] virtio-net: support receive timestamp 2026-01-29 8:06 [PATCH RFC v2 0/2] virtio-net: add flow filter for receive timestamps Steffen Trumtrar 2026-01-29 8:06 ` [PATCH RFC v2 1/2] tun: support rx-tstamp Steffen Trumtrar @ 2026-01-29 8:06 ` Steffen Trumtrar 2026-01-29 9:48 ` Xuan Zhuo 2026-02-01 21:05 ` Willem de Bruijn 2026-01-29 13:27 ` [syzbot ci] Re: virtio-net: add flow filter for receive timestamps syzbot ci 2026-02-01 21:00 ` [PATCH RFC v2 0/2] " Willem de Bruijn 3 siblings, 2 replies; 17+ messages in thread From: Steffen Trumtrar @ 2026-01-29 8:06 UTC (permalink / raw) To: Michael S. Tsirkin, Jason Wang, Xuan Zhuo, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran, Willem de Bruijn, Andrew Lunn, Eugenio Pérez Cc: virtualization, netdev, linux-kernel, Steffen Trumtrar Add optional hardware rx timestamp offload for virtio-net. Introduce virtio feature VIRTIO_NET_F_TSTAMP. If negotiated, the virtio-net header is expanded with room for a timestamp. To get and set the hwtstamp the functions ndo_hwtstamp_set/get need to be implemented. This allows filtering the packets and only time stamp the packets where the filter matches. This way, the timestamping can be en/disabled at runtime. Tested: guest: ./timestamping eth0 \ SOF_TIMESTAMPING_RAW_HARDWARE \ SOF_TIMESTAMPING_RX_HARDWARE host: nc -4 -u 192.168.1.1 319 Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> -- Changes to last version: - rework series to use flow filters - add new struct virtio_net_hdr_v1_hash_tunnel_ts - original work done by: Willem de Bruijn <willemb@google.com> --- drivers/net/virtio_net.c | 136 ++++++++++++++++++++++++++++++++++++---- include/uapi/linux/virtio_net.h | 9 +++ 2 files changed, 133 insertions(+), 12 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 1bb3aeca66c6e..4e8d9b20c1b34 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -429,6 +429,9 @@ struct virtnet_info { struct virtio_net_rss_config_trailer rss_trailer; u8 rss_hash_key_data[VIRTIO_NET_RSS_MAX_KEY_SIZE]; + /* Device passes time stamps from the driver */ + bool has_tstamp; + /* Has control virtqueue */ bool has_cvq; @@ -475,6 +478,8 @@ struct virtnet_info { struct control_buf *ctrl; + struct kernel_hwtstamp_config tstamp_config; + /* Ethtool settings */ u8 duplex; u32 speed; @@ -511,6 +516,7 @@ struct virtio_net_common_hdr { struct virtio_net_hdr_mrg_rxbuf mrg_hdr; struct virtio_net_hdr_v1_hash hash_v1_hdr; struct virtio_net_hdr_v1_hash_tunnel tnl_hdr; + struct virtio_net_hdr_v1_hash_tunnel_ts ts_hdr; }; }; @@ -682,6 +688,13 @@ skb_vnet_common_hdr(struct sk_buff *skb) return (struct virtio_net_common_hdr *)skb->cb; } +static inline struct virtio_net_hdr_v1_hash_tunnel_ts *skb_vnet_hdr_ts(struct sk_buff *skb) +{ + BUILD_BUG_ON(sizeof(struct virtio_net_hdr_v1_hash_tunnel_ts) > sizeof(skb->cb)); + + return (void *)skb->cb; +} + /* * private is used to chain pages for big packets, put the whole * most recent used list in the beginning for reuse @@ -2560,6 +2573,15 @@ virtio_net_hash_value(const struct virtio_net_hdr_v1_hash *hdr_hash) (__le16_to_cpu(hdr_hash->hash_value_hi) << 16); } +static inline u64 +virtio_net_tstamp_value(const struct virtio_net_hdr_v1_hash_tunnel_ts *hdr_hash_ts) +{ + return (u64)__le16_to_cpu(hdr_hash_ts->tstamp_0) | + ((u64)__le16_to_cpu(hdr_hash_ts->tstamp_1) << 16) | + ((u64)__le16_to_cpu(hdr_hash_ts->tstamp_2) << 32) | + ((u64)__le16_to_cpu(hdr_hash_ts->tstamp_3) << 48); +} + static void virtio_skb_set_hash(const struct virtio_net_hdr_v1_hash *hdr_hash, struct sk_buff *skb) { @@ -2589,6 +2611,18 @@ static void virtio_skb_set_hash(const struct virtio_net_hdr_v1_hash *hdr_hash, skb_set_hash(skb, virtio_net_hash_value(hdr_hash), rss_hash_type); } +static inline void virtnet_record_rx_tstamp(const struct virtnet_info *vi, + struct sk_buff *skb) +{ + struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb); + const struct virtio_net_hdr_v1_hash_tunnel_ts *h = skb_vnet_hdr_ts(skb); + u64 ts; + + ts = virtio_net_tstamp_value(h); + memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps)); + shhwtstamps->hwtstamp = ns_to_ktime(ts); +} + static void virtnet_receive_done(struct virtnet_info *vi, struct receive_queue *rq, struct sk_buff *skb, u8 flags) { @@ -2617,6 +2651,8 @@ static void virtnet_receive_done(struct virtnet_info *vi, struct receive_queue * goto frame_err; } + if (vi->has_tstamp && vi->tstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) + virtnet_record_rx_tstamp(vi, skb); skb_record_rx_queue(skb, vq2rxq(rq->vq)); skb->protocol = eth_type_trans(skb, dev); pr_debug("Receiving skb proto 0x%04x len %i type %i\n", @@ -3321,7 +3357,7 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb, bool orphan) { const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest; struct virtnet_info *vi = sq->vq->vdev->priv; - struct virtio_net_hdr_v1_hash_tunnel *hdr; + struct virtio_net_hdr_v1_hash_tunnel_ts *hdr; int num_sg; unsigned hdr_len = vi->hdr_len; bool can_push; @@ -3329,8 +3365,8 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb, bool orphan) pr_debug("%s: xmit %p %pM\n", vi->dev->name, skb, dest); /* Make sure it's safe to cast between formats */ - BUILD_BUG_ON(__alignof__(*hdr) != __alignof__(hdr->hash_hdr)); - BUILD_BUG_ON(__alignof__(*hdr) != __alignof__(hdr->hash_hdr.hdr)); + BUILD_BUG_ON(__alignof__(*hdr) != __alignof__(hdr->tnl.hash_hdr)); + BUILD_BUG_ON(__alignof__(*hdr) != __alignof__(hdr->tnl.hash_hdr.hdr)); can_push = vi->any_header_sg && !((unsigned long)skb->data & (__alignof__(*hdr) - 1)) && @@ -3338,18 +3374,18 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb, bool orphan) /* Even if we can, don't push here yet as this would skew * csum_start offset below. */ if (can_push) - hdr = (struct virtio_net_hdr_v1_hash_tunnel *)(skb->data - - hdr_len); + hdr = (struct virtio_net_hdr_v1_hash_tunnel_ts *)(skb->data - + hdr_len); else - hdr = &skb_vnet_common_hdr(skb)->tnl_hdr; + hdr = &skb_vnet_common_hdr(skb)->ts_hdr; - if (virtio_net_hdr_tnl_from_skb(skb, hdr, vi->tx_tnl, + if (virtio_net_hdr_tnl_from_skb(skb, &hdr->tnl, vi->tx_tnl, virtio_is_little_endian(vi->vdev), 0, false)) return -EPROTO; if (vi->mergeable_rx_bufs) - hdr->hash_hdr.hdr.num_buffers = 0; + hdr->tnl.hash_hdr.hdr.num_buffers = 0; sg_init_table(sq->sg, skb_shinfo(skb)->nr_frags + (can_push ? 1 : 2)); if (can_push) { @@ -5563,6 +5599,22 @@ static int virtnet_get_per_queue_coalesce(struct net_device *dev, return 0; } +static int virtnet_get_ts_info(struct net_device *dev, + struct kernel_ethtool_ts_info *info) +{ + /* setup default software timestamp */ + ethtool_op_get_ts_info(dev, info); + + info->rx_filters = (BIT(HWTSTAMP_FILTER_NONE) | + BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) | + BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) | + BIT(HWTSTAMP_FILTER_ALL)); + + info->tx_types = HWTSTAMP_TX_OFF; + + return 0; +} + static void virtnet_init_settings(struct net_device *dev) { struct virtnet_info *vi = netdev_priv(dev); @@ -5658,7 +5710,7 @@ static const struct ethtool_ops virtnet_ethtool_ops = { .get_ethtool_stats = virtnet_get_ethtool_stats, .set_channels = virtnet_set_channels, .get_channels = virtnet_get_channels, - .get_ts_info = ethtool_op_get_ts_info, + .get_ts_info = virtnet_get_ts_info, .get_link_ksettings = virtnet_get_link_ksettings, .set_link_ksettings = virtnet_set_link_ksettings, .set_coalesce = virtnet_set_coalesce, @@ -6242,6 +6294,58 @@ static void virtnet_tx_timeout(struct net_device *dev, unsigned int txqueue) jiffies_to_usecs(jiffies - READ_ONCE(txq->trans_start))); } +static int virtnet_hwtstamp_get(struct net_device *dev, + struct kernel_hwtstamp_config *tstamp_config) +{ + struct virtnet_info *vi = netdev_priv(dev); + + if (!netif_running(dev)) + return -EINVAL; + + *tstamp_config = vi->tstamp_config; + + return 0; +} + +static int virtnet_hwtstamp_set(struct net_device *dev, + struct kernel_hwtstamp_config *tstamp_config, + struct netlink_ext_ack *extack) +{ + struct virtnet_info *vi = netdev_priv(dev); + + if (!netif_running(dev)) + return -EINVAL; + + switch (tstamp_config->rx_filter) { + case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: + case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: + break; + case HWTSTAMP_FILTER_PTP_V2_EVENT: + case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: + case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: + case HWTSTAMP_FILTER_PTP_V2_SYNC: + case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: + case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: + case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: + case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: + case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: + tstamp_config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; + break; + case HWTSTAMP_FILTER_NONE: + break; + case HWTSTAMP_FILTER_ALL: + tstamp_config->rx_filter = HWTSTAMP_FILTER_ALL; + break; + default: + tstamp_config->rx_filter = HWTSTAMP_FILTER_ALL; + return -ERANGE; + } + + vi->tstamp_config = *tstamp_config; + + return 0; +} + static int virtnet_init_irq_moder(struct virtnet_info *vi) { u8 profile_flags = 0, coal_flags = 0; @@ -6289,6 +6393,8 @@ static const struct net_device_ops virtnet_netdev = { .ndo_get_phys_port_name = virtnet_get_phys_port_name, .ndo_set_features = virtnet_set_features, .ndo_tx_timeout = virtnet_tx_timeout, + .ndo_hwtstamp_set = virtnet_hwtstamp_set, + .ndo_hwtstamp_get = virtnet_hwtstamp_get, }; static void virtnet_config_changed_work(struct work_struct *work) @@ -6911,6 +7017,9 @@ static int virtnet_probe(struct virtio_device *vdev) if (virtio_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT)) vi->has_rss_hash_report = true; + if (virtio_has_feature(vdev, VIRTIO_NET_F_TSTAMP)) + vi->has_tstamp = true; + if (virtio_has_feature(vdev, VIRTIO_NET_F_RSS)) { vi->has_rss = true; @@ -6945,8 +7054,10 @@ static int virtnet_probe(struct virtio_device *vdev) dev->xdp_metadata_ops = &virtnet_xdp_metadata_ops; } - if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO) || - virtio_has_feature(vdev, VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO)) + if (vi->has_tstamp) + vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash_tunnel_ts); + else if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO) || + virtio_has_feature(vdev, VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO)) vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash_tunnel); else if (vi->has_rss_hash_report) vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash); @@ -7269,7 +7380,8 @@ static struct virtio_device_id id_table[] = { VIRTIO_NET_F_SPEED_DUPLEX, VIRTIO_NET_F_STANDBY, \ VIRTIO_NET_F_RSS, VIRTIO_NET_F_HASH_REPORT, VIRTIO_NET_F_NOTF_COAL, \ VIRTIO_NET_F_VQ_NOTF_COAL, \ - VIRTIO_NET_F_GUEST_HDRLEN, VIRTIO_NET_F_DEVICE_STATS + VIRTIO_NET_F_GUEST_HDRLEN, VIRTIO_NET_F_DEVICE_STATS, \ + VIRTIO_NET_F_TSTAMP static unsigned int features[] = { VIRTNET_FEATURES, diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h index 1db45b01532b5..9f967575956b8 100644 --- a/include/uapi/linux/virtio_net.h +++ b/include/uapi/linux/virtio_net.h @@ -56,6 +56,7 @@ #define VIRTIO_NET_F_MQ 22 /* Device supports Receive Flow * Steering */ #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ +#define VIRTIO_NET_F_TSTAMP 49 /* Device sends TAI receive time */ #define VIRTIO_NET_F_DEVICE_STATS 50 /* Device can provide device-level statistics. */ #define VIRTIO_NET_F_VQ_NOTF_COAL 52 /* Device supports virtqueue notification coalescing */ #define VIRTIO_NET_F_NOTF_COAL 53 /* Device supports notifications coalescing */ @@ -215,6 +216,14 @@ struct virtio_net_hdr_v1_hash_tunnel { __le16 inner_nh_offset; }; +struct virtio_net_hdr_v1_hash_tunnel_ts { + struct virtio_net_hdr_v1_hash_tunnel tnl; + __le16 tstamp_0; + __le16 tstamp_1; + __le16 tstamp_2; + __le16 tstamp_3; +}; + #ifndef VIRTIO_NET_NO_LEGACY /* This header comes first in the scatter-gather list. * For legacy virtio, if VIRTIO_F_ANY_LAYOUT is not negotiated, it must -- 2.52.0 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v2 2/2] virtio-net: support receive timestamp 2026-01-29 8:06 ` [PATCH RFC v2 2/2] virtio-net: support receive timestamp Steffen Trumtrar @ 2026-01-29 9:48 ` Xuan Zhuo 2026-01-29 10:08 ` Steffen Trumtrar 2026-02-01 21:05 ` Willem de Bruijn 1 sibling, 1 reply; 17+ messages in thread From: Xuan Zhuo @ 2026-01-29 9:48 UTC (permalink / raw) To: Steffen Trumtrar Cc: virtualization, netdev, linux-kernel, Steffen Trumtrar, Michael S. Tsirkin, Jason Wang, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran, Willem de Bruijn, Andrew Lunn, Eugenio Pérez On Thu, 29 Jan 2026 09:06:42 +0100, Steffen Trumtrar <s.trumtrar@pengutronix.de> wrote: > Add optional hardware rx timestamp offload for virtio-net. > > Introduce virtio feature VIRTIO_NET_F_TSTAMP. If negotiated, the > virtio-net header is expanded with room for a timestamp. > > To get and set the hwtstamp the functions ndo_hwtstamp_set/get need > to be implemented. This allows filtering the packets and only time stamp > the packets where the filter matches. This way, the timestamping can > be en/disabled at runtime. > > Tested: > guest: ./timestamping eth0 \ > SOF_TIMESTAMPING_RAW_HARDWARE \ > SOF_TIMESTAMPING_RX_HARDWARE > host: nc -4 -u 192.168.1.1 319 > > Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> > > -- > Changes to last version: > - rework series to use flow filters > - add new struct virtio_net_hdr_v1_hash_tunnel_ts > - original work done by: Willem de Bruijn <willemb@google.com> > --- > drivers/net/virtio_net.c | 136 ++++++++++++++++++++++++++++++++++++---- > include/uapi/linux/virtio_net.h | 9 +++ > 2 files changed, 133 insertions(+), 12 deletions(-) > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > index 1bb3aeca66c6e..4e8d9b20c1b34 100644 > --- a/drivers/net/virtio_net.c > +++ b/drivers/net/virtio_net.c > @@ -429,6 +429,9 @@ struct virtnet_info { > struct virtio_net_rss_config_trailer rss_trailer; > u8 rss_hash_key_data[VIRTIO_NET_RSS_MAX_KEY_SIZE]; > > + /* Device passes time stamps from the driver */ > + bool has_tstamp; > + > /* Has control virtqueue */ > bool has_cvq; > > @@ -475,6 +478,8 @@ struct virtnet_info { > > struct control_buf *ctrl; > > + struct kernel_hwtstamp_config tstamp_config; > + > /* Ethtool settings */ > u8 duplex; > u32 speed; > @@ -511,6 +516,7 @@ struct virtio_net_common_hdr { > struct virtio_net_hdr_mrg_rxbuf mrg_hdr; > struct virtio_net_hdr_v1_hash hash_v1_hdr; > struct virtio_net_hdr_v1_hash_tunnel tnl_hdr; > + struct virtio_net_hdr_v1_hash_tunnel_ts ts_hdr; > }; > }; > > @@ -682,6 +688,13 @@ skb_vnet_common_hdr(struct sk_buff *skb) > return (struct virtio_net_common_hdr *)skb->cb; > } > > +static inline struct virtio_net_hdr_v1_hash_tunnel_ts *skb_vnet_hdr_ts(struct sk_buff *skb) > +{ > + BUILD_BUG_ON(sizeof(struct virtio_net_hdr_v1_hash_tunnel_ts) > sizeof(skb->cb)); > + > + return (void *)skb->cb; > +} > + > /* > * private is used to chain pages for big packets, put the whole > * most recent used list in the beginning for reuse > @@ -2560,6 +2573,15 @@ virtio_net_hash_value(const struct virtio_net_hdr_v1_hash *hdr_hash) > (__le16_to_cpu(hdr_hash->hash_value_hi) << 16); > } > > +static inline u64 > +virtio_net_tstamp_value(const struct virtio_net_hdr_v1_hash_tunnel_ts *hdr_hash_ts) > +{ > + return (u64)__le16_to_cpu(hdr_hash_ts->tstamp_0) | > + ((u64)__le16_to_cpu(hdr_hash_ts->tstamp_1) << 16) | > + ((u64)__le16_to_cpu(hdr_hash_ts->tstamp_2) << 32) | > + ((u64)__le16_to_cpu(hdr_hash_ts->tstamp_3) << 48); > +} > + > static void virtio_skb_set_hash(const struct virtio_net_hdr_v1_hash *hdr_hash, > struct sk_buff *skb) > { > @@ -2589,6 +2611,18 @@ static void virtio_skb_set_hash(const struct virtio_net_hdr_v1_hash *hdr_hash, > skb_set_hash(skb, virtio_net_hash_value(hdr_hash), rss_hash_type); > } > > +static inline void virtnet_record_rx_tstamp(const struct virtnet_info *vi, > + struct sk_buff *skb) > +{ > + struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb); > + const struct virtio_net_hdr_v1_hash_tunnel_ts *h = skb_vnet_hdr_ts(skb); > + u64 ts; > + > + ts = virtio_net_tstamp_value(h); > + memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps)); > + shhwtstamps->hwtstamp = ns_to_ktime(ts); > +} > + > static void virtnet_receive_done(struct virtnet_info *vi, struct receive_queue *rq, > struct sk_buff *skb, u8 flags) > { > @@ -2617,6 +2651,8 @@ static void virtnet_receive_done(struct virtnet_info *vi, struct receive_queue * > goto frame_err; > } > > + if (vi->has_tstamp && vi->tstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) > + virtnet_record_rx_tstamp(vi, skb); > skb_record_rx_queue(skb, vq2rxq(rq->vq)); > skb->protocol = eth_type_trans(skb, dev); > pr_debug("Receiving skb proto 0x%04x len %i type %i\n", > @@ -3321,7 +3357,7 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb, bool orphan) > { > const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest; > struct virtnet_info *vi = sq->vq->vdev->priv; > - struct virtio_net_hdr_v1_hash_tunnel *hdr; > + struct virtio_net_hdr_v1_hash_tunnel_ts *hdr; > int num_sg; > unsigned hdr_len = vi->hdr_len; > bool can_push; > @@ -3329,8 +3365,8 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb, bool orphan) > pr_debug("%s: xmit %p %pM\n", vi->dev->name, skb, dest); > > /* Make sure it's safe to cast between formats */ > - BUILD_BUG_ON(__alignof__(*hdr) != __alignof__(hdr->hash_hdr)); > - BUILD_BUG_ON(__alignof__(*hdr) != __alignof__(hdr->hash_hdr.hdr)); > + BUILD_BUG_ON(__alignof__(*hdr) != __alignof__(hdr->tnl.hash_hdr)); > + BUILD_BUG_ON(__alignof__(*hdr) != __alignof__(hdr->tnl.hash_hdr.hdr)); > > can_push = vi->any_header_sg && > !((unsigned long)skb->data & (__alignof__(*hdr) - 1)) && > @@ -3338,18 +3374,18 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb, bool orphan) > /* Even if we can, don't push here yet as this would skew > * csum_start offset below. */ > if (can_push) > - hdr = (struct virtio_net_hdr_v1_hash_tunnel *)(skb->data - > - hdr_len); > + hdr = (struct virtio_net_hdr_v1_hash_tunnel_ts *)(skb->data - > + hdr_len); > else > - hdr = &skb_vnet_common_hdr(skb)->tnl_hdr; > + hdr = &skb_vnet_common_hdr(skb)->ts_hdr; > > - if (virtio_net_hdr_tnl_from_skb(skb, hdr, vi->tx_tnl, > + if (virtio_net_hdr_tnl_from_skb(skb, &hdr->tnl, vi->tx_tnl, > virtio_is_little_endian(vi->vdev), 0, > false)) > return -EPROTO; > > if (vi->mergeable_rx_bufs) > - hdr->hash_hdr.hdr.num_buffers = 0; > + hdr->tnl.hash_hdr.hdr.num_buffers = 0; > > sg_init_table(sq->sg, skb_shinfo(skb)->nr_frags + (can_push ? 1 : 2)); > if (can_push) { > @@ -5563,6 +5599,22 @@ static int virtnet_get_per_queue_coalesce(struct net_device *dev, > return 0; > } > > +static int virtnet_get_ts_info(struct net_device *dev, > + struct kernel_ethtool_ts_info *info) > +{ > + /* setup default software timestamp */ > + ethtool_op_get_ts_info(dev, info); > + > + info->rx_filters = (BIT(HWTSTAMP_FILTER_NONE) | > + BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) | > + BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) | > + BIT(HWTSTAMP_FILTER_ALL)); > + > + info->tx_types = HWTSTAMP_TX_OFF; > + > + return 0; > +} > + > static void virtnet_init_settings(struct net_device *dev) > { > struct virtnet_info *vi = netdev_priv(dev); > @@ -5658,7 +5710,7 @@ static const struct ethtool_ops virtnet_ethtool_ops = { > .get_ethtool_stats = virtnet_get_ethtool_stats, > .set_channels = virtnet_set_channels, > .get_channels = virtnet_get_channels, > - .get_ts_info = ethtool_op_get_ts_info, > + .get_ts_info = virtnet_get_ts_info, > .get_link_ksettings = virtnet_get_link_ksettings, > .set_link_ksettings = virtnet_set_link_ksettings, > .set_coalesce = virtnet_set_coalesce, > @@ -6242,6 +6294,58 @@ static void virtnet_tx_timeout(struct net_device *dev, unsigned int txqueue) > jiffies_to_usecs(jiffies - READ_ONCE(txq->trans_start))); > } > > +static int virtnet_hwtstamp_get(struct net_device *dev, > + struct kernel_hwtstamp_config *tstamp_config) > +{ > + struct virtnet_info *vi = netdev_priv(dev); > + > + if (!netif_running(dev)) > + return -EINVAL; > + > + *tstamp_config = vi->tstamp_config; > + > + return 0; > +} > + > +static int virtnet_hwtstamp_set(struct net_device *dev, > + struct kernel_hwtstamp_config *tstamp_config, > + struct netlink_ext_ack *extack) > +{ > + struct virtnet_info *vi = netdev_priv(dev); > + > + if (!netif_running(dev)) > + return -EINVAL; > + > + switch (tstamp_config->rx_filter) { > + case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: > + case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: > + break; > + case HWTSTAMP_FILTER_PTP_V2_EVENT: > + case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: > + case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: > + case HWTSTAMP_FILTER_PTP_V2_SYNC: > + case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: > + case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: > + case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: > + case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: > + case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: > + tstamp_config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; > + break; > + case HWTSTAMP_FILTER_NONE: > + break; > + case HWTSTAMP_FILTER_ALL: > + tstamp_config->rx_filter = HWTSTAMP_FILTER_ALL; > + break; > + default: > + tstamp_config->rx_filter = HWTSTAMP_FILTER_ALL; > + return -ERANGE; > + } > + > + vi->tstamp_config = *tstamp_config; > + > + return 0; > +} > + > static int virtnet_init_irq_moder(struct virtnet_info *vi) > { > u8 profile_flags = 0, coal_flags = 0; > @@ -6289,6 +6393,8 @@ static const struct net_device_ops virtnet_netdev = { > .ndo_get_phys_port_name = virtnet_get_phys_port_name, > .ndo_set_features = virtnet_set_features, > .ndo_tx_timeout = virtnet_tx_timeout, > + .ndo_hwtstamp_set = virtnet_hwtstamp_set, > + .ndo_hwtstamp_get = virtnet_hwtstamp_get, > }; > > static void virtnet_config_changed_work(struct work_struct *work) > @@ -6911,6 +7017,9 @@ static int virtnet_probe(struct virtio_device *vdev) > if (virtio_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT)) > vi->has_rss_hash_report = true; > > + if (virtio_has_feature(vdev, VIRTIO_NET_F_TSTAMP)) > + vi->has_tstamp = true; > + > if (virtio_has_feature(vdev, VIRTIO_NET_F_RSS)) { > vi->has_rss = true; > > @@ -6945,8 +7054,10 @@ static int virtnet_probe(struct virtio_device *vdev) > dev->xdp_metadata_ops = &virtnet_xdp_metadata_ops; > } > > - if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO) || > - virtio_has_feature(vdev, VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO)) > + if (vi->has_tstamp) > + vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash_tunnel_ts); > + else if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO) || > + virtio_has_feature(vdev, VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO)) > vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash_tunnel); > else if (vi->has_rss_hash_report) > vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash); > @@ -7269,7 +7380,8 @@ static struct virtio_device_id id_table[] = { > VIRTIO_NET_F_SPEED_DUPLEX, VIRTIO_NET_F_STANDBY, \ > VIRTIO_NET_F_RSS, VIRTIO_NET_F_HASH_REPORT, VIRTIO_NET_F_NOTF_COAL, \ > VIRTIO_NET_F_VQ_NOTF_COAL, \ > - VIRTIO_NET_F_GUEST_HDRLEN, VIRTIO_NET_F_DEVICE_STATS > + VIRTIO_NET_F_GUEST_HDRLEN, VIRTIO_NET_F_DEVICE_STATS, \ > + VIRTIO_NET_F_TSTAMP > > static unsigned int features[] = { > VIRTNET_FEATURES, > diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h > index 1db45b01532b5..9f967575956b8 100644 > --- a/include/uapi/linux/virtio_net.h > +++ b/include/uapi/linux/virtio_net.h > @@ -56,6 +56,7 @@ > #define VIRTIO_NET_F_MQ 22 /* Device supports Receive Flow > * Steering */ > #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ > +#define VIRTIO_NET_F_TSTAMP 49 /* Device sends TAI receive time */ > #define VIRTIO_NET_F_DEVICE_STATS 50 /* Device can provide device-level statistics. */ > #define VIRTIO_NET_F_VQ_NOTF_COAL 52 /* Device supports virtqueue notification coalescing */ > #define VIRTIO_NET_F_NOTF_COAL 53 /* Device supports notifications coalescing */ > @@ -215,6 +216,14 @@ struct virtio_net_hdr_v1_hash_tunnel { > __le16 inner_nh_offset; > }; > > +struct virtio_net_hdr_v1_hash_tunnel_ts { > + struct virtio_net_hdr_v1_hash_tunnel tnl; > + __le16 tstamp_0; > + __le16 tstamp_1; > + __le16 tstamp_2; > + __le16 tstamp_3; > +}; Since patch #1 used this struct, this one should be placed first in the series. Also, has the virtio specification process accepted such a draft proposal? Thanks > + > #ifndef VIRTIO_NET_NO_LEGACY > /* This header comes first in the scatter-gather list. > * For legacy virtio, if VIRTIO_F_ANY_LAYOUT is not negotiated, it must > > -- > 2.52.0 > ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v2 2/2] virtio-net: support receive timestamp 2026-01-29 9:48 ` Xuan Zhuo @ 2026-01-29 10:08 ` Steffen Trumtrar 2026-01-29 11:03 ` Xuan Zhuo 0 siblings, 1 reply; 17+ messages in thread From: Steffen Trumtrar @ 2026-01-29 10:08 UTC (permalink / raw) To: Xuan Zhuo Cc: virtualization, netdev, linux-kernel, Michael S. Tsirkin, Jason Wang, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran, Willem de Bruijn, Andrew Lunn, Eugenio Pérez Hi, On 2026-01-29 at 17:48 +08, Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote: > > Since patch #1 used this struct, this one should be placed first in the series. oh, you are right, the order should be the other way around. > Also, has the virtio specification process accepted such a draft proposal? I haven't sent the draft yet, because I'm unsure if I understood the way this should be implemented with the flow filter correctly. If the direction is correct, I'd try and get the specification process going again. (That is not that easy, if you're not used to it and not that deep into the whole virtio universe ;)) Best regards, Steffen -- Pengutronix e.K. | Dipl.-Inform. Steffen Trumtrar | Steuerwalder Str. 21 | https://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686| Fax: +49-5121-206917-5555 | ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v2 2/2] virtio-net: support receive timestamp 2026-01-29 10:08 ` Steffen Trumtrar @ 2026-01-29 11:03 ` Xuan Zhuo 0 siblings, 0 replies; 17+ messages in thread From: Xuan Zhuo @ 2026-01-29 11:03 UTC (permalink / raw) To: Steffen Trumtrar Cc: virtualization, netdev, linux-kernel, Michael S. Tsirkin, Jason Wang, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran, Willem de Bruijn, Andrew Lunn, Eugenio Pérez On Thu, 29 Jan 2026 11:08:27 +0100, Steffen Trumtrar <s.trumtrar@pengutronix.de> wrote: > > Hi, > > On 2026-01-29 at 17:48 +08, Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote: > > > > Since patch #1 used this struct, this one should be placed first in the series. > > oh, you are right, the order should be the other way around. > > > Also, has the virtio specification process accepted such a draft proposal? > > I haven't sent the draft yet, because I'm unsure if I understood the way this should be implemented with the flow filter correctly. > If the direction is correct, I'd try and get the specification process going again. > (That is not that easy, if you're not used to it and not that deep into the whole virtio universe ;)) There have been many historical attempts in this area- you may want to take a look first. Thanks. > > > Best regards, > Steffen > > -- > Pengutronix e.K. | Dipl.-Inform. Steffen Trumtrar | > Steuerwalder Str. 21 | https://www.pengutronix.de/ | > 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | > Amtsgericht Hildesheim, HRA 2686| Fax: +49-5121-206917-5555 | ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v2 2/2] virtio-net: support receive timestamp 2026-01-29 8:06 ` [PATCH RFC v2 2/2] virtio-net: support receive timestamp Steffen Trumtrar 2026-01-29 9:48 ` Xuan Zhuo @ 2026-02-01 21:05 ` Willem de Bruijn 2026-02-02 7:34 ` Steffen Trumtrar ` (2 more replies) 1 sibling, 3 replies; 17+ messages in thread From: Willem de Bruijn @ 2026-02-01 21:05 UTC (permalink / raw) To: Steffen Trumtrar, Michael S. Tsirkin, Jason Wang, Xuan Zhuo, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran, Willem de Bruijn, Andrew Lunn, Eugenio Pérez Cc: virtualization, netdev, linux-kernel, Steffen Trumtrar Steffen Trumtrar wrote: > Add optional hardware rx timestamp offload for virtio-net. > > Introduce virtio feature VIRTIO_NET_F_TSTAMP. If negotiated, the > virtio-net header is expanded with room for a timestamp. > > To get and set the hwtstamp the functions ndo_hwtstamp_set/get need > to be implemented. This allows filtering the packets and only time stamp > the packets where the filter matches. This way, the timestamping can > be en/disabled at runtime. > > Tested: > guest: ./timestamping eth0 \ > SOF_TIMESTAMPING_RAW_HARDWARE \ > SOF_TIMESTAMPING_RX_HARDWARE > host: nc -4 -u 192.168.1.1 319 > > Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> > > -- > Changes to last version: > - rework series to use flow filters > - add new struct virtio_net_hdr_v1_hash_tunnel_ts > - original work done by: Willem de Bruijn <willemb@google.com> > --- > drivers/net/virtio_net.c | 136 ++++++++++++++++++++++++++++++++++++---- > include/uapi/linux/virtio_net.h | 9 +++ > 2 files changed, 133 insertions(+), 12 deletions(-) > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > index 1bb3aeca66c6e..4e8d9b20c1b34 100644 > --- a/drivers/net/virtio_net.c > +++ b/drivers/net/virtio_net.c > @@ -429,6 +429,9 @@ struct virtnet_info { > struct virtio_net_rss_config_trailer rss_trailer; > u8 rss_hash_key_data[VIRTIO_NET_RSS_MAX_KEY_SIZE]; > > + /* Device passes time stamps from the driver */ > + bool has_tstamp; > + > /* Has control virtqueue */ > bool has_cvq; > > @@ -475,6 +478,8 @@ struct virtnet_info { > > struct control_buf *ctrl; > > + struct kernel_hwtstamp_config tstamp_config; > + > /* Ethtool settings */ > u8 duplex; > u32 speed; > @@ -511,6 +516,7 @@ struct virtio_net_common_hdr { > struct virtio_net_hdr_mrg_rxbuf mrg_hdr; > struct virtio_net_hdr_v1_hash hash_v1_hdr; > struct virtio_net_hdr_v1_hash_tunnel tnl_hdr; > + struct virtio_net_hdr_v1_hash_tunnel_ts ts_hdr; Jason, Michael: creating a new struct for every field is not very elegant. Is it time to find a more forward looking approach to expanding with new fields? Like a TLV, or how netlink structs like tcp_info are extended with support for legacy users that only use a truncated struct? > }; > }; > > @@ -682,6 +688,13 @@ skb_vnet_common_hdr(struct sk_buff *skb) > return (struct virtio_net_common_hdr *)skb->cb; > } > > +static inline struct virtio_net_hdr_v1_hash_tunnel_ts *skb_vnet_hdr_ts(struct sk_buff *skb) > +{ > + BUILD_BUG_ON(sizeof(struct virtio_net_hdr_v1_hash_tunnel_ts) > sizeof(skb->cb)); > + > + return (void *)skb->cb; > +} > + > /* > * private is used to chain pages for big packets, put the whole > * most recent used list in the beginning for reuse > @@ -2560,6 +2573,15 @@ virtio_net_hash_value(const struct virtio_net_hdr_v1_hash *hdr_hash) > (__le16_to_cpu(hdr_hash->hash_value_hi) << 16); > } > > +static inline u64 > +virtio_net_tstamp_value(const struct virtio_net_hdr_v1_hash_tunnel_ts *hdr_hash_ts) > +{ > + return (u64)__le16_to_cpu(hdr_hash_ts->tstamp_0) | > + ((u64)__le16_to_cpu(hdr_hash_ts->tstamp_1) << 16) | > + ((u64)__le16_to_cpu(hdr_hash_ts->tstamp_2) << 32) | > + ((u64)__le16_to_cpu(hdr_hash_ts->tstamp_3) << 48); > +} > + > static void virtio_skb_set_hash(const struct virtio_net_hdr_v1_hash *hdr_hash, > struct sk_buff *skb) > { > @@ -2589,6 +2611,18 @@ static void virtio_skb_set_hash(const struct virtio_net_hdr_v1_hash *hdr_hash, > skb_set_hash(skb, virtio_net_hash_value(hdr_hash), rss_hash_type); > } > > +static inline void virtnet_record_rx_tstamp(const struct virtnet_info *vi, > + struct sk_buff *skb) > +{ > + struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb); > + const struct virtio_net_hdr_v1_hash_tunnel_ts *h = skb_vnet_hdr_ts(skb); > + u64 ts; > + > + ts = virtio_net_tstamp_value(h); > + memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps)); > + shhwtstamps->hwtstamp = ns_to_ktime(ts); > +} > + > static void virtnet_receive_done(struct virtnet_info *vi, struct receive_queue *rq, > struct sk_buff *skb, u8 flags) > { > @@ -2617,6 +2651,8 @@ static void virtnet_receive_done(struct virtnet_info *vi, struct receive_queue * > goto frame_err; > } > > + if (vi->has_tstamp && vi->tstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) > + virtnet_record_rx_tstamp(vi, skb); > skb_record_rx_queue(skb, vq2rxq(rq->vq)); > skb->protocol = eth_type_trans(skb, dev); > pr_debug("Receiving skb proto 0x%04x len %i type %i\n", > @@ -3321,7 +3357,7 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb, bool orphan) > { > const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest; > struct virtnet_info *vi = sq->vq->vdev->priv; > - struct virtio_net_hdr_v1_hash_tunnel *hdr; > + struct virtio_net_hdr_v1_hash_tunnel_ts *hdr; > int num_sg; > unsigned hdr_len = vi->hdr_len; > bool can_push; > @@ -3329,8 +3365,8 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb, bool orphan) > pr_debug("%s: xmit %p %pM\n", vi->dev->name, skb, dest); > > /* Make sure it's safe to cast between formats */ > - BUILD_BUG_ON(__alignof__(*hdr) != __alignof__(hdr->hash_hdr)); > - BUILD_BUG_ON(__alignof__(*hdr) != __alignof__(hdr->hash_hdr.hdr)); > + BUILD_BUG_ON(__alignof__(*hdr) != __alignof__(hdr->tnl.hash_hdr)); > + BUILD_BUG_ON(__alignof__(*hdr) != __alignof__(hdr->tnl.hash_hdr.hdr)); > > can_push = vi->any_header_sg && > !((unsigned long)skb->data & (__alignof__(*hdr) - 1)) && > @@ -3338,18 +3374,18 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb, bool orphan) > /* Even if we can, don't push here yet as this would skew > * csum_start offset below. */ > if (can_push) > - hdr = (struct virtio_net_hdr_v1_hash_tunnel *)(skb->data - > - hdr_len); > + hdr = (struct virtio_net_hdr_v1_hash_tunnel_ts *)(skb->data - > + hdr_len); > else > - hdr = &skb_vnet_common_hdr(skb)->tnl_hdr; > + hdr = &skb_vnet_common_hdr(skb)->ts_hdr; > > - if (virtio_net_hdr_tnl_from_skb(skb, hdr, vi->tx_tnl, > + if (virtio_net_hdr_tnl_from_skb(skb, &hdr->tnl, vi->tx_tnl, > virtio_is_little_endian(vi->vdev), 0, > false)) > return -EPROTO; > > if (vi->mergeable_rx_bufs) > - hdr->hash_hdr.hdr.num_buffers = 0; > + hdr->tnl.hash_hdr.hdr.num_buffers = 0; > > sg_init_table(sq->sg, skb_shinfo(skb)->nr_frags + (can_push ? 1 : 2)); > if (can_push) { > @@ -5563,6 +5599,22 @@ static int virtnet_get_per_queue_coalesce(struct net_device *dev, > return 0; > } > > +static int virtnet_get_ts_info(struct net_device *dev, > + struct kernel_ethtool_ts_info *info) > +{ > + /* setup default software timestamp */ > + ethtool_op_get_ts_info(dev, info); > + > + info->rx_filters = (BIT(HWTSTAMP_FILTER_NONE) | > + BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) | > + BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) | > + BIT(HWTSTAMP_FILTER_ALL)); > + > + info->tx_types = HWTSTAMP_TX_OFF; > + > + return 0; > +} > + > static void virtnet_init_settings(struct net_device *dev) > { > struct virtnet_info *vi = netdev_priv(dev); > @@ -5658,7 +5710,7 @@ static const struct ethtool_ops virtnet_ethtool_ops = { > .get_ethtool_stats = virtnet_get_ethtool_stats, > .set_channels = virtnet_set_channels, > .get_channels = virtnet_get_channels, > - .get_ts_info = ethtool_op_get_ts_info, > + .get_ts_info = virtnet_get_ts_info, > .get_link_ksettings = virtnet_get_link_ksettings, > .set_link_ksettings = virtnet_set_link_ksettings, > .set_coalesce = virtnet_set_coalesce, > @@ -6242,6 +6294,58 @@ static void virtnet_tx_timeout(struct net_device *dev, unsigned int txqueue) > jiffies_to_usecs(jiffies - READ_ONCE(txq->trans_start))); > } > > +static int virtnet_hwtstamp_get(struct net_device *dev, > + struct kernel_hwtstamp_config *tstamp_config) > +{ > + struct virtnet_info *vi = netdev_priv(dev); > + > + if (!netif_running(dev)) > + return -EINVAL; > + > + *tstamp_config = vi->tstamp_config; > + > + return 0; > +} > + > +static int virtnet_hwtstamp_set(struct net_device *dev, > + struct kernel_hwtstamp_config *tstamp_config, > + struct netlink_ext_ack *extack) > +{ > + struct virtnet_info *vi = netdev_priv(dev); > + > + if (!netif_running(dev)) > + return -EINVAL; > + > + switch (tstamp_config->rx_filter) { > + case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: > + case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: > + break; > + case HWTSTAMP_FILTER_PTP_V2_EVENT: > + case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: > + case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: > + case HWTSTAMP_FILTER_PTP_V2_SYNC: > + case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: > + case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: > + case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: > + case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: > + case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: > + tstamp_config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; > + break; > + case HWTSTAMP_FILTER_NONE: > + break; > + case HWTSTAMP_FILTER_ALL: > + tstamp_config->rx_filter = HWTSTAMP_FILTER_ALL; > + break; It's fine to implement filters, but also fine to only support ALL or NONE for simplicity. In the end it probably depends on what the underlying physical device supports. > + default: > + tstamp_config->rx_filter = HWTSTAMP_FILTER_ALL; > + return -ERANGE; > + } > + > + vi->tstamp_config = *tstamp_config; > + > + return 0; > +} > + > static int virtnet_init_irq_moder(struct virtnet_info *vi) > { > u8 profile_flags = 0, coal_flags = 0; > @@ -6289,6 +6393,8 @@ static const struct net_device_ops virtnet_netdev = { > .ndo_get_phys_port_name = virtnet_get_phys_port_name, > .ndo_set_features = virtnet_set_features, > .ndo_tx_timeout = virtnet_tx_timeout, > + .ndo_hwtstamp_set = virtnet_hwtstamp_set, > + .ndo_hwtstamp_get = virtnet_hwtstamp_get, > }; > > static void virtnet_config_changed_work(struct work_struct *work) > @@ -6911,6 +7017,9 @@ static int virtnet_probe(struct virtio_device *vdev) > if (virtio_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT)) > vi->has_rss_hash_report = true; > > + if (virtio_has_feature(vdev, VIRTIO_NET_F_TSTAMP)) > + vi->has_tstamp = true; > + > if (virtio_has_feature(vdev, VIRTIO_NET_F_RSS)) { > vi->has_rss = true; > > @@ -6945,8 +7054,10 @@ static int virtnet_probe(struct virtio_device *vdev) > dev->xdp_metadata_ops = &virtnet_xdp_metadata_ops; > } > > - if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO) || > - virtio_has_feature(vdev, VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO)) > + if (vi->has_tstamp) > + vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash_tunnel_ts); > + else if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO) || > + virtio_has_feature(vdev, VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO)) > vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash_tunnel); > else if (vi->has_rss_hash_report) > vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash); > @@ -7269,7 +7380,8 @@ static struct virtio_device_id id_table[] = { > VIRTIO_NET_F_SPEED_DUPLEX, VIRTIO_NET_F_STANDBY, \ > VIRTIO_NET_F_RSS, VIRTIO_NET_F_HASH_REPORT, VIRTIO_NET_F_NOTF_COAL, \ > VIRTIO_NET_F_VQ_NOTF_COAL, \ > - VIRTIO_NET_F_GUEST_HDRLEN, VIRTIO_NET_F_DEVICE_STATS > + VIRTIO_NET_F_GUEST_HDRLEN, VIRTIO_NET_F_DEVICE_STATS, \ > + VIRTIO_NET_F_TSTAMP > > static unsigned int features[] = { > VIRTNET_FEATURES, > diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h > index 1db45b01532b5..9f967575956b8 100644 > --- a/include/uapi/linux/virtio_net.h > +++ b/include/uapi/linux/virtio_net.h > @@ -56,6 +56,7 @@ > #define VIRTIO_NET_F_MQ 22 /* Device supports Receive Flow > * Steering */ > #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ > +#define VIRTIO_NET_F_TSTAMP 49 /* Device sends TAI receive time */ > #define VIRTIO_NET_F_DEVICE_STATS 50 /* Device can provide device-level statistics. */ > #define VIRTIO_NET_F_VQ_NOTF_COAL 52 /* Device supports virtqueue notification coalescing */ > #define VIRTIO_NET_F_NOTF_COAL 53 /* Device supports notifications coalescing */ > @@ -215,6 +216,14 @@ struct virtio_net_hdr_v1_hash_tunnel { > __le16 inner_nh_offset; > }; > > +struct virtio_net_hdr_v1_hash_tunnel_ts { > + struct virtio_net_hdr_v1_hash_tunnel tnl; > + __le16 tstamp_0; > + __le16 tstamp_1; > + __le16 tstamp_2; > + __le16 tstamp_3; > +}; Why the multiple fields, rather than u64. More broadly: can my old patchset be dusted off as is. Does it require significant changes? I only paused it at the time, because I did not have a real device back-end that was going to support it. > + > #ifndef VIRTIO_NET_NO_LEGACY > /* This header comes first in the scatter-gather list. > * For legacy virtio, if VIRTIO_F_ANY_LAYOUT is not negotiated, it must > > -- > 2.52.0 > ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v2 2/2] virtio-net: support receive timestamp 2026-02-01 21:05 ` Willem de Bruijn @ 2026-02-02 7:34 ` Steffen Trumtrar 2026-02-02 7:59 ` Michael S. Tsirkin 2026-02-03 3:24 ` Jason Wang 2 siblings, 0 replies; 17+ messages in thread From: Steffen Trumtrar @ 2026-02-02 7:34 UTC (permalink / raw) To: Willem de Bruijn Cc: Michael S. Tsirkin, Jason Wang, Xuan Zhuo, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran, Andrew Lunn, Eugenio Pérez, virtualization, netdev, linux-kernel On 2026-02-01 at 16:05 -05, Willem de Bruijn <willemdebruijn.kernel@gmail.com> wrote: > Steffen Trumtrar wrote: > > Add optional hardware rx timestamp offload for virtio-net. > > > > Introduce virtio feature VIRTIO_NET_F_TSTAMP. If negotiated, the > > virtio-net header is expanded with room for a timestamp. > > > > To get and set the hwtstamp the functions ndo_hwtstamp_set/get need > > to be implemented. This allows filtering the packets and only time stamp > > the packets where the filter matches. This way, the timestamping can > > be en/disabled at runtime. > > > > Tested: > > guest: ./timestamping eth0 \ > > SOF_TIMESTAMPING_RAW_HARDWARE \ > > SOF_TIMESTAMPING_RX_HARDWARE > > host: nc -4 -u 192.168.1.1 319 > > > > Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> > > > > -- > > Changes to last version: > > - rework series to use flow filters > > - add new struct virtio_net_hdr_v1_hash_tunnel_ts > > - original work done by: Willem de Bruijn <willemb@google.com> > > --- > > drivers/net/virtio_net.c | 136 ++++++++++++++++++++++++++++++++++++---- > > include/uapi/linux/virtio_net.h | 9 +++ > > 2 files changed, 133 insertions(+), 12 deletions(-) > > > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > > index 1bb3aeca66c6e..4e8d9b20c1b34 100644 > > --- a/drivers/net/virtio_net.c > > +++ b/drivers/net/virtio_net.c > > @@ -429,6 +429,9 @@ struct virtnet_info { > > struct virtio_net_rss_config_trailer rss_trailer; > > u8 rss_hash_key_data[VIRTIO_NET_RSS_MAX_KEY_SIZE]; > > > > + /* Device passes time stamps from the driver */ > > + bool has_tstamp; > > + > > /* Has control virtqueue */ > > bool has_cvq; > > > > @@ -475,6 +478,8 @@ struct virtnet_info { > > > > struct control_buf *ctrl; > > > > + struct kernel_hwtstamp_config tstamp_config; > > + > > /* Ethtool settings */ > > u8 duplex; > > u32 speed; > > @@ -511,6 +516,7 @@ struct virtio_net_common_hdr { > > struct virtio_net_hdr_mrg_rxbuf mrg_hdr; > > struct virtio_net_hdr_v1_hash hash_v1_hdr; > > struct virtio_net_hdr_v1_hash_tunnel tnl_hdr; > > + struct virtio_net_hdr_v1_hash_tunnel_ts ts_hdr; > > Jason, Michael: creating a new struct for every field is not very > elegant. Is it time to find a more forward looking approach to > expanding with new fields? Like a TLV, or how netlink structs like > tcp_info are extended with support for legacy users that only use > a truncated struct? > Yes, this gets complicated real fast and leads to really long calls for all the nested fields. If there is a different way, I'd prefer that. > > }; > > }; > > > > @@ -682,6 +688,13 @@ skb_vnet_common_hdr(struct sk_buff *skb) > > return (struct virtio_net_common_hdr *)skb->cb; > > } > > > > +static inline struct virtio_net_hdr_v1_hash_tunnel_ts *skb_vnet_hdr_ts(struct sk_buff *skb) > > +{ > > + BUILD_BUG_ON(sizeof(struct virtio_net_hdr_v1_hash_tunnel_ts) > sizeof(skb->cb)); > > + > > + return (void *)skb->cb; > > +} > > + > > /* > > * private is used to chain pages for big packets, put the whole > > * most recent used list in the beginning for reuse > > @@ -2560,6 +2573,15 @@ virtio_net_hash_value(const struct virtio_net_hdr_v1_hash *hdr_hash) > > (__le16_to_cpu(hdr_hash->hash_value_hi) << 16); > > } > > > > +static inline u64 > > +virtio_net_tstamp_value(const struct virtio_net_hdr_v1_hash_tunnel_ts *hdr_hash_ts) > > +{ > > + return (u64)__le16_to_cpu(hdr_hash_ts->tstamp_0) | > > + ((u64)__le16_to_cpu(hdr_hash_ts->tstamp_1) << 16) | > > + ((u64)__le16_to_cpu(hdr_hash_ts->tstamp_2) << 32) | > > + ((u64)__le16_to_cpu(hdr_hash_ts->tstamp_3) << 48); > > +} > > + > > static void virtio_skb_set_hash(const struct virtio_net_hdr_v1_hash *hdr_hash, > > struct sk_buff *skb) > > { > > @@ -2589,6 +2611,18 @@ static void virtio_skb_set_hash(const struct virtio_net_hdr_v1_hash *hdr_hash, > > skb_set_hash(skb, virtio_net_hash_value(hdr_hash), rss_hash_type); > > } > > > > +static inline void virtnet_record_rx_tstamp(const struct virtnet_info *vi, > > + struct sk_buff *skb) > > +{ > > + struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb); > > + const struct virtio_net_hdr_v1_hash_tunnel_ts *h = skb_vnet_hdr_ts(skb); > > + u64 ts; > > + > > + ts = virtio_net_tstamp_value(h); > > + memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps)); > > + shhwtstamps->hwtstamp = ns_to_ktime(ts); > > +} > > + > > static void virtnet_receive_done(struct virtnet_info *vi, struct receive_queue *rq, > > struct sk_buff *skb, u8 flags) > > { > > @@ -2617,6 +2651,8 @@ static void virtnet_receive_done(struct virtnet_info *vi, struct receive_queue * > > goto frame_err; > > } > > > > + if (vi->has_tstamp && vi->tstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) > > + virtnet_record_rx_tstamp(vi, skb); > > skb_record_rx_queue(skb, vq2rxq(rq->vq)); > > skb->protocol = eth_type_trans(skb, dev); > > pr_debug("Receiving skb proto 0x%04x len %i type %i\n", > > @@ -3321,7 +3357,7 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb, bool orphan) > > { > > const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest; > > struct virtnet_info *vi = sq->vq->vdev->priv; > > - struct virtio_net_hdr_v1_hash_tunnel *hdr; > > + struct virtio_net_hdr_v1_hash_tunnel_ts *hdr; > > int num_sg; > > unsigned hdr_len = vi->hdr_len; > > bool can_push; > > @@ -3329,8 +3365,8 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb, bool orphan) > > pr_debug("%s: xmit %p %pM\n", vi->dev->name, skb, dest); > > > > /* Make sure it's safe to cast between formats */ > > - BUILD_BUG_ON(__alignof__(*hdr) != __alignof__(hdr->hash_hdr)); > > - BUILD_BUG_ON(__alignof__(*hdr) != __alignof__(hdr->hash_hdr.hdr)); > > + BUILD_BUG_ON(__alignof__(*hdr) != __alignof__(hdr->tnl.hash_hdr)); > > + BUILD_BUG_ON(__alignof__(*hdr) != __alignof__(hdr->tnl.hash_hdr.hdr)); > > > > can_push = vi->any_header_sg && > > !((unsigned long)skb->data & (__alignof__(*hdr) - 1)) && > > @@ -3338,18 +3374,18 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb, bool orphan) > > /* Even if we can, don't push here yet as this would skew > > * csum_start offset below. */ > > if (can_push) > > - hdr = (struct virtio_net_hdr_v1_hash_tunnel *)(skb->data - > > - hdr_len); > > + hdr = (struct virtio_net_hdr_v1_hash_tunnel_ts *)(skb->data - > > + hdr_len); > > else > > - hdr = &skb_vnet_common_hdr(skb)->tnl_hdr; > > + hdr = &skb_vnet_common_hdr(skb)->ts_hdr; > > > > - if (virtio_net_hdr_tnl_from_skb(skb, hdr, vi->tx_tnl, > > + if (virtio_net_hdr_tnl_from_skb(skb, &hdr->tnl, vi->tx_tnl, > > virtio_is_little_endian(vi->vdev), 0, > > false)) > > return -EPROTO; > > > > if (vi->mergeable_rx_bufs) > > - hdr->hash_hdr.hdr.num_buffers = 0; > > + hdr->tnl.hash_hdr.hdr.num_buffers = 0; > > > > sg_init_table(sq->sg, skb_shinfo(skb)->nr_frags + (can_push ? 1 : 2)); > > if (can_push) { > > @@ -5563,6 +5599,22 @@ static int virtnet_get_per_queue_coalesce(struct net_device *dev, > > return 0; > > } > > > > +static int virtnet_get_ts_info(struct net_device *dev, > > + struct kernel_ethtool_ts_info *info) > > +{ > > + /* setup default software timestamp */ > > + ethtool_op_get_ts_info(dev, info); > > + > > + info->rx_filters = (BIT(HWTSTAMP_FILTER_NONE) | > > + BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) | > > + BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) | > > + BIT(HWTSTAMP_FILTER_ALL)); > > + > > + info->tx_types = HWTSTAMP_TX_OFF; > > + > > + return 0; > > +} > > + > > static void virtnet_init_settings(struct net_device *dev) > > { > > struct virtnet_info *vi = netdev_priv(dev); > > @@ -5658,7 +5710,7 @@ static const struct ethtool_ops virtnet_ethtool_ops = { > > .get_ethtool_stats = virtnet_get_ethtool_stats, > > .set_channels = virtnet_set_channels, > > .get_channels = virtnet_get_channels, > > - .get_ts_info = ethtool_op_get_ts_info, > > + .get_ts_info = virtnet_get_ts_info, > > .get_link_ksettings = virtnet_get_link_ksettings, > > .set_link_ksettings = virtnet_set_link_ksettings, > > .set_coalesce = virtnet_set_coalesce, > > @@ -6242,6 +6294,58 @@ static void virtnet_tx_timeout(struct net_device *dev, unsigned int txqueue) > > jiffies_to_usecs(jiffies - READ_ONCE(txq->trans_start))); > > } > > > > +static int virtnet_hwtstamp_get(struct net_device *dev, > > + struct kernel_hwtstamp_config *tstamp_config) > > +{ > > + struct virtnet_info *vi = netdev_priv(dev); > > + > > + if (!netif_running(dev)) > > + return -EINVAL; > > + > > + *tstamp_config = vi->tstamp_config; > > + > > + return 0; > > +} > > + > > +static int virtnet_hwtstamp_set(struct net_device *dev, > > + struct kernel_hwtstamp_config *tstamp_config, > > + struct netlink_ext_ack *extack) > > +{ > > + struct virtnet_info *vi = netdev_priv(dev); > > + > > + if (!netif_running(dev)) > > + return -EINVAL; > > + > > + switch (tstamp_config->rx_filter) { > > + case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: > > + case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: > > + break; > > + case HWTSTAMP_FILTER_PTP_V2_EVENT: > > + case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: > > + case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: > > + case HWTSTAMP_FILTER_PTP_V2_SYNC: > > + case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: > > + case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: > > + case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: > > + case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: > > + case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: > > + tstamp_config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; > > + break; > > + case HWTSTAMP_FILTER_NONE: > > + break; > > + case HWTSTAMP_FILTER_ALL: > > + tstamp_config->rx_filter = HWTSTAMP_FILTER_ALL; > > + break; > > It's fine to implement filters, but also fine to only support ALL or > NONE for simplicity. > > In the end it probably depends on what the underlying physical device > supports. > > > + default: > > + tstamp_config->rx_filter = HWTSTAMP_FILTER_ALL; > > + return -ERANGE; > > + } > > + > > + vi->tstamp_config = *tstamp_config; > > + > > + return 0; > > +} > > + > > static int virtnet_init_irq_moder(struct virtnet_info *vi) > > { > > u8 profile_flags = 0, coal_flags = 0; > > @@ -6289,6 +6393,8 @@ static const struct net_device_ops virtnet_netdev = { > > .ndo_get_phys_port_name = virtnet_get_phys_port_name, > > .ndo_set_features = virtnet_set_features, > > .ndo_tx_timeout = virtnet_tx_timeout, > > + .ndo_hwtstamp_set = virtnet_hwtstamp_set, > > + .ndo_hwtstamp_get = virtnet_hwtstamp_get, > > }; > > > > static void virtnet_config_changed_work(struct work_struct *work) > > @@ -6911,6 +7017,9 @@ static int virtnet_probe(struct virtio_device *vdev) > > if (virtio_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT)) > > vi->has_rss_hash_report = true; > > > > + if (virtio_has_feature(vdev, VIRTIO_NET_F_TSTAMP)) > > + vi->has_tstamp = true; > > + > > if (virtio_has_feature(vdev, VIRTIO_NET_F_RSS)) { > > vi->has_rss = true; > > > > @@ -6945,8 +7054,10 @@ static int virtnet_probe(struct virtio_device *vdev) > > dev->xdp_metadata_ops = &virtnet_xdp_metadata_ops; > > } > > > > - if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO) || > > - virtio_has_feature(vdev, VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO)) > > + if (vi->has_tstamp) > > + vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash_tunnel_ts); > > + else if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO) || > > + virtio_has_feature(vdev, VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO)) > > vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash_tunnel); > > else if (vi->has_rss_hash_report) > > vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash); > > @@ -7269,7 +7380,8 @@ static struct virtio_device_id id_table[] = { > > VIRTIO_NET_F_SPEED_DUPLEX, VIRTIO_NET_F_STANDBY, \ > > VIRTIO_NET_F_RSS, VIRTIO_NET_F_HASH_REPORT, VIRTIO_NET_F_NOTF_COAL, \ > > VIRTIO_NET_F_VQ_NOTF_COAL, \ > > - VIRTIO_NET_F_GUEST_HDRLEN, VIRTIO_NET_F_DEVICE_STATS > > + VIRTIO_NET_F_GUEST_HDRLEN, VIRTIO_NET_F_DEVICE_STATS, \ > > + VIRTIO_NET_F_TSTAMP > > > > static unsigned int features[] = { > > VIRTNET_FEATURES, > > diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h > > index 1db45b01532b5..9f967575956b8 100644 > > --- a/include/uapi/linux/virtio_net.h > > +++ b/include/uapi/linux/virtio_net.h > > @@ -56,6 +56,7 @@ > > #define VIRTIO_NET_F_MQ 22 /* Device supports Receive Flow > > * Steering */ > > #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ > > +#define VIRTIO_NET_F_TSTAMP 49 /* Device sends TAI receive time */ > > #define VIRTIO_NET_F_DEVICE_STATS 50 /* Device can provide device-level statistics. */ > > #define VIRTIO_NET_F_VQ_NOTF_COAL 52 /* Device supports virtqueue notification coalescing */ > > #define VIRTIO_NET_F_NOTF_COAL 53 /* Device supports notifications coalescing */ > > @@ -215,6 +216,14 @@ struct virtio_net_hdr_v1_hash_tunnel { > > __le16 inner_nh_offset; > > }; > > > > +struct virtio_net_hdr_v1_hash_tunnel_ts { > > + struct virtio_net_hdr_v1_hash_tunnel tnl; > > + __le16 tstamp_0; > > + __le16 tstamp_1; > > + __le16 tstamp_2; > > + __le16 tstamp_3; > > +}; > > Why the multiple fields, rather than u64. Should have added a comment, but this is based on this patch c3838262b824c71c145cd3668722e99a69bc9cd9 virtio_net: fix alignment for virtio_net_hdr_v1_hash Changing alignment of header would mean it's no longer safe to cast a 2 byte aligned pointer between formats. Use two 16 bit fields to make it 2 byte aligned as previously. > > More broadly: can my old patchset be dusted off as is. Does it require > significant changes? > This is the dusted off version ;) With the flow filter it should be possible to turn the timestamps on and off during runtime. Best regards, Steffen -- Pengutronix e.K. | Dipl.-Inform. Steffen Trumtrar | Steuerwalder Str. 21 | https://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686| Fax: +49-5121-206917-5555 | ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v2 2/2] virtio-net: support receive timestamp 2026-02-01 21:05 ` Willem de Bruijn 2026-02-02 7:34 ` Steffen Trumtrar @ 2026-02-02 7:59 ` Michael S. Tsirkin 2026-02-02 17:40 ` Willem de Bruijn 2026-02-03 3:24 ` Jason Wang 2 siblings, 1 reply; 17+ messages in thread From: Michael S. Tsirkin @ 2026-02-02 7:59 UTC (permalink / raw) To: Willem de Bruijn Cc: Steffen Trumtrar, Jason Wang, Xuan Zhuo, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran, Andrew Lunn, Eugenio Pérez, virtualization, netdev, linux-kernel On Sun, Feb 01, 2026 at 04:05:54PM -0500, Willem de Bruijn wrote: > Steffen Trumtrar wrote: > > Add optional hardware rx timestamp offload for virtio-net. > > > > Introduce virtio feature VIRTIO_NET_F_TSTAMP. If negotiated, the > > virtio-net header is expanded with room for a timestamp. > > > > To get and set the hwtstamp the functions ndo_hwtstamp_set/get need > > to be implemented. This allows filtering the packets and only time stamp > > the packets where the filter matches. This way, the timestamping can > > be en/disabled at runtime. > > > > Tested: > > guest: ./timestamping eth0 \ > > SOF_TIMESTAMPING_RAW_HARDWARE \ > > SOF_TIMESTAMPING_RX_HARDWARE > > host: nc -4 -u 192.168.1.1 319 > > > > Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> > > > > -- > > Changes to last version: > > - rework series to use flow filters > > - add new struct virtio_net_hdr_v1_hash_tunnel_ts > > - original work done by: Willem de Bruijn <willemb@google.com> > > --- > > drivers/net/virtio_net.c | 136 ++++++++++++++++++++++++++++++++++++---- > > include/uapi/linux/virtio_net.h | 9 +++ > > 2 files changed, 133 insertions(+), 12 deletions(-) > > > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > > index 1bb3aeca66c6e..4e8d9b20c1b34 100644 > > --- a/drivers/net/virtio_net.c > > +++ b/drivers/net/virtio_net.c > > @@ -429,6 +429,9 @@ struct virtnet_info { > > struct virtio_net_rss_config_trailer rss_trailer; > > u8 rss_hash_key_data[VIRTIO_NET_RSS_MAX_KEY_SIZE]; > > > > + /* Device passes time stamps from the driver */ > > + bool has_tstamp; > > + > > /* Has control virtqueue */ > > bool has_cvq; > > > > @@ -475,6 +478,8 @@ struct virtnet_info { > > > > struct control_buf *ctrl; > > > > + struct kernel_hwtstamp_config tstamp_config; > > + > > /* Ethtool settings */ > > u8 duplex; > > u32 speed; > > @@ -511,6 +516,7 @@ struct virtio_net_common_hdr { > > struct virtio_net_hdr_mrg_rxbuf mrg_hdr; > > struct virtio_net_hdr_v1_hash hash_v1_hdr; > > struct virtio_net_hdr_v1_hash_tunnel tnl_hdr; > > + struct virtio_net_hdr_v1_hash_tunnel_ts ts_hdr; > > Jason, Michael: creating a new struct for every field is not very > elegant. Is it time to find a more forward looking approach to > expanding with new fields? Like a TLV, or how netlink structs like > tcp_info are extended with support for legacy users that only use > a truncated struct? I certainly wouldn't mind, though I suspect tlv is too complex as hardware implementations can't efficiently follow linked lists. I'll try to ping some hardware designers for what works well for offloads. > > }; > > }; > > > > @@ -682,6 +688,13 @@ skb_vnet_common_hdr(struct sk_buff *skb) > > return (struct virtio_net_common_hdr *)skb->cb; > > } > > > > +static inline struct virtio_net_hdr_v1_hash_tunnel_ts *skb_vnet_hdr_ts(struct sk_buff *skb) > > +{ > > + BUILD_BUG_ON(sizeof(struct virtio_net_hdr_v1_hash_tunnel_ts) > sizeof(skb->cb)); > > + > > + return (void *)skb->cb; > > +} > > + > > /* > > * private is used to chain pages for big packets, put the whole > > * most recent used list in the beginning for reuse > > @@ -2560,6 +2573,15 @@ virtio_net_hash_value(const struct virtio_net_hdr_v1_hash *hdr_hash) > > (__le16_to_cpu(hdr_hash->hash_value_hi) << 16); > > } > > > > +static inline u64 > > +virtio_net_tstamp_value(const struct virtio_net_hdr_v1_hash_tunnel_ts *hdr_hash_ts) > > +{ > > + return (u64)__le16_to_cpu(hdr_hash_ts->tstamp_0) | > > + ((u64)__le16_to_cpu(hdr_hash_ts->tstamp_1) << 16) | > > + ((u64)__le16_to_cpu(hdr_hash_ts->tstamp_2) << 32) | > > + ((u64)__le16_to_cpu(hdr_hash_ts->tstamp_3) << 48); > > +} > > + > > static void virtio_skb_set_hash(const struct virtio_net_hdr_v1_hash *hdr_hash, > > struct sk_buff *skb) > > { > > @@ -2589,6 +2611,18 @@ static void virtio_skb_set_hash(const struct virtio_net_hdr_v1_hash *hdr_hash, > > skb_set_hash(skb, virtio_net_hash_value(hdr_hash), rss_hash_type); > > } > > > > +static inline void virtnet_record_rx_tstamp(const struct virtnet_info *vi, > > + struct sk_buff *skb) > > +{ > > + struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb); > > + const struct virtio_net_hdr_v1_hash_tunnel_ts *h = skb_vnet_hdr_ts(skb); > > + u64 ts; > > + > > + ts = virtio_net_tstamp_value(h); > > + memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps)); > > + shhwtstamps->hwtstamp = ns_to_ktime(ts); > > +} > > + > > static void virtnet_receive_done(struct virtnet_info *vi, struct receive_queue *rq, > > struct sk_buff *skb, u8 flags) > > { > > @@ -2617,6 +2651,8 @@ static void virtnet_receive_done(struct virtnet_info *vi, struct receive_queue * > > goto frame_err; > > } > > > > + if (vi->has_tstamp && vi->tstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) > > + virtnet_record_rx_tstamp(vi, skb); > > skb_record_rx_queue(skb, vq2rxq(rq->vq)); > > skb->protocol = eth_type_trans(skb, dev); > > pr_debug("Receiving skb proto 0x%04x len %i type %i\n", > > @@ -3321,7 +3357,7 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb, bool orphan) > > { > > const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest; > > struct virtnet_info *vi = sq->vq->vdev->priv; > > - struct virtio_net_hdr_v1_hash_tunnel *hdr; > > + struct virtio_net_hdr_v1_hash_tunnel_ts *hdr; > > int num_sg; > > unsigned hdr_len = vi->hdr_len; > > bool can_push; > > @@ -3329,8 +3365,8 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb, bool orphan) > > pr_debug("%s: xmit %p %pM\n", vi->dev->name, skb, dest); > > > > /* Make sure it's safe to cast between formats */ > > - BUILD_BUG_ON(__alignof__(*hdr) != __alignof__(hdr->hash_hdr)); > > - BUILD_BUG_ON(__alignof__(*hdr) != __alignof__(hdr->hash_hdr.hdr)); > > + BUILD_BUG_ON(__alignof__(*hdr) != __alignof__(hdr->tnl.hash_hdr)); > > + BUILD_BUG_ON(__alignof__(*hdr) != __alignof__(hdr->tnl.hash_hdr.hdr)); > > > > can_push = vi->any_header_sg && > > !((unsigned long)skb->data & (__alignof__(*hdr) - 1)) && > > @@ -3338,18 +3374,18 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb, bool orphan) > > /* Even if we can, don't push here yet as this would skew > > * csum_start offset below. */ > > if (can_push) > > - hdr = (struct virtio_net_hdr_v1_hash_tunnel *)(skb->data - > > - hdr_len); > > + hdr = (struct virtio_net_hdr_v1_hash_tunnel_ts *)(skb->data - > > + hdr_len); > > else > > - hdr = &skb_vnet_common_hdr(skb)->tnl_hdr; > > + hdr = &skb_vnet_common_hdr(skb)->ts_hdr; > > > > - if (virtio_net_hdr_tnl_from_skb(skb, hdr, vi->tx_tnl, > > + if (virtio_net_hdr_tnl_from_skb(skb, &hdr->tnl, vi->tx_tnl, > > virtio_is_little_endian(vi->vdev), 0, > > false)) > > return -EPROTO; > > > > if (vi->mergeable_rx_bufs) > > - hdr->hash_hdr.hdr.num_buffers = 0; > > + hdr->tnl.hash_hdr.hdr.num_buffers = 0; > > > > sg_init_table(sq->sg, skb_shinfo(skb)->nr_frags + (can_push ? 1 : 2)); > > if (can_push) { > > @@ -5563,6 +5599,22 @@ static int virtnet_get_per_queue_coalesce(struct net_device *dev, > > return 0; > > } > > > > +static int virtnet_get_ts_info(struct net_device *dev, > > + struct kernel_ethtool_ts_info *info) > > +{ > > + /* setup default software timestamp */ > > + ethtool_op_get_ts_info(dev, info); > > + > > + info->rx_filters = (BIT(HWTSTAMP_FILTER_NONE) | > > + BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) | > > + BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) | > > + BIT(HWTSTAMP_FILTER_ALL)); > > + > > + info->tx_types = HWTSTAMP_TX_OFF; > > + > > + return 0; > > +} > > + > > static void virtnet_init_settings(struct net_device *dev) > > { > > struct virtnet_info *vi = netdev_priv(dev); > > @@ -5658,7 +5710,7 @@ static const struct ethtool_ops virtnet_ethtool_ops = { > > .get_ethtool_stats = virtnet_get_ethtool_stats, > > .set_channels = virtnet_set_channels, > > .get_channels = virtnet_get_channels, > > - .get_ts_info = ethtool_op_get_ts_info, > > + .get_ts_info = virtnet_get_ts_info, > > .get_link_ksettings = virtnet_get_link_ksettings, > > .set_link_ksettings = virtnet_set_link_ksettings, > > .set_coalesce = virtnet_set_coalesce, > > @@ -6242,6 +6294,58 @@ static void virtnet_tx_timeout(struct net_device *dev, unsigned int txqueue) > > jiffies_to_usecs(jiffies - READ_ONCE(txq->trans_start))); > > } > > > > +static int virtnet_hwtstamp_get(struct net_device *dev, > > + struct kernel_hwtstamp_config *tstamp_config) > > +{ > > + struct virtnet_info *vi = netdev_priv(dev); > > + > > + if (!netif_running(dev)) > > + return -EINVAL; > > + > > + *tstamp_config = vi->tstamp_config; > > + > > + return 0; > > +} > > + > > +static int virtnet_hwtstamp_set(struct net_device *dev, > > + struct kernel_hwtstamp_config *tstamp_config, > > + struct netlink_ext_ack *extack) > > +{ > > + struct virtnet_info *vi = netdev_priv(dev); > > + > > + if (!netif_running(dev)) > > + return -EINVAL; > > + > > + switch (tstamp_config->rx_filter) { > > + case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: > > + case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: > > + break; > > + case HWTSTAMP_FILTER_PTP_V2_EVENT: > > + case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: > > + case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: > > + case HWTSTAMP_FILTER_PTP_V2_SYNC: > > + case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: > > + case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: > > + case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: > > + case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: > > + case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: > > + tstamp_config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; > > + break; > > + case HWTSTAMP_FILTER_NONE: > > + break; > > + case HWTSTAMP_FILTER_ALL: > > + tstamp_config->rx_filter = HWTSTAMP_FILTER_ALL; > > + break; > > It's fine to implement filters, but also fine to only support ALL or > NONE for simplicity. > > In the end it probably depends on what the underlying physical device > supports. > > > + default: > > + tstamp_config->rx_filter = HWTSTAMP_FILTER_ALL; > > + return -ERANGE; > > + } > > + > > + vi->tstamp_config = *tstamp_config; > > + > > + return 0; > > +} > > + > > static int virtnet_init_irq_moder(struct virtnet_info *vi) > > { > > u8 profile_flags = 0, coal_flags = 0; > > @@ -6289,6 +6393,8 @@ static const struct net_device_ops virtnet_netdev = { > > .ndo_get_phys_port_name = virtnet_get_phys_port_name, > > .ndo_set_features = virtnet_set_features, > > .ndo_tx_timeout = virtnet_tx_timeout, > > + .ndo_hwtstamp_set = virtnet_hwtstamp_set, > > + .ndo_hwtstamp_get = virtnet_hwtstamp_get, > > }; > > > > static void virtnet_config_changed_work(struct work_struct *work) > > @@ -6911,6 +7017,9 @@ static int virtnet_probe(struct virtio_device *vdev) > > if (virtio_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT)) > > vi->has_rss_hash_report = true; > > > > + if (virtio_has_feature(vdev, VIRTIO_NET_F_TSTAMP)) > > + vi->has_tstamp = true; > > + > > if (virtio_has_feature(vdev, VIRTIO_NET_F_RSS)) { > > vi->has_rss = true; > > > > @@ -6945,8 +7054,10 @@ static int virtnet_probe(struct virtio_device *vdev) > > dev->xdp_metadata_ops = &virtnet_xdp_metadata_ops; > > } > > > > - if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO) || > > - virtio_has_feature(vdev, VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO)) > > + if (vi->has_tstamp) > > + vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash_tunnel_ts); > > + else if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO) || > > + virtio_has_feature(vdev, VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO)) > > vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash_tunnel); > > else if (vi->has_rss_hash_report) > > vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash); > > @@ -7269,7 +7380,8 @@ static struct virtio_device_id id_table[] = { > > VIRTIO_NET_F_SPEED_DUPLEX, VIRTIO_NET_F_STANDBY, \ > > VIRTIO_NET_F_RSS, VIRTIO_NET_F_HASH_REPORT, VIRTIO_NET_F_NOTF_COAL, \ > > VIRTIO_NET_F_VQ_NOTF_COAL, \ > > - VIRTIO_NET_F_GUEST_HDRLEN, VIRTIO_NET_F_DEVICE_STATS > > + VIRTIO_NET_F_GUEST_HDRLEN, VIRTIO_NET_F_DEVICE_STATS, \ > > + VIRTIO_NET_F_TSTAMP > > > > static unsigned int features[] = { > > VIRTNET_FEATURES, > > diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h > > index 1db45b01532b5..9f967575956b8 100644 > > --- a/include/uapi/linux/virtio_net.h > > +++ b/include/uapi/linux/virtio_net.h > > @@ -56,6 +56,7 @@ > > #define VIRTIO_NET_F_MQ 22 /* Device supports Receive Flow > > * Steering */ > > #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ > > +#define VIRTIO_NET_F_TSTAMP 49 /* Device sends TAI receive time */ > > #define VIRTIO_NET_F_DEVICE_STATS 50 /* Device can provide device-level statistics. */ > > #define VIRTIO_NET_F_VQ_NOTF_COAL 52 /* Device supports virtqueue notification coalescing */ > > #define VIRTIO_NET_F_NOTF_COAL 53 /* Device supports notifications coalescing */ > > @@ -215,6 +216,14 @@ struct virtio_net_hdr_v1_hash_tunnel { > > __le16 inner_nh_offset; > > }; > > > > +struct virtio_net_hdr_v1_hash_tunnel_ts { > > + struct virtio_net_hdr_v1_hash_tunnel tnl; > > + __le16 tstamp_0; > > + __le16 tstamp_1; > > + __le16 tstamp_2; > > + __le16 tstamp_3; > > +}; > > Why the multiple fields, rather than u64. > > More broadly: can my old patchset be dusted off as is. Does it require > significant changes? > > I only paused it at the time, because I did not have a real device > back-end that was going to support it. > > > + > > #ifndef VIRTIO_NET_NO_LEGACY > > /* This header comes first in the scatter-gather list. > > * For legacy virtio, if VIRTIO_F_ANY_LAYOUT is not negotiated, it must > > > > -- > > 2.52.0 > > > ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v2 2/2] virtio-net: support receive timestamp 2026-02-02 7:59 ` Michael S. Tsirkin @ 2026-02-02 17:40 ` Willem de Bruijn 0 siblings, 0 replies; 17+ messages in thread From: Willem de Bruijn @ 2026-02-02 17:40 UTC (permalink / raw) To: Michael S. Tsirkin, Willem de Bruijn Cc: Steffen Trumtrar, Jason Wang, Xuan Zhuo, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran, Andrew Lunn, Eugenio Pérez, virtualization, netdev, linux-kernel Michael S. Tsirkin wrote: > On Sun, Feb 01, 2026 at 04:05:54PM -0500, Willem de Bruijn wrote: > > Steffen Trumtrar wrote: > > > Add optional hardware rx timestamp offload for virtio-net. > > > > > > Introduce virtio feature VIRTIO_NET_F_TSTAMP. If negotiated, the > > > virtio-net header is expanded with room for a timestamp. > > > > > > To get and set the hwtstamp the functions ndo_hwtstamp_set/get need > > > to be implemented. This allows filtering the packets and only time stamp > > > the packets where the filter matches. This way, the timestamping can > > > be en/disabled at runtime. > > > > > > Tested: > > > guest: ./timestamping eth0 \ > > > SOF_TIMESTAMPING_RAW_HARDWARE \ > > > SOF_TIMESTAMPING_RX_HARDWARE > > > host: nc -4 -u 192.168.1.1 319 > > > > > > Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> > > > @@ -475,6 +478,8 @@ struct virtnet_info { > > > > > > struct control_buf *ctrl; > > > > > > + struct kernel_hwtstamp_config tstamp_config; > > > + > > > /* Ethtool settings */ > > > u8 duplex; > > > u32 speed; > > > @@ -511,6 +516,7 @@ struct virtio_net_common_hdr { > > > struct virtio_net_hdr_mrg_rxbuf mrg_hdr; > > > struct virtio_net_hdr_v1_hash hash_v1_hdr; > > > struct virtio_net_hdr_v1_hash_tunnel tnl_hdr; > > > + struct virtio_net_hdr_v1_hash_tunnel_ts ts_hdr; > > > > Jason, Michael: creating a new struct for every field is not very > > elegant. Is it time to find a more forward looking approach to > > expanding with new fields? Like a TLV, or how netlink structs like > > tcp_info are extended with support for legacy users that only use > > a truncated struct? > > I certainly wouldn't mind, though I suspect tlv is too complex as > hardware implementations can't efficiently follow linked lists. I'll > try to ping some hardware designers for what works well for offloads. Great thanks. Agreed that TLV was probably the wrong suggestion. We can definitely have a required order of fields. My initial thought is as said like many user/kernel structures: where both sides agree on the basic order of the struct, and pass along the length, so that they agree only to process the min of both their supported lengths. New fields are added at the tail of the struct. See for instance getsockopt TCP_INFO. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v2 2/2] virtio-net: support receive timestamp 2026-02-01 21:05 ` Willem de Bruijn 2026-02-02 7:34 ` Steffen Trumtrar 2026-02-02 7:59 ` Michael S. Tsirkin @ 2026-02-03 3:24 ` Jason Wang 2026-02-04 17:55 ` Willem de Bruijn 2 siblings, 1 reply; 17+ messages in thread From: Jason Wang @ 2026-02-03 3:24 UTC (permalink / raw) To: Willem de Bruijn Cc: Steffen Trumtrar, Michael S. Tsirkin, Xuan Zhuo, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran, Andrew Lunn, Eugenio Pérez, virtualization, netdev, linux-kernel On Mon, Feb 2, 2026 at 5:06 AM Willem de Bruijn <willemdebruijn.kernel@gmail.com> wrote: > > Steffen Trumtrar wrote: > > Add optional hardware rx timestamp offload for virtio-net. > > > > Introduce virtio feature VIRTIO_NET_F_TSTAMP. If negotiated, the > > virtio-net header is expanded with room for a timestamp. > > > > To get and set the hwtstamp the functions ndo_hwtstamp_set/get need > > to be implemented. This allows filtering the packets and only time stamp > > the packets where the filter matches. This way, the timestamping can > > be en/disabled at runtime. > > > > Tested: > > guest: ./timestamping eth0 \ > > SOF_TIMESTAMPING_RAW_HARDWARE \ > > SOF_TIMESTAMPING_RX_HARDWARE > > host: nc -4 -u 192.168.1.1 319 > > > > Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> > > > > -- > > Changes to last version: > > - rework series to use flow filters > > - add new struct virtio_net_hdr_v1_hash_tunnel_ts > > - original work done by: Willem de Bruijn <willemb@google.com> > > --- > > drivers/net/virtio_net.c | 136 ++++++++++++++++++++++++++++++++++++---- > > include/uapi/linux/virtio_net.h | 9 +++ > > 2 files changed, 133 insertions(+), 12 deletions(-) > > > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > > index 1bb3aeca66c6e..4e8d9b20c1b34 100644 > > --- a/drivers/net/virtio_net.c > > +++ b/drivers/net/virtio_net.c > > @@ -429,6 +429,9 @@ struct virtnet_info { > > struct virtio_net_rss_config_trailer rss_trailer; > > u8 rss_hash_key_data[VIRTIO_NET_RSS_MAX_KEY_SIZE]; > > > > + /* Device passes time stamps from the driver */ > > + bool has_tstamp; > > + > > /* Has control virtqueue */ > > bool has_cvq; > > > > @@ -475,6 +478,8 @@ struct virtnet_info { > > > > struct control_buf *ctrl; > > > > + struct kernel_hwtstamp_config tstamp_config; > > + > > /* Ethtool settings */ > > u8 duplex; > > u32 speed; > > @@ -511,6 +516,7 @@ struct virtio_net_common_hdr { > > struct virtio_net_hdr_mrg_rxbuf mrg_hdr; > > struct virtio_net_hdr_v1_hash hash_v1_hdr; > > struct virtio_net_hdr_v1_hash_tunnel tnl_hdr; > > + struct virtio_net_hdr_v1_hash_tunnel_ts ts_hdr; > > Jason, Michael: creating a new struct for every field is not very > elegant. Is it time to find a more forward looking approach to > expanding with new fields? Like a TLV, or how netlink structs like > tcp_info are extended with support for legacy users that only use > a truncated struct? I fully agree, we need somebody to work on this. Thanks ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v2 2/2] virtio-net: support receive timestamp 2026-02-03 3:24 ` Jason Wang @ 2026-02-04 17:55 ` Willem de Bruijn 2026-02-04 18:44 ` Michael S. Tsirkin 0 siblings, 1 reply; 17+ messages in thread From: Willem de Bruijn @ 2026-02-04 17:55 UTC (permalink / raw) To: Jason Wang, Willem de Bruijn Cc: Steffen Trumtrar, Michael S. Tsirkin, Xuan Zhuo, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran, Andrew Lunn, Eugenio Pérez, virtualization, netdev, linux-kernel Jason Wang wrote: > On Mon, Feb 2, 2026 at 5:06 AM Willem de Bruijn > <willemdebruijn.kernel@gmail.com> wrote: > > > > Steffen Trumtrar wrote: > > > Add optional hardware rx timestamp offload for virtio-net. > > > > > > Introduce virtio feature VIRTIO_NET_F_TSTAMP. If negotiated, the > > > virtio-net header is expanded with room for a timestamp. > > > > > > To get and set the hwtstamp the functions ndo_hwtstamp_set/get need > > > to be implemented. This allows filtering the packets and only time stamp > > > the packets where the filter matches. This way, the timestamping can > > > be en/disabled at runtime. > > > > > > Tested: > > > guest: ./timestamping eth0 \ > > > SOF_TIMESTAMPING_RAW_HARDWARE \ > > > SOF_TIMESTAMPING_RX_HARDWARE > > > host: nc -4 -u 192.168.1.1 319 > > > > > > Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> > > > > > > -- > > > Changes to last version: > > > - rework series to use flow filters > > > - add new struct virtio_net_hdr_v1_hash_tunnel_ts > > > - original work done by: Willem de Bruijn <willemb@google.com> > > > --- > > > drivers/net/virtio_net.c | 136 ++++++++++++++++++++++++++++++++++++---- > > > include/uapi/linux/virtio_net.h | 9 +++ > > > 2 files changed, 133 insertions(+), 12 deletions(-) > > > > > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > > > index 1bb3aeca66c6e..4e8d9b20c1b34 100644 > > > --- a/drivers/net/virtio_net.c > > > +++ b/drivers/net/virtio_net.c > > > @@ -429,6 +429,9 @@ struct virtnet_info { > > > struct virtio_net_rss_config_trailer rss_trailer; > > > u8 rss_hash_key_data[VIRTIO_NET_RSS_MAX_KEY_SIZE]; > > > > > > + /* Device passes time stamps from the driver */ > > > + bool has_tstamp; > > > + > > > /* Has control virtqueue */ > > > bool has_cvq; > > > > > > @@ -475,6 +478,8 @@ struct virtnet_info { > > > > > > struct control_buf *ctrl; > > > > > > + struct kernel_hwtstamp_config tstamp_config; > > > + > > > /* Ethtool settings */ > > > u8 duplex; > > > u32 speed; > > > @@ -511,6 +516,7 @@ struct virtio_net_common_hdr { > > > struct virtio_net_hdr_mrg_rxbuf mrg_hdr; > > > struct virtio_net_hdr_v1_hash hash_v1_hdr; > > > struct virtio_net_hdr_v1_hash_tunnel tnl_hdr; > > > + struct virtio_net_hdr_v1_hash_tunnel_ts ts_hdr; > > > > Jason, Michael: creating a new struct for every field is not very > > elegant. Is it time to find a more forward looking approach to > > expanding with new fields? Like a TLV, or how netlink structs like > > tcp_info are extended with support for legacy users that only use > > a truncated struct? > > I fully agree, we need somebody to work on this. Great. I'll take a look when I have some time. The current approach infers struct virtio_net_hdr_$VARIANT size from negotiated features: - virtio_net: virtio_has_feature - vhost_net: virtio_features_test_bit - tun: tun_vnet_parse_size Tuntap however also explicitly negotiates length with TUNSETVNETHDRSZ. If we create a struct virtio_net_hdr_ext that can be continuously extended going forward, the host and guest will have to negotiate the length they both understand, and agree to the min of the two. We could use that to implicitly negotiate supported features. E.g., if len is sizeof(virtio_net_hdr_v1_hash_tunnel) then these features are supported: VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO VIRTIO_NET_F_HASH_REPORT etc. But that would mean that all features up to the length have to be supported, no gaps. I think that is probably not preferable? So then they still need to negotiate features, as well as length. Does virtio have a mechanism to negotiate not boolean feature enable/disable but integers such as struct length? Else the change will probably be simpler: keep existing negotiation, only change the code to once define a struct and keep adding fields. Rather than defining new structs with each feature and updating many function arguments and variables to switch to the new struct type. Again, for that see as example struct tcp_info, which is UAPI, but has been extended many times. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v2 2/2] virtio-net: support receive timestamp 2026-02-04 17:55 ` Willem de Bruijn @ 2026-02-04 18:44 ` Michael S. Tsirkin 2026-02-05 2:52 ` Jason Wang 0 siblings, 1 reply; 17+ messages in thread From: Michael S. Tsirkin @ 2026-02-04 18:44 UTC (permalink / raw) To: Willem de Bruijn Cc: Jason Wang, Steffen Trumtrar, Xuan Zhuo, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran, Andrew Lunn, Eugenio Pérez, virtualization, netdev, linux-kernel On Wed, Feb 04, 2026 at 12:55:59PM -0500, Willem de Bruijn wrote: > Jason Wang wrote: > > On Mon, Feb 2, 2026 at 5:06 AM Willem de Bruijn > > <willemdebruijn.kernel@gmail.com> wrote: > > > > > > Steffen Trumtrar wrote: > > > > Add optional hardware rx timestamp offload for virtio-net. > > > > > > > > Introduce virtio feature VIRTIO_NET_F_TSTAMP. If negotiated, the > > > > virtio-net header is expanded with room for a timestamp. > > > > > > > > To get and set the hwtstamp the functions ndo_hwtstamp_set/get need > > > > to be implemented. This allows filtering the packets and only time stamp > > > > the packets where the filter matches. This way, the timestamping can > > > > be en/disabled at runtime. > > > > > > > > Tested: > > > > guest: ./timestamping eth0 \ > > > > SOF_TIMESTAMPING_RAW_HARDWARE \ > > > > SOF_TIMESTAMPING_RX_HARDWARE > > > > host: nc -4 -u 192.168.1.1 319 > > > > > > > > Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> > > > > > > > > -- > > > > Changes to last version: > > > > - rework series to use flow filters > > > > - add new struct virtio_net_hdr_v1_hash_tunnel_ts > > > > - original work done by: Willem de Bruijn <willemb@google.com> > > > > --- > > > > drivers/net/virtio_net.c | 136 ++++++++++++++++++++++++++++++++++++---- > > > > include/uapi/linux/virtio_net.h | 9 +++ > > > > 2 files changed, 133 insertions(+), 12 deletions(-) > > > > > > > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > > > > index 1bb3aeca66c6e..4e8d9b20c1b34 100644 > > > > --- a/drivers/net/virtio_net.c > > > > +++ b/drivers/net/virtio_net.c > > > > @@ -429,6 +429,9 @@ struct virtnet_info { > > > > struct virtio_net_rss_config_trailer rss_trailer; > > > > u8 rss_hash_key_data[VIRTIO_NET_RSS_MAX_KEY_SIZE]; > > > > > > > > + /* Device passes time stamps from the driver */ > > > > + bool has_tstamp; > > > > + > > > > /* Has control virtqueue */ > > > > bool has_cvq; > > > > > > > > @@ -475,6 +478,8 @@ struct virtnet_info { > > > > > > > > struct control_buf *ctrl; > > > > > > > > + struct kernel_hwtstamp_config tstamp_config; > > > > + > > > > /* Ethtool settings */ > > > > u8 duplex; > > > > u32 speed; > > > > @@ -511,6 +516,7 @@ struct virtio_net_common_hdr { > > > > struct virtio_net_hdr_mrg_rxbuf mrg_hdr; > > > > struct virtio_net_hdr_v1_hash hash_v1_hdr; > > > > struct virtio_net_hdr_v1_hash_tunnel tnl_hdr; > > > > + struct virtio_net_hdr_v1_hash_tunnel_ts ts_hdr; > > > > > > Jason, Michael: creating a new struct for every field is not very > > > elegant. Is it time to find a more forward looking approach to > > > expanding with new fields? Like a TLV, or how netlink structs like > > > tcp_info are extended with support for legacy users that only use > > > a truncated struct? > > > > I fully agree, we need somebody to work on this. > > Great. I'll take a look when I have some time. > > The current approach infers struct virtio_net_hdr_$VARIANT size from > negotiated features: > > - virtio_net: virtio_has_feature > - vhost_net: virtio_features_test_bit > - tun: tun_vnet_parse_size > > Tuntap however also explicitly negotiates length with TUNSETVNETHDRSZ. > > If we create a struct virtio_net_hdr_ext that can be continuously > extended going forward, the host and guest will have to negotiate the > length they both understand, and agree to the min of the two. > > We could use that to implicitly negotiate supported features. E.g., > if len is sizeof(virtio_net_hdr_v1_hash_tunnel) then these features > are supported: > > VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO > VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO > VIRTIO_NET_F_HASH_REPORT > etc. > > But that would mean that all features up to the length have to be > supported, no gaps. I think that is probably not preferable? So then > they still need to negotiate features, as well as length. Does virtio > have a mechanism to negotiate not boolean feature enable/disable but > integers such as struct length? > > Else the change will probably be simpler: keep existing negotiation, > only change the code to once define a struct and keep adding fields. > Rather than defining new structs with each feature and updating many > function arguments and variables to switch to the new struct type. Right I am not sure why we keep doing this. Let's add a VLA at the end of the struct and declare fields can be added at will. > Again, for that see as example struct tcp_info, which is UAPI, but has > been extended many times. -- MST ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v2 2/2] virtio-net: support receive timestamp 2026-02-04 18:44 ` Michael S. Tsirkin @ 2026-02-05 2:52 ` Jason Wang 0 siblings, 0 replies; 17+ messages in thread From: Jason Wang @ 2026-02-05 2:52 UTC (permalink / raw) To: Michael S. Tsirkin Cc: Willem de Bruijn, Steffen Trumtrar, Xuan Zhuo, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran, Andrew Lunn, Eugenio Pérez, virtualization, netdev, linux-kernel On Thu, Feb 5, 2026 at 2:44 AM Michael S. Tsirkin <mst@redhat.com> wrote: > > On Wed, Feb 04, 2026 at 12:55:59PM -0500, Willem de Bruijn wrote: > > Jason Wang wrote: > > > On Mon, Feb 2, 2026 at 5:06 AM Willem de Bruijn > > > <willemdebruijn.kernel@gmail.com> wrote: > > > > > > > > Steffen Trumtrar wrote: > > > > > Add optional hardware rx timestamp offload for virtio-net. > > > > > > > > > > Introduce virtio feature VIRTIO_NET_F_TSTAMP. If negotiated, the > > > > > virtio-net header is expanded with room for a timestamp. > > > > > > > > > > To get and set the hwtstamp the functions ndo_hwtstamp_set/get need > > > > > to be implemented. This allows filtering the packets and only time stamp > > > > > the packets where the filter matches. This way, the timestamping can > > > > > be en/disabled at runtime. > > > > > > > > > > Tested: > > > > > guest: ./timestamping eth0 \ > > > > > SOF_TIMESTAMPING_RAW_HARDWARE \ > > > > > SOF_TIMESTAMPING_RX_HARDWARE > > > > > host: nc -4 -u 192.168.1.1 319 > > > > > > > > > > Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> > > > > > > > > > > -- > > > > > Changes to last version: > > > > > - rework series to use flow filters > > > > > - add new struct virtio_net_hdr_v1_hash_tunnel_ts > > > > > - original work done by: Willem de Bruijn <willemb@google.com> > > > > > --- > > > > > drivers/net/virtio_net.c | 136 ++++++++++++++++++++++++++++++++++++---- > > > > > include/uapi/linux/virtio_net.h | 9 +++ > > > > > 2 files changed, 133 insertions(+), 12 deletions(-) > > > > > > > > > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > > > > > index 1bb3aeca66c6e..4e8d9b20c1b34 100644 > > > > > --- a/drivers/net/virtio_net.c > > > > > +++ b/drivers/net/virtio_net.c > > > > > @@ -429,6 +429,9 @@ struct virtnet_info { > > > > > struct virtio_net_rss_config_trailer rss_trailer; > > > > > u8 rss_hash_key_data[VIRTIO_NET_RSS_MAX_KEY_SIZE]; > > > > > > > > > > + /* Device passes time stamps from the driver */ > > > > > + bool has_tstamp; > > > > > + > > > > > /* Has control virtqueue */ > > > > > bool has_cvq; > > > > > > > > > > @@ -475,6 +478,8 @@ struct virtnet_info { > > > > > > > > > > struct control_buf *ctrl; > > > > > > > > > > + struct kernel_hwtstamp_config tstamp_config; > > > > > + > > > > > /* Ethtool settings */ > > > > > u8 duplex; > > > > > u32 speed; > > > > > @@ -511,6 +516,7 @@ struct virtio_net_common_hdr { > > > > > struct virtio_net_hdr_mrg_rxbuf mrg_hdr; > > > > > struct virtio_net_hdr_v1_hash hash_v1_hdr; > > > > > struct virtio_net_hdr_v1_hash_tunnel tnl_hdr; > > > > > + struct virtio_net_hdr_v1_hash_tunnel_ts ts_hdr; > > > > > > > > Jason, Michael: creating a new struct for every field is not very > > > > elegant. Is it time to find a more forward looking approach to > > > > expanding with new fields? Like a TLV, or how netlink structs like > > > > tcp_info are extended with support for legacy users that only use > > > > a truncated struct? > > > > > > I fully agree, we need somebody to work on this. > > > > Great. I'll take a look when I have some time. > > > > The current approach infers struct virtio_net_hdr_$VARIANT size from > > negotiated features: > > > > - virtio_net: virtio_has_feature > > - vhost_net: virtio_features_test_bit > > - tun: tun_vnet_parse_size > > > > Tuntap however also explicitly negotiates length with TUNSETVNETHDRSZ. > > > > If we create a struct virtio_net_hdr_ext that can be continuously > > extended going forward, the host and guest will have to negotiate the > > length they both understand, and agree to the min of the two. > > > > We could use that to implicitly negotiate supported features. E.g., > > if len is sizeof(virtio_net_hdr_v1_hash_tunnel) then these features > > are supported: > > > > VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO > > VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO > > VIRTIO_NET_F_HASH_REPORT > > etc. > > > > But that would mean that all features up to the length have to be > > supported, no gaps. I think that is probably not preferable? So then > > they still need to negotiate features, as well as length. Does virtio > > have a mechanism to negotiate not boolean feature enable/disable but > > integers such as struct length? I think not. > > > > Else the change will probably be simpler: keep existing negotiation, > > only change the code to once define a struct and keep adding fields. > > Rather than defining new structs with each feature and updating many > > function arguments and variables to switch to the new struct type. > > Right I am not sure why we keep doing this. Let's add a VLA at > the end of the struct and declare fields can be added at will. > > > > Again, for that see as example struct tcp_info, which is UAPI, but has > > been extended many times. > > Yes. Thanks > -- > MST > ^ permalink raw reply [flat|nested] 17+ messages in thread
* [syzbot ci] Re: virtio-net: add flow filter for receive timestamps 2026-01-29 8:06 [PATCH RFC v2 0/2] virtio-net: add flow filter for receive timestamps Steffen Trumtrar 2026-01-29 8:06 ` [PATCH RFC v2 1/2] tun: support rx-tstamp Steffen Trumtrar 2026-01-29 8:06 ` [PATCH RFC v2 2/2] virtio-net: support receive timestamp Steffen Trumtrar @ 2026-01-29 13:27 ` syzbot ci 2026-02-01 21:00 ` [PATCH RFC v2 0/2] " Willem de Bruijn 3 siblings, 0 replies; 17+ messages in thread From: syzbot ci @ 2026-01-29 13:27 UTC (permalink / raw) To: andrew, davem, edumazet, eperezma, jasowang, kuba, linux-kernel, mst, netdev, pabeni, richardcochran, s.trumtrar, virtualization, willemdebruijn.kernel, xuanzhuo Cc: syzbot, syzkaller-bugs syzbot ci has tested the following series [v2] virtio-net: add flow filter for receive timestamps https://lore.kernel.org/all/20260129-v6-7-topic-virtio-net-ptp-v2-0-30a27dc52760@pengutronix.de * [PATCH RFC v2 1/2] tun: support rx-tstamp * [PATCH RFC v2 2/2] virtio-net: support receive timestamp and found the following issue: WARNING in __copy_overflow Full report is available here: https://ci.syzbot.org/series/0b35c8c9-603b-4126-ac04-0095faadb2f5 *** WARNING in __copy_overflow tree: net-next URL: https://kernel.googlesource.com/pub/scm/linux/kernel/git/netdev/net-next.git base: ffeafa65b2b26df2f5b5a6118d3174f17bd12ec5 arch: amd64 compiler: Debian clang version 21.1.8 (++20251221033036+2078da43e25a-1~exp1~20251221153213.50), Debian LLD 21.1.8 config: https://ci.syzbot.org/builds/d8316da2-2688-4d74-bbf4-e8412e24d106/config C repro: https://ci.syzbot.org/findings/96af937a-787b-4fd5-baef-529fc80e0bb7/c_repro syz repro: https://ci.syzbot.org/findings/96af937a-787b-4fd5-baef-529fc80e0bb7/syz_repro ------------[ cut here ]------------ Buffer overflow detected (32 < 1840)! WARNING: mm/maccess.c:234 at __copy_overflow+0x17/0x30 mm/maccess.c:234, CPU#0: syz.0.17/5993 Modules linked in: CPU: 0 UID: 0 PID: 5993 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT(full) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 RIP: 0010:__copy_overflow+0x1c/0x30 mm/maccess.c:234 Code: 90 90 90 90 90 90 90 90 90 90 90 90 90 90 f3 0f 1e fa 55 53 48 89 f3 89 fd e8 60 b1 c4 ff 48 8d 3d 39 25 d5 0d 89 ee 48 89 da <67> 48 0f b9 3a 5b 5d c3 cc cc cc cc cc cc cc cc cc cc cc cc 90 90 RSP: 0018:ffffc90003b97888 EFLAGS: 00010293 RAX: ffffffff81fdcf50 RBX: 0000000000000730 RCX: ffff88810ccd9d40 RDX: 0000000000000730 RSI: 0000000000000020 RDI: ffffffff8fd2f490 RBP: 0000000000000020 R08: ffffffff8fcec777 R09: 1ffffffff1f9d8ee R10: dffffc0000000000 R11: ffffffff81742230 R12: dffffc0000000000 R13: 0000000000000000 R14: 0000000000000730 R15: 1ffff92000772f30 FS: 00007f08c446a6c0(0000) GS:ffff88818e32d000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f08c4448ff8 CR3: 000000010cec2000 CR4: 00000000000006f0 Call Trace: <TASK> copy_overflow include/linux/ucopysize.h:41 [inline] check_copy_size include/linux/ucopysize.h:50 [inline] copy_to_iter include/linux/uio.h:219 [inline] tun_put_user drivers/net/tun.c:2089 [inline] tun_do_read+0x1f44/0x28a0 drivers/net/tun.c:2190 tun_chr_read_iter+0x13b/0x260 drivers/net/tun.c:2214 do_iter_readv_writev+0x619/0x8c0 fs/read_write.c:-1 vfs_readv+0x288/0x840 fs/read_write.c:1018 do_readv+0x154/0x2e0 fs/read_write.c:1080 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xe2/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f08c359acb9 Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007f08c446a028 EFLAGS: 00000246 ORIG_RAX: 0000000000000013 RAX: ffffffffffffffda RBX: 00007f08c3815fa0 RCX: 00007f08c359acb9 RDX: 0000000000000002 RSI: 0000200000000080 RDI: 0000000000000003 RBP: 00007f08c3608bf7 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f08c3816038 R14: 00007f08c3815fa0 R15: 00007fff6491da78 </TASK> ---------------- Code disassembly (best guess): 0: 90 nop 1: 90 nop 2: 90 nop 3: 90 nop 4: 90 nop 5: 90 nop 6: 90 nop 7: 90 nop 8: 90 nop 9: 90 nop a: 90 nop b: 90 nop c: 90 nop d: 90 nop e: f3 0f 1e fa endbr64 12: 55 push %rbp 13: 53 push %rbx 14: 48 89 f3 mov %rsi,%rbx 17: 89 fd mov %edi,%ebp 19: e8 60 b1 c4 ff call 0xffc4b17e 1e: 48 8d 3d 39 25 d5 0d lea 0xdd52539(%rip),%rdi # 0xdd5255e 25: 89 ee mov %ebp,%esi 27: 48 89 da mov %rbx,%rdx * 2a: 67 48 0f b9 3a ud1 (%edx),%rdi <-- trapping instruction 2f: 5b pop %rbx 30: 5d pop %rbp 31: c3 ret 32: cc int3 33: cc int3 34: cc int3 35: cc int3 36: cc int3 37: cc int3 38: cc int3 39: cc int3 3a: cc int3 3b: cc int3 3c: cc int3 3d: cc int3 3e: 90 nop 3f: 90 nop *** If these findings have caused you to resend the series or submit a separate fix, please add the following tag to your commit message: Tested-by: syzbot@syzkaller.appspotmail.com --- This report is generated by a bot. It may contain errors. syzbot ci engineers can be reached at syzkaller@googlegroups.com. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v2 0/2] virtio-net: add flow filter for receive timestamps 2026-01-29 8:06 [PATCH RFC v2 0/2] virtio-net: add flow filter for receive timestamps Steffen Trumtrar ` (2 preceding siblings ...) 2026-01-29 13:27 ` [syzbot ci] Re: virtio-net: add flow filter for receive timestamps syzbot ci @ 2026-02-01 21:00 ` Willem de Bruijn 3 siblings, 0 replies; 17+ messages in thread From: Willem de Bruijn @ 2026-02-01 21:00 UTC (permalink / raw) To: Steffen Trumtrar, Michael S. Tsirkin, Jason Wang, Xuan Zhuo, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran, Willem de Bruijn, Andrew Lunn, Eugenio Pérez Cc: virtualization, netdev, linux-kernel, Steffen Trumtrar Steffen Trumtrar wrote: > This series tries to pick up the work on the virtio-net timestamping > feature from Willem de Bruijn. > > Original series > Message-Id: 20210208185558.995292-1-willemdebruijn.kernel@gmail.com > Subject: [PATCH RFC v2 0/4] virtio-net: add tx-hash, rx-tstamp, > tx-tstamp and tx-time > From: Willem de Bruijn <willemb@google.com> > > RFC for four new features to the virtio network device: > > 1. pass tx flow state to host, for routing + telemetry > 2. pass rx tstamp to guest, for better RTT estimation > 3. pass tx tstamp to guest, idem > 3. pass tx delivery time to host, for accurate pacing > > All would introduce an extension to the virtio spec. > > The changes in this series are to the driver side. For the changes to qemu see: > https://github.com/strumtrar/qemu/tree/v10.2.0/virtio-rx-stamps > > Currently only virtio-net is supported. Performance was tested with > pktgen which doesn't show a decrease in transfer speeds. > > As these patches are now mostly different from the initial patchset, I removed > the Signed-off-bys from Willem, so he mustn't be ashamed of what his work evolved to ;) Good to see this picked up. I would also still like to see support in virtio-net for HW timestamps pass-through for virtio-net. > Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> > --- > Changes in v2: > - rework patches to use flow filter instead of feature flag > - Link to v1: https://lore.kernel.org/r/20231218-v6-7-topic-virtio-net-ptp-v1-0-cac92b2d8532@pengutronix.de > > --- > Steffen Trumtrar (2): > tun: support rx-tstamp > virtio-net: support receive timestamp > > drivers/net/tun.c | 30 +++++---- > drivers/net/virtio_net.c | 136 ++++++++++++++++++++++++++++++++++++---- > include/uapi/linux/virtio_net.h | 9 +++ > 3 files changed, 151 insertions(+), 24 deletions(-) > --- > base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 > change-id: 20231218-v6-7-topic-virtio-net-ptp-3df023bc4f4d > > Best regards, > -- > Steffen Trumtrar <s.trumtrar@pengutronix.de> > ^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2026-02-05 2:52 UTC | newest] Thread overview: 17+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-01-29 8:06 [PATCH RFC v2 0/2] virtio-net: add flow filter for receive timestamps Steffen Trumtrar 2026-01-29 8:06 ` [PATCH RFC v2 1/2] tun: support rx-tstamp Steffen Trumtrar 2026-02-01 21:00 ` Willem de Bruijn 2026-01-29 8:06 ` [PATCH RFC v2 2/2] virtio-net: support receive timestamp Steffen Trumtrar 2026-01-29 9:48 ` Xuan Zhuo 2026-01-29 10:08 ` Steffen Trumtrar 2026-01-29 11:03 ` Xuan Zhuo 2026-02-01 21:05 ` Willem de Bruijn 2026-02-02 7:34 ` Steffen Trumtrar 2026-02-02 7:59 ` Michael S. Tsirkin 2026-02-02 17:40 ` Willem de Bruijn 2026-02-03 3:24 ` Jason Wang 2026-02-04 17:55 ` Willem de Bruijn 2026-02-04 18:44 ` Michael S. Tsirkin 2026-02-05 2:52 ` Jason Wang 2026-01-29 13:27 ` [syzbot ci] Re: virtio-net: add flow filter for receive timestamps syzbot ci 2026-02-01 21:00 ` [PATCH RFC v2 0/2] " Willem de Bruijn
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox