Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp699314pxb; Mon, 7 Feb 2022 23:52:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzYpn9oFqpbVBWh1mejv9OfhneZ+6s8bXbrDrieS0dsoDqduXoqGjCMBnVw3W0Wlwxek5fU X-Received: by 2002:a17:907:216d:: with SMTP id rl13mr2733988ejb.193.1644306762361; Mon, 07 Feb 2022 23:52:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644306762; cv=none; d=google.com; s=arc-20160816; b=TzoSBD3wx5w7IY52tigoc+kPs6RcmDkheLv+1kl/vKjOAZHfC97mqQL4NQCRNxzge+ 1br51UunTad6lNsjN580d8PXIgpTEFyuop/i2QMCrt5iL1fwOxiR9mkkKiWX+MpdlsOS QW9IC8wNDWD51TDpQgRVrsZyBWQAEfQtfcDjmP5+sNoeBTVAJ6/YLXBH/ZMCcOKvWJhd +WI6yJBpSI7Y3a6W+ouEvJbbbw77bsP3MJ40rko22mDmKVNaxmM+jpRpTsRMxeuAwftA QapazSqxJ0wLJbQIuTs+/BoZPspbKAzMTMZPuXEzLGZJepd7zMx/KsqG/MLB8G8n53pE 58nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=FwnKbpTkC/zdPmCdqrahzy52SJ9rfemmtNQ6qp1un1k=; b=Wkclggsz8K2P79XjuLu3p1TYpQ0Q2gV70h+x5/DW73YXY9KShGs2REDeIcjDUbhB/u yaoL56OjxSq7YWFS5TqlCx6QMEN64VuedivQ/OwY06BENuGoDFIiHkj6Kxr9itJT4KLy 4ZiLz2Z9hATsG5O95vRLLl40CSy/3yNZrdkHZGLH1A5rshJOxUJJ0YbRlmSvtzeGGta5 SA4NMOWuEGmEtlV9xL+y3tGQYrHe8emCCnLVCm1qPMAkgaD07oN5DJxvU8codG3n41xz 2j4mLgv5ORGCdkNPz2R0ftv6U3G9FY+s7kWp9xIS62Rwi8sz9YKuxMEMbJpp0ErCXzCF 207Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="mdBf/hKJ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o29si6794088edi.286.2022.02.07.23.52.15; Mon, 07 Feb 2022 23:52:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="mdBf/hKJ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232367AbiBGVBn (ORCPT + 99 others); Mon, 7 Feb 2022 16:01:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231667AbiBGVBl (ORCPT ); Mon, 7 Feb 2022 16:01:41 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61EBFC06173B; Mon, 7 Feb 2022 13:01:41 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id y9so6529477pjf.1; Mon, 07 Feb 2022 13:01:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FwnKbpTkC/zdPmCdqrahzy52SJ9rfemmtNQ6qp1un1k=; b=mdBf/hKJ/7B7hDsVbKCWNpdxhMkuPUxF+0PCUNUeV4B7/F0tSXEYtNLmofwufiy7PF 33C0zLeSB9ip82NjcKe5b1K+LgbtzGt5ubSD3HtaVAgQWZXb9eCelUPgZo0tNeCcouzO RQ748JIssLc69N49BLL6f88Ob9HZCEhToJOrFQdxPUlpAD4rySIQ7JwxmsOoYigL7BP0 YF25ZKf41yAUP7rj+PW/q/iI2ZXn4C5q4GgH1HUUF9Yjx7zTBYNdANKIxcInlwmvDcVo ubTnKttmQg1Exb5/EzkpePJSqpT1AANZxtpl5ligRT14obtT866fOsKHNfXrwGpoQF71 RA2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FwnKbpTkC/zdPmCdqrahzy52SJ9rfemmtNQ6qp1un1k=; b=wwyYQ68IuZlo5uasQKyKsMpsno3So6nQknmhVFlfEwicGLLmi6RsNOV32frrCMGxZF /rTDzQv+JqDxmAjXF/E6V02QYR8xBY8DcdNUi8Uqjg/F7JIocY6QzVbnAEf6lnt5T/48 j45e9VvM1psNnz/k+tT9jkEXJUDP2hPxQvAGXX5kPyghtujls1Bh0kh0ahxpZgMcikt7 PXtUBDQQ1YSNDxqrpZNhDP8gbMEnxmBW26DIyqj6OyuXKsPp1GlZQP7y2KDkhVDng0aw oUT8qzl6A6FVTrwLaufaH7GYDjDoT8zK99TmpbVpx8p8UmtfGaVSM12BJpxwtIXBzUD/ ywRg== X-Gm-Message-State: AOAM532MeyiAbcukS6wI4Fe+HpJt+caXpdqubUdMbcISNly9cQC77Nyh kUA4VkcVSbudyijY+4N/aymtnqhI317316uHaOI= X-Received: by 2002:a17:902:ced1:: with SMTP id d17mr1249891plg.78.1644267700768; Mon, 07 Feb 2022 13:01:40 -0800 (PST) MIME-Version: 1.0 References: <20220202135333.190761-1-jolsa@kernel.org> <20220202135333.190761-3-jolsa@kernel.org> In-Reply-To: From: Alexei Starovoitov Date: Mon, 7 Feb 2022 13:01:29 -0800 Message-ID: Subject: Re: [PATCH 2/8] bpf: Add bpf_get_func_ip kprobe helper for fprobe link To: Andrii Nakryiko Cc: Jiri Olsa , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Masami Hiramatsu , Networking , bpf , lkml , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Steven Rostedt , Jiri Olsa Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 7, 2022 at 10:59 AM Andrii Nakryiko wrote: > > On Wed, Feb 2, 2022 at 5:53 AM Jiri Olsa wrote: > > > > Adding support to call get_func_ip_fprobe helper from kprobe > > programs attached by fprobe link. > > > > Also adding support to inline it, because it's single load > > instruction. > > > > Signed-off-by: Jiri Olsa > > --- > > kernel/bpf/verifier.c | 19 ++++++++++++++++++- > > kernel/trace/bpf_trace.c | 16 +++++++++++++++- > > 2 files changed, 33 insertions(+), 2 deletions(-) > > > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > > index 1ae41d0cf96c..a745ded00635 100644 > > --- a/kernel/bpf/verifier.c > > +++ b/kernel/bpf/verifier.c > > @@ -13625,7 +13625,7 @@ static int do_misc_fixups(struct bpf_verifier_env *env) > > continue; > > } > > > > - /* Implement bpf_get_func_ip inline. */ > > + /* Implement tracing bpf_get_func_ip inline. */ > > if (prog_type == BPF_PROG_TYPE_TRACING && > > insn->imm == BPF_FUNC_get_func_ip) { > > /* Load IP address from ctx - 16 */ > > @@ -13640,6 +13640,23 @@ static int do_misc_fixups(struct bpf_verifier_env *env) > > continue; > > } > > > > + /* Implement kprobe/fprobe bpf_get_func_ip inline. */ > > + if (prog_type == BPF_PROG_TYPE_KPROBE && > > + eatype == BPF_TRACE_FPROBE && > > + insn->imm == BPF_FUNC_get_func_ip) { > > + /* Load IP address from ctx (struct pt_regs) ip */ > > + insn_buf[0] = BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, > > + offsetof(struct pt_regs, ip)); > > Isn't this architecture-specific? I'm starting to dislike this > inlining whole more and more. It's just a complication in verifier > without clear real-world benefits. We are clearly prematurely > optimizing here. In practice you'll just call bpf_get_func_ip() once > and that's it. Function call overhead will be negligible compare to > other *userful* work you'll be doing in your BPF program. We should be doing inlining when we can. Every bit of performance matters.