From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by mail.toke.dk (Postfix) with ESMTPS id 473A19D298D for ; Tue, 20 Dec 2022 23:21:05 +0100 (CET) Authentication-Results: mail.toke.dk; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=rxtoE1VY Received: by mail-pj1-x1049.google.com with SMTP id k7-20020a17090a39c700b002192c16f19aso90369pjf.1 for ; Tue, 20 Dec 2022 14:21:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=42wm0a27iiQaqPiSJuj7splEpSMGU4ZjOPqnU9s94do=; b=rxtoE1VYqwQY9hBRMUi1LtSlMz5yygsOknAu6BMYKomYu0z56FVgwAMIcv9LmdQlEd oWD12QcybdiKmNkaNmr9jWpZ26fP7MzBcWKLbQjU42p5/831j13vhaNarGNWW1rJCAoH kFERcp5K4d3+B1VVB1Kf/SN7Aus72KhdG+7z8VneEdXuDY357uGK4ldfo+J7zNJkh/7P +fiPG6xVImS9EhWkZJ6Id2bQ/McREhuLFNuHK4nAbM7KbQoipvpeJdykYW2sHbpIexTx n+w/lmG2MXO0E3nkULJr3sYqNnB+Vi+fIQxHJBMMIaHBW3XIRMSTwy3tUDjzcnDnvi6K xhzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=42wm0a27iiQaqPiSJuj7splEpSMGU4ZjOPqnU9s94do=; b=TTQxKaUKt9N+jV6s0N3TnIhK57twpnwRXKoBduwVlIXbfudXT1npCqQR1+AZQVHkSl MJC8wTmFCUrJ41Im5FrXNcplgo+da/wPdhLNVyQOEq4R5CFwiVSKXmG/SzWwEh2mhkR8 ZBFoTEQ+pLJTB6vaYFqAuehXaxiyMOKzkhrgqfy0tqPxPQy7twZm5+pKHAqCLfVYgAl/ RVR2Ny9eDJvzIHGos53bQQzz6QsBTZ1VcN6mbSQXLRJ800YCoUvzhZll1NMvrPFs3Xtm KB7BHHXS6tKWNKiJuVOPg1844pveWej4pM8gvVOqB//ruqv75yJZtxnGOIasNKOjvaLT 9bLw== X-Gm-Message-State: ANoB5pl6MxH3T6X11+uFAxBBtnAib2IboMt4h8Xp0eWbzq5fOznlCqhf bpxjVf6pF9QJqrvpsmspMfdBUF0= X-Google-Smtp-Source: AA0mqf6trWl0IdVYulJR22Ry3jJNsPIJ3Mkae+G4CRY1mztpYoxb7APnDVXqsh1uxl/PvB9LEQ779WE= X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:a17:902:e48a:b0:189:63f2:d58f with SMTP id i10-20020a170902e48a00b0018963f2d58fmr68968592ple.161.1671574863626; Tue, 20 Dec 2022 14:21:03 -0800 (PST) Date: Tue, 20 Dec 2022 14:20:36 -0800 In-Reply-To: <20221220222043.3348718-1-sdf@google.com> Mime-Version: 1.0 References: <20221220222043.3348718-1-sdf@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221220222043.3348718-11-sdf@google.com> From: Stanislav Fomichev To: bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Message-ID-Hash: X53LUVPCUBJZYGOQAZKQ3UYOYSMZFLPQ X-Message-ID-Hash: X53LUVPCUBJZYGOQAZKQ3UYOYSMZFLPQ X-MailFrom: 3TzWiYwMKCWYWHJKSSKPI.GSQbHT-LMRXWbHT-TVSNIGX.RIX@flex--sdf.bounces.google.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, David Ahern , Jakub Kicinski , Willem de Bruijn , Jesper Dangaard Brouer , Anatoly Burakov , Alexander Lobakin , Magnus Karlsson , Maryam Tahhan , xdp-hints@xdp-project.net, netdev@vger.kernel.org X-Mailman-Version: 3.3.7 Precedence: list Subject: [xdp-hints] [PATCH bpf-next v5 10/17] veth: Support RX XDP metadata List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The goal is to enable end-to-end testing of the metadata for AF_XDP. Cc: John Fastabend Cc: David Ahern Cc: Martin KaFai Lau Cc: Jakub Kicinski Cc: Willem de Bruijn Cc: Jesper Dangaard Brouer Cc: Anatoly Burakov Cc: Alexander Lobakin Cc: Magnus Karlsson Cc: Maryam Tahhan Cc: xdp-hints@xdp-project.net Cc: netdev@vger.kernel.org Signed-off-by: Stanislav Fomichev --- drivers/net/veth.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 04ffd8cb2945..71966de4e942 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -118,6 +118,7 @@ static struct { struct veth_xdp_buff { struct xdp_buff xdp; + struct sk_buff *skb; }; static int veth_get_link_ksettings(struct net_device *dev, @@ -602,6 +603,7 @@ static struct xdp_frame *veth_xdp_rcv_one(struct veth_rq *rq, xdp_convert_frame_to_buff(frame, xdp); xdp->rxq = &rq->xdp_rxq; + vxbuf.skb = NULL; act = bpf_prog_run_xdp(xdp_prog, xdp); @@ -823,6 +825,7 @@ static struct sk_buff *veth_xdp_rcv_skb(struct veth_rq *rq, __skb_push(skb, skb->data - skb_mac_header(skb)); if (veth_convert_skb_to_xdp_buff(rq, xdp, &skb)) goto drop; + vxbuf.skb = skb; orig_data = xdp->data; orig_data_end = xdp->data_end; @@ -1601,6 +1604,28 @@ static int veth_xdp(struct net_device *dev, struct netdev_bpf *xdp) } } +static int veth_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp) +{ + struct veth_xdp_buff *_ctx = (void *)ctx; + + if (!_ctx->skb) + return -EOPNOTSUPP; + + *timestamp = skb_hwtstamps(_ctx->skb)->hwtstamp; + return 0; +} + +static int veth_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash) +{ + struct veth_xdp_buff *_ctx = (void *)ctx; + + if (!_ctx->skb) + return -EOPNOTSUPP; + + *hash = skb_get_hash(_ctx->skb); + return 0; +} + static const struct net_device_ops veth_netdev_ops = { .ndo_init = veth_dev_init, .ndo_open = veth_open, @@ -1622,6 +1647,11 @@ static const struct net_device_ops veth_netdev_ops = { .ndo_get_peer_dev = veth_peer_dev, }; +static const struct xdp_metadata_ops veth_xdp_metadata_ops = { + .xmo_rx_timestamp = veth_xdp_rx_timestamp, + .xmo_rx_hash = veth_xdp_rx_hash, +}; + #define VETH_FEATURES (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HW_CSUM | \ NETIF_F_RXCSUM | NETIF_F_SCTP_CRC | NETIF_F_HIGHDMA | \ NETIF_F_GSO_SOFTWARE | NETIF_F_GSO_ENCAP_ALL | \ @@ -1638,6 +1668,7 @@ static void veth_setup(struct net_device *dev) dev->priv_flags |= IFF_PHONY_HEADROOM; dev->netdev_ops = &veth_netdev_ops; + dev->xdp_metadata_ops = &veth_xdp_metadata_ops; dev->ethtool_ops = &veth_ethtool_ops; dev->features |= NETIF_F_LLTX; dev->features |= VETH_FEATURES; -- 2.39.0.314.g84b9a713c41-goog