All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Tissoires <bentiss@kernel.org>
To: Jiri Kosina <jikos@kernel.org>,
	 Benjamin Tissoires <benjamin.tissoires@redhat.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Benjamin Tissoires <bentiss@kernel.org>,
	stable@vger.kernel.org
Subject: [PATCH 3/3] HID: bpf: lazy load the hid_tail_call entrypoint
Date: Fri, 19 Apr 2024 16:47:53 +0200	[thread overview]
Message-ID: <20240419-hid_bpf_lazy_skel-v1-3-9210bcd4b61c@kernel.org> (raw)
In-Reply-To: <20240419-hid_bpf_lazy_skel-v1-0-9210bcd4b61c@kernel.org>

Turns out that on some professional distributions, with things partly
backported (not sure exactly), loading this kernel bpf program might
enter a RCU task deadlock.

Given that it actually does not make sense to preload this in every
environment, we can lazy load it the first time we need it, i.e. the
first time the kfunc hid_bpf_attach_prog() is called.

Cc: stable@vger.kernel.org
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
---
 drivers/hid/bpf/hid_bpf_dispatch.c  | 6 ------
 drivers/hid/bpf/hid_bpf_jmp_table.c | 7 +++++++
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/hid/bpf/hid_bpf_dispatch.c b/drivers/hid/bpf/hid_bpf_dispatch.c
index 10289f44d0cc..1946ad962d03 100644
--- a/drivers/hid/bpf/hid_bpf_dispatch.c
+++ b/drivers/hid/bpf/hid_bpf_dispatch.c
@@ -642,12 +642,6 @@ static int __init hid_bpf_init(void)
 		return 0;
 	}
 
-	err = hid_bpf_preload_skel();
-	if (err) {
-		pr_warn("error while preloading HID BPF dispatcher: %d", err);
-		return 0;
-	}
-
 	/* 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) {
diff --git a/drivers/hid/bpf/hid_bpf_jmp_table.c b/drivers/hid/bpf/hid_bpf_jmp_table.c
index 301ac79db241..75ce215f0ada 100644
--- a/drivers/hid/bpf/hid_bpf_jmp_table.c
+++ b/drivers/hid/bpf/hid_bpf_jmp_table.c
@@ -404,6 +404,13 @@ __hid_bpf_attach_prog(struct hid_device *hdev, enum hid_bpf_prog_type prog_type,
 
 	mutex_lock(&hid_bpf_attach_lock);
 
+	if (!jmp_table.map) {
+		err = hid_bpf_preload_skel();
+		WARN_ONCE(err, "error while preloading HID BPF dispatcher: %d", err);
+		if (err)
+			goto err_unlock;
+	}
+
 	link = kzalloc(sizeof(*link), GFP_USER);
 	if (!link) {
 		err = -ENOMEM;

-- 
2.44.0


  parent reply	other threads:[~2024-04-19 14:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-19 14:47 [PATCH 0/3] HID: bpf: some fixes for pre-loading HID-BPF Benjamin Tissoires
2024-04-19 14:47 ` [PATCH 1/3] HID: bpf: fix a comment in a define Benjamin Tissoires
2024-04-19 14:47 ` [PATCH 2/3] HID: bpf: fix return value of entrypoints_*__attach() Benjamin Tissoires
2024-04-19 14:47 ` Benjamin Tissoires [this message]
2024-04-23  7:10   ` [PATCH 3/3] HID: bpf: lazy load the hid_tail_call entrypoint Dan Carpenter
2024-04-24 14:17     ` Benjamin Tissoires
2024-04-25 12:52       ` Benjamin Tissoires
2024-04-23  3:49 kernel test robot

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=20240419-hid_bpf_lazy_skel-v1-3-9210bcd4b61c@kernel.org \
    --to=bentiss@kernel.org \
    --cc=benjamin.tissoires@redhat.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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.