diff mbox series

[HID,for-next,v2,9/9] HID: bpf: reorder BPF registration

Message ID 20230113090935.1763477-10-benjamin.tissoires@redhat.com (mailing list archive)
State Accepted
Commit 0c2d572828a68e8416619e0832d4d55317cb3c57
Headers show
Series HID-BPF LLVM fixes, no more hacks | expand

Commit Message

Benjamin Tissoires Jan. 13, 2023, 9:09 a.m. UTC
Given that our initial BPF program is not using any kfuncs anymore,
we can reorder the initialization to first try to load it and then
register the kfuncs. This has the advantage of not exporting kfuncs
when HID-BPF is not working.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>

---

no changes in v2
---
 drivers/hid/bpf/hid_bpf_dispatch.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Alexei Starovoitov Jan. 15, 2023, 6 p.m. UTC | #1
On Fri, Jan 13, 2023 at 10:09:35AM +0100, Benjamin Tissoires wrote:
> Given that our initial BPF program is not using any kfuncs anymore,
> we can reorder the initialization to first try to load it and then
> register the kfuncs. This has the advantage of not exporting kfuncs
> when HID-BPF is not working.
> 
> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>

Acked-by: Alexei Starovoitov <ast@kernel.org>
diff mbox series

Patch

diff --git a/drivers/hid/bpf/hid_bpf_dispatch.c b/drivers/hid/bpf/hid_bpf_dispatch.c
index 26117b4ec016..8a034a555d4c 100644
--- a/drivers/hid/bpf/hid_bpf_dispatch.c
+++ b/drivers/hid/bpf/hid_bpf_dispatch.c
@@ -514,15 +514,16 @@  static int __init hid_bpf_init(void)
 		return 0;
 	}
 
-	err = register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, &hid_bpf_kfunc_set);
+	err = hid_bpf_preload_skel();
 	if (err) {
-		pr_warn("error while setting HID BPF tracing kfuncs: %d", err);
+		pr_warn("error while preloading HID BPF dispatcher: %d", err);
 		return 0;
 	}
 
-	err = hid_bpf_preload_skel();
+	/* register tracing kfuncs after we are sure we can load our preloaded bpf program */
+	err = register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, &hid_bpf_kfunc_set);
 	if (err) {
-		pr_warn("error while preloading HID BPF dispatcher: %d", err);
+		pr_warn("error while setting HID BPF tracing kfuncs: %d", err);
 		return 0;
 	}