A handle_events program should be able to parse the CQ and submit new requests, add kfuncs to cover that. The only essential kfunc here is bpf_io_uring_submit_sqes, and the rest are likely be removed in a non-RFC version in favour of a more general approach. Signed-off-by: Pavel Begunkov --- io_uring/bpf.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/io_uring/bpf.c b/io_uring/bpf.c index 683e87f1a58b..006cea78cc10 100644 --- a/io_uring/bpf.c +++ b/io_uring/bpf.c @@ -3,10 +3,55 @@ #include "bpf.h" #include "register.h" +#include "memmap.h" static DEFINE_MUTEX(io_bpf_ctrl_mutex); static const struct btf_type *loop_state_type; +__bpf_kfunc_start_defs(); + +__bpf_kfunc int bpf_io_uring_submit_sqes(struct io_ring_ctx *ctx, u32 nr) +{ + return io_submit_sqes(ctx, nr); +} + +__bpf_kfunc +__u8 *bpf_io_uring_get_region(struct io_ring_ctx *ctx, __u32 region_id, + const size_t rdwr_buf_size) +{ + struct io_mapped_region *r; + + switch (region_id) { + case 0: + r = &ctx->ring_region; + break; + case 1: + r = &ctx->sq_region; + break; + case 2: + r = &ctx->param_region; + break; + default: + return NULL; + } + + if (unlikely(rdwr_buf_size > io_region_size(r))) + return NULL; + return io_region_get_ptr(r); +} + +__bpf_kfunc_end_defs(); + +BTF_KFUNCS_START(io_uring_kfunc_set) +BTF_ID_FLAGS(func, bpf_io_uring_submit_sqes, KF_SLEEPABLE | KF_TRUSTED_ARGS); +BTF_ID_FLAGS(func, bpf_io_uring_get_region, KF_RET_NULL | KF_TRUSTED_ARGS); +BTF_KFUNCS_END(io_uring_kfunc_set) + +static const struct btf_kfunc_id_set bpf_io_uring_kfunc_set = { + .owner = THIS_MODULE, + .set = &io_uring_kfunc_set, +}; + static int io_bpf_ops__loop(struct io_ring_ctx *ctx, struct iou_loop_state *ls) { return IOU_RES_STOP; @@ -68,12 +113,20 @@ io_lookup_struct_type(struct btf *btf, const char *name) static int bpf_io_init(struct btf *btf) { + int ret; + loop_state_type = io_lookup_struct_type(btf, "iou_loop_state"); if (!loop_state_type) { pr_err("io_uring: Failed to locate iou_loop_state\n"); return -EINVAL; } + ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, + &bpf_io_uring_kfunc_set); + if (ret) { + pr_err("io_uring: Failed to register kfuncs (%d)\n", ret); + return ret; + } return 0; } -- 2.49.0