From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F755C47095 for ; Wed, 9 Jun 2021 05:09:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 276CF61351 for ; Wed, 9 Jun 2021 05:09:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231168AbhFIFLh (ORCPT ); Wed, 9 Jun 2021 01:11:37 -0400 Received: from mail-yb1-f173.google.com ([209.85.219.173]:36777 "EHLO mail-yb1-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229792AbhFIFLh (ORCPT ); Wed, 9 Jun 2021 01:11:37 -0400 Received: by mail-yb1-f173.google.com with SMTP id c14so4644475ybk.3; Tue, 08 Jun 2021 22:09:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7cayuynw3axnZYGZCGIG/avL9L6H8rpp5DbZ9eDadGI=; b=Y4VM4Tf8Z8FHhIkeBPLnupfB9QR+qEBXZCw8KN7RxcbeYNeQtvC2G/n3+dg1NM/VyF 3+tflGDhbdSMOwejsquEiqqmJ+lYPRRT3Somk2m7vY7qwnnDFRqql42YNSxVgmnMajHv pzV33be4yFxTFBsKFxMr3vwlIbeGXClG4b54laWGF5OUYWPUxQkt68u3HJTA6cPBbe3w 8pk/RImKduXxHCt7eaIMsIAsPhH5uyViu4qj4pQVNmiEBSTE2K6GvYBXdFRfLAdCCAHP wO2Ezq1A5iD/WSvYMhoHp4RTEGiKEsMcILV9MAc6Hsu3kkuSACLg3L0Te2Jl5vtG28bu bIuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7cayuynw3axnZYGZCGIG/avL9L6H8rpp5DbZ9eDadGI=; b=ZMn3zYcvSyODaw1AbQJ8BkMRpM0B4Ze2J/50M9wa3LxOEcaKj3A0VMyMSvwYjHV2ct jYDxlyH2ZqpE5adBIKzA1qXsJOiVhSt/5oMGkpDSh50DYyOEczYQGFdD2zoGZJHe0Q/a glwM+eHa+N+Zbpmwpjsa5iKeEYaJswKLlpynDDaMRTFOKVbiXCwP+vjO4CNj1AWe2Vu0 eQgvVcDl/1xrrqLXhkut+I831bWiEQ5SXRu9CdwxLafBbgfEzGc7MHg3nvJsXERKGD/s oDiTAlX2/P8RewYTW6CITxesrY52LlfDcC3Xyamgb9VXgnXPAjNEHNU25x1+bAdpFotf i+9g== X-Gm-Message-State: AOAM5303U+8mxOl7dU8t3nmZLOpAR9BLskb0rzPDMSr2UfjPDB4Xga2G BC3KPTOszlHqSqlxd/JbRrOhMRFAyvu7BdcXAj0= X-Google-Smtp-Source: ABdhPJy4dD5yHmfGUCO0PAO4pHLZMKdqQ46uWPfZbl1WNUEvdddhADj93gyapt/L6X0eOXQKcWV434JCTRsDyqee5B0= X-Received: by 2002:a25:9942:: with SMTP id n2mr36963709ybo.230.1623215323295; Tue, 08 Jun 2021 22:08:43 -0700 (PDT) MIME-Version: 1.0 References: <20210605111034.1810858-1-jolsa@kernel.org> <20210605111034.1810858-14-jolsa@kernel.org> <20210608184903.rgnv65jimekqugol@ast-mbp.dhcp.thefacebook.com> In-Reply-To: From: Andrii Nakryiko Date: Tue, 8 Jun 2021 22:08:32 -0700 Message-ID: Subject: Re: [PATCH 13/19] bpf: Add support to link multi func tracing program To: Alexei Starovoitov Cc: Jiri Olsa , Jiri Olsa , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , "Steven Rostedt (VMware)" , Network Development , bpf , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Daniel Xu , Viktor Malik Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Tue, Jun 8, 2021 at 4:07 PM Alexei Starovoitov wrote: > > On Tue, Jun 8, 2021 at 2:07 PM Jiri Olsa wrote: > > > > On Tue, Jun 08, 2021 at 11:49:03AM -0700, Alexei Starovoitov wrote: > > > On Tue, Jun 08, 2021 at 08:17:00PM +0200, Jiri Olsa wrote: > > > > On Tue, Jun 08, 2021 at 08:42:32AM -0700, Alexei Starovoitov wrote: > > > > > On Sat, Jun 5, 2021 at 4:11 AM Jiri Olsa wrote: > > > > > > > > > > > > Adding support to attach multiple functions to tracing program > > > > > > by using the link_create/link_update interface. > > > > > > > > > > > > Adding multi_btf_ids/multi_btf_ids_cnt pair to link_create struct > > > > > > API, that define array of functions btf ids that will be attached > > > > > > to prog_fd. > > > > > > > > > > > > The prog_fd needs to be multi prog tracing program (BPF_F_MULTI_FUNC). > > > > > > > > > > > > The new link_create interface creates new BPF_LINK_TYPE_TRACING_MULTI > > > > > > link type, which creates separate bpf_trampoline and registers it > > > > > > as direct function for all specified btf ids. > > > > > > > > > > > > The new bpf_trampoline is out of scope (bpf_trampoline_lookup) of > > > > > > standard trampolines, so all registered functions need to be free > > > > > > of direct functions, otherwise the link fails. > > > > > > > > > > Overall the api makes sense to me. > > > > > The restriction of multi vs non-multi is too severe though. > > > > > The multi trampoline can serve normal fentry/fexit too. > > > > > > > > so multi trampoline gets called from all the registered functions, > > > > so there would need to be filter for specific ip before calling the > > > > standard program.. single cmp/jnz might not be that bad, I'll check > > > > > > You mean reusing the same multi trampoline for all IPs and regenerating > > > it with a bunch of cmp/jnz checks? There should be a better way to scale. > > > Maybe clone multi trampoline instead? > > > IPs[1-10] will point to multi. > > > IP[11] will point to a clone of multi that serves multi prog and > > > fentry/fexit progs specific for that IP. > > > > ok, so we'd clone multi trampoline if there's request to attach > > standard trampoline to some IP from multi trampoline > > > > .. and transform currently attached standard trampoline for IP > > into clone of multi trampoline, if there's request to create > > multi trampoline that covers that IP > > yep. For every IP==btf_id there will be only two possible trampolines. > Should be easy enough to track and transition between them. > The standard fentry/fexit will only get negligible slowdown from > going through multi. > multi+fexit and fmod_ret needs to be thought through as well. > That's why I thought that 'ip' at the end should simplify things. Putting ip at the end has downsides. We might support >6 arguments eventually, at which point it will be super weird to have 6 args, ip, then the rest of arguments?.. Would it be too bad to put IP at -8 offset relative to ctx? That will also work for normal fentry/fexit, for which it's useful to have ip passed in as well, IMO. So no special casing for multi/non-multi, and it's backwards compatible. Ideally, I'd love it to be actually retrievable through a new BPF helper, something like bpf_caller_ip(ctx), but I'm not sure if we can implement this sanely, so I don't hold high hopes. > Only multi will have access to it. > But we can store it first too. fentry/fexit will see ctx=r1 with +8 offset > and will have normal args in ctx. Like ip isn't even there. > While multi trampoline is always doing ip, arg1,arg2, .., arg6 > and passes ctx = &ip into multi prog and ctx = &arg1 into fentry/fexit. > 'ret' for fexit is problematic though. hmm. > Maybe such clone multi trampoline for specific ip with 2 args will do: > ip, arg1, arg2, ret, 0, 0, 0, ret. > Then multi will have 6 args, though 3rd is actually ret. > Then fexit will have ret in the right place and multi prog will have > it as 7th arg.