Commit graph

2448 commits

Author SHA1 Message Date
Andrew Turner c2e0d56f5e arm64: Support BTI checking in most of the kernel
LLD has the -zbti-report=error argument to check if the BTI note is
present when linking. To allow for this to be used when linking the
kernel and modules:
 - Add the BTI note to the remaining assembly files
 - Mark ptrauth.c as protected by BTI
 - Disable -zbti-report for vmm hypervisor switching code as it's not
   used there.

The linux64 module doesn't build with the flag as it includes vdso code
that doesn't include the note.

Reviewed by:	imp, kib, emaste
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D45466
2024-06-05 09:23:40 +00:00
Mark Johnston 2468e20df4 boot/zfs: Sync the definition of dsl_dataset_phys with OpenZFS
No functional change intended.

MFC after:	1 week
2024-06-01 11:12:12 -04:00
Andriy Gapon b9827c007a Revert "dtrace: make 'ring' and 'fill' policies imply 'noswitch' flag"
This reverts commit e92491d95f.

The general idea looked good to me.  In particular, it allowed to save
some memory and avoid memory allocation failures when a large buffer
size was requested along with ring and fill policies.

But I didn't take into account that the second, supposedly unused
buffer, was actually used as the scratch buffer.  The scratch buffer is
used as a temporary space for DTrace subroutines like copyin, copyinstr,
and alloca.

I think that the change can be fixed by allocating a separate smaller
buffer for the scratch buffer, but that fix would require more work than
I am able to do now.  Hence the revert.

Reported by:	Domagoj Stolfa
Diagnosed by:	Domagoj Stolfa, markj
MFC after:	immediately
2024-04-21 15:17:08 +03:00
John Baldwin e48770de68 arm64: Use void pointers for arguments to arm64_get_writable_addr
No functional change, but this reduces diffs with CheriBSD downstream.

Reviewed by:	andrew
Sponsored by:	University of Cambridge, Google, Inc.
Differential Revision:	https://reviews.freebsd.org/D44344
2024-03-15 10:10:24 -07:00
John Baldwin 1e3f42b6ba arm64: Switch the address argument to cpu_*cache* to a pointer
No functional change, but this reduces diffs with CheriBSD downstream.

Reviewed by:	andrew
Sponsored by:	University of Cambridge, Google, Inc.
Differential Revision:	https://reviews.freebsd.org/D44342
2024-03-15 10:09:49 -07:00
Alfredo Mazzinghi 61cc4830a7 Abstract UIO allocation and deallocation.
Introduce the allocuio() and freeuio() functions to allocate and
deallocate struct uio. This hides the actual allocator interface, so it
is easier to modify the sub-allocation layout of struct uio and the
corresponding iovec array.

Obtained from:	CheriBSD
Reviewed by:	kib, markj
MFC after:	2 weeks
Sponsored by:	CHaOS, EPSRC grant EP/V000292/1
Differential Revision:	https://reviews.freebsd.org/D43711
2024-02-10 11:38:04 -05:00
Andriy Gapon e92491d95f dtrace: make 'ring' and 'fill' policies imply 'noswitch' flag
This should disable allocation of the second per-CPU principal buffer
which is never used.  This will also enable additional asserts
for buffers that are never switched.
2024-01-28 15:15:17 +02:00
Mark Johnston 7d35b38972 dtrace/profile: Set t_dtrace_trapframe for profile probes
profile provider probes fire in the context of a timer interrupt.  Thus,
the "regs" action can make use of the interrupt trap frame to get
register values when the interrupt happened in kernel mode.  Make that
trap frame available when possible so that "regs" works more or less as
it already does with the fbt and kinst providers.

MFC after:	1 week
2024-01-07 11:46:13 -05:00
Warner Losh fdafd315ad sys: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:24:00 -07:00
Warner Losh 29363fb446 sys: Remove ancient SCCS tags.
Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by:		Netflix
2023-11-26 22:23:30 -07:00
Mark Johnston 3115538908 boot/zfs: Add some fields to dsl_dir_phys_t
Most of the first block of pad bytes are now used for space accounting
purposes.  No functional change intended.

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2023-10-23 11:12:14 -04:00
Ed Maste e49c7cd677 dtrace: remove x86 non-EARLY_AP_STARTUP support
After 792655abd6 EARLY_AP_STARTUP is mandatory for x86.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D42139
2023-10-10 11:03:27 -04:00
Igor Ostapenko b4db386f9f dtrace: fix fbt regression for aarch64
fbt computes incorrect instruction position for AArch64 kernel module symbol.

The issue is with the for loop, it does an extra increment of instr pointer
after the required instruction is found. Hence, a wrong instruction is
targeted for patching.

Signed-off-by:  Igor Ostapenko <pm@igoro.pro>

Fixes:		980746e5cb ("fbt: simplify arm64 function-prologue parsing")
Reviewed by:	markj
Pull Request:	https://github.com/freebsd/freebsd-src/pull/855
MFC after:	1 week
2023-10-03 13:07:41 -04:00
Christos Margiolis bbe8195bfa kinst: do not look for a function epilogue
kinst currently only traces functions that start and end with the usual
function prologue and epilogue respectively. Ignoring functions that do
not have an epilogue however, makes the filtering too strict, as this
means that we can not trace functions that never return (e.g
vnlru_proc()). This patch relaxes the filtering and only checks whether
the function pushes the frame pointer.

Reviewed by:	markj
Approved by:	markj
Differential Revision:	https://reviews.freebsd.org/D41876
2023-09-15 16:33:41 +01:00
Domagoj Stolfa 8527bb2aee dtrace: Fix a kernel panic in printm()
When using printm(), one should always pass a scratch pointer to it.
This is achieved by calling printm with memref

  BEGIN { printm(fixed_len, memref(ptr, var_len)); }

which will return a pointer to the DTrace scratch space of size
sizeof(uintptr_t) * 2. However, one can easily call printm() as follows

  BEGIN { printm(10, (void *)NULL); }

and panic the kernel as a result. This commit does two things:

  (1) adds a new macro DTRACE_INSCRATCHPTR(mstate, ptr, howmany) which
      checks if a certain pointer is in the DTrace scratch space;
  (2) uses DTRACE_INSCRATCHPTR() to implement a check on printm()'s DIFO
      return value in order to avoid the panic and sets CPU_DTRACE_BADADDR
      if the address is not in the scratch space.

Reviewed by:	markj
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D41722
2023-09-06 10:00:59 -04:00
Warner Losh 2063df1471 sys: Remove $FreeBSD$: one-line catalog
Remove /^\s*\$\s*\$FreeBSD\$$\n/
2023-08-16 11:55:22 -06:00
Warner Losh 78d146160d sys: Remove $FreeBSD$: one-line bare tag
Remove /^\s*\$FreeBSD\$$\n/
2023-08-16 11:55:17 -06:00
Warner Losh 685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Warner Losh 71625ec9ad sys: Remove $FreeBSD$: one-line .c comment pattern
Remove /^/[*/]\s*\$FreeBSD\$.*\n/
2023-08-16 11:54:24 -06:00
Warner Losh 2ff63af9b8 sys: Remove $FreeBSD$: one-line .h pattern
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:18 -06:00
Warner Losh 95ee2897e9 sys: Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:11 -06:00
Christos Margiolis 02402ec888 kinst.h: make pointer to probe in kinst_cpu_state const
Fixes: 5b701ed19c ("kinst: start moving towards per-probe
trampolines")

Sponsored by: The FreeBSD Foundation
2023-07-19 19:57:44 +03:00
Christos Margiolis e967a9a5d5 Revert "dtrace: cache current probe in kdtrace_thread_t"
This reverts commit 22508c8b6c.

The t_kinst_curprobe field is no longer needed by kinst.

Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41031
2023-07-19 17:58:49 +03:00
Christos Margiolis 07864a8a24 kinst: port to arm64
Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40337
2023-07-19 17:58:18 +03:00
Christos Margiolis 2517b2085b kinst: use per-probe trampolines in riscv
Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40963
2023-07-19 17:57:59 +03:00
Christos Margiolis 5b701ed19c kinst: start moving towards per-probe trampolines
Using per-CPU and per-thread trampolines is expensive and error-prone,
since we're rewriting the same memory blocks constantly. Per-probe
trampolines solve this problem by giving each probe its own block of
executable memory, which more or less remains the same after the initial
write.

What this patch does, is get rid of the initialization code which
allocates a trampoline for each thread, and instead let each port of
kinst allocate a trampoline for each new probe created. It also sets up
the infrastructure needed to support the new trampoline scheme.

This change is not currently supported on amd64, as the amd64 port needs
further changes to work, so this is a temporary/gradual patch to fix the
riscv and arm64 ports.

Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40962
2023-07-19 17:57:21 +03:00
Christos Margiolis eb1413c9a6 kinst: exclude cpu_switch
Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40985
2023-07-19 17:56:29 +03:00
Christos Margiolis ea89133dbc kinst: check for 'push %rbp' anywhere in the function
Currently kinst checks if only the first instruction is 'push %rbp',
essentially excluding functions that do push RBP, but not in the first
instruction. This patch modifies kinst to check for 'push %rbp', as
well, as a following 'pop %rbp', anywhere in the function. This behavior
also matches that of FBT.

Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40283
2023-07-19 17:53:08 +03:00
Christos Margiolis 8ada3f78e6 kinst.h: reorder function declarations based on implementation file
Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41032
2023-07-19 17:50:24 +03:00
Jessica Clarke c63c4e694c Don't bother to check COMPAT_32BIT when __LP64__ is defined
Under COMPAT_32BIT we are compiling 32-bit code and so __LP64__ is not
defined, __ILP32__ is, and thus the check is completely redundant.

Reviewed by:	brooks, jhb, imp
Differential Revision:	https://reviews.freebsd.org/D40917
2023-07-09 18:45:32 +01:00
Doug Moore e087768130 inline_fls: remove redundant INLINE_FLS test
HAS_INLINE_FLS and similar macros are defined always.
Removes the redundant tests for these always-true conditions.
Reviewed by:	mhorne
Differential Revision:	https://reviews.freebsd.org/D40707
2023-07-06 13:29:13 -05:00
Christos Margiolis 9310bf5404 kinst: update LICENSE headers
Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40875
2023-07-04 18:38:25 +03:00
Christos Margiolis 2d7bb03adb kinst: port to riscv
Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D39884
2023-07-04 18:38:01 +03:00
Christos Margiolis 22508c8b6c dtrace: cache current probe in kdtrace_thread_t
Needed by the forthcoming RISC-V and ARM64 ports.

Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40872
2023-07-04 18:37:55 +03:00
Mark Johnston 6281147a96 dtrace/arm64: Fix user memory access routines
Use unprivileged loads to access user memory.  Without this, the
accesses trap and various dtrace actions such as ustack() fail.

Reviewed by:	andrew
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40540
2023-06-15 12:39:21 -04:00
Mark Johnston 91522683d4 dtrace/arm64: Store the fault address when suppressing a page fault
Reviewed by:	andrew
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40539
2023-06-15 12:38:45 -04:00
Mark Johnston d325184232 arm64: Remove struct arm64_frame
It was used in one place and was added specifically to support dtrace
stack unwinding code.  Write an equivalent expression using struct
unwind_state instead.  No functional change intended.

Reviewed by:	andrew
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40538
2023-06-15 12:38:45 -04:00
Christos Margiolis 1aa4862187 kinst: rename t_kinst to t_kinst_tramp
The forthcoming RISC-V and ARM64 ports of kinst introduce a new field
named "t_kinst_curprobe", so "t_kinst" (which points to a trampoline)
becomes a misleading name.

No functional change intended.

Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40507
2023-06-13 15:46:45 +03:00
Christos Margiolis 333731274f kinst: hide KINST_TRAMPCHUNK_SIZE from ISA-specific headers
Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40505
2023-06-13 15:46:33 +03:00
Christos Margiolis 47a5d58e3b kinst: fix kinst_probe_md field indentation
Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40411
2023-06-03 23:03:14 +03:00
Christos Margiolis d434607b3d kinst: use bool where appropriate
Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40412
2023-06-03 23:02:53 +03:00
Christos Margiolis 9b091f1200 kinst: simplify trampoline fill definitions
Centralize KINST_TRAMP_FILL_PATTERN and KINST_TRAMP_FILL_SIZE to reduce
redefinitions, and use the architecture-dependent kinst_patchval_t as
their size.

Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40406
2023-06-03 20:04:57 +03:00
Christos Margiolis 980746e5cb fbt: simplify arm64 function-prologue parsing
Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40364
2023-06-03 20:04:33 +03:00
Christos Margiolis bab7781e78 dtrace: deduplicate arm64 breakpoint definition
Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40363
2023-06-03 20:04:10 +03:00
Christos Margiolis 7a8cf053d1 dtrace: deduplicate some RISC-V functions
match_opcode() is defined in FBT, kinst, and dtrace_subr.c. The function
prologue-checking functions are defined in FBT and kinst.

Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40335
2023-05-30 18:07:18 +03:00
Christos Margiolis 5c134fba22 kinst: fix memcpy() tracing crash
Tracing memcpy() would crash the kernel, because we'd also trace the
memcpy() calls from kinst_invop(). To fix this, introduce kinst_memcpy()
whose arguments are 'volatile', so that we avoid having the compiler
replace it with a regular memcpy().

Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40284
2023-05-26 18:43:37 +03:00
Christos Margiolis 9c80ad6839 kinst: add kinst_excluded()
Exclude functions that are not safe-to-trace.

Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
ifferential Revision:	https://reviews.freebsd.org/D39229
2023-05-26 16:54:08 +03:00
Christos Margiolis 855ade9e72 kinst: be explicit about trampoline placement
The current implementation and comment was specific to amd64. Even
though in the case of kinst's supported architectures (RISC-V and ARM64)
VM_MIN_KERNEL_ADDRESS is equal to KERNBASE, it's better to be explicit.

Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40266
2023-05-25 23:40:46 +03:00
Christos Margiolis ff624eb636 kinst: use dtrace_dis_get_byte() instead of own copy
No functional change intended.

Reviewed by:	markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D39872
2023-05-23 18:12:18 +03:00
Christos Margiolis 98ab9802af dtrace: rename rp to frame in dtrace_getreg()
Reviewed by:	mhorne, markj
Approved by:	markj (mentor)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40231
2023-05-23 17:44:47 +03:00