[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAADnVQK+xX8oKF5f=FzmE+xxbSovJ+rbZD6TRxTAtdH+-ockEw@mail.gmail.com>
Date: Thu, 23 Jul 2020 08:22:19 -0700
From: Alexei Starovoitov <alexei.starovoitov@...il.com>
To: Song Liu <songliubraving@...com>
Cc: open list <linux-kernel@...r.kernel.org>,
bpf <bpf@...r.kernel.org>, Networking <netdev@...r.kernel.org>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Kernel Team <Kernel-team@...com>,
john fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...omium.org>,
Jesper Dangaard Brouer <brouer@...hat.com>,
"peterz@...radead.org" <peterz@...radead.org>
Subject: Re: [PATCH v4 bpf-next 2/4] bpf: fail PERF_EVENT_IOC_SET_BPF when
bpf_get_[stack|stackid] cannot work
On Wed, Jul 22, 2020 at 11:20 PM Song Liu <songliubraving@...com> wrote:
>
>
>
> > On Jul 22, 2020, at 10:55 PM, Alexei Starovoitov <alexei.starovoitov@...il.com> wrote:
> >
> > On Wed, Jul 22, 2020 at 11:42:08AM -0700, Song Liu wrote:
> >> diff --git a/kernel/events/core.c b/kernel/events/core.c
> >> index 856d98c36f562..f77d009fcce95 100644
> >> --- a/kernel/events/core.c
> >> +++ b/kernel/events/core.c
> >> @@ -9544,6 +9544,24 @@ static int perf_event_set_bpf_handler(struct perf_event *event, u32 prog_fd)
> >> if (IS_ERR(prog))
> >> return PTR_ERR(prog);
> >>
> >> + if (event->attr.precise_ip &&
> >> + prog->call_get_stack &&
> >> + (!(event->attr.sample_type & __PERF_SAMPLE_CALLCHAIN_EARLY) ||
> >> + event->attr.exclude_callchain_kernel ||
> >> + event->attr.exclude_callchain_user)) {
> >> + /*
> >> + * On perf_event with precise_ip, calling bpf_get_stack()
> >> + * may trigger unwinder warnings and occasional crashes.
> >> + * bpf_get_[stack|stackid] works around this issue by using
> >> + * callchain attached to perf_sample_data. If the
> >> + * perf_event does not full (kernel and user) callchain
> >> + * attached to perf_sample_data, do not allow attaching BPF
> >> + * program that calls bpf_get_[stack|stackid].
> >> + */
> >> + bpf_prog_put(prog);
> >> + return -EINVAL;
> >
> > I suspect this will be a common error. bpftrace and others will be hitting
> > this issue and would need to fix how they do perf_event_open.
> > But EINVAL is too ambiguous and sys_perf_event_open has no ability to
> > return a string.
> > So how about we pick some different errno here to make future debugging
> > a bit less painful?
> > May be EBADFD or EPROTO or EPROTOTYPE ?
> > I think anything would be better than EINVAL.
>
> I like EPROTO most. I will change it to EPROTO if we don't have better ideas.
>
> Btw, this is not the error code on sys_perf_event_open(). It is the ioctl()
> on the perf_event fd. So debugging this error will be less painful than
> debugging sys_perf_event_open() errors.
ahh. right. Could you also add a string hint to libbpf when it sees this errno?
Powered by blists - more mailing lists