public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: io-uring@vger.kernel.org,
	Caleb Sander Mateos <csander@purestorage.com>,
	Akilesh Kailash <akailash@google.com>,
	bpf@vger.kernel.org, Xiao Ni <xni@redhat.com>,
	Alexei Starovoitov <ast@kernel.org>
Subject: Re: [PATCH V3 05/12] io_uring: bpf: extend io_uring with bpf struct_ops
Date: Sat, 4 Apr 2026 10:54:45 +0800	[thread overview]
Message-ID: <adB9dYjVAGFoIyTG@fedora> (raw)
In-Reply-To: <cb3e52fc-3dad-4385-b9b7-ade9add5292f@kernel.dk>

On Fri, Apr 03, 2026 at 09:46:29AM -0600, Jens Axboe wrote:
> On 4/2/26 10:17 PM, Ming Lei wrote:
> > On Wed, Mar 25, 2026 at 08:09:03PM -0600, Jens Axboe wrote:
> >> On 3/24/26 10:37 AM, Ming Lei wrote:
> >>>  int io_uring_bpf_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
> >>>  {
> >>> +	struct uring_bpf_data *data = io_kiocb_to_cmd(req, struct uring_bpf_data);
> >>> +	u32 opf = READ_ONCE(sqe->bpf_op_flags);
> >>> +	unsigned char bpf_op = uring_bpf_get_op(opf);
> >>> +	const struct uring_bpf_ops *ops;
> >>> +
> >>> +	if (unlikely(!(req->ctx->flags & IORING_SETUP_BPF_EXT)))
> >>> +		goto fail;
> >>> +
> >>> +	if (bpf_op >= IO_RING_MAX_BPF_OPS)
> >>> +		return -EINVAL;
> >>> +
> >>> +	ops = req->ctx->bpf_ext_ops[bpf_op].ops;
> >>> +	data->opf = opf;
> >>> +	data->ops = ops;
> >>> +	if (ops && ops->prep_fn)
> >>> +		return ops->prep_fn(data, sqe);
> >>> +fail:
> >>>  	return -EOPNOTSUPP;
> >>>  }
> >>
> >> Any early exit should ensure 'data' is sane, so that the cleanup doesn't
> >> potentially touch uninitialized crap. This is something that has bit us
> >> in the past. Not an issue for this patch that adds the code, but it will
> >> be once the next patch is applied. Better to clear ->opf/ops here
> >> upfront, so that we never leave this function without 'data' being fully
> >> initialized.
> > 
> > But ->cleanup() is only called in case of REQ_F_NEED_CLEANUP.
> > 
> > Or maybe you mean other cleanup instead of ->cleanup()?
> 
> I do mean ->cleanup() - what I'm trying to say here is that we've had
> cases of REQ_F_NEED_CLEANUP being set late, and hence missing cleanup
> for easily hit error conditions, and non-initialized data being exposed
> in cleanup. It's very easy to miss for later patches that adds another
> error condition. My recommendation is to fully initialize 'data' and set
> REQ_F_NEED_CLEANUP early, which handily avoids that for future changes
> too.

OK, your recommendation is definitely clean & safe, will take it.


Thanks,
Ming


  reply	other threads:[~2026-04-04  2:54 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-24 16:37 [PATCH v3 0/12] io_uring: add IORING_OP_BPF for extending io_uring Ming Lei
2026-03-24 16:37 ` [PATCH V3 01/12] io_uring: make io_import_fixed() global Ming Lei
2026-03-24 16:37 ` [PATCH V3 02/12] io_uring: refactor io_prep_reg_iovec() for BPF kfunc use Ming Lei
2026-03-24 16:37 ` [PATCH V3 03/12] io_uring: refactor io_import_reg_vec() " Ming Lei
2026-03-24 16:37 ` [PATCH V3 04/12] io_uring: prepare for extending io_uring with bpf Ming Lei
2026-03-24 16:37 ` [PATCH V3 05/12] io_uring: bpf: extend io_uring with bpf struct_ops Ming Lei
2026-03-26  1:49   ` Jens Axboe
2026-04-03  4:05     ` Ming Lei
2026-04-03 15:44       ` Jens Axboe
2026-04-04  2:53         ` Ming Lei
2026-03-26  2:09   ` Jens Axboe
2026-04-03  4:17     ` Ming Lei
2026-04-03 15:46       ` Jens Axboe
2026-04-04  2:54         ` Ming Lei [this message]
2026-03-24 16:37 ` [PATCH V3 06/12] io_uring: bpf: implement struct_ops registration Ming Lei
2026-03-24 16:37 ` [PATCH V3 07/12] io_uring: bpf: add BPF buffer descriptor for IORING_OP_BPF Ming Lei
2026-03-24 16:37 ` [PATCH V3 08/12] io_uring: bpf: add per-buffer iterator kfuncs Ming Lei
2026-03-24 16:37 ` [PATCH V3 09/12] bpf: add bpf_uring_buf_dynptr to special_kfunc_list Ming Lei
2026-03-24 16:37 ` [PATCH V3 10/12] selftests/io_uring: add io_uring_unregister_buffers() Ming Lei
2026-03-24 16:37 ` [PATCH V3 11/12] selftests/io_uring: add BPF struct_ops and kfunc tests Ming Lei
2026-03-24 16:37 ` [PATCH V3 12/12] selftests/io_uring: add buffer iterator selftest with BPF arena 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=adB9dYjVAGFoIyTG@fedora \
    --to=ming.lei@redhat.com \
    --cc=akailash@google.com \
    --cc=ast@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=bpf@vger.kernel.org \
    --cc=csander@purestorage.com \
    --cc=io-uring@vger.kernel.org \
    --cc=xni@redhat.com \
    /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