BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tao Cui" <cui.tao@linux.dev>
Cc: mkoutny@suse.com, tj@kernel.org, hannes@cmpxchg.org, bpf@vger.kernel.org
Subject: Re: [PATCH] blk-iocost: add BPF struct_ops cost model support
Date: Wed, 16 Sep 2026 07:26:42 +0000	[thread overview]
Message-ID: <20260916072643.28D501F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260916071740.1068341-2-cui.tao@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] bpf: premature removal from lifecycle list causes map/memory leaks
--

commit e92f1828b80c32e5c3b26c9b38e384109bedf0de
Author: Tao Cui <cuitao@kylinos.cn>

blk-iocost: add BPF struct_ops cost model support

Add the iocost_model_ops struct_ops: a bound BPF model fully replaces
the builtin linear model on a device.

> diff --git a/block/blk-iocost-bpf.c b/block/blk-iocost-bpf.c
> new file mode 100644
> index 0000000000000..7f1f9a2e51cb2
> --- /dev/null
> +++ b/block/blk-iocost-bpf.c

[ ... ]

> +void iocost_bpf_model_put(const struct iocost_model_ops *ops)
> +{
> +	struct iocost_bpf_model *m;
> +
> +	mutex_lock(&iocost_bpf_reg_lock);
> +	list_for_each_entry(m, &iocost_bpf_lifecycle, lifecycle) {
> +		if (m->ops == ops)
> +			break;
> +	}
> +	if (&m->lifecycle != &iocost_bpf_lifecycle) {
[Severity: High]
If a single registered BPF iocost model is bound to multiple block devices
and one of them unbinds it, does this skip the cleanup block entirely on
subsequent unbinds?

Because the model is prematurely removed from the lifecycle list below,
subsequent unbinds will fail to find it in the loop above. 

This causes iocost_bpf_model_put() to return early, permanently leaking BPF
struct_ops map references and iocost_bpf_model structures, as well as missing
blkcg online/offline notifications for active bindings.

> +		bool freed = refcount_dec_and_test(&m->refs);
> +
> +		/* leave the notify list with the last binding: the
> +		 * remaining ref is either the registry's (node still on
> +		 * iocost_bpf_models) or zero and the node is freed
> +		 */
> +		if (freed || !list_empty(&m->list))
> +			list_del(&m->lifecycle);
[Severity: High]
Can this condition cause the model to be removed from the lifecycle list on
the very first unbind?

The condition !list_empty(&m->list) evaluates to true unconditionally for
any registered model because m->list remains actively linked in the
registry (iocost_bpf_models) until it is unregistered.

> +		mutex_unlock(&iocost_bpf_reg_lock);
> +		bpf_struct_ops_put(ops);
> +		if (freed)
> +			kfree(m);
> +		return;
> +	}
> +	mutex_unlock(&iocost_bpf_reg_lock);
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260916071740.1068341-2-cui.tao@linux.dev?part=1

      reply	other threads:[~2026-09-16  7:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16  7:17 [RFC PATCH v4 0/5] blk-iocost: BPF struct_ops cost model Tao Cui
2026-09-16  7:17 ` [PATCH] blk-iocost: add BPF struct_ops cost model support Tao Cui
2026-09-16  7:26   ` sashiko-bot [this message]

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=20260916072643.28D501F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cui.tao@linux.dev \
    --cc=hannes@cmpxchg.org \
    --cc=mkoutny@suse.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tj@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