diff mbox series

bpf: export btf_find_by_name_kind and bpf_base_func_proto

Message ID 20240724031930.2606568-1-ming.lei@redhat.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series bpf: export btf_find_by_name_kind and bpf_base_func_proto | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 273 this patch: 273
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 8 maintainers not CCed: kpsingh@kernel.org haoluo@google.com daniel@iogearbox.net john.fastabend@gmail.com jolsa@kernel.org yonghong.song@linux.dev eddyz87@gmail.com sdf@fomichev.me
netdev/build_clang success Errors and warnings before: 281 this patch: 281
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 336 this patch: 336
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 14 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 9 this patch: 9
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-13 fail Logs for s390x-gcc / test (test_maps, false, 360) / test_maps on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-18 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
bpf/vmtest-bpf-next-VM_Test-42 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18

Commit Message

Ming Lei July 24, 2024, 3:19 a.m. UTC
Export btf_find_by_name_kind and bpf_base_func_proto, so that kernel
module can use them.

Almost all existed struct_ops users(hid, sched_ext, ...) need the two APIs.

Without this change, hid-bpf can't be built as module.

Cc: Benjamin Tissoires <bentiss@kernel.org>
Cc: Jiri Kosina <jikos@kernel.org>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 kernel/bpf/btf.c     | 1 +
 kernel/bpf/helpers.c | 1 +
 2 files changed, 2 insertions(+)

Comments

Kui-Feng Lee July 24, 2024, 4:43 a.m. UTC | #1
On 7/23/24 20:19, Ming Lei wrote:
> Export btf_find_by_name_kind and bpf_base_func_proto, so that kernel
> module can use them.
> 
> Almost all existed struct_ops users(hid, sched_ext, ...) need the two APIs.
> 
> Without this change, hid-bpf can't be built as module.

Could you give me more context?
Give me a link of an example code or something?
Or explain the use case?

Thanks!

> 
> Cc: Benjamin Tissoires <bentiss@kernel.org>
> Cc: Jiri Kosina <jikos@kernel.org>
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
>   kernel/bpf/btf.c     | 1 +
>   kernel/bpf/helpers.c | 1 +
>   2 files changed, 2 insertions(+)
> 
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index d5019c4454d6..fdc4c0c1829d 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -567,6 +567,7 @@ s32 btf_find_by_name_kind(const struct btf *btf, const char *name, u8 kind)
>   
>   	return -ENOENT;
>   }
> +EXPORT_SYMBOL_GPL(btf_find_by_name_kind);
>   
>   s32 bpf_find_btf_id(const char *name, u32 kind, struct btf **btf_p)
>   {
> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
> index b5f0adae8293..18d1a76f96d2 100644
> --- a/kernel/bpf/helpers.c
> +++ b/kernel/bpf/helpers.c
> @@ -2033,6 +2033,7 @@ bpf_base_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
>   		return NULL;
>   	}
>   }
> +EXPORT_SYMBOL_GPL(bpf_base_func_proto);
>   
>   void bpf_list_head_free(const struct btf_field *field, void *list_head,
>   			struct bpf_spin_lock *spin_lock)
Ming Lei July 24, 2024, 9:13 a.m. UTC | #2
On Tue, Jul 23, 2024 at 09:43:12PM -0700, Kui-Feng Lee wrote:
> 
> 
> On 7/23/24 20:19, Ming Lei wrote:
> > Export btf_find_by_name_kind and bpf_base_func_proto, so that kernel
> > module can use them.
> > 
> > Almost all existed struct_ops users(hid, sched_ext, ...) need the two APIs.
> > 
> > Without this change, hid-bpf can't be built as module.
> 
> Could you give me more context?
> Give me a link of an example code or something?
> Or explain the use case?

The merged patchset "Registrating struct_ops types from modules" is
trying to allow module to register struct_ops, which often needs
bpf_base_func_proto()(for allowing generic helpers available in
prog) and btf_find_by_name_kind() (for implementing .btf_struct_access).

One example is hid-bpf, which is a driver and supposed to build as module,
but it can't be done because the two APIs aren't exported.

I am working on ublk bpf support, which needs bpf_base_func_proto() at
least, and might require btf_find_by_name_kind() in future.


Thanks,
Ming
Yonghong Song July 26, 2024, 3:20 a.m. UTC | #3
On 7/24/24 2:13 AM, Ming Lei wrote:
> On Tue, Jul 23, 2024 at 09:43:12PM -0700, Kui-Feng Lee wrote:
>>
>> On 7/23/24 20:19, Ming Lei wrote:
>>> Export btf_find_by_name_kind and bpf_base_func_proto, so that kernel
>>> module can use them.
>>>
>>> Almost all existed struct_ops users(hid, sched_ext, ...) need the two APIs.
>>>
>>> Without this change, hid-bpf can't be built as module.
>> Could you give me more context?
>> Give me a link of an example code or something?
>> Or explain the use case?
> The merged patchset "Registrating struct_ops types from modules" is
> trying to allow module to register struct_ops, which often needs
> bpf_base_func_proto()(for allowing generic helpers available in
> prog) and btf_find_by_name_kind() (for implementing .btf_struct_access).
>
> One example is hid-bpf, which is a driver and supposed to build as module,
> but it can't be done because the two APIs aren't exported.

Could you give more specific examples about where these two APIs are
used in hid-bpf?

>
> I am working on ublk bpf support, which needs bpf_base_func_proto() at
> least, and might require btf_find_by_name_kind() in future.
>
>
> Thanks,
> Ming
>
>
Ming Lei July 26, 2024, 3:45 a.m. UTC | #4
On Fri, Jul 26, 2024 at 11:21 AM Yonghong Song <yonghong.song@linux.dev> wrote:
>
>
> On 7/24/24 2:13 AM, Ming Lei wrote:
> > On Tue, Jul 23, 2024 at 09:43:12PM -0700, Kui-Feng Lee wrote:
> >>
> >> On 7/23/24 20:19, Ming Lei wrote:
> >>> Export btf_find_by_name_kind and bpf_base_func_proto, so that kernel
> >>> module can use them.
> >>>
> >>> Almost all existed struct_ops users(hid, sched_ext, ...) need the two APIs.
> >>>
> >>> Without this change, hid-bpf can't be built as module.
> >> Could you give me more context?
> >> Give me a link of an example code or something?
> >> Or explain the use case?
> > The merged patchset "Registrating struct_ops types from modules" is
> > trying to allow module to register struct_ops, which often needs
> > bpf_base_func_proto()(for allowing generic helpers available in
> > prog) and btf_find_by_name_kind() (for implementing .btf_struct_access).
> >
> > One example is hid-bpf, which is a driver and supposed to build as module,
> > but it can't be done because the two APIs aren't exported.
>
> Could you give more specific examples about where these two APIs are
> used in hid-bpf?

Sure, hid-bpf struct_ops has been merged to linus tree already.

However, it can't be built as module because the two APIs aren't exported:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/hid/bpf/hid_bpf_struct_ops.c

Thanks,
Ming
Yonghong Song July 26, 2024, 5:39 a.m. UTC | #5
On 7/25/24 8:45 PM, Ming Lei wrote:
> On Fri, Jul 26, 2024 at 11:21 AM Yonghong Song <yonghong.song@linux.dev> wrote:
>>
>> On 7/24/24 2:13 AM, Ming Lei wrote:
>>> On Tue, Jul 23, 2024 at 09:43:12PM -0700, Kui-Feng Lee wrote:
>>>> On 7/23/24 20:19, Ming Lei wrote:
>>>>> Export btf_find_by_name_kind and bpf_base_func_proto, so that kernel
>>>>> module can use them.
>>>>>
>>>>> Almost all existed struct_ops users(hid, sched_ext, ...) need the two APIs.
>>>>>
>>>>> Without this change, hid-bpf can't be built as module.
>>>> Could you give me more context?
>>>> Give me a link of an example code or something?
>>>> Or explain the use case?
>>> The merged patchset "Registrating struct_ops types from modules" is
>>> trying to allow module to register struct_ops, which often needs
>>> bpf_base_func_proto()(for allowing generic helpers available in
>>> prog) and btf_find_by_name_kind() (for implementing .btf_struct_access).
>>>
>>> One example is hid-bpf, which is a driver and supposed to build as module,
>>> but it can't be done because the two APIs aren't exported.
>> Could you give more specific examples about where these two APIs are
>> used in hid-bpf?
> Sure, hid-bpf struct_ops has been merged to linus tree already.
>
> However, it can't be built as module because the two APIs aren't exported:
>
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/hid/bpf/hid_bpf_struct_ops.c

Okay, From the above hid_bpf_struct_ops.c, I do see bpf_base_func_proto() and
btf_find_by_name_kind() are used.

Your change looks good to me. Please add more details in the commit message and resubmit.
Your subject
    [PATCH] bpf: export btf_find_by_name_kind and bpf_base_func_proto
please change to
    [PATCH bpf-next] bpf: export btf_find_by_name_kind and bpf_base_func_proto

The above 'bpf-next' ensures CI to test your patch.

>
> Thanks,
> Ming
>
Ming Lei July 26, 2024, 11:52 a.m. UTC | #6
On Fri, Jul 26, 2024 at 1:40 PM Yonghong Song <yonghong.song@linux.dev> wrote:
>
>
> On 7/25/24 8:45 PM, Ming Lei wrote:
> > On Fri, Jul 26, 2024 at 11:21 AM Yonghong Song <yonghong.song@linux.dev> wrote:
> >>
> >> On 7/24/24 2:13 AM, Ming Lei wrote:
> >>> On Tue, Jul 23, 2024 at 09:43:12PM -0700, Kui-Feng Lee wrote:
> >>>> On 7/23/24 20:19, Ming Lei wrote:
> >>>>> Export btf_find_by_name_kind and bpf_base_func_proto, so that kernel
> >>>>> module can use them.
> >>>>>
> >>>>> Almost all existed struct_ops users(hid, sched_ext, ...) need the two APIs.
> >>>>>
> >>>>> Without this change, hid-bpf can't be built as module.
> >>>> Could you give me more context?
> >>>> Give me a link of an example code or something?
> >>>> Or explain the use case?
> >>> The merged patchset "Registrating struct_ops types from modules" is
> >>> trying to allow module to register struct_ops, which often needs
> >>> bpf_base_func_proto()(for allowing generic helpers available in
> >>> prog) and btf_find_by_name_kind() (for implementing .btf_struct_access).
> >>>
> >>> One example is hid-bpf, which is a driver and supposed to build as module,
> >>> but it can't be done because the two APIs aren't exported.
> >> Could you give more specific examples about where these two APIs are
> >> used in hid-bpf?
> > Sure, hid-bpf struct_ops has been merged to linus tree already.
> >
> > However, it can't be built as module because the two APIs aren't exported:
> >
> > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/hid/bpf/hid_bpf_struct_ops.c
>
> Okay, From the above hid_bpf_struct_ops.c, I do see bpf_base_func_proto() and
> btf_find_by_name_kind() are used.
>
> Your change looks good to me. Please add more details in the commit message and resubmit.
> Your subject
>     [PATCH] bpf: export btf_find_by_name_kind and bpf_base_func_proto
> please change to
>     [PATCH bpf-next] bpf: export btf_find_by_name_kind and bpf_base_func_proto
>
> The above 'bpf-next' ensures CI to test your patch.

OK, I will follow the above and post v2, and  thanks for the review!
diff mbox series

Patch

diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index d5019c4454d6..fdc4c0c1829d 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -567,6 +567,7 @@  s32 btf_find_by_name_kind(const struct btf *btf, const char *name, u8 kind)
 
 	return -ENOENT;
 }
+EXPORT_SYMBOL_GPL(btf_find_by_name_kind);
 
 s32 bpf_find_btf_id(const char *name, u32 kind, struct btf **btf_p)
 {
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
index b5f0adae8293..18d1a76f96d2 100644
--- a/kernel/bpf/helpers.c
+++ b/kernel/bpf/helpers.c
@@ -2033,6 +2033,7 @@  bpf_base_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
 		return NULL;
 	}
 }
+EXPORT_SYMBOL_GPL(bpf_base_func_proto);
 
 void bpf_list_head_free(const struct btf_field *field, void *list_head,
 			struct bpf_spin_lock *spin_lock)