Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Low] dm-verity: missing return on kobject_add() error in verity_presuspend_undo() - [Low] dm-verity: redundant post-definition verity_register_bufio_sysfs() prototype - [Low] dm-verity: dead code and redundant kobject reallocation in verity_resume() --
commit 2adf10b9bb56217937bcf599cad99cc4d02fedf6 Author: Yongpeng Yang <[email protected]> dm-verity: size the hash retain target from the hash area This commit sets the default dm-bufio retain target for a dm-verity hash client to a configurable percentage of the hash area and publishes the dm-bufio clients in sysfs under /sys/block/dm-N/dm-bufio/. > diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c > index 6d589867623c0..15dee27d58a7a 100644 > --- a/drivers/md/dm-verity-target.c > +++ b/drivers/md/dm-verity-target.c [ ... ] > @@ -1797,6 +1825,49 @@ static inline void > verity_security_clear_integrity(struct dm_target *ti) > > #endif /* CONFIG_SECURITY */ > > +/* Detach the dm-bufio directories from sysfs, keeping the kobjects. */ > +static void verity_detach_bufio_sysfs(struct dm_verity *v) > +{ > + dm_bufio_client_sysfs_detach(v->bufio); > + if (verity_fec_is_enabled(v)) { > + dm_bufio_client_sysfs_detach(v->fec->bufio); > + dm_bufio_client_sysfs_detach(v->fec->data_bufio); > + } > + > + if (v->bufio_kobj && v->bufio_kobj->state_in_sysfs) > + kobject_del(v->bufio_kobj); > +} > + > +/* > + * Free the directory names before a table reload resumes a new > + * instance. Presuspend runs before the queue is frozen, so the kernfs > + * drain cannot block on I/O. > + */ > +static void verity_presuspend(struct dm_target *ti) > +{ > + verity_detach_bufio_sysfs(ti->private); > +} > + > +static void verity_presuspend_undo(struct dm_target *ti) > +{ > + struct dm_verity *v = ti->private; > + struct mapped_device *md = dm_table_get_md(v->ti->table); > + struct kobject *parent = &disk_to_dev(dm_disk(md))->kobj; > + > + if (!v->bufio_kobj) > + return; > + > + if (!v->bufio_kobj->state_in_sysfs && > + kobject_add(v->bufio_kobj, parent, "%s", "dm-bufio")) > + DMERR("cannot re-attach dm-bufio sysfs directory"); > + > + (void)dm_bufio_client_sysfs_add(v->bufio, v->bufio_kobj, "hash"); > + if (verity_fec_is_enabled(v)) { > + (void)dm_bufio_client_sysfs_add(v->fec->bufio, v->bufio_kobj, > "fec"); > + (void)dm_bufio_client_sysfs_add(v->fec->data_bufio, > v->bufio_kobj, "fec-data"); > + } > +} [Severity: Low] Should verity_presuspend_undo() return early when kobject_add() fails to re-attach v->bufio_kobj? Falling through passes the unattached v->bufio_kobj (with a NULL kernfs node) as the parent to dm_bufio_client_sysfs_add(), causing each child registration to fail with -ENOENT and emit additional kobject error messages. Also, the client registration sequence here duplicates verity_register_bufio_sysfs(). > static void verity_postsuspend(struct dm_target *ti) > { > struct dm_verity *v = ti->private; > @@ -1806,6 +1877,53 @@ static void verity_postsuspend(struct dm_target *ti) > verity_security_clear_integrity(ti); > } > > +/* > + * Publish the bufio clients under /sys/block/dm-N/dm-bufio/. This runs > + * from ->resume, not ->ctr, because the dm device's block device does not > + * exist until the table is loaded. > + */ > +static void verity_register_bufio_sysfs(struct dm_verity *v) > +{ > + struct mapped_device *md = dm_table_get_md(v->ti->table); > + struct kobject *parent = &disk_to_dev(dm_disk(md))->kobj; > + > + if (v->bufio_kobj) > + return; > + > + v->bufio_kobj = kobject_create_and_add("dm-bufio", parent); > + if (!v->bufio_kobj) { > + DMERR("cannot create dm-bufio sysfs directory"); > + return; > + } > + > + if (dm_bufio_client_sysfs_add(v->bufio, v->bufio_kobj, "hash")) > + DMERR("cannot register hash bufio client in sysfs"); > + > + if (verity_fec_is_enabled(v)) { > + if (dm_bufio_client_sysfs_add(v->fec->bufio, v->bufio_kobj, > "fec")) > + DMERR("cannot register FEC bufio client in sysfs"); > + if (dm_bufio_client_sysfs_add(v->fec->data_bufio, > v->bufio_kobj, "fec-data")) > + DMERR("cannot register FEC data bufio client in sysfs"); > + } > +} > + > +static void verity_resume(struct dm_target *ti) > +{ > + struct dm_verity *v = ti->private; > + > + if (v->bufio_kobj) { > + /* detached by presuspend, or re-attached by presuspend_undo */ > + if (v->bufio_kobj->state_in_sysfs) > + kobject_del(v->bufio_kobj); > + kobject_put(v->bufio_kobj); > + v->bufio_kobj = NULL; > + } > + > + verity_register_bufio_sysfs(v); > +} [Severity: Low] Why does verity_resume() drop and reallocate v->bufio_kobj instead of re-attaching it? The commit message notes that presuspend keeps the kobjects until the table is destroyed, and verity_register_bufio_sysfs() checks if v->bufio_kobj is already allocated, which is dead code because verity_resume() is its only caller and always clears v->bufio_kobj first. In addition, if v->bufio_kobj->state_in_sysfs were ever set on entry to verity_resume(), calling kobject_del(v->bufio_kobj) without detaching the child client kobjects first would leave their state_in_sysfs flags set and cause the subsequent dm_bufio_client_sysfs_add() calls to fail with -EBUSY. > + > +static void verity_register_bufio_sysfs(struct dm_verity *v); [Severity: Low] This isn't a bug, but this forward declaration of verity_register_bufio_sysfs() is placed after both its definition and its caller. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=3
