public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Kui-Feng Lee <sinquersw@gmail.com>
To: Martin KaFai Lau <martin.lau@linux.dev>, 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
Subject: Re: [RFC bpf-next v2 2/9] bpf: add register and unregister functions for struct_ops.
Date: Fri, 15 Sep 2023 18:14:49 -0700	[thread overview]
Message-ID: <912b0d41-5959-74ff-a1a9-6277bf62aac2@gmail.com> (raw)
In-Reply-To: <414e9f49-ad34-5282-6c05-882876440f34@linux.dev>



On 9/15/23 17:05, Martin KaFai Lau wrote:
> On 9/12/23 11:14 PM, thinker.li@gmail.com wrote:
>> +int register_bpf_struct_ops(struct bpf_struct_ops_mod *mod)
>> +{
>> +    struct bpf_struct_ops *st_ops = mod->st_ops;
>> +    struct bpf_verifier_log *log;
>> +    struct btf *btf;
>> +    int err;
>> +
>> +    if (mod->st_ops == NULL ||
>> +        mod->owner == NULL)
>> +        return -EINVAL;
>> +
>> +    log = kzalloc(sizeof(*log), GFP_KERNEL | __GFP_NOWARN);
>> +    if (!log) {
>> +        err = -ENOMEM;
>> +        goto errout;
>> +    }
>> +
>> +    log->level = BPF_LOG_KERNEL;
>> +
>> +    btf = btf_get_module_btf(mod->owner);
> 
> Where is btf_put called?
> 
> It is not stored anywhere in patch 2, so a bit confusing. I quickly 
> looked at the following patches but also don't see the bpf_put.

It is my fault to use it without calling btf_put().
I miss-understood the API, thought it doesn't increase refcount by
mistake.

> 
>> +    if (!btf) {
>> +        err = -EINVAL;
>> +        goto errout;
>> +    }
>> +
>> +    bpf_struct_ops_init_one(st_ops, btf, log);
>> +    err = add_struct_ops(st_ops);
>> +
>> +errout:
>> +    kfree(log);
>> +
>> +    return err;
>> +}
>> +EXPORT_SYMBOL(register_bpf_struct_ops);
>> +
>> +int unregister_bpf_struct_ops(struct bpf_struct_ops_mod *mod)
> 
> It is not clear to me why the subsystem needs to explicitly call 
> unregister_bpf_struct_ops(). Can it be done similar to the module kfunc 
> support (the kfunc_set_tab goes away with the btf)?

It could be. However, registering to module notifier
(register_module_notifier()) is more straight forward if we go
this way. What do you think?

> 
> Related to this, does it need to maintain a global struct_ops array for 
> all kernel module? Can the struct_ops be maintained under its 
> corresponding module btf itself?

What is the purpose?
We have a global struct_ops array already, although it is not
per-module. For now, the number of struct_ops is pretty small.
We have only one so far, and it is unlikely to grow fast in
near future. It is probably a bit overkill to have
per-module ones if this is what you mean.

> 
>> +{
>> +    struct bpf_struct_ops *st_ops = mod->st_ops;
>> +    int err;
>> +
>> +    err = remove_struct_ops(st_ops);
>> +    if (!err && st_ops->uninit)
>> +        err = st_ops->uninit();
>> +
>> +    return err;
>> +}
>> +EXPORT_SYMBOL(unregister_bpf_struct_ops);
> 
> 

  reply	other threads:[~2023-09-16  1:14 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-13  6:14 [RFC bpf-next v2 0/9] Registrating struct_ops types from modules thinker.li
2023-09-13  6:14 ` [RFC bpf-next v2 1/9] bpf: refactory struct_ops type initialization to a function thinker.li
2023-09-15 22:43   ` Martin KaFai Lau
2023-09-16  1:35     ` Kui-Feng Lee
2023-09-13  6:14 ` [RFC bpf-next v2 2/9] bpf: add register and unregister functions for struct_ops thinker.li
2023-09-16  0:05   ` Martin KaFai Lau
2023-09-16  1:14     ` Kui-Feng Lee [this message]
2023-09-18 18:47       ` Martin KaFai Lau
2023-09-18 20:40         ` Kui-Feng Lee
2023-09-13  6:14 ` [RFC bpf-next v2 3/9] bpf: attach a module BTF to a bpf_struct_ops thinker.li
2023-09-13  6:14 ` [RFC bpf-next v2 4/9] bpf: use attached BTF to find correct type info of struct_ops progs thinker.li
2023-09-13  6:14 ` [RFC bpf-next v2 5/9] bpf: hold module for bpf_struct_ops_map thinker.li
2023-09-13  6:14 ` [RFC bpf-next v2 6/9] libbpf: Find correct module BTFs for struct_ops maps and progs thinker.li
2023-09-13  6:14 ` [RFC bpf-next v2 7/9] bpf: export btf_ctx_access to modules thinker.li
2023-09-13  6:14 ` [RFC bpf-next v2 8/9] selftests/bpf: test case for register_bpf_struct_ops() thinker.li
2023-09-13  6:14 ` [RFC bpf-next v2 9/9] Comments and debug thinker.li

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=912b0d41-5959-74ff-a1a9-6277bf62aac2@gmail.com \
    --to=sinquersw@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=kernel-team@meta.com \
    --cc=kuifeng@meta.com \
    --cc=martin.lau@linux.dev \
    --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