Repository navigation
fix(core): capture write-zeroes events so integrity mkfs replays completely - #170
Merged
Merged
Conversation
Since kernel commit bc49af56eea8 ("blktrace: add support for
REQ_OP_WRITE_ZEROES tracing", 6.19) write-zeroes bios carry their own
trace category, BLK_TC_WRITE_ZEROES, above the v1 category ceiling
BLK_TC_END_V1. v1 trace sessions silently drop records whose category
exceeds that ceiling, so write-zeroes events vanish from the v1 stream.
That breaks the integrity mkfs path in cryptpilot-core: mkfs tools zero
large regions (the xfs log, the ext4 inode table) with
fallocate(FALLOC_FL_ZERO_RANGE), which the block layer turns into
write-zeroes bios. On 6.19+ kernels those pages were no longer recorded
as touched, never migrated from the dummy device to the real
LUKS2+dm-integrity volume, and their integrity tags stayed
uninitialized, so mounting failed on AEAD verification.
blktrace-rs 0.2.0 speaks the v2 trace API to fix this. Sessions try
BLKTRACESETUP2, with a 64-bit act_mask including the write-zeroes
category, before falling back to v1 BLKTRACESETUP. Kernels without the
v2 ioctl answer ENOTTY, or EINVAL when the device driver handles unknown
ioctls itself (loop does), and both trigger the fallback; on pre-6.19
kernels write-zeroes bios are traced as plain writes, so the v1 path
keeps identical capture semantics. The record parser dispatches on the
magic version byte and normalizes both layouts into one plain Rust
event: BlkTraceEvent now exposes kind (read, write, write-zeroes,
discard, flush, or other with the record's raw action), sector, bytes, pid, cpu, device, sequence,
time_ns, error and data instead of the raw blk_io_trace record. That is
a breaking API change, hence the minor version bump on a 0.x crate.
Every UAPI type, v1 and v2 alike, is hand-written against fixed
upstream header commits and pinned by compile-time size and offset
assertions, so the crate builds without bindgen, libclang or kernel
headers on any kernel version.
mkfs.rs now treats write-zeroes events as touching pages and migrates
them like writes: the dummy device reads back as zeros, and writing
them to the real volume is exactly what initializes the integrity tags
there. Discard stays excluded - a discard resets the range to the
unwritten state, so there is no content to migrate - and the
"Recording finished" log gained a zeroed-page count.
Assisted-by: Claude:glm-5.3
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
|
@imlk0 ,您好,您的请求已接收,请耐心等待结果。 |
|
@imlk0 ,您好,未检测到有镜像需要构建,如需重新检测请评论 /start 。 |
|
@imlk0 ,您好,您的请求已接收,请耐心等待结果。 |
|
@imlk0 ,您好,未检测到有镜像需要构建,如需重新检测请评论 /start 。 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #170 +/- ##
==========================================
+ Coverage 33.05% 37.23% +4.17%
==========================================
Files 89 93 +4
Lines 7370 8286 +916
Branches 7370 8286 +916
==========================================
+ Hits 2436 3085 +649
- Misses 4672 4900 +228
- Partials 262 301 +39 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since kernel commit bc49af56eea8 ("blktrace: add support for REQ_OP_WRITE_ZEROES tracing", Linux 6.19), write-zeroes bios carry their own trace category, BLK_TC_WRITE_ZEROES, above the v1 category ceiling BLK_TC_END_V1. v1 trace sessions silently drop records whose category exceeds that ceiling, so write-zeroes events vanish from the v1 stream.
That breaks the integrity mkfs path. mkfs tools zero large regions (the xfs log, the ext4 inode table) with fallocate(FALLOC_FL_ZERO_RANGE), which the block layer turns into write-zeroes bios. On 6.19+ kernels those pages stopped being recorded as touched, were never migrated from the dummy device to the real LUKS2+dm-integrity volume, and their integrity tags stayed uninitialized, so mounting failed AEAD verification with EILSEQ. This is what the provider_exec legs started failing with once the runners moved to kernel 7.0.
Two parts:
blktrace-rs 0.2.0 speaks the v2 trace API. Sessions try BLKTRACESETUP2 with a 64-bit act_mask that includes the write-zeroes category, falling back to v1 BLKTRACESETUP on ENOTTY or EINVAL (kernels without the v2 ioctl, or drivers like loop that answer unknown ioctls themselves). On pre-6.19 kernels write-zeroes bios are traced as plain writes, so the fallback keeps identical capture semantics. Both record formats are parsed and normalized into one plain Rust event, and BlkIoKind::Other carries the record's raw action field so callers can classify categories the enum does not name. All UAPI structs, v1 and v2 alike, are now hand-written against pinned kernel header commits with compile-time size and offset assertions: the crate builds without bindgen, libclang or kernel headers. That is a breaking API change, hence the minor bump on a 0.x crate.
mkfs.rs treats write-zeroes events as touching pages and migrates them like writes: the dummy device reads back as zeros, and writing those pages to the real volume is exactly what initializes the integrity tags there. Discard stays excluded (a discard resets the range to the unwritten state, so there is no content to migrate). The "Recording finished" log gained a zeroed-page count.
Verification:
cargo build,cargo clippy --all-targets --all-features -- -D warningsandcargo fmt --checkpass.