From: sashiko-bot@kernel.org
To: "Yongpeng Yang" <yangyongpeng.storage@gmail.com>,
"Alasdair Kergon" <agk@redhat.com>,
"Mike Snitzer" <snitzer@kernel.org>,
"Mikulas Patocka" <mpatocka@redhat.com>,
"Benjamin Marzinski" <bmarzins@redhat.com>
Cc: dm-devel@lists.linux.dev, "Yongpeng Yang" <yangyongpeng@xiaomi.com>
Subject: Re: [PATCH 2/4] dm-bufio: allow exposing a client in sysfs under a caller-chosen kobject
Date: Tue, 17 Nov 2026 13:40:55 +0000 [thread overview]
Message-ID: <sashiko-outbox-218893@kernel.org> (raw)
In-Reply-To: <20261117131918.2745193-5-yangyongpeng.storage@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] dm-bufio: module unload race in dm_bufio_kobj_release()
- [Medium] dm-bufio: double free of kobj.name if
dm_bufio_client_sysfs_add() is retried
- [Medium] dm-bufio: missing sysfs unregistration API breaks DM table
reloads
--
commit 865aec6258e84e1a7aa1322dc0e3b22f9e5e966b
Author: Yongpeng Yang <yangyongpeng@xiaomi.com>
dm-bufio: allow exposing a client in sysfs under a caller-chosen kobject
This commit adds dm_bufio_client_sysfs_add() to expose per-client dm-bufio
statistics and the writable retain_bytes target in sysfs under a
caller-supplied kobject.
> diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
> index 75b6e5c027ae2..627a64f981c5c 100644
> --- a/drivers/md/dm-bufio.c
> +++ b/drivers/md/dm-bufio.c
[ ... ]
> @@ -2504,6 +2510,144 @@ static unsigned long dm_bufio_shrink_count(struct shrinker *shrink, struct shrin
[ ... ]
> +static void dm_bufio_kobj_release(struct kobject *kobj)
> +{
> + struct dm_bufio_client *c = container_of(kobj, struct dm_bufio_client, kobj);
> +
> + /*
> + * The client is freed only after this completes, as in dm-sysfs.
> + */
> + complete(&c->kobj_unregister);
> +}
> +
> +static const struct kobj_type dm_bufio_ktype = {
> + .sysfs_ops = &dm_bufio_sysfs_ops,
> + .default_groups = dm_bufio_groups,
> + .release = dm_bufio_kobj_release,
> +};
> +
> +static int dm_bufio_kobj_add(struct dm_bufio_client *c, struct kobject *parent,
> + const char *name)
> +{
> + init_completion(&c->kobj_unregister);
> +
> + return kobject_init_and_add(&c->kobj, &dm_bufio_ktype, parent, "%s",
> + name);
> +}
> +
> +/* Drop the sysfs reference and wait for the release method to run. */
> +static void dm_bufio_kobj_del(struct dm_bufio_client *c)
> +{
> + kobject_put(&c->kobj);
> + wait_for_completion(&c->kobj_unregister);
> +}
[Severity: Medium]
Can dm-bufio.ko be unloaded while another task is still returning from
dm_bufio_kobj_release()?
CONFIG_DM_BUFIO is tristate, so dm_bufio_kobj_release() lives in
loadable module text. If the last reference to c->kobj is dropped by
another context after dm_bufio_kobj_del() calls kobject_put() (for
example, a concurrent sysfs reader or kobject_delayed_cleanup()), that
context can be preempted right after complete(&c->kobj_unregister):
CPU0 CPU1
dm_bufio_client_destroy()
dm_bufio_kobj_del()
kobject_put(&c->kobj)
kobject_put(&c->kobj)
dm_bufio_kobj_release()
complete(&c->kobj_unregister)
<preempted>
wait_for_completion()
kfree(c)
delete_module("dm_bufio")
return; <-- unmapped module text
dm-sysfs avoids this race by placing dm_kobject_release() in built-in
code in drivers/md/dm-builtin.c.
> +
> +int dm_bufio_client_sysfs_add(struct dm_bufio_client *c, struct kobject *parent,
> + const char *name)
> +{
> + int r;
> +
> + if (c->sysfs_added)
> + return -EBUSY;
> +
> + r = dm_bufio_kobj_add(c, parent, name);
> + if (r) {
> + dm_bufio_kobj_del(c);
> + return r;
> + }
> +
> + c->sysfs_added = true;
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(dm_bufio_client_sysfs_add);
[Severity: Medium]
Does retrying dm_bufio_client_sysfs_add() after a failed call double free
c->kobj.name?
When kobject_init_and_add() fails after kobject_init() and
kobject_set_name_vargs(), dm_bufio_kobj_del() runs kobject_cleanup(),
which calls kfree_const(c->kobj.name) without clearing c->kobj.name or
c->kobj.state_initialized. Because c->sysfs_added remains false and
c->kobj is not zeroed on the error path, a second call to
dm_bufio_client_sysfs_add() on the same client triggers the
state_initialized warning in kobject_init() and then calls
kfree_const(kobj->name) on the dangling pointer in
kobject_set_name_vargs().
> @@ -2660,6 +2804,9 @@ void dm_bufio_client_destroy(struct dm_bufio_client *c)
> {
> unsigned int i;
>
> + if (c->sysfs_added)
> + dm_bufio_kobj_del(c);
> +
> drop_buffers(c);
>
> shrinker_free(c->shrinker);
[Severity: Medium]
How can a device-mapper target reload its table without colliding on the
sysfs directory when c->kobj is only removed in
dm_bufio_client_destroy()?
During a table reload in do_resume(), dm_suspend() suspends the old table
and dm_resume() resumes the new table before dm_table_destroy() destroys
the old table and its dm_bufio_client. When a target registers its
clients under the device-level path /sys/block/<dm-device>/dm-bufio/<name>
(as documented in Documentation/ABI/testing/sysfs-kernel-dm-bufio and
used by dm-verity in commit "dm-verity: size the hash retain target from
the hash area"), the old table's sysfs entries are still present when the
new table resumes, so kobject_init_and_add() fails with -EEXIST and
triggers a dump_stack() warning in sysfs_warn_dup(). Without an exported
unregistration helper that targets can call during suspend, reloading a
table fails to publish the new client's sysfs directory and leaves the
device without /sys/block/<dm-device>/dm-bufio/ once the old table is
destroyed.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117131918.2745193-2-yangyongpeng.storage@gmail.com?part=2
next prev parent reply other threads:[~2026-11-17 13:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 13:19 [PATCH 0/4] dm-bufio: per-client retain target, sysfs and dm-verity cache control Yongpeng Yang
2026-11-17 13:19 ` [PATCH 1/4] dm-bufio: make the retain target per client Yongpeng Yang
2026-11-18 0:41 ` Benjamin Marzinski
2026-11-17 13:19 ` [PATCH 2/4] dm-bufio: allow exposing a client in sysfs under a caller-chosen kobject Yongpeng Yang
2026-11-17 13:40 ` sashiko-bot [this message]
2026-11-17 13:19 ` [PATCH 3/4] dm-verity: size the hash retain target from the hash area Yongpeng Yang
2026-11-17 13:44 ` sashiko-bot
2026-11-17 13:19 ` [PATCH 4/4] dm-verity: add messages to inspect, prefetch and drop hash blocks Yongpeng Yang
2026-11-17 13:49 ` sashiko-bot
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=sashiko-outbox-218893@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agk@redhat.com \
--cc=bmarzins@redhat.com \
--cc=dm-devel@lists.linux.dev \
--cc=mpatocka@redhat.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=snitzer@kernel.org \
--cc=yangyongpeng.storage@gmail.com \
--cc=yangyongpeng@xiaomi.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.