freebsd-src/sys/cddl
Mark Johnston 84d7fe4a6f kinst: Add per-CPU interrupt trampolines
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:		f0bc4ed144 ("kinst: Initial revision")
Differential Revision:	https://reviews.freebsd.org/D37619
2022-12-08 15:03:51 -05:00
..
boot/zfs stand/libsa: zfs use standard ZFS_EARLY stuff 2022-07-24 16:53:36 -06:00
compat/opensolaris opensolaris: Delete unused sources 2022-09-29 08:34:29 -04:00
contrib/opensolaris powerpc/dtrace: Guard fuword64 usage for powerpc64 only 2022-11-20 19:50:45 -05:00
dev kinst: Add per-CPU interrupt trampolines 2022-12-08 15:03:51 -05:00