Commit graph

8720 commits

Author SHA1 Message Date
Dmitry Chagin
6fddab804a amd64: Reload CPU ext features after resume or cr4 changes
Reviewed by:		kib
Differential revision:	https://reviews.freebsd.org/D35555
MFC after:		2 weeks

(cherry picked from commit 050f5a8405)
2022-07-13 14:48:49 +03:00
Dmitry Chagin
e20c669d21 linux(4): To reuse MD linux.h hide kernel dependencies unde _KERNEL constraint
MFC after:		2 weeks

(cherry picked from commit d416ee86c7)
2022-07-06 14:02:15 +03:00
Alexander Motin
15183f36e5 amd64: Stop using REP MOVSB for backward memmove()s.
Enhanced REP MOVSB feature of CPUs starting from Ivy Bridge makes
REP MOVSB the fastest way to copy memory in most of cases. However
Intel Optimization Reference Manual says: "setting the DF to force
REP MOVSB to copy bytes from high towards low addresses will expe-
rience significant performance degradation". Measurements on Intel
Cascade Lake and Alder Lake, same as on AMD Zen3 show that it can
drop throughput to as low as 2.5-3.5GB/s, comparing to ~10-30GB/s
of REP MOVSQ or hand-rolled loop, used for non-ERMS CPUs.

This patch keeps ERMS use for forward ordered memory copies, but
removes it for backward overlapped moves where it does not work.

Reviewed by:	mjg
MFC after:	2 weeks

(cherry picked from commit 6210ac95a1)
2022-06-29 21:15:49 -04:00
Mark Johnston
f1400b2ecc pmap: Keep PTI page table pages busy
PTI page table pages are allocated from a VM object, so must be
exclusively busied when they are freed, e.g., when a thread loses a race
in pmap_pti_pde().  Simply keep PTPs busy at all times, as was done for
some other kernel allocators in commit
e9ceb9dd11.

Also remove some redundant assertions on "ref_count":
vm_page_unwire_noq() already asserts that the page's reference count is
greater than zero.

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

(cherry picked from commit c6d092b510)
2022-06-29 10:13:57 -04:00
Mitchell Horne
5a96b88f05 kerneldump: remove physical from dump routines
It is unused, especially now that the underlying d_dumper methods do not
accept the argument.

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

(cherry picked from commit db71383b88)
2022-06-27 16:32:06 -03:00
Vitaliy Gusev
bb52489444 vmm: move bumping VMEXIT_USERSPACE stat to the right place
Statistic for "number of vm exits handled in userspace" should be
increased in vm_run() instead of vmx_run() because in some cases
vm_run() doesn't exit to userspace and keeps entering the guest.

Also svm_run's implementation even wrongly misses that stat.

Reviewed by:	markj

(cherry picked from commit e7d34aeda4)
2022-06-24 10:40:48 -04:00
Corvin Köhne
f195c503ad vmm: add tunable to trap WBINVD
x86 is cache coherent. However, there are special cases where cache
coherency isn't ensured (e.g. when switching the caching mode). In these
cases, WBINVD can be used. WBINVD writes all cache lines back into main
memory and invalidates the whole cache.

Due to the invalidation of the whole cache, WBINVD is a very heavy
instruction and degrades the performance on all cores. So, we should
minimize the use of WBINVD as much as possible.

In a virtual environment, the WBINVD call is mostly useless. The guest
isn't able to break cache coherency because he can't switch the physical
cache mode. When using pci passthrough WBINVD might be useful.

Nevertheless, trapping and ignoring WBINVD is an unsafe operation. For
that reason, we implement it as tunable.

Reviewed by:	jhb
Sponsored by:	Beckhoff Automation GmbH & Co. KG
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D35253

(cherry picked from commit 3ba952e1a2)
2022-06-20 17:05:36 +02:00
Dmitry Chagin
d37548e010 linux(4): Properly restore the thread signal mask after signal delivery on i386
Replace sigframe sf_extramask by native sigset_t and use it to
store/restore the thread signal mask without conversion to/from
Linux signal mask.

Pointy hat to:		dchagin
MFC after:		2 weeks

(cherry picked from commit 4a6c2d075d)
2022-06-17 22:35:40 +03:00
Dmitry Chagin
c272720e2a linux(4): Properly build argument list for the signal handler
Provide arguments 2 and 3 if signal handler installed with SA_SIGINFO.

MFC after:		2 weeks

(cherry picked from commit 109fd18ad9)
2022-06-17 22:35:38 +03:00
Dmitry Chagin
fa6d9e24f4 linux(4): Microoptimize rt_sendsig(), convert signal mask once
On amd64 Linux saves the thread signal mask in both contexts, in the machine
dependent and in the machine independent. Both contexts are user accessible.
Convert the mask once, then copy it.

MFC after:		2 weeks

(cherry picked from commit c30a767c6f)
2022-06-17 22:35:38 +03:00
Dmitry Chagin
0f23fc29f9 linux(4): Avoid direct manipulation of td_sigmask
Use kern_sigprocmask() instead of direct manipulation of td_sigmask
to reschedule newly blocked signals.

MFC after:		2 weeks

(cherry picked from commit 2ab9b59faa)
2022-06-17 22:35:37 +03:00
Dmitry Chagin
601c19df36 linux(4): Reduce duplication between MD parts of the Linuxulator
Move sigprocmask actions defines under compat/linux,
they are identical across all Linux architectures.

MFC after:		2 weeks

(cherry picked from commit 2ca34847e7)
2022-06-17 22:35:37 +03:00
Dmitry Chagin
6bee81f9c6 linux(4): Handle 64-bit SO_TIMESTAMP for 32-bit binaries
To solve y2k38 problem in the recvmsg syscall the new SO_TIMESTAMP
constant were added on v5.1 Linux kernel. So, old 32-bit binaries
that knows only 32-bit time_t uses the old value of the constant,
and binaries that knows 64-bit time_t uses the new constant.

To determine what size of time_t type is expected by the user-space,
store requested value (SO_TIMESTAMP) in the process emuldata structure.

MFC after:		2 weeks

(cherry picked from commit 0e26e54bdf)
2022-06-17 22:35:34 +03:00
Dmitry Chagin
959d0bdc24 linux(4): Deduplicate execve
As linux_execve is common across archs, except amd64 32-bit Linuxulator,
move it under compat/linux.

Noted by:               andrew@
MFC after:              2 weeks

(cherry picked from commit 26700ac0c4)
2022-06-17 22:35:30 +03:00
Dmitry Chagin
464d2fec88 linux(4): Fix execve() on amd64/linux32 after a125ed50
MFC after:		2 weeks

(cherry picked from commit 53726a1f1e)
2022-06-17 22:35:28 +03:00
Dmitry Chagin
06f6414a64 linux(4): Deduplicate bsd_to_linux_trapcode()
As bsd_to_linux_trapcode() is common for x86 Linuxulators,
move it under x86/linux.

MFC after:		2 weeks

(cherry picked from commit 9016ec056a)
2022-06-17 22:35:28 +03:00
Dmitry Chagin
f327f595cb linux(4): Deduplicate translate_traps()
As translate_traps() is common for x86 Linuxulators,
move it under x86/linux.

MFC after:		2 weeks

(cherry picked from commit 2434137f69)
2022-06-17 22:35:28 +03:00
Dmitry Chagin
3cf95e49cb Retire sv_transtrap
Call translate_traps directly from sendsig().

MFC after:		2 weeks

(cherry picked from commit eca368ecb6)
2022-06-17 22:35:27 +03:00
Dmitry Chagin
68384ee5e4 linux(4): Retire handmade DWARF annotations from signal trampolines
The Linux exports __kernel_sigreturn and __kernel_rt_sigreturn from the
vdso. Modern glibc's sigaction sets the sa_restorer field of sigaction
to the corresponding vdso __sigreturn, and sets the SA_RESTORER.
Our signal trampolines uses the FreeBSD-way to call a signal handler,
so does not use the sigaction's sa_restorer.

However, as glibc's runtime linker depends on the existment of the vdso
__sigreturn symbols, for all Linuxulators was added separate trampolines
named __sigcode with DWARF anotations and left separate __sigreturn
methods, which are exported.

MFC after:              2 weeks

(cherry picked from commit 8f9635dc99)
2022-06-17 22:35:21 +03:00
Dmitry Chagin
c2704d3780 linux(4): Better naming for ucontext field of struct rt_sigframe
To reduce sendsig code difference and to avoid confusing me,
rename sf_sc to sf_uc to match the content.

MFC after:		2 weeks

(cherry picked from commit 6e826d27c3)
2022-06-17 22:35:21 +03:00
Dmitry Chagin
43dbc72cc5 linux(4): Rework the definition of struct siginfo to match Linux actual one
Rework the defintion of struct siginfo so that the array padding
struct siginfo to SI_MAX_SIZE can be placed in a union along side of the
rest of the struct siginfo members.  The result is that we no longer need
the __ARCH_SI_PREAMBLE_SIZE or SI_PAD_SIZE definitions.

Move struct siginfo definition under /compat/linux to reduce MD part.
To avoid headers polution include linux_siginfo.h in the MD linux.h

MFC after:		2 weeks

(cherry picked from commit af557e649c)
2022-06-17 22:35:20 +03:00
Dmitry Chagin
3f3bfb8266 linux(4): Move sigframe definitions to separate headers
The signal trampoine-related definitions are used only in the MD part
of code, wherefore moved from everywhere used linux.h to separate MD
headers.

MFC after:		2 weeks

(cherry picked from commit 21f2461741)
2022-06-17 22:35:20 +03:00
Dmitry Chagin
0fae97fd1c linux(4): Cleanup signal trampolines
This is the first stage of a signal trampolines refactoring.

From trampolines retired emulation of the 'call' instruction, which is
replaced by direct call of a signal handler. The signal handler address
is in the register.

The previous trampoline implemenatation used semi-Linux-way to call
a signal handler via the 'jmp' instruction. Wherefore the trampoline
emulated a 'call' instruction to into the stack the return address for
signal handler's 'ret' instruction.  Wherefore handmade DWARD annotations
was used.

While here rephrased and removed excessive comments.

MFC after:		2 weeks

(cherry picked from commit ba279bcd6d)
2022-06-17 22:35:19 +03:00
Dmitry Chagin
4be4063cef linux(4): Retire unneeded initialization
Both uc_flags and uc_link are zeroed above. On amd64 and i386 the
uc_link field is not used at all. The UC_FP_XSTATE bit should be set
in the uc_flags if OS xsave knob is turned on (and xsave is implemented).

MFC after:		2 weeks

(cherry picked from commit 0b5d5dc376)
2022-06-17 22:35:19 +03:00
Dmitry Chagin
77158a5b2b linux(4): Regen for prctl fix.
MFC after:              2 weeks

(cherry picked from commit 7b76c79b0b)
2022-06-17 22:35:11 +03:00
Dmitry Chagin
c8a5bcdb11 linux(4): Fix 039e98e6.
The patch was about an year in my local queue and I still screwed up...

MFC after:		2 weeks

(cherry picked from commit bfae7fbaa2)
2022-06-17 22:35:07 +03:00
Dmitry Chagin
d9c17939f0 linux(4): Return native error from futex_atomic_op to avoid conversion by the caller.
MFC after:		2 weeks

(cherry picked from commit 07d108932a)
2022-06-17 22:35:06 +03:00
Dmitry Chagin
9e7d26a0ca linux(4): Regen for prctl syscall.
MFC after:              2 weeks

(cherry picked from commit e768576718)
2022-06-17 22:35:05 +03:00
Dmitry Chagin
b54dadc226 linux(4): Change prctl syscall definition to match Linux actual one.
Otherwise argX conversion leads to an unexpected behaviour.

MFC after:		2 weeks

(cherry picked from commit 039e98e60c)
2022-06-17 22:35:01 +03:00
Dmitry Chagin
e7a07ad1db linux(4): Implement vdso getcpu for x86.
This is modeled after f2395455 (by kib@).

MFC after:		2 weeks

(cherry picked from commit 5a6a4fb284)
2022-06-17 22:35:00 +03:00
Dmitry Chagin
f360bdf68d linux(4): Refactor vdso_gettc_x86 includes.
Factor out includes from common vdso_gettc_x86 file to the corresponding
MD files.

MFC after:		2 weeks

(cherry picked from commit 332eca05b5)
2022-06-17 22:34:59 +03:00
Dmitry Chagin
fe35736d0b linux(4): Regen for ppoll_time64 syscall.
MFC after:              2 weeks

(cherry picked from commit 61f45f6733)
2022-06-17 22:34:58 +03:00
Dmitry Chagin
9d88adb476 linux(4): Fix ppoll_time64 syscall definition.
Fixed my typo in ed61e0ce1d. Here tsp is a pointer to the 64-bit timespec.

MFC after:		2 weeks

(cherry picked from commit 94f5f150ef)
2022-06-17 22:34:54 +03:00
Dmitry Chagin
9fd86dde83 linux(4): Implement semtimedop syscalls.
On i386 are two semtimedop. The old one is called via multiplexor and
uses 32-bit timespec, and new semtimedop_tim64, which is uses 64-bit
timespec.

MFC after:		2 weeks

(cherry picked from commit 3245a2ecea)
2022-06-17 22:34:53 +03:00
Dmitry Chagin
639c685d25 linux(4): Regen for semtimedop syscalls.
MFC after:              2 weeks

(cherry picked from commit 430460d717)
2022-06-17 22:34:53 +03:00
Dmitry Chagin
6fe321e3ac linux(4): Change semtimedop syscall definition to match Linux actual one.
MFC after:		2 weeks

(cherry picked from commit f19c4e2341)
2022-06-17 22:34:47 +03:00
Dmitry Chagin
d5316587f0 linux(4): Retire linux_semop implementation.
In i386 Linux semop called via ipc() multiplexor, so use kern_semop
directly from multiplexor.

MFC after:		2 weeks

(cherry picked from commit f48a68874b)
2022-06-17 22:34:47 +03:00
Dmitry Chagin
2f5e4f652a linux(4): Regen for semop syscall.
MFC after:              2 weeks

(cherry picked from commit cd875998dc)
2022-06-17 22:34:47 +03:00
Dmitry Chagin
219681b57b linux(4): Call semop directly.
As the Linux semop syscall is not defined in i386, and as it is equal
to the native semop syscall, call it directly.
Fix semop definition to match Linux actual one - nsops is size_t type.

MFC after:		2 weeks

(cherry picked from commit f686092664)
2022-06-17 22:34:43 +03:00
Dmitry Chagin
3f8eb6f28b linux(4): Implement recvmmsg_time64 syscall.
MFC after:		2 weeks

(cherry picked from commit 1744f14e26)
2022-06-17 22:34:42 +03:00
Dmitry Chagin
3f3b7fb182 linux(4): Regen for recvmmsg_time64 syscall.
MFC after:      2 weeks

(cherry picked from commit 79695e9585)
2022-06-17 22:34:42 +03:00
Dmitry Chagin
2ea4eb7484 linux(4): Change recvmmsg_time64 syscall definition to match Linux actual one.
MFC after:		2 weeks

(cherry picked from commit 17ccda0039)
2022-06-17 22:34:37 +03:00
Dmitry Chagin
d32db5360b linux(4): Implement timerfd_gettime64 syscall.
MFC after:		2 weeks

(cherry picked from commit ce9f8d6ab0)
2022-06-17 22:34:37 +03:00
Dmitry Chagin
fd2a538abf linux(4): Regen for timerfd_gettime64 syscall.
MFC after:      2 weeks

(cherry picked from commit ac80ae9313)
2022-06-17 22:34:36 +03:00
Dmitry Chagin
487ac6631f linux(4): Change timerfd_gettime64 syscall definition to match Linux actual one.
MFC after:		2 weeks

(cherry picked from commit 16aefe5ba3)
2022-06-17 22:34:32 +03:00
Dmitry Chagin
eea4b5db71 linux(4): Implement timerfd_settime64 syscall.
MFC after:		2weeks

(cherry picked from commit b1f0b08d93)
2022-06-17 22:34:31 +03:00
Dmitry Chagin
e24e366054 linux(4): Regen for timerfd_settime64 syscall.
MFC after:      2 weeks

(cherry picked from commit f4228fbb4e)
2022-06-17 22:34:31 +03:00
Dmitry Chagin
82f7b817cd linux(4): Change timerfd_settime64 syscall definition to match Linux actual one.
MFC after:		2 weeks

(cherry picked from commit 8545bcff31)
2022-06-17 22:34:26 +03:00
Dmitry Chagin
ad5e9b9867 linux(4): Implement timer_settime64 syscall.
MFC after:		2 weeks

(cherry picked from commit a1fd2911dd)
2022-06-17 22:34:26 +03:00
Dmitry Chagin
62787d1535 linux(4): Regen for timer_settime64 syscall.
MFC after:      2 weeks

(cherry picked from commit 9038a0b74c)
2022-06-17 22:34:26 +03:00