Skip to content

fix(core): capture write-zeroes events so integrity mkfs replays completely - #170

Merged
imlk0 merged 1 commit into
masterfrom
blktrace-write-zeroes
Nov 2, 2026
Merged

imlk0 merged 1 commit into
masterfrom
blktrace-write-zeroes

Conversation

@imlk0

@imlk0 imlk0 commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

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:

  • Host kernel 5.10, the v1 fallback path: blktrace-rs unit tests (13) and live loop capture tests pass with default and async features, and the cryptpilot provider_exec suite passes 16/16 serially, so the fallback path has no regression. Workspace cargo build, cargo clippy --all-targets --all-features -- -D warnings and cargo fmt --check pass.
  • Before/after on the 7.0 runners, where the bug bites: on master the provider_exec suite fails 4 of 16 tests per architecture (the integrity makefs cases) with EILSEQ at mount; the one-shot CI workflow this branch carried before (https://github.com/openanolis/cryptpilot/actions/runs/41380904995) ran the same suite serially at kernel 7.0.0-1017-azure on x86_64 and aarch64: 16 passed, 0 failed on both legs. The suite forks each test case and only replays a child's log when that test fails, so a green run carries no mkfs-side detail lines; the before/after result counts are the evidence.
  • That temporary workflow is dropped from the branch; the test.yml pull_request run of this PR (four container legs plus the go tests) is the authoritative full-suite check.

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>
@ostest-bot

Copy link
Copy Markdown

@imlk0 ,您好,您的请求已接收,请耐心等待结果。

@ostest-bot

Copy link
Copy Markdown

@imlk0 ,您好,未检测到有镜像需要构建,如需重新检测请评论 /start 。

@ostest-bot

Copy link
Copy Markdown

@imlk0 ,您好,您的请求已接收,请耐心等待结果。

@ostest-bot

Copy link
Copy Markdown

@imlk0 ,您好,未检测到有镜像需要构建,如需重新检测请评论 /start 。

@codecov

codecov Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.84071% with 48 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.23%. Comparing base (cdb3f4b) to head (304c235).
⚠️ Report is 97 commits behind head on master.

Files with missing lines Patch % Lines
blktrace-rs/src/session.rs 47.27% 26 Missing and 3 partials ⚠️
blktrace-rs/src/event.rs 94.86% 10 Missing and 3 partials ⚠️
blktrace-rs/src/uapi.rs 72.22% 5 Missing ⚠️
cryptpilot-core/src/fs/mkfs.rs 92.30% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@imlk0
imlk0 merged commit 304c235 into master Nov 2, 2026
56 of 57 checks passed
@imlk0
imlk0 deleted the blktrace-write-zeroes branch November 2, 2026 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants