FreeBSD provides a feature called AdaptiveMutexes, which allows
a thread to spin for a while when the mutex is taken instead of
immediately going to sleep. This makes issues when called from
syscall handler if interrupts are masked. If every other core
also attempts to access the same mutex there is a chance that
all of them are spinning on the same lock at the same time.
If interrupts aer disabled, no kernel preemtion can occur and
the system becomes unresponsive.
This patch enables interrupts when syscall is being executed
end masks them as soon as it is finished.
Procedure to trigger the issue fixed by this patch:
- run (mp_ncpus + 1) threads of "cat /dev/urandom > /dev/null"
Issue was seen only on the real hardware, qemu and simulators
are working fine.