Commit Graph

456 Commits

Author SHA1 Message Date
Warner Losh
a2f733abcf lib: 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:23:59 -07:00
Warner Losh
dc36d6f9bb lib: 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:28 -07:00
Warner Losh
b2c76c41be Remove $FreeBSD$: one-line nroff pattern
Remove /^\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:15 -06:00
Warner Losh
fa9896e082 Remove $FreeBSD$: two-line nroff pattern
Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:10 -06:00
Warner Losh
d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh
1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Warner Losh
42b388439b Remove $FreeBSD$: one-line .h pattern
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:23 -06:00
Warner Losh
b3e7694832 Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:16 -06:00
Andrew Turner
29629d9e76 arm: Rename pte-v6.h to pte.h
There is no need for this to be versioned after the removal of armv4/v5

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D41139
2023-07-24 17:58:15 +01:00
John Baldwin
e6ef68530b libkvm: Remove set but unused variable from ppc64mmu_hpt_init.
Reported by:	GCC
2023-06-20 09:28:59 -07:00
Warner Losh
4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Ashish SHUKLA
e6901a29bc
kvm_close(3): Check kd->sparse_map != NULL before munmap
PR:		266113
Reviewed by:	markj
2022-10-16 16:49:16 +00:00
firk
bb53dd56c3 kern_tc.c/cputick2usec() (which is used to calculate cputime from
cpu ticks) has some imprecision and, worse, huge timestep (about
20 minutes on 4GHz CPU) near 53.4 days of elapsed time.

kern_time.c/cputick2timespec() (it is used for clock_gettime() for
querying process or thread consumed cpu time) Uses cputick2usec()
and then needlessly converting usec to nsec, obviously losing
precision even with fixed cputick2usec().

kern_time.c/kern_clock_getres() uses some weird (anyway wrong)
formula for getting cputick resolution.

PR:		262215
Reviewed by:	gnn
Differential Revision:	https://reviews.freebsd.org/D34558
2022-03-21 09:33:46 -04:00
Andrew Turner
f2e36d47e3 Make page size dynamic in libkvm for arm64
To allow for a future 16k or 64k page size we need to tell libkvm which
is being used. Add a flag field in unused space in minidumphdr and use
it to signal between the different options.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34548
2022-03-15 09:52:15 +00:00
Warner Losh
fe532f1a50 libkvm: Remove mips support
libkvm references files in sys/mips, so remove it ahead of removing
sys/mips.

Sponsored by:		Netflix
2021-12-30 20:57:24 -07:00
David E. O'Brien
0cd475f86b Document 7f911abe's new functions came in 11.0
Document that the 7f911abe "Add support to libkvm for reading vmcores
from other architectures." added functions appeared first in FreeBSD 11.0.
2021-12-15 16:18:59 -08:00
Bora Özarslan
08055452cb libkvm: fix kvm_walk_pages
Correct bitmap operations in _kvm_bitmap_next.

Reviewed by:	jhb
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D19183
2021-12-10 14:15:15 -05:00
Michał Górny
8099a35446 libkvm: Fix kvm_getloadavg() on modern kernel vmcores
Fix kvm_getloadavg() to work correctly on vmcores for modern kernel
versions.  The kernels no longer include the `_fscale` symbol causing
the kvm_nlist() invocation to fail.  The code seemed to already assume
that `_fscale` could be missing but the early kvm_nlist() result check
has caused the function to fail if any symbol were missing.  Modify
it to only treat `_averunnable` as obligatory, and handle missing
`_fscale` gracefully.

Sponsored by:   The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32884
2021-12-07 15:36:34 -08:00
Konstantin Belousov
e67ef6ce66 libkvm: Fix build after removeal of p_tracevp
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2021-05-22 16:36:54 +03:00
Jung-uk Kim
483c6da3a2 libkvm: Refine the previous commit (645eaa2cca)
Resort free()'ing memory in kvm_close() to make it easier to MFC.

MFC after:	3 days
2021-03-03 18:50:45 -05:00
Jung-uk Kim
645eaa2cca libkvm: Plug couple of memory leaks and check possible calloc(3) failure
First, r204494 introduced dpcpu_off in struct __kvm and it was allocated
from _kvm_dpcpu_init() but it was not free(3)'ed from kvm_close(3).
Second, r291406 introduced kvm_nlist2(3) and converted kvm_nlist(3) to
use the new function but it did not free the temporary buffer.
Also, check possible calloc(3) failure while I am in the neighborhood.

MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D29019
2021-03-03 18:10:00 -05:00
Alex Richardson
fa2528ac64 Use atomic loads/stores when updating td->td_state
KCSAN complains about racy accesses in the locking code. Those races are
fine since they are inside a TD_SET_RUNNING() loop that expects the value
to be changed by another CPU.

Use relaxed atomic stores/loads to indicate that this variable can be
written/read by multiple CPUs at the same time. This will also prevent
the compiler from doing unexpected re-ordering.

Reported by:	GENERIC-KCSAN
Test Plan:	KCSAN no longer complains, kernel still runs fine.
Reviewed By:	markj, mjg (earlier version)
Differential Revision: https://reviews.freebsd.org/D28569
2021-02-18 14:02:48 +00:00
Konstantin Belousov
5844bd058a jobc: rework detection of orphaned groups.
Instead of trying to maintain pg_jobc counter on each process group
update (and sometimes before), just calculate the counter when needed.
Still, for the benefit of the signal delivery code, explicitly mark
orphaned groups as such with the new process group flag.

This way we prevent bugs in the corner cases where updates to the counter
were missed due to complicated configuration of p_pptr/p_opptr/real_parent
(debugger).

Since we need to iterate over all children of the process on exit, this
change mostly affects the process group entry and leave, where we need
to iterate all process group members to detect orpaned status.

(For MFC, keep pg_jobc around but unused).

Reported by:	jhb
Reviewed by:	jilles
Tested by:	pho
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D27871
2021-01-10 04:41:20 +02:00
Mark Johnston
b957b18594 Always use 64-bit physical addresses for dump_avail[] in minidumps
As of r365978, minidumps include a copy of dump_avail[].  This is an
array of vm_paddr_t ranges.  libkvm walks the array assuming that
sizeof(vm_paddr_t) is equal to the platform "word size", but that's not
correct on some platforms.  For instance, i386 uses a 64-bit vm_paddr_t.

Fix the problem by always dumping 64-bit addresses.  On platforms where
vm_paddr_t is 32 bits wide, namely arm and mips (sometimes), translate
dump_avail[] to an array of uint64_t ranges.  With this change, libkvm
no longer needs to maintain a notion of the target word size, so get rid
of it.

This is a no-op on platforms where sizeof(vm_paddr_t) == 8.

Reviewed by:	alc, kib
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D27082
2020-12-03 17:12:31 +00:00
Conrad Meyer
85078b8573 Split out cwd/root/jail, cmask state from filedesc table
No functional change intended.

Tracking these structures separately for each proc enables future work to
correctly emulate clone(2) in linux(4).

__FreeBSD_version is bumped (to 1300130) for consumption by, e.g., lsof.

Reviewed by:	kib
Discussed with:	markj, mjg
Differential Revision:	https://reviews.freebsd.org/D27037
2020-11-17 21:14:13 +00:00
Mateusz Guzik
f165a1df9a libkvm: catch up with pre-subtracated per-cpu addresses
Only concerns amd64.

Reported by:	imp
2020-10-06 02:57:37 +00:00
Kyle Evans
7cc42f6d25 Do a sweep and remove most WARNS=6 settings
Repeating the default WARNS here makes it slightly more difficult to
experiment with default WARNS changes, e.g. if we did something absolutely
bananas and introduced a WARNS=7 and wanted to try lifting the default to
that.

Drop most of them; there is one in the blake2 kernel module, but I suspect
it should be dropped -- the default WARNS in the rest of the build doesn't
currently apply to kernel modules, and I haven't put too much thought into
whether it makes sense to make it so.
2020-10-01 01:10:51 +00:00
Brandon Bergren
f4eb39ba6b [PowerPC64LE] libkvm powerpc64le support.
* Add missing _kvm16toh() function.
* Teach libkvm about powerpc64le.

Sponsored by:	Tag1 Consulting, Inc.
2020-09-23 02:11:24 +00:00
D Scott Phillips
00e6614750 Sparsify the vm_page_dump bitmap
On Ampere Altra systems, the sparse population of RAM within the
physical address space causes the vm_page_dump bitmap to be much
larger than necessary, increasing the size from ~8 Mib to > 2 Gib
(and overflowing `int` for the size).

Changing the page dump bitmap also changes the minidump file
format, so changes are also necessary in libkvm.

Reviewed by:	jhb
Approved by:	scottl (implicit)
MFC after:	1 week
Sponsored by:	Ampere Computing, Inc.
Differential Revision:	https://reviews.freebsd.org/D26131
2020-09-21 22:21:59 +00:00
Alfredo Dal'Ava Junior
537976d190 test: add libkvm read test
This test checks if value received from kvm_read is sane, based on
value returned by sysctl interface.

This should catch regression on bug fixed by r359160

Reviewed by:	jhb
Approved by:	jhibbits (mentor)
MFC after:	1 week
Sponsored by:	Eldorado Research Institute (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D23783
2020-07-08 18:58:44 +00:00
Dimitry Andric
ea143d1be6 Fix copy/paste mistake in kvm_getswapinfo(3)
It seems this manpage was copied from kvm_getloadavg(3), but the
DIAGNOSTICS section was not updated completely. Update the section with
correct information about a return value of -1.

MFC after:	3 days
2020-06-25 20:04:35 +00:00
Mark Johnston
34e2051faf Remove swblk_t.
It was used only to store the bounds of each swap device.  However,
since swblk_t is a signed 32-bit int and daddr_t is a signed 64-bit
int, swp_pager_isondev() may return an invalid result if swap devices
are repeatedly added and removed and sw_end for a device ends up
becoming a negative number.

Note that the removed comment about maximum swap size still applies.

Reviewed by:	jeff, kib
Tested by:	pho
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D23666
2020-02-17 15:11:07 +00:00
Bjoern A. Zeeb
10108cb673 Partially revert VNET change and expand VNET structure.
Revert parts of r353274 replacing vnet_state with a shutdown flag.

Not having the state flag for the current SI_SUB_* makes it harder to debug
kernel or module panics related to VNET bringup or teardown.
Not having the state also does not allow us to check for other dependency
levels between components, e.g. for moving interfaces.

Expand the VNET structure with the new boolean flag indicating that we are
doing a shutdown of a given vnet and update the vnet magic cookie for the
change.

Update libkvm to compile with a bool in the kernel struct.

Bump __FreeBSD_version for (external) module builds to more easily detect
the change.

Reviewed by:	hselasky
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D23097
2020-02-17 11:08:50 +00:00
Warner Losh
08d7456502 Remove sparc64 files
These were disconnected from the build when the kernel was
removed. Since they depend on removed parts of the kernel, remove them
completely.
2020-02-12 06:53:29 +00:00
Leandro Lupori
38cf2a4334 Implement kvm_kerndisp
This change adds a new libkvm function, kvm_kerndisp(), that can be used to
retrieve the kernel displacement, that is the difference between the kernel's
base virtual address at run time and the kernel base virtual address specified
in the kernel image file.

This will be used by kgdb, to properly relocate kernel symbols, when needed.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D23285
2020-02-06 13:21:59 +00:00
Warner Losh
58aa35d429 Remove sparc64 kernel support
Remove all sparc64 specific files
Remove all sparc64 ifdefs
Removee indireeect sparc64 ifdefs
2020-02-03 17:35:11 +00:00
Simon J. Gerraty
2c9a9dfc18 Update Makefile.depend files
Update a bunch of Makefile.depend files as
a result of adding Makefile.depend.options files

Reviewed by:	 bdrewery
MFC after:	1 week
Sponsored by:   Juniper Networks
Differential Revision:  https://reviews.freebsd.org/D22494
2019-12-11 17:37:53 +00:00
Leandro Lupori
d3c34fc0f4 [PPC64] Initial libkvm minidump implementation
This change adds PowerPC64 support for minidumps on libkvm.

Address translation, page walk, and data retrieval were tested and seem to be
working correctly.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D21555
2019-12-09 13:59:36 +00:00
Ed Maste
9dc7ed6253 kvm: fix types for cross-debugging
As with other libkvm interfaces use maximum-sized types to support
cross-debugging (e.g. a 64-bit vmcore on a 32-bit host).  See
https://lists.freebsd.org/pipermail/svn-src-all/2019-February/176051.html
for further discussion.

This is an API-breaking change, but there are few consumers of this
interface today.

Reviewed by:	will
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D21945
2019-11-08 14:51:09 +00:00
Mike Karels
789f4e26e6 Add support for ps -H on corefiles in libkvm
Add support for kernel threads in kvm_getprocs() and the underlying
kvm_proclist() in libkvm when fetching from a kernel core file. This
has been missing/needed for several releases, when kernel threads became
normal threads.  The loop over the processes now contains a sub-loop for
threads, which iterates beyond the first thread only when threads are
requested.  Also set some fields such as tid that were previously
uninitialized.

Reviewed by:	vangyzen jhb(earlier revision)
MFC after:	4 days
Sponsored by:	Forcepoint LLC
Differential Revision:	https://reviews.freebsd.org/D21461
2019-09-22 13:56:27 +00:00
Leandro Lupori
8024ba45db Add powerpc support to libkvm probe function
PowerPC kernels are of DYN type, instead of EXEC.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D21583
2019-09-10 18:46:32 +00:00
Emmanuel Vadot
a7b5a3d486 pkgbase: Put a lot of binaries and lib in FreeBSD-runtime
All of them are needed to be able to boot to single user and be able
to repair a existing FreeBSD installation so put them directly into
FreeBSD-runtime.

Reviewed by:    bapt, gjb
Differential Revision:  https://reviews.freebsd.org/D21503
2019-09-05 14:13:08 +00:00
Mark Johnston
4fa0295937 Chase r350037.
Reported by:	jenkins
MFC with:	r350037
Sponsored by:	The FreeBSD Foundation
2019-07-16 16:02:20 +00:00
Enji Cooper
148a8da8d9 Update the spelling of my name (continuation of r346571)
Previous spellings of my name (NGie, Ngie) weren't my legal spelling. Use Enji
instead for clarity.

While here, remove "All Rights Reserved" from copyrights I "own".

MFC after:	1 week
2019-04-22 18:05:33 +00:00
John Baldwin
2e43efd0bb Drop "All rights reserved" from my copyright statements.
Reviewed by:	rgrimes
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D19485
2019-03-06 22:11:45 +00:00
Mark Johnston
f3af92bd36 Reorder copyright lines to preserve the source of "All rights reserved."
Reported by:	rgrimes
MFC with:	r344829, r344830
2019-03-06 16:50:14 +00:00
Mark Johnston
5e58ed820a Add riscv minidump support to libkvm.
Submitted by:	Mitchell Horne <mhorne063@gmail.com>
Differential Revision:	https://reviews.freebsd.org/D19171
2019-03-05 23:59:55 +00:00
Konstantin Belousov
9a52756044 i386: Merge PAE and non-PAE pmaps into same kernel.
Effectively all i386 kernels now have two pmaps compiled in: one
managing PAE pagetables, and another non-PAE. The implementation is
selected at cold time depending on the CPU features. The vm_paddr_t is
always 64bit now. As result, nx bit can be used on all capable CPUs.

Option PAE only affects the bus_addr_t: it is still 32bit for non-PAE
configs, for drivers compatibility. Kernel layout, esp. max kernel
address, low memory PDEs and max user address (same as trampoline
start) are now same for PAE and for non-PAE regardless of the type of
page tables used.

Non-PAE kernel (when using PAE pagetables) can handle physical memory
up to 24G now, larger memory requires re-tuning the KVA consumers and
instead the code caps the maximum at 24G. Unfortunately, a lot of
drivers do not use busdma(9) properly so by default even 4G barrier is
not easy. There are two tunables added: hw.above4g_allow and
hw.above24g_allow, the first one is kept enabled for now to evaluate
the status on HEAD, second is only for dev use.

i386 now creates three freelists if there is any memory above 4G, to
allow proper bounce pages allocation. Also, VM_KMEM_SIZE_SCALE changed
from 3 to 1.

The PAE_TABLES kernel config option is retired.

In collaboarion with: pho
Discussed with:	emaste
Reviewed by:	markj
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D18894
2019-01-30 02:07:13 +00:00
Konstantin Belousov
c9bbc3ef29 Make cache coherency attributes definitions available in machine/vm.h on MIPS.
Move definitions from cpuregs.h into the cca.h, and include cca.h into vm.h.
This is required to make MIPS MD memattr definitions usable in userspace.

Sponsored by:	The FreeBSD Foundation, Mellanox Technologies
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D15583
2018-08-01 18:35:17 +00:00
Brooks Davis
f38b68ae8a Make struct xinpcb and friends word-size independent.
Replace size_t members with ksize_t (uint64_t) and pointer members
(never used as pointers in userspace, but instead as unique
idenitifiers) with kvaddr_t (uint64_t). This makes the structs
identical between 32-bit and 64-bit ABIs.

On 64-bit bit systems, the ABI is maintained. On 32-bit systems,
this is an ABI breaking change. The ABI of most of these structs
was previously broken in r315662.  This also imposes a small API
change on userspace consumers who must handle kernel pointers
becoming virtual addresses.

PR:		228301 (exp-run by antoine)
Reviewed by:	jtl, kib, rwatson (various versions)
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D15386
2018-07-05 13:13:48 +00:00