From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Benjamin Tissoires <benjamin.tissoires@redhat.com>,
Florent Revest <revest@chromium.org>,
Mark Rutland <mark.rutland@arm.com>,
KP Singh <kpsingh@kernel.org>
Cc: Jon Hunter <jonathanh@nvidia.com>,
Greg KH <gregkh@linuxfoundation.org>,
Jiri Kosina <jikos@kernel.org>, Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <shuah@kernel.org>,
Tero Kristo <tero.kristo@linux.intel.com>,
LKML <linux-kernel@vger.kernel.org>,
"open list:HID CORE LAYER" <linux-input@vger.kernel.org>,
bpf <bpf@vger.kernel.org>,
"open list:KERNEL SELFTEST FRAMEWORK"
<linux-kselftest@vger.kernel.org>,
"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
"linux-tegra@vger.kernel.org" <linux-tegra@vger.kernel.org>
Subject: Re: [PATCH hid v12 03/15] HID: initial BPF implementation
Date: Wed, 23 Nov 2022 12:13:47 -0800 [thread overview]
Message-ID: <CAADnVQ+kE+EJ9LAfwge9ksC0LR8r+ShQNYi5g-MDajufXq8Yxw@mail.gmail.com> (raw)
In-Reply-To: <CAO-hwJJZxgeTT8mLwFrYynSVASva=o7qL9Kr4xOywV3KDUu2GA@mail.gmail.com>
On Wed, Nov 23, 2022 at 6:53 AM Benjamin Tissoires
<benjamin.tissoires@redhat.com> wrote:
>
> Hi Jon,
>
> On Wed, Nov 23, 2022 at 2:25 PM Jon Hunter <jonathanh@nvidia.com> wrote:
> >
> >
> > On 03/11/2022 15:57, Benjamin Tissoires wrote:
> > > Declare an entry point that can use fmod_ret BPF programs, and
> > > also an API to access and change the incoming data.
> > >
> > > A simpler implementation would consist in just calling
> > > hid_bpf_device_event() for any incoming event and let users deal
> > > with the fact that they will be called for any event of any device.
> > >
> > > The goal of HID-BPF is to partially replace drivers, so this situation
> > > can be problematic because we might have programs which will step on
> > > each other toes.
> > >
> > > For that, we add a new API hid_bpf_attach_prog() that can be called
> > > from a syscall and we manually deal with a jump table in hid-bpf.
> > >
> > > Whenever we add a program to the jump table (in other words, when we
> > > attach a program to a HID device), we keep the number of time we added
> > > this program in the jump table so we can release it whenever there are
> > > no other users.
> > >
> > > HID devices have an RCU protected list of available programs in the
> > > jump table, and those programs are called one after the other thanks
> > > to bpf_tail_call().
> > >
> > > To achieve the detection of users losing their fds on the programs we
> > > attached, we add 2 tracing facilities on bpf_prog_release() (for when
> > > a fd is closed) and bpf_free_inode() (for when a pinned program gets
> > > unpinned).
> > >
> > > Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > > Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
> >
> > ...
> >
> > > +static int __init hid_bpf_init(void)
> > > +{
> > > + int err;
> > > +
> > > + /* Note: if we exit with an error any time here, we would entirely break HID, which
> > > + * is probably not something we want. So we log an error and return success.
> > > + *
> > > + * This is not a big deal: the syscall allowing to attach a BPF program to a HID device
> > > + * will not be available, so nobody will be able to use the functionality.
> > > + */
> > > +
> > > + err = register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, &hid_bpf_kfunc_set);
> > > + if (err) {
> > > + pr_warn("error while setting HID BPF tracing kfuncs: %d", err);
> > > + return 0;
> > > + }
> > > +
> > > + err = hid_bpf_preload_skel();
> > > + if (err) {
> > > + pr_warn("error while preloading HID BPF dispatcher: %d", err);
> > > + return 0;
> > > + }
> > > +
> > > + /* register syscalls after we are sure we can load our preloaded bpf program */
> > > + err = register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, &hid_bpf_syscall_kfunc_set);
> > > + if (err) {
> > > + pr_warn("error while setting HID BPF syscall kfuncs: %d", err);
> > > + return 0;
> > > + }
> > > +
> > > + return 0;
> > > +}
> >
> >
> > We have a kernel test that checks for new warning and error messages on
> > boot and with this change I am now seeing the following error message on
> > our Tegra platforms ...
> >
> > WARNING KERN hid_bpf: error while preloading HID BPF dispatcher: -13
> >
> > I have a quick look at the code, but I can't say I am familiar with
> > this. So I wanted to ask if a way to fix this or avoid this? I see the
> > code returns 0, so one option would be to make this an informational or
> > debug print.
>
> I am not in favor of debug in that case, because I suspect it'll hide
> too much when getting a bug report. Informational could do, yes.
>
> However, before that, I'd like to dig a little bit more on why it is
> failing. I thought arm64 now has support of tracing bpf programs, so I
> would not expect this to fail.
Unfortunately the patches to add support for such tracing bpf progs got stuck.
Florent/Mark can probably share the latest status.
next prev parent reply other threads:[~2022-11-23 20:14 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-03 15:57 [PATCH hid v12 00/15] Introduce eBPF support for HID devices Benjamin Tissoires
2022-11-03 15:57 ` [PATCH hid v12 01/15] HID: fix I2C_HID not selected when I2C_HID_OF_ELAN is Benjamin Tissoires
2022-11-15 15:27 ` Jiri Kosina
2022-11-03 15:57 ` [PATCH hid v12 02/15] HID: Kconfig: split HID support and hid-core compilation Benjamin Tissoires
2022-11-03 15:57 ` [PATCH hid v12 03/15] HID: initial BPF implementation Benjamin Tissoires
2022-11-23 13:25 ` Jon Hunter
2022-11-23 14:48 ` Benjamin Tissoires
2022-11-23 18:47 ` Jon Hunter
2022-11-23 20:13 ` Alexei Starovoitov [this message]
2022-11-24 15:50 ` Benjamin Tissoires
2022-11-29 18:00 ` Florent Revest
2022-11-30 8:49 ` Benjamin Tissoires
2022-11-03 15:57 ` [PATCH hid v12 04/15] selftests: add tests for the HID-bpf initial implementation Benjamin Tissoires
2022-11-03 15:57 ` [PATCH hid v12 05/15] HID: bpf jmp table: simplify the logic of cleaning up programs Benjamin Tissoires
2022-12-12 17:02 ` Benjamin Tissoires
2022-12-12 17:08 ` Jiri Kosina
2022-12-12 17:52 ` Yonghong Song
2022-12-12 18:20 ` Greg KH
2022-12-12 18:39 ` Yonghong Song
2022-12-13 6:28 ` Greg KH
2022-12-13 7:59 ` Benjamin Tissoires
2022-12-13 18:13 ` Yonghong Song
2022-11-03 15:57 ` [PATCH hid v12 06/15] HID: bpf: allocate data memory for device_event BPF programs Benjamin Tissoires
2022-11-03 15:57 ` [PATCH hid v12 07/15] selftests/hid: add test to change the report size Benjamin Tissoires
2022-11-03 15:57 ` [PATCH hid v12 08/15] HID: bpf: introduce hid_hw_request() Benjamin Tissoires
2022-11-03 15:57 ` [PATCH hid v12 09/15] selftests/hid: add tests for bpf_hid_hw_request Benjamin Tissoires
2022-11-03 15:57 ` [PATCH hid v12 10/15] HID: bpf: allow to change the report descriptor Benjamin Tissoires
2022-11-03 15:57 ` [PATCH hid v12 11/15] selftests/hid: add report descriptor fixup tests Benjamin Tissoires
2022-11-03 15:57 ` [PATCH hid v12 12/15] selftests/hid: Add a test for BPF_F_INSERT_HEAD Benjamin Tissoires
2022-11-03 15:57 ` [PATCH hid v12 13/15] samples/hid: add new hid BPF example Benjamin Tissoires
2022-11-03 15:57 ` [PATCH hid v12 14/15] samples/hid: add Surface Dial example Benjamin Tissoires
2022-11-03 15:57 ` [PATCH hid v12 15/15] Documentation: add HID-BPF docs Benjamin Tissoires
2022-11-15 15:32 ` [PATCH hid v12 00/15] Introduce eBPF support for HID devices Jiri Kosina
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=CAADnVQ+kE+EJ9LAfwge9ksC0LR8r+ShQNYi5g-MDajufXq8Yxw@mail.gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=benjamin.tissoires@redhat.com \
--cc=bpf@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=gregkh@linuxfoundation.org \
--cc=jikos@kernel.org \
--cc=jonathanh@nvidia.com \
--cc=kpsingh@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=revest@chromium.org \
--cc=shuah@kernel.org \
--cc=tero.kristo@linux.intel.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).