All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yongpeng Yang" <yangyongpeng.storage@gmail.com>,
	agk@redhat.com, bmarzins@redhat.com, dm-devel@lists.linux.dev,
	mpatocka@redhat.com, snitzer@kernel.org
Cc: yangyongpeng@xiaomi.com
Subject: Re: [PATCH v2 2/4] dm-bufio: allow exposing a client in sysfs under a caller-chosen kobject
Date: Wed, 18 Nov 2026 17:57:54 +0000	[thread overview]
Message-ID: <sashiko-outbox-221706@kernel.org> (raw)
In-Reply-To: <20261118172133.689163-4-yangyongpeng.storage@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] dm-bufio: sysfs client exposure retained despite maintainer
  direction
- [Medium] dm-bufio: module unload race in dm_bufio_kobj_release()
- [Low] dm-bufio: undocumented dm_bufio_client_sysfs_detach() and
  lifetime claims
--

commit a1c1b2bd57f6306f0bce7f21a188c32909bec5c3
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() and
dm_bufio_client_sysfs_detach() to expose a dm-bufio client's attributes and
writable retain_bytes target in sysfs under a caller-supplied kobject.

> diff --git a/Documentation/ABI/testing/sysfs-kernel-dm-bufio b/Documentation/ABI/testing/sysfs-kernel-dm-bufio
> new file mode 100644
> index 0000000000000..bccd679c1b607
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-kernel-dm-bufio
> @@ -0,0 +1,76 @@
> +What:		/sys/block/<dm-device>/dm-bufio/<name>/
> +Date:		November 2026
> +KernelVersion:	7.4
> +Contact:	dm-devel@lists.linux.dev
> +Description:
> +		Directory exposing one dm-bufio client whose user opted in
> +		through dm_bufio_client_sysfs_add().  <name> is chosen by that
> +		user; dm-verity, which places the directory under the block
> +		device of its own dm device, uses <name> "hash" for the hash
> +		tree client, "fec" for the FEC parity client and "fec-data"
> +		for the FEC data client.  The directory lives from
> +		registration until the client is destroyed, independently of
> +		any device-mapper table loaded on the device, so a suspend or
> +		table reload never leaves dangling entries behind.  The
> +		read-only counters are instantaneous snapshots and may be
> +		approximate.

[Severity: High]
As reported by Mikulas Patocka on v1 [1], should dm-bufio clients be
exposed in sysfs at all?

Multiple targets in a device-mapper table would clash under the same
/sys/block/<dm-device>/dm-bufio/ directory, and reloading a table creates a
new dm_bufio_client and discards any retain_bytes value configured in
sysfs.  The maintainer requested configuring dm-bufio parameters through
device-mapper target messages or constructor arguments instead.

[ ... ]

> diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
> index 367f878c17dc1..a2991dcd532fb 100644
> --- a/drivers/md/dm-bufio.c
> +++ b/drivers/md/dm-bufio.c
[ ... ]
> @@ -2505,6 +2511,165 @@ 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 dm_bufio_kobj_release() is still
executing?

CONFIG_DM_BUFIO is tristate, and when the release callback runs
asynchronously (for example via kobject_delayed_cleanup() under
CONFIG_DEBUG_KOBJECT_RELEASE=y, or when another task drops the last kobject
reference), the caller waiting in dm_bufio_kobj_del() unblocks as soon as
complete() is called:

CPU0                              CPU1
dm_bufio_client_destroy()
  dm_bufio_kobj_del()
    kobject_put(&c->kobj)
    wait_for_completion()
                                  kobject_release()
                                    dm_bufio_kobj_release()
                                      complete(&c->kobj_unregister)
                                      <preempted>
  kfree(c)
sys_delete_module("dm_bufio")
                                      return;  <-- unmapped module text

2995fa78e423 ("dm sysfs: fix a module unload race") added
dm_kobject_release() in drivers/md/dm-builtin.c (always built into vmlinux
when CONFIG_BLK_DEV_DM is enabled) so kobject release callbacks that signal
a completion do not reside in unloadable module text.

> diff --git a/include/linux/dm-bufio.h b/include/linux/dm-bufio.h
> index 9bf3f805c43c2..ac168ac797e4f 100644
> --- a/include/linux/dm-bufio.h
> +++ b/include/linux/dm-bufio.h
[ ... ]
> @@ -165,6 +166,14 @@ void dm_bufio_set_minimum_buffers(struct dm_bufio_client *c, unsigned int n);
>  void dm_bufio_set_retain_bytes(struct dm_bufio_client *c, unsigned long bytes);
>  unsigned long dm_bufio_get_retain_bytes(struct dm_bufio_client *c);
>  
> +/*
> + * Publish the client as <name> under <parent> in sysfs; removed in
> + * dm_bufio_client_destroy().
> + */
> +int dm_bufio_client_sysfs_add(struct dm_bufio_client *c, struct kobject *parent,
> +			      const char *name);
> +void dm_bufio_client_sysfs_detach(struct dm_bufio_client *c);

[Severity: Low]
This comment, the commit message, Documentation/ABI/testing/sysfs-kernel-dm-bufio,
and Documentation/admin-guide/device-mapper/dm-bufio.rst all state that the
sysfs directory lives from registration until the client is destroyed in
dm_bufio_client_destroy(), without mentioning dm_bufio_client_sysfs_detach()
or that dm_bufio_client_sysfs_add() can re-attach a detached directory
across suspend and table reload.

[1] https://lore.kernel.org/r/d4fc9150-4768-f747-ca97-688bc9bebc46@redhat.com

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118172133.689163-2-yangyongpeng.storage@gmail.com?part=2

  reply	other threads:[~2026-11-18 17:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 17:21 [PATCH v2 0/4] dm-bufio: per-client retain target, sysfs and dm-verity cache control Yongpeng Yang
2026-11-18 17:21 ` [PATCH v2 1/4] dm-bufio: make the retain target per client Yongpeng Yang
2026-11-18 17:21 ` [PATCH v2 2/4] dm-bufio: allow exposing a client in sysfs under a caller-chosen kobject Yongpeng Yang
2026-11-18 17:57   ` sashiko-bot [this message]
2026-11-18 17:21 ` [PATCH v2 3/4] dm-verity: size the hash retain target from the hash area Yongpeng Yang
2026-11-18 17:50   ` sashiko-bot
2026-11-18 17:21 ` [PATCH v2 4/4] dm-verity: add messages to inspect, prefetch and drop hash blocks Yongpeng Yang
2026-11-18 17:43   ` 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-221706@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.