Re: [PATCHv2 bpf-next 09/11] bpf: Remove trace_in argument from __bpf_get_stack
Andrii Nakryiko <[email protected]>
| Newsgroups | org.kernel.vger.bpf |
|---|---|
| Message-ID | <CAEf4BzaWoB-RnBqa62X4pzM0PBvn21ZA_Fh3P9pWZ6s5_Hjoeg@mail.gmail.com> |
On Fri, Jul 31, 2026 at 6:33 AM Jiri Olsa <[email protected]> wrote: > > 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 in general, but bpf_get_stack and bpf_get_stackid never request both kernel and user stack trace in one go and we set add_mark to false, so we can't have PERF_CONTEXT_USER, which is why I am asking what's the deal with this nr_kernel calculation. If it's unnecessary, we should just drop that part and not have that extra unnecessary complication > > > 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 > > >