Skip to content

Protect homa_tx_pool_core with a local lock - #141

Open
Stuartwastaken wants to merge 1 commit into
PlatformLab:mainfrom
Stuartwastaken:fix/tx-pool-local-lock
Open

Stuartwastaken wants to merge 1 commit into
PlatformLab:mainfrom
Stuartwastaken:fix/tx-pool-local-lock

Conversation

@Stuartwastaken

Copy link
Copy Markdown
Contributor

On PREEMPT_RT, local_bh_disable() no longer keeps other tasks off the core: unless CONFIG_PREEMPT_RT_NEEDS_BH_LOCK is set, it only disables migration (kernel/softirq.c). So the per-core page state that homa_tx_pool_alloc uses isn't protected there, and two sendmsg calls on one core can interleave in __homa_tx_pool_alloc_frag. Both can read the same tx_core->allocated and get overlapping fragments, so one message goes out with the other's data, or both can put the same cached page when replacing it.

This adds a local_lock_t to homa_tx_pool_core and takes it with local_lock_nested_bh inside the BH-disabled section, the same pattern as napi_alloc_cache in net/core/skbuff.c. Outside RT it compiles to a lockdep annotation. The new unit-test mocks check that the lock is only taken with BHs disabled and is released by the end of each test, so the existing homa_tx_pool tests cover both exits of homa_tx_pool_alloc. All unit tests and the smoke tests pass. I don't have an RT kernel, so this hasn't been run under PREEMPT_RT.

* homa_tx_pool_alloc relied on local_bh_disable to keep other tasks
  away from the per-core page. On PREEMPT_RT that only disables
  migration, so two sendmsg calls on one core could hand out the same
  bytes or put the cached page twice.
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