From: Yonghong Song <yhs@fb.com>
To: Namhyung Kim <namhyung@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>
Cc: Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
netdev@vger.kernel.org, bpf@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Eugene Loh <eugene.loh@oracle.com>, Hao Luo <haoluo@google.com>
Subject: Re: [PATCH 1/2] bpf: Adjust BPF stack helper functions to accommodate skip > 0
Date: Thu, 10 Mar 2022 14:54:48 -0800 [thread overview]
Message-ID: <d2af0d13-68cf-ad8c-5b16-af76201452c4@fb.com> (raw)
In-Reply-To: <20220310082202.1229345-1-namhyung@kernel.org>
On 3/10/22 12:22 AM, Namhyung Kim wrote:
> Let's say that the caller has storage for num_elem stack frames. Then,
> the BPF stack helper functions walk the stack for only num_elem frames.
> This means that if skip > 0, one keeps only 'num_elem - skip' frames.
>
> This is because it sets init_nr in the perf_callchain_entry to the end
> of the buffer to save num_elem entries only. I believe it was because
> the perf callchain code unwound the stack frames until it reached the
> global max size (sysctl_perf_event_max_stack).
>
> However it now has perf_callchain_entry_ctx.max_stack to limit the
> iteration locally. This simplifies the code to handle init_nr in the
> BPF callstack entries and removes the confusion with the perf_event's
> __PERF_SAMPLE_CALLCHAIN_EARLY which sets init_nr to 0.
>
> Also change the comment on bpf_get_stack() in the header file to be
> more explicit what the return value means.
>
> Based-on-patch-by: Eugene Loh <eugene.loh@oracle.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
The change looks good to me. This patch actually fixed a bug
discussed below:
https://lore.kernel.org/bpf/30a7b5d5-6726-1cc2-eaee-8da2828a9a9c@oracle.com/
A reference to the above link in the commit message
will be useful for people to understand better with an
example.
Also, the following fixes tag should be added:
Fixes: c195651e565a ("bpf: add bpf_get_stack helper")
Since the bug needs skip > 0 which is seldomly used,
and the current returned stack is still correct although
with less entries, I guess that is why less people
complains.
Anyway, ack the patch:
Acked-by: Yonghong Song <yhs@fb.com>
> ---
> include/uapi/linux/bpf.h | 4 +--
> kernel/bpf/stackmap.c | 56 +++++++++++++++++-----------------------
> 2 files changed, 26 insertions(+), 34 deletions(-)
>
> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> index b0383d371b9a..77f4a022c60c 100644
> --- a/include/uapi/linux/bpf.h
> +++ b/include/uapi/linux/bpf.h
> @@ -2975,8 +2975,8 @@ union bpf_attr {
> *
> * # sysctl kernel.perf_event_max_stack=<new value>
> * Return
> - * A non-negative value equal to or less than *size* on success,
> - * or a negative error in case of failure.
> + * The non-negative copied *buf* length equal to or less than
> + * *size* on success, or a negative error in case of failure.
> *
> * long bpf_skb_load_bytes_relative(const void *skb, u32 offset, void *to, u32 len, u32 start_header)
[...]
next prev parent reply other threads:[~2022-03-10 22:55 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-10 8:22 [PATCH 1/2] bpf: Adjust BPF stack helper functions to accommodate skip > 0 Namhyung Kim
2022-03-10 8:22 ` [PATCH 2/2] bpf/selftests: Test skipping stacktrace Namhyung Kim
2022-03-10 23:21 ` Yonghong Song
2022-03-11 0:40 ` Namhyung Kim
2022-03-11 22:23 ` Andrii Nakryiko
2022-03-14 17:28 ` Namhyung Kim
2022-03-10 22:54 ` Yonghong Song [this message]
2022-03-11 0:23 ` [PATCH 1/2] bpf: Adjust BPF stack helper functions to accommodate skip > 0 Hao Luo
2022-03-11 0:33 ` Namhyung Kim
2022-03-11 0:32 ` Namhyung Kim
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=d2af0d13-68cf-ad8c-5b16-af76201452c4@fb.com \
--to=yhs@fb.com \
--cc=acme@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eugene.loh@oracle.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=namhyung@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.org \
--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).