From: Ming Lei <ming.lei@redhat.com>
To: Pavel Begunkov <asml.silence@gmail.com>
Cc: io-uring@vger.kernel.org, axboe@kernel.dk,
Martin KaFai Lau <martin.lau@linux.dev>,
bpf@vger.kernel.org,
Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>
Subject: Re: [PATCH v3 07/10] io_uring/bpf: implement struct_ops registration
Date: Mon, 24 Nov 2025 11:44:52 +0800 [thread overview]
Message-ID: <aSPUtMqilzaPui4f@fedora> (raw)
In-Reply-To: <cce6ee02362fe62aefab81de6ec0d26f43c6c22d.1763031077.git.asml.silence@gmail.com>
On Thu, Nov 13, 2025 at 11:59:44AM +0000, Pavel Begunkov wrote:
> Add ring_fd to the struct_ops and implement [un]registration.
>
> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
> ---
> include/linux/io_uring_types.h | 2 +
> io_uring/bpf.c | 69 +++++++++++++++++++++++++++++++++-
> 2 files changed, 70 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h
> index 43432a06d177..3a71ed2d05ea 100644
> --- a/include/linux/io_uring_types.h
> +++ b/include/linux/io_uring_types.h
> @@ -274,6 +274,8 @@ struct io_ring_ctx {
> unsigned int compat: 1;
> unsigned int iowq_limits_set : 1;
>
> + unsigned int bpf_installed: 1;
> +
> struct task_struct *submitter_task;
> struct io_rings *rings;
> struct percpu_ref refs;
> diff --git a/io_uring/bpf.c b/io_uring/bpf.c
> index 24dd2fe9134f..683e87f1a58b 100644
> --- a/io_uring/bpf.c
> +++ b/io_uring/bpf.c
> @@ -4,6 +4,7 @@
> #include "bpf.h"
> #include "register.h"
>
> +static DEFINE_MUTEX(io_bpf_ctrl_mutex);
> static const struct btf_type *loop_state_type;
>
> static int io_bpf_ops__loop(struct io_ring_ctx *ctx, struct iou_loop_state *ls)
> @@ -87,20 +88,86 @@ static int bpf_io_init_member(const struct btf_type *t,
> const struct btf_member *member,
> void *kdata, const void *udata)
> {
> + u32 moff = __btf_member_bit_offset(t, member) / 8;
> + const struct io_uring_ops *uops = udata;
> + struct io_uring_ops *ops = kdata;
> +
> + switch (moff) {
> + case offsetof(struct io_uring_ops, ring_fd):
> + ops->ring_fd = uops->ring_fd;
> + return 1;
> + }
> + return 0;
> +}
> +
> +static int io_install_bpf(struct io_ring_ctx *ctx, struct io_uring_ops *ops)
> +{
> + if (ctx->bpf_ops)
> + return -EBUSY;
> + ops->priv = ctx;
> + ctx->bpf_ops = ops;
> + ctx->bpf_installed = 1;
> return 0;
> }
>
> static int bpf_io_reg(void *kdata, struct bpf_link *link)
> {
> - return -EOPNOTSUPP;
> + struct io_uring_ops *ops = kdata;
> + struct io_ring_ctx *ctx;
> + struct file *file;
> + int ret = -EBUSY;
> +
> + file = io_uring_register_get_file(ops->ring_fd, false);
> + if (IS_ERR(file))
> + return PTR_ERR(file);
> + ctx = file->private_data;
> +
> + scoped_guard(mutex, &io_bpf_ctrl_mutex) {
> + guard(mutex)(&ctx->uring_lock);
> + ret = io_install_bpf(ctx, ops);
> + }
I feel per-io-uring struct_ops is less useful, because it means the io_uring
application has to be capable of loading/registering struct_ops prog, which
often needs privilege.
For example of IO link use case you mentioned, why does the application need
to get privilege for running IO link?
Thanks
Ming
next prev parent reply other threads:[~2025-11-24 3:45 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-13 11:59 [PATCH v3 00/10] BPF controlled io_uring Pavel Begunkov
2025-11-13 11:59 ` [PATCH v3 01/10] io_uring: rename the wait queue entry field Pavel Begunkov
2025-11-13 11:59 ` [PATCH v3 02/10] io_uring: simplify io_cqring_wait_schedule results Pavel Begunkov
2025-11-13 11:59 ` [PATCH v3 03/10] io_uring: export __io_run_local_work Pavel Begunkov
2025-11-13 11:59 ` [PATCH v3 04/10] io_uring: extract waiting parameters into a struct Pavel Begunkov
2025-11-13 11:59 ` [PATCH v3 05/10] io_uring/bpf: add stubs for bpf struct_ops Pavel Begunkov
2025-11-13 11:59 ` [PATCH v3 06/10] io_uring/bpf: add handle events callback Pavel Begunkov
2025-11-13 11:59 ` [PATCH v3 07/10] io_uring/bpf: implement struct_ops registration Pavel Begunkov
2025-11-24 3:44 ` Ming Lei [this message]
2025-11-24 13:12 ` Pavel Begunkov
2025-11-24 14:29 ` Ming Lei
2025-11-25 12:46 ` Pavel Begunkov
2025-11-13 11:59 ` [PATCH v3 08/10] io_uring/bpf: add basic kfunc helpers Pavel Begunkov
2025-11-13 11:59 ` [PATCH v3 09/10] selftests/io_uring: update mini liburing Pavel Begunkov
2025-11-13 11:59 ` [PATCH v3 10/10] selftests/io_uring: add bpf io_uring selftests Pavel Begunkov
2025-11-14 13:08 ` Ming Lei
2025-11-19 19:00 ` Pavel Begunkov
2025-11-20 1:41 ` Ming Lei
2025-11-21 16:12 ` Pavel Begunkov
2025-11-22 0:19 ` Ming Lei
2025-11-24 11:57 ` Pavel Begunkov
2025-11-24 13:28 ` Ming Lei
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=aSPUtMqilzaPui4f@fedora \
--to=ming.lei@redhat.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=bpf@vger.kernel.org \
--cc=io-uring@vger.kernel.org \
--cc=martin.lau@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox