From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mail.toke.dk (Postfix) with ESMTPS id 1E2BB9CE700 for ; Sun, 11 Dec 2022 12:09:42 +0100 (CET) Authentication-Results: mail.toke.dk; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MEF9Zwvn DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670756981; 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=khqYQ6ao58HEonL3Tw0vVUzswYB2HQq7BgFa7siHNew=; b=MEF9ZwvnL0vkJDh6FCLTsTMEYaUw2da5Xc95sC8IyNba4WBmkoTZmTjLYpu1o1+Bckk4uD HPTxZ2cXmynVTvRzbrC4yiPdUL9JXAIE/tojr0TlWMyfpxkRvIc/rCOB5j4p6gJi37ZtO1 xUonIP3byvZ7nH05g2X3OG52S588060= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-310-xIwgeQiMOymWL0kOoW93Aw-1; Sun, 11 Dec 2022 06:09:39 -0500 X-MC-Unique: xIwgeQiMOymWL0kOoW93Aw-1 Received: by mail-ej1-f71.google.com with SMTP id xh12-20020a170906da8c00b007413144e87fso5441209ejb.14 for ; Sun, 11 Dec 2022 03:09:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:to :content-language:subject:cc:user-agent:mime-version:date:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=khqYQ6ao58HEonL3Tw0vVUzswYB2HQq7BgFa7siHNew=; b=FzrC7bW4hg+Pco1ulQUsXb2izuUgXaPWH6ilDO1WTObuu5BUV1qua+67e2wWh2wZdt GDRUl8b4qkZR2NoQhxwaZ0oMofNOiIdH3ZituJnhzdG2tdawUn4xgcc7CEPaUrWgQWXo owbaLl/OecrMVI/P62b/ngVXobXp+9b+QvvYlSIQkBx2PH24IEmE4UHOgsXZQ/0s6ZZp fV35nN7qtGexRtzaYLoCmNkP7ilj4SOncpA/nIppAuiKQhyPf7Ce17tuQY/uny6+zq2d 2vQ33sITBgoYfnPCaBys6562mtQM3odBIkj6M60KzIoiRdcOUK+TqXTi2BYRR5K28loy jgJg== X-Gm-Message-State: ANoB5pl//h1qWCT/l/JRg8ODFBrLD8P9P4RyTfVVmq+feQRHw+WnfORj 0FPqZMbBzBtP8zcPhuO9KOW6msIRy9/lXE3Lq2svXJXHsluA2QN3eWBayxzMDn/o2jageeUNQTy k+/1HKiJ5I0Hqr+X8eziW X-Received: by 2002:a17:907:6e20:b0:7bc:fbd1:4ca with SMTP id sd32-20020a1709076e2000b007bcfbd104camr19461923ejc.69.1670756978185; Sun, 11 Dec 2022 03:09:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf6N6n+Vnd4vzu9yXAgvM4CfIZVvrUH2lwFn6sv4kXMHxZCB46RvwHkhInlqea0H7MpGbx6FZQ== X-Received: by 2002:a17:907:6e20:b0:7bc:fbd1:4ca with SMTP id sd32-20020a1709076e2000b007bcfbd104camr19461878ejc.69.1670756977896; Sun, 11 Dec 2022 03:09:37 -0800 (PST) Received: from [192.168.41.200] (83-90-141-187-cable.dk.customer.tdc.net. [83.90.141.187]) by smtp.gmail.com with ESMTPSA id f3-20020a17090631c300b007b9269a0423sm2004034ejf.172.2022.12.11.03.09.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 11 Dec 2022 03:09:36 -0800 (PST) From: Jesper Dangaard Brouer X-Google-Original-From: Jesper Dangaard Brouer Message-ID: Date: Sun, 11 Dec 2022 12:09:28 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 To: Stanislav Fomichev , Jesper Dangaard Brouer References: <20221206024554.3826186-1-sdf@google.com> <20221206024554.3826186-4-sdf@google.com> In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: 3CSBWZQFDY2WA6GRMLVJUOQ5CQUXLXWI X-Message-ID-Hash: 3CSBWZQFDY2WA6GRMLVJUOQ5CQUXLXWI X-MailFrom: jbrouer@redhat.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: brouer@redhat.com, bpf@vger.kernel.org, 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, haoluo@google.com, jolsa@kernel.org, David Ahern , Jakub Kicinski , Willem de Bruijn , 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] Re: [PATCH bpf-next v3 03/12] bpf: XDP metadata RX kfuncs List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 09/12/2022 18.47, Stanislav Fomichev wrote: > On Fri, Dec 9, 2022 at 3:11 AM Jesper Dangaard Brouer > wrote: >> >> >> On 06/12/2022 03.45, Stanislav Fomichev wrote: >>> There is an ndo handler per kfunc, the verifier replaces a call to the >>> generic kfunc with a call to the per-device one. >>> >>> For XDP, we define a new kfunc set (xdp_metadata_kfunc_ids) which >>> implements all possible metatada kfuncs. Not all devices have to >>> implement them. If kfunc is not supported by the target device, >>> the default implementation is called instead. >>> >>> Upon loading, if BPF_F_XDP_HAS_METADATA is passed via prog_flags, >>> we treat prog_index as target device for kfunc resolution. >>> >> >> [...cut...] >>> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h >>> index 5aa35c58c342..2eabb9157767 100644 >>> --- a/include/linux/netdevice.h >>> +++ b/include/linux/netdevice.h >>> @@ -74,6 +74,7 @@ struct udp_tunnel_nic_info; >>> struct udp_tunnel_nic; >>> struct bpf_prog; >>> struct xdp_buff; >>> +struct xdp_md; >>> >>> void synchronize_net(void); >>> void netdev_set_default_ethtool_ops(struct net_device *dev, >>> @@ -1611,6 +1612,10 @@ struct net_device_ops { >>> ktime_t (*ndo_get_tstamp)(struct net_device *dev, >>> const struct skb_shared_hwtstamps *hwtstamps, >>> bool cycles); >>> + bool (*ndo_xdp_rx_timestamp_supported)(const struct xdp_md *ctx); >>> + u64 (*ndo_xdp_rx_timestamp)(const struct xdp_md *ctx); >>> + bool (*ndo_xdp_rx_hash_supported)(const struct xdp_md *ctx); >>> + u32 (*ndo_xdp_rx_hash)(const struct xdp_md *ctx); >>> }; >>> >> >> Would it make sense to add a 'flags' parameter to ndo_xdp_rx_timestamp >> and ndo_xdp_rx_hash ? >> >> E.g. we could have a "STORE" flag that asks the kernel to store this >> information for later. This will be helpful for both the SKB and >> redirect use-cases. >> For redirect e.g into a veth, then BPF-prog can use the same function >> bpf_xdp_metadata_rx_hash() to receive the RX-hash, as it can obtain the >> "stored" value (from the BPF-prog that did the redirect). >> >> (p.s. Hopefully a const 'flags' variable can be optimized when unrolling >> to eliminate store instructions when flags==0) > > Are we concerned that doing this without a flag and with another > function call will be expensive? Yes, but if we can unroll (to avoid the function calls) it would be more flexible and explicit API with below instead. > For xdp->skb path, I was hoping we would be to do something like: > > timestamp = bpf_xdp_metadata_rx_hash(ctx); > bpf_xdp_metadata_export_rx_hash_to_skb(ctx, timestamp); > > This should also let the users adjust the metadata before storing it. > Am I missing something here? Why would the flag be preferable? I do like this ability to let the users adjust the metadata before storing it. This would be a more flexible API for the BPF-programmer. I like your "export" suggestion. The main concern for me was performance overhead of the extra function call, which I guess can be removed via unrolling later. Unrolling these 'export' functions might be easier to accept from a maintainer perspective, as it is not device driver specific, thus we can place that in the core BPF code. --Jesper