linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Song Liu <songliubraving@fb.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: open list <linux-kernel@vger.kernel.org>,
	bpf <bpf@vger.kernel.org>, Networking <netdev@vger.kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Kernel Team <Kernel-team@fb.com>,
	john fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@chromium.org>,
	Jesper Dangaard Brouer <brouer@redhat.com>,
	"peterz@infradead.org" <peterz@infradead.org>
Subject: Re: [PATCH v4 bpf-next 2/4] bpf: fail PERF_EVENT_IOC_SET_BPF when bpf_get_[stack|stackid] cannot work
Date: Thu, 23 Jul 2020 06:20:29 +0000	[thread overview]
Message-ID: <684DA506-6780-4CB5-B99C-24D939CDE6DF@fb.com> (raw)
In-Reply-To: <20200723055518.onydx7uhmzomt7ud@ast-mbp.dhcp.thefacebook.com>



> On Jul 22, 2020, at 10:55 PM, Alexei Starovoitov <alexei.starovoitov@gmail.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. 

Thanks,
Song

  reply	other threads:[~2020-07-23  6:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-22 18:42 [PATCH v4 bpf-next 0/4] bpf: fix stackmap on perf_events with PEBS Song Liu
2020-07-22 18:42 ` [PATCH v4 bpf-next 1/4] bpf: separate bpf_get_[stack|stackid] for perf events BPF Song Liu
2020-07-22 18:42 ` [PATCH v4 bpf-next 2/4] bpf: fail PERF_EVENT_IOC_SET_BPF when bpf_get_[stack|stackid] cannot work Song Liu
2020-07-23  5:55   ` Alexei Starovoitov
2020-07-23  6:20     ` Song Liu [this message]
2020-07-23 15:22       ` Alexei Starovoitov
2020-07-22 18:42 ` [PATCH v4 bpf-next 4/4] selftests/bpf: add get_stackid_cannot_attach Song Liu

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=684DA506-6780-4CB5-B99C-24D939CDE6DF@fb.com \
    --to=songliubraving@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brouer@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=kpsingh@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=peterz@infradead.org \
    /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).