summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorriastradh <riastradh@NetBSD.org>2022-03-20 00:19:11 +0000
committerriastradh <riastradh@NetBSD.org>2022-03-20 00:19:11 +0000
commit30afedb017fa787130b2f2cacc2920d02fcd1e9c (patch)
tree78bfb2d2556348238adf5b4549de39cdc26b35f0 /sys/dev
parente1a7e1e1f8ff50be095ecb82bf7d3741c118fd29 (diff)
entropy(9): Avoid reentrance to per-CPU state from sleeping on lock.
Changing the global entropy lock from IPL_VM to IPL_SOFTSERIAL meant it went from being a spin lock, which blocks preemption, to being an adaptive lock, which might sleep -- and allow other threads to run concurrently with the softint, even if those threads have softints blocked with splsoftserial. This manifested as KASSERT(!ec->ec_locked) triggering in entropy_consolidate_xc -- presumably entropy_softintr slept on the global entropy lock while holding the per-CPU state locked with ec->ec_locked, and then entropy_consolidate_xc ran. Instead, to protect access to the per-CPU state without taking a global lock, defer entropy_account_cpu until after ec->ec_locked is cleared. This way, we never sleep while holding ec->ec_locked, nor do we incur any contention on shared memory when entering entropy unless we're about to distribute it. To verify this, sprinkle in assertions that curlwp->l_ncsw hasn't changed by the time we release ec->ec_locked.
Diffstat (limited to 'sys/dev')
0 files changed, 0 insertions, 0 deletions