From: Jiri Olsa <jolsa@redhat.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: "Jiri Olsa" <jolsa@kernel.org>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andriin@fb.com>,
"Michael Ellerman" <mpe@ellerman.id.au>,
"Naveen N . Rao" <naveen.n.rao@linux.vnet.ibm.com>,
Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
"Martin KaFai Lau" <kafai@fb.com>,
"Song Liu" <songliubraving@fb.com>, "Yonghong Song" <yhs@fb.com>,
"John Fastabend" <john.fastabend@gmail.com>,
"KP Singh" <kpsingh@chromium.org>,
"Toke Høiland-Jørgensen" <toke@redhat.com>,
"Yauheni Kaliuta" <ykaliuta@redhat.com>
Subject: Re: [PATCHv2 bpf-next] selftests/bpf: Fix test_attach_probe for powerpc uprobes
Date: Sun, 7 Mar 2021 12:12:31 +0100 [thread overview]
Message-ID: <YES1HwAheriyuT6w@krava> (raw)
In-Reply-To: <CAEf4BzanY2ogGDORCsOXrAivWii06vsUpJFT7rQy2nj0xarm+A@mail.gmail.com>
On Sat, Mar 06, 2021 at 07:13:17PM -0800, Andrii Nakryiko wrote:
> On Fri, Mar 5, 2021 at 5:42 AM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > When testing uprobes we the test gets GEP (Global Entry Point)
> > address from kallsyms, but then the function is called locally
> > so the uprobe is not triggered.
> >
> > Fixing this by adjusting the address to LEP (Local Entry Point)
> > for powerpc arch plus instruction check stolen from ppc_function_entry
> > function pointed out and explained by Michael and Naveen.
> >
> > Cc: Michael Ellerman <mpe@ellerman.id.au>
> > Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> > .../selftests/bpf/prog_tests/attach_probe.c | 40 ++++++++++++++++++-
> > 1 file changed, 39 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/bpf/prog_tests/attach_probe.c b/tools/testing/selftests/bpf/prog_tests/attach_probe.c
> > index a0ee87c8e1ea..9dc4e3dfbcf3 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/attach_probe.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/attach_probe.c
> > @@ -2,6 +2,44 @@
> > #include <test_progs.h>
> > #include "test_attach_probe.skel.h"
> >
> > +#if defined(__powerpc64__) && defined(_CALL_ELF) && _CALL_ELF == 2
> > +
> > +#define OP_RT_RA_MASK 0xffff0000UL
> > +#define LIS_R2 0x3c400000UL
> > +#define ADDIS_R2_R12 0x3c4c0000UL
> > +#define ADDI_R2_R2 0x38420000UL
> > +
> > +static ssize_t get_offset(ssize_t addr, ssize_t base)
> > +{
> > + u32 *insn = (u32 *) addr;
> > +
> > + /*
> > + * A PPC64 ABIv2 function may have a local and a global entry
> > + * point. We need to use the local entry point when patching
> > + * functions, so identify and step over the global entry point
> > + * sequence.
> > + *
> > + * The global entry point sequence is always of the form:
> > + *
> > + * addis r2,r12,XXXX
> > + * addi r2,r2,XXXX
> > + *
> > + * A linker optimisation may convert the addis to lis:
> > + *
> > + * lis r2,XXXX
> > + * addi r2,r2,XXXX
> > + */
> > + if ((((*insn & OP_RT_RA_MASK) == ADDIS_R2_R12) ||
> > + ((*insn & OP_RT_RA_MASK) == LIS_R2)) &&
> > + ((*(insn + 1) & OP_RT_RA_MASK) == ADDI_R2_R2))
> > + return (ssize_t)(insn + 2) - base;
> > + else
> > + return addr - base;
> > +}
> > +#else
> > +#define get_offset(addr, base) (addr - base)
>
> I turned this into a static function, not sure why you preferred
seemed simple enough to be dealt with in preprocessor,
why bother compiler ;-)
> #define here. Applied to bpf-next.
thanks,
jirka
next prev parent reply other threads:[~2021-03-07 11:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-05 13:40 [PATCHv2 bpf-next] selftests/bpf: Fix test_attach_probe for powerpc uprobes Jiri Olsa
2021-03-07 3:13 ` Andrii Nakryiko
2021-03-07 11:12 ` Jiri Olsa [this message]
2021-03-08 10:44 ` 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=YES1HwAheriyuT6w@krava \
--to=jolsa@redhat.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kafai@fb.com \
--cc=kpsingh@chromium.org \
--cc=mpe@ellerman.id.au \
--cc=naveen.n.rao@linux.vnet.ibm.com \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.com \
--cc=toke@redhat.com \
--cc=yhs@fb.com \
--cc=ykaliuta@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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox