From: Linlin Zhang <linlin.zhang@oss.qualcomm.com>
To: Milan Broz <gmazyland@gmail.com>,
linux-block@vger.kernel.org, ebiggers@kernel.org
Cc: linux-kernel@vger.kernel.org, adrianvovk@gmail.com,
dm-devel@lists.linux.dev, quic_mdalam@quicinc.com,
israelr@nvidia.com, mpatocka@redhat.com
Subject: Re: [PATCH v1 2/3] dm-inlinecrypt: add target for inline block device encryption
Date: Wed, 25 Mar 2026 19:27:49 +0800 [thread overview]
Message-ID: <8bd50656-6b6d-41d3-8093-c97dd1bb3e91@oss.qualcomm.com> (raw)
In-Reply-To: <682506ea-c9c2-458b-8123-8d78fc53cc7f@gmail.com>
On 3/4/2026 9:11 PM, Milan Broz wrote:
> Hi,
>
> just few comments below, but I am not DM maintainer so feel free to ignore it :)
>
> On 3/4/26 1:17 PM, Linlin Zhang wrote:
>> From: Eric Biggers <ebiggers@google.com>
>>
>> Add a new device-mapper target "dm-inlinecrypt" that is similar to
>> dm-crypt but uses the blk-crypto API instead of the regular crypto API.
>> This allows it to take advantage of inline encryption hardware such as
>> that commonly built into UFS host controllers.
>>
>> The table syntax matches dm-crypt's, but for now only a stripped-down
>> set of parameters is supported. For example, for now AES-256-XTS is the
>> only supported cipher.
>>
>> dm-inlinecrypt is based on Android's dm-default-key with the
>> controversial passthrough support removed. Note that due to the removal
>> of passthrough support, use of dm-inlinecrypt in combination with
>> fscrypt causes double encryption of file contents (similar to dm-crypt +
>> fscrypt), with the fscrypt layer not being able to use the inline
>> encryption hardware. This makes dm-inlinecrypt unusable on systems such
>> as Android that use fscrypt and where a more optimized approach is
>> needed. It is however suitable as a replacement for dm-crypt.
>>
>> Signed-off-by: Eric Biggers <ebiggers@google.com>
>> Signed-off-by: Linlin Zhang <linlin.zhang@oss.qualcomm.com>
>> ---
>> drivers/md/Kconfig | 10 +
>> drivers/md/Makefile | 1 +
>> drivers/md/dm-inlinecrypt.c | 416 ++++++++++++++++++++++++++++++++++++
>
> I think it should also add doc in
> Documentation/admin-guide/device-mapper/dm-inlinecrypt.rst
Thanks for your review.
You're right. I'll add it in next patch.
> ...
>
>> +#define DM_MSG_PREFIX "inlinecrypt"
>> +
>> +static const struct dm_inlinecrypt_cipher {
>> + const char *name;
>> + enum blk_crypto_mode_num mode_num;
>> + int key_size;
>> +} dm_inlinecrypt_ciphers[] = {
>> + {
>> + .name = "aes-xts-plain64",
>> + .mode_num = BLK_ENCRYPTION_MODE_AES_256_XTS,
>> + .key_size = 64,
>
> Hm. I can understand some translation table for this stupid
> dm-crypt notation to inline enum, but why you need key size here?
>
> Shouldn't there be some helper for inline crypt returning
> keysize based on BLK_ENCRYPTION_MODE_AES_256_XTS?
Similar to dm-default-key in Android (https://android.googlesource.com/kernel/common/+/android-mainline/drivers/md/dm-default-key.c),
key_size 64 here is always corresponding to a raw key. For a HW wrapped key, the key
size differs from different manufacturers. Linux kernel only constraints that the max
key size of HW wrapped key isn't larger than BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE(128).
So we get the actual key size based on the input key parameter received in ctr functions.
>
> I guess you have fixed cipher list already, but what about IV?
> Is it always little-endian, or someone already reinvented plain64be (big-endian)?
>
> ...> + while (opt_params--) {
>
> ...> +/*
Same to dm-crypt, 'plain64' in "aes-xts-plain64" of cipher name is the IV mode. It uses
the 64‑bit little‑endian sector number as the IV.
>> + * Construct an inlinecrypt mapping:
>> + * <cipher> <key> <iv_offset> <dev_path> <start>
>
> As above, it supports opt params, it should mention it here (or in doc).
ACK, refer to dm-crypt, I'll add it in doc.
>
>
> ...
>> + /* <key> */
>> + if (strlen(argv[1]) != 2 * cipher->key_size) {
>> + ti->error = "Incorrect key size for cipher";
>> + err = -EINVAL;
>> + goto bad;
>> + }
>> + if (hex2bin(raw_key, argv[1], cipher->key_size) != 0) {
>> + ti->error = "Malformed key string";
>> + err = -EINVAL;
>> + goto bad;
>> + }
>
>
> Any reason it does not support keyring keys from the beginning?
No special reason. The implementation of `dm-inlinecrypt` was modeled after
'dm-default-key', which, in Android, does not support keyring keys.
I'll have a insight about keyring and dm-crypt, inspect how to add keyring support
in dm-inline-crypt.
>
> ...
>> +static int inlinecrypt_map(struct dm_target *ti, struct bio *bio)
>
>> + /* Map the bio's sector to the underlying device. (512-byte sectors) */
>> + sector_in_target = dm_target_offset(ti, bio->bi_iter.bi_sector);
>> + bio->bi_iter.bi_sector = ctx->start + sector_in_target;
>> + /*
>> + * If the bio doesn't have any data (e.g. if it's a DISCARD request),
>> + * there's nothing more to do.
>> + */
>
> dmcrypt uses bio_set_dev() for REQ_PREFLUSH or REQ_OP_DISCARD, why this differs?
bio_has_data() is a payload‑based check that decides whether an encryption context
is needed, while REQ_PREFLUSH and REQ_OP_DISCARD are semantic checks that ensure
flush and discard requests bypass the dm‑crypt processing pipeline to maintain
correct I/O ordering. As a result, the two mechanisms address different concerns
and are not interchangeable.
In addition, bio_has_data is called in the beginning of inlinecrypt_map, rather
in the conditional branch like dm-crypt. But they have same effect.
>
>> +
>> + switch (type) {
>> + case STATUSTYPE_INFO:
>> + case STATUSTYPE_IMA:
>> + result[0] = '\0';
>
> This should really emit audit information similar to dm-crypt.
>
>> + break;
>> +
>> + case STATUSTYPE_TABLE:
>> + /*
>> + * Warning: like dm-crypt, dm-inlinecrypt includes the key in
>> + * the returned table. Userspace is responsible for redacting
>> + * the key when needed.
>
> Again, why not support keyring format? LUKS2 uses it by default for dm-crypt table.
ACK. Need support keyring format.
I see both hex key and keyring-based keys are supported in dm-crypt. can both of them
be supported in dm-inlinecrypt?
>
> Milan
>
next prev parent reply other threads:[~2026-03-25 11:27 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-04 12:17 [PATCH v1 0/3] " Linlin Zhang
2026-03-04 12:17 ` [PATCH v1 1/3] block: export blk-crypto symbols required by dm-inlinecrypt Linlin Zhang
2026-03-09 14:01 ` Mikulas Patocka
2026-03-09 15:05 ` Jens Axboe
2026-03-09 16:12 ` Mikulas Patocka
2026-03-04 12:17 ` [PATCH v1 2/3] dm-inlinecrypt: add target for inline block device encryption Linlin Zhang
2026-03-04 13:11 ` Milan Broz
2026-03-25 11:27 ` Linlin Zhang [this message]
2026-03-12 7:01 ` Eric Biggers
2026-03-13 13:25 ` Mikulas Patocka
2026-03-13 15:27 ` Milan Broz
2026-03-25 11:57 ` Linlin Zhang
2026-03-25 15:07 ` Milan Broz
2026-03-25 6:55 ` Linlin Zhang
2026-03-04 12:17 ` [PATCH v1 3/3] dm-inlinecrypt: Expose inline crypto caps to the device Linlin Zhang
2026-03-12 6:35 ` Eric Biggers
2026-03-13 13:19 ` Mikulas Patocka
2026-03-25 6:38 ` Linlin Zhang
2026-03-04 13:06 ` [PATCH v1 0/3] dm-inlinecrypt: add target for inline block device encryption Christoph Hellwig
2026-03-04 18:09 ` Adrian Vovk
[not found] ` <CAAdYy_mSB4U39Onwa=V2e2XB0sJXV6tCGkzwV2-z7ZtMcm+8zg@mail.gmail.com>
2026-03-05 14:38 ` Christoph Hellwig
2026-03-25 7:04 ` Linlin Zhang
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=8bd50656-6b6d-41d3-8093-c97dd1bb3e91@oss.qualcomm.com \
--to=linlin.zhang@oss.qualcomm.com \
--cc=adrianvovk@gmail.com \
--cc=dm-devel@lists.linux.dev \
--cc=ebiggers@kernel.org \
--cc=gmazyland@gmail.com \
--cc=israelr@nvidia.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mpatocka@redhat.com \
--cc=quic_mdalam@quicinc.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®