File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,6 +26,8 @@ static const struct io_bpf_filter dummy_filter;
2626static void io_uring_populate_bpf_ctx (struct io_uring_bpf_ctx * bctx ,
2727 struct io_kiocb * req )
2828{
29+ const struct io_issue_def * def = & io_issue_defs [req -> opcode ];
30+
2931 bctx -> opcode = req -> opcode ;
3032 bctx -> sqe_flags = (__force int ) req -> flags & SQE_VALID_FLAGS ;
3133 bctx -> user_data = req -> cqe .user_data ;
@@ -34,19 +36,12 @@ static void io_uring_populate_bpf_ctx(struct io_uring_bpf_ctx *bctx,
3436 sizeof (* bctx ) - offsetof(struct io_uring_bpf_ctx , pdu_size ));
3537
3638 /*
37- * Opcodes can provide a handler fo populating more data into bctx,
39+ * Opcodes can provide a handler for populating more data into bctx,
3840 * for filters to use.
3941 */
40- switch (req -> opcode ) {
41- case IORING_OP_SOCKET :
42- bctx -> pdu_size = sizeof (bctx -> socket );
43- io_socket_bpf_populate (bctx , req );
44- break ;
45- case IORING_OP_OPENAT :
46- case IORING_OP_OPENAT2 :
47- bctx -> pdu_size = sizeof (bctx -> open );
48- io_openat_bpf_populate (bctx , req );
49- break ;
42+ if (def -> filter_pdu_size ) {
43+ bctx -> pdu_size = def -> filter_pdu_size ;
44+ def -> filter_populate (bctx , req );
5045 }
5146}
5247
Original file line number Diff line number Diff line change @@ -221,8 +221,10 @@ const struct io_issue_def io_issue_defs[] = {
221221 .issue = io_fallocate ,
222222 },
223223 [IORING_OP_OPENAT ] = {
224+ .filter_pdu_size = sizeof_field (struct io_uring_bpf_ctx , open ),
224225 .prep = io_openat_prep ,
225226 .issue = io_openat ,
227+ .filter_populate = io_openat_bpf_populate ,
226228 },
227229 [IORING_OP_CLOSE ] = {
228230 .prep = io_close_prep ,
@@ -309,8 +311,10 @@ const struct io_issue_def io_issue_defs[] = {
309311#endif
310312 },
311313 [IORING_OP_OPENAT2 ] = {
314+ .filter_pdu_size = sizeof_field (struct io_uring_bpf_ctx , open ),
312315 .prep = io_openat2_prep ,
313316 .issue = io_openat2 ,
317+ .filter_populate = io_openat_bpf_populate ,
314318 },
315319 [IORING_OP_EPOLL_CTL ] = {
316320 .unbound_nonreg_file = 1 ,
@@ -406,8 +410,10 @@ const struct io_issue_def io_issue_defs[] = {
406410 [IORING_OP_SOCKET ] = {
407411 .audit_skip = 1 ,
408412#if defined(CONFIG_NET )
413+ .filter_pdu_size = sizeof_field (struct io_uring_bpf_ctx , socket ),
409414 .prep = io_socket_prep ,
410415 .issue = io_socket ,
416+ .filter_populate = io_socket_bpf_populate ,
411417#else
412418 .prep = io_eopnotsupp_prep ,
413419#endif
Original file line number Diff line number Diff line change 22#ifndef IOU_OP_DEF_H
33#define IOU_OP_DEF_H
44
5+ struct io_uring_bpf_ctx ;
6+
57struct io_issue_def {
68 /* needs req->file assigned */
79 unsigned needs_file : 1 ;
@@ -33,8 +35,12 @@ struct io_issue_def {
3335 /* size of async data needed, if any */
3436 unsigned short async_size ;
3537
38+ /* bpf filter pdu size, if any */
39+ unsigned short filter_pdu_size ;
40+
3641 int (* issue )(struct io_kiocb * , unsigned int );
3742 int (* prep )(struct io_kiocb * , const struct io_uring_sqe * );
43+ void (* filter_populate )(struct io_uring_bpf_ctx * , struct io_kiocb * );
3844};
3945
4046struct io_cold_def {
You can’t perform that action at this time.
0 commit comments