From: Eduard Zingerman <eddyz87@gmail.com>
To: Kui-Feng Lee <sinquersw@gmail.com>,
thinker.li@gmail.com, bpf@vger.kernel.org, ast@kernel.org,
martin.lau@linux.dev, song@kernel.org, kernel-team@meta.com,
andrii@kernel.org, drosen@google.com
Cc: kuifeng@meta.com, netdev@vger.kernel.org
Subject: Re: [PATCH bpf-next v6 07/10] bpf, net: switch to dynamic registration
Date: Sat, 28 Oct 2023 01:02:45 +0300 [thread overview]
Message-ID: <af3b92d434b1d85e9dc3e60c46ed7ed68dde438e.camel@gmail.com> (raw)
In-Reply-To: <df8f71ce-4e3b-4e65-a197-e2ce0ca494de@gmail.com>
On Fri, 2023-10-27 at 14:32 -0700, Kui-Feng Lee wrote:
>
> On 10/26/23 21:39, Kui-Feng Lee wrote:
> >
> >
> > On 10/26/23 14:02, Eduard Zingerman wrote:
> > > On Sat, 2023-10-21 at 22:03 -0700, thinker.li@gmail.com wrote:
> > > > From: Kui-Feng Lee <thinker.li@gmail.com>
> [...]
> > > > +
> > > > + btf = btf_get_module_btf(st_ops->owner);
> > > > + if (!btf)
> > > > + return -EINVAL;
> > > > +
> > > > + log = kzalloc(sizeof(*log), GFP_KERNEL | __GFP_NOWARN);
> > > > + if (!log) {
> > > > + err = -ENOMEM;
> > > > + goto errout;
> > > > + }
> > > > +
> > > > + log->level = BPF_LOG_KERNEL;
> > >
> > > Nit: maybe use bpf_vlog_init() here to avoid breaking encapsulation?
> >
> > Agree!
> >
>
> I don't use bpf_vlog_init() eventually.
>
> I found bpf_vlog_init() is not for BPF_LOG_KERNEL.
> According to the comment next to BPF_LOG_KERNEL, it
> is an internal log level.
> According to the code of bpf_vlog_init(), the level passing to
> bpf_vlog_init() should be covered by BPF_LOG_MASK. BPF_LOG_KERNEL is
> defined as BPF_LOG_MASK + 1. So, it is intended not being used with
> bpf_vlog_init().
I see, looks like btf_parse_vmlinux does the same, sorry should have checked there.
Thank you for looking into it.
>
> > >
> > > > +
> > > > + desc = btf_add_struct_ops(btf, st_ops);
> > > > + if (IS_ERR(desc)) {
> > > > + err = PTR_ERR(desc);
> > > > + goto errout;
> > > > + }
> > > > +
> > > > + bpf_struct_ops_init(desc, btf, log);
> > >
> > > Nit: I think bpf_struct_ops_init() could be changed to return 'int',
> > > then register_bpf_struct_ops() could report to calling module if
> > > something went wrong on the last phase, wdyt?
> >
> >
> > Agree!
> >
> > >
> > > > +
> > > > +errout:
> > > > + kfree(log);
> > > > + btf_put(btf);
> > > > +
> > > > + return err;
> > > > +}
> > > > +EXPORT_SYMBOL_GPL(register_bpf_struct_ops);
> > > > diff --git a/net/bpf/bpf_dummy_struct_ops.c
> > > > b/net/bpf/bpf_dummy_struct_ops.c
> > > > index ffa224053a6c..148a5851c4fa 100644
> > > > --- a/net/bpf/bpf_dummy_struct_ops.c
> > > > +++ b/net/bpf/bpf_dummy_struct_ops.c
> > > > @@ -7,7 +7,7 @@
> > > > #include <linux/bpf.h>
> > > > #include <linux/btf.h>
> > > > -extern struct bpf_struct_ops bpf_bpf_dummy_ops;
> > > > +static struct bpf_struct_ops bpf_bpf_dummy_ops;
> > > > /* A common type for test_N with return value in bpf_dummy_ops */
> > > > typedef int (*dummy_ops_test_ret_fn)(struct bpf_dummy_ops_state
> > > > *state, ...);
> > > > @@ -223,11 +223,13 @@ static int bpf_dummy_reg(void *kdata)
> > > > return -EOPNOTSUPP;
> > > > }
> > > > +DEFINE_STRUCT_OPS_VALUE_TYPE(bpf_dummy_ops);
> > > > +
> > > > static void bpf_dummy_unreg(void *kdata)
> > > > {
> > > > }
> > > > -struct bpf_struct_ops bpf_bpf_dummy_ops = {
> > > > +static struct bpf_struct_ops bpf_bpf_dummy_ops = {
> > > > .verifier_ops = &bpf_dummy_verifier_ops,
> > > > .init = bpf_dummy_init,
> > > > .check_member = bpf_dummy_ops_check_member,
> > > > @@ -235,4 +237,12 @@ struct bpf_struct_ops bpf_bpf_dummy_ops = {
> > > > .reg = bpf_dummy_reg,
> > > > .unreg = bpf_dummy_unreg,
> > > > .name = "bpf_dummy_ops",
> > > > + .owner = THIS_MODULE,
> > > > };
> > > > +
> > > > +static int __init bpf_dummy_struct_ops_init(void)
> > > > +{
> > > > + BTF_STRUCT_OPS_TYPE_EMIT(bpf_dummy_ops);
> > > > + return register_bpf_struct_ops(&bpf_bpf_dummy_ops);
> > > > +}
> > > > +late_initcall(bpf_dummy_struct_ops_init);
> > > > diff --git a/net/ipv4/bpf_tcp_ca.c b/net/ipv4/bpf_tcp_ca.c
> > > > index 3c8b76578a2a..b36a19274e5b 100644
> > > > --- a/net/ipv4/bpf_tcp_ca.c
> > > > +++ b/net/ipv4/bpf_tcp_ca.c
> > > > @@ -12,7 +12,7 @@
> > > > #include <net/bpf_sk_storage.h>
> > > > /* "extern" is to avoid sparse warning. It is only used in
> > > > bpf_struct_ops.c. */
> > > > -extern struct bpf_struct_ops bpf_tcp_congestion_ops;
> > > > +static struct bpf_struct_ops bpf_tcp_congestion_ops;
> > > > static u32 unsupported_ops[] = {
> > > > offsetof(struct tcp_congestion_ops, get_info),
> > > > @@ -277,7 +277,9 @@ static int bpf_tcp_ca_validate(void *kdata)
> > > > return tcp_validate_congestion_control(kdata);
> > > > }
> > > > -struct bpf_struct_ops bpf_tcp_congestion_ops = {
> > > > +DEFINE_STRUCT_OPS_VALUE_TYPE(tcp_congestion_ops);
> > > > +
> > > > +static struct bpf_struct_ops bpf_tcp_congestion_ops = {
> > > > .verifier_ops = &bpf_tcp_ca_verifier_ops,
> > > > .reg = bpf_tcp_ca_reg,
> > > > .unreg = bpf_tcp_ca_unreg,
> > > > @@ -287,10 +289,18 @@ struct bpf_struct_ops bpf_tcp_congestion_ops = {
> > > > .init = bpf_tcp_ca_init,
> > > > .validate = bpf_tcp_ca_validate,
> > > > .name = "tcp_congestion_ops",
> > > > + .owner = THIS_MODULE,
> > > > };
> > > > static int __init bpf_tcp_ca_kfunc_init(void)
> > > > {
> > > > - return register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
> > > > &bpf_tcp_ca_kfunc_set);
> > > > + int ret;
> > > > +
> > > > + BTF_STRUCT_OPS_TYPE_EMIT(tcp_congestion_ops);
> > > > +
> > > > + ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
> > > > &bpf_tcp_ca_kfunc_set);
> > > > + ret = ret ?: register_bpf_struct_ops(&bpf_tcp_congestion_ops);
> > > > +
> > > > + return ret;
> > > > }
> > > > late_initcall(bpf_tcp_ca_kfunc_init);
> > >
prev parent reply other threads:[~2023-10-27 22:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20231022050335.2579051-1-thinker.li@gmail.com>
2023-10-22 5:03 ` [PATCH bpf-next v6 02/10] bpf, net: introduce bpf_struct_ops_desc thinker.li
2023-10-22 5:03 ` [PATCH bpf-next v6 07/10] bpf, net: switch to dynamic registration thinker.li
2023-10-26 21:02 ` Eduard Zingerman
2023-10-27 4:39 ` Kui-Feng Lee
2023-10-27 21:32 ` Kui-Feng Lee
2023-10-27 22:02 ` Eduard Zingerman [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=af3b92d434b1d85e9dc3e60c46ed7ed68dde438e.camel@gmail.com \
--to=eddyz87@gmail.com \
--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=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--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 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).