Skip to contentSkip to conversation

bpf: export btf_find_by_name_kind and bpf_base_func_proto

PATCH In review Ming Lei 4 participants 6 messages Jul 26, 2024 – Aug 1, 2024 BPF

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH v2 1/1 bpf: export btf_find_by_name_kind and bpf_base_func_proto

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

In-tree hid-bpf code(drivers/hid/bpf/hid_bpf_struct_ops.c) can't be built as module because the two APIs aren't exported.

Export btf_find_by_name_kind and bpf_base_func_proto, so that any kernel module can use them given bpf community is supporting to register struct_ops in module, see the patchset "Registrating struct_ops types from modules"[1], which is merged to v6.9.

Cc Yonghong Song <[email protected]>
Cc Benjamin Tissoires <[email protected]>
Cc Jiri Kosina <[email protected]>

---
V2:
- add more details in commit log (Yonghong)
- add 'bpf-next' in patch title (Yonghong)

 kernel/bpf/btf.c     | 1 +
 kernel/bpf/helpers.c | 1 +
 2 files changed, 2 insertions(+)
kernel/bpf/btf.c +1 -0
index 520f49f422fe..519c6e5a57d5 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.42.0
reviewer Acked-by on v2 1/1
#1 lore raw
Quoted 10 lines · Ming Lei

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

In-tree hid-bpf code(drivers/hid/bpf/hid_bpf_struct_ops.c) can't be built as module because the two APIs aren't exported.

Export btf_find_by_name_kind and bpf_base_func_proto, so that any kernel module can use them given bpf community is supporting to register struct_ops in module, see the patchset "Registrating struct_ops types from modules"[1], which is merged to v6.9.

Quoted 4 lines
Cc Yonghong Song <[email protected]>
Cc Benjamin Tissoires <[email protected]>
Cc Jiri Kosina <[email protected]>
Acked-by on v2 1/1
#2 lore raw
In reply to Ming Lei
Quoted 40 lines · Ming Lei

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

In-tree hid-bpf code(drivers/hid/bpf/hid_bpf_struct_ops.c) can't be built as module because the two APIs aren't exported.

Export btf_find_by_name_kind and bpf_base_func_proto, so that any kernel module can use them given bpf community is supporting to register struct_ops in module, see the patchset "Registrating struct_ops types from modules"[1], which is merged to v6.9.

Cc Yonghong Song <[email protected]>
Cc Benjamin Tissoires <[email protected]>
Cc Jiri Kosina <[email protected]>

---
V2:
- add more details in commit log (Yonghong)
- add 'bpf-next' in patch title (Yonghong)

  kernel/bpf/btf.c     | 1 +
  kernel/bpf/helpers.c | 1 +
  2 files changed, 2 insertions(+)
kernel/bpf/btf.c +1 -0
index 520f49f422fe..519c6e5a57d5 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 +0 -0
index b5f0adae8293..18d1a76f96d2 100644

kernel/bpf/helpers.c bpf_base_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) · line 2039

Quoted 7 lines
kernel/bpf/helpers.c +1 -0
@@ -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)
#3 lore raw
In reply to Ming Lei
Quoted 4 lines · Ming Lei

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

In-tree hid-bpf code(drivers/hid/bpf/hid_bpf_struct_ops.c) can't be built as module because the two APIs aren't exported.

The patch looks fine. I don't see "config HID_BPF" can be built as a module now though that could expose this issue. Did I miss something?

Quoted 5 lines

Export btf_find_by_name_kind and bpf_base_func_proto, so that any kernel module can use them given bpf community is supporting to register struct_ops in module, see the patchset "Registrating struct_ops types from modules"[1], which is merged to v6.9.

author
#4 lore raw
Quoted 9 lines · Martin KaFai Lau
Quoted 4 lines · Ming Lei

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

In-tree hid-bpf code(drivers/hid/bpf/hid_bpf_struct_ops.c) can't be built as module because the two APIs aren't exported.

The patch looks fine. I don't see "config HID_BPF" can be built as a module now though that could expose this issue. Did I miss something?

Yeah, this patch doesn't try to change HID_BPF yet, and it can be thought as one struct_ops module prep patch.

The issue itself is observed when I write ublk-bpf since ublk is one module and struct_ops is allowed to be registered in the module.

Thanks,
Ming

#5 lore raw
Quoted 8 lines · Ming Lei
Quoted 7 lines · Martin KaFai Lau
Quoted 4 lines · Ming Lei

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

In-tree hid-bpf code(drivers/hid/bpf/hid_bpf_struct_ops.c) can't be built as module because the two APIs aren't exported.

Quoted 8 lines
Quoted 2 lines

The patch looks fine. I don't see "config HID_BPF" can be built as a module now though that could expose this issue. Did I miss something?

Yeah, this patch doesn't try to change HID_BPF yet, and it can be thought as one struct_ops module prep patch.

The issue itself is observed when I write ublk-bpf since ublk is one module and struct_ops is allowed to be registered in the module.

Good to hear struct_ops find another potential use case. The ublk-bpf development cannot continue without building as kmod?

Instead of exporting it now and pending without a user, I will wait till the first in-tree kmod use case comes up first.