From: Jens Axboe <axboe@kernel.dk>
To: io-uring@vger.kernel.org
Cc: brauner@kernel.org, linux-kernel@vger.kernel.org,
Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 1/2] io_uring/bpf_filter: move filter size and populate helper into struct
Date: Wed, 11 Feb 2026 08:01:17 -0700 [thread overview]
Message-ID: <20260211150626.136826-2-axboe@kernel.dk> (raw)
In-Reply-To: <20260211150626.136826-1-axboe@kernel.dk>
Rather than open-code this logic in io_uring_populate_bpf_ctx() with
a switch, move it to the issue side definitions. Outside of making this
easier to extend in the future, it's also a prep patch for using the
pdu size for a given opcode filter elsewhere.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
io_uring/bpf_filter.c | 17 ++++++-----------
io_uring/opdef.c | 6 ++++++
io_uring/opdef.h | 6 ++++++
3 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/io_uring/bpf_filter.c b/io_uring/bpf_filter.c
index 3816883a45ed..8ac7d06de122 100644
--- a/io_uring/bpf_filter.c
+++ b/io_uring/bpf_filter.c
@@ -26,6 +26,8 @@ static const struct io_bpf_filter dummy_filter;
static void io_uring_populate_bpf_ctx(struct io_uring_bpf_ctx *bctx,
struct io_kiocb *req)
{
+ const struct io_issue_def *def = &io_issue_defs[req->opcode];
+
bctx->opcode = req->opcode;
bctx->sqe_flags = (__force int) req->flags & SQE_VALID_FLAGS;
bctx->user_data = req->cqe.user_data;
@@ -34,19 +36,12 @@ static void io_uring_populate_bpf_ctx(struct io_uring_bpf_ctx *bctx,
sizeof(*bctx) - offsetof(struct io_uring_bpf_ctx, pdu_size));
/*
- * Opcodes can provide a handler fo populating more data into bctx,
+ * Opcodes can provide a handler for populating more data into bctx,
* for filters to use.
*/
- switch (req->opcode) {
- case IORING_OP_SOCKET:
- bctx->pdu_size = sizeof(bctx->socket);
- io_socket_bpf_populate(bctx, req);
- break;
- case IORING_OP_OPENAT:
- case IORING_OP_OPENAT2:
- bctx->pdu_size = sizeof(bctx->open);
- io_openat_bpf_populate(bctx, req);
- break;
+ if (def->filter_pdu_size) {
+ bctx->pdu_size = def->filter_pdu_size;
+ def->filter_populate(bctx, req);
}
}
diff --git a/io_uring/opdef.c b/io_uring/opdef.c
index df52d760240e..91a23baf415e 100644
--- a/io_uring/opdef.c
+++ b/io_uring/opdef.c
@@ -221,8 +221,10 @@ const struct io_issue_def io_issue_defs[] = {
.issue = io_fallocate,
},
[IORING_OP_OPENAT] = {
+ .filter_pdu_size = sizeof_field(struct io_uring_bpf_ctx, open),
.prep = io_openat_prep,
.issue = io_openat,
+ .filter_populate = io_openat_bpf_populate,
},
[IORING_OP_CLOSE] = {
.prep = io_close_prep,
@@ -309,8 +311,10 @@ const struct io_issue_def io_issue_defs[] = {
#endif
},
[IORING_OP_OPENAT2] = {
+ .filter_pdu_size = sizeof_field(struct io_uring_bpf_ctx, open),
.prep = io_openat2_prep,
.issue = io_openat2,
+ .filter_populate = io_openat_bpf_populate,
},
[IORING_OP_EPOLL_CTL] = {
.unbound_nonreg_file = 1,
@@ -406,8 +410,10 @@ const struct io_issue_def io_issue_defs[] = {
[IORING_OP_SOCKET] = {
.audit_skip = 1,
#if defined(CONFIG_NET)
+ .filter_pdu_size = sizeof_field(struct io_uring_bpf_ctx, socket),
.prep = io_socket_prep,
.issue = io_socket,
+ .filter_populate = io_socket_bpf_populate,
#else
.prep = io_eopnotsupp_prep,
#endif
diff --git a/io_uring/opdef.h b/io_uring/opdef.h
index aa37846880ff..faf3955dce8b 100644
--- a/io_uring/opdef.h
+++ b/io_uring/opdef.h
@@ -2,6 +2,8 @@
#ifndef IOU_OP_DEF_H
#define IOU_OP_DEF_H
+struct io_uring_bpf_ctx;
+
struct io_issue_def {
/* needs req->file assigned */
unsigned needs_file : 1;
@@ -33,8 +35,12 @@ struct io_issue_def {
/* size of async data needed, if any */
unsigned short async_size;
+ /* bpf filter pdu size, if any */
+ unsigned short filter_pdu_size;
+
int (*issue)(struct io_kiocb *, unsigned int);
int (*prep)(struct io_kiocb *, const struct io_uring_sqe *);
+ void (*filter_populate)(struct io_uring_bpf_ctx *, struct io_kiocb *);
};
struct io_cold_def {
--
2.51.0
next prev parent reply other threads:[~2026-02-11 15:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-11 15:01 [PATCHSET 0/2] cBPF filter API adjustment Jens Axboe
2026-02-11 15:01 ` Jens Axboe [this message]
2026-02-11 15:01 ` [PATCH 2/2] io_uring/bpf_filter: pass in expected filter payload size Jens Axboe
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=20260211150626.136826-2-axboe@kernel.dk \
--to=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=io-uring@vger.kernel.org \
--cc=linux-kernel@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