All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kui-Feng Lee <sinquersw@gmail.com>
To: Eduard Zingerman <eddyz87@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: Fri, 27 Oct 2023 14:32:42 -0700	[thread overview]
Message-ID: <df8f71ce-4e3b-4e65-a197-e2ce0ca494de@gmail.com> (raw)
In-Reply-To: <f2c33ec4-339d-464d-893e-4f5ba0b9c294@gmail.com>



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().

>>
>>> +
>>> +    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);
>>

  reply	other threads:[~2023-10-27 21:32 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-22  5:03 [PATCH bpf-next v6 00/10] Registrating struct_ops types from modules thinker.li
2023-10-22  5:03 ` [PATCH bpf-next v6 01/10] bpf: refactory struct_ops type initialization to a function thinker.li
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 03/10] bpf: add struct_ops_tab to btf thinker.li
2023-10-22  5:03 ` [PATCH bpf-next v6 04/10] bpf: hold module for bpf_struct_ops_map thinker.li
2023-10-26 21:11   ` Eduard Zingerman
2023-10-27  4:35     ` Kui-Feng Lee
2023-10-22  5:03 ` [PATCH bpf-next v6 05/10] bpf: validate value_type thinker.li
2023-10-22  5:03 ` [PATCH bpf-next v6 06/10] bpf: pass attached BTF to the bpf_struct_ops subsystem thinker.li
2023-10-22  5:03 ` [PATCH bpf-next v6 07/10] bpf, net: switch to dynamic registration thinker.li
2023-10-22  6:46   ` kernel test robot
2023-10-26 21:02   ` Eduard Zingerman
2023-10-27  4:39     ` Kui-Feng Lee
2023-10-27 21:32       ` Kui-Feng Lee [this message]
2023-10-27 22:02         ` Eduard Zingerman
2023-10-22  5:03 ` [PATCH bpf-next v6 08/10] libbpf: Find correct module BTFs for struct_ops maps and progs thinker.li
2023-10-22  5:03 ` [PATCH bpf-next v6 09/10] bpf: export btf_ctx_access to modules thinker.li
2023-10-22  5:03 ` [PATCH bpf-next v6 10/10] selftests/bpf: test case for register_bpf_struct_ops() thinker.li
2023-10-22  7:08   ` kernel test robot
2023-10-26 20:31   ` Eduard Zingerman
2023-10-27  4:55     ` Kui-Feng Lee
2023-10-27  7:09       ` Kui-Feng Lee
2023-10-27 14:13       ` Eduard Zingerman
2023-10-29  2:34     ` 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=df8f71ce-4e3b-4e65-a197-e2ce0ca494de@gmail.com \
    --to=sinquersw@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=drosen@google.com \
    --cc=eddyz87@gmail.com \
    --cc=kernel-team@meta.com \
    --cc=kuifeng@meta.com \
    --cc=martin.lau@linux.dev \
    --cc=netdev@vger.kernel.org \
    --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.