mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: s.trumtrar@pengutronix.de
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
Subject: Re: [PATCH net-next v5 7/9] vhost-net: support VIRTIO_NET_F_RX_TSTAMP
Date: Mon, 16 Nov 2026 13:55:07 +0000	[thread overview]
Message-ID: <179483730723.3136.9748134612882994107@kernel.org> (raw)
In-Reply-To: <20261112-v6-7-topic-virtio-net-ptp-v5-7-7ab67b572f4f@pengutronix.de>

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

  reply	other threads:[~2026-11-16 13:55 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-16 13:55   ` netdev-bot+sashiko
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-16 13:55   ` netdev-bot+sashiko
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-16 13:55   ` netdev-bot+sashiko [this message]
2026-11-12 11:19 ` [PATCH net-next v5 8/9] virtio-net: add XDP rx timestamp metadata Steffen Trumtrar
2026-11-16 13:55   ` netdev-bot+sashiko
2026-11-12 11:19 ` [PATCH net-next v5 9/9] tun: add rx timestamp to the vnet header Steffen Trumtrar
2026-11-16 13:55   ` netdev-bot+sashiko
2026-11-12 11:26 ` [PATCH net-next v5 0/9] virtio-net: add receive timestamp support netdev-bot+sinfo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179483730723.3136.9748134612882994107@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrew@lunn.ch \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=eperezma@redhat.com \
    --cc=hawk@kernel.org \
    --cc=hengqi@linux.alibaba.com \
    --cc=horms@kernel.org \
    --cc=jasowangio@gmail.com \
    --cc=john.fastabend@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=kory.maincent@bootlin.com \
    --cc=kuba@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=liangchen.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=s.trumtrar@pengutronix.de \
    --cc=sdf@fomichev.me \
    --cc=virtualization@lists.linux.dev \
    --cc=willemdebruijn.kernel@gmail.com \
    --cc=xuanzhuo@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®