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 <[email protected]> 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: [email protected] > +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/[email protected] -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=2
