Commit graph

2113 commits

Author SHA1 Message Date
John Baldwin
848513a77f x86: Remove silly checks for <sys/cdefs.h>.
These headers #include <sys/cdefs.h> right after checking if it has
already been #included.  The nested #include already existed when the
check for _SYS_CDEFS_H_ was added, so the check shouldn't have been
added in the first place.

PR:		263102 (exp-run)
Reported by:	brooks
Reviewed by:	brooks, imp, emaste
Differential Revision:	https://reviews.freebsd.org/D34796

(cherry picked from commit 1c1bf5bd7c)
2022-05-13 13:12:26 -07:00
Andrew Turner
e5e2c7ffa0 Create sys/reg.h for the common code previously in machine/reg.h
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

(cherry picked from commit b792434150)
2022-05-12 15:12:59 -07:00
John Baldwin
ed159d5f88 bhyve: Remove VM_MAXCPU from the userspace API/ABI.
Reviewed by:	grehan
Differential Revision:	https://reviews.freebsd.org/D34494

(cherry picked from commit f1d450ddee)
2022-05-11 11:54:15 -07:00
John Baldwin
ffd150099c Extend the VMM stats interface to support a dynamic count of statistics.
- Add a starting index to 'struct vmstats' and change the
  VM_STATS ioctl to fetch the 64 stats starting at that index.
  A compat shim for <= 13 continues to fetch only the first 64
  stats.

- Extend vm_get_stats() in libvmmapi to use a loop and a static
  thread local buffer which grows to hold the stats needed.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D27463

(cherry picked from commit 6426978617)
2022-04-29 16:08:17 -07:00
John Baldwin
5159d50a1e Simplify swi for bus_dma.
When a DMA request using bounce pages completes, a swi is triggered to
schedule pending DMA requests using the just-freed bounce pages.  For
a long time this bus_dma swi has been tied to a "virtual memory" swi
(swi_vm).  However, all of the swi_vm implementations are the same and
consist of checking a flag (busdma_swi_pending) which is always true
and if set calling busdma_swi.  I suspect this dates back to the
pre-SMPng days and that the intention was for swi_vm to serve as a
mux.  However, in the current scheme there's no need for the mux.

Instead, remove swi_vm and vm_ih.  Each bus_dma implementation that
uses bounce pages is responsible for creating its own swi (busdma_ih)
which it now schedules directly.  This swi invokes busdma_swi directly
removing the need for busdma_swi_pending.

One consequence is that the swi now works on RISC-V which had previously
failed to invoke busdma_swi from swi_vm.

Reviewed by:	imp, kib
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D33447

(cherry picked from commit 254e4e5b77)
2022-04-29 14:27:47 -07:00
John Baldwin
25f14b19c6 Add <machine/tls.h> header to hold MD constants and helpers for TLS.
The header exports the following:

- Definition of struct tcb.
- Helpers to get/set the tcb for the current thread.
- TLS_TCB_SIZE (size of TCB)
- TLS_TCB_ALIGN (alignment of TCB)
- TLS_VARIANT_I or TLS_VARIANT_II
- TLS_DTV_OFFSET (bias of pointers in dtv[])
- TLS_TP_OFFSET (bias of "thread pointer" relative to TCB)

Note that TLS_TP_OFFSET does not account for if the unbiased thread
pointer points to the start of the TCB (arm and x86) or the end of the
TCB (MIPS, PowerPC, and RISC-V).

Note also that for amd64, the struct tcb does not include the unused
tcb_spare field included in the current structure in libthr.  libthr
does not use this field, and the existing calls in libc and rtld that
allocate a TCB for amd64 assume it is the size of 3 Elf_Addr's (and
thus do not allocate room for tcb_spare).

A <sys/_tls_variant_i.h> header is used by architectures using
Variant I TLS which uses a common struct tcb.

Reviewed by:	kib (older version of x86/tls.h), jrtc27
Sponsored by:	The University of Cambridge, Google Inc.
Differential Revision:	https://reviews.freebsd.org/D33351

For stable/13 only, sys/arm/include/tls.h includes support for
ARM_TP_ADDRESS which is not present in main.

(cherry picked from commit 1a62e9bc00)
2022-04-29 13:50:05 -07:00
Greg V
4cfd4d5482 smbios: support getting address from EFI
On some systems (e.g. Lenovo ThinkPad X240, Apple MacBookPro12,1)
the SMBIOS entry point is not found in the <0xFFFFF space.

Follow the SMBIOS spec and use the EFI Configuration Table for
locating the entry point on EFI systems.

Reviewed by:	rpokala, dab
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D29276

(cherry picked from commit a29bff7a52)
2022-03-03 08:20:07 -06:00
Allan Jude
7abbfbda1e smbios: Move smbios driver out from x86 machdep code
Add it to the x86 GENERIC and MINIMAL kernels

Sponsored by:	Ampere Computing LLC
Submitted by:	Klara Inc.
Reviewed by:	rpokala
Differential Revision:	https://reviews.freebsd.org/D28738

(cherry picked from commit d0673fe160)
2022-03-03 08:20:07 -06:00
Konstantin Belousov
d07bca9b93 x86 atomic.h: remove obsoleted comment
(cherry picked from commit 9596b349bb)
2022-02-11 12:52:55 +02:00
Konstantin Belousov
9d1361ef0a x86 atomics: use lock prefix unconditionally
(cherry picked from commit 9c0b759bf9)
2022-02-11 12:52:55 +02:00
Konstantin Belousov
725225a72a x86 atomic.h: cleanup comments for preprocessor directives
(cherry picked from commit cbf999e75d)
2022-02-11 12:52:55 +02:00
Ed Maste
94e6d14488 Remove "All Rights Reserved" from FreeBSD Foundation sys/ copyrights
These ones were unambiguous cases where the Foundation was the only
listed copyright holder (in the associated license block).

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 9feff969a0)
2022-02-08 15:00:55 -05:00
Mark Johnston
eb62bd1d38 x86: Deduplicate clock.h
The headers were mostly identical on amd64 and i386.

No functional change intended.

Reviewed by:	cperciva, mav, imp, kib, jhb
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit f06f1d1fdb)
2021-12-27 10:48:00 -05:00
Mark Johnston
55e020a6f9 amd64: Reduce the amount of cpuset copying done for TLB shootdowns
We use pmap_invalidate_cpu_mask() to get the set of active CPUs.  This
(32-byte) set is copied by value through multiple frames until we get to
smp_targeted_tlb_shootdown(), where it is copied yet again.

Avoid this copying by having smp_targeted_tlb_shootdown() make a local
copy of the active CPUs for the pmap, and drop the cpuset parameter,
simplifying callers.  Also leverage the use of the non-destructive
CPU_FOREACH_ISSET to avoid unneeded copying within
smp_targeted_tlb_shootdown().

Reviewed by:	alc, kib
Tested by:	pho
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit ab12e8db29)
2021-12-15 08:31:48 -05:00
Mitchell Horne
a6172e6353 amd64: provide PHYS_IN_DMAP() and VIRT_IN_DMAP()
It is useful for quickly checking an address against the DMAP region.
These definitions exist already on arm64 and riscv.

Reviewed by:	kib, markj
MFC after:	3 days
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D32962

(cherry picked from commit 90d4da6225)
2021-12-03 10:02:02 -04:00
Mark Johnston
bc7bc3bdf9 netinet: Remove in_cksum_update()
It was never implemented on powerpc or riscv and appears to have been
unused since it was added in 1998.  No functional change intended.

Reviewed by:	kp, glebius, cy
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 09100f936b)
2021-12-01 07:41:55 -05:00
Mark Johnston
e0cee46f58 amd64: Initialize kernel_pmap's active CPU set to all_cpus
This is in preference to simply filling the cpuset, and allows the
conditional in pmap_invalidate_cpu_mask() to be elided.

Also export pmap_invalidate_cpu_mask() outside of pmap.c for use in a
subsequent commit.

Suggested by:	kib
Reviewed by:	alc, kib
Tested by:	pho
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 71e6e9da22)
2021-11-29 09:17:08 -05:00
Mark Johnston
36ca4b79b8 amd64: Define KVA regions for KMSAN shadow maps
KMSAN requires two shadow maps, each one-to-one with the kernel map.
Allocate regions of the kernels PML4 page for them.  Add functions to
create mappings in the shadow map regions, these will be used by the
KMSAN runtime.

Reviewed by:	alc, kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit f95f780ea4)
2021-11-02 18:17:58 -04:00
Mark Johnston
bf0986b742 Generalize bus_space(9) and atomic(9) sanitizer interceptors
Make it easy to define interceptors for new sanitizer runtimes, rather
than assuming KCSAN.  Lay a bit of groundwork for KASAN and KMSAN.

When a sanitizer is compiled in, atomic(9) and bus_space(9) definitions
in atomic_san.h are used by default instead of the inline
implementations in the platform's atomic.h.  These definitions are
implemented in the sanitizer runtime, which includes
machine/{atomic,bus}.h with SAN_RUNTIME defined to pull in the actual
implementations.

No functional change intended.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 3ead60236f)
2021-11-01 10:16:39 -04:00
Mark Johnston
65f3c07b98 amd64: Add MD bits for KASAN
- Initialize KASAN before executing SYSINITs.
- Add a GENERIC-KASAN kernel config, akin to GENERIC-KCSAN.
- Increase the kernel stack size if KASAN is enabled.  Some of the
  ASAN instrumentation increases stack usage and it's enough to
  trigger stack overflows in ZFS.
- Mark the trapframe as valid in interrupt handlers if it is
  assigned to td_intr_frame.  Otherwise, an interrupt in a function
  which creates a poisoned alloca region can trigger false positives.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit f115c06121)
2021-11-01 10:02:41 -04:00
Mark Johnston
a3d4c8e21d amd64: Implement a KASAN shadow map
The idea behind KASAN is to use a region of memory to track the validity
of buffers in the kernel map.  This region is the shadow map.  The
compiler inserts calls to the KASAN runtime for every emitted load
and store, and the runtime uses the shadow map to decide whether the
access is valid.  Various kernel allocators call kasan_mark() to update
the shadow map.

Since the shadow map tracks only accesses to the kernel map, accesses to
other kernel maps are not validated by KASAN.  UMA_MD_SMALL_ALLOC is
disabled when KASAN is configured to reduce usage of the direct map.
Currently we have no mechanism to completely eliminate uses of the
direct map, so KASAN's coverage is not comprehensive.

The shadow map uses one byte per eight bytes in the kernel map.  In
pmap_bootstrap() we create an initial set of page tables for the kernel
and preloaded data.

When pmap_growkernel() is called, we call kasan_shadow_map() to extend
the shadow map.  kasan_shadow_map() uses pmap_kasan_enter() to allocate
memory for the shadow region and map it.

Reviewed by:	kib
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D29417

(cherry picked from commit 6faf45b34b)
2021-11-01 09:57:30 -04:00
Konstantin Belousov
56c136a0d5 amd64: add pmap_page_set_memattr_noflush()
(cherry picked from commit 33c17670af)
2021-10-10 12:21:18 +03:00
Konstantin Belousov
a53e3f3bf2 Revert "linux32: add a hack to avoid redefining the type of the savefpu tag"
(cherry picked from commit e36d0e86e3)
2021-10-10 12:21:17 +03:00
Konstantin Belousov
3804d1ff77 amd64: eliminate td_md.md_fpu_scratch
(cherry picked from commit bd9e0f5df6)
2021-10-10 12:21:17 +03:00
Konstantin Belousov
4d0d7ea9e7 amd64: stop using top of the thread' kernel stack for FPU user save area
MFC note: this commit changes layout of td_md for amd64, resulting in
static checks for struct thread ABI in kern_thread.c to fail.  Next
two commits restore the layout, I decided to not overcomplicate the
merge and not do the work that is going to be overwritten immediately.

(cherry picked from commit df8dd6025a)
2021-10-10 12:21:17 +03:00
Konstantin Belousov
61b29720ef amd64: centralize definitions of CS_SECURE and EFL_SECURE
(cherry picked from commit a42d362bb5)
2021-10-10 12:21:17 +03:00
Adam Fenn
9ba8ea3f05 x86: cpufunc: Add rdtsc_ordered()
(cherry picked from commit 652ae7b114)
2021-10-10 12:21:16 +03:00
Adam Fenn
60490b72ba x86: cpufunc: Add rdtscp_aux()
(cherry picked from commit 908e277230)
2021-10-10 12:21:16 +03:00
Jason A. Harmening
166784e275 amd64 pmap: convert to counter(9), add PV and pagetable page counts
This change converts most of the counters in the amd64 pmap from
global atomics to scalable counter(9) counters.  Per discussion
with kib@, it also removes the handrolled per-CPU PCID save count
as it isn't considered generally useful.

The bulk of these counters remain guarded by PV_STATS, as it seems
unlikely that they will be useful outside of very specific debugging
scenarios.  However, this change does add two new counters that
are available without PV_STATS.  pt_page_count and pv_page_count
track the number of active physical-to-virtual list pages and page
table pages, respectively.  These will be useful in evaluating
the memory footprint of pmap structures under various workloads,
which will help to guide future changes in this area.

Reviewed by:	kib

(cherry picked from commit e4b8deb222)
2021-09-01 09:29:01 -04:00
Konstantin Belousov
89423483e8 amd64 pmap_vm_page_alloc_check(): loose the assert
(cherry picked from commit 665895db26)
2021-08-24 02:21:14 +03:00
Konstantin Belousov
9452209154 amd64 pmap_vm_page_alloc_check(): print more data for failed assert
(cherry picked from commit 1a55a3a729)
2021-08-24 02:21:14 +03:00
Konstantin Belousov
a686d177a7 Add pmap_vm_page_alloc_check()
(cherry picked from commit 041b7317f7)
2021-08-24 02:21:13 +03:00
Konstantin Belousov
8ca493ffb4 amd64: do not assume that kernel is loaded at 2M physical
(cherry picked from commit e18380e341)
2021-08-24 02:21:13 +03:00
Konstantin Belousov
c946f69985 amd64: rework AP startup
(cherry picked from commit d6717f8778)
2021-08-24 02:21:12 +03:00
Konstantin Belousov
6ba7789189 amd64: add pmap_alloc_page_below_4g()
(cherry picked from commit c8bae074d9)
2021-08-03 12:52:37 +03:00
Konstantin Belousov
21049f0567 amd64: make efi_boot global
(cherry picked from commit 6a3821369f)
2021-08-03 12:52:36 +03:00
Andrew Turner
ade8b810b0 Create VM_MEMATTR_DEVICE on all architectures
This is intended to be used with memory mapped IO, e.g. from
bus_space_map with no flags, or pmap_mapdev.

Use this new memory type in the map request configured by
resource_init_map_request, and in pciconf.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D29692

(cherry picked from commit 5d2d599d3f)
2021-06-13 16:49:36 +01:00
Mitchell Horne
e21ed730a5 gdb: report specific stop reason for watchpoints
The remote protocol allows for implementations to report more specific
reasons for the break in execution back to the client [1]. This is
entirely optional, so it is only implemented for amd64, arm64, and i386
at the moment.

[1] https://sourceware.org/gdb/current/onlinedocs/gdb/Stop-Reply-Packets.html

Reviewed by:	jhb
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
NetApp PR:	51

(cherry picked from commit 7446b0888d)
2021-04-21 10:20:33 -03:00
Mitchell Horne
20e6d79f43 x86: implement kdb watchpoint functions
Add wrappers around the dbreg interface that can be consumed by MI
kernel debugger code. The dbreg functions themselves are updated to
return error codes, not just -1. dbreg_set_watchpoint() is extended to
accept access bits as an argument.

Reviewed by:	jhb, kib, markj
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.

(cherry picked from commit 15dc1d4452)
2021-04-21 10:20:33 -03:00
Mark Johnston
5e96fbdfc4 amd64: Make KPDPphys local to pmap.c
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 7ae2e70336)
2021-03-31 09:16:11 -04:00
D Scott Phillips
7590d7800c bhyve: support relocating fbuf and passthru data BARs
We want to allow the UEFI firmware to enumerate and assign
addresses to PCI devices so we can boot from NVMe[1]. Address
assignment of PCI BARs is properly handled by the PCI emulation
code in general, but a few specific cases need additional support.
fbuf and passthru map additional objects into the guest physical
address space and so need to handle address updates. Here we add a
callback to emulated PCI devices to inform them of a BAR
configuration change. fbuf and passthru then watch for these BAR
changes and relocate the frame buffer memory segment and passthru
device mmio area respectively.

We also add new VM_MUNMAP_MEMSEG and VM_UNMAP_PPTDEV_MMIO ioctls
to vmm(4) to facilitate the unmapping needed for addres updates.

[1]: https://github.com/freebsd/uefi-edk2/pull/9/

Originally by:	scottph
Sponsored by:	Intel Corporation
Reviewed by:	grehan
Approved by:	philip (mentor)
Differential Revision:	https://reviews.freebsd.org/D24066

(cherry picked from commit f8a6ec2d57)
2021-03-26 21:50:41 +08:00
Mark Johnston
980da033a8 Rename _cscan_atomic.h and _cscan_bus.h to atomic_san.h and bus_san.h
Other kernel sanitizers (KMSAN, KASAN) require interceptors as well, so
put these in a more generic place as a step towards importing the other
sanitizers.

No functional change intended.

Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D29103

(cherry picked from commit 435c7cfb24)
2021-03-15 11:39:11 -04:00
Mateusz Guzik
6d3ce617f3 amd64: use compiler intrinsics for bsf* and bsr*
(cherry picked from commit aae89f6f09)
2021-02-04 18:01:08 +00:00
Mateusz Guzik
be03df57d6 amd64: retire sse2_pagezero
All page zeroing is using temporal stores with rep movs*, the routine is
unused for several years.

Should a need arise for zeroing using non-temporal stores, a more
optimized variant can be implemented with a more descriptive name.

(cherry picked from commit d1de5698df)
2021-02-01 12:39:18 +00:00
Mateusz Guzik
37bd3aa6fa amd64: use builtins for all ffs* variants
While here even up whitespace.
2021-01-14 14:37:22 +00:00
Roger Pau Monne
ed78016d00 xen/privcmd: implement the dm op ioctl
Use an interface compatible with the Linux one so that the user-space
libraries already using the Linux interface can be used without much
modifications.

This allows user-space to make use of the dm_op family of hypercalls,
which are used by device models.

Sponsored by:	Citrix Systems R&D
2021-01-11 16:33:27 +01:00
Konstantin Belousov
45974de8fb x86: Add rdtscp32() into cpufunc.h.
Suggested by:	markj
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D27986
2021-01-10 04:42:34 +02:00
Mitchell Horne
72939459bd amd64: use register macros for gdb_cpu_getreg()
Prefer these newly-added definitions to bare values.

MFC after:	2 weeks
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
2020-12-18 16:16:03 +00:00
Mitchell Horne
0ef474de88 amd64: allow gdb(4) to write to most registers
Similar to the recent patch to arm's gdb stub in r368414, allow GDB to
update the contents of most general purpose registers.

Reviewed by:	cem, jhb, markj
MFC after:	2 weeks
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
NetApp PR:	44
Differential Revision:	https://reviews.freebsd.org/D27642
2020-12-18 16:09:24 +00:00
Peter Grehan
15add60d37 Convert vmm_ops calls to IFUNC
There is no need for these to be function pointers since they are
never modified post-module load.

Rename AMD/Intel ops to be more consistent.

Submitted by:	adam_fenn.io
Reviewed by:	markj, grehan
Approved by:	grehan (bhyve)
MFC after:	3 weeks
Differential Revision:	https://reviews.freebsd.org/D27375
2020-11-28 01:16:59 +00:00