From: Yafang Shao <laoar.shao@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@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@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>,
Masami Hiramatsu <mhiramat@kernel.org>, bpf <bpf@vger.kernel.org>,
linux-trace-kernel@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH bpf-next 5/6] bpf: Improve tracing recursion prevention mechanism
Date: Thu, 27 Apr 2023 20:35:45 +0800 [thread overview]
Message-ID: <CALOAHbCXRwp9--MV2k8z3aJyAL6vzQLimtHgkeza7g0C=Edb8g@mail.gmail.com> (raw)
In-Reply-To: <CALOAHbAqsSq+gVg9xTYGAkrdZaFXc=PVoOYqej33dCEjWtHfFw@mail.gmail.com>
On Thu, Apr 27, 2023 at 8:15 PM Yafang Shao <laoar.shao@gmail.com> wrote:
>
> On Thu, Apr 27, 2023 at 5:57 PM Yafang Shao <laoar.shao@gmail.com> wrote:
> >
> > On Tue, Apr 25, 2023 at 5:40 AM Steven Rostedt <rostedt@goodmis.org> wrote:
> > >
> > > On Wed, 19 Apr 2023 15:46:34 -0700
> > > Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:
> > >
> > > > No. Just one prog at entry into any of the kernel functions
> > > > and another prog at entry of funcs that 1st bpf prog called indirectly.
> > > > Like one prog is tracing networking events while another
> > > > is focusing on mm. They should not conflict.
> > >
> > > You mean that you have:
> > >
> > > function start:
> > > __bpf_prog_enter_recur()
> > > bpf_program1()
> > > __bpf_prog_enter_recur()
> > > bpf_program2();
> > > __bpf_prog_exit_recur()
> > > __bpf_prog_exit_recur()
> > >
> > > rest of function
> > >
> > > That is, a bpf program can be called within another bpf pogram between
> > > the prog_enter and prog_exit(), that is in the same context (normal,
> > > softirq, irq, etc)?
> > >
> >
> > Right, that can happen per my verification. Below is a simple bpf
> > program to verify it.
> >
> > struct {
> > __uint(type, BPF_MAP_TYPE_LPM_TRIE);
> > __type(key, __u64);
> > __type(value, __u64);
> > __uint(max_entries, 1024);
> > __uint(map_flags, BPF_F_NO_PREALLOC);
> > } write_map SEC(".maps");
> >
> > __u64 key;
> >
> > SEC("fentry/kernel_clone")
> > int program1()
> > {
> > __u64 value = 1;
> >
> > bpf_printk("before update");
> > // It will call trie_update_elem and thus trigger program2.
> > bpf_map_update_elem(&write_map, &key, &value, BPF_ANY);
> > __sync_fetch_and_add(&key, 1);
> > bpf_printk("after update");
> > return 0;
> > }
> >
> > SEC("fentry/trie_update_elem")
> > int program2()
> > {
> > bpf_printk("trie_update_elem");
> > return 0;
> > }
> >
> > The result as follows,
> >
> > kubelet-203203 [018] ....1 9579.862862:
> > __bpf_prog_enter_recur: __bpf_prog_enter_recur
> > kubelet-203203 [018] ...11 9579.862869: bpf_trace_printk:
> > before update
> > kubelet-203203 [018] ....2 9579.862869:
> > __bpf_prog_enter_recur: __bpf_prog_enter_recur
> > kubelet-203203 [018] ...12 9579.862870: bpf_trace_printk:
> > trie_update_elem
> > kubelet-203203 [018] ....2 9579.862870:
> > __bpf_prog_exit_recur: __bpf_prog_exit_recur
> > kubelet-203203 [018] ...11 9579.862870: bpf_trace_printk:
> > after update
> > kubelet-203203 [018] ....1 9579.862871:
> > __bpf_prog_exit_recur: __bpf_prog_exit_recur
> >
> > Note that we can't trace __bpf_prog_enter_recur and
> > __bpf_prog_exit_recur, so we have to modify the kernel to print them.
> >
>
> ... However, surprisingly it still works even after this patchset is
> applied, because the hardirq/softirq flag is set when the program2 is
> running, see also the flags in the above trace_pipe output. Is that
> expected ?!
> I need some time to figure it out, but maybe you have a quick answer...
Answer it by myself, that is because of the
allowing-one-single-recursion rule. I misread the trace flags before.
Sorry about the noise.
--
Regards
Yafang
next prev parent reply other threads:[~2023-04-27 12:36 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-17 15:47 [PATCH bpf-next 0/6] bpf: Tracing recursion prevention mechanism improvement Yafang Shao
2023-04-17 15:47 ` [PATCH bpf-next 1/6] bpf: Add __rcu_read_{lock,unlock} into btf id deny list Yafang Shao
2023-04-17 15:47 ` [PATCH bpf-next 2/6] tracing: Add generic test_recursion_try_acquire() Yafang Shao
2023-04-20 6:51 ` Masami Hiramatsu
2023-04-17 15:47 ` [PATCH bpf-next 3/6] tracing: Add the comment for allowing one single recursion in process context Yafang Shao
2023-04-17 15:47 ` [PATCH bpf-next 4/6] selftests/bpf: Allow one single recursion in fentry recursion test Yafang Shao
2023-04-17 15:47 ` [PATCH bpf-next 5/6] bpf: Improve tracing recursion prevention mechanism Yafang Shao
2023-04-17 20:14 ` Alexei Starovoitov
2023-04-18 1:49 ` Yafang Shao
2023-04-18 15:38 ` Alexei Starovoitov
2023-04-19 11:46 ` Yafang Shao
[not found] ` <CAADnVQ+FO-+1OALTtgVkcpH3Adc6xS9qjzORyq2vwVtwY2UoxQ@mail.gmail.com>
2023-04-24 21:40 ` Steven Rostedt
2023-04-27 9:57 ` Yafang Shao
2023-04-27 12:15 ` Yafang Shao
2023-04-27 12:35 ` Yafang Shao [this message]
2023-04-17 23:29 ` kernel test robot
2023-04-27 13:26 ` Steven Rostedt
2023-04-27 14:22 ` Yafang Shao
2023-04-27 15:18 ` Steven Rostedt
2023-04-27 15:23 ` Yafang Shao
2023-04-27 15:36 ` Steven Rostedt
2023-04-27 15:39 ` Alexei Starovoitov
2023-04-27 15:43 ` Yafang Shao
2023-04-27 15:46 ` Steven Rostedt
2023-04-17 15:47 ` [PATCH bpf-next 6/6] bpf: Remove some denied functions from the btf id deny list Yafang Shao
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='CALOAHbCXRwp9--MV2k8z3aJyAL6vzQLimtHgkeza7g0C=Edb8g@mail.gmail.com' \
--to=laoar.shao@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
--cc=sdf@google.com \
--cc=songliubraving@fb.com \
--cc=yhs@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).