Article View: linux.kernel.netdev
Article #14217Re: [PATCH RFC v4 5/6] virtio-net: add XDP rx timestamp metadata
From: Steffen Trumtrar
Date: Tue, 10 Nov 2026 19:27
Date: Tue, 10 Nov 2026 19:27
94 lines
12696 bytes
12696 bytes
On 2026-11-01 at 10:12 -05, Willem de Bruijn <willemdebruijn.kernel@gmail.com> wrote:
> Steffen Trumtrar wrote:
> > 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 virtnet_xdp_rx_hash(), the callback finds the header relative to
> > xdp->data, so it has to be called before bpf_xdp_adjust_head().
> >
> > Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
> > Assisted-by: Claude:claude-opus-5-5
> > ---
> > drivers/net/virtio_net.c | 26 ++++++++++++++++++++++++++
> > 1 file changed, 26 insertions(+)
> >
> > 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);
>
> Reading `hdr->tstamp` in place from `xdp->data - vi->hdr_len` violates the XDP
> metadata area contract (`Documentation/networking/xdp-rx-metadata.rst`: drivers
> must copy device-reserved metadata out of `[data_hard_start, data)` before
> presenting the frame to XDP) and breaks standard XDP metadata consumers:
> - `hdr->tstamp` sits at `[xdp->data - 8, xdp->data)`. Standard XDP programs—such
> as `tools/testing/selftests/bpf/progs/xdp_hw_metadata.c`—call
> `bpf_xdp_adjust_meta(ctx, -(int)sizeof(struct xdp_meta))` first, initialize
> fields in `meta` (e.g. `meta->hint_valid = 0` at `[xdp->data - 4, xdp->data)`),
> and only then call `bpf_xdp_metadata_rx_timestamp(ctx, &meta->rx_timestamp)`.
> Initializing `meta` overwrites `hdr->tstamp` (and `hdr->hash_v1_hdr`) before
> this kfunc runs.
> - Calling `bpf_xdp_adjust_head()` before reading metadata also shifts `xdp->data`,
> reading arbitrary bytes at `xdp->data - vi->hdr_len`.
>
> Wrap `struct xdp_buff` in a driver struct on the stack (`container_of`, and in
> `struct xdp_buff_xsk`'s `cb` verified with `XSK_CHECK_PRIV_TYPE()` for AF_XDP,
> matching `gve`/`igc`/`ice`/`mlx5`) and stash `tstamp` (already extracted in
> `receive_buf()` and `virtnet_receive_xsk_buf()` before XDP runs) and the hash
> fields before `bpf_prog_run_xdp()`.
Agreed, Sashiko complained about the same thing. I'll stash the
timestamp in a wrapper around xdp_buff before the program runs.
Steffen
--
Pengutronix e.K. | Dipl.-Inform. Steffen Trumtrar |
Steuerwalder Str. 21 | https://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686| Fax: +49-5121-206917-5555 |
Technical Details
Message-ID:
<87pkwczdvb.fsf@pengutronix.de>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-360555-linux-kernel-netdev=dewy.ruReferences:
<20261026-v6-7-topic-virtio-net-ptp-v4-0-008af03cd43b@pengutronix.de> <20261026-v6-7-topic-virtio-net-ptp-v4-5-008af03cd43b@pengutronix.de> <willemdebruijn.kernel.9c17365c41b3@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-360555-linux-kernel-netdev=dewy.ru From: s.trumtrar@pengutronix.de (Steffen Trumtrar) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH RFC v4 5/6] virtio-net: add XDP rx timestamp metadata Date: Tue, 10 Nov 2026 20:27:04 +0100 Organization: Usenet Network Message-ID: <87pkwczdvb.fsf@pengutronix.de> References: <20261026-v6-7-topic-virtio-net-ptp-v4-0-008af03cd43b@pengutronix.de> <20261026-v6-7-topic-virtio-net-ptp-v4-5-008af03cd43b@pengutronix.de> <willemdebruijn.kernel.9c17365c41b3@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: usenet.network; logging-data="709681"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:4O/wpDM28IeB3VhoAvtPX0CaUm4= sha256:iG7VAFPopwXFv38IS1lBXf4SHQOEl4o6Dmh/o90Bdaw= sha1:nLHNDJvi47AHdNc+zbC4Mz//5QY= sha256:uuBq/mkaeVUxVnYZg6aUASBkj4/XrNynf9GRsNt89Ko= 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 5079D113D57; Wed, 11 Nov 2026 00:46:02 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.05 X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=pengutronix.de 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 7OkMDSnlDo2o; Wed, 11 Nov 2026 00:45:52 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-360555-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=pengutronix.de X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 3C399113CF8; Wed, 11 Nov 2026 00:45:43 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 68CDF124663; Tue, 10 Nov 2026 19:27:28 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=fail 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 317EF60A2618; Tue, 10 Nov 2026 19:27:18 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pengutronix.de header.i=@pengutronix.de header.a=rsa-sha256 header.s=20260414 header.b=axFxc57Y X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=185.203.200.13 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1794338832; b=d5TbZWG1TSJbI1AVkVxIyFI7uiczoneJbQDijKjhuLlrpK/PabcvQH64V216HPmaZFKc eBQQpfhABVez0rxFgntzhdcBJRyTtmBVhKBy96rMC5doYt2ZXsuwwudgC5EgfSswQ8k93 vJzV5CVDqnnKTEV8/z0hfGAnv3HTiXLuR5gepxqCTSMMf56ysPgTWXnOrN5XWmIrsi1na eyyOzNd0izcnTKw0sqU8TVUKNuE/7yLEtuK53vJD4+VLJMWQV7z9mTgpA8nAk0Ju4HR8e ostCRmd7To7TX7PMawx9YFHB5qr5jGnytwTIVdgCemCWaeBYw8lr4YtVy0xoPzq9QGg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794338832; h=DMARC-Filter:Received:DKIM-Signature:From:To:Cc:Subject:In-Reply-To: References:User-Agent:Date:Message-ID:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=ODatzweUCW7o26hwhl5kE9FWoziqlEwZz6tErIYcf3Q=; b=k8M6dz08z013fZ7xjtqK07Ro7hbIjyW34+xRvrQyT860rT48HHr9+7B6RZR6qFM+iY61 31jEcQd/8eM/b1zOSrJPKG5tVQmT/k1fxiHWnD8FxC4SZ1MTdsnuslF4at2i6lMNUEaqV F3GkIMnyS6OUsEdiWp2uK8XGcYGYuVohBHM5N2ZBg4L2QCehEVIdTAiGMzmBShZulkTMq I2ILYJ4oBjCYNh6KsZ40X9lhyGhSPw5jl6CaXqJysZNF49UrTyvXRJaf7QGKdQkrWtvN8 VJwoJn9XKuB1WOrvsdBXpB5H879Etjxar6pXFhxwUmm2caTHwx4lQ6XBEdSO4Ys9Tiw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; dkim=pass header.d=pengutronix.de header.i=@pengutronix.de header.a=rsa-sha256 header.s=20260414 header.b=axFxc57Y; arc=fail smtp.remote-ip=185.203.200.13 X-Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (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 ECFF8606A323; Tue, 10 Nov 2026 19:27:10 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org ECFF8606A323 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de X-Received: from ratatoskr.pengutronix.de (unknown [IPv6:2a00:1f:f805:2b01:a03:2f4:308a:7b52]) (Authenticated sender: str@pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id 8BD0E201F43; Tue, 10 Nov 2026 20:27:04 +0100 (CET) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de; s=20260414; t=1794338824; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ODatzweUCW7o26hwhl5kE9FWoziqlEwZz6tErIYcf3Q=; b=axFxc57YGOskhC2HI2z4xDSvzgCtzuAXY8Knr9qFzsc+a7wrW8VAQx/IsBszC7lven9owS 2FfsB78fRdwzNe47fV2HcPaI0iWunzz5ZMUGJc2mr4/dy6FWo8ACnpoMxBeA/6pKKhXJUR QB3+86oOjzX81gKVi130N9q1McuVWktylsu+C1gXCgXIQDDDEPPptbQn6t6JuUcyf5BOE4 rKPfn33jjKEZPYEw6ihaClJbFpa9kvhDCCqrhWT9o6YQO3z3EP83rBubBfgXjyfPN2jINo NDFYV+f8O4KudinwcrmPWIyVTtNnn033e6cTBF8QesUYgkucwN+v2YtOz+SXIQ== X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de; s=20260414; t=1794338824; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ODatzweUCW7o26hwhl5kE9FWoziqlEwZz6tErIYcf3Q=; b=BuwLSFTXEPbgZoXPmMfP847UiDdg7yfDag5qeRedm6DCAisISY+tAM3ib9uJL4DxX+esnL UcBIrds43eOXIbYN7JjoIqbYjk4eKlPgP+FebysRP8HEGfHmg2ycjF2biXZEnolOYSVAE3 /i8EdUzhzUue/XFv6aUoSDDK17iwNsGl/uZT11NPJOfp5zNEDiUmqMXI/QET/lFq8S8ys2 J+SFA/7woz09hIdZqXi71fQ4Z1jhE7gvLXvkjy3VT7kwq3QamOH+D5JYCJoFx81dbKRNyX SMoAygzG2W/5j1E0sCrtBN7LYbyUmvkphAhjmRkN8Q3ZMh+cFaiyWcpw8Cis7Q== X-ARC-Seal: i=1; s=20260414; d=pengutronix.de; t=1794338824; a=rsa-sha256; cv=none; b=VP+KPQ5a7GMBOJPnXBnWZlwAKh3chavc2oaAqwJmKA6Me6u1CuToWDrd0RMFVCdEPgwjDb WYEG6EhF6UgqsEk7/lKNVmEajmnuzmlhyx3UCrzdBqz/P4M3oU2csBLGv1nzZ1ABCfApN+ DA5gGKCqUBokK5qbDEaDBpJlQXjBYs+O/OeqXvmjFBqbEa83bTUcI0vZ+kcU5ZZ726Df6m Awfrcmmy/VJT8poW8tYP3PEU1kmUeLJ/JhMLw9EfHh12unTwm2mxUs4nk8YJOf7XZ4xE47 krNeN+kXbw6/OEJauq2nn4qBSTWYxRQhLBig3Y1jGv29PGIe0DOepYTHrmGfXA== X-ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=str@pengutronix.de smtp.mailfrom=s.trumtrar@pengutronix.de X-Cc: "Michael S. Tsirkin" <mst@redhat.com>, Xuan Zhuo <xuanzhuo@linux.alibaba.com>, "David S. Miller" <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Richard Cochran <richardcochran@gmail.com>, Andrew Lunn <andrew+netdev@lunn.ch>, Eugenio Pérez <eperezma@redhat.com>, Jason Wang <jasowangio@gmail.com>, Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Jesper Dangaard Brouer <hawk@kernel.org>, John Fastabend <john.fastabend@gmail.com>, Stanislav Fomichev <sdf@fomichev.me>, Eric Dumazet <edumazet@kernel.org>, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, kvm@vger.kernel.org X-In-Reply-To: <willemdebruijn.kernel.9c17365c41b3@gmail.com> X-User-Agent: mu4e 1.14.3; emacs 31.1 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