From: Martin KaFai Lau <martin.lau@linux.dev>
To: Kui-Feng Lee <sinquersw@gmail.com>, thinker.li@gmail.com
Cc: kuifeng@meta.com, bpf@vger.kernel.org, ast@kernel.org,
song@kernel.org, kernel-team@meta.com, andrii@kernel.org,
drosen@google.com
Subject: Re: [PATCH bpf-next v8 10/10] selftests/bpf: test case for register_bpf_struct_ops().
Date: Wed, 1 Nov 2023 18:43:40 -0700 [thread overview]
Message-ID: <223ab9b2-ca4b-4670-449b-5256af5e589a@linux.dev> (raw)
In-Reply-To: <c1267fed-e982-46ab-b0c7-83bed4108cd3@gmail.com>
On 10/31/23 5:30 PM, Kui-Feng Lee wrote:
>
>
> On 10/30/23 23:59, Martin KaFai Lau wrote:
>> On 10/30/23 12:28 PM, thinker.li@gmail.com wrote:
>>> diff --git a/tools/testing/selftests/bpf/prog_tests/test_struct_ops_module.c
>>> b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_module.c
>>> new file mode 100644
>>> index 000000000000..3a00dc294583
>>> --- /dev/null
>>> +++ b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_module.c
>>> @@ -0,0 +1,39 @@
>>> +// SPDX-License-Identifier: GPL-2.0
>>> +/* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */
>>> +#include <test_progs.h>
>>> +#include <time.h>
>>> +
>>> +#include "rcu_tasks_trace_gp.skel.h"
>>> +#include "struct_ops_module.skel.h"
>>> +
>>> +static void test_regular_load(void)
>>> +{
>>> + struct struct_ops_module *skel;
>>> + struct bpf_link *link;
>>> + DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts);
>>> + int err;
>>> +
>>> + skel = struct_ops_module__open_opts(&opts);
>>> + if (!ASSERT_OK_PTR(skel, "struct_ops_module_open"))
>>> + return;
>>> + err = struct_ops_module__load(skel);
>>> + if (!ASSERT_OK(err, "struct_ops_module_load"))
>>> + return;
>>> +
>>> + link = bpf_map__attach_struct_ops(skel->maps.testmod_1);
>>> + ASSERT_OK_PTR(link, "attach_test_mod_1");
>>> +
>>> + /* test_2() will be called from bpf_dummy_reg() in bpf_testmod.c */
>>> + ASSERT_EQ(skel->bss->test_2_result, 7, "test_2_result");
>>> +
>>> + bpf_link__destroy(link);
>>> +
>>> + struct_ops_module__destroy(skel);
>>> +}
>>> +
>>> +void serial_test_struct_ops_module(void)
>>> +{
>>> + if (test__start_subtest("regular_load"))
>>> + test_regular_load();
>>
>> Could it also add some negative tests, e.g. missing 'struct
>> bpf_struct_ops_common_value', reg() when the module is gone...etc.
>>
>> [ ... ]
>>
>>> +/* This function will trigger call_rcu_tasks_trace() in the kernel */
>>> +static int kern_sync_rcu_tasks_trace(void)
>>
>> With patch 4, is it still needed?
>
> Patch 4 shortens time of holding the module, but it still can happen
> since bpf_link_put() is performed asynchronously.
Is the link pinned to a file that triggers bpf_link_put()?
Otherwise, close() should reach bpf_link_put_direct() which is synchronous.
Even if it went through bpf_link_put(), rcu_tasks_trace_gp is very specific to
the bpf sleepable tracing prog. Is it the correct one to wait?
>
>>
>>> +{
>>> + struct rcu_tasks_trace_gp *rcu;
>>> + time_t start;
>>> + long gp_seq;
>>> + LIBBPF_OPTS(bpf_test_run_opts, opts);
>>> +
>>> + rcu = rcu_tasks_trace_gp__open_and_load();
>>> + if (IS_ERR(rcu))
>>> + return -EFAULT;
>>> + if (rcu_tasks_trace_gp__attach(rcu))
>>> + return -EFAULT;
>>> +
>>> + gp_seq = READ_ONCE(rcu->bss->gp_seq);
>>> +
>>> + if
>>> (bpf_prog_test_run_opts(bpf_program__fd(rcu->progs.do_call_rcu_tasks_trace),
>>> + &opts))
>>> + return -EFAULT;
>>> + if (opts.retval != 0)
>>> + return -EFAULT;
>>> +
>>> + start = time(NULL);
>>> + while ((start + 2) > time(NULL) &&
>>> + gp_seq == READ_ONCE(rcu->bss->gp_seq))
>>> + sched_yield();
>>> +
>>> + rcu_tasks_trace_gp__destroy(rcu);
>>> +
>>> + return 0;
>>> +}
>>> +
>>> /*
>>> * Trigger synchronize_rcu() in kernel.
>>> */
>>> int kern_sync_rcu(void)
>>> {
>>> + if (kern_sync_rcu_tasks_trace())
>>> + return -EFAULT;
>>> return syscall(__NR_membarrier, MEMBARRIER_CMD_SHARED, 0, 0);
>>> }
>>
next prev parent reply other threads:[~2023-11-02 1:43 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-30 19:28 [PATCH bpf-next v8 00/10] Registrating struct_ops types from modules thinker.li
2023-10-30 19:28 ` [PATCH bpf-next v8 01/10] bpf: refactory struct_ops type initialization to a function thinker.li
2023-10-30 19:28 ` [PATCH bpf-next v8 02/10] bpf, net: introduce bpf_struct_ops_desc thinker.li
2023-10-31 6:40 ` Martin KaFai Lau
2023-10-31 16:00 ` Kui-Feng Lee
2023-10-30 19:28 ` [PATCH bpf-next v8 03/10] bpf: add struct_ops_tab to btf thinker.li
2023-10-31 1:09 ` Martin KaFai Lau
2023-10-31 16:57 ` Kui-Feng Lee
2023-10-30 19:28 ` [PATCH bpf-next v8 04/10] bpf: hold module for bpf_struct_ops_map thinker.li
2023-10-31 1:21 ` Martin KaFai Lau
2023-10-31 17:46 ` Kui-Feng Lee
2023-10-30 19:28 ` [PATCH bpf-next v8 05/10] bpf: validate value_type thinker.li
2023-10-30 19:28 ` [PATCH bpf-next v8 06/10] bpf: pass attached BTF to the bpf_struct_ops subsystem thinker.li
2023-10-31 1:53 ` Martin KaFai Lau
2023-10-31 20:31 ` Kui-Feng Lee
2023-10-30 19:28 ` [PATCH bpf-next v8 07/10] bpf, net: switch to dynamic registration thinker.li
2023-10-31 6:36 ` Martin KaFai Lau
2023-10-31 23:34 ` Kui-Feng Lee
2023-11-01 0:02 ` Martin KaFai Lau
2023-11-01 0:19 ` Kui-Feng Lee
2023-11-01 0:19 ` Kui-Feng Lee
2023-11-02 0:17 ` Martin KaFai Lau
2023-11-02 0:59 ` Kui-Feng Lee
2023-11-02 1:32 ` Martin KaFai Lau
2023-11-02 4:19 ` Kui-Feng Lee
2023-10-30 19:28 ` [PATCH bpf-next v8 08/10] libbpf: Find correct module BTFs for struct_ops maps and progs thinker.li
2023-10-30 19:28 ` [PATCH bpf-next v8 09/10] bpf: export btf_ctx_access to modules thinker.li
2023-10-30 19:28 ` [PATCH bpf-next v8 10/10] selftests/bpf: test case for register_bpf_struct_ops() thinker.li
2023-10-31 6:59 ` Martin KaFai Lau
2023-11-01 0:30 ` Kui-Feng Lee
2023-11-02 1:43 ` Martin KaFai Lau [this message]
2023-11-02 18:26 ` Kui-Feng Lee
2023-10-31 20:45 ` [PATCH bpf-next v8 00/10] Registrating struct_ops types from modules Martin KaFai Lau
2023-11-01 0:48 ` Kui-Feng Lee
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=223ab9b2-ca4b-4670-449b-5256af5e589a@linux.dev \
--to=martin.lau@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=drosen@google.com \
--cc=kernel-team@meta.com \
--cc=kuifeng@meta.com \
--cc=sinquersw@gmail.com \
--cc=song@kernel.org \
--cc=thinker.li@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.