Commit graph

9225 commits

Author SHA1 Message Date
Doug Moore
feeeb1c7a1 libkern: add ilog2 macro
The kernel source contains several definitions of an ilog2 function;
some are slower than necessary, and one of them is incorrect.
Elimininate them all and define an ilog2 macro in libkern to replace
them, in a way that is fast, correct for all argument types, and, in a
GENERIC kernel, includes a check for an invalid zero parameter.

Folks at Microsoft have verified that having a correct ilog2
definition for their MANA driver doesn't break it.

Reviewed by:	alc, markj, mhorne (older version), jhibbits (older version)
Differential Revision:	https://reviews.freebsd.org/D45170
Differential Revision:	https://reviews.freebsd.org/D45235

(cherry picked from commit b0056b31e90029553894d17c441cbb2c06d31412)
2025-02-18 10:44:00 +01:00
Konstantin Belousov
5ae76ff513 la57: explain how the trampoline works
(cherry picked from commit 6244b9dc4a03e87246bad1c94067dfe54ff4cdbc)
2024-10-23 21:04:58 +03:00
Kristof Provost
0d4081ed69 sys: add conf/std.debug, generic debugging options
The new sys/conf/std.debug contains the list of debugging options
enabled by default in -CURRENT, so they don't need to be listed
individually in every kernel config.

Introduce *-DEBUG variants of the major kernel configs.

(cherry picked and modified from commit 4f8f9d708e6a4143f3b178bfab10d0a9b75ba2fe)

Reviewed by:	markj, imp, olce (previous version)
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D46871
2024-10-09 10:44:35 +02:00
Pierre Pronchery
f8db6fb90e vmm: avoid potential KASSERT kernel panic in vm_handle_db
If the guest VM emits the exit code VM_EXITCODE_DB the kernel will
execute the function named vm_handle_db.

If the value of rsp is not page aligned and if rsp+sizeof(uint64_t)
spans across two pages, the function vm_copy_setup will need two structs
vm_copyinfo to prepare the copy operation.

For instance is rsp value is 0xFFC, two vm_copyinfo objects are needed:

* address=0xFFC, len=4
* address=0x1000, len=4

The vulnerability was addressed by commit 51fda658baa ("vmm: Properly
handle writes spanning across two pages in vm_handle_db").  Still,
replace the KASSERT with an error return as a more defensive approach.

Reported by:    Synacktiv
Reviewed by	markj, emaste
Security:       HYP-09
Sponsored by:   The Alpha-Omega Project
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D46133

(cherry picked from commit d19fa9c1b72bc52e51524abcc59ad844012ec365)
2024-10-06 11:01:24 -04:00
Bojan Novković
2dea4de8e0 vmm: Properly handle writes spanning across two pages in vm_handle_db
The vm_handle_db function is responsible for writing correct status
register values into memory when a guest VM is being single-stepped
using the RFLAGS.TF mechanism. However, it currently does not properly
handle an edge case where the resulting write spans across two pages.
This commit fixes this by making vm_handle_db use two vm_copy_info
structs.

Security:	HYP-09
Reviewed by:	markj

(cherry picked from commit 51fda658baa3f80c9778f3a9873fbf67df87119b)
2024-10-06 11:01:24 -04:00
Konstantin Belousov
81c47bfc70 amd64/mp_machdep.c: style
(cherry picked from commit c2fe7156e992a295756206f59c282b9e971b8c91)
2024-10-05 10:08:53 +03:00
Pierre Pronchery
a03acfa434 bhyve: initialize register value
In case of an error in a code pattern like

```
uint64_t val;
error = memread(vcpu, gpa, &val, 1, arg);
error = vie_update_register(vcpu, reg, val, size);
```

uninitialized stack data would be used.

Reported by:    Synacktiv
Reviewed by:	markj
Security:       HYP-21
Sponsored by:   The Alpha-Omega Project
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D46107

(cherry picked from commit 94693ec7c85363f9b0098247489cea3efdb183f9)
2024-09-30 08:11:15 -04: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
Konstantin Belousov
c3cd4db461 amd64: add convenience wrappers for INVLPGB and TBLSYNC
(cherry picked from commit 111c7fc2fe21356a637f89fa58c407958f05ad93)
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
Emmanuel Vadot
8e908fab6c conf: Add usbhid and hidbus to GENERIC* kernel configs
Include the new unified HID stack by default in generic.
This will allow us to migrate to the multi-stack hkbd and hms instead of
relying on the older ukbd and ums which only work with USB.
To test those drivers just add hw.usb.usbhid.enable=1 in loader.conf

Differential Revision:	https://reviews.freebsd.org/D45658
Reviewed by:	emaste, imp, wulf (all older version)
Sponsored by:	Beckhoff Automation GmbH & Co. KG

(cherry picked from commit 13d00a43cba4c35fcc9e0ab567baf530126a6348)

conf: hidmap is always needed for hms

So bring it in when hms is in the kernel config

Fixes:	13d00a43cba4 ("conf: Add usbhid and hidbus to GENERIC* kernel configs")
Sponsored by:	Beckhoff Automation GmbH & Co. KG

(cherry picked from commit 5ed91e788f0b97c9e6c544671ffef71fad7cad27)

conf: powerpc: Add evdev to some kernel configs

Fixes:	13d00a43cba4 ("conf: Add usbhid and hidbus to GENERIC* kernel configs")
Sponsored by:	Beckhoff Automation GmbH & Co. KG

(cherry picked from commit 43a62df0b464e60895084c7f9d9eddf70906fda3)
2024-07-29 18:36:42 +02:00
John Baldwin
74b9fc7adc amd64 GENERIC: Switch uart hints from "isa" to "acpi"
This causes these hints to be only used to wire device unit numbers
for serial ports enumerated by ACPI but will not create ISA device
nodes if ACPI doesn't enumerate them.  Note that IRQ hints are not
used for wiring so have been removed.

PR:		270707
Reported by:	aixdroix_OSS@protonmail.com, Michael Dexter
Reported by:	mfw_burn@pm.me, Hannes Hfauswedell <h2+fbsdports@fsfe.org>
Reported by:	Matthias Lanter <freebsd@lanter-it.ch>
Reported by:	William Bulley <web@umich.edu>
Reviewed by:	imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D45945

(cherry picked from commit 9cc06bf7aa2846c35483de567779bb8afc289f53)
2024-07-22 15:56:00 -04:00
John Baldwin
4efd13ffd6 amd64 GENERIC: Drop hints for fdc0 and ppc0
Modern x86 systems do not ship with ISA floppy disk controllers or LPT
ports.

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

(cherry picked from commit 480cc750a2a8f92d078803f15eecb1f8a084a1ea)
2024-07-22 15:55:58 -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
John Baldwin
eb1f270950 x86 NOTES: Move shared options from amd/i386 NOTES to x86 NOTES
While here, reorder some of the entries using headers more aligned
with sys/conf/NOTES.  Also add a pointer from the amd64/i386 NOTES
files to x86 NOTES.

The "extra" ACPI device drivers were only present in i386 NOTES
previously.

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

(cherry picked from commit 1f38677ba40b26b861e063e130117143c9342c5d)
2024-07-18 13:33:13 -04:00
John Baldwin
d1c97c1871 NOTES: Move ENABLE_ALART option to MI NOTES next to intpm device
This option is for this driver.

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

(cherry picked from commit 5ea0b89242dbc1e4d4bac16983291a7c3803f88e)
2024-07-18 13:33:03 -04:00
John Baldwin
883640ffd7 x86 NOTES: Move NKPT and PMAP_SHPGPERPROC options to VM OPTIONS section
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D44785

(cherry picked from commit b620daf63309f655546caa060ea79cb230e4c9bc)
2024-07-18 13:32:30 -04:00
John Baldwin
6563c2a328 x86 NOTES: Remove some obsolete comments
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D44784

(cherry picked from commit 717b22e18ca249dee0ec858c6571f68e00008290)
2024-07-18 13:31:59 -04:00
John Baldwin
c0e4d94873 NOTES: Move the VirtIO entries to the MI NOTES file
While here, add virtio_gpu

Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D44782

(cherry picked from commit 1f678b6ba215aad01a1610772c77af653a981601)
2024-07-18 13:30:41 -04:00
John Baldwin
97d1a0cde1 NOTES: Move safe(4) to the MI NOTES file
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D44780

(cherry picked from commit ff3569be6fe01839affdefa14f55cc03a1f4f9d0)
2024-07-18 13:20:58 -04:00
John Baldwin
c68dcc0781 NOTES: Move IEEE80211_DEBUG_REFCNT to the MI NOTES file
This option is not specific to amd64

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

(cherry picked from commit 9c3fd2c1c7b8887d2ffaf14c61b04c55657d68bf)
2024-07-18 13:20:50 -04:00
John Baldwin
9f756367a0 NOTES: Move NVMe entries to MI file
While here, adjust the sample setting for NVME_USE_NVD to use a
non-default setting as is typical in entries in NOTES.

Discussed with:	imp
Reviewed by:	manu
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44691

(cherry picked from commit 8f7105a20697d47060dbedc966cf085a64aeced6)
2024-07-18 13:20:12 -04:00
John Baldwin
422911ca58 NOTES: Move OFED options to MI NOTES
Disable in armv7 NOTES to match sys/modules/Makefile

Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44686

(cherry picked from commit 973d3a82096bc135f6c230e348e2f33c382096bc)
2024-07-18 13:06:06 -04:00
Konstantin Belousov
7a3d7aec41 pmap: move the smp_targeted_tlb_shutdown pointer stuff to amd64 pmap.h
Fixes:	bec000c9c1ef409989685bb03ff0532907befb4aESC
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 9c5d7e4a0c02bc45b61f565586da2abcc65d70fa)
2024-07-01 13:07:38 +00: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
Mark Johnston
3026c74b87 amd64/vmm: Make vmm.h more self-contained
CTASSERT is defined in kassert.h, so include that here.  No functional
change intended.

MFC after:	1 week

(cherry picked from commit aede0d3badd1be92b57deb14c494785ab61022d4)
2024-06-27 11:27:42 -04: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
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