Skip to contentSkip to conversation

bpf: export btf_find_by_name_kind and bpf_base_func_proto

PATCH Superseded Ming Lei 3 participants 7 messages Jul 24, 2024 – Jul 26, 2024 BPF

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 bpf: export btf_find_by_name_kind and bpf_base_func_proto

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 <[email protected]>
Cc Jiri Kosina <[email protected]>
---
 kernel/bpf/btf.c     | 1 +
 kernel/bpf/helpers.c | 1 +
 2 files changed, 2 insertions(+)
kernel/bpf/btf.c +1 -0
index d5019c4454d6..fdc4c0c1829d 100644
@@ -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)
 {
kernel/bpf/helpers.c +1 -0
index b5f0adae8293..18d1a76f96d2 100644
@@ -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)
Signature · 1 line
2.45.2
#1 lore raw
Quoted 6 lines · Ming Lei

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!

Quoted 33 lines
Cc Benjamin Tissoires <[email protected]>
Cc Jiri Kosina <[email protected]>
---
  kernel/bpf/btf.c     | 1 +
  kernel/bpf/helpers.c | 1 +
  2 files changed, 2 insertions(+)
kernel/bpf/btf.c +1 -0
index d5019c4454d6..fdc4c0c1829d 100644
@@ -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)
  {
kernel/bpf/helpers.c +1 -0
index b5f0adae8293..18d1a76f96d2 100644
@@ -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)
author
#2 lore raw
Quoted 6 lines · Kui-Feng Lee
Quoted 3 lines · Ming Lei

Export btf_find_by_name_kind and bpf_base_func_proto, so that kernel module can use them.

Quoted 7 lines
Quoted 3 lines

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

reviewer
#3 lore raw
Quoted 12 lines · Ming Lei
Quoted 11 lines · Kui-Feng Lee
Quoted 6 lines · Ming Lei

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?

Quoted 7 lines

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?

Quoted 9 lines

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

author
#4 lore raw
Quoted 20 lines · Yonghong Song
Quoted 17 lines · Ming Lei
Quoted 11 lines · Kui-Feng Lee
Quoted 6 lines · Ming Lei

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

Quoted 5 lines
Quoted 2 lines

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

reviewer
#5 lore raw
Quoted 21 lines · Ming Lei
Quoted 20 lines · Yonghong Song
Quoted 18 lines · Ming Lei
Quoted 10 lines · Kui-Feng Lee
Quoted 6 lines · Ming Lei

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.

Quoted 7 lines
Quoted 2 lines

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.

Quoted 4 lines

Thanks,
Ming

author
#6 lore raw
Quoted 35 lines · Yonghong Song
Quoted 21 lines · Ming Lei
Quoted 20 lines · Yonghong Song
Quoted 18 lines · Ming Lei
Quoted 10 lines · Kui-Feng Lee
Quoted 6 lines · Ming Lei

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.

Quoted 7 lines
Quoted 2 lines

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.

Quoted 7 lines

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!