netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Song Liu <songliubraving@fb.com>
Cc: Matt Mullins <mmullins@fb.com>, Andrew Hall <hall@fb.com>,
	Alexei Starovoitov <ast@kernel.org>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>,
	Networking <netdev@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>, Martin Lau <kafai@fb.com>,
	Yonghong Song <yhs@fb.com>, Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>
Subject: Re: [PATCH bpf v2] bpf: preallocate a perf_sample_data per event fd
Date: Fri, 31 May 2019 20:12:49 -0700	[thread overview]
Message-ID: <CAADnVQKS1eMMzDRh-fkXQyQihoDBbdg3vAC9jvuOB9QgAakxag@mail.gmail.com> (raw)
In-Reply-To: <B719E003-E100-463E-A921-E59189572181@fb.com>

On Fri, May 31, 2019 at 6:28 PM Song Liu <songliubraving@fb.com> wrote:
>
>
>
> > On May 31, 2019, at 3:37 PM, Matt Mullins <mmullins@fb.com> wrote:
> >
> > It is possible that a BPF program can be called while another BPF
> > program is executing bpf_perf_event_output.  This has been observed with
> > I/O completion occurring as a result of an interrupt:
> >
> >       bpf_prog_247fd1341cddaea4_trace_req_end+0x8d7/0x1000
> >       ? trace_call_bpf+0x82/0x100
> >       ? sch_direct_xmit+0xe2/0x230
> >       ? blk_mq_end_request+0x1/0x100
> >       ? blk_mq_end_request+0x5/0x100
> >       ? kprobe_perf_func+0x19b/0x240
> >       ? __qdisc_run+0x86/0x520
> >       ? blk_mq_end_request+0x1/0x100
> >       ? blk_mq_end_request+0x5/0x100
> >       ? kprobe_ftrace_handler+0x90/0xf0
> >       ? ftrace_ops_assist_func+0x6e/0xe0
> >       ? ip6_input_finish+0xbf/0x460
> >       ? 0xffffffffa01e80bf
> >       ? nbd_dbg_flags_show+0xc0/0xc0 [nbd]
> >       ? blkdev_issue_zeroout+0x200/0x200
> >       ? blk_mq_end_request+0x1/0x100
> >       ? blk_mq_end_request+0x5/0x100
> >       ? flush_smp_call_function_queue+0x6c/0xe0
> >       ? smp_call_function_single_interrupt+0x32/0xc0
> >       ? call_function_single_interrupt+0xf/0x20
> >       ? call_function_single_interrupt+0xa/0x20
> >       ? swiotlb_map_page+0x140/0x140
> >       ? refcount_sub_and_test+0x1a/0x50
> >       ? tcp_wfree+0x20/0xf0
> >       ? skb_release_head_state+0x62/0xc0
> >       ? skb_release_all+0xe/0x30
> >       ? napi_consume_skb+0xb5/0x100
> >       ? mlx5e_poll_tx_cq+0x1df/0x4e0
> >       ? mlx5e_poll_tx_cq+0x38c/0x4e0
> >       ? mlx5e_napi_poll+0x58/0xc30
> >       ? mlx5e_napi_poll+0x232/0xc30
> >       ? net_rx_action+0x128/0x340
> >       ? __do_softirq+0xd4/0x2ad
> >       ? irq_exit+0xa5/0xb0
> >       ? do_IRQ+0x7d/0xc0
> >       ? common_interrupt+0xf/0xf
> >       </IRQ>
> >       ? __rb_free_aux+0xf0/0xf0
> >       ? perf_output_sample+0x28/0x7b0
> >       ? perf_prepare_sample+0x54/0x4a0
> >       ? perf_event_output+0x43/0x60
> >       ? bpf_perf_event_output_raw_tp+0x15f/0x180
> >       ? blk_mq_start_request+0x1/0x120
> >       ? bpf_prog_411a64a706fc6044_should_trace+0xad4/0x1000
> >       ? bpf_trace_run3+0x2c/0x80
> >       ? nbd_send_cmd+0x4c2/0x690 [nbd]
> >
> > This also cannot be alleviated by further splitting the per-cpu
> > perf_sample_data structs (as in commit 283ca526a9bd ("bpf: fix
> > corruption on concurrent perf_event_output calls")), as a raw_tp could
> > be attached to the block:block_rq_complete tracepoint and execute during
> > another raw_tp.  Instead, keep a pre-allocated perf_sample_data
> > structure per perf_event_array element and fail a bpf_perf_event_output
> > if that element is concurrently being used.
> >
> > Fixes: 20b9d7ac4852 ("bpf: avoid excessive stack usage for perf_sample_data")
> > Signed-off-by: Matt Mullins <mmullins@fb.com>
>
> This looks great. Thanks for the fix.
>
> Acked-by: Song Liu <songliubraving@fb.com>
>
> > ---
> > v1->v2:
> >       keep a pointer to the struct perf_sample_data rather than directly
> >       embedding it in the structure, avoiding the circular include and
> >       removing the need for in_use.  Suggested by Song.
> >
> > include/linux/bpf.h      |  1 +
> > kernel/bpf/arraymap.c    |  3 ++-
> > kernel/trace/bpf_trace.c | 29 ++++++++++++++++-------------
> > 3 files changed, 19 insertions(+), 14 deletions(-)
> >
> > diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> > index 4fb3aa2dc975..47fd85cfbbaf 100644
> > --- a/include/linux/bpf.h
> > +++ b/include/linux/bpf.h
> > @@ -472,6 +472,7 @@ struct bpf_event_entry {
> >       struct file *perf_file;
> >       struct file *map_file;
> >       struct rcu_head rcu;
> > +     struct perf_sample_data *sd;
> > };
> >
> > bool bpf_prog_array_compatible(struct bpf_array *array, const struct bpf_prog *fp);
> > diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c
> > index 584636c9e2eb..c7f5d593e04f 100644
> > --- a/kernel/bpf/arraymap.c
> > +++ b/kernel/bpf/arraymap.c
> > @@ -654,11 +654,12 @@ static struct bpf_event_entry *bpf_event_entry_gen(struct file *perf_file,
> > {
> >       struct bpf_event_entry *ee;
> >
> > -     ee = kzalloc(sizeof(*ee), GFP_ATOMIC);
> > +     ee = kzalloc(sizeof(*ee) + sizeof(struct perf_sample_data), GFP_ATOMIC);
> >       if (ee) {
> >               ee->event = perf_file->private_data;
> >               ee->perf_file = perf_file;
> >               ee->map_file = map_file;
> > +             ee->sd = (void *)ee + sizeof(*ee);

This bit looks quite weird, but I don't have better ideas
to avoid circular .h pain.

Applied to bpf tree. Thanks

  reply	other threads:[~2019-06-01  3:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-31 22:37 [PATCH bpf v2] bpf: preallocate a perf_sample_data per event fd Matt Mullins
2019-06-01  1:27 ` Song Liu
2019-06-01  3:12   ` Alexei Starovoitov [this message]
2019-06-03 13:08 ` Daniel Borkmann
2019-06-03 13:22   ` Daniel Borkmann
2019-06-03 22:58     ` Matt Mullins
2019-06-03 23:27       ` Alexei Starovoitov
2019-06-03 23:48         ` Daniel Borkmann
2019-06-03 23:54           ` Alexei Starovoitov
2019-06-04  0:43             ` Daniel Borkmann
2019-06-04  0:56               ` Alexei Starovoitov
2019-06-04  3:17               ` Matt Mullins
2019-06-06 18:54                 ` [PATCH bpf] bpf: fix nested bpf tracepoints with per-cpu data Matt Mullins
2019-06-06 22:13                   ` Jakub Kicinski
2019-06-06 22:39                     ` Matt Mullins
2019-06-07  2:59                   ` Andrii Nakryiko
2019-06-07  7:55                     ` Steven Rostedt

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=CAADnVQKS1eMMzDRh-fkXQyQihoDBbdg3vAC9jvuOB9QgAakxag@mail.gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=hall@fb.com \
    --cc=kafai@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=mmullins@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=songliubraving@fb.com \
    --cc=yhs@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).