Skip to content

Free tx frag arrays with kvfree - #142

Open
Stuartwastaken wants to merge 1 commit into
PlatformLab:mainfrom
Stuartwastaken:fix/tx-frags-kvfree
Open

Stuartwastaken wants to merge 1 commit into
PlatformLab:mainfrom
Stuartwastaken:fix/tx-frags-kvfree

Conversation

@Stuartwastaken

@Stuartwastaken Stuartwastaken commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

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.

* 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.
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.

1 participant