From: Kui-Feng Lee <kuifeng@meta.com>
To: "song@kernel.org" <song@kernel.org>,
Kernel Team <kernel-team@meta.com>,
"ast@kernel.org" <ast@kernel.org>, Yonghong Song <yhs@meta.com>,
"andrii@kernel.org" <andrii@kernel.org>,
Kui-Feng Lee <kuifeng@meta.com>,
"bpf@vger.kernel.org" <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next 2/2] selftests/bpf: create new processes repeatedly in the background.
Date: Fri, 16 Dec 2022 21:44:59 +0000 [thread overview]
Message-ID: <3af45b9a9fe91e72a362aff3575f6bb5c5986555.camel@fb.com> (raw)
In-Reply-To: <aea7a3fa-3335-fc32-e87c-52972251579b@meta.com>
On Fri, 2022-12-16 at 12:05 -0800, Yonghong Song wrote:
>
>
> On 12/15/22 5:59 PM, Kui-Feng Lee wrote:
> > According to a report, the system may crash when a task iterator
>
> There is no context about this 'a report'. You can just remove it
> and say:
> When a task iterator traverses vma(s), it is possible task->mm
> might become invalid in the middle of traversal and this may
> cause kernel misbehave (e.g., crash).
>
> > travels vma(s). The investigation shows it takes place if the
> > visiting task dies during the visit. >
> > This test case creates iterators repeatedly and forks short-lived
> > processes in the background to detect this bug. The test will last
> > for 3 seconds to get the chance to trigger the issue.
>
> The subject is not precise. The test is not about
> "create new processes repeatedly in the background."
> It is about
> "Add a test for iter/task_vma with shortlived processes"
>
> >
> > Signed-off-by: Kui-Feng Lee <kuifeng@meta.com>
>
> Ack with a few nits.
>
> Acked-by: Yonghong Song <yhs@fb.com>
>
Thank you for the review.
> > ---
> > .../selftests/bpf/prog_tests/bpf_iter.c | 79
> > +++++++++++++++++++
> > 1 file changed, 79 insertions(+)
> >
> > diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> > b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> > index 6f8ed61fc4b4..df13350d615a 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
> > @@ -1465,6 +1465,83 @@ static void test_task_vma_common(struct
> > bpf_iter_attach_opts *opts)
> > bpf_iter_task_vma__destroy(skel);
> > }
> >
> > +static void test_task_vma_dead_task(void)
> > +{
> > + int err, iter_fd = -1;
> > + struct bpf_iter_task_vma *skel;
> > + int wstatus, child_pid = -1;
> > + time_t start_tm, cur_tm;
> > + int wait_sec = 3;
>
> Since it is new code, maybe reverse Christmas tree coding style.
Got it!
>
> > +
> > + skel = bpf_iter_task_vma__open();
> > + if (!ASSERT_OK_PTR(skel, "bpf_iter_task_vma__open"))
> > + return;
> > +
> > + skel->bss->pid = getpid();
> > +
> > + err = bpf_iter_task_vma__load(skel);
> > + if (!ASSERT_OK(err, "bpf_iter_task_vma__load"))
> > + goto out;
> > +
> > + skel->links.proc_maps = bpf_program__attach_iter(
> > + skel->progs.proc_maps, NULL);
> > +
> > + if (!ASSERT_OK_PTR(skel->links.proc_maps,
> > "bpf_program__attach_iter")) {
> > + skel->links.proc_maps = NULL;
> > + goto out;
> > + }
> > +
> > + start_tm = time(NULL);
> > + if (start_tm < 0)
> > + goto out;
>
> From the man page, start_tm should not fail. Note that you didn't
> put
> an ASSERT* either. So I think you can remove it. The same for a few
> instances below.
The only reason that mentioned in the man page to fail is passing an
invalid pointer. But, in our case, passing a NULL pointer, you are
right.
>
> > + cur_tm = start_tm;
> > +
> > + child_pid = fork();
> > + if (child_pid == 0) {
> > + /* Fork short-lived processes in the background. */
> > + while (cur_tm < start_tm + wait_sec) {
> > + system("echo > /dev/null");
> > + cur_tm = time(NULL);
> > + if (cur_tm < 0)
> > + exit(1);
> > + }
> > + exit(0);
> > + }
> > +
> > + if (!ASSERT_GE(child_pid, 0, "fork_child"))
> > + goto out;
> > +
> > + while (cur_tm < start_tm + wait_sec) {
> > + iter_fd = bpf_iter_create(bpf_link__fd(skel-
> > >links.proc_maps));
> > + if (!ASSERT_GE(iter_fd, 0, "create_iter"))
> > + goto out;
> > +
> > + /* Drain all data from iter_fd. */
> > + while (cur_tm < start_tm + wait_sec) {
> > + err = read_fd_into_buffer(iter_fd,
> > task_vma_output, CMP_BUFFER_SIZE);
> > + if (!ASSERT_GE(err, 0, "read_iter_fd"))
> > + goto out;
> > +
> > + cur_tm = time(NULL);
> > + if (cur_tm < 0)
> > + goto out;
> > +
> > + if (err == 0)
> > + break;
> > + }
> > +
> > + close(iter_fd);
> > + iter_fd = -1;
> > + }
> > +
> > + check_bpf_link_info(skel->progs.proc_maps);
> > +
> > +out:
> > + waitpid(child_pid, &wstatus, 0);
> > + close(iter_fd);
> > + bpf_iter_task_vma__destroy(skel);
> > +}
> > +
> > void test_bpf_sockmap_map_iter_fd(void)
> > {
> > struct bpf_iter_sockmap *skel;
> > @@ -1586,6 +1663,8 @@ void test_bpf_iter(void)
> > test_task_file();
> > if (test__start_subtest("task_vma"))
> > test_task_vma();
> > + if (test__start_subtest("task_vma_dead_task"))
> > + test_task_vma_dead_task();
> > if (test__start_subtest("task_btf"))
> > test_task_btf();
> > if (test__start_subtest("tcp4"))
prev parent reply other threads:[~2022-12-16 21:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-16 1:59 [PATCH bpf-next 0/2] bpf: fix the crash caused by task iterators over vma Kui-Feng Lee
2022-12-16 1:59 ` [PATCH bpf-next 1/2] bpf: keep a reference to the mm, in case the task is dead Kui-Feng Lee
2022-12-16 19:09 ` Yonghong Song
2022-12-16 1:59 ` [PATCH bpf-next 2/2] selftests/bpf: create new processes repeatedly in the background Kui-Feng Lee
2022-12-16 20:05 ` Yonghong Song
2022-12-16 21:44 ` Kui-Feng Lee [this message]
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=3af45b9a9fe91e72a362aff3575f6bb5c5986555.camel@fb.com \
--to=kuifeng@meta.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kernel-team@meta.com \
--cc=song@kernel.org \
--cc=yhs@meta.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