fix(bpf): widen nr_bytes to __u64 to prevent overflow on large I/O#197
Open
Kokila-chandrakar wants to merge 8 commits into
Open
fix(bpf): widen nr_bytes to __u64 to prevent overflow on large I/O#197Kokila-chandrakar wants to merge 8 commits into
Kokila-chandrakar wants to merge 8 commits into
Conversation
ctx->nr_sector * 512 was computed in __u32, wrapping for any merged or discard request larger than ~8 MiB (nr_sector > 8_388_607). Cast the operand to __u64 so the multiply is done in 64-bit arithmetic. Widen the nr_bytes field in struct disk_event (kerno.h) from __u32 to __u64 and re-pad _pad from [3]byte to [7]byte to keep the struct size a multiple of 8. Mirror the new layout in the Go DiskEvent struct and update the bpf2go-generated field order accordingly. Add TestDecodeDiskEventLargeIO to catch regressions: a 16 MiB discard (nr_sector=32768) previously decoded to NrBytes=0. Fixes: disk_io.c:55 __u32 overflow on large merged/discard requests
|
🚀 First PR — welcome aboard! A few things to expect:
If you get stuck, reply here or jump to Discussions. We want this PR to land. |
Member
|
lint failing |
btwshivam
requested changes
Jun 7, 2026
btwshivam
left a comment
Member
There was a problem hiding this comment.
the u64 widening and the go-side struct mirror are correct (offsets line up at 64 bytes), but events.go isn't gofmt-clean so lint is red, and the fix drops a load-bearing verifier comment in disk_io.c. fix those two and it's an approve.
Contributor
Author
|
Contributor
Author
|
Hi @btwshivam , This PR has been waiting for review for a few days now. All conflicts have been resolved and the changes are ready for maintainer review. I'd be grateful if you could take a look when available. Thanks! |
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.
Problem
disk_io.c:55computesnr_bytes = ctx->nr_sector * 512in__u32arithmetic. Any merged or discard request larger than ~8 MiB (nr_sector > 8_388_607) silently wraps, producing a garbage byte count in the ring buffer event and corrupting the throughput totals accumulated in the collector.Regular single requests are usually well under this limit, but merged block requests and discard operations routinely exceed it.
Fix
c/disk_io.c— castctx->nr_sectorto__u64before multiplying by 512 so the product is computed in 64-bit arithmetic.c/headers/kerno.h— widenstruct disk_event.nr_bytesfrom__u32to__u64; reorderpidbeforenr_bytesfor natural alignment; expand_padfrom[3]to[7]bytes to keep the struct size a multiple of 8 (total: 32 → 40 bytes).internal/bpf/events.go— mirror the new C layout exactly inDiskEventsobinary.Readdeserializes correctly.internal/bpf/decode_test.go— addTestDecodeDiskEventLargeIO: encodes a 16 MiB discard event (nr_sector=32768, expectedNrBytes=16_777_216) and asserts it is not truncated. This test would have failed on the olduint32field.Struct layout change
dev__u32__u32nr_bytes__u32movedpid__u32__u32nr_bytes__u64op__u8__u8_pad__u8[3]__u8[7]The Go
DiskEventstruct is updated to match field-for-field.Testing
close #124