From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Cc: Benjamin Tissoires <bentiss@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>, Jiri Kosina <jikos@kernel.org>,
Jonathan Corbet <corbet@lwn.net>, Shuah Khan <shuah@kernel.org>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-input@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH RFC bpf-next 0/9] allow HID-BPF to do device IOs
Date: Mon, 12 Feb 2024 18:46:34 +0100 [thread overview]
Message-ID: <87r0hhfudh.fsf@toke.dk> (raw)
In-Reply-To: <CAO-hwJLvEGNRXc8G2PR+AQ6kJg+k5YqSt3F7LCSc0zWnmFfe5g@mail.gmail.com>
Benjamin Tissoires <benjamin.tissoires@redhat.com> writes:
[...]
>> IIUC, the bpf_timer callback is just a function (subprog) from the
>> verifier PoV, so it is verified as whatever program type is creating the
>> timer. So in other words, as long as you setup the timer from inside a
>> tracing prog type, you should have access to all the same kfuncs, I
>> think?
>
> Yep, you are correct. But as mentioned above, I am now in trouble with
> the sleepable state:
> - I need to call timer_start() from a non sleepable tracing function
> (I'm in hard IRQ when dealing with a physical device)
> - but then, ideally, the callback function needs to be tagged as a
> sleepable one, so I can export my kfuncs which are doing kzalloc and
> device IO as such.
>
> However, I can not really teach the BPF verifier to do so:
> - it seems to check for the callback first when it is loaded, and
> there is no SEC() equivalent for static functions
> - libbpf doesn't have access to the callback as a prog as it has to be
> a static function, and thus isn't exported as a full-blown prog.
> - the verifier only checks for the callback when dealing with
> BPF_FUNC_timer_set_callback, which doesn't have a "flag" argument
> (though the validation of the callback has already been done while
> checking it first, so we are already too late to change the sleppable
> state of the callback)
>
> Right now, the only OK-ish version I have is declaring the kfunc as
> non-sleepable, but checking that we are in a different context than
> the IRQ of the initial event. This way, I am not crashing if this
> function is called from the initial IRQ, but will still crash if used
> outside of the hid context.
>
> This is not satisfactory, but I feel like it's going to be hard to
> teach the verifier that the callback function is sleepable in that
> case (maybe we could suffix the callback name, like we do for
> arguments, but this is not very clean either).
The callback is only set once when the timer is first setup; I *think*
it works to do the setup (bpf_timer_init() and bpf_timer_set_callback())
in the context you need (from a sleepable prog), but do the arming
(bpf_timer_start()) from a different program that is not itself sleepable?
-Toke
next prev parent reply other threads:[~2024-02-12 17:46 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-09 13:26 [PATCH RFC bpf-next 0/9] allow HID-BPF to do device IOs Benjamin Tissoires
2024-02-09 13:26 ` [PATCH RFC bpf-next 1/9] bpf: allow more maps in sleepable bpf programs Benjamin Tissoires
2024-02-09 13:26 ` [PATCH RFC bpf-next 2/9] HID: bpf/dispatch: regroup kfuncs definitions Benjamin Tissoires
2024-02-09 13:26 ` [PATCH RFC bpf-next 3/9] HID: bpf: export hid_hw_output_report as a BPF kfunc Benjamin Tissoires
2024-02-09 13:26 ` [PATCH RFC bpf-next 4/9] selftests/hid: Add test for hid_bpf_hw_output_report Benjamin Tissoires
2024-02-09 13:26 ` [PATCH RFC bpf-next 5/9] HID: bpf: allow to inject HID event from BPF Benjamin Tissoires
2024-02-09 13:26 ` [PATCH RFC bpf-next 6/9] selftests/hid: add tests for hid_bpf_input_report Benjamin Tissoires
2024-02-09 13:26 ` [PATCH RFC bpf-next 7/9] HID: bpf: allow to defer work in a delayed workqueue Benjamin Tissoires
2024-02-09 13:26 ` [PATCH RFC bpf-next 8/9] selftests/hid: add test for hid_bpf_schedule_delayed_work Benjamin Tissoires
2024-02-09 13:26 ` [PATCH RFC bpf-next 9/9] selftests/hid: add another set of delayed work tests Benjamin Tissoires
2024-02-09 15:42 ` [PATCH RFC bpf-next 0/9] allow HID-BPF to do device IOs Toke Høiland-Jørgensen
2024-02-09 16:26 ` Benjamin Tissoires
2024-02-09 17:05 ` Toke Høiland-Jørgensen
2024-02-12 16:47 ` Benjamin Tissoires
2024-02-12 17:46 ` Toke Høiland-Jørgensen [this message]
2024-02-12 18:20 ` Benjamin Tissoires
2024-02-12 21:24 ` Alexei Starovoitov
2024-02-13 17:46 ` Benjamin Tissoires
2024-02-13 19:23 ` Kumar Kartikeya Dwivedi
2024-02-13 19:51 ` Toke Høiland-Jørgensen
2024-02-13 20:52 ` Alexei Starovoitov
2024-02-14 12:56 ` Toke Høiland-Jørgensen
2024-02-13 20:48 ` Alexei Starovoitov
2024-02-14 17:10 ` Benjamin Tissoires
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=87r0hhfudh.fsf@toke.dk \
--to=toke@redhat.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=benjamin.tissoires@redhat.com \
--cc=bentiss@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=jikos@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--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=martin.lau@linux.dev \
--cc=sdf@google.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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.