84d7fe4a6f
In the common case, kinst emulates a traced instruction by copying it to a trampoline, where it is followed by a jump back to the original code, and pointing the interrupted thread's %rip at the trampoline. In particular, the trampoline is executed with the same CPU context as the original instruction, so if interrupts are enabled at the point where the probe fires, they will be enabled when the trampoline is subsequently executed. It can happen that an interrupt is raised while a thread is executing a kinst trampoline. In that case, it is possible that the interrupt handler will trigger a kinst probe, so we must ensure that the thread does not recurse and overwrite its trampoline before it is finished executing the original contents, otherwise an attempt to trace code called from interrupt handlers can crash the kernel. To that end, add a per-CPU trampoline, used when the probe fired with interrupts disabled. Note that this is not quite complete since it does not handle the possibility of kinst probes firing while executing an NMI handler. Also ensure that we do not trace instructions which set IF, since in that case it is not clear which trampoline (the per-thread trampoline or the per-CPU trampoline) we should use, and since such instructions are rare. Reported and tested by: Domagoj Stolfa Reviewed by: christos Fixes: f0bc4ed144fc ("kinst: Initial revision") Differential Revision: https://reviews.freebsd.org/D37619