From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Song Liu <songliubraving@fb.com>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, linux-mm@kvack.org,
ast@kernel.org, daniel@iogearbox.net, kernel-team@fb.com,
akpm@linux-foundation.org, Yonghong Song <yhs@fb.com>
Subject: Re: [PATCH v6 bpf-next 1/4] bpf: introduce task_vma bpf_iter
Date: Thu, 11 Feb 2021 20:47:13 -0800 [thread overview]
Message-ID: <20210212044713.ptgvtsnh22vp5axg@ast-mbp.dhcp.thefacebook.com> (raw)
In-Reply-To: <20210212014232.414643-2-songliubraving@fb.com>
On Thu, Feb 11, 2021 at 05:42:29PM -0800, Song Liu wrote:
> +static int __task_vma_seq_show(struct seq_file *seq, bool in_stop)
> +{
> + struct bpf_iter_seq_task_vma_info *info = seq->private;
> + struct bpf_iter__task_vma ctx;
> + struct bpf_iter_meta meta;
> + struct bpf_prog *prog;
> +
> + meta.seq = seq;
> + prog = bpf_iter_get_info(&meta, in_stop);
> + if (!prog)
> + return 0;
> +
> + ctx.meta = &meta;
> + ctx.task = info->task;
> + ctx.vma = info->vma;
> + return bpf_iter_run_prog(prog, &ctx);
> +}
That part doesn't match patch 2.
If it needs to call sleepable prog it should call it differently,
since bpf_iter_run_prog() is doing rcu_read_lock().
Try adding the following:
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 845b2168e006..06f65b18bc54 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -1159,6 +1159,8 @@ BPF_CALL_3(bpf_d_path, struct path *, path, char *, buf, u32, sz)
long len;
char *p;
+ might_sleep();
and you will see a splat from patch 4's task_vma test.
But this might_sleep above is not correct. d_path is not about sleepability.
It does its locking under rcu_read_lock.
The bpf_d_path_allowed is confusing, since it checks for lsm sleepable hooks,
but it's not about sleeping. Those hooks are safe because they don't hold
any vfs locks. With bpf iterators the situation is the same.
They all are called from bpf_seq_read. Which runs in user context and
there are no vfs locks to worry about.
So it's safe to enable all iterators to access bpf_d_path. No need
to introduce sleepable iterators.
The upcoming bpf_for_each_map_elem is kinda an iterator too where
map elem callback shouldn't be able to call bpf_d_path, but
it won't have expected_attach_type == BPF_TRACE_ITER, so
bpf_for_each_map_elem will be fine the way last patches were done.
So just drop 'prog->aux->sleepable' from patch 2 and delete patch 3.
next prev parent reply other threads:[~2021-02-12 4:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-12 1:42 [PATCH v6 bpf-next 0/4] introduce bpf_iter for task_vma Song Liu
2021-02-12 1:42 ` [PATCH v6 bpf-next 1/4] bpf: introduce task_vma bpf_iter Song Liu
2021-02-12 4:47 ` Alexei Starovoitov [this message]
2021-02-12 1:42 ` [PATCH v6 bpf-next 2/4] bpf: allow bpf_d_path in sleepable bpf_iter program Song Liu
2021-02-12 1:42 ` [PATCH v6 bpf-next 3/4] libbpf: introduce section "iter.s/" for " Song Liu
2021-02-12 1:42 ` [PATCH v6 bpf-next 4/4] selftests/bpf: add test for bpf_iter_task_vma 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=20210212044713.ptgvtsnh22vp5axg@ast-mbp.dhcp.thefacebook.com \
--to=alexei.starovoitov@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=linux-mm@kvack.org \
--cc=netdev@vger.kernel.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