Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1297155rwd; Thu, 8 Jun 2023 15:54:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4NkKYFtGSKXq5wS4Tm82FQuTwjmjDRm3kBrEqqCojbJDb3lxdanYLz1R3Cl78MpGBeDFAs X-Received: by 2002:a05:6a21:7888:b0:105:2e9e:b13a with SMTP id bf8-20020a056a21788800b001052e9eb13amr102179pzc.8.1686264852223; Thu, 08 Jun 2023 15:54:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686264852; cv=none; d=google.com; s=arc-20160816; b=tFUorpRpINnbWHspeM0meQjrQlyJs08RDcudWUggunkVzzZb4ASlwzrQP2TokND/L4 71zRIb7NTOmq4cRhSuruSsluoROenjiIIHxIjitZFRWXhOiKtnm341Cu3GMB0rqsIvV8 H74WzTSbO78DqbbgRopwTY6eSiuEcZMfFiVBRFv7HPGinePSh4qphvQdT1FseP7GEcmL KfUvv2Vh17oE1lxrwYidkgxZ26FVBAUkcnyP2gONvWWy9lNuvICN9Yk1Z+sMGuzanw0s hZ5P9oXVVP/T2Ol/q4f+HXSq9Qe2Q/oGc8z7olpxY1KZke4pqAhqzDHUuRMkRTG9Gxxl rqEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=nNrbQrLzaDyIVZlVtGLtW2jLk0N+5CabOX0/0BQtIdw=; b=jUJDqFdsOOzTuxWAek6VFHkTM5FlpLVsN2EDmMhsA7Y8oEugqAuCEka3FJT7kGU0kA GE5dUZlzn/iyusVtqENb6lQfUPuHigr4IzpvyKsHE86/Z0Ozjw+WN9JYEbXAYKicdwci ASauRFJKcA2lqelG/rp3pt1k5oG0OMszByXCdqmHJIuOiQ0lrgkimcxO0EcJo4Zj7KaF kdhmhyNseTIx7yk/nYReKc4rtYoE9fRSOhrAL7NF74gfN3TYubQrvsqrXod47v104Xcd lxAG2M1+PC6w9BjKNoXxHbGEBBX3V/DWEK5yoHbEKTEfTRv/aViL+EC1S2Iej6WBxc12 7fRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Z8oBiTuS; 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 y72-20020a638a4b000000b005211941267asi1622426pgd.153.2023.06.08.15.53.59; Thu, 08 Jun 2023 15:54:12 -0700 (PDT) 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=20221208 header.b=Z8oBiTuS; 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 S236809AbjFHWnZ (ORCPT + 99 others); Thu, 8 Jun 2023 18:43:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229503AbjFHWnX (ORCPT ); Thu, 8 Jun 2023 18:43:23 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CEC02D51; Thu, 8 Jun 2023 15:43:17 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-5149390b20aso1993631a12.3; Thu, 08 Jun 2023 15:43:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686264195; x=1688856195; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=nNrbQrLzaDyIVZlVtGLtW2jLk0N+5CabOX0/0BQtIdw=; b=Z8oBiTuSmda8WfrnWpSBXAFblGJZQhW+0gngR6wRk7rrGg7SictdrYmBd3xkFewYo8 V3PSBTjd9MB1aSMDSeHmVSRelYw+nb8rnTDPXiejzg3Hj0FRIL2IQKrMBu5WFqz3qDsH 4J68L2N6MPRx6sESdlsfwHJfOYVBMUbMLMKNW9qRzzuwWm8lyTV16OwYQ2b/E+EQsUmD trKPFvuBONhEsf+mPRlMrWfit/IfDDIU77VsHld20ghn7ipbcNDaE35yvVUBQbTEthli 4pimfH8SlDCJoxXSzR0Vxhfahm4QiphI3OgMBuuKgUt2MSupdb0YglLhsFGbeKX1Ey8R rxQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686264195; x=1688856195; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nNrbQrLzaDyIVZlVtGLtW2jLk0N+5CabOX0/0BQtIdw=; b=Xx7pG1xbEXR+cV5fe5rkBJmFnZr/WljT+w57D6ufB0SUAIzkhdxtBxTCmMqeJOGngM 9vt4EDLVqIEI0C4UkLChMCLqxv6QMBJGXeaNfkkynI/FcJvvzWhDSBU/lHUsKqRGTUPs d5HGpqdnPTqzBmxFBTjZBhTwoflimiXTWiuP/nD1YoUfyPZDuRLTVaNQmtnCyjPTYnve TCNItvubounYcuT8EjLu2VSk0NMVq7NxBfk4gudCg6ZVy/f5lzsJ9WUDiURGfseQdhS6 OYhYjvIAiQKrVERXyELaCYKDbPquKD1kD4T8gxeC5JAFpDXM0F5RDdSc/m0ivubcOcmx NAfA== X-Gm-Message-State: AC+VfDziT5pYvflE6AI+ChJVMpAgtZeeTIxK4A4z1DQvEG46T+AYjDEn K8nMnswq/27arqu/zcOC3ufh9JYfeFZl3nf5BEs= X-Received: by 2002:a17:907:5c1:b0:965:fb87:4215 with SMTP id wg1-20020a17090705c100b00965fb874215mr514444ejb.15.1686264195492; Thu, 08 Jun 2023 15:43:15 -0700 (PDT) MIME-Version: 1.0 References: <20230608212613.424070-1-jolsa@kernel.org> In-Reply-To: <20230608212613.424070-1-jolsa@kernel.org> From: Andrii Nakryiko Date: Thu, 8 Jun 2023 15:43:03 -0700 Message-ID: Subject: Re: [PATCH RFC] ftrace: Show all functions with addresses in available_filter_functions_addrs To: Jiri Olsa Cc: Steven Rostedt , Masami Hiramatsu , Mark Rutland , Andrii Nakryiko , lkml , linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org, Jackie Liu Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 Thu, Jun 8, 2023 at 2:26=E2=80=AFPM Jiri Olsa wrote: > > > hi, > when ftrace based tracers we need to cross check available_filter_functio= ns > with /proc/kallsyms. For example for kprobe_multi bpf link (based on fpro= be) > we need to make sure that symbol regex resolves to traceable symbols and > that we get proper addresses for them. > > Looks like on the last last LSF/MM/BPF there was an agreement to add new > file that will have available_filter_functions symbols plus addresses. > > This RFC is to kick off the discussion, I'm not sure Steven wants to do > that differently ;-) > > thanks, > jirka > > > --- > Adding new available_filter_functions_addrs file that shows all available > functions (same as available_filter_functions) together with addresses, > like: > > # cat available_filter_functions_addrs | head nit: can we have some more succinct name, like "traceable_funcs" or something? And btw, does this have to be part of tracefs/debugfs (never knew the difference, sorry). E.g., can it be instead exposed through sysfs? Either than these minor things, yep, I think this is something that would be extremely useful, thanks, Jiri, for taking a stab at it! > ffffffff81000770 __traceiter_initcall_level > ffffffff810007c0 __traceiter_initcall_start > ffffffff81000810 __traceiter_initcall_finish > ffffffff81000860 trace_initcall_finish_cb > ... > > It's useful to have address avilable for traceable symbols, so we don't > need to allways cross check kallsyms with available_filter_functions > (or the other way around) and have all the data in single file. > > For backwards compatibility reasons we can't change the existing > available_filter_functions file output, but we need to add new file. > > Suggested-by: Steven Rostedt (Google) > Suggested-by: Andrii Nakryiko > Signed-off-by: Jiri Olsa > --- > include/linux/ftrace.h | 1 + > kernel/trace/ftrace.c | 52 ++++++++++++++++++++++++++++++++++++++---- > 2 files changed, 48 insertions(+), 5 deletions(-) > > diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h > index b23bdd414394..6e372575a8e9 100644 > --- a/include/linux/ftrace.h > +++ b/include/linux/ftrace.h > @@ -633,6 +633,7 @@ enum { > FTRACE_ITER_MOD =3D (1 << 5), > FTRACE_ITER_ENABLED =3D (1 << 6), > FTRACE_ITER_TOUCHED =3D (1 << 7), > + FTRACE_ITER_ADDRS =3D (1 << 8), > }; > > void arch_ftrace_update_code(int command); > diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c > index 764668467155..1f33e1f04834 100644 > --- a/kernel/trace/ftrace.c > +++ b/kernel/trace/ftrace.c > @@ -3804,7 +3804,7 @@ static int __init ftrace_check_sync(void) > late_initcall_sync(ftrace_check_sync); > subsys_initcall(ftrace_check_for_weak_functions); > > -static int print_rec(struct seq_file *m, unsigned long ip) > +static int print_rec(struct seq_file *m, unsigned long ip, bool print_ad= dr) > { > unsigned long offset; > char str[KSYM_SYMBOL_LEN]; > @@ -3819,7 +3819,11 @@ static int print_rec(struct seq_file *m, unsigned = long ip) > ret =3D NULL; > } > > - seq_puts(m, str); > + if (print_addr) > + seq_printf(m, "%lx %s", ip, str); > + else > + seq_puts(m, str); > + > if (modname) > seq_printf(m, " [%s]", modname); > return ret =3D=3D NULL ? -1 : 0; > @@ -3830,9 +3834,13 @@ static inline int test_for_valid_rec(struct dyn_ft= race *rec) > return 1; > } > > -static inline int print_rec(struct seq_file *m, unsigned long ip) > +static inline int print_rec(struct seq_file *m, unsigned long ip, bool p= rint_addr) > { > - seq_printf(m, "%ps", (void *)ip); > + if (print_addr) > + seq_printf(m, "%lx %ps", ip, (void *)ip); > + else > + seq_printf(m, "%ps", (void *)ip); > + > return 0; > } > #endif > @@ -3861,7 +3869,7 @@ static int t_show(struct seq_file *m, void *v) > if (!rec) > return 0; > > - if (print_rec(m, rec->ip)) { > + if (print_rec(m, rec->ip, iter->flags & FTRACE_ITER_ADDRS)) { > /* This should only happen when a rec is disabled */ > WARN_ON_ONCE(!(rec->flags & FTRACE_FL_DISABLED)); > seq_putc(m, '\n'); > @@ -3996,6 +4004,30 @@ ftrace_touched_open(struct inode *inode, struct fi= le *file) > return 0; > } > > +static int > +ftrace_avail_addrs_open(struct inode *inode, struct file *file) > +{ > + struct ftrace_iterator *iter; > + int ret; > + > + ret =3D security_locked_down(LOCKDOWN_TRACEFS); > + if (ret) > + return ret; > + > + if (unlikely(ftrace_disabled)) > + return -ENODEV; > + > + iter =3D __seq_open_private(file, &show_ftrace_seq_ops, sizeof(*i= ter)); > + if (!iter) > + return -ENOMEM; > + > + iter->pg =3D ftrace_pages_start; > + iter->flags =3D FTRACE_ITER_ADDRS; > + iter->ops =3D &global_ops; > + > + return 0; > +} > + > /** > * ftrace_regex_open - initialize function tracer filter files > * @ops: The ftrace_ops that hold the hash filters > @@ -5916,6 +5948,13 @@ static const struct file_operations ftrace_touched= _fops =3D { > .release =3D seq_release_private, > }; > > +static const struct file_operations ftrace_avail_addrs_fops =3D { > + .open =3D ftrace_avail_addrs_open, > + .read =3D seq_read, > + .llseek =3D seq_lseek, > + .release =3D seq_release_private, > +}; > + > static const struct file_operations ftrace_filter_fops =3D { > .open =3D ftrace_filter_open, > .read =3D seq_read, > @@ -6377,6 +6416,9 @@ static __init int ftrace_init_dyn_tracefs(struct de= ntry *d_tracer) > trace_create_file("available_filter_functions", TRACE_MODE_READ, > d_tracer, NULL, &ftrace_avail_fops); > > + trace_create_file("available_filter_functions_addrs", TRACE_MODE_= READ, > + d_tracer, NULL, &ftrace_avail_addrs_fops); > + > trace_create_file("enabled_functions", TRACE_MODE_READ, > d_tracer, NULL, &ftrace_enabled_fops); > > -- > 2.40.1 >