From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com, bpf@vger.kernel.org
Subject: [PATCH v4 3/6] io_uring/bpf-ops: add loop_step struct_ops callback
Date: Tue, 27 Jan 2026 10:14:07 +0000 [thread overview]
Message-ID: <05a3f3c4b6f1e3117ba90ba87611c292f436bcb5.1769470552.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1769470552.git.asml.silence@gmail.com>
Allow BPF to implement the loop_step callback to overwrite the main loop
logic. As described in the patch introducing the callback, it receives
iou_loop_params as an argument, which BPF can directly use to control
the loop.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
io_uring/bpf-ops.c | 36 ++++++++++++++++++++++++++++++++++++
io_uring/bpf-ops.h | 4 ++++
2 files changed, 40 insertions(+)
diff --git a/io_uring/bpf-ops.c b/io_uring/bpf-ops.c
index a89d1dea60c7..7db07eda5a48 100644
--- a/io_uring/bpf-ops.c
+++ b/io_uring/bpf-ops.c
@@ -1,11 +1,22 @@
#include <linux/mutex.h>
#include <linux/bpf.h>
+#include <linux/bpf_verifier.h>
#include "io_uring.h"
#include "register.h"
#include "bpf-ops.h"
+#include "loop.h"
+
+static const struct btf_type *loop_params_type;
+
+static int io_bpf_ops__loop_step(struct io_ring_ctx *ctx,
+ struct iou_loop_params *lp)
+{
+ return IOU_LOOP_STOP;
+}
static struct io_uring_bpf_ops io_bpf_ops_stubs = {
+ .loop_step = io_bpf_ops__loop_step,
};
static bool bpf_io_is_valid_access(int off, int size,
@@ -27,6 +38,14 @@ static int bpf_io_btf_struct_access(struct bpf_verifier_log *log,
const struct bpf_reg_state *reg, int off,
int size)
{
+ const struct btf_type *t = btf_type_by_id(reg->btf, reg->btf_id);
+
+ if (t == loop_params_type) {
+ if (off >= offsetof(struct iou_loop_params, cq_wait_idx) &&
+ off + size <= offsetofend(struct iou_loop_params, cq_wait_idx))
+ return SCALAR_VALUE;
+ }
+
return -EACCES;
}
@@ -36,8 +55,25 @@ static const struct bpf_verifier_ops bpf_io_verifier_ops = {
.btf_struct_access = bpf_io_btf_struct_access,
};
+static const struct btf_type *
+io_lookup_struct_type(struct btf *btf, const char *name)
+{
+ s32 type_id;
+
+ type_id = btf_find_by_name_kind(btf, name, BTF_KIND_STRUCT);
+ if (type_id < 0)
+ return NULL;
+ return btf_type_by_id(btf, type_id);
+}
+
static int bpf_io_init(struct btf *btf)
{
+ loop_params_type = io_lookup_struct_type(btf, "iou_loop_params");
+ if (!loop_params_type) {
+ pr_err("io_uring: Failed to locate iou_loop_params\n");
+ return -EINVAL;
+ }
+
return 0;
}
diff --git a/io_uring/bpf-ops.h b/io_uring/bpf-ops.h
index a6756b391387..e8a08ae2df0a 100644
--- a/io_uring/bpf-ops.h
+++ b/io_uring/bpf-ops.h
@@ -5,6 +5,10 @@
#include <linux/io_uring_types.h>
struct io_uring_bpf_ops {
+ int (*loop_step)(struct io_ring_ctx *ctx, struct iou_loop_params *lp);
+
+ __u32 ring_fd;
+ void *priv;
};
#endif /* IOU_BPF_OPS_H */
--
2.52.0
next prev parent reply other threads:[~2026-01-27 10:14 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-27 10:14 [PATCH v4 0/6] BPF controlled io_uring Pavel Begunkov
2026-01-27 10:14 ` [PATCH v4 1/6] io_uring: introduce callback driven main loop Pavel Begunkov
2026-01-27 10:14 ` [PATCH v4 2/6] io_uring/bpf-ops: add basic bpf struct_ops boilerplate Pavel Begunkov
2026-01-27 10:14 ` Pavel Begunkov [this message]
2026-01-27 10:14 ` [PATCH v4 4/6] io_uring/bpf-ops: add kfunc helpers Pavel Begunkov
2026-01-27 10:14 ` [PATCH v4 5/6] io_uring/bpf-ops: add bpf struct ops registration Pavel Begunkov
2026-01-27 10:14 ` [PATCH v4 6/6] selftests/io_uring: add a bpf io_uring selftest Pavel Begunkov
2026-01-27 17:32 ` Alexei Starovoitov
2026-01-27 18:42 ` Pavel Begunkov
2026-01-27 18:53 ` Alexei Starovoitov
2026-01-27 19:20 ` 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=05a3f3c4b6f1e3117ba90ba87611c292f436bcb5.1769470552.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--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