fix(tx_pool): compute tx page-pool floor in 64-bit to avoid overflow - #95
Open
randomizedcoder wants to merge 1 commit into
Open
randomizedcoder wants to merge 1 commit into
randomizedcoder wants to merge 1 commit into
Conversation
homa_tx_pool_gc() turns the tx_page_pool_min_kb floor into a page count with `homa->tx_page_pool_min_kb * 1000`. tx_page_pool_min_kb is a plain int, so for large floors (a multi-GB tx reserve is a legitimate sysctl setting) the multiply overflows 32-bit int. The resulting min_pages is garbage -- typically negative -- which makes `release = max_low_mark - min_pages` huge, so gc reclaims pages that the floor was supposed to keep. Promote the multiply to u64 (and cast the shifted result back to int). Adds a table-driven regression test, homa_tx_pool_gc__min_kb_floor_no_overflow, whose corner row sets a floor whose `* 1000` overflows a 32-bit int: before the fix gc frees the whole pool (avail 10 -> 0); after the fix the floor is honored and the pool is left intact. Existing tx_pool suite stays green (30/30). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Bug: 32-bit overflow computing the tx page-pool floor
homa_tx_pool_gc()converts thetx_page_pool_min_kbfloor (in KB) into a page count:tx_page_pool_min_kbis a plainint.int * 1000is evaluated in 32-bit, so any floor above ~2.1 GB (min_kb > 2,147,483) overflows — a multi-GB tx reserve is a perfectly legitimate sysctl setting. The overflow makesmin_pagesgarbage, typically negative, and the routine then computes:so gc reclaims exactly the pages the floor was meant to protect.
Fix
Do the arithmetic in 64-bit, then narrow the (now-small) page count back to
int.Verification (TDD, red → green)
Table-driven regression test
homa_tx_pool_gc__min_kb_floor_no_overflow, written first:Built and run against the
test/kselftest unit harness (ASan on).Uses the table-driven test style proposed in the first PR of this series.