diff options
| author | Itai Handler <itai.handler@gmail.com> | 2026-10-04 13:16:22 +0300 |
|---|---|---|
| committer | Mikulas Patocka <mpatocka@redhat.com> | 2026-10-09 18:26:50 +0200 |
| commit | 1acc65c30f85d3cce8dbd53ab40d59339a0add85 (patch) | |
| tree | a6c506440ea62039295525e1e5e0f82c2bd1ad61 /tools/lib/python | |
| parent | 17383c7b81b9fa0736bae1db21fed200eff3c6e3 (diff) | |
dm-crypt: allow encryption sector size up to PAGE_SIZE
The "sector_size:<bytes>" option is capped at 4096 bytes. The reason is
stated in commit 8f0009a22517 ("dm crypt: optionally support larger
encryption sector size"): "the maximal IO must fit into the page limit,
so the limit is set to the minimal page size possible (4096 bytes)."
The rule is right; only the way it is resolved is not. The page limit
it refers to is a property of the kernel that is running, but it was
written as the smallest page size of any architecture, so a kernel with
larger pages is held to a limit that belongs to a different one. The
block layer has since stopped doing that for its own block size, in
commit 47dd67532303 ("block/bdev: lift block size restrictions to 64k"),
and dm-crypt is now the stricter of the two.
Apply the same rule to the kernel being built: raise the cap to
min(PAGE_SIZE, BLK_MAX_BLOCK_SIZE).
PAGE_SIZE is still the page limit the original commit meant. A sector is
passed to the crypto API as a single scatterlist entry, bio_iter_iovec()
never returns more than PAGE_SIZE bytes, and crypt_alloc_buffer() may
fall back to order-0 pages for the write bounce buffer.
BLK_MAX_BLOCK_SIZE caps the logical block size that crypt_io_hints()
announces. It is PAGE_SIZE without transparent hugepages, and 64K with
them, which no architecture having a PAGE_SIZE above 64K can enable - so
it does not lower the bound on any configuration today. It is in the
expression so that this target cannot announce a block size
blk_validate_limits() would reject.
A larger unit also turns several crypto requests per page into one.
Whether that is worth anything depends on the driver: for a CPU cipher
the per-request cost is small, and it only pays off where a request
carries a large fixed cost, as when the cipher is offloaded over DMA.
Widen sector_size to unsigned int so that it can hold a sector larger
than 65535. That also makes the option reject an argument of 69632,
which %hu truncates to 4096 and accepts as a 4096-byte sector.
Document that an encryption sector larger than the unit the device
writes atomically can be torn by a power failure, and what each cipher
mode does when that happens.
The maximum stays 4096 wherever PAGE_SIZE is 4096, the default stays 512
bytes, and every table using a size from 512 to 4096 behaves as it did.
The one behavioural change is the truncation above: an argument that
wrapped into range is now rejected rather than silently accepted. A
mapping larger than 4096 bytes can only be activated where PAGE_SIZE
allows, so it is not suitable for portable on-disk formats. Bump the
target version so that userspace can detect the new limit.
Assisted-by: LLM
Signed-off-by: Itai Handler <itai.handler@gmail.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Diffstat (limited to 'tools/lib/python')
0 files changed, 0 insertions, 0 deletions
