All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kui-Feng Lee <sinquersw@gmail.com>
To: Martin KaFai Lau <martin.lau@linux.dev>
Cc: kuifeng@meta.com, netdev@vger.kernel.org, bpf@vger.kernel.org,
	ast@kernel.org, song@kernel.org, kernel-team@meta.com,
	andrii@kernel.org, thinker.li@gmail.com, drosen@google.com
Subject: Re: [PATCH bpf-next v8 07/10] bpf, net: switch to dynamic registration
Date: Wed, 1 Nov 2023 17:59:30 -0700	[thread overview]
Message-ID: <c4427a57-aea9-4acc-a6be-e30cfb1dbaad@gmail.com> (raw)
In-Reply-To: <331802b3-07bd-7fec-32a7-b85a8dae1391@linux.dev>



On 11/1/23 17:17, Martin KaFai Lau wrote:
> On 10/31/23 5:19 PM, Kui-Feng Lee wrote:
>>
>>
>> On 10/31/23 17:02, Martin KaFai Lau wrote:
>>> On 10/31/23 4:34 PM, Kui-Feng Lee wrote:
>>>>>> diff --git a/include/linux/btf.h b/include/linux/btf.h
>>>>>> index a8813605f2f6..954536431e0b 100644
>>>>>> --- a/include/linux/btf.h
>>>>>> +++ b/include/linux/btf.h
>>>>>> @@ -12,6 +12,8 @@
>>>>>>   #include <uapi/linux/bpf.h>
>>>>>>   #define BTF_TYPE_EMIT(type) ((void)(type *)0)
>>>>>> +#define BTF_STRUCT_OPS_TYPE_EMIT(type) {((void)(struct type 
>>>>>> *)0);    \
>>>>>
>>>>> ((void)(struct type *)0); is new. Why is it needed?
>>>>
>>>> This is a trick of BTF to force compiler generate type info for
>>>> the given type. Without trick, compiler may skip these types if these
>>>> type are not used at all in the module.  For example, modules usually
>>>> don't use value types of struct_ops directly.
>>> It is not the value type and value type emit is understood. It is the 
>>> struct_ops type itself and it is new addition in this patchset 
>>> afaict. The value type emit is in the next line which was cut out 
>>> from the context here.
>>>
>> I mean both of them are required.
>> In the case of a dummy implementation, struct_ops type itself properly 
>> never being used, only being declared by the module. Without this line,
> 
> Other than bpf_dummy_ops, after reg(), the struct_ops->func() must be 
> used somewhere in the kernel or module. Like tcp must be using the 
> tcp_congestion_ops after reg(). bpf_dummy_ops is very special and 
> probably should be moved out to bpf_testmod somehow but this is for 
> later. Even bpf_dummy_ops does not have an issue now. Why it is needed 
> after the kmod support change?
> 
> or it is a preemptive addition to be future proof only?
> 
> Addition is fine if it is required to work. I am trying to understand 
> why this new addition is needed after the kmod support change. The 
> reason why this is needed after the kmod support change is not obvious 
> from looking at the code. The commit message didn't mention why and what 
> broke after this kmod change. If someone wants to clean it up a few 
> months later, we will need to figure out why it was added in the first 
> place.


It is a future proof.
What do you think if I add a comment in the code?

> 
> 
>> the module developer will fail to load a struct_ops map of the dummy
>> type. This line is added to avoid this awful situation.
>>
> 

  reply	other threads:[~2023-11-02  0:59 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 [this message]
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
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=c4427a57-aea9-4acc-a6be-e30cfb1dbaad@gmail.com \
    --to=sinquersw@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=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.