From: Steven Rostedt <rostedt@goodmis.org> To: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> Cc: Daniel Borkmann <daniel@iogearbox.net>, Yauheni Kaliuta <yauheni.kaliuta@redhat.com>, Jiri Olsa <jolsa@redhat.com>, Jordan Niethe <jniethe5@gmail.com>, bpf@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Alexei Starovoitov <alexei.starovoitov@gmail.com>, Hari Bathini <hbathini@linux.ibm.com> Subject: Re: [RFC PATCH 2/3] powerpc/ftrace: Override ftrace_location_lookup() for MPROFILE_KERNEL Date: Mon, 7 Feb 2022 10:24:54 -0500 [thread overview] Message-ID: <20220207102454.41b1d6b5@gandalf.local.home> (raw) In-Reply-To: <fadc5f2a295d6cb9f590bbbdd71fc2f78bf3a085.1644216043.git.naveen.n.rao@linux.vnet.ibm.com> On Mon, 7 Feb 2022 12:37:21 +0530 "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> wrote: > --- a/arch/powerpc/kernel/trace/ftrace.c > +++ b/arch/powerpc/kernel/trace/ftrace.c > @@ -1137,3 +1137,14 @@ char *arch_ftrace_match_adjust(char *str, const char *search) > return str; > } > #endif /* PPC64_ELF_ABI_v1 */ > + > +#ifdef CONFIG_MPROFILE_KERNEL > +unsigned long ftrace_location_lookup(unsigned long ip) > +{ > + /* > + * Per livepatch.h, ftrace location is always within the first > + * 16 bytes of a function on powerpc with -mprofile-kernel. > + */ > + return ftrace_location_range(ip, ip + 16); I think this is the wrong approach for the implementation and error prone. > +} > +#endif > -- What I believe is a safer approach is to use the record address and add the range to it. That is, you know that the ftrace modification site is a range (multiple instructions), where in the ftrace infrastructure, only one ip represents that range. What you want is if you pass in an ip, and that ip is within that range, you return the ip that represents that range to ftrace. It looks like we need to change the compare function in the bsearch. Perhaps add a new macro to define the size of the range to be searched, instead of just using MCOUNT_INSN_SIZE? Then we may not even need this new lookup function? static int ftrace_cmp_recs(const void *a, const void *b) { const struct dyn_ftrace *key = a; const struct dyn_ftrace *rec = b; if (key->flags < rec->ip) return -1; if (key->ip >= rec->ip + ARCH_IP_SIZE) return 1; return 0; } Where ARCH_IP_SIZE is defined to MCOUNT_INSN_SIZE by default, but an arch could define it to something else, like 16. Would that work for you, or am I missing something? -- Steve
WARNING: multiple messages have this Message-ID (diff)
From: Steven Rostedt <rostedt@goodmis.org> To: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> Cc: Daniel Borkmann <daniel@iogearbox.net>, Alexei Starovoitov <alexei.starovoitov@gmail.com>, Michael Ellerman <mpe@ellerman.id.au>, <bpf@vger.kernel.org>, <linuxppc-dev@lists.ozlabs.org>, Yauheni Kaliuta <yauheni.kaliuta@redhat.com>, Hari Bathini <hbathini@linux.ibm.com>, Jordan Niethe <jniethe5@gmail.com>, Jiri Olsa <jolsa@redhat.com> Subject: Re: [RFC PATCH 2/3] powerpc/ftrace: Override ftrace_location_lookup() for MPROFILE_KERNEL Date: Mon, 7 Feb 2022 10:24:54 -0500 [thread overview] Message-ID: <20220207102454.41b1d6b5@gandalf.local.home> (raw) In-Reply-To: <fadc5f2a295d6cb9f590bbbdd71fc2f78bf3a085.1644216043.git.naveen.n.rao@linux.vnet.ibm.com> On Mon, 7 Feb 2022 12:37:21 +0530 "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> wrote: > --- a/arch/powerpc/kernel/trace/ftrace.c > +++ b/arch/powerpc/kernel/trace/ftrace.c > @@ -1137,3 +1137,14 @@ char *arch_ftrace_match_adjust(char *str, const char *search) > return str; > } > #endif /* PPC64_ELF_ABI_v1 */ > + > +#ifdef CONFIG_MPROFILE_KERNEL > +unsigned long ftrace_location_lookup(unsigned long ip) > +{ > + /* > + * Per livepatch.h, ftrace location is always within the first > + * 16 bytes of a function on powerpc with -mprofile-kernel. > + */ > + return ftrace_location_range(ip, ip + 16); I think this is the wrong approach for the implementation and error prone. > +} > +#endif > -- What I believe is a safer approach is to use the record address and add the range to it. That is, you know that the ftrace modification site is a range (multiple instructions), where in the ftrace infrastructure, only one ip represents that range. What you want is if you pass in an ip, and that ip is within that range, you return the ip that represents that range to ftrace. It looks like we need to change the compare function in the bsearch. Perhaps add a new macro to define the size of the range to be searched, instead of just using MCOUNT_INSN_SIZE? Then we may not even need this new lookup function? static int ftrace_cmp_recs(const void *a, const void *b) { const struct dyn_ftrace *key = a; const struct dyn_ftrace *rec = b; if (key->flags < rec->ip) return -1; if (key->ip >= rec->ip + ARCH_IP_SIZE) return 1; return 0; } Where ARCH_IP_SIZE is defined to MCOUNT_INSN_SIZE by default, but an arch could define it to something else, like 16. Would that work for you, or am I missing something? -- Steve
next prev parent reply other threads:[~2022-02-07 15:28 UTC|newest] Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-02-07 7:07 [RFC PATCH 0/3] powerpc64/bpf: Add support for BPF Trampolines Naveen N. Rao 2022-02-07 7:07 ` Naveen N. Rao 2022-02-07 7:07 ` [RFC PATCH 1/3] ftrace: Add ftrace_location_lookup() to lookup address of ftrace location Naveen N. Rao 2022-02-07 7:07 ` Naveen N. Rao 2022-02-07 7:07 ` [RFC PATCH 2/3] powerpc/ftrace: Override ftrace_location_lookup() for MPROFILE_KERNEL Naveen N. Rao 2022-02-07 7:07 ` Naveen N. Rao 2022-02-07 15:24 ` Steven Rostedt [this message] 2022-02-07 15:24 ` Steven Rostedt 2022-02-09 17:50 ` Naveen N. Rao 2022-02-09 17:50 ` Naveen N. Rao 2022-02-09 21:10 ` Steven Rostedt 2022-02-09 21:10 ` Steven Rostedt 2022-02-10 13:58 ` Naveen N. Rao 2022-02-10 13:58 ` Naveen N. Rao 2022-02-10 14:59 ` Steven Rostedt 2022-02-10 14:59 ` Steven Rostedt 2022-02-10 16:40 ` Naveen N. Rao 2022-02-10 16:40 ` Naveen N. Rao 2022-02-10 17:01 ` Steven Rostedt 2022-02-10 17:01 ` Steven Rostedt 2022-02-11 11:36 ` Naveen N. Rao 2022-02-11 11:36 ` Naveen N. Rao 2022-02-07 7:07 ` [RFC PATCH 3/3] powerpc64/bpf: Add support for bpf trampolines Naveen N. Rao 2022-02-07 7:07 ` Naveen N. Rao 2022-02-11 14:40 ` [RFC PATCH 0/3] powerpc64/bpf: Add support for BPF Trampolines Christophe Leroy 2022-02-11 14:40 ` Christophe Leroy 2022-02-14 10:47 ` Naveen N. Rao 2022-02-14 10:47 ` Naveen N. Rao
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220207102454.41b1d6b5@gandalf.local.home \ --to=rostedt@goodmis.org \ --cc=alexei.starovoitov@gmail.com \ --cc=bpf@vger.kernel.org \ --cc=daniel@iogearbox.net \ --cc=hbathini@linux.ibm.com \ --cc=jniethe5@gmail.com \ --cc=jolsa@redhat.com \ --cc=linuxppc-dev@lists.ozlabs.org \ --cc=naveen.n.rao@linux.vnet.ibm.com \ --cc=yauheni.kaliuta@redhat.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.