Commit graph

5077 commits

Author SHA1 Message Date
Ahmad Khalifa
ae0350f1c0 Add a new sysctl in order to diffrentiate UEFI architectures
With the new 32-bit UEFI loader, it's convenient to have a sysctl to
figure out how we booted. Can be accessed at machdep.efi_arch

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1098

(cherry picked from commit b538d4911004ca541507166b8ec9689d2e87d1aa)
(cherry picked from commit 0e8890a425bc778d323566c881e26bad7c54baf2)

Approved by:	so
Security:	FreeBSD-EN-25:12.efi
2025-08-08 11:49:17 +02:00
Konstantin Belousov
b9a015bd0a amd64: print limited EFIRT fault messages on first fault, not second
(cherry picked from commit 9227ecea6f4d4fc8a0ac9830a63eac6d79b5ce57)
2025-04-16 04:38:33 +03:00
Konstantin Belousov
ab259b19bd amd64: also limit printings of EFIRT page faults
PR:	285797

(cherry picked from commit 99332926f6fc6d1e4bb850a2b26744b948b14014)
2025-04-16 04:38:33 +03:00
Konstantin Belousov
e6a470ffcb efirt: add a tunable to disable printing faults during EFIRT calls
PR:	285797

(cherry picked from commit fd748c7d5b7aefbeda604403f203637b12ae89df)
2025-04-09 03:53:17 +03:00
John Baldwin
939bcd2c20 cpu_set_upcall / linux_clone_thread: Remove calls to cpu_thread_clean
This is intended to clean state of a thread at the end of its
lifecycle during wait(), not the beginning of its life cycle.

Reviewed by:	kib
Sponsored by:	AFRL, DARPA
Differential Revision:	https://reviews.freebsd.org/D48023

(cherry picked from commit 0e742cc77454d0872ac2f6e7fd755b6d0322b711)
2025-03-03 11:56:20 -05:00
Konstantin Belousov
e27089cda5 amd64: on any fault during call to EFI RT, restore execution and print fault details
(cherry picked from commit dd2b5443644505af51c95503898ab363e7d7c29d)
2025-01-01 12:30:20 +02:00
Konstantin Belousov
8094b35e57 amd64: extract code to print fault details from trap_fatal() into a new helper
(cherry picked from commit 5e3ab1894e1ef0520925038f8d4e4a451e841345)
2025-01-01 12:30:19 +02:00
Konstantin Belousov
7302cdd349 amd64: switch pmap_map_io_transient() to use pmap_kenter_attr()
(cherry picked from commit 6ec4ff70885d8048be8de9b9d690dd371e3d4a3e)
2024-12-02 03:44:55 +02:00
Konstantin Belousov
8e9f1e10c6 amd64 pmap: assert and explain why pmap_qremove() is safe WRT supermappings
(cherry picked from commit 2d6923790b16785ac691cedb23234067672fe1cc)
2024-12-02 03:44:55 +02:00
John Baldwin
f5641a80b7 x86: Remove invalid DEVMETHOD methods for leaf devices
None of these drivers are for bus devices, so bus_generic_* is not
appropriate.  Most of these were nops except that detach would
actually "succeed" (but not do any cleanup).

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

(cherry picked from commit df615735960370255d3acc4ac2a6f4fd297b7461)
2024-11-30 21:46:07 -05:00
John Baldwin
13e770f1f0 uio: Use switch statements when handling UIO_READ vs UIO_WRITE
This is mostly to reduce the diff with CheriBSD which adds additional
constants to enum uio_rw, but also matches the normal style used for
uio_segflg.

Reviewed by:	kib, emaste
Obtained from:	CheriBSD
Differential Revision:	https://reviews.freebsd.org/D45142

(cherry picked from commit 473c90ac04cec0abbb414978c53e9c259c9129e8)
2024-11-30 08:55:57 -05:00
John Baldwin
5ced86e1e2 amd64: Use bool for booleans in getmemsize
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D43693

(cherry picked from commit 70539d5da600a65d34c8d965ef2a9d475cbc9c4e)
2024-11-30 08:55:56 -05:00
Konstantin Belousov
5f5b47e374 amd64 efi rt: handle #BP
PR:	282860

(cherry picked from commit e6ec41fa86d88f80bd663e55455a6844619a9b24)
2024-11-28 14:53:17 +02:00
Konstantin Belousov
5ae76ff513 la57: explain how the trampoline works
(cherry picked from commit 6244b9dc4a03e87246bad1c94067dfe54ff4cdbc)
2024-10-23 21:04:58 +03:00
Konstantin Belousov
81c47bfc70 amd64/mp_machdep.c: style
(cherry picked from commit c2fe7156e992a295756206f59c282b9e971b8c91)
2024-10-05 10:08:53 +03:00
Konstantin Belousov
73f2b9f05a sysarch: improve checks for max user address
(cherry picked from commit 666303f5980896346c455bc949e49952220d02b7)
2024-09-23 16:03:07 +03:00
Konstantin Belousov
1ed40b4506 amd64: pml5 entries do not support PAT bits
(cherry picked from commit e134cd9580ad62e87c8e8678bdbc45936b11ee86)
2024-09-23 16:03:07 +03:00
Konstantin Belousov
6a0a7c6a05 amd64 pmap: do not set PG_G for usermode pmap pml5 kernel entry
(cherry picked from commit 4f82af24f1113a7df224daded227d4e9de582c0b)
2024-09-23 16:03:07 +03:00
Konstantin Belousov
ad6b949da5 pmap_bootstrap_la57(): reload IDT
(cherry picked from commit bbb00b1719f11c58efd5375aebc30ccd13bf0906)
2024-09-23 16:03:07 +03:00
Konstantin Belousov
e6fa60a77b la57: do not set global bit for PML5 entry
(cherry picked from commit 678bc2281c3727e920604545240d9115de3d1bd3)
2024-09-23 16:03:07 +03:00
Konstantin Belousov
2e6e9d1541 amd64 la57_trampoline: save registers in memory
(cherry picked from commit 280e50461a1f638088e7a0b9116976821c374b56)
2024-09-23 16:03:07 +03:00
Konstantin Belousov
371dcd4c35 amd64 la57_trampoline: lgdt descriptor is always 10 bytes in long mode
(cherry picked from commit 687b896f8ea58e67c3a0bfbd3af3041733e57dcf)
2024-09-23 16:03:06 +03:00
Konstantin Belousov
cdcaf2e073 amd64 la57_trampoline: turn off global pages and PCID before turning off paging
(cherry picked from commit 1be58e67eb24024bc808357771579d396679ecb0)
2024-09-23 16:03:06 +03:00
Konstantin Belousov
3f79c8c46f amd64 la57_trampoline: disable EFER.LME around setting CR4.LA57
(cherry picked from commit b7ea2b69ef666ee8cdc6dcc814d610df0a7f0999)
2024-09-23 16:03:06 +03:00
Konstantin Belousov
7a1723912e amd64 la57_trampoline: stop using %rdx to remember original %cr0
(cherry picked from commit 9a49c98bafbea2a896f72defe7d9f2b65a474c41)
2024-09-23 16:03:06 +03:00
Konstantin Belousov
8179f2a775 amd64 la57_trampoline: jump immediately after re-enabling paging
(cherry picked from commit 180c8ab079950acb15c6629ce293055ea0117b39)
2024-09-23 16:03:06 +03:00
Konstantin Belousov
1c34183035 amd64 pmap: flush whole TLB after LA57 trampoline is installed
(cherry picked from commit 787259bfe56478b9aa0699f2516d00722b9cc309)
2024-09-23 16:03:06 +03:00
Konstantin Belousov
0eec03f113 amd64 pmap: be more verbose around entering and leaving LA57 trampoline
(cherry picked from commit 2912c2fbd44072b7372c24dd34392c01f5104497)
2024-09-23 16:03:06 +03:00
Konstantin Belousov
81f829b301 amd64 sysarch(2): style
(cherry picked from commit 29a0a720c33fc70601ea85f813d982a99c3e7896)
2024-09-22 12:25:15 +03:00
Konstantin Belousov
43605618aa amd64: use INVLPGB for kernel pmap invalidations
(cherry picked from commit 47656cc1ef1cac307f24de88a4fe23a1389af44e)
2024-08-28 03:26:34 +03:00
Konstantin Belousov
23117748f2 amd64: add variables indicating INVLPGB works
(cherry picked from commit bc4ffcadf2681c954444e1853200dca3f5e65676)
2024-08-28 03:26:34 +03:00
Ed Maste
34f7ebd563 vt/sc: retire logic to select vt(4) by default for UEFI boot
We previously defaulted to using sc(4) with a special case to prefer
vt(4) when booted via UEFI.  As vt(4) is now always the default we can
simplify this.

Reviewed by:	imp, kevans
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D45356

(cherry picked from commit 9b1de7e4844d951a7d7335cbde75a86a2380e220)
2024-08-01 12:10:26 -04:00
Konstantin Belousov
010f09a7b1 amd64 pmap_allocpte_nosleep(): stop testing tautological condition
(cherry picked from commit 10a6ae0ddffb1de842a0ba6a6ca29786de6d3bfd)
2024-07-21 11:50:29 +03:00
Konstantin Belousov
8c405f08c0 amd64 pmap_allocpte_nosleep(): fix indent
(cherry picked from commit 616dd88a2e68c1243e4c8b57e883742937a61af0)
2024-07-21 11:50:29 +03:00
Souradeep Chakrabarti
840d8e0c30 amd64: add a func pointer to tlb shootdown function
Make the tlb shootdown function as a pointer. By default, it still
points to the system function smp_targeted_tlb_shootdown(). It allows
other implemenations to overwrite in the future.

Reviewed by:	kib
Tested by:	whu
Authored-by:    Souradeep Chakrabarti <schakrabarti@microsoft.com>
Co-Authored-by: Erni Sri Satya Vennela <ernis@microsoft.com>
MFC after:	1 week
Sponsored by:	Microsoft
Differential Revision:	https://reviews.freebsd.org/D45174

(cherry picked from commit bec000c9c1ef409989685bb03ff0532907befb4a)
2024-07-01 13:03:02 +00:00
Mitchell Horne
227b486de4 Adjust comments referencing vm_mem_init()
I cannot find a time where the function was not named this.

Reviewed by:	kib, markj
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D45383

(cherry picked from commit deab57178f0b06eab56d7811674176985a8ea98d)
2024-06-06 11:23:01 -03:00
Jake Freeland
fa92eaede4 ktrace: Record syscall violations with KTR_CAPFAIL
Report syscalls that are not allowed in capability mode with
CAPFAIL_SYSCALL.

Reviewed by:	markj
Approved by:	markj (mentor)
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D40678

(cherry picked from commit 05296a0ff615566d25c77c5e6619b08724d2eecb)
2024-05-11 18:57:44 -05: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
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
10896d25a5 amd64 gdt_segs: use designated initializers
(cherry picked from commit 1d6230b07ff29b4d3ae527dbc0fc3f9775a7542a)
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
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
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
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