From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com, bpf@vger.kernel.org, axboe@kernel.dk,
Alexei Starovoitov <alexei.starovoitov@gmail.com>
Subject: [PATCH io_uring-7.1 v6 0/5] BPF controlled io_uring
Date: Wed, 11 Feb 2026 19:04:51 +0000 [thread overview]
Message-ID: <cover.1770836401.git.asml.silence@gmail.com> (raw)
This series introduces a way to override the standard io_uring_enter
syscall execution with an extendible event loop, which can be controlled
by BPF via new io_uring struct_ops or from within the kernel.
There are multiple use cases I want to cover with this:
- Syscall avoidance. Instead of returning to the userspace for
CQE processing, a part of the logic can be moved into BPF to
avoid excessive number of syscalls.
- Access to in-kernel io_uring resources. For example, there are
registered buffers that can't be directly accessed by the userspace,
however we can give BPF the ability to peek at them. It can be used
to take a look at in-buffer app level headers to decide what to do
with data next and issuing IO using it.
- Smarter request ordering and linking. Request links are pretty
limited and inflexible as they can't pass information from one
request to another. With BPF we can peek at CQEs and memory and
compile a subsequent request.
- Feature semi-deprecation. It can be used to simplify handling
of deprecated features by moving it into the callback out core
io_uring. For example, it should be trivial to simulate
IOSQE_IO_DRAIN. Another target could be request linking logic.
- It can serve as a base for custom algorithms and fine tuning.
Often, it'd be impractical to introduce a generic feature because
it's either niche or requires a lot of configuration. For example,
there is support min-wait, however BPF can help to further fine tune
it by doing it in multiple steps with different number of CQEs /
timeouts. Another feature people were asking about is allowing
to over queue SQEs but make the kernel to maintain a given QD.
- Smarter polling. Napi polling is performed only once per syscall
and then it switches to waiting. We can do smarter and intermix
polling with waiting using the hook.
It might need more specialised kfuncs in the future, but the core
functionality is implemented with just two simple functions. One
returns region memory, which gives BPF access to CQ/SQ/etc. And
the second is for submitting requests. It's also given a structure
as an argument, which is used to pass waiting parameters.
It showed good numbers in a test that sequentially executes N nop
requests, where BPF was more than twice as fast than a 2-nop
request link implementation.
I've got ideas on how the user space part while writing toy programs,
mostly about simplifying life to BPF writers, but I want to turn it
into something more cohesive before posting.
v6: - Fix inversed check on ejection leaving function pointer and
add a selftest checking that.
- Add spdx headers
- Remove sqe reassignment in selftests
v5: - Selftests are now using vmlinux.h
- Checking for unexpected loop return codes
- Remove KF_TRUSTED_ARGS (default)
- Squashed one of the patches, it's more sensible this way
v4: - Separated the event loop from the normal waiting path.
- Improved the selftest.
v3: - Removed most of utility kfuncs and replaced it with a single
helper returning the ring memory.
- Added KF_TRUSTED_ARGS to kfuncs
- Fix ifdef guarding
- Added a selftest
- Adjusted the waiting loop
- Reused the bpf lock section for task_work execution
Pavel Begunkov (5):
io_uring: introduce callback driven main loop
io_uring/bpf-ops: implement loop_step with BPF struct_ops
io_uring/bpf-ops: add kfunc helpers
io_uring/bpf-ops: implement bpf ops registration
selftests/io_uring: add a bpf io_uring selftest
include/linux/io_uring_types.h | 10 +
io_uring/Kconfig | 5 +
io_uring/Makefile | 3 +-
io_uring/bpf-ops.c | 272 ++++++++++++++++++
io_uring/bpf-ops.h | 28 ++
io_uring/io_uring.c | 8 +
io_uring/loop.c | 97 +++++++
io_uring/loop.h | 27 ++
tools/testing/selftests/Makefile | 3 +-
tools/testing/selftests/io_uring/Makefile | 162 +++++++++++
tools/testing/selftests/io_uring/common.h | 7 +
.../selftests/io_uring/nops_loop.bpf.c | 131 +++++++++
tools/testing/selftests/io_uring/nops_loop.c | 110 +++++++
tools/testing/selftests/io_uring/unreg.bpf.c | 26 ++
tools/testing/selftests/io_uring/unreg.c | 113 ++++++++
15 files changed, 1000 insertions(+), 2 deletions(-)
create mode 100644 io_uring/bpf-ops.c
create mode 100644 io_uring/bpf-ops.h
create mode 100644 io_uring/loop.c
create mode 100644 io_uring/loop.h
create mode 100644 tools/testing/selftests/io_uring/Makefile
create mode 100644 tools/testing/selftests/io_uring/common.h
create mode 100644 tools/testing/selftests/io_uring/nops_loop.bpf.c
create mode 100644 tools/testing/selftests/io_uring/nops_loop.c
create mode 100644 tools/testing/selftests/io_uring/unreg.bpf.c
create mode 100644 tools/testing/selftests/io_uring/unreg.c
--
2.52.0
next reply other threads:[~2026-02-11 19:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-11 19:04 Pavel Begunkov [this message]
2026-02-11 19:04 ` [PATCH v6 1/5] io_uring: introduce callback driven main loop Pavel Begunkov
2026-02-11 19:04 ` [PATCH v6 2/5] io_uring/bpf-ops: implement loop_step with BPF struct_ops Pavel Begunkov
2026-02-11 19:04 ` [PATCH v6 3/5] io_uring/bpf-ops: add kfunc helpers Pavel Begunkov
2026-02-11 19:04 ` [PATCH v6 4/5] io_uring/bpf-ops: implement bpf ops registration Pavel Begunkov
2026-02-11 19:04 ` [PATCH v6 5/5] selftests/io_uring: add a bpf io_uring selftest Pavel Begunkov
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=cover.1770836401.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=axboe@kernel.dk \
--cc=bpf@vger.kernel.org \
--cc=io-uring@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox