From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by mail.toke.dk (Postfix) with ESMTPS id 01E239B2E47 for ; Fri, 4 Nov 2022 04:25:42 +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=fPcnLbYP Received: by mail-yb1-xb49.google.com with SMTP id h67-20020a252146000000b006ccc4702068so3860533ybh.12 for ; Thu, 03 Nov 2022 20:25:41 -0700 (PDT) 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=OCCgxbTVge/6IILt05Wsg/+KZJkjj0dhtDZEa8P1RhM=; b=fPcnLbYP2Vz1k8K5iokHm8DjUtShAMal+AwffWSwfc3qkX8LY2oTllmEirmO+TThQ7 SV3I4kgyOXiyPY4K4sEBRo0luzBxKmMaq6eRNo1sbDHNo/AmuSkLwc7Ts4/OzOR8VzEJ /lfHJD4UgUmzMLLZpEGhEHdFtpcNyB/R2ugVBzt/p/yodp6/s/dB224eyR7LxwL/PWQS Sjk2ct14H7QA5Iju8k4lOPveepGFIIo7/akjt/E9iHoVOdbbaHR82lx2mjsQZVrDngTo JncLWsOsatZJBCpmq8VTrRr4Kee8dUa58mHK2vdKzupXyxWBcn8iHLeQ7YABgqqCXu6D utOw== 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=OCCgxbTVge/6IILt05Wsg/+KZJkjj0dhtDZEa8P1RhM=; b=qT1XeC82Bd0ZHUqG5vHyI6pyHrm3bfe8xQkhJj2jwzIXIxuqcTfNzVeUNCDA2ur55T 8BX4oKL49l7+d5ELONeViq7O2EcpXY8UkY4126jzJxOBl0JtahnXC4/QX5TSfx95QbtJ catou3t1cxJcJ7y3YlNgGlsYbWKYoDvovvDy0p1dBpgtCJnygtFY9Gsj5EhvxsPgsTYT 8YgtLyTPqFB0yJfVDU0j8X+5kXJ/WyuNpMUupwPQaoeZCVCBFqEADN/NdQKq1F3kP7M3 wFQEAIjrKXSzKoJK9wU9Js7VE6HTvL+Ygg6cRLXDXPVQal9i/zu8q17zIQ+t9JqplCqH B2AA== X-Gm-Message-State: ACrzQf2c7tZF9B++lQy6S0iOp7S423jT4aKlJ2ZstyfHzV3eJhP9UAf1 0H3de2scSFmbzJKHNS8BuH8IcnM= X-Google-Smtp-Source: AMsMyM5hULLNnXmCgtXNIAvHt43WTGt0K7Anj0qbolVVBOnPVRMfsXgsVkc/qJrLcSztj4Srn1M9p3o= X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:a5b:a07:0:b0:6c5:513b:387c with SMTP id k7-20020a5b0a07000000b006c5513b387cmr32440032ybq.234.1667532340850; Thu, 03 Nov 2022 20:25:40 -0700 (PDT) Date: Thu, 3 Nov 2022 20:25:22 -0700 In-Reply-To: <20221104032532.1615099-1-sdf@google.com> Mime-Version: 1.0 References: <20221104032532.1615099-1-sdf@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221104032532.1615099-5-sdf@google.com> From: Stanislav Fomichev To: bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Message-ID-Hash: PXNQL2WN3UMFYIFJEQJFENIQQBU7X3PC X-Message-ID-Hash: PXNQL2WN3UMFYIFJEQJFENIQQBU7X3PC X-MailFrom: 3NIZkYwMKCfMnYabjjbgZ.XjhsYk-cdionsYk-kmjeZXo.iZo@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.5 Precedence: list Subject: [xdp-hints] [RFC bpf-next v2 04/14] veth: Support rx timestamp metadata for xdp List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: xskxceiver conveniently setups up veth pairs so it seems logical to use veth as an example for some of the metadata handling. We timestamp skb right when we "receive" it, store its pointer in new veth_xdp_buff wrapper and generate BPF bytecode to reach it from the BPF program. This largely follows the idea of "store some queue context in the xdp_buff/xdp_frame so the metadata can be reached out from the BPF program". 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 917ba57453c1..0e629ceb087b 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #define DRV_NAME "veth" @@ -118,6 +119,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 +604,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); @@ -826,6 +829,7 @@ static struct sk_buff *veth_xdp_rcv_skb(struct veth_rq *rq, orig_data = xdp->data; orig_data_end = xdp->data_end; + vxbuf.skb = skb; act = bpf_prog_run_xdp(xdp_prog, xdp); @@ -942,6 +946,7 @@ static int veth_xdp_rcv(struct veth_rq *rq, int budget, struct sk_buff *skb = ptr; stats->xdp_bytes += skb->len; + __net_timestamp(skb); skb = veth_xdp_rcv_skb(rq, skb, bq, stats); if (skb) { if (skb_shared(skb) || skb_unclone(skb, GFP_ATOMIC)) @@ -1665,6 +1670,31 @@ static int veth_xdp(struct net_device *dev, struct netdev_bpf *xdp) } } +static void veth_unroll_kfunc(const struct bpf_prog *prog, u32 func_id, + struct bpf_patch *patch) +{ + if (func_id == xdp_metadata_kfunc_id(XDP_METADATA_KFUNC_RX_TIMESTAMP_SUPPORTED)) { + /* return true; */ + bpf_patch_append(patch, BPF_MOV64_IMM(BPF_REG_0, 1)); + } else if (func_id == xdp_metadata_kfunc_id(XDP_METADATA_KFUNC_RX_TIMESTAMP)) { + bpf_patch_append(patch, + /* r5 = ((struct veth_xdp_buff *)r1)->skb; */ + BPF_LDX_MEM(BPF_DW, BPF_REG_5, BPF_REG_1, + offsetof(struct veth_xdp_buff, skb)), + /* if (r5 == NULL) { */ + BPF_JMP_IMM(BPF_JNE, BPF_REG_5, 0, 2), + /* return 0; */ + BPF_MOV64_IMM(BPF_REG_0, 0), + BPF_JMP_A(1), + /* } else { */ + /* return ((struct sk_buff *)r5)->tstamp; */ + BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_5, + offsetof(struct sk_buff, tstamp)), + /* } */ + ); + } +} + static const struct net_device_ops veth_netdev_ops = { .ndo_init = veth_dev_init, .ndo_open = veth_open, @@ -1684,6 +1714,7 @@ static const struct net_device_ops veth_netdev_ops = { .ndo_bpf = veth_xdp, .ndo_xdp_xmit = veth_ndo_xdp_xmit, .ndo_get_peer_dev = veth_peer_dev, + .ndo_unroll_kfunc = veth_unroll_kfunc, }; #define VETH_FEATURES (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HW_CSUM | \ -- 2.38.1.431.g37b22c650d-goog