Re: [PATCHv2 bpf-next 09/11] bpf: Remove trace_in argument from __bpf_get_stack

Jiri Olsa <[email protected]>
Newsgroups org.kernel.vger.bpf
Message-ID <amykPmjhfVJlAevL@krava>
On Thu, Jul 30, 2026 at 04:06:14PM -0700, Andrii Nakryiko wrote:

SNIP

> >  BPF_CALL_4(bpf_get_stack_pe, struct bpf_perf_event_data_kern *, ctx,
> >            void *, buf, u32, size, u64, flags)
> >  {
> > @@ -947,7 +970,7 @@ BPF_CALL_4(bpf_get_stack_pe, struct bpf_perf_event_data_kern *, ctx,
> >         int err = -EINVAL;
> >
> >         if (!(event->attr.sample_type & PERF_SAMPLE_CALLCHAIN))
> > -               return __bpf_get_stack(regs, NULL, NULL, buf, size, flags, false /* !may_fault */);
> > +               return __bpf_get_stack(regs, NULL, buf, size, flags, false /* !may_fault */);
> >
> >         if (unlikely(flags & ~(BPF_F_SKIP_FIELD_MASK | BPF_F_USER_STACK |
> >                                BPF_F_USER_BUILD_ID)))
> > @@ -966,7 +989,7 @@ BPF_CALL_4(bpf_get_stack_pe, struct bpf_perf_event_data_kern *, ctx,
> >
> >         if (kernel) {
> >                 trace->nr = nr_kernel;
> 
> this whole count_kernel_ip() logic above, why do we have it? I don't
> think we can have combined user and kernel stack trace, so how can we
> end up with PERF_CONTEXT_USER "ip" at all? I might be missing

the callchain comes from perf event's callchain and that can
have both kernel and user part

> something subtle here, but can you please check again if this whole
> trace->nr calculation/override is even necessary.

as I wrote in the other reply I don't think we need to change
trace->nr directly, just pass the needed nr/count as argument

jirka

> 
> > -               err = __bpf_get_stack(regs, NULL, trace, buf, size, flags, false /* !may_fault */);
> > +               err = __bpf_get_stack_pe(trace, buf, size, flags);
> >
> >         } else { /* user */
> >                 u64 skip = flags & BPF_F_SKIP_FIELD_MASK;
> > @@ -974,9 +997,8 @@ BPF_CALL_4(bpf_get_stack_pe, struct bpf_perf_event_data_kern *, ctx,
> >                 skip += nr_kernel;
> >                 if (skip > BPF_F_SKIP_FIELD_MASK)
> >                         goto clear;
> > -
> >                 flags = (flags & ~BPF_F_SKIP_FIELD_MASK) | skip;
> > -               err = __bpf_get_stack(regs, NULL, trace, buf, size, flags, false /* !may_fault */);
> > +               err = __bpf_get_stack_pe(trace, buf, size, flags);
> >         }
> >
> >         /* restore nr */
> > --
> > 2.54.0
> >
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.