From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Hengqi Chen <hengqi.chen@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Andrii Nakryiko <andrii@kernel.org>,
Song Liu <songliubraving@fb.com>
Subject: Re: [PATCH bpf-next] libbpf: Allow kprobe attach using legacy debugfs interface
Date: Thu, 31 Mar 2022 10:29:48 -0700 [thread overview]
Message-ID: <CAEf4Bzb=v12ajT5xwwSGwjJu25JX0hWh1WzAxQkBW9+_B-Ynzw@mail.gmail.com> (raw)
In-Reply-To: <9c3aece7-84d1-9fd6-76f0-acb2dd9597a9@gmail.com>
On Tue, Mar 29, 2022 at 8:03 PM Hengqi Chen <hengqi.chen@gmail.com> wrote:
>
>
>
> On 2022/3/30 10:50 AM, Andrii Nakryiko wrote:
> > On Tue, Mar 29, 2022 at 7:30 PM Hengqi Chen <hengqi.chen@gmail.com> wrote:
> >>
> >> Hello, Andrii
> >>
> >> On 2022/3/30 7:18 AM, Andrii Nakryiko wrote:
> >>> On Sat, Mar 26, 2022 at 7:43 AM Hengqi Chen <hengqi.chen@gmail.com> wrote:
> >>>>
> >>>> On some old kernels, kprobe auto-attach may fail when attach to symbols
> >>>> like udp_send_skb.isra.52 . This is because the kernel has kprobe PMU
> >>>> but don't allow attach to a symbol with '.' ([0]). Add a new option to
> >>>> bpf_kprobe_opts to allow using the legacy kprobe attach directly.
> >>>> This way, users can use bpf_program__attach_kprobe_opts in a dedicated
> >>>> custom sec handler to handle such case.
> >>>>
> >>>> [0]: https://github.com/torvalds/linux/blob/v4.18/kernel/trace/trace_kprobe.c#L340-L343
> >>>>
> >>>> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
> >>>> ---
> >>>
> >>> It's sad, but it makes sense. But, let's have a selftests that
> >>> validates uses legacy option explicitly (e.g., in
> >>> prog_tests/attach_probe.c). Also, let's fix this limitation in the
> >>
> >> OK, will add a selftest to exercise the new option.
> >>
> >>> kernel? It makes no sense to limit attaching to a proper kallsym
> >>> symbol.
> >>
> >> This limitation is lifted in newer kernel. Kernel v5.4 don't have this issue.
> >
> > Oh, ok. So how about another plan of attack then: if kprobe target
> > function has '.' *and* we are on the kernel that doesn't support that,
> > switch to legacy kprobe automatically? No need for a new option,
> > libbpf handles this transparently.
> >
>
> That's better, and also eliminate the need for custom SEC() handler.
>
> > Still need a test for kprobe with '.' in it, though not sure how
> > reliable that will be... We can use kallsyms cache to check if
> > expected xxx.isra.0 (or whatever) is present, and if not - skip
> > subtest?
> >
>
> Not sure how to do that. Even if such symbol exists, how to reliably
> trigger it is another problem.
In addition to what Alan proposed, which relies on compiler to do this
whole isra thingy. I wonder if we can just create an alias symbol with
dots in its name? I haven't tried, but would be curious to see if that
works in bpf_testmod.
>
> >>
> >>>
> >>>> tools/lib/bpf/libbpf.c | 9 ++++++++-
> >>>> tools/lib/bpf/libbpf.h | 4 +++-
> >>>> 2 files changed, 11 insertions(+), 2 deletions(-)
> >>>>
> >>>
> >>> [...]
> >>
> >> --
> >> Hengqi
prev parent reply other threads:[~2022-03-31 17:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-26 14:43 [PATCH bpf-next] libbpf: Allow kprobe attach using legacy debugfs interface Hengqi Chen
2022-03-29 23:18 ` Andrii Nakryiko
2022-03-30 2:30 ` Hengqi Chen
2022-03-30 2:50 ` Andrii Nakryiko
2022-03-30 3:03 ` Hengqi Chen
2022-03-31 9:27 ` Alan Maguire
2022-03-31 13:34 ` Hengqi Chen
2022-03-31 17:29 ` Andrii Nakryiko [this message]
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='CAEf4Bzb=v12ajT5xwwSGwjJu25JX0hWh1WzAxQkBW9+_B-Ynzw@mail.gmail.com' \
--to=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=hengqi.chen@gmail.com \
--cc=songliubraving@fb.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;
as well as URLs for NNTP newsgroup(s).