Skip to content

Commit e35fde4

Browse files
ebiggersaxboe
authored andcommitted
blk-crypto: show supported key types in sysfs
Add sysfs files that indicate which type(s) of keys are supported by the inline encryption hardware associated with a particular request queue: /sys/block/$disk/queue/crypto/hw_wrapped_keys /sys/block/$disk/queue/crypto/raw_keys Userspace can use the presence or absence of these files to decide what encyption settings to use. Don't use a single key_type file, as devices might support both key types at the same time. Signed-off-by: Eric Biggers <[email protected]> Tested-by: Bartosz Golaszewski <[email protected]> # sm8650 Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent ebc4176 commit e35fde4

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

Documentation/ABI/stable/sysfs-block

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,17 @@ Description:
229229
encryption, refer to Documentation/block/inline-encryption.rst.
230230

231231

232+
What: /sys/block/<disk>/queue/crypto/hw_wrapped_keys
233+
Date: February 2025
234+
235+
Description:
236+
[RO] The presence of this file indicates that the device
237+
supports hardware-wrapped inline encryption keys, i.e. key blobs
238+
that can only be unwrapped and used by dedicated hardware. For
239+
more information about hardware-wrapped inline encryption keys,
240+
see Documentation/block/inline-encryption.rst.
241+
242+
232243
What: /sys/block/<disk>/queue/crypto/max_dun_bits
233244
Date: February 2022
234245
@@ -267,6 +278,15 @@ Description:
267278
use with inline encryption.
268279

269280

281+
What: /sys/block/<disk>/queue/crypto/raw_keys
282+
Date: February 2025
283+
284+
Description:
285+
[RO] The presence of this file indicates that the device
286+
supports raw inline encryption keys, i.e. keys that are managed
287+
in raw, plaintext form in software.
288+
289+
270290
What: /sys/block/<disk>/queue/dax
271291
Date: June 2016
272292

block/blk-crypto-sysfs.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ static struct blk_crypto_attr *attr_to_crypto_attr(struct attribute *attr)
3131
return container_of(attr, struct blk_crypto_attr, attr);
3232
}
3333

34+
static ssize_t hw_wrapped_keys_show(struct blk_crypto_profile *profile,
35+
struct blk_crypto_attr *attr, char *page)
36+
{
37+
/* Always show supported, since the file doesn't exist otherwise. */
38+
return sysfs_emit(page, "supported\n");
39+
}
40+
3441
static ssize_t max_dun_bits_show(struct blk_crypto_profile *profile,
3542
struct blk_crypto_attr *attr, char *page)
3643
{
@@ -43,20 +50,48 @@ static ssize_t num_keyslots_show(struct blk_crypto_profile *profile,
4350
return sysfs_emit(page, "%u\n", profile->num_slots);
4451
}
4552

53+
static ssize_t raw_keys_show(struct blk_crypto_profile *profile,
54+
struct blk_crypto_attr *attr, char *page)
55+
{
56+
/* Always show supported, since the file doesn't exist otherwise. */
57+
return sysfs_emit(page, "supported\n");
58+
}
59+
4660
#define BLK_CRYPTO_RO_ATTR(_name) \
4761
static struct blk_crypto_attr _name##_attr = __ATTR_RO(_name)
4862

63+
BLK_CRYPTO_RO_ATTR(hw_wrapped_keys);
4964
BLK_CRYPTO_RO_ATTR(max_dun_bits);
5065
BLK_CRYPTO_RO_ATTR(num_keyslots);
66+
BLK_CRYPTO_RO_ATTR(raw_keys);
67+
68+
static umode_t blk_crypto_is_visible(struct kobject *kobj,
69+
struct attribute *attr, int n)
70+
{
71+
struct blk_crypto_profile *profile = kobj_to_crypto_profile(kobj);
72+
struct blk_crypto_attr *a = attr_to_crypto_attr(attr);
73+
74+
if (a == &hw_wrapped_keys_attr &&
75+
!(profile->key_types_supported & BLK_CRYPTO_KEY_TYPE_HW_WRAPPED))
76+
return 0;
77+
if (a == &raw_keys_attr &&
78+
!(profile->key_types_supported & BLK_CRYPTO_KEY_TYPE_RAW))
79+
return 0;
80+
81+
return 0444;
82+
}
5183

5284
static struct attribute *blk_crypto_attrs[] = {
85+
&hw_wrapped_keys_attr.attr,
5386
&max_dun_bits_attr.attr,
5487
&num_keyslots_attr.attr,
88+
&raw_keys_attr.attr,
5589
NULL,
5690
};
5791

5892
static const struct attribute_group blk_crypto_attr_group = {
5993
.attrs = blk_crypto_attrs,
94+
.is_visible = blk_crypto_is_visible,
6095
};
6196

6297
/*

0 commit comments

Comments
 (0)