Repository navigation
Free tx frag arrays with kvfree - #142
Open
Stuartwastaken wants to merge 1 commit into
Open
Stuartwastaken wants to merge 1 commit into
Stuartwastaken wants to merge 1 commit into
Conversation
* homa_tx_pool_alloc allocates the frag array with kvmalloc_array, but it and homa_rpc_reap freed it with kfree. Since 6.19, kvmalloc falls back to vmalloc even for GFP_ATOMIC when kmalloc fails, which can happen once the array is bigger than a page (high-order pages not available and a message near 1 MB). * The unit-test kvmalloc mock now marks its blocks so that kfree on them fails.
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.
homa_tx_pool_alloc allocates its frag array with kvmalloc_array(..., GFP_ATOMIC), but the array is freed with kfree in three places: when it is regrown and on the error path in homa_tx_pool_alloc, and in homa_rpc_reap. Before 6.19, kvmalloc never used vmalloc for non-blocking flags, so this was harmless. Since 6.19, __kvmalloc_node_noprof falls back to vmalloc for GFP_ATOMIC too when kmalloc fails (it only drops VM_ALLOW_HUGE_VMAP), and kfree on vmalloc memory is a bad free. The array only gets bigger than a page when high-order pages aren't available and the message is close to 1 MB, so it takes memory pressure, but any sender can get there. 7.3, the planned LTS base for main, has the vmalloc fallback.
This switches the three frees to kvfree. kvfree is safe in all of those contexts: homa_tx_pool_alloc runs with BHs disabled, where vfree defers, and homa_rpc_reap has dropped the socket lock before freeing. To catch this in the unit tests, the kvmalloc mock now tags its blocks and kfree fails on a tagged block. Without the fix, 23 existing tests fail that way, covering all three frees. With it, all unit tests and the smoke tests pass. homa-gcp's 6.17.8 kernel predates the fallback, so this hasn't been reproduced on a running kernel.