From: Peter Zijlstra <peterz@infradead.org>
To: Song Liu <songliubraving@fb.com>
Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
acme@kernel.org, mingo@redhat.com, kjain@linux.ibm.com,
kernel-team@fb.com
Subject: Re: [PATCH v3 bpf-next 2/3] bpf: introduce helper bpf_get_branch_snapshot
Date: Tue, 31 Aug 2021 17:32:11 +0200 [thread overview]
Message-ID: <YS5LexDSokkcOJ7O@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20210830214106.4142056-3-songliubraving@fb.com>
On Mon, Aug 30, 2021 at 02:41:05PM -0700, Song Liu wrote:
> @@ -564,6 +565,18 @@ static void notrace inc_misses_counter(struct bpf_prog *prog)
> u64 notrace __bpf_prog_enter(struct bpf_prog *prog)
> __acquires(RCU)
> {
preempt_disable_notrace();
> +#ifdef CONFIG_PERF_EVENTS
> + /* Calling migrate_disable costs two entries in the LBR. To save
> + * some entries, we call perf_snapshot_branch_stack before
> + * migrate_disable to save some entries. This is OK because we
> + * care about the branch trace before entering the BPF program.
> + * If migrate happens exactly here, there isn't much we can do to
> + * preserve the data.
> + */
> + if (prog->call_get_branch)
> + static_call(perf_snapshot_branch_stack)(
> + this_cpu_ptr(&bpf_perf_branch_snapshot));
Here the comment is accurate, but if you recall the calling context
requirements of perf_snapshot_branch_stack from the last patch, you'll
see it requires you have at the very least preemption disabled, which
you just violated.
I think you'll find that (on x86 at least) the suggested
preempt_disable_notrace() incurs no additional branches.
Still, there is the next point to consider...
> +#endif
> rcu_read_lock();
> migrate_disable();
preempt_enable_notrace();
> if (unlikely(__this_cpu_inc_return(*(prog->active)) != 1)) {
> @@ -1863,9 +1892,23 @@ void bpf_put_raw_tracepoint(struct bpf_raw_event_map *btp)
> preempt_enable();
> }
>
> +DEFINE_PER_CPU(struct perf_branch_snapshot, bpf_perf_branch_snapshot);
> +
> static __always_inline
> void __bpf_trace_run(struct bpf_prog *prog, u64 *args)
> {
> +#ifdef CONFIG_PERF_EVENTS
> + /* Calling migrate_disable costs two entries in the LBR. To save
> + * some entries, we call perf_snapshot_branch_stack before
> + * migrate_disable to save some entries. This is OK because we
> + * care about the branch trace before entering the BPF program.
> + * If migrate happens exactly here, there isn't much we can do to
> + * preserve the data.
> + */
> + if (prog->call_get_branch)
> + static_call(perf_snapshot_branch_stack)(
> + this_cpu_ptr(&bpf_perf_branch_snapshot));
> +#endif
> cant_sleep();
In the face of ^^^^^^ the comment makes no sense. Still, what are the
nesting rules for __bpf_trace_run() and __bpf_prog_enter() ? I'm
thinking the trace one can nest inside an occurence of prog, at which
point you have pieces.
> rcu_read_lock();
> (void) bpf_prog_run(prog, args);
next prev parent reply other threads:[~2021-08-31 15:33 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-30 21:41 [PATCH v3 bpf-next 0/3] bpf: introduce bpf_get_branch_snapshot Song Liu
2021-08-30 21:41 ` [PATCH v3 bpf-next 1/3] perf: enable branch record for software events Song Liu
2021-08-30 22:05 ` Andrii Nakryiko
2021-08-31 15:24 ` Peter Zijlstra
2021-08-31 16:12 ` Song Liu
2021-08-30 21:41 ` [PATCH v3 bpf-next 2/3] bpf: introduce helper bpf_get_branch_snapshot Song Liu
2021-08-30 22:14 ` Andrii Nakryiko
2021-08-31 11:16 ` kernel test robot
2021-08-31 15:32 ` Peter Zijlstra [this message]
2021-08-31 16:41 ` Song Liu
2021-08-31 21:24 ` Song Liu
2021-08-31 21:37 ` Alexei Starovoitov
2021-08-30 21:41 ` [PATCH v3 bpf-next 3/3] selftests/bpf: add test for bpf_get_branch_snapshot Song Liu
2021-08-30 22:28 ` Andrii Nakryiko
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=YS5LexDSokkcOJ7O@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=acme@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kernel-team@fb.com \
--cc=kjain@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.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).