mbox series

[v2,0/3] block: show crypto capabilities in sysfs

Message ID 20211130040306.148925-1-ebiggers@kernel.org
Headers show
Series block: show crypto capabilities in sysfs | expand

Message

Eric Biggers Nov. 30, 2021, 4:03 a.m. UTC
This series adds sysfs files that expose the inline encryption
capabilities of request queues.

Patches 1 and 2 are some related cleanups for existing blk-sysfs code.
Patch 3 is the real change; see there for more details.

This applies to linux-block/for-next.

Changed v1 => v2:
   - Use sysfs_emit() instead of sprintf().
   - Use __ATTR_RO().

Eric Biggers (3):
  block: simplify calling convention of elv_unregister_queue()
  block: don't delete queue kobject before its children
  blk-crypto: show crypto capabilities in sysfs

 Documentation/block/queue-sysfs.rst |  30 +++++
 block/Makefile                      |   3 +-
 block/blk-crypto-internal.h         |  12 ++
 block/blk-crypto-sysfs.c            | 172 ++++++++++++++++++++++++++++
 block/blk-crypto.c                  |   3 +
 block/blk-sysfs.c                   |  17 ++-
 block/elevator.c                    |   8 +-
 include/linux/blkdev.h              |   1 +
 8 files changed, 236 insertions(+), 10 deletions(-)
 create mode 100644 block/blk-crypto-sysfs.c


base-commit: c2626d30f312afc341158e07bf088f5a23b4eeeb

Comments

Hannes Reinecke Nov. 30, 2021, 6:44 a.m. UTC | #1
On 11/30/21 5:03 AM, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
> 
> Make elv_unregister_queue() a no-op if q->elevator is NULL or is not
> registered.
> 
> This simplifies the existing callers, as well as the future caller in
> the error path of blk_register_queue().
> 
> Also don't bother checking whether q is NULL, since it never is.
> 
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
>   block/blk-sysfs.c | 3 +--
>   block/elevator.c  | 8 ++++----
>   2 files changed, 5 insertions(+), 6 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
Greg KH Nov. 30, 2021, 7:09 a.m. UTC | #2
On Mon, Nov 29, 2021 at 08:03:05PM -0800, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
> 
> kobjects aren't supposed to be deleted before their child kobjects are
> deleted.  Apparently this is usually benign; however, a WARN will be
> triggered if one of the child kobjects has a named attribute group:
> 
>     sysfs group 'modes' not found for kobject 'crypto'
>     WARNING: CPU: 0 PID: 1 at fs/sysfs/group.c:278 sysfs_remove_group+0x72/0x80
>     ...
>     Call Trace:
>       sysfs_remove_groups+0x29/0x40 fs/sysfs/group.c:312
>       __kobject_del+0x20/0x80 lib/kobject.c:611
>       kobject_cleanup+0xa4/0x140 lib/kobject.c:696
>       kobject_release lib/kobject.c:736 [inline]
>       kref_put include/linux/kref.h:65 [inline]
>       kobject_put+0x53/0x70 lib/kobject.c:753
>       blk_crypto_sysfs_unregister+0x10/0x20 block/blk-crypto-sysfs.c:159
>       blk_unregister_queue+0xb0/0x110 block/blk-sysfs.c:962
>       del_gendisk+0x117/0x250 block/genhd.c:610
> 
> Fix this by moving the kobject_del() and the corresponding
> kobject_uevent() to the correct place.
> 
> Fixes: 2c2086afc2b8 ("block: Protect less code with sysfs_lock in blk_{un,}register_queue()")
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
>  block/blk-sysfs.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
> index 91d3805a6ec6b..1368dfe3ee500 100644
> --- a/block/blk-sysfs.c
> +++ b/block/blk-sysfs.c
> @@ -951,15 +951,17 @@ void blk_unregister_queue(struct gendisk *disk)
>  	 */
>  	if (queue_is_mq(q))
>  		blk_mq_unregister_dev(disk_to_dev(disk), q);
> -
> -	kobject_uevent(&q->kobj, KOBJ_REMOVE);
> -	kobject_del(&q->kobj);
>  	blk_trace_remove_sysfs(disk_to_dev(disk));
>  
>  	mutex_lock(&q->sysfs_lock);
>  	elv_unregister_queue(q);
>  	disk_unregister_independent_access_ranges(disk);
>  	mutex_unlock(&q->sysfs_lock);
> +
> +	/* Now that all child objects were deleted, the queue can be deleted. */
> +	kobject_uevent(&q->kobj, KOBJ_REMOVE);
> +	kobject_del(&q->kobj);
> +
>  	mutex_unlock(&q->sysfs_dir_lock);
>  
>  	kobject_put(&disk_to_dev(disk)->kobj);
> -- 
> 2.34.1
> 

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>