๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #17227

Re: [PATCH net-next v5 5/9] virtio-net: support receive timestamp

#17227
From: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 13:55
174 lines
15527 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 ยท High: 0 (1) ยท Medium: 1 ยท Low: 1

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] Feature bit and wire layout are chosen without citing the
  virtio spec.
- [Low] The feature bit is exported to userspace but the header layout it
  enables is not.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch
  extends it.

--

virtio-net: support receive timestamp

This adds a VIRTIO_NET_F_RX_TSTAMP feature (bit 49) to virtio-net. When
it is negotiated, the vnet header grows to 40 bytes and carries a le64 TAI
receive timestamp at offset 32, which is attached to skbs through
skb_hwtstamps(). Timestamping is switched on and off at runtime with
ndo_hwtstamp_get/set.

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

[ ... ]

> @@ -1324,7 +1344,9 @@ static void virtnet_receive_xsk_buf(struct virtnet_info *vi, struct receive_queu
>  		return;
>  	}
>  
> -	flags = ((struct virtio_net_common_hdr *)(xdp->data - vi->hdr_len))->hdr.flags;
> +	hdr = (struct virtio_net_common_hdr *)(xdp->data - vi->hdr_len);
> +	flags = hdr->hdr.flags;
> +	tstamp = virtnet_record_rx_tstamp(vi, hdr);

[Severity: High]
This is a pre-existing issue, but this patch adds a new read from the same
region. On the AF_XDP zero-copy path, is the vnet header in front of
xdp->data ever synced for the CPU?

virtnet_add_recvbuf_xsk() posts the descriptor hdr_len bytes before the xsk
DMA address:

	addr = xsk_buff_xdp_get_dma(xsk_buffs[i]) - vi->hdr_len;

buf_to_xdp() only calls xsk_buff_dma_sync_for_cpu(), which ends up in:

include/net/xsk_buff_pool.h:xp_dma_sync_for_cpu() {
	dma_sync_single_for_cpu(xskb->pool->dev, xskb->dma,
				xskb->pool->frame_len,
				DMA_BIDIRECTIONAL);
}

That range starts at xskb->dma, so it does not cover the hdr_len bytes the
device wrote in front of it.

Under swiotlb bouncing (for example SEV/TDX guests with
VIRTIO_F_ACCESS_PLATFORM, or swiotlb=force),
__swiotlb_sync_single_for_cpu() copies back only the synced range.
Non-coherent DMA has the same problem. In both cases the CPU reads stale
bytes from the umem page, and userspace or bpf_xdp_adjust_meta() may have
written those bytes.

virtnet_record_rx_tstamp() now reads hdr->tstamp from that region, and
virtnet_receive_done() reports the value through skb_hwtstamps(). Could a
stale or user-controlled value end up reported as the hardware timestamp?

The same gap already affects hdr->hdr.flags (VIRTIO_NET_HDR_F_DATA_VALID)
and num_buffers in virtnet_receive_xsk_merge(). If num_buffers reads as 0,
the while (--num_buf) loop in xsk_append_merge_buffer() wraps the u32, then
consumes and drops buffers that belong to the following packets.

Would syncing the header range too, starting at the posted address
(xskb->dma - vi->hdr_len), fix all of these?

[ ... ]

> diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
> index a6de308b8f25e..2abd8a614a23f 100644
> --- a/include/linux/virtio_net.h
> +++ b/include/linux/virtio_net.h
> @@ -17,6 +17,16 @@ struct virtio_net_common_hdr {
>  		struct virtio_net_hdr_v1_hash hash_v1_hdr;
>  		struct virtio_net_hdr_v1_hash_tunnel tnl_hdr;
>  	};
> +	/*
> +	 * The wire layout is fixed and cumulative: a field sits at the same
> +	 * offset whether or not the features before it were negotiated; unused
> +	 * bytes are padding. tstamp is thus always at offset 32 and only
> +	 * present (header size 40) if VIRTIO_NET_F_RX_TSTAMP was negotiated.
> +	 * The negotiated header size tells how much of this struct is
> +	 * on the wire. Only ever append new fields at the end.
> +	 */
> +	__u8 reserved[8];	/* outer_nh_offset, ipsec_resource_hdr (not implemented) */
> +	__le16 tstamp[4];	/* le64 TAI receive time in ns, 0 if none */
>  };

[Severity: Low]
Should this layout be exported in include/uapi/linux/virtio_net.h along
with the feature bit?

VIRTIO_NET_F_RX_TSTAMP is now in the uAPI header. The 40 byte layout it
turns on (reserved[8] at offset 24, le64 tstamp at offset 32) is defined
only in this kernel-internal struct. The earlier patch in the series,
"virtio-net: move virtio_net_common_hdr to virtio_net.h", moved it here,
and the series never adds a uAPI struct.

Other features that extend the header have exported wire structs. Examples
are struct virtio_net_hdr_v1_hash for VIRTIO_NET_F_HASH_REPORT and struct
virtio_net_hdr_v1_hash_tunnel for the UDP tunnel GSO bits.

Device implementations that import the uAPI header (QEMU standard-headers,
vhost-user and DPDK backends) get the bit but no definition of the offset
and size they have to produce.

reserved[] stands in for outer_nh_offset and ipsec_resource_hdr, and
neither field is in the uAPI. The cumulative layout claim therefore can't
be checked against any exported definition.

> diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h
> index 1db45b01532b5..15e8e408d50fb 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_RX_TSTAMP	  49	/* Device sends TAI receive time */

[Severity: Medium]
Is bit 49, and this header layout, reserved in the virtio spec?

The commit message does not reference an OASIS virtio-comment change. The
only device it was tested with is "a patched QEMU". The tun patch in this
series says it is "not intended to be merged" and links an out-of-tree QEMU
branch.

A gap in this header doesn't mean a bit is free in the spec. Bit 51 is also
unassigned here, and bits 46/47 are already reused as
VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO_MAPPED and
VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO_CSUM_MAPPED. Willem de Bruijn's earlier
timestamp work used bits that the spec later gave to USO and notification
coalescing.

Placing the timestamp at offset 32 also relies on outer_nh_offset and
ipsec_resource_hdr, which are not implemented here.

Suppose the spec gives bit 49, or the timestamp offset, to something else.
A device offering bit 49 would then make virtnet_probe() choose:

	if (vi->rx_tstamp_supported)
		vi->hdr_len = offsetofend(struct virtio_net_common_hdr, tstamp);

for both RX and TX. RX would strip the wrong number of bytes, TX would send
a header of the wrong size, and unrelated bytes would be reported as
hardware timestamps.

The vhost-net patch later in the series also advertises the bit to
userspace. That would make it negotiated ABI as soon as this is merged.

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-v6-7-topic-virtio-net-ptp-v5-0-7ab67b572f4f%40pengutronix.de
Technical Details
Message-ID: <179483730496.3136.1220905083498568586@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer05.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364394-linux-kernel-netdev=dewy.ru
References: <20261112-v6-7-topic-virtio-net-ptp-v5-5-7ab67b572f4f@pengutronix.de>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer05.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364394-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v5 5/9] virtio-net: support receive timestamp
Date: Mon, 16 Nov 2026 13:55:04 +0000
Organization: Usenet Network
Message-ID: <179483730496.3136.1220905083498568586@kernel.org>
References: <20261112-v6-7-topic-virtio-net-ptp-v5-5-7ab67b572f4f@pengutronix.de>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network; logging-data="2079554"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:jMnC1tohIjgndLFwFcNxvoTeYMA= sha256:PqDFN8h3JctKzUMixPYhwp8QwLtQC4lh+W+9A39Q+0Y= sha1:LjUOiKh+BbgRXleGqM1ex6eaQQ4= sha256:5bj31D2GOr9zEaWGonbjKnj2aE5hbAq0YjG1CDz5Jcc=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id D6338114C5F; Mon, 16 Nov 2026 16:57:26 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jikxF-8rtsoN; Mon, 16 Nov 2026 16:57:23 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-364394-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id A3245114C5D; Mon, 16 Nov 2026 16:57:14 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 9886A3200C; Mon, 16 Nov 2026 13:56:23 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794837313; b=y5sT1nm0CuaUc11UA/S3z7ZdlKybPU5eBhHj+eY4/m4R9PKZDS4NlEvXFizkVmUunWaB VdhQy7t+mnfnPHDVsYsicOuSYDhoNf9JhUiXh+cdU4f0UqBSN+n/w67057O7M0l/SR62N +uEVjwirgYAht1eQNzT66njPz0T3owuGXzCgkPcWIV6RYXe6QKKvAxab1hRPiM4OE3rDy y7ZRpu06hFu+ifmRLuCMtkm7r64dMmqCiOHvbEOYWEr8ZcTZeXmPVpxBiA8pta9MOu1I7 /XtKJD3Ilr2rvRgHeUzrDJ43IfrM8Kq1zghRB1K3XWibjJ/n0sXCrQOmK+upBuvhWgQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794837313; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=dJmBvsHxmFsY/NHiTygrkfChS2jWEf5KeHz33qzwJMI=; b=dzyKcgiM0MxaISxbDWPllTNNncLurGDPcQ10EHskotGYxBjNwBWhpiZRcSZDSbzTM6K3 qL7/OwLfx3GbDWl5Jm3n1mO206g7nB3DbA5UNGCJ6ROGcFOhpGGUNXEreAnl63munNOzs cmZ9dsQjCLQ5dO5wvxJqU49mZpCN38smX7a3EatgKwPPtcSgFAtwhsmI+/kH+S/FDeexg D4LIbo6JZNnIXYSmGDRkfqTzaPodfP25NtDOA/iexuLsYWMIdpEowIolakIwLY6+E6Z5q o/MQDyDAKZrKBosGH8J/uliPZmDJvzpmMPOMGPmhbkQ7OWh+rqR1lp7Uqnsax7cjZeA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=me975jvN; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 42B7360A5BCB; Mon, 16 Nov 2026 13:55:13 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=me975jvN
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794837307; b=u5Zka2GM0oV28ocVWsP571yZFj5Mz4Uc4t233dr1Bk0UgLUVgQUv2FfuWWsY/ukbpeIy p8Cly9yaK6NUR4zwpnZbB3JmkiyyqZrhZpaPuJ84jlaVZy4hixs/bt5PtCuqzGE1PbT4f Wjq+wHHbmsnbmxvoXwxTttyozd8GOCwqDu7rLyqNxeBFQDgTdIQ9UZgTjnhdo2ZEZ9WnD svphjOHi9mU2ExnPuH01NDQ1fTB8LHr35eNWv+aoq41Vv0tlJr+VmfPg9onBcuWxGQZRj G2w+fkhneyKpq8A6E+9lO7HOaF7tp11NzgVi2XvVKfaudCZj1UPrKLmLH7lMmch45rQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794837307; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=dJmBvsHxmFsY/NHiTygrkfChS2jWEf5KeHz33qzwJMI=; b=H+JvxtuekTTEvTBxp8ENIuWmQu0jBcDZ4cOHb+RhbQiR9OVahGP14/QqYKHed0jSj8Oo 3x6OhnS2yjL8nHE26LZ831Z4trFAlxVIlYeNUF+NgyKNWZprtuQF+9lTGSWY+iIw3KZqi Hb7HjrK12b1ZxSdMSyw9h1+vg5IuJTgqBBe4w5B8VLD4CLFSSEl779Rz7b/Qayc6IoIM1 swhBUuLfsOeI6kh6WMhGiN4qagUij95duQgn8v26siswIrAfHP4LxMjWx7XX7xm4Qu7Qh rOU2lSoD+9/f6MhTdfMgHLSbDNi6o912me3y2/XaymLBW3EdqT5sJLlIu+tN9prBN/w==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=me975jvN; arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6343C606D54B; Mon, 16 Nov 2026 13:55:07 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E7861F000C5; Mon, 16 Nov 2026 13:55:05 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794837307; bh=dJmBvsHxmFsY/NHiTygrkfChS2jWEf5KeHz33qzwJMI=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=me975jvNDmUmvwA6FWFpPXMGtDNyifM8vZozlY5X4jl0OSAHXR6uPZshnPbXAMvHn 61ZpD4PP5BnE1LbiNwqUrhOsOkbAyF03vztminGJrZ7B9uFUBhK0M0EfiKFJsk0jWX CJB+gzcO0HGSWHsbX7aoCVDKUaMHUt4W69ybxpOvaYsE1DQXLRem7xNl94hC+UBTRv lyu6tXVPYA16TG1iD14X1JJai/Ez23xjubdXaXxp+007uwYB2N9/6wbuMoLVvnLq8y /NUWuSKl2PmAgOXiC+J1qO/g8ppmiAW0ARPUiHln+emknOLP6HOFQkbH7fZQkQJdGT xF3RLMRvN6tog==
X-Cc: mst@redhat.com, xuanzhuo@linux.alibaba.com, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, richardcochran@gmail.com, willemdebruijn.kernel@gmail.com, andrew+netdev@lunn.ch, eperezma@redhat.com, jasowangio@gmail.com, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, sdf@fomichev.me, edumazet@kernel.org, andrew@lunn.ch, horms@kernel.org, kory.maincent@bootlin.com, liangchen.linux@gmail.com, hengqi@linux.alibaba.com, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, kvm@vger.kernel.org, kernel@pengutronix.de
X-In-Reply-To: <20261112-v6-7-topic-virtio-net-ptp-v5-5-7ab67b572f4f@pengutronix.de>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-Received-Bytes: 15241