aboutsummaryrefslogtreecommitdiff
path: root/sys/cddl/dev
Commit message (Collapse)AuthorAgeFilesLines
...
* dtrace: Fix up %rip for invop probes on x86Mark Johnston2022-10-312-1/+15
| | | | | | | | | | | | When a breakpoint exception is raised, the saved value of %rip points to the instruction following the breakpoint. However, when fetching the value of %rip using regs[], it's more natural to provide the address of the breakpoint itself, so modify the kinst and fbt providers accordingly. Reported by: khng Reviewed by: christos, khng MFC after: 2 months Differential Revision: https://reviews.freebsd.org/D37218
* kinst: Clarify a comment in the trampoline allocatorMark Johnston2022-10-141-4/+5
| | | | Fixes: f0bc4ed144fc ("kinst: Initial revision")
* kinst: Remove an unused constantMark Johnston2022-10-141-5/+0
| | | | | | This was left over after a rework of the trampoline allocator. Fixes: f0bc4ed144fc ("kinst: Initial revision")
* dtrace: Drop illumos ifdefs for CPU register definitionsMark Johnston2022-10-122-60/+0
| | | | | | | | These are fixed, so having upstream's version is not especially useful, and the duplicated definitions make for confusing reading. No functional change intended. MFC after: 1 week
* kinst: Initial revisionChristos Margiolis2022-10-116-0/+1204
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 kernel 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. In particular, the "regs" variable recently added to D allows the CPU's register file to be accessed from kinst probes. 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 Differential Revision: https://reviews.freebsd.org/D36851
* dtrace: Add a "regs" variableMark Johnston2022-10-047-36/+56
| | | | | | | | | | | | | | | | | | | | | | | | This allows invop-based providers (i.e., fbt and kinst) to expose the register file of the CPU at the point where the probe fired. It does not work for SDT providers because their probes are implemented as plain function calls and so don't save registers. It's not clear what semantics "regs" should have for them anyway. This is akin to "uregs", which nominally provides access to the userspace registers. In fact, DIF already had a DIF_VAR_REGS variable defined, it was simply unimplemented. Usage example: print the contents of %rdi upon each call to amd64_syscall(): fbt::amd64_syscall:entry {printf("%x", regs[R_RDI]);} Note that the R_* constants are defined in /usr/lib/dtrace/regs_x86.d. Currently there are no similar definitions for non-x86 platforms. Reviewed by: christos MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D36799
* Adjust function definition in riscv's dtrace_subr.c to avoid clang 15 warningDimitry Andric2022-08-141-1/+1
| | | | | | | | | | | | | | | With clang 15, the following -Werror warning is produced: sys/cddl/dev/dtrace/riscv/dtrace_subr.c:165:17: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes] dtrace_gethrtime() ^ void This is because dtrace_gethrtime() is declared with a (void) argument list, but defined with an empty argument list. Make the definition match the declaration. MFC after: 3 days
* Adjust function definition in powerpc's dtrace_subr.c to avoid clang 15 warningDimitry Andric2022-08-141-1/+1
| | | | | | | | | | | | | | | With clang 15, the following -Werror warning is produced: sys/cddl/dev/dtrace/powerpc/dtrace_subr.c:237:17: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes] dtrace_gethrtime() ^ void This is because dtrace_gethrtime() is declared with a (void) argument list, but defined with an empty argument list. Make the definition match the declaration. MFC after: 3 days
* Adjust function definition in arm's dtrace_subr.c to avoid clang 15 warningDimitry Andric2022-08-141-1/+1
| | | | | | | | | | | | | | | With clang 15, the following -Werror warning is produced: sys/cddl/dev/dtrace/arm/dtrace_subr.c:174:17: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes] dtrace_gethrtime() ^ void This is because dtrace_gethrtime() is declared with a (void) argument list, but defined with an empty argument list. Make the definition match the declaration. MFC after: 3 days
* dtrace/amd64: Implement emulation of call instructionsMark Johnston2022-08-092-7/+55
| | | | | | | | | | | | | | | | | | | Here, the provider is responsible for updating the trapframe to redirect control flow and for computing the return address. Once software-saved registers are restored, the emulation shifts the remaining context down on the stack to make space for the return address, then copies the address provided by the invop handler. dtrace_invop() is modified to allocate temporary storage space on the stack for use by the provider to return the return address. This is to support a new provider for amd64 which can instrument arbitrary instructions, not just function entry and exit instructions as FBT does. In collaboration with: christos Sponsored by: Google, Inc. (GSoC 2022) Sponsored by: The FreeBSD Foundation MFC after: 2 weeks
* fbt/x86: Extract arg1 for return probes from the trapframeMark Johnston2022-08-091-2/+4
| | | | | | | | | dtrace invop handlers have access to the whole trapframe, just use that to extract %rax/%eax for return probes instead of relying on an additional parameter to the handler. No functional change intended. MFC after: 2 weeks Sponsored by: The FreeBSD Foundation
* Adjust fbt_unload() definition to avoid clang 15 warningDimitry Andric2022-07-211-1/+1
| | | | | | | | | | | | | | | With clang 15, the following -Werror warning is produced: sys/cddl/dev/fbt/fbt.c:1273:11: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes] fbt_unload() ^ void This is because fbt_unload() is declared with a (void) argument list, but defined with an empty argument list. Make the definition match the declaration. MFC after: 3 days
* Adjust prototype_unload() definition to avoid clang 15 warningDimitry Andric2022-07-201-1/+1
| | | | | | | | | | | | | | | With clang 15, the following -Werror warnings is produced: sys/cddl/dev/prototype.c:99:17: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes] prototype_unload() ^ void This is because prototype_unload() is declared with a (void) argument list, but defined with an empty argument list. Make the definition match the declaration. MFC after: 3 days
* Adjust dtrace_unload() definition to avoid clang 15 warningDimitry Andric2022-07-191-1/+1
| | | | | | | | | | | | | | | | With clang 15, the following -Werror warnings is produced: In file included from sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c:18440: sys/cddl/dev/dtrace/dtrace_unload.c:26:14: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes] dtrace_unload() ^ void This is because dtrace_unload() is declared with a (void) argument list, but defined with an empty argument list. Make the definition match the declaration. MFC after: 3 days
* Adjust profile_unload() definition to avoid clang 15 warningDimitry Andric2022-07-191-1/+1
| | | | | | | | | | | | | | | With clang 15, the following -Werror warnings is produced: sys/cddl/dev/profile/profile.c:640:15: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes] profile_unload() ^ void This is because profile_unload() is declared with a (void) argument list, but defined with an empty argument list. Make the definition match the declaration. MFC after: 3 days
* Adjust dtmalloc_unload() definition to avoid clang 15 warningDimitry Andric2022-07-191-1/+1
| | | | | | | | | | | | | | | With clang 15, the following -Werror warnings is produced: sys/cddl/dev/dtmalloc/dtmalloc.c:177:16: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes] dtmalloc_unload() ^ void This is because dtmalloc_unload() is declared with a (void) argument list, but defined with an empty argument list. Make the definition match the declaration. MFC after: 3 days
* dtrace: add warning for /dev/dtrace/prototypeChristos Margiolis2022-06-011-1/+4
| | | | | | | Let the programmer know that creating a device is not necessary. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D35381
* dtrace: remove /dev/dtrace/fbtChristos Margiolis2022-06-011-20/+0
| | | | | | | It is unused. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D35377
* dtrace: remove /dev/dtrace/profileChristos Margiolis2022-06-011-21/+0
| | | | | | | It is unused. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D35380
* dtrace: remove /dev/dtrace/dtmallocChristos Margiolis2022-06-011-20/+0
| | | | | | | It is unused. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D35379
* fbt: Add support for CTFv3 containersMark Johnston2022-03-071-78/+231
| | | | | | | | | | | | | | | The general aim in this and subsequent patches is to minimize the amount of code that directly references CTF types such as ctf_type_t, ctf_array_t, etc. To that end, introduce some routines similar to the existing fbt_get_ctt_size() (which exists to deal with differences between v1 and v2) and change ctf_lookup_by_id() to return a void pointer. Support for v2 containers is preserved. MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D34361
* fbt: Remove handling for CTFv1Mark Johnston2022-02-231-2/+1
| | | | | MFC after: 1 week Sponsored by: The FreeBSD Foundation
* Teach DTrace about BTI on arm64Andrew Turner2022-01-191-0/+8
| | | | | | | | | | | | | The Branch Target Identification (BTI) Armv8-A extension adds new instructions that can be placed where we may indirrectly branch to, e.g. at the start of a function called via a function pointer. We can't emulate these in DTrace as the kernel will have raised a different exception before the DTrace handler has run. Skip over the BTI instruction if it's used as the first instruction in a function. Sponsored by: The FreeBSD Foundation
* dtrace: add a knob to control maximum size of principal buffersAndriy Gapon2022-01-111-0/+4
| | | | | | | | | | | | | | | | | | We had a hardcoded limit of 1/128-th of physical memory that was further subdivided between all CPUs as principal buffers are allocated on the per-CPU basis. Actually, the buffers could use up 1/64-th of the memmory because with the default switch policy there are two buffers per CPU. This commit allows to change that limit. Note that the discussed limit is per dtrace command invocation. The idea is to limit the size of a single malloc(9) call, not the total memory size used by DTrace buffers. Reviewed by: markj MFC after: 3 weeks Differential Revision: https://reviews.freebsd.org/D33648
* Remove mips dtrace.Warner Losh2022-01-076-1503/+0
| | | | | | Remove mips dtrace code. It's no longer needed. Sponsored by: Netflix
* dtrace: Use C99 fixed-width integer types.John Baldwin2021-12-281-12/+12
| | | | | | | No functional change. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D33631
* Fix dtrace fbt return probes on arm64Andrew Turner2021-12-142-6/+12
| | | | | | | | | | As with arm and riscv fix return fbt probes on arm64. arg0 should be the offset within the function of the return instruction and arg1 should be the return value. Reviewed by: kp, markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D33440
* Allow ddb and dtrace use the DMAP region on arm64Andrew Turner2021-10-011-1/+5
| | | | | | | | | | | | When writing to memory on arm64 we may be trying to be accessing a read-only page. In this case try to access via the DMAP region to get a writable location. While here simplify writing data in DDB and stop trashing the size as it is passed into the cache handling functions. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D32053
* kern: drop remaining references to removed makesyscalls.shKyle Evans2021-09-101-2/+2
| | | | | | | This was accidentally omitted from the recent removal of makeyscalls.sh. Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D30250
* Create sys/reg.h for the common code previously in machine/reg.hAndrew Turner2021-08-306-6/+0
| | | | | | | | | | Move the common kernel function signatures from machine/reg.h to a new sys/reg.h. This is in preperation for adding PT_GETREGSET to ptrace(2). Reviewed by: imp, markj Sponsored by: DARPA, AFRL (original work) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D19830
* sys/cddl: remove extraneous semicolonsEd Maste2021-08-161-2/+2
| | | | | | | Fixes: 5a1b490d502e ("FreeBSD changes to vendor source.") Fixes: 91eaf3e1831d ("Custom DTrace kernel module...") MFC after: 1 week Sponsored by: The FreeBSD Foundation
* dtrace: use %zu format specifier for data of size_t typeKonstantin Belousov2021-08-081-1/+1
| | | | Sponsored by: The FreeBSD Foundation
* fbt: Remove some handling for multiple CTF containersMark Johnston2021-04-021-35/+9
| | | | | | | | | | | | | This was ported from illumos but not completely done. Currently we do not perform type deduplication between KLDs and the kernel, i.e., kernel modules have a complete type graph. So, remove it for now since it's not functional and complicates the task of modifying various CTF type definitions, and we are hitting some limits in the current format which necessitate an update. No functional change intended. MFC after: 2 weeks
* x86: remove gcov kernel supportKonstantin Belousov2021-04-021-2/+1
| | | | | | Reviewed by: jhb Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D29529
* Tune DTrace 'aframes' for the FBT and profile providers on arm64.Robert Watson2021-03-222-4/+4
| | | | | | | | | In both cases, too few frames were trimmed, leading to exception handling or DTrace internals being exposed in stack traces exposed by D's stack() primitive. MFC after: 3 days Reviewed by: emaste, andrew
* DTrace: remove sparc64 remnants in non-contrib codeEd Maste2021-03-221-17/+0
| | | | Sponsored by: The FreeBSD Foundation
* Handle functions that use a nop in the arm64 fbtAndrew Turner2021-03-032-19/+37
| | | | | | | | | To trace leaf asm functions we can insert a single nop instruction as the first instruction in a function and trigger off this. Reviewed by: gnn Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D28132
* Reimplement the arm64 dtrace_gethrtime(), which provides theRobert Watson2021-02-191-10/+13
| | | | | | | | | | | | | high-resolution nanosecond timestamp used for the DTrace 'timestamp' built-in variable. The new implementation uses the EL0 cycle counter and frequency registers in ARMv8-A. This replaces a previous implementation that relied on an instrumentation-safe implementation of getnanotime(), which provided only timer resolution. MFC after: 3 days Reviewed by: andrew, bsdimp (older version) Useful comments appreciated: jrtc27, emaste
* arm64: Improve DDB backtrace supportJessica Clarke2021-02-011-10/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | The existing implementation relies on each trap handler saving a normal stack frame record, which is a waste of time and space when we're already saving a trapframe to the stack. It's also wrong as it currently saves LR not ELR. Instead of patching it up, rewrite it based on the RISC-V implementation with inspiration from the amd64 implementation for how to handle vectored traps to provide an improved implementation. This includes compressing the information down to one line like other architectures rather than the highly-verbose old form that repeats itself by printing LR and FP in one frame only to print them as PC and SP in the next. It also includes printing out actually useful information about the traps that occurred, though FAR is not saved in the trapframe so we cannot print it (in general it can be clobbered between when the trap happened and now), only ESR. The AAPCS also allows the stack frame record to be located anywhere in the frame, not just the top, so the caller's SP is not at a fixed offset from the callee's FP like on almost all other architectures in existence. This means there is no way to derive the caller's SP in the unwinder, and so we have to drop that bit of (unused) state everywhere. Reviewed by: jhb, markj Differential Revision: https://reviews.freebsd.org/D28026
* riscv: fix kernel buildMitchell Horne2021-01-151-0/+2
| | | | | | | A more complete fix for this function is being worked on in D28054. Fix the uninitialized variable error so that builds can at least proceed. Reported by: several
* Handle using a sub instruction in the arm64 fbtAndrew Turner2021-01-122-1/+22
| | | | | | | | Some stack frames are too large for a store pair instruction we already detect in the arm64 fbt code. Add support for handling subtracting the stack pointer directly. Sponsored by: Innovate UK
* Only allow a store through sp in the arm64 fbtAndrew Turner2021-01-121-3/+13
| | | | | | | | | | | | | | | | When searching for an instruction to patch out in the arm64 function boundary trace we search for a store pair with a write back. This instruction is commonly used to store two registers to the stack and update the stack pointer to hold space for more. This works in many cases, however not all functions use this, e.g. when the stack frame is too large. In these cases we may find another instruction of the same type that doesn't store through the stack pointer. Filter these instructions out and assume if we see one we are past the function prologue. Reported by: rwatson Sponsored by: Innovate UK
* dtrace: Blacklist riscv exception handlers for fbtKristof Provost2021-01-121-0/+13
| | | | | | | | | We can't safely instrument those exception handlers, so blacklist them. Test case: dtrace -n ::: Reviewed by: markj (previous version) Differential Revision: https://reviews.freebsd.org/D27754
* Changes that improve DTrace FBT reliability on freebsd/arm64:Robert Watson2021-01-115-3/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Implement a dtrace_getnanouptime(), matching the existing dtrace_getnanotime(), to avoid DTrace calling out to a potentially instrumentable function. (These should probably both be under KDTRACE_HOOKS. Also, it's not clear to me that they are correct implementations for the DTrace thread time functions they are used in .. fixes for another commit.) - Don't allow FBT to instrument functions involved in EL1 exception handling that are involved in FBT trap processing: handle_el1h_sync() and do_el1h_sync(). - Don't allow FBT to instrument DDB and KDB functions, as that makes it rather harder to debug FBT problems. Prior to these changes, use of FBT on FreeBSD/arm64 rapidly led to kernel panics due to recursion in DTrace. Reliable FBT on FreeBSD/arm64 is reliant on another change from @andrew to have the aarch64 instrumentor more carefully check that instructions it replaces are against the stack pointer, which can otherwise lead to memory corruption. That change remains under review. MFC after: 2 weeks Reviewed by: andrew, kp, markj (earlier version), jrtc27 (earlier version) Differential revision: https://reviews.freebsd.org/D27766
* Check that the frame pointer is within the current stack.John Baldwin2020-12-082-13/+8
| | | | | | | | | | | | | | This same check is used on other architectures. Previously this would permit a stack frame to unwind into any arbitrary kernel address (including unmapped addresses). Reviewed by: andrew, markj Obtained from: CheriBSD Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D27362 Notes: svn path=/head/; revision=368455
* Stack unwinding robustness fixes for RISC-V.John Baldwin2020-12-082-4/+13
| | | | | | | | | | | | | | | | - Push the kstack_contains check down into unwind_frame() so that it is honored by DDB and DTrace. - Check that the trapframe for an exception frame is contained in the traced thread's kernel stack for DDB traces. Reviewed by: markj Obtained from: CheriBSD Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D27357 Notes: svn path=/head/; revision=368454
* sdt: Create providers and probes in separate passes when loading sdt.koMark Johnston2020-12-031-17/+39
| | | | | | | | | | | | | | | | | | | | | The sdt module's load handler iterates over SDT linker sets for the kernel and all loaded modules to create probes and providers defined by SDT(9). Probes in one module may belong to a provider in a different module, but when a probe is created we assume that the provider is already defined. To maintain this invariant, modify the load handler to perform two separate passes over loaded modules: one to define providers and the other to define probes. The problem manifests when loading linux.ko, which depends on linux_common.ko, which defines providers used by probes defined in linux.ko. Reported by: gallatin MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=368306
* Fix syntaxKonstantin Belousov2020-12-011-2/+3
| | | | Notes: svn path=/head/; revision=368269
* Fix syntaxKonstantin Belousov2020-12-011-2/+2
| | | | Notes: svn path=/head/; revision=368263
* Use uintptr_t instead of uint64_t for pointers in stack frames.John Baldwin2020-12-011-4/+4
| | | | | | | | | | Reviewed by: andrew Obtained from: CheriBSD Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D27361 Notes: svn path=/head/; revision=368245