🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
11 messages
11 total messages Started by Steffen Trumtrar Thu, 12 Nov 2026 11:19
[PATCH net-next v5 0/9] virtio-net: add receive timestamp support
#15100
Author: Steffen Trumtrar
Date: Thu, 12 Nov 2026 11:19
113 lines
16302 bytes
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>
[PATCH net-next v5 1/9] net: ethtool: tsconfig: allow hardware timestamping without a PHC
#15112
Author: Steffen Trumtrar
Date: Thu, 12 Nov 2026 11:19
47 lines
12275 bytes
A driver can do hardware timestamping without a PTP hardware clock; its
get_ts_info() then reports hardware timestamping with phc_index -1.
ngbe and txgbe (libwx) do so when no PTP clock is registered, e.g. with
CONFIG_PTP_1588_CLOCK=n, and dpaa without a ptimer-handle.

SIOCGHWTSTAMP and SIOCSHWTSTAMP work for such a device, but
tsconfig_prepare_data() refuses it with -ENODEV:

 - TSCONFIG_GET fails.
 - TSCONFIG_SET passes the new config to ndo_hwtstamp_set() first and
   fails only when building the reply, so user space gets an error
   although the config was applied.
 - In a dump only -EOPNOTSUPP is skipped; the error ends the dump, and
   the devices after this one are not listed.

The reply already leaves out ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER when
the index is -1. Let tsconfig_prepare_data() take that path instead of
failing.

Fixes: 6e9e2eed4f39 ("net: ethtool: Add support for tsconfig command to get/set hwtstamp config")

Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
 net/ethtool/tsconfig.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/net/ethtool/tsconfig.c b/net/ethtool/tsconfig.c
index 2db0e7ba8b9f5..75f9b319aa310 100644
--- a/net/ethtool/tsconfig.c
+++ b/net/ethtool/tsconfig.c
@@ -73,11 +73,7 @@ static int tsconfig_prepare_data(const struct ethnl_req_info *req_base,
 		if (ret)
 			goto out;
 
-		if (ts_info.phc_index == -1) {
-			ret = -ENODEV;
-			goto out;
-		}
-
+		/* -1 without a PHC: the reply leaves out the provider */
 		data->hwprov_desc.index = ts_info.phc_index;
 		data->hwprov_desc.qualifier = ts_info.phc_qualifier;
 	}

-- 
2.56.0
[PATCH net-next v5 3/9] virtio-net: copy the XDP rx hash before the program runs
#15109
Author: Steffen Trumtrar
Date: Thu, 12 Nov 2026 11:19
213 lines
18025 bytes
virtnet_xdp_rx_hash() reads the hash from the vnet header at
xdp->data - vi->hdr_len when the XDP program calls
bpf_xdp_metadata_rx_hash(). That is only the header until the program
changes the buffer: bpf_xdp_adjust_meta() writes the metadata right in
front of xdp->data, over the header, and bpf_xdp_adjust_head() moves
xdp->data, so the callback then reads metadata or packet bytes.

Wrap struct xdp_buff in struct virtnet_xdp_buff, copy hash value and
report type into it in virtnet_xdp_handler() before
bpf_prog_run_xdp(), and let the callback read the copy. The small and
mergeable paths put the wrapper on the stack; for AF_XDP the fields are
in the cb of struct xdp_buff_xsk, checked with XSK_CHECK_PRIV_TYPE().

Move virtio_net_hash_value() up so the copy can use it.

Fixes: aa37f8916d20 ("virtio_net: Support RX hash XDP hint")
Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
 drivers/net/virtio_net.c | 86 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 58 insertions(+), 28 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 4c740b403ad1e..ffd7313663c18 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -491,6 +491,26 @@ struct padded_vnet_hdr {
 	char padding[12];
 };
 
+/*
+ * The vnet header sits in the headroom in front of xdp->data, which the
+ * XDP program may overwrite with bpf_xdp_adjust_head() or
+ * bpf_xdp_adjust_meta(). What the metadata kfuncs report is copied from
+ * it before the program runs. For AF_XDP the fields behind xdp live in
+ * the cb of struct xdp_buff_xsk.
+ */
+struct virtnet_xdp_buff {
+	struct xdp_buff xdp;
+	u32 hash_value;
+	u16 hash_report;
+};
+
+static inline u32
+virtio_net_hash_value(const struct virtio_net_hdr_v1_hash *hdr_hash)
+{
+	return __le16_to_cpu(hdr_hash->hash_value_lo) |
+		(__le16_to_cpu(hdr_hash->hash_value_hi) << 16);
+}
+
 struct virtio_net_common_hdr {
 	union {
 		struct virtio_net_hdr hdr;
@@ -1687,6 +1707,24 @@ static void put_xdp_frags(struct receive_queue *rq, struct xdp_buff *xdp)
 	}
 }
 
+/* xdp must be embedded in struct virtnet_xdp_buff or struct xdp_buff_xsk */
+static void virtnet_xdp_save_hdr(const struct virtnet_info *vi,
+				 struct xdp_buff *xdp)
+{
+	struct virtnet_xdp_buff *ctx = container_of(xdp, struct virtnet_xdp_buff, xdp);
+	const struct virtio_net_hdr_v1_hash *hdr_hash = xdp->data - vi->hdr_len;
+
+	XSK_CHECK_PRIV_TYPE(struct virtnet_xdp_buff);
+
+	if (vi->has_rss_hash_report) {
+		ctx->hash_value = virtio_net_hash_value(hdr_hash);
+		ctx->hash_report = __le16_to_cpu(hdr_hash->hash_report);
+	} else {
+		ctx->hash_value = 0;
+		ctx->hash_report = VIRTIO_NET_HASH_REPORT_NONE;
+	}
+}
+
 static int virtnet_xdp_handler(struct bpf_prog *xdp_prog, struct xdp_buff *xdp,
 			       struct net_device *dev,
 			       unsigned int *xdp_xmit,
@@ -1696,6 +1734,8 @@ static int virtnet_xdp_handler(struct bpf_prog *xdp_prog, struct xdp_buff *xdp,
 	int err;
 	u32 act;
 
+	virtnet_xdp_save_hdr(netdev_priv(dev), xdp);
+
 	act = bpf_prog_run_xdp(xdp_prog, xdp);
 	u64_stats_inc(&stats->xdp_packets);
 
@@ -1867,7 +1907,8 @@ static struct sk_buff *receive_small_xdp(struct net_device *dev,
 	struct virtio_net_hdr_mrg_rxbuf *hdr = buf + header_offset;
 	struct page *page = virt_to_head_page(buf);
 	struct page *xdp_page;
-	struct xdp_buff xdp;
+	struct virtnet_xdp_buff vxdp;
+	struct xdp_buff *xdp = &vxdp.xdp;
 	struct sk_buff *skb;
 	unsigned int metasize = 0;
 	u32 act;
@@ -1900,17 +1941,17 @@ static struct sk_buff *receive_small_xdp(struct net_device *dev,
 		page = xdp_page;
 	}
 
-	xdp_init_buff(&xdp, buflen, &rq->xdp_rxq);
-	xdp_prepare_buff(&xdp, buf + VIRTNET_RX_PAD + vi->hdr_len,
+	xdp_init_buff(xdp, buflen, &rq->xdp_rxq);
+	xdp_prepare_buff(xdp, buf + VIRTNET_RX_PAD + vi->hdr_len,
 			 xdp_headroom, len, true);
 
-	act = virtnet_xdp_handler(xdp_prog, &xdp, dev, xdp_xmit, stats);
+	act = virtnet_xdp_handler(xdp_prog, xdp, dev, xdp_xmit, stats);
 
 	switch (act) {
 	case XDP_PASS:
 		/* Recalculate length in case bpf program changed it */
-		len = xdp.data_end - xdp.data;
-		metasize = xdp.data - xdp.data_meta;
+		len = xdp->data_end - xdp->data;
+		metasize = xdp->data - xdp->data_meta;
 		break;
 
 	case XDP_TX:
@@ -1921,7 +1962,7 @@ static struct sk_buff *receive_small_xdp(struct net_device *dev,
 		goto err_xdp;
 	}
 
-	skb = virtnet_build_skb(buf, buflen, xdp.data - buf, len);
+	skb = virtnet_build_skb(buf, buflen, xdp->data - buf, len);
 	if (unlikely(!skb)) {
 		u64_stats_inc(&stats->alloc_fail);
 		goto err;
@@ -2288,7 +2329,8 @@ static struct sk_buff *receive_mergeable_xdp(struct net_device *dev,
 	unsigned int xdp_frags_truesz = 0;
 	struct sk_buff *head_skb;
 	unsigned int frame_sz;
-	struct xdp_buff xdp;
+	struct virtnet_xdp_buff vxdp;
+	struct xdp_buff *xdp = &vxdp.xdp;
 	void *data;
 	u32 act;
 	int err;
@@ -2298,16 +2340,16 @@ static struct sk_buff *receive_mergeable_xdp(struct net_device *dev,
 	if (unlikely(!data))
 		goto err_xdp;
 
-	err = virtnet_build_xdp_buff_mrg(dev, vi, rq, &xdp, data, len, frame_sz,
+	err = virtnet_build_xdp_buff_mrg(dev, vi, rq, xdp, data, len, frame_sz,
 					 &num_buf, &xdp_frags_truesz, stats);
 	if (unlikely(err))
 		goto err_xdp;
 
-	act = virtnet_xdp_handler(xdp_prog, &xdp, dev, xdp_xmit, stats);
+	act = virtnet_xdp_handler(xdp_prog, xdp, dev, xdp_xmit, stats);
 
 	switch (act) {
 	case XDP_PASS:
-		head_skb = build_skb_from_xdp_buff(dev, vi, &xdp, xdp_frags_truesz);
+		head_skb = build_skb_from_xdp_buff(dev, vi, xdp, xdp_frags_truesz);
 		if (unlikely(!head_skb)) {
 			u64_stats_inc(&stats->alloc_fail);
 			break;
@@ -2324,7 +2366,7 @@ static struct sk_buff *receive_mergeable_xdp(struct net_device *dev,
 		break;
 	}
 
-	put_xdp_frags(rq, &xdp);
+	put_xdp_frags(rq, xdp);
 
 err_xdp:
 	page_pool_put_page(rq->page_pool, page, -1, true);
@@ -2477,13 +2519,6 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 	return NULL;
 }
 
-static inline u32
-virtio_net_hash_value(const struct virtio_net_hdr_v1_hash *hdr_hash)
-{
-	return __le16_to_cpu(hdr_hash->hash_value_lo) |
-		(__le16_to_cpu(hdr_hash->hash_value_hi) << 16);
-}
-
 static void virtio_skb_set_hash(const struct virtio_net_hdr_v1_hash *hdr_hash,
 				struct sk_buff *skb)
 {
@@ -6760,23 +6795,18 @@ virtnet_xdp_rss_type[VIRTIO_NET_HASH_REPORT_MAX_TABLE] = {
 static int virtnet_xdp_rx_hash(const struct xdp_md *_ctx, u32 *hash,
 			       enum xdp_rss_hash_type *rss_type)
 {
-	const struct xdp_buff *xdp = (void *)_ctx;
-	struct virtio_net_hdr_v1_hash *hdr_hash;
-	struct virtnet_info *vi;
+	const struct virtnet_xdp_buff *ctx = (void *)_ctx;
 	u16 hash_report;
 
-	if (!(xdp->rxq->dev->features & NETIF_F_RXHASH))
+	if (!(ctx->xdp.rxq->dev->features & NETIF_F_RXHASH))
 		return -ENODATA;
 
-	vi = netdev_priv(xdp->rxq->dev);
-	hdr_hash = (struct virtio_net_hdr_v1_hash *)(xdp->data - vi->hdr_len);
-	hash_report = __le16_to_cpu(hdr_hash->hash_report);
-
+	hash_report = ctx->hash_report;
 	if (hash_report >= VIRTIO_NET_HASH_REPORT_MAX_TABLE)
 		hash_report = VIRTIO_NET_HASH_REPORT_NONE;
 
 	*rss_type = virtnet_xdp_rss_type[hash_report];
-	*hash = virtio_net_hash_value(hdr_hash);
+	*hash = ctx->hash_value;
 	return 0;
 }
 

-- 
2.56.0
[PATCH net-next v5 4/9] virtio-net: move virtio_net_common_hdr to virtio_net.h
#15113
Author: Steffen Trumtrar
Date: Thu, 12 Nov 2026 11:19
57 lines
12394 bytes
tun and vhost need to know the layout and size of the virtio-net
header as the driver uses it, e.g. to fill in fields behind
virtio_net_hdr_v1_hash_tunnel. Move struct virtio_net_common_hdr to
the kernel-internal header that they include already.

No functional change.

Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
 drivers/net/virtio_net.c   | 9 ---------
 include/linux/virtio_net.h | 9 +++++++++
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index ffd7313663c18..23e7f62a6ff64 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -511,15 +511,6 @@ virtio_net_hash_value(const struct virtio_net_hdr_v1_hash *hdr_hash)
 		(__le16_to_cpu(hdr_hash->hash_value_hi) << 16);
 }
 
-struct virtio_net_common_hdr {
-	union {
-		struct virtio_net_hdr 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;
-	};
-};
-
 static struct virtio_net_common_hdr xsk_hdr;
 
 static void virtnet_sq_free_unused_buf(struct virtqueue *vq, void *buf);
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index d6466f96cdd00..a6de308b8f25e 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -10,6 +10,15 @@
 #include <uapi/linux/tcp.h>
 #include <uapi/linux/virtio_net.h>
 
+struct virtio_net_common_hdr {
+	union {
+		struct virtio_net_hdr 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;
+	};
+};
+
 static inline bool virtio_net_hdr_match_proto(__be16 protocol, __u8 gso_type)
 {
 	switch (gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {

-- 
2.56.0
[PATCH net-next v5 6/9] virtio-net: assert header sizes
#15103
Author: Steffen Trumtrar
Date: Thu, 12 Nov 2026 11:19
35 lines
11859 bytes
The header is cast from skb->cb and from device buffers, so its layout
must not change silently. Add static_asserts for the offset of tstamp,
the total size, the alignment, and that the header fits into skb->cb.

Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
 include/linux/virtio_net.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index 2abd8a614a23f..e7776a37a486b 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -29,6 +29,17 @@ struct virtio_net_common_hdr {
 	__le16 tstamp[4];	/* le64 TAI receive time in ns, 0 if none */
 };
 
+/*
+ * The header is cast from skb->cb and from device buffers, the layout must not
+ * change silently.
+ */
+static_assert(offsetof(struct virtio_net_common_hdr, tstamp) == 32);
+static_assert(sizeof(struct virtio_net_common_hdr) ==
+	      offsetofend(struct virtio_net_common_hdr, tstamp));
+static_assert(__alignof__(struct virtio_net_common_hdr) == 2);
+/* virtio_net_common_hdr must fit into skb->cb */
+static_assert(sizeof(struct virtio_net_common_hdr) <= sizeof_field(struct sk_buff, cb));
+
 static inline bool virtio_net_hdr_match_proto(__be16 protocol, __u8 gso_type)
 {
 	switch (gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {

-- 
2.56.0
[PATCH net-next v5 7/9] vhost-net: support VIRTIO_NET_F_RX_TSTAMP
#15102
Author: Steffen Trumtrar
Date: Thu, 12 Nov 2026 11:19
80 lines
13547 bytes
Advertise VIRTIO_NET_F_RX_TSTAMP to userspace and size the vnet header
for it, so a guest can negotiate the feature with a vhost-net backed
tap device.

The header is 40 bytes if the feature is negotiated. Whoever writes
the header (tun, or vhost itself with VHOST_NET_F_VIRTIO_NET_HDR) has
to fill in the timestamp; vhost only reserves the room. If vhost
writes the header, it zeroes everything behind the fields it fills in
(num_buffers only with VIRTIO_F_VERSION_1 or VIRTIO_NET_F_MRG_RXBUF),
so the timestamp is 0, which the guest ignores.

Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
 drivers/vhost/net.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 435d8ed3851f3..1b171af105a22 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -77,7 +77,8 @@ static const int vhost_net_bits[] = {
 	VIRTIO_F_RING_RESET,
 	VIRTIO_F_IN_ORDER,
 	VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO,
-	VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO
+	VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO,
+	VIRTIO_NET_F_RX_TSTAMP
 };
 
 enum {
@@ -1166,6 +1167,7 @@ static void handle_rx(struct vhost_net *net)
 	s16 headcount;
 	size_t vhost_hlen, sock_hlen;
 	size_t vhost_len, sock_len;
+	size_t hdr_filled;
 	bool busyloop_intr = false;
 	bool set_num_buffers;
 	struct socket *sock;
@@ -1193,6 +1195,9 @@ static void handle_rx(struct vhost_net *net)
 	mergeable = vhost_has_feature(vq, VIRTIO_NET_F_MRG_RXBUF);
 	set_num_buffers = mergeable ||
 			  vhost_has_feature(vq, VIRTIO_F_VERSION_1);
+	/* Header bytes written below, if vhost supplies the header */
+	hdr_filled = sizeof(hdr) +
+		     (set_num_buffers ? sizeof(num_buffers) : 0);
 
 	do {
 		sock_len = vhost_net_rx_peek_head_len(net, sock->sk,
@@ -1278,6 +1283,16 @@ static void handle_rx(struct vhost_net *net)
 			vhost_discard_vq_desc(vq, headcount, ndesc);
 			goto out;
 		}
+		/* Zero the rest of a header supplied by vhost, e.g. tstamp */
+		if (unlikely(vhost_hlen > hdr_filled)) {
+			size_t rest = vhost_hlen - hdr_filled;
+
+			if (iov_iter_zero(rest, &fixup) != rest) {
+				vq_err(vq, "Failed vnet_hdr zeroing");
+				vhost_discard_vq_desc(vq, headcount, ndesc);
+				goto out;
+			}
+		}
 		nvq->done_idx += headcount;
 		count += in_order ? 1 : headcount;
 		if (nvq->done_idx > VHOST_NET_BATCH) {
@@ -1684,6 +1699,10 @@ static int vhost_net_set_features(struct vhost_net *n, const u64 *features)
 				     VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO))
 		hdr_len = sizeof(struct virtio_net_hdr_v1_hash_tunnel);
 
+	/* The header layout is cumulative, tstamp sits behind all other fields. */
+	if (virtio_features_test_bit(features, VIRTIO_NET_F_RX_TSTAMP))
+		hdr_len = offsetofend(struct virtio_net_common_hdr, tstamp);
+
 	if (virtio_features_test_bit(features, VHOST_NET_F_VIRTIO_NET_HDR)) {
 		/* vhost provides vnet_hdr */
 		vhost_hlen = hdr_len;

-- 
2.56.0
[PATCH net-next v5 8/9] virtio-net: add XDP rx timestamp metadata
#15108
Author: Steffen Trumtrar
Date: Thu, 12 Nov 2026 11:19
78 lines
13232 bytes
For the skb, the timestamp is read from the header before the XDP
program runs, so XDP_PASS keeps it even if the program changes the
packet. XDP therefore works with rx timestamping enabled.

Add xmo_rx_timestamp so XDP programs can read the timestamp with
bpf_xdp_metadata_rx_timestamp(). It returns -ENODATA if timestamping
is not enabled or the device did not timestamp the packet. Install the
metadata ops also if only VIRTIO_NET_F_RX_TSTAMP is negotiated;
rx_hash returns -ENODATA then.

Like the hash, the timestamp is copied into struct virtnet_xdp_buff
before the program runs, so the callback still works after the program
changed the headroom with bpf_xdp_adjust_head() or
bpf_xdp_adjust_meta().

Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
 drivers/net/virtio_net.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 57b7c32625dfb..46be686e34b79 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -511,6 +511,7 @@ struct virtnet_xdp_buff {
 	struct xdp_buff xdp;
 	u32 hash_value;
 	u16 hash_report;
+	u64 tstamp;
 };
 
 static inline u32
@@ -1736,6 +1737,8 @@ static void virtnet_xdp_save_hdr(const struct virtnet_info *vi,
 		ctx->hash_value = 0;
 		ctx->hash_report = VIRTIO_NET_HASH_REPORT_NONE;
 	}
+
+	ctx->tstamp = virtnet_record_rx_tstamp(vi, xdp->data - vi->hdr_len);
 }
 
 static int virtnet_xdp_handler(struct bpf_prog *xdp_prog, struct xdp_buff *xdp,
@@ -6896,8 +6899,21 @@ static int virtnet_xdp_rx_hash(const struct xdp_md *_ctx, u32 *hash,
 	return 0;
 }
 
+static int virtnet_xdp_rx_timestamp(const struct xdp_md *_ctx, u64 *timestamp)
+{
+	const struct virtnet_xdp_buff *ctx = (void *)_ctx;
+
+	/* 0: timestamping is off or the device did not timestamp the packet */
+	if (!ctx->tstamp)
+		return -ENODATA;
+
+	*timestamp = ctx->tstamp;
+	return 0;
+}
+
 static const struct xdp_metadata_ops virtnet_xdp_metadata_ops = {
 	.xmo_rx_hash			= virtnet_xdp_rx_hash,
+	.xmo_rx_timestamp		= virtnet_xdp_rx_timestamp,
 };
 
 static int virtnet_probe(struct virtio_device *vdev)
@@ -7063,6 +7079,10 @@ static int virtnet_probe(struct virtio_device *vdev)
 		dev->xdp_metadata_ops = &virtnet_xdp_metadata_ops;
 	}
 
+	/* rx_hash returns -ENODATA without NETIF_F_RXHASH */
+	if (vi->rx_tstamp_supported)
+		dev->xdp_metadata_ops = &virtnet_xdp_metadata_ops;
+
 	if (vi->rx_tstamp_supported)
 		vi->hdr_len = offsetofend(struct virtio_net_common_hdr, tstamp);
 	else if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO) ||

-- 
2.56.0
Re: [PATCH net-next v5 0/9] virtio-net: add receive timestamp support
#15129
Author: netdev-bot+sinfo
Date: Thu, 12 Nov 2026 11:26
18 lines
9281 bytes
Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account. If the series needs another revision for
other reasons, please include the information in the commit messages
then.

The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
Re: [PATCH net-next v5 7/9] vhost-net: support VIRTIO_NET_F_RX_TSTAMP
#17223
Author: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 13:55
143 lines
14034 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] vhost-net now always offers VIRTIO_NET_F_RX_TSTAMP ("Device
  sends TAI receive time") through VHOST_GET_FEATURES…
- [Medium] Sizing the vnet header to 40 bytes for VIRTIO_NET_F_RX_TSTAMP
  alone (vhost_net_set_features(), drivers/vhost/net.c:1702-1704) breaks…

--

vhost-net: support VIRTIO_NET_F_RX_TSTAMP

This commit advertises VIRTIO_NET_F_RX_TSTAMP from vhost-net and sizes the
vnet header to 40 bytes when the feature is negotiated. When vhost supplies
the header itself, everything behind the fields it fills in is zeroed, so
the timestamp is left at 0.

> diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
> index 435d8ed3851f3..1b171af105a22 100644
> --- a/drivers/vhost/net.c
> +++ b/drivers/vhost/net.c
> @@ -77,7 +77,8 @@ static const int vhost_net_bits[] = {
>  	VIRTIO_F_RING_RESET,
>  	VIRTIO_F_IN_ORDER,
>  	VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO,
> -	VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO
> +	VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO,
> +	VIRTIO_NET_F_RX_TSTAMP
>  };

[Severity: Medium]
Should VIRTIO_NET_F_RX_TSTAMP be offered unconditionally through
VHOST_GET_FEATURES when nothing in the RX path writes a timestamp?

With VHOST_NET_F_VIRTIO_NET_HDR, the new block in handle_rx() zeroes every
byte after hdr_filled, so tstamp is always 0:

    if (unlikely(vhost_hlen > hdr_filled)) {
        size_t rest = vhost_hlen - hdr_filled;

        if (iov_iter_zero(rest, &fixup) != rest) {

With a socket-supplied header, the commit message says tun fills in the
timestamp. But __tun_vnet_hdr_put() in drivers/net/tun_vnet.h copies only
tun_vnet_parse_size(features) bytes (10 or 24) and zeroes the rest:

    unsigned int parsed_size = tun_vnet_parse_size(features);
    ...
    if (iov_iter_zero(sz - parsed_size, iter) != sz - parsed_size)
        return -EFAULT;

tun.c, tap.c and tun_vnet.h don't reference tstamp at all.

The last patch in the series, "tun: add rx timestamp to the vnet header",
is labeled as not intended to be merged. Even with that patch applied, only
tun_put_user() fills in the timestamp. tun_put_user_xdp() and tap_put_user()
still go through tun_vnet_hdr_put() with a zero-initialized
virtio_net_common_hdr, so tstamp stays 0 on those paths.

On the guest side, negotiating the bit sets vi->rx_tstamp_supported.
virtnet_get_ts_info() then reports:

    if (vi->rx_tstamp_supported) {
        info->so_timestamping |=
            SOF_TIMESTAMPING_RX_HARDWARE |
            SOF_TIMESTAMPING_RAW_HARDWARE;

virtnet_hwtstamp_set() also accepts HWTSTAMP_FILTER_ALL. Since every
timestamp is 0, no skb ever gets a hwtstamp. A guest PTP stack that turns
on hardware RX timestamping because of the advertised capability will
never receive any timestamps.

Once the bit is in vhost_net_bits[] it is visible to userspace. Could the
feature be offered only when the attached backend can actually produce a
timestamp?

[ ... ]

> @@ -1684,6 +1699,10 @@ static int vhost_net_set_features(struct vhost_net *n, const u64 *features)
>  				     VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO))
>  		hdr_len = sizeof(struct virtio_net_hdr_v1_hash_tunnel);
>  
> +	/* The header layout is cumulative, tstamp sits behind all other fields. */
> +	if (virtio_features_test_bit(features, VIRTIO_NET_F_RX_TSTAMP))
> +		hdr_len = offsetofend(struct virtio_net_common_hdr, tstamp);
> +

[Severity: Medium]
Does a 40 byte header for RX_TSTAMP alone break the way tun guesses the
guest features?

tun_vnet_hdr_guest_features() in drivers/net/tun_vnet.h infers the tunnel
features from the header size:

    /*
     * Tun is not aware of the negotiated guest features, guess them from the
     * virtio net hdr size
     */
    static inline netdev_features_t tun_vnet_hdr_guest_features(int vnet_hdr_sz)
    {
        if (vnet_hdr_sz >= TUN_VNET_TNL_SIZE)
            return NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_UDP_TUNNEL_CSUM;
        return 0;
    }

Take socket-header mode with a guest that negotiates RX_TSTAMP but neither
HOST_UDP_TUNNEL_GSO nor GUEST_UDP_TUNNEL_GSO. It gets sock_hlen = 40, so
the tap's vnet_hdr_sz is 40. Both guest TX paths then treat the tunnel
features as negotiated:

    tun_get_user()
        features = tun_vnet_hdr_guest_features(vnet_hdr_sz);
        hdr_len = __tun_vnet_hdr_get(vnet_hdr_sz, tun->flags,
                                     features, from, gso);

    vhost_net_build_xdp() ... tun_sendmsg()->tun_xdp_one()
        features = tun_vnet_hdr_guest_features(READ_ONCE(tun->vnet_hdr_sz));
        ...
        tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, tnl_hdr)

This passes tnl_hdr_negotiated = true and tnl_csum_negotiated = true into
virtio_net_hdr_tnl_to_skb(). As a result, the -EINVAL check for a header
that asks for tunnel GSO without negotiating it is skipped. The
VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM check is skipped as well.

Could a guest then get UDP tunnel GSO packets, and the tunnel csum flag,
accepted by the host even when the VMM left host UDP tunnel GSO disabled?

Before this patch, only the tunnel features made the vhost-net header 24
bytes or larger, so the heuristic held. Nothing else in the series updates
tun.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-v6-7-topic-virtio-net-ptp-v5-0-7ab67b572f4f%40pengutronix.de
Re: [PATCH net-next v5 8/9] virtio-net: add XDP rx timestamp metadata
#17230
Author: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 13:55
101 lines
11941 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] virtnet_probe() now reports XDP rx-metadata capabilities the
  device does not have.

--

virtio-net: add XDP rx timestamp metadata

This adds an xmo_rx_timestamp callback to virtio-net, so XDP programs can
read the rx timestamp with bpf_xdp_metadata_rx_timestamp(). The timestamp
is copied into struct virtnet_xdp_buff before the program runs. The
metadata ops are now also installed when VIRTIO_NET_F_RX_TSTAMP is the
only one of these features negotiated.

> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 57b7c32625dfb..46be686e34b79 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c

[ ... ]

> @@ -6896,8 +6899,21 @@ static int virtnet_xdp_rx_hash(const struct xdp_md *_ctx, u32 *hash,

[ ... ]

>  static const struct xdp_metadata_ops virtnet_xdp_metadata_ops = {
>  	.xmo_rx_hash			= virtnet_xdp_rx_hash,
> +	.xmo_rx_timestamp		= virtnet_xdp_rx_timestamp,
>  };
>  
>  static int virtnet_probe(struct virtio_device *vdev)
> @@ -7063,6 +7079,10 @@ static int virtnet_probe(struct virtio_device *vdev)
>  		dev->xdp_metadata_ops = &virtnet_xdp_metadata_ops;
>  	}
>  
> +	/* rx_hash returns -ENODATA without NETIF_F_RXHASH */
> +	if (vi->rx_tstamp_supported)
> +		dev->xdp_metadata_ops = &virtnet_xdp_metadata_ops;
> +

[Severity: Medium]

virtnet_probe() installs the same virtnet_xdp_metadata_ops table in both
places. Does that change what netdev netlink reports for devices that
have only one of the two features?

netdev_nl_dev_fill() sets an xdp-rx-metadata-features bit for every
xmo_* pointer that is not NULL:

net/core/netdev-genl.c:netdev_nl_dev_fill() {
    ...
#define XDP_METADATA_KFUNC(_, flag, __, xmo) \
	if (netdev->xdp_metadata_ops && netdev->xdp_metadata_ops->xmo) \
		xdp_rx_meta |= flag;
    ...
}

Documentation/netlink/specs/netdev.yaml describes the timestamp bit as
"Device is capable of exposing receive HW timestamp via
bpf_xdp_metadata_rx_timestamp()".

Take an existing device that negotiates VIRTIO_NET_F_RSS or
VIRTIO_NET_F_HASH_REPORT, but not VIRTIO_NET_F_RX_TSTAMP. It still gets
the table from the has_rss || has_rss_hash_report block above. After this
patch, that table has xmo_rx_timestamp, so the device now reports the
timestamp capability.

Can such a device ever deliver a timestamp? virtnet_hwtstamp_set()
rejects the request:

	if (!vi->rx_tstamp_supported)
		return -EOPNOTSUPP;

So rx_tstamp_enabled stays false and virtnet_record_rx_tstamp() always
returns 0. As a result, virtnet_xdp_rx_timestamp() always returns
-ENODATA.

virtnet_get_ts_info() also does not set SOF_TIMESTAMPING_RX_HARDWARE in
this case. The ethtool and netdev netlink answers then disagree.

The opposite case is the one the new comment mentions. A device with only
VIRTIO_NET_F_RX_TSTAMP never gets NETIF_F_RXHASH. It now reports the hash
capability, but virtnet_xdp_rx_hash() always returns -ENODATA.

Would separate xdp_metadata_ops tables, chosen by which features were
negotiated, keep the reported bits accurate? The commit message covers
the rx_hash case, but not the change for existing RSS/hash-only devices.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-v6-7-topic-virtio-net-ptp-v5-0-7ab67b572f4f%40pengutronix.de
Re: [PATCH net-next v5 6/9] virtio-net: assert header sizes
#17454
Author: kernel test robot
Date: Mon, 16 Nov 2026 20:50
75 lines
14023 bytes
Hi Steffen,

kernel test robot noticed the following build errors:

[auto build test ERROR on c88fd6989aea9237a60a4859139a265bfb7ddc0b]

url:    https://github.com/intel-lab-lkp/linux/commits/Steffen-Trumtrar/net-ethtool-tsconfig-allow-hardware-timestamping-without-a-PHC/20261112-121933
base:   c88fd6989aea9237a60a4859139a265bfb7ddc0b
patch link:    https://lore.kernel.org/r/20261112-v6-7-topic-virtio-net-ptp-v5-6-7ab67b572f4f%40pengutronix.de
patch subject: [PATCH net-next v5 6/9] virtio-net: assert header sizes
config: arm-neponset_defconfig (https://download.01.org/0day-ci/archive/20261117/202611170421.klVDQaAD-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 16.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261117/202611170421.klVDQaAD-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202611170421.klVDQaAD-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from include/linux/bits.h:30,
                    from include/linux/bitops.h:6,
                    from include/linux/bitmap.h:8,
                    from include/linux/ethtool.h:16,
                    from net/packet/af_packet.c:51:
>> include/linux/build_bug.h:80:41: error: static assertion failed: "offsetof(struct virtio_net_common_hdr, tstamp) == 32"
      80 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
         |                                         ^~~~~~~~~~~~~~
   include/linux/build_bug.h:79:34: note: in expansion of macro '__static_assert'
      79 | #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
         |                                  ^~~~~~~~~~~~~~~
   include/linux/virtio_net.h:36:1: note: in expansion of macro 'static_assert'
      36 | static_assert(offsetof(struct virtio_net_common_hdr, tstamp) == 32);
         | ^~~~~~~~~~~~~
>> include/linux/build_bug.h:80:41: error: static assertion failed: "__alignof__(struct virtio_net_common_hdr) == 2"
      80 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
         |                                         ^~~~~~~~~~~~~~
   include/linux/build_bug.h:79:34: note: in expansion of macro '__static_assert'
      79 | #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
         |                                  ^~~~~~~~~~~~~~~
   include/linux/virtio_net.h:39:1: note: in expansion of macro 'static_assert'
      39 | static_assert(__alignof__(struct virtio_net_common_hdr) == 2);
         | ^~~~~~~~~~~~~


vim +80 include/linux/build_bug.h

bc6245e5efd70c4 Ian Abbott       2017-07-10  61  
6bab69c65013bed Rasmus Villemoes 2019-03-07  62  /**
6bab69c65013bed Rasmus Villemoes 2019-03-07  63   * static_assert - check integer constant expression at build time
6ffd853b0b10e1e Randy Dunlap     2026-03-01  64   * @expr: expression to be checked
6bab69c65013bed Rasmus Villemoes 2019-03-07  65   *
6bab69c65013bed Rasmus Villemoes 2019-03-07  66   * static_assert() is a wrapper for the C11 _Static_assert, with a
6bab69c65013bed Rasmus Villemoes 2019-03-07  67   * little macro magic to make the message optional (defaulting to the
6bab69c65013bed Rasmus Villemoes 2019-03-07  68   * stringification of the tested expression).
6bab69c65013bed Rasmus Villemoes 2019-03-07  69   *
6bab69c65013bed Rasmus Villemoes 2019-03-07  70   * Contrary to BUILD_BUG_ON(), static_assert() can be used at global
6bab69c65013bed Rasmus Villemoes 2019-03-07  71   * scope, but requires the expression to be an integer constant
6bab69c65013bed Rasmus Villemoes 2019-03-07  72   * expression (i.e., it is not enough that __builtin_constant_p() is
6bab69c65013bed Rasmus Villemoes 2019-03-07  73   * true for expr).
6bab69c65013bed Rasmus Villemoes 2019-03-07  74   *
6bab69c65013bed Rasmus Villemoes 2019-03-07  75   * Also note that BUILD_BUG_ON() fails the build if the condition is
6bab69c65013bed Rasmus Villemoes 2019-03-07  76   * true, while static_assert() fails the build if the expression is
6bab69c65013bed Rasmus Villemoes 2019-03-07  77   * false.
6bab69c65013bed Rasmus Villemoes 2019-03-07  78   */
6bab69c65013bed Rasmus Villemoes 2019-03-07  79  #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
6bab69c65013bed Rasmus Villemoes 2019-03-07 @80  #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
6bab69c65013bed Rasmus Villemoes 2019-03-07  81  
07a368b3f55a79d Maxim Levitsky   2022-10-25  82  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads