Commit graph

8448 commits

Author SHA1 Message Date
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
5a84640fcf amd64 pti init: fix calculation of the kernel text start
(cherry picked from commit 34516d4ad1)
2021-08-03 12:52:37 +03:00
Konstantin Belousov
2c7315c09a amd64: do not touch low memory in AP startup unless we used legacy boot
(cherry picked from commit 2572376f7f)
2021-08-03 12:52:36 +03:00
Konstantin Belousov
17332276a6 amd64: do not touch low memory in AP startup unless we used legacy boot
(cherry picked from commit 48216088b1)
2021-08-03 12:52:36 +03:00
Konstantin Belousov
21049f0567 amd64: make efi_boot global
(cherry picked from commit 6a3821369f)
2021-08-03 12:52:36 +03:00
Konstantin Belousov
39f259b1d5 Do not call FreeBSD-ABI specific code for all ABIs
(cherry picked from commit 28a66fc3da)
2021-07-22 01:11:52 +03:00
Ka Ho Ng
fc661f1903 vmm: Fix AMD-vi using wrong rid range
The ACPI parsing code around rid range was wrong on assuming there is
only one pair of start/end device id range. Besides, ivhd_dev_parse()
never work as supposed. The start/end rid info was always zero.

Restructure the code to build dynamic-sized tables for each IOMMU softc
holding device entries. The device entries are enumerated to find a
suitable IOMMU unit. Operations on devices not governed (e.g. the IOMMU
unit itself) are no-op from now on. There are also a minor fix on wrong
%b formatting string usage.

Tested on my EPYC 7282.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	grehan
Differential Revision:	https://reviews.freebsd.org/D30827

(cherry picked from commit b5c74dfd64)
2021-07-21 23:06:35 +08:00
Konstantin Belousov
fec5a70e1f x86: use ANSI C definition style for trap_fatal
PR:	257062

(cherry picked from commit 55e63ed307)
2021-07-17 13:52:04 +03:00
Konstantin Belousov
4b52622de7 amd64 pmap: unexpand the NBPDR macro definition
(cherry picked from commit fdc71fa112)
2021-07-17 13:51:59 +03:00
Konstantin Belousov
dc5511d75d amd64 locore.S: trim .globl list from symbols gone for long time
(cherry picked from commit 9dc715230c)
2021-07-17 13:51:55 +03:00
Konstantin Belousov
48619df1d2 amd64 mpboot.S: fix typo in comment
(cherry picked from commit 71463a34ab)
2021-07-17 13:51:50 +03:00
Konstantin Belousov
0ecd3cde77 amd64 locore.S: add FF copyright for LA57 work
(cherry picked from commit 63664df720)
2021-07-17 13:51:45 +03:00
Helge Oldach
864b57281a MINIMAL: remove debugging and some loadable network modules
Remove deugging stuff, since it's arguably not needed in a minimal
setup. Also vlan, tuntap and gif since they can be loaded.

imp didn't include the part of the patch that removed xen guest support.
Xen guest is relatively small and has no way of being loaded.

Reviewed by:	imp
PR:		229564
MFC After:	3 days

(cherry picked from commit b21f19c9e0)
2021-07-16 12:28:44 -06:00
Ka Ho Ng
67d02e1301 vmm: Fix ivrs_drv device_printf usage
The original %b description string is wrong.

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

(cherry picked from commit 210e6aec4f)
2021-07-14 01:58:56 +08:00
Konstantin Belousov
99c12760d0 amd64: do not touch BIOS reset flag halfword, unless we boot through BIOS
(cherry picked from commit 33e1287b6a)
2021-06-30 07:42:13 +03:00
Mateusz Guzik
9aee734554 amd64: typo fix: memcmpy -> memcmp in a comment
Sponsored by:	Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 9a8e4527f0)
2021-06-26 16:27:06 +00:00
Konstantin Belousov
d16b938e73 amd64 efirt: initialize vm_pages backing EFI runtime memory
(cherry picked from commit 0247c33e89)
2021-06-24 05:20:41 +03:00
Konstantin Belousov
52d8029e93 Add quirks for Linux ABI signals handling
(cherry picked from commit 870e197d52)
2021-06-22 04:45:32 +03:00
Mark Johnston
4a77ce73ea amd64: Fix propagation of LDT updates
When a process has used sysarch(2) to specify descriptors for its
private LDT, upon rfork(RFMEM) descriptors are copied into the new child
process.  Any updates to the descriptors are thus reflected to all other
processes sharing the vmspace.  However, this is incorrect in the rather
obscure case where the child process was created before the LDT was
modified.  Fix this by only modifying other processes which already
share the LDT.

Reported by:	syzkaller
Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 70dd5eebc0)
2021-06-21 09:13:20 -04:00
Mark Johnston
85a55e0c5e vmm: Let guests enable SMEP/SMAP if the host supports it
Reviewed by:	kib, grehan, jhb
Tested by:	grehan (AMD)
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 4c599db71a)
2021-06-16 10:03:12 -04: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
Konstantin Belousov
dc107fe1f9 linuxolator: Add compat.linux.setid_allowed knob
PR:	21463

(cherry picked from commit 598f6fb49c)
2021-06-13 04:22:33 +03:00
Mark Johnston
cb5fe9aa9f amd64: Clear the local TSS when creating a new thread
Otherwise it is copied from the creating thread.  Then, if either thread
exits, the other is left with a dangling pointer, typically resulting in
a page fault upon the next context switch.

Reported by:	syzkaller
Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 8cd05b8833)
2021-06-08 09:33:59 -04:00
Mark Johnston
2a87d7c013 amd64: Relax the assertion added in commit 4a59cbc12
We only need to ensure that interrupts are disabled when handling a
fault from iret.  Otherwise it's possible to trigger the assertion
legitimately, e.g., by copying in from an invalid address.

Fixes:		4a59cbc12
Reported by:	pho
Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 6cda627556)
2021-06-06 21:02:38 -04:00
Mark Johnston
10e697949a amd64: Avoid enabling interrupts when handling kernel mode prot faults
When PTI is enabled, we may have been on the trampoline stack when iret
faults.  So, we have to switch back to the regular stack before
re-entering trap().

trap() has the somewhat strange behaviour of re-enabling interrupts when
handling certain kernel-mode execeptions.  In particular, it was doing
this for exceptions raised during execution of iret.  When switching
away from the trampoline stack, however, the thread must not be migrated
to a different CPU.  Fix the problem by simply leaving interrupts
disabled during the window.

Reported by:	syzbot+6cfa544fd86ad4647ffc@syzkaller.appspotmail.com
Reported by:	syzbot+cfdfc9e5a8f28f11a7f5@syzkaller.appspotmail.com
Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 4a59cbc125)
2021-06-06 21:02:27 -04:00
Konstantin Belousov
14bc67f1e7 x86: initialize initial FPU state earlier
PR:	255997

(cherry picked from commit c56de177d2)
2021-06-04 03:43:59 +03:00
Konstantin Belousov
876ffe2879 amd64/linux*: add required header to get the constant value
Otherwise asm silently interpret it as the external global symbol.

Reported by:	bz
Sponsored by:	The FreeBSD Foundation
Fixes:	91aae953cb

(cherry picked from commit a59f028537)
2021-05-26 15:18:54 -04:00
Konstantin Belousov
6bbde34ae6 amd64: clear PSL.AC in the right frame
If copyin family of routines fault, kernel does clear PSL.AC on the
fault entry, but the AC flag of the faulted frame is kept intact.  Since
onfault handler is effectively jump, AC survives until syscall exit.

Reported by:	m00nbsd, via Sony
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
admbugs:	975

(cherry picked from commit 91aae953cb)
2021-05-26 15:18:41 -04:00
Mark Johnston
f1119657d8 linux: Fix a mistake in commit fb58045145
The change to futex_andl_smap() should have ordered stac before the
load from a user address, otherwise it does not fix anything.

Fixes:	fb58045145 ("linux: Fix SMAP-enabled futex routines")
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 60cb98a1bd)
2021-05-24 10:05:43 -04:00
Mark Johnston
14cc132657 linux: Fix SMAP-enabled futex routines
Some of them were dereferencing the user pointer before disabling SMAP.

PR:		255591
Reviewed by:	kib
Tested by:	pitwuu@gmail.com
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit fb58045145)
2021-05-23 12:43:43 -04:00
Ed Maste
6cd1cb27a9 regen syscall files after 0bd5d81f1e 2021-05-19 20:32:47 -04:00
Konstantin Belousov
af861a369e amd64: invalidate TLB between page table update and access
(cherry picked from commit 21fc6a2a10)
2021-05-07 03:35:54 +03:00
Piotr Pawel Stefaniak
6ac7b0221f Balance parentheses in sysctl descriptions
(cherry picked from commit a212f56d10)
2021-05-05 13:04:58 +02:00
Konstantin Belousov
df6241fcef amd64: disable LA57 by default for now
(cherry picked from commit 72a42ec63b)
2021-05-03 04:27:22 +03:00
Konstantin Belousov
6c74b12295 amd64 linux64: use x86_clear_dbregs()
(cherry picked from commit 2f15884747)
2021-04-23 14:14:08 +03:00
Konstantin Belousov
f06f665430 x86: use x86_clear_dbregs() on fork
(cherry picked from commit 290b0d123a)
2021-04-23 14:14:08 +03:00
Konstantin Belousov
f6b3c49256 amd64: clear debug registers on execing 32bit native binary
(cherry picked from commit d50adfec9e)
2021-04-23 14:14:08 +03:00
Konstantin Belousov
0d51148255 amd64: clear debug registers on execing 32bit Linux binary
(cherry picked from commit 94172affa4)
2021-04-23 14:14:08 +03:00
Konstantin Belousov
88d6f049c1 x86: add x86_clear_dbregs() helper
(cherry picked from commit a8b75a57c9)
2021-04-23 14:14:08 +03: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
ea2f252e97 ddb: replace watchpoint set/clear functions
Use the new kdb variants. Print more specific error messages.

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

(cherry picked from commit 9d81dd5404)
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
Mitchell Horne
47301dfb9a x86: consolidate hw watchpoint logic into new file
This is a prerequisite to using these functions outside of ddb, but also
provides some cleanup and minor refactoring. This code is almost
entirely duplicated between the two implementations, the only
significant difference being the lack of dbreg synchronization on i386.

Cleanups are:
 - demote some internal functions to static
 - use the constant NDBREGS instead of a '4' literal
 - remove K&R definitions
 - some added comments

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

(cherry picked from commit c02c04f113)
2021-04-21 10:20:32 -03:00
Mark Johnston
f28241ca13 Remove more remnants of sio(4)
Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D29626

(cherry picked from commit 0f07c234ca)
2021-04-14 09:19:49 -04:00
Mateusz Guzik
9535440569 amd64: implement strlen in assembly, take 2
Tested with glibc test suite.

The C variant in libkern performs excessive branching to find the zero
byte instead of using the bsfq instruction. The same code patched to use
it is still slower than the routine implemented here as the compiler
keeps neglecting to perform certain optimizations (like using leaq).

On top of that the routine can be used as a starting point for copyinstr
which operates on words intead of bytes.

The previous attempt had an instance of swapped operands to andq when
dealing with fully aligned case, which had a side effect of breaking the
code for certain corner cases. Noted by jrtc27.

Sample results:

$(perl -e "print 'A' x 3"):
stock:  211198039
patched:338626619
asm:    465609618

$(perl -e "print 'A' x 100"):
stock:   83151997
patched: 98285919
asm:    120719888

Reviewed by:	jhb, kib
Differential Revision:	https://reviews.freebsd.org/D28779

(cherry picked from commit 5fa12fe0cd)
2021-04-10 13:53:46 +00:00
Ka Ho Ng
9d7eb557c1 AMD-vi: Mixed format IVHD block should replace fixed format IVHD block
This fixes double IVHD_SETUP_INTR calls on the same IOMMU device.

Sponsored by:	The FreeBSD Foundation
MFC with:	74ada297e8
Reported by:	Oleg Ginzburg <olevole@olevole.ru>
Reviewed by:	grehan
Approved by:	philip (mentor)
Differential Revision:	https://reviews.freebsd.org/D29521

(cherry picked from commit 03efa462b2)
2021-04-07 18:55:38 +08:00
Ka Ho Ng
1bbe0448e4 AMD-vi: Fix mismatched NULL checking in amdiommu teardown path
Sponsored by:	The FreeBSD Foundation
Approved by:	lwhsu (mentor)
MFC with:	74ada297e8

(cherry picked from commit cf76495e0a)
2021-04-07 18:55:38 +08:00
Ka Ho Ng
d7ffa208d9 AMD-vi: Fix IOMMU device interrupts being overridden
Currently, AMD-vi PCI-e passthrough will lead to the following lines in
dmesg:
"kernel: CPU0: local APIC error 0x40
ivhd0: Error: completion failed tail:0x720, head:0x0."

After some tracing, the problem is due to the interaction with
amdvi_alloc_intr_resources() and pci_driver_added(). In ivrs_drv, the
identification of AMD-vi IVHD is done by walking over the ACPI IVRS
table and ivhdX device_ts are added under the acpi bus, while there are
no driver handling the corresponding IOMMU PCI function. In
amdvi_alloc_intr_resources(), the MSI intr are allocated with the ivhdX
device_t instead of the IOMMU PCI function device_t. bus_setup_intr() is
called on ivhdX. the IOMMU pci function device_t is only used for
pci_enable_msi(). Since bus_setup_intr() is not called on IOMMU pci
function, the IOMMU PCI function device_t's dinfo->cfg.msi is never
updated to reflect the supposed msi_data and msi_addr. So the msi_data
and msi_addr stay in the value 0. When pci_driver_added() tried to loop
over the children of a pci bus, and do pci_cfg_restore() on each of
them, msi_addr and msi_data with value 0 will be written to the MSI
capability of the IOMMU pci function, thus explaining the errors in
dmesg.

This change includes an amdiommu driver which currently does attaching,
detaching and providing DEVMETHODs for setting up and tearing down
interrupt. The purpose of the driver is to prevent pci_driver_added()
from calling pci_cfg_restore() on the IOMMU PCI function device_t.
The introduction of the amdiommu driver handles allocation of an IRQ
resource within the IOMMU PCI function, so that the dinfo->cfg.msi is
populated.

This has been tested on EPYC Rome 7282 with Radeon 5700XT GPU.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	jhb
Approved by:	philip (mentor)
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D28984

(cherry picked from commit 74ada297e8)
2021-04-07 18:55:38 +08:00
Ka Ho Ng
c5345a05ce ivrs_drv: Fix IVHDs with duplicated BaseAddress
Reviewed by:	jhb
Approved by:	philip (mentor)
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D28945

(cherry picked from commit ede14736fd)
2021-04-07 18:55:38 +08:00
Konstantin Belousov
5524122ee3 x86: clear %db registers in new process
PR:	254661

(cherry picked from commit 8223717ce6)
2021-04-06 03:47:34 +03:00