Page MenuHomeFreeBSD

kinst: Initial revision
ClosedPublic

Authored by markj on Oct 1 2022, 3:47 PM.

Details

Summary

This is a new DTrace provider which allows arbitrary kernel instructions
to be traced. Currently it is implemented only for amd64.

kinst probes are created on demand by libdtrace, and there is a probe
for each kernel instruction. Probes are named
kinst:<module>:<function>:<offset>, where "offset" is the offset of the
target instruction relative to the beginning of the function. Omitting
"offset" causes all instructions in the function to be traced.

kinst works similarly to FBT in that it places a breakpoint on the
target instruction and hooks into the breakpoint handler. Because kinst
has to be able to trace arbitrary instructions, it does not emulate most
of them in software but rather causes the traced thread to execute a
copy of the instruction before returning to the original code.

The provider is quite low-level and as-is will be useful mostly only to
kernel developers. However, it provides a great deal of visibility into
kernel code execution and could be used as a building block for
higher-level tooling which can in some sense translate between C sources
and generated machine code.

kinst is experimental and should not be used on production systems for
now.

In collaboration with: markj
Sponsored by: Google, Inc. (GSoC 2022)
MFC after: 3 months

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

markj requested review of this revision.Oct 1 2022, 3:47 PM
sys/cddl/dev/kinst/amd64/kinst_isa.c
545

Doesn't dtrace_disx86() also increase the pointer?

sys/cddl/dev/kinst/kinst.c
212

Again, should we use KINST_LOG()?

sys/cddl/dev/kinst/trampoline.c
139

Should we use KINST_LOG() instead?

markj marked an inline comment as done.

Address review comments, make some minor fixups.

Fix an incomplete comment.

This revision is now accepted and ready to land.Oct 4 2022, 5:32 PM
This revision was automatically updated to reflect the committed changes.