Commit graph

9181 commits

Author SHA1 Message Date
Gordon Bergling
025a5f6b25 vmm(4): Fix a typo in a kernel message
- s/cant/can't/

(cherry picked from commit 8b5c5cae92d5b44f03636540a787fd6e994ce816)
2024-04-28 07:20:46 +02:00
Minsoo Choo
3b2b83bcef Stop using expressions in _Alignof()
_Alignof(expression) is a non-standard extension.  This is not allowed
in gnu11 and gnu17 which follow the C11 standard _Alignof(type).

Reviewed by:	arichardson, imp, jhb
Fixes:		4a9cd9fc22d7 amd64 db_trace: Reject unaligned frame pointers
Fixes:		7ccaf76a27 riscv db_trace: Ensure trapframe pointer is suitably aligned.
Fixes:		638c68897f arm64 db_trace: Ensure trapframe pointer is suitably aligned.
Differential Revision:	https://reviews.freebsd.org/D43409

(cherry picked from commit 03d04bf49492fc70366e6d78194336a4122282a2)
2024-04-08 10:26:16 -07:00
Konstantin Belousov
38fdb37047 x86: handle MXCSR from XSAVEOPT when x87 state was optimized
PR:	275322

(cherry picked from commit 1c091d11261a3c8cc3728b92760e65242c0f5949)
2024-04-02 11:58:20 +03:00
Konstantin Belousov
b40ed1134d x86: test the right CPUID bit when checking for XSAVEOPT support
(cherry picked from commit 960d151eaa1ecde109accc30ca0c3306551d8e58)
2024-04-02 11:58:20 +03:00
Bjoern A. Zeeb
faf66c373a ath(4): always enable 11n
Enabling 11n for ath(4) so far was handled by a kernel option, which
was only enabled for certain kernel configurations.
In order to allow loading ath(4) as a module with 11n support on
all platforms, remove the kernel option and unconditionally enable
11n in ath(4).

Reported by:	pkubaj
Reviewed by:	adrian, imp

(cherry picked from commit 89c1e54a71cc4e04d4c575ee6df956a12e163cde)
2024-04-01 23:46:10 +00:00
Mark Johnston
a0f02252c4 vmm: Expose more registers to VM_GET_REGISTER
In a follow-up revision the gdb stub will support sending an XML target
description to gdb, which lets us send additional registers, including
the ones added in this patch.

Reviewed by:	jhb
MFC after:	1 month
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D43665

(cherry picked from commit f493ea650e6137ba657dfa0627da1e8bb4a985e9)
2024-03-08 23:28:39 -05:00
Alfredo Mazzinghi
2de742797b 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

(cherry picked from commit 61cc4830a7b16400efade3d884a59fda6d80d651)
2024-03-08 23:27:20 -05:00
Vitaliy Gusev
14e782708d vmm: Fix compiling error with BHYVE_SNAPSHOT
The return values of copyin() and copyout() must be checked.
vm_snapshot_buf_cmp() is unused by the kernel and was incorrectly
implemented, so just remove it.

Reviewed by:	markj
Sponsored by:	vStack
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D43754

(cherry picked from commit 7572fe89ada63719b558c6b844e2743cd3ff6b6a)
2024-02-20 09:21:14 -05:00
Andriy Gapon
007b84e6c1 rdmsr_safe/wrmsr_safe: handle pcb_onfault nesting
rdmsr_safe and wrmsr_safe can be called while pcb_onfault is already
set, so the functions are modified to preserve the handler rather than
resetting it before returning.

One case where that happens is when AMD microcode update routine
is executed on a stack where copyin / copyout was already active.

Here is a sample panic message from a crash caused by resetting the
handler:

  <118>Updating CPU Microcode...

  Fatal trap 12: page fault while in kernel mode
  cpuid = 3; apic id = 03
  fault virtual address   = 0x11ed0de6000
  fault code              = supervisor write data, page not present
  instruction pointer     = 0x20:0xffffffff80c2df03
  stack pointer           = 0x28:0xfffffe01ce4a4c70
  frame pointer           = 0x28:0xfffffe01ce4a4c70
  code segment            = base 0x0, limit 0xfffff, type 0x1b
                          = DPL 0, pres 1, long 1, def32 0, gran 1
  processor eflags        = interrupt enabled, resume, IOPL = 0
  current process         = 117 (logger)
  trap number             = 12
  panic: page fault
  cpuid = 3
  time = 1681462027
  KDB: stack backtrace:
  db_trace_self_wrapper() at 0xffffffff80615deb = db_trace_self_wrapper+0x2b/frame 0xfffffe01ce4a4830
  kdb_backtrace() at 0xffffffff80943c77 = kdb_backtrace+0x37/frame 0xfffffe01ce4a48e0
  vpanic() at 0xffffffff808f5fe5 = vpanic+0x185/frame 0xfffffe01ce4a4940
  panic() at 0xffffffff808f5da3 = panic+0x43/frame 0xfffffe01ce4a49a0
  trap_fatal() at 0xffffffff80c31849 = trap_fatal+0x379/frame 0xfffffe01ce4a4a00
  trap_pfault() at 0xffffffff80c318b5 = trap_pfault+0x65/frame 0xfffffe01ce4a4a60
  trap() at 0xffffffff80c30f5f = trap+0x29f/frame 0xfffffe01ce4a4b80
  trap_check() at 0xffffffff80c31c29 = trap_check+0x29/frame 0xfffffe01ce4a4ba0
  calltrap() at 0xffffffff80c07fd8 = calltrap+0x8/frame 0xfffffe01ce4a4ba0
  --- trap 0xc, rip = 0xffffffff80c2df03, rsp = 0xfffffe01ce4a4c70, rbp = 0xfffffe01ce4a4c70 ---
  copyout_nosmap_std() at 0xffffffff80c2df03 = copyout_nosmap_std+0x63/frame 0xfffffe01ce4a4c70
  uiomove_faultflag() at 0xffffffff8095f0d5 = uiomove_faultflag+0xe5/frame 0xfffffe01ce4a4cb0
  uiomove() at 0xffffffff8095efeb = uiomove+0xb/frame 0xfffffe01ce4a4cc0
  pipe_read() at 0xffffffff80968860 = pipe_read+0x230/frame 0xfffffe01ce4a4d30
  dofileread() at 0xffffffff809653cb = dofileread+0x8b/frame 0xfffffe01ce4a4d80
  sys_read() at 0xffffffff80964fa0 = sys_read+0xc0/frame 0xfffffe01ce4a4df0
  amd64_syscall() at 0xffffffff80c3221a = amd64_syscall+0x18a/frame 0xfffffe01ce4a4f30
  fast_syscall_common() at 0xffffffff80c088eb = fast_syscall_common+0xf8/frame 0xfffffe01ce4a4f30
  --- syscall (3, FreeBSD ELF64, read), rip = 0x11ece41cfaa, rsp = 0x11ecbec4908, rbp = 0x11ecbec4920 ---
  Uptime: 41s

And another one:

  Fatal trap 12: page fault while in kernel mode
  cpuid = 4; apic id = 04
  fault virtual address   = 0x800a22000
  fault code              = supervisor write data, page not present
  instruction pointer     = 0x20:0xffffffff80b2c7ca
  stack pointer           = 0x28:0xfffffe01c55b5480
  frame pointer           = 0x28:0xfffffe01c55b5480
  code segment            = base 0x0, limit 0xfffff, type 0x1b
                          = DPL 0, pres 1, long 1, def32 0, gran 1
  processor eflags        = interrupt enabled, resume, IOPL = 0
  current process         = 68418 (pfctl)
  trap number             = 12
  panic: page fault
  cpuid = 4
  time = 1625184463
  KDB: stack backtrace:
  db_trace_self_wrapper() at 0xffffffff805c1e8b = db_trace_self_wrapper+0x2b/frame 0xfffffe01c55b5040
  kdb_backtrace() at 0xffffffff808874b7 = kdb_backtrace+0x37/frame 0xfffffe01c55b50f0
  vpanic() at 0xffffffff808449d8 = vpanic+0x188/frame 0xfffffe01c55b5150
  panic() at 0xffffffff808445f3 = panic+0x43/frame 0xfffffe01c55b51b0
  trap_fatal() at 0xffffffff80b300a5 = trap_fatal+0x375/frame 0xfffffe01c55b5210
  trap_pfault() at 0xffffffff80b30180 = trap_pfault+0x80/frame 0xfffffe01c55b5280
  trap() at 0xffffffff80b2f729 = trap+0x289/frame 0xfffffe01c55b5390
  trap_check() at 0xffffffff80b304d9 = trap_check+0x29/frame 0xfffffe01c55b53b0
  calltrap() at 0xffffffff80b0bb28 = calltrap+0x8/frame 0xfffffe01c55b53b0
  --- trap 0xc, rip = 0xffffffff80b2c7ca, rsp = 0xfffffe01c55b5480, rbp = 0xfffffe01c55b5480 ---
  copyout_nosmap_std() at 0xffffffff80b2c7ca = copyout_nosmap_std+0x15a/frame 0xfffffe01c55b5480
  pfioctl() at 0xffffffff85539358 = pfioctl+0x4d28/frame 0xfffffe01c55b5940
  devfs_ioctl() at 0xffffffff807176cf = devfs_ioctl+0xcf/frame 0xfffffe01c55b59a0
  VOP_IOCTL_APV() at 0xffffffff80bb26e2 = VOP_IOCTL_APV+0x92/frame 0xfffffe01c55b59c0
  VOP_IOCTL() at 0xffffffff80928014 = VOP_IOCTL+0x34/frame 0xfffffe01c55b5a10
  vn_ioctl() at 0xffffffff80923330 = vn_ioctl+0xc0/frame 0xfffffe01c55b5b00
  devfs_ioctl_f() at 0xffffffff80717bbe = devfs_ioctl_f+0x1e/frame 0xfffffe01c55b5b20
  fo_ioctl() at 0xffffffff808abc6b = fo_ioctl+0xb/frame 0xfffffe01c55b5b30
  kern_ioctl() at 0xffffffff808abc01 = kern_ioctl+0x1d1/frame 0xfffffe01c55b5b80
  sys_ioctl() at 0xffffffff808ab982 = sys_ioctl+0x132/frame 0xfffffe01c55b5c50
  syscallenter() at 0xffffffff80b30cc9 = syscallenter+0x159/frame 0xfffffe01c55b5ca0
  amd64_syscall() at 0xffffffff80b309a5 = amd64_syscall+0x15/frame 0xfffffe01c55b5d30
  fast_syscall_common() at 0xffffffff80b0c44e = fast_syscall_common+0xf8/frame 0xfffffe01c55b5d30

PR:		276426
Reviewed by:	kib, markj
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D43639

(cherry picked from commit 486b265a8fb6b2aad37f2819fa04feacf8184d53)
2024-02-17 16:18:20 +02:00
Konstantin Belousov
1f7c8f047f amd64 pcb.h: use 4 hex digits for pcb flags
(cherry picked from commit 5f7ac491eef4994b23b4de250927a85c69a64a31)
2024-02-14 05:42:40 +02:00
Konstantin Belousov
10896d25a5 amd64 gdt_segs: use designated initializers
(cherry picked from commit 1d6230b07ff29b4d3ae527dbc0fc3f9775a7542a)
2024-02-14 05:42:40 +02:00
Konstantin Belousov
fc738836d1 amd64/linux*: mark brandlists as static
(cherry picked from commit be707ee09556a3fa345bc30c04aeeaa2a5d2efa2)
2024-02-14 05:42:40 +02:00
Konstantin Belousov
f35c790206 amd64 uprintf_signal: add space between %rax value and code bytes
(cherry picked from commit 130bad217bd8bbd7531539e4f5eb83d3c284e991)
2024-02-14 05:42:39 +02:00
Mark Johnston
40adc27878 arm64: Remove pmap_san_bootstrap() and call kasan_init_early() directly
pmap_san_bootstrap() doesn't really do much, and it was hard-coding the
the bootstrap stack size defined in locore.S.  Moreover, the name is a
bit confusing given the existence of pmap_bootstrap_san().  Just remove
it and call kasan_init_early() directly like we do on amd64.  It will
not be used by KMSAN in a forthcoming patch series.

No functional change intended.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Sponsored by:	Juniper Networks, Inc.
Differential Revision:	https://reviews.freebsd.org/D43403

(cherry picked from commit 90372a9e3cda838914bc8518dbc4340906351e98)
2024-02-02 09:31:08 -05:00
Colin Percival
6a75d3b3fb x86: Adjust base addr for PCI MCFG regions
Each bus gets 1 MB of address space; the actual base address for an
MCFG bus range is the address from the table plus the starting bus
number times 1 MB.

The PCI spec is unclear on this point, but this change matches what
Linux does, which is likely enough of a de facto standard regardless
of what any de jure standard might attempt to say.

Fixes:	f54a3890b1f4 ("x86: Support multiple PCI MCFG regions")
Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D43206

(cherry picked from commit 61e2161367bb4e68e603f53b1107f9427f988861)
2024-01-18 15:24:35 -08:00
John Baldwin
4b5f644088 x86: Support multiple PCI MCFG regions
In particular, this enables support for PCI config access for domains
(segments) other than 0.

Reported by:	cperciva
Tested by:	cperciva (m7i.metal-48xl AWS instance)
Reviewed by:	imp
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D42828

(cherry picked from commit f54a3890b1f419d4a9edc99000efef52b9071b8f)
2024-01-18 15:23:44 -08:00
John Baldwin
1fc6f25daf x86: Refactor pcie_cfgregopen
Split out some bits of pcie_cfgregopen that only need to be executed
once into helper functions in preparation for supporting multiple MCFG
entries.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D42829

(cherry picked from commit 9893a4fd31fa4b2e19a7b9cf786f49b9de50b407)
2024-01-18 15:23:32 -08:00
John Baldwin
b5d2a06b2c pci_cfgreg: Add shims to preserve ABI of pci_cfgreg(read|write)
This is a direct commit to stable/14 to preserve the ABI of the
the pci_cfgregread and pci_cfgregwrite functions.   The new routines
are renamed to add a _domain suffix and macros map the new API to
the new functions.

Note: No API compatibility has been provided as modules in ports
should not be using this internal API (normal PCI drivers use
pci_read_config and pci_write_config with a device_t).
2024-01-18 15:19:11 -08:00
John Baldwin
98b822fccd pci_cfgreg: Add a PCI domain argument to the low-level register API
This commit changes the API of pci_cfgreg(read|write) to add a domain
argument (referred to as a segment in ACPI parlance) (note that this
is not the same as a NUMA domain, but something PCI-specific).  This
does not yet enable access to domains other than 0, but updates the
API to support domains.

Places that use hard-coded bus/slot/function addresses have been
updated to hardcode a domain of 0.  A few places that have the PCI
domain (segment) available such as the acpi_pcib_acpi.c Host-PCI
bridge driver pass the PCI domain.

The hpt27xx(4) and hptnr(4) drivers fail to attach to a device not on
domain 0 since they provide APIs to their binary blobs that only
permit bus/slot/function addressing.

The x86 non-ACPI PCI bus drivers all hardcode a domain of 0 as they do
not support multiple domains.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D42827

(cherry picked from commit 1587a9db92c03c738bb3f0fc5874b43c961e7c99)
2024-01-18 14:44:51 -08:00
Bojan Novković
b879ddc755 vmm: implement VM_CAP_MASK_HWINTR on AMD CPUs
This patch implements the interrupt blocking VM capability on AMD
CPUs.  Implementing this capability allows the GDB stub to single-step
a virtual machine without landing inside interrupt handlers.

Reviewed by:	jhb, corvink
Sponsored by:   Google, Inc. (GSoC 2022)
Differential Revision:	https://reviews.freebsd.org/D42299

(cherry picked from commit 181afaaaee0025f948346fe8b9ec5356a0cdef97)
2024-01-04 16:25:49 -08:00
Bojan Novković
8da9183dcd vmm: implement single-stepping for AMD CPUs
This patch implements single-stepping for AMD CPUs using the RFLAGS.TF
single-stepping mechanism.  The GDB stub requests single-stepping
using the VM_CAP_RFLAGS_TF capability.  Setting this capability will
set the RFLAGS.TF bit on the selected vCPU, activate DB exception
intercepts, and activate POPF/PUSH instruction intercepts.  The
resulting DB exception is then caught by the IDT_DB vmexit handler and
bounced to userland where it is processed by the GDB stub.  This patch
also makes sure that the value of the TF bit is correctly updated and
that it is not erroneously propagated into memory.  Stepping over PUSHF
will cause the vm_handle_db function to correct the pushed RFLAGS
value and stepping over POPF will update the shadowed TF bit copy.

Reviewed by:	jhb
Sponsored by:	Google, Inc. (GSoC 2022)
Differential Revision:	https://reviews.freebsd.org/D42296

(cherry picked from commit e3b4fe645e50bfd06becb74e52ea958315024d5f)
2024-01-04 16:25:41 -08:00
Bojan Novković
3613a28066 vmm: enable software breakpoints for AMD CPUs
This patch adds support for software breakpoint vmexits on AMD SVM.
It implements the VM_CAP_BPT_EXIT used to enable software breakpoints.
When enabled, breakpoint vmexits are passed to userspace where they
are handled by the GDB stub.

Reviewed by:	jhb
Sponsored by:	Google, Inc. (GSoC 2022)
Differential Revision:	https://reviews.freebsd.org/D42295

(cherry picked from commit 231eee17d2905682014b71d1f01719003b13bd91)
2024-01-04 16:25:22 -08:00
Bojan Novković
6d80d20a64 vmm: refactor event reflection in AMD SVM
This patch refactors AMD SVM event reflection to allow events to be
propagated to userland, rather than always reflected into the guest.

This is necessary to implement some capabilities that request VMEXITs
when a specific exception occurs (e.g. VM_CAP_BPT_EXIT).

Reviewed by:	jhb
Sponsored by:	Google, Inc. (GSoC 2022)
Differential Revision:	https://reviews.freebsd.org/D42405

(cherry picked from commit 78c1d174a1e13c6522bd4d663225fc9cbabc329d)
2024-01-04 16:24:36 -08:00
Mark Johnston
266eefe7f4 vmm: Fix handling of errors from subyte()
subyte() returns -1 upon an error, not an errno value.

MFC after:	1 week
Fixes:	e17eca3276 ("vmm: Avoid embedding cpuset_t ioctl ABIs")

(cherry picked from commit 6adf554abd1c848d2c9ab7ea8a7fb7dd20a0c186)
2024-01-01 19:30:00 -05:00
Mark Johnston
f9c3b1be36 thread: Add a return value to cpu_set_upcall()
Some implementations copy data to userspace, an operation which can in
principle fail.  In preparation for adding a __result_use_check
annotation to copyin() and related functions, let implementations of
cpu_set_upcall() return an error, and check for errors when copying data
to user memory.

Reviewed by:	kib, jhb
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43100

(cherry picked from commit 7b68fb5ab2a276ccd081cc1a43cebf0fb315e952)
2024-01-01 19:29:48 -05:00
John Baldwin
f27c8ff817 x86: Rename {stop,start}_emulating to fpu_{enable,disable}
While here, centralize the macros in <x86/fpu.h>.

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

(cherry picked from commit cc1cb9ea0c5607931fa9b7ecf786468d38fb8491)
2023-12-29 13:49:42 -08:00
Konstantin Belousov
e9251d68b2 vm_iommu_map()/unmap(): stop transiently wiring already wired pages
(cherry picked from commit 671a00491d7ac9d6663cdc597ff8c13024eda00d)
2023-12-29 02:33:21 +02:00
Konstantin Belousov
6ed6db3206 vmm_iommu_modify(): split vm_iommu_map()/unmap() into separate functions
(cherry picked from commit 3abc72f8716b55fc71e9463388f5a74fb6abf5ce)
2023-12-29 02:33:21 +02:00
Konstantin Belousov
c06a5fd3b1 vmm.h: remove dup declaration
(cherry picked from commit 7c8f16318499d2b05e916abd66148e5409284a9d)
2023-12-25 05:57:25 +02:00
Brooks Davis
3ad2fd6fb1 makesyscalls: don't make syscall.mk by default
We only want to produce syscall.mk for the main syscall table so default
to not producing it (send it to /dev/null) and add a syscalls.conf to
sys/kern to trigger the creation of sys/sys/syscall.mk.  This eliminates
the need for entries in other syscalls.conf files and is a cleaner
pattern going forward.

Reviewed by:	kevans, imp
Differential Revision:	https://reviews.freebsd.org/D42663

(cherry picked from commit 54d487c4d01d68ef0ac03eae1fc574f7533d46f6)
2023-12-13 23:07:06 +00:00
Mark Johnston
3c3a703ee6 amd64: Remove PMAP_INLINE
With clang it expands to "inline"; clang in practice may inline
externally visible functions even without the hint.  So just remove the
hints and let the compiler decide.

No functional change intended.  pmap.o is identical before and after
this patch.

Reviewed by:	alc
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42446

(cherry picked from commit 2b084923824e0d5133fe5aff580b4e562fe7dd19)
2023-11-09 09:39:57 -05:00
John Baldwin
fbeb784ff4 amd64: Remove a stale comment from cpu_setregs
Reviewed by:	kib, markj, emaste
Differential Revision:	https://reviews.freebsd.org/D42134

(cherry picked from commit e839ebfc0dc5851d383ac38740f32e96f7bd5186)
2023-10-24 11:40:17 -07:00
Mark Johnston
2d49b111a3 uiomove: Add some assertions
Make sure that we don't try to copy with a negative resid.

Make sure that we don't walk off the end of the iovec array.

Reviewed by:	kib
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D42098

(cherry picked from commit 8fd0ec53deaad34383d4b344714b74d67105b258)
2023-10-24 09:19:01 -04:00
Zhenlei Huang
8784b153a3 amd64 pmap: Prefer consistent naming for loader tunable
The sysctl knob 'vm.pmap.allow_2m_x_ept' is loader tunable and have
public document entry in security(7) but is fetched from kernel
environment 'hw.allow_2m_x_ept'. That is inconsistent and obscure.

As there is public security advisory FreeBSD-SA-19:25.mcepsc [1],
people may refer to it and use 'hw.allow_2m_x_ept', let's keep old
name for compatibility.

[1] https://www.freebsd.org/security/advisories/FreeBSD-SA-19:25.mcepsc.asc

Reviewed by:	kib
Fixes:		c08973d09c Workaround for Intel SKL002/SKL012S errata
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D42311

(cherry picked from commit 9e7f349ff10691c2e3fb03898dbc942794a47566)
2023-10-24 12:39:32 +08:00
Zhenlei Huang
9e48b627ae vmx: Prefer consistent naming for loader tunables
The following loader tunables do have corresponding sysctl MIBs but
with different names. That may be historical reason. Let's prefer
consistent naming for them so that it will be easier to read and
maintain.

 1. hw.vmm.l1d_flush -> hw.vmm.vmx.l1d_flush
 2. hw.vmm.l1d_flush_sw -> hw.vmm.vmx.l1d_flush_sw
 3. hw.vmm.vmx.use_apic_pir -> hw.vmm.vmx.cap.posted_interrupts
 4. hw.vmm.vmx.use_apic_vid -> hw.vmm.vmx.cap.virtual_interrupt_delivery
 5. hw.vmm.vmx.use_tpr_shadowing -> hw.vmm.vmx.cap.tpr_shadowing

Old names are kept for compatibility.

Meanwhile, add sysctl flag CTLFLAG_TUN to them so that `sysctl -T` will
report them correctly.

Reviewed by:	corvink, jhb, kib, #bhyve
MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D42251

(cherry picked from commit f3ff0918ffcdbcb4c39175f3f9be70999edb14e8)
2023-10-24 12:39:31 +08:00
Zhenlei Huang
032a0b4454 amd64: Fix two typos of loader tunables
To match the sysctl MIBs and document entries in security(7).

Fixes:	2dec2b4a34 amd64: flush L1 data cache on syscall return with an error
Fixes:	17edf152e5 Control for Special Register Buffer Data Sampling mitigation

Reviewed by:	kib
MFC after:	1 day
Differential Revision:	https://reviews.freebsd.org/D42249

(cherry picked from commit afbb8041a0633c97acb51ac895c9ae3cde4fe540)
2023-10-21 22:41:09 +08:00
Mark Johnston
4533fa42ad amd64: Zero-fill AP PCPU pages
At least KMSAN relies on zero-initialization of AP PCPU regions, see
commit 4b136ef259.

Prior to commit af1c6d3f30 these were allocated with allocpages() in
the amd64 pmap, which always returns zero-initialized memory.

Reviewed by:	kib
Fixes:		af1c6d3f30 ("amd64: do not leak pcpu pages")
MFC after:	3 days
Sponsored by:	Klara, Inc.
Sponsored by:	Juniper Networks, Inc.
Differential Revision:	https://reviews.freebsd.org/D42241

(cherry picked from commit a37e484d049758c70f2d61be0d28a115b6f2f01e)
2023-10-20 12:02:05 -04:00
Dmitry Chagin
c9ec2fb86c linux(4): Drop the outdated comments about sixth register on i386 int0x80
This is well documented in the Linux syscall(2).

MFC after:		1 week

(cherry picked from commit 5bdd74cc05e6c7d110688feacdbd22b6dffe5d72)
2023-10-18 08:52:33 +03:00
John Baldwin
e23f1b86a6 amd64 db_trace: Reject unaligned frame pointers
Switch to using db_addr_t to hold frame pointer values until they are
verified to be suitably aligned.

Reviewed by:	kib, markj
Differential Revision:	https://reviews.freebsd.org/D41532

(cherry picked from commit 4a9cd9fc22d7f87a27ccd3d41b93a0356cd7061c)
2023-10-11 08:10:32 -07:00
John Baldwin
842a945c40 efirt_machdep.c: Trim some unused includes
Reviewed by:	imp, kib, markj
Differential Revision:	https://reviews.freebsd.org/D41596

(cherry picked from commit d1e4c63d9e93b113f7ef5aef5e0e79a4d7dca144)
2023-10-11 08:10:32 -07:00
John Baldwin
b53155d4df efirt: Move comment about fpu_kern_enter to where it is called
Reviewed by:	imp, kib, andrew, markj
Differential Revision:	https://reviews.freebsd.org/D41576

(cherry picked from commit 8173fa60ddb7e9a805dec9fef7bf07e74ae4144d)
2023-10-11 08:10:31 -07:00
Olivier Certner
6c59ac8c79 x86: AMD Zen2: Zenbleed chicken bit mitigation
Applies only to bare-metal Zen2 processors.  The system currently
automatically applies it to all of them.

Tunable/sysctl 'machdep.mitigations.zenbleed.enable' can be used to
forcibly enable or disable the mitigation at boot or run-time.  Possible
values are:

    0: Mitigation disabled
    1: Mitigation enabled
    2: Run the automatic determination.

Currently, value 2 is the default and has identical effect as value 1.
This might change in the future if we choose to take into account
microcode revisions in the automatic determination process.

The tunable/sysctl value is simply ignored on non-applicable CPU models,
which is useful to apply the same configuration on a set of machines
that do not all have Zen2 processors.  Trying to set it to any integer
value not listed above is silently equivalent to setting it to value 2
(automatic determination).

The current mitigation state can be queried through sysctl
'machdep.mitigations.zenbleed.state', which returns "Not applicable",
"Mitigation enabled" or "Mitigation disabled".  Note that this state is
not guaranteed to be accurate in case of intervening modifications of
the corresponding chicken bit directly via cpuctl(4) (this includes the
cpucontrol(8) utility).  Resetting the desired policy through
'machdep.mitigations.zenbleed.enable' (possibly to its current value)
will reset the hardware state and ensure that the reported state is
again coherent with it.

Reviewed by:	kib
Sponsored by:   The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41817

(cherry picked from commit ebaea1bcd2eb0aa90937637ed305184b6fedc69b)
2023-10-10 09:34:31 -04:00
Dmitry Chagin
78d34c77f4 linux(4): Deduplicate SystemV IPC defines from amd64/linux
MFC after:		1 week

(cherry picked from commit 4fe779900b5d9359969426d44679d28d3178604e)
2023-10-10 12:06:28 +03:00
Dmitry Chagin
ce693de706 linux(4): Deorbit linux_nosys
Differential Revision:	https://reviews.freebsd.org/D41901
MFC after:		1 week

(cherry picked from commit 199e397e9bf1076ae905e2742ef8e294870f5b27)
2023-10-10 08:12:12 +03:00
Dmitry Chagin
a4b328aa41 linux(4): Regen for linux_nosys change
MFC after:		1 week

(cherry picked from commit 99abee8b7be2d19be583b942b470f7af11d32ddc)
2023-10-10 08:12:12 +03:00
Dmitry Chagin
ea54d65b34 linux(4): Deorbit linux_nosys from syscalls.master
Differential Revision:	https://reviews.freebsd.org/D41902
MFC after:		1 week

(cherry picked from commit 8e523be5a5a2cb9660021d2de5732ee7257b2788)
2023-10-10 08:12:12 +03:00
Konstantin Belousov
9a077205ca linuxolator: fix nosys() to not send SIGSYS
(cherry picked from commit 7acc4240ce00af540093b47ad00be0508310b515)
2023-10-09 06:24:31 +03:00
Konstantin Belousov
45ebb15ab1 sysentvec: add SV_SIGSYS flag
(cherry picked from commit b82b4ae752501469053979393e33bbfa74fbc9d2)
2023-10-09 06:24:31 +03:00
Konstantin Belousov
e0f1021386 syscalls: fix missing SIGSYS for several ENOSYS errors
(cherry picked from commit 39024a89146902ca9aba250130b828ad9aced99d)
2023-10-09 06:24:31 +03:00
Konstantin Belousov
6c19376f44 amd64 cpu_fetch_syscall_args_fallback(): fix whitespace
(cherry picked from commit 6b3bb233cd0c3eeeb70e388a62b142b4f22b62b2)
2023-10-09 06:24:31 +03:00