Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v5 0/9] virtio-net: add receive timestamp support
@ 2026-11-12 11:19 Steffen Trumtrar
  2026-11-12 11:19 ` [PATCH net-next v5 1/9] net: ethtool: tsconfig: allow hardware timestamping without a PHC Steffen Trumtrar
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Steffen Trumtrar @ 2026-11-12 11:19 UTC (permalink / raw)
  To: Michael S. Tsirkin, Xuan Zhuo, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Richard Cochran, Willem de Bruijn, Andrew Lunn,
	Eugenio Pérez, Jason Wang, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
	Stanislav Fomichev, Eric Dumazet, Andrew Lunn, Simon Horman,
	Kory Maincent, Liang Chen, Heng Qi
  Cc: virtualization, netdev, linux-kernel, bpf, kvm, kernel,
	Steffen Trumtrar

This series picks up Willem de Bruijn's work on a virtio-net receive
timestamp. The device puts the time of arrival (TAI, ns) into the virtio-net
header so the guest can use it for PTP and RTT estimation without
taking the timestamp itself after the host-to-guest latency.

In detail, with the points that are still open:

 - The timestamp is a new field at the end of virtio_net_common_hdr
   after outer_nh_offset and ipsec, offset 32 (see virtio spec),
   negotiated with VIRTIO_NET_F_RX_TSTAMP (bit 49). Header size now 40
   bytes.
   Willem noted on v3 that virtio_net_common_hdr was not meant to be
   extended this way; I kept it as the simplest approach, but a
   separate struct for the timestamp header is an option.
 - Timestamping is enabled at runtime with SIOCSHWTSTAMP; all
   supported rx filters behave the same for now.
 - XDP programs can read the timestamp with
   bpf_xdp_metadata_rx_timestamp().
 - vhost-net passes the feature through; the timestamp itself is
   written by tun, the device side in software.
 - The timestamp is in TAI. On v4 Willem and I discussed whether the
   spec should fix the time base at all. Fixing it to TAI is the
   simplest: a software device like tun can convert its own clock, and
   the guest needs nothing else. The driver reports the timestamp as
   SOF_TIMESTAMPING_RAW_HARDWARE without a PTP clock (phc_index -1).
   For hardware virtio-net queues, which may not be able to convert,
   the model of NIC timestamps and their PHC would fit better: the
   device names a clock (e.g. a virtio_rtc clock, whose PHC the driver
   reports) or virtio-net gets a PHC of its own. That needs consensus
   on the virtio side; Which way would you prefer?
 - With phc_index -1, ETHTOOL_MSG_TSCONFIG_GET and _SET fail with
   -ENODEV (SET after the config was already applied). Other drivers
   with hardware timestamps but no PHC have the same problem
   (ngbe/txgbe, dpaa); patch 1 lets tsconfig handle phc_index -1.

Patches 1 to 3 fix existing code and do not depend on the rest:
tsconfig refused devices with hardware timestamps but no PHC, the tx
header was not fully cleared, and the XDP rx hash was read from the
headroom after the XDP program could have overwritten it. They can go
to net on their own if preferred.

A virtio spec change is needed as well and not yet proposed.

Testing: the feature needs a QEMU that knows VIRTIO_NET_F_RX_TSTAMP and
sets the matching vnet header size; see
https://github.com/strumtrar/qemu/tree/v11.0.1/virtio-rx-stamps
Each patch builds with W=1 on arm64 on top of net-next.

Tools: this version was developed with an LLM coding assistant (Claude
Opus 5.5 in Claude Code). From the review of v4 (Willem's and the
Sashiko findings) it wrote patches 1 to 3, the xdp_buff wrapper and
the other changes listed below, and drafts of the commit messages and
of this cover letter.
v4 carried Assisted-by tags; after commit 1e035297ffda ("docs: remove
Assisted-by references") this is said here instead.

Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
Changes in v5:
- new patch: let tsconfig handle devices without a PHC
- new patch: clear the whole tx header in xmit_skb()
- new patch: copy the XDP rx hash into a wrapper around xdp_buff
  before the XDP program runs
- use the same wrapper for the XDP rx timestamp
- rename has_rx_tstamp/hwts_rx_en to rx_tstamp_supported/rx_tstamp_enabled
- add VIRTIO_NET_F_RX_TSTAMP to features[] only, not to features_legacy[]
- vhost: zero the rest of the header also when num_buffers is not written
- timestamp stays TAI, open question for the virtio side in the cover letter
- drop the performance numbers from the cover letter
- drop the Assisted-by tags, tool use is described in the cover letter
- send as PATCH, no longer RFC
- rebase onto net-next/main 20261112
- Link to v4: https://patch.msgid.link/20261026-v6-7-topic-virtio-net-ptp-v4-0-008af03cd43b@pengutronix.de
Changes in v4:
- add static_asserts for header sizes
- rework hdr_len handling
- add support in vhost
- fix/add support for xdp
- Link to v3: https://patch.msgid.link/20260921-v6-7-topic-virtio-net-ptp-v3-0-3350851c4f88@pengutronix.de
Changes in v3:
- rework to use virtio_net_common_hdr instead of adding new struct
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 (9):
      net: ethtool: tsconfig: allow hardware timestamping without a PHC
      virtio-net: zero the whole tx header
      virtio-net: copy the XDP rx hash before the program runs
      virtio-net: move virtio_net_common_hdr to virtio_net.h
      virtio-net: support receive timestamp
      virtio-net: assert header sizes
      vhost-net: support VIRTIO_NET_F_RX_TSTAMP
      virtio-net: add XDP rx timestamp metadata
      tun: add rx timestamp to the vnet header

 drivers/net/tun.c               |  14 ++-
 drivers/net/tun_vnet.h          |  18 ++-
 drivers/net/virtio_net.c        | 250 +++++++++++++++++++++++++++++++---------
 drivers/vhost/net.c             |  21 +++-
 include/linux/virtio_net.h      |  30 +++++
 include/uapi/linux/virtio_net.h |   1 +
 net/ethtool/tsconfig.c          |   6 +-
 7 files changed, 270 insertions(+), 70 deletions(-)
---
base-commit: c88fd6989aea9237a60a4859139a265bfb7ddc0b
change-id: 20231218-v6-7-topic-virtio-net-ptp-3df023bc4f4d

Best regards,
--  
Steffen Trumtrar <s.trumtrar@pengutronix.de>


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

end of thread, other threads:[~2026-11-12 11:26 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 11:19 [PATCH net-next v5 0/9] virtio-net: add receive timestamp support Steffen Trumtrar
2026-11-12 11:19 ` [PATCH net-next v5 1/9] net: ethtool: tsconfig: allow hardware timestamping without a PHC Steffen Trumtrar
2026-11-12 11:19 ` [PATCH net-next v5 2/9] virtio-net: zero the whole tx header Steffen Trumtrar
2026-11-12 11:19 ` [PATCH net-next v5 3/9] virtio-net: copy the XDP rx hash before the program runs Steffen Trumtrar
2026-11-12 11:19 ` [PATCH net-next v5 4/9] virtio-net: move virtio_net_common_hdr to virtio_net.h Steffen Trumtrar
2026-11-12 11:19 ` [PATCH net-next v5 5/9] virtio-net: support receive timestamp Steffen Trumtrar
2026-11-12 11:19 ` [PATCH net-next v5 6/9] virtio-net: assert header sizes Steffen Trumtrar
2026-11-12 11:19 ` [PATCH net-next v5 7/9] vhost-net: support VIRTIO_NET_F_RX_TSTAMP Steffen Trumtrar
2026-11-12 11:19 ` [PATCH net-next v5 8/9] virtio-net: add XDP rx timestamp metadata Steffen Trumtrar
2026-11-12 11:19 ` [PATCH net-next v5 9/9] tun: add rx timestamp to the vnet header Steffen Trumtrar
2026-11-12 11:26 ` [PATCH net-next v5 0/9] virtio-net: add receive timestamp support netdev-bot+sinfo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox