From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by mail.toke.dk (Postfix) with ESMTPS id 61E759E0577 for ; Thu, 19 Jan 2023 23:15:57 +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=P68YSDFg Received: by mail-pg1-x54a.google.com with SMTP id g7-20020a636b07000000b004d1c5988521so1626795pgc.22 for ; Thu, 19 Jan 2023 14:15:57 -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=DdiKboA1OinZW68Ps6utmlxIN/WHRtMp9NTtEZItVqo=; b=P68YSDFgefbeRUc21+cOfPdeWm7m5dX0uI3ajYDALuFzhpHKbJx7u9LfrxQW/noR6B 5lXe4rpbdCcl0mti08Cr72hWRRKeE4GGbP0gmgXjpqAoa0CNszTfju9nJvC6ybvC5Paa dvlb0/YVXuFK65vLBsxMXFzudGXd6dVaRQfkrtkpEcmn+13I1kbq2UwMniSOI6y4gHL6 B+lIZP7uFL57r5keeEl+4rCbOICUBt6RdhaZZLjjcZ8HcIjw8+Qa2pPv9EA/QChWigAh JSK3voiQnc/oBzZK6FrvOrOeTiN0zjQBhJ3dgzA8G/6Y/HW52Y537UbC4HHPY6hB+vnj Doaw== 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=DdiKboA1OinZW68Ps6utmlxIN/WHRtMp9NTtEZItVqo=; b=1LsbOfM9h7iVWJvy3bdYRMhyodOokOg8euxD/0Zc3F4vSWAGDvy3D75ZC3O4qjDj0e PGdDjJKcibQq+otIU0V9yZVi1lLYtVVNgc1Gy5u3/MZIGrJTnZ52egc18x2EmG/VPMb0 7k3BTE5fAizJpoKGmLz9oElk7JeO1E3ztAoFIZu91jhH6ZB73eMDA7bg5rF9Q5rz1ntr NhPs+Ejv+OxZpt8Dz3LsmVMm9wXL6qyBg6ExPaQTk//wrrVuQZS8JPqVwFwbNfKknryH w5frI7YhPAcL39F/c+iy8JAsqE1jHqYv0A2GIGTjJRg1IkTCaMpNoiFBPK1fs/qlEqy1 rPCQ== X-Gm-Message-State: AFqh2krAfVfYrv9jd75+NJV2Ra/+K6Z44MWZpINO6NRHDdMx98fMG0Qj KxfKp3mOOFbywET5KjZWBZrtFYM= X-Google-Smtp-Source: AMrXdXvAviVOQO16RvrAUOJynbCzmNs+BL1R17o46mu7wBT/6W0lvyC7VjwGyFDp+gwnwDpmsaXgLEQ= X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:a17:902:d703:b0:192:b43e:267 with SMTP id w3-20020a170902d70300b00192b43e0267mr1111668ply.38.1674166555550; Thu, 19 Jan 2023 14:15:55 -0800 (PST) Date: Thu, 19 Jan 2023 14:15:29 -0800 In-Reply-To: <20230119221536.3349901-1-sdf@google.com> Mime-Version: 1.0 References: <20230119221536.3349901-1-sdf@google.com> X-Mailer: git-send-email 2.39.0.246.g2a6d74b583-goog Message-ID: <20230119221536.3349901-11-sdf@google.com> From: Stanislav Fomichev To: bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Message-ID-Hash: OKTCRONIB2K5265M2BNV4PXMM5LMHC55 X-Message-ID-Hash: OKTCRONIB2K5265M2BNV4PXMM5LMHC55 X-MailFrom: 3G8HJYwMKCegcNPQYYQVO.MYWhNZ-RSXdchNZ-ZbYTOMd.XOd@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 v8 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 70f50602287a..ba3e05832843 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; @@ -1602,6 +1605,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, @@ -1623,6 +1648,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 | \ @@ -1639,6 +1669,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.246.g2a6d74b583-goog