Commit Graph

2387 Commits

Author SHA1 Message Date
Christos Margiolis
1fef7abdc7 dtrace: add register bindings for RISC-V
Reviewed by:	mhorne, markj
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D39611
2023-04-20 13:35:57 -04:00
Christos Margiolis
75081b9ed8 dtrace: use dtrace_instr_size() in the riscv dtrace_subr.c
No functional change intended.

Reviewed by:	mhorne, markj
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D39652
2023-04-20 13:35:57 -04:00
Christos Margiolis
080e56a6c9 dtrace: expose dtrace_instr_size() to userland and implement it for riscv
dtrace_instr_size() is needed by the forthcoming RISC-V port of kinst,
as well as by libdtrace in D38825 for both amd64 and RISC-V.

Reviewed by:	markj, mhorne
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D39489
2023-04-20 13:35:57 -04:00
Christos Margiolis
1a149d65ba dtrace: get rid of uchar_t types
Callers are specifying uint8_t anyway and this slightly reduces
dependencies on compatibility typedefs.  No functional change intended.

Reviewed by:	markj, mhorne
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D39490
2023-04-20 13:35:56 -04:00
Christos Margiolis
0388a0887a dtrace: handle NOP instructions in the riscv invop handler
This will be used by a forthcoming port of the kinst provider.

Reviewed by:	markj
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D39481
2023-04-10 12:14:11 -04:00
Justin Hibbits
e620e088cb dtrace/powerpc: Remove accidental commented out line
Fixes:	3e1155ade1
2023-03-13 11:37:40 -04:00
Justin Hibbits
3e1155ade1 dtrace/powerpc: "Fix" stack traces across trap frames
In function boundary tracing the link register is not yet saved to the
save stack location, so the save point contains whatever the previous
'lr' save was, or even garbage, at the time the trap is taken.  Address
this by explicitly loading the link register from the trap frame instead
of the stack, and propagate that out.
2023-03-11 11:35:27 -05:00
Justin Hibbits
635ecbf470 dtrace/powerpc: Adjust AFRAMES for fbt and profile
FBT_AFRAMES was skipping over too many frames, while PROFILE_AFRAMES was
skipping over too few.  Adjust them empirically.
2023-03-11 11:35:27 -05:00
Mitchell Horne
c6943b44f7 dtrace: implement riscv dtrace_getustackdepth()
Pretty trivial following other implementations. The existing
dtrace_getustack_common() does most of the work.

Reviewed by:	markj
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D38303
2023-02-06 15:26:53 -04:00
Jessica Clarke
3872010732 dtrace: Fix RISC-V user stack unwinder
The unwind logic was copied from AArch64 which follows the peculiar
AACPS (where, unlike typical RISC architectures, its frame pointer
follows an x86/stack machine-like convention where the frame pointer
points at the bottom of the frame record, not the top). Delete the
pointless riscv_frame struct and fix this.

Reviewed by:	mhorne
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D28054
2023-02-06 15:26:53 -04:00
Mitchell Horne
06faad1de2 dtrace: handle page faults in riscv dtrace_trap()
We must detect the correct amount to increment sepc, as it may have been
a compressed instruction that triggered the fault.

Reviewed by:	markj
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D38299
2023-02-06 15:26:53 -04:00
Mitchell Horne
0e563bde48 dtrace_asm.S: properly enter/exit user access
In order to read or write userspace memory without generating an access
fault, we must first enable the SUM bit in the sstatus CSR.

Reviewed by:	markj
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D38298
2023-02-06 15:26:53 -04:00
Domagoj Stolfa
7c5bc69a1a dtrace: Improve a verifier error message
Using '%r0' in efunc causes it to parse %r as a 'r' specifier.

This diff just adds a '%' in front of '%r0' in order to create the
correct output.

Reviewed by:	markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D38176
2023-01-24 09:09:27 -05:00
Mitchell Horne
36a9ce874b dtrace: correct the aframes value for fbt provider
Set the number of artificial frames to 5:
 1. cpu_exception_handler_supervisor()
 2. do_trap_supervisor()
 3. dtrace_invop_start()
 4. dtrace_invop()
 5. fbt_invop()

Reviewed by:	markj
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D37663
2023-01-12 11:06:07 -04:00
Mitchell Horne
40fdda022a dtrace: correct profile aframes value for riscv
Experimentation shows this is the correct value; the dtrace/interrupt
handler frames are omitted, while the backtrace of the active thread is
recorded in its entirety.

Reviewed by:	markj
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D37662
2023-01-12 11:06:07 -04:00
Mitchell Horne
cdfa49f258 dtrace: dtrace_getpcstack() tweaks for riscv
Backtraces for fbt probes are missing the caller's frame. Despite what
the inherited comment claims, we do need to insert this manually on
riscv. In fbt_invop(), set cpu_dtrace_caller to be the return address,
not addr.

We should not increment aframes within this function, since we begin the
main loop by unwinding past the current frame.

Plus some very small comment/style tweaks.

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D37661
2023-01-12 11:04:58 -04:00
Mitchell Horne
756a67e15e dtrace: kill mips definitions in profile provider
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D37660
2023-01-12 11:04:51 -04:00
Mitchell Horne
2f2ec4bce9 dtrace: remove unused defines
Reviewed by:	markj, emaste
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D37659
2023-01-12 11:04:47 -04:00
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
Mark Johnston
778b74378f kinst: Make the provider ops table const
No functional change intended.
2022-12-08 15:03:41 -05:00
Mark Johnston
ad5d6f38c4 kinst: Correct a comment
Fixes:	f0bc4ed144 ("kinst: Initial revision")
2022-12-08 15:03:32 -05:00
Justin Hibbits
088cf0c5db powerpc/dtrace: Guard fuword64 usage for powerpc64 only
32-bit powerpc doesn't have a fuword64, so only use it on powerpc64.
This could also be done elsewhere that splits 32-bit and 64-bit
accesses, but adding ifdefs everywhere would just clutter up the source
for little benefit.  This is the only usage of fuword64 directly; other
archs have a dtrace_fuword64_nocheck(), but powerpc does not, and I
don't see a need to add it currently.

MFC after:	1 week
2022-11-20 19:50:45 -05:00
Mateusz Guzik
a72edfea57 dtrace: avoid kinst warn when not used
Reviewed by:	markj
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-11-15 13:40:31 +00:00
Mark Johnston
60013d9c50 dtrace: Fix the i386 FBT build
Reported by:	Jenkins
Fixes:	0e69c95915 ("dtrace: Fix up %rip for invop probes on x86")
2022-11-01 00:17:48 -04:00
Mark Johnston
0e69c95915 dtrace: Fix up %rip for invop probes on x86
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
2022-10-31 19:11:36 -04:00
Justin Hibbits
ec9388ddba dtrace: Make pid provider work on trivial tests
'newpc' needs set in the "common" case.  With this, the trivial test

 $ dtrace -n 'pid$target:libc:strlen:entry { trace(timestamp); }' -p
 <pid>

now works.

MFC after:	3 weeks
2022-10-30 16:00:44 -04:00
Mark Johnston
73a78b5efa kinst: Clarify a comment in the trampoline allocator
Fixes:	f0bc4ed144 ("kinst: Initial revision")
2022-10-14 11:32:47 -04:00
Mark Johnston
b4e483bdb0 kinst: Remove an unused constant
This was left over after a rework of the trampoline allocator.

Fixes:	f0bc4ed144 ("kinst: Initial revision")
2022-10-14 11:32:46 -04:00
Mark Johnston
b34a6e0fed dtrace: Drop illumos ifdefs for CPU register definitions
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
2022-10-12 16:06:33 -04:00
Christos Margiolis
f0bc4ed144 kinst: Initial revision
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
2022-10-11 18:19:08 -04:00
Mark Johnston
bdd101c4d4 dtrace: Add a "regs" variable
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
2022-10-04 13:05:54 -04:00
Mark Johnston
a2578094a3 opensolaris: Delete unused sources
The SDT implementation in the opensolaris compat module just defines the
sdt:::set-error probe for ZFS.  But OpenZFS provides its own
implementation, and this one was not connected to the build.

No functional change intended.

MFC after:	1 week
2022-09-29 08:34:29 -04:00
Dimitry Andric
0beb88a242 Adjust function definition in riscv's dtrace_subr.c to avoid clang 15 warning
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
2022-08-14 21:27:34 +02:00
Dimitry Andric
7701f30159 Adjust function definition in powerpc's dtrace_subr.c to avoid clang 15 warning
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
2022-08-14 21:27:34 +02:00
Dimitry Andric
7357c2e5a6 Adjust function definition in arm's dtrace_subr.c to avoid clang 15 warning
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
2022-08-14 21:27:34 +02:00
Mark Johnston
3ba8e9dc4a dtrace/amd64: Implement emulation of call instructions
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
2022-08-09 18:34:01 -04:00
Mark Johnston
a7aa3d4d75 fbt/x86: Extract arg1 for return probes from the trapframe
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
2022-08-09 18:34:01 -04:00
Warner Losh
1306a5dc07 stand/libsa: zfs use standard ZFS_EARLY stuff
Now that the minor issues preventing zfs.c from using CFLAGS_EARLY have
been fixed, use that mechanism like everything else that needs the
OpenZFS spl headers. This simplifies things somewhat. Update comments to
document why zfs.c is still special, though in different ways.

Note: We also use the fact that NEED_SOLARIS_BOOLEAN is only defined in
an environment where the solaris compat boolean stuff will be defined
prior to this point (eg, when we're building zfs.c in libsa), but not in
other environments (like when we're building mkimage and stand-alone
boot loaders that don't use libsa). These latter uses should be changed
to use the same ZFS compile env, but aren't as part of this commit.
This has to be done in the same change as the ZFS_EARLY change to not
break zfs.c building for one commit affecting bisectabiltiy.

Sponsored by:		Netflix
Reviewed by:		tsoome, delphij
Differential Revision:	https://reviews.freebsd.org/D35894
2022-07-24 16:53:36 -06:00
Warner Losh
976b977c61 zfs: Increase compatibility for different environments
libsa uses the full OpenZFS compilation environment when we build this
included in zfs.c there. Other parts of the tree have not been adapted
to the full OpenZFS environment yet and need these ASSERT* defines to
build properly. Since the ASSERT* macros are normally defined in
sys/debug.h in the OpenZFS compatibility spl, only define them when
ASSERT3S is not defined to cope with the parts of the loader that don't
yet use the full OpenZFS environment.

Sponsored by:		Netflix
Reviewed by:		tsoome, delphij
Differential Revision:	https://reviews.freebsd.org/D35893
2022-07-24 16:53:36 -06:00
Dimitry Andric
6339314c73 Adjust fbt_unload() definition to avoid clang 15 warning
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
2022-07-21 19:42:43 +02:00
Dimitry Andric
9a97978883 Adjust prototype_unload() definition to avoid clang 15 warning
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
2022-07-20 17:13:49 +02:00
Dimitry Andric
6f5f44562a Adjust dtrace_unload() definition to avoid clang 15 warning
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
2022-07-19 20:48:47 +02:00
Dimitry Andric
bd0e3cc2e7 Adjust dtrace_getf_barrier() definition to avoid clang 15 warning
With clang 15, the following -Werror warnings is produced:

    sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c:17019:20: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    dtrace_getf_barrier()
		       ^
			void

This is because dtrace_getf_barrier() is declared with a (void) argument
list, but defined with an empty argument list. Make the definition match
the declaration.

MFC after:	3 days
2022-07-19 20:46:18 +02:00
Dimitry Andric
2d03b58f9a Adjust profile_unload() definition to avoid clang 15 warning
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
2022-07-19 20:42:52 +02:00
Dimitry Andric
a0c55bac79 Adjust dtmalloc_unload() definition to avoid clang 15 warning
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
2022-07-19 20:37:08 +02:00
Warner Losh
75ad24775b stand: Add blake3 support to boot loader
Add the necessary glue to get blake3 building for the boot loaded as
well as connected to the ZFS system so it is useful.

On some platforms, we create references to blake3_sse2_impl and
blake3_sse41_impl ops structs to utilize SIMD. These aren't present on
x86 (since we dind't ask for them), but are on aarch64 with no
implementation. Since we don't want SIMD in the boot loader, have these
all return 'unsupported' always. This should be fixed upstream to allow
more flexibility in this selection, but for now we use this hack to not
modify the sys/contrib/openzfs with difficult to maintain hacks while
an upstreamable solution is found.

tsoome@ did the implementation bits in sys/cddl/boot, and I did the
Makefile work and the aweful blake3_impl_hack.c.

Co-author:		tsoome@freebsd.org
Sponsored by:		Netflix
Reviewed by:		kevans (earlier version)
Differential Revision:	https://reviews.freebsd.org/D35750
2022-07-08 22:57:59 -06:00
Toomas Soome
e50e40684a loader: add support for gzip compression
As we do have zlib code in loader, we should also support gzip
compression in zfs.

PR:		153173
Submitted by:	Mikhail Zakharov <zmey20000@yahoo.com>
Reviewed by:	imp, markj, delphij
Differential Revision: https://reviews.freebsd.org/D35320
MFC after:	1 month
2022-06-09 20:54:30 +03:00
Mitchell Horne
35eb9b10c2 Use KERNEL_PANICKED() in more places
This is slightly more optimized than checking panicstr directly. For
most of these instances performance doesn't matter, but let's make
KERNEL_PANICKED() the common idiom.

Reviewed by:	mjg
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D35373
2022-06-02 10:15:43 -03:00
Christos Margiolis
034667f9fa dtrace: add warning for /dev/dtrace/prototype
Let the programmer know that creating a device is not necessary.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D35381
2022-06-01 12:58:31 -04:00
Christos Margiolis
2a72a1a41b dtrace: remove /dev/dtrace/fbt
It is unused.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D35377
2022-06-01 12:49:43 -04:00