From: sashiko-bot@kernel.org
To: "Steffen Trumtrar" <s.trumtrar@pengutronix.de>
Cc: virtualization@lists.linux.dev, bpf@vger.kernel.org,
kvm@vger.kernel.org, "Michael S. Tsirkin" <mst@redhat.com>,
"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH RFC v4 5/6] virtio-net: add XDP rx timestamp metadata
Date: Mon, 26 Oct 2026 09:04:00 +0000 [thread overview]
Message-ID: <sashiko-outbox-184725@kernel.org> (raw)
In-Reply-To: <20261026-v6-7-topic-virtio-net-ptp-v4-5-008af03cd43b@pengutronix.de>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] virtio-net: virtnet_xdp_rx_timestamp() reads header overlapping XDP data_meta
--
commit 232ef11034e0a6c3f2481ceaa1291cc9268f328c
Author: Steffen Trumtrar <s.trumtrar@pengutronix.de>
virtio-net: add XDP rx timestamp metadata
This commit implements the xmo_rx_timestamp XDP metadata callback in
virtio_net so XDP programs can read hardware receive timestamps via
bpf_xdp_metadata_rx_timestamp(). It also installs virtnet_xdp_metadata_ops
when VIRTIO_NET_F_RX_TSTAMP is negotiated.
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 23af10c613b48..e79b65653fad7 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -6848,8 +6848,30 @@ 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 xdp_buff *xdp = (void *)_ctx;
> + const struct virtio_net_common_hdr *hdr;
> + struct virtnet_info *vi;
> + u64 tstamp;
> +
> + vi = netdev_priv(xdp->rxq->dev);
> + if (!READ_ONCE(vi->hwts_rx_en))
> + return -ENODATA;
> +
> + hdr = (const struct virtio_net_common_hdr *)(xdp->data - vi->hdr_len);
> + tstamp = get_unaligned_le64(hdr->tstamp);
[Severity: High]
Can reading hdr->tstamp in place from xdp->data - vi->hdr_len collide with
the XDP data_meta region when an XDP program uses bpf_xdp_adjust_meta()?
When VIRTIO_NET_F_RX_TSTAMP is negotiated and hardware rx timestamping is
enabled via virtnet_hwtstamp_set(), virtnet_probe() sets vi->hdr_len to 40
bytes:
drivers/net/virtio_net.c:virtnet_probe() {
if (vi->has_rx_tstamp)
vi->hdr_len = offsetofend(struct virtio_net_common_hdr, tstamp);
}
In the XDP receive paths (receive_small_xdp(), receive_mergeable_xdp() ->
virtnet_build_xdp_buff_mrg(), and virtnet_receive_xsk_buf()), the
virtio_net_common_hdr remains in the headroom immediately preceding
xdp->data, spanning [xdp->data - 40, xdp->data). Within that header,
hdr->tstamp sits at [xdp->data - 8, xdp->data) and hdr->hash_v1_hdr sits at
[xdp->data - 28, xdp->data - 20).
Documentation/networking/xdp-rx-metadata.rst notes that drivers must move
device-reserved metadata out of the [xdp->data_meta, xdp->data) area before
running the XDP program because XDP programs call bpf_xdp_adjust_meta()
first and then populate their custom metadata structure in [xdp->data_meta,
xdp->data) using the xdp_metadata kfuncs.
For example, in tools/testing/selftests/bpf/progs/xdp_hw_metadata.c:rx(),
where struct xdp_meta is 32 bytes:
err = bpf_xdp_adjust_meta(ctx, -(int)sizeof(struct xdp_meta));
if (err)
return XDP_PASS;
data = (void *)(long)ctx->data;
meta = (void *)(long)ctx->data_meta;
if (meta + 1 > data)
return XDP_PASS;
meta->hint_valid = 0;
meta->xdp_timestamp = bpf_ktime_get_tai_ns();
err = bpf_xdp_metadata_rx_timestamp(ctx, &meta->rx_timestamp);
if (err)
meta->rx_timestamp_err = err;
else
meta->hint_valid |= XDP_META_FIELD_TS;
err = bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash,
&meta->rx_hash_type);
Here, initializing meta->hint_valid = 0 writes to [xdp->data - 4,
xdp->data), which overwrites the upper 32 bits of hdr->tstamp before
bpf_xdp_metadata_rx_timestamp() calls virtnet_xdp_rx_timestamp(). Then,
writing meta->xdp_timestamp and meta->rx_timestamp at [xdp->data - 32,
xdp->data - 16) overwrites hdr->hash_v1_hdr at [xdp->data - 28,
xdp->data - 22) before bpf_xdp_metadata_rx_hash() calls
virtnet_xdp_rx_hash().
Unlike the skb paths (receive_buf() and virtnet_receive_xsk_buf()), which
save the timestamp via virtnet_record_rx_tstamp() before invoking the XDP
program, virtnet_xdp_rx_timestamp() reads from the live buffer during XDP
execution. Should the driver extract or preserve the rx metadata outside
the [xdp->data_meta, xdp->data) region before running the XDP program?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261026-v6-7-topic-virtio-net-ptp-v4-0-008af03cd43b@pengutronix.de?part=5
next prev parent reply other threads:[~2026-10-26 9:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 8:29 [PATCH RFC v4 0/6] virtio-net: add receive timestamp support Steffen Trumtrar
2026-10-26 8:29 ` [PATCH RFC v4 1/6] virtio-net: move virtio_net_common_hdr to virtio_net.h Steffen Trumtrar
2026-10-26 8:29 ` [PATCH RFC v4 2/6] virtio-net: support receive timestamp Steffen Trumtrar
2026-10-26 8:51 ` sashiko-bot
2026-10-26 8:29 ` [PATCH RFC v4 3/6] virtio-net: assert header sizes Steffen Trumtrar
2026-10-26 8:29 ` [PATCH RFC v4 4/6] vhost-net: support VIRTIO_NET_F_RX_TSTAMP Steffen Trumtrar
2026-10-26 8:51 ` sashiko-bot
2026-10-26 8:29 ` [PATCH RFC v4 5/6] virtio-net: add XDP rx timestamp metadata Steffen Trumtrar
2026-10-26 9:04 ` sashiko-bot [this message]
2026-10-26 8:29 ` [PATCH RFC v4 6/6] tun: add rx timestamp to the vnet header Steffen Trumtrar
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=sashiko-outbox-184725@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=eperezma@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mst@redhat.com \
--cc=s.trumtrar@pengutronix.de \
--cc=sashiko-reviews@lists.linux.dev \
--cc=virtualization@lists.linux.dev \
/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