Commit graph

9158 commits

Author SHA1 Message Date
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
Bojan Novković
ca79521be1 amd64: Add a leaf PTP when pmap_enter(psind=1) creates a wired mapping
This patch reverts the changes made in D19670 and fixes the original
issue by allocating and prepopulating a leaf page table page for wired
userspace 2M pages.

The original issue is an edge case that creates an unmapped, wired
region in userspace. Subsequent faults on this region can trigger wired
superpage creation, which leads to a panic in pmap_demote_pde_locked()
as the pmap does not create a leaf page table page for the wired
superpage. D19670 fixed this by disallowing preemptive creation of
wired superpage mappings, but that fix is currently interfering with an
ongoing effort of speeding up vm_map_wire for large, contiguous entries
(e.g. bhyve wiring guest memory).

Reviewed by:	alc, markj
Sponsored by:	Google, Inc. (GSoC 2023)
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D41132

(cherry picked from commit aa3bcaad51076ceb346fa0c64ab69a35e5241b20)
2023-10-02 08:55:49 -04:00
Dmitry Chagin
6f63d749fe linux(4): Regen
MFC after:		1 week

(cherry picked from commit 28035f675b8590a24fddb418083788609ef75cc8)
2023-10-02 08:44:53 +03:00
Dmitry Chagin
4d46ca6550 linux(4): Update syscalls.master to 6.5
MFC after:		1 week

(cherry picked from commit 0a16d3d14db67c89ee08f954c670ec4f447a7ab5)
2023-10-02 08:44:53 +03:00
Mark Johnston
fa1ffd9f4b amd64: Convert a cheap DIAGNOSTIC check to a KASSERT
MFC after:	1 week

(cherry picked from commit f7c733e4fe5d55fd78cd2b0c27483eeaff3f79a3)
2023-09-27 08:32:25 -04:00
Olivier Certner
d0c0dcf9db x86: Add defines for workaround bits in AMD's MSR "Decode Configuration"
They are a bit more informative than raw hexadecimal values.

While here, sort existing defines of bits for AMD MSRs to match the address
order.

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

(cherry picked from commit 125bbadf6084ac341673c9eb1979a740d3d5899a)
2023-09-25 09:45:06 -04:00
Dmitry Chagin
cba7b3b956 linux(4): Cleanup includes under amd64/linux32
No functional changes.

MFC after:		1 week

(cherry picked from commit ba90a31d08e413b82c1d1d4d697c2cdb32a13674)
2023-09-24 13:51:36 +03:00
Dmitry Chagin
41a4122b7b linux(4): Cleanup includes under amd64/linux
No functional changes.

MFC after:		1 week

(cherry picked from commit 68df2376e0e50cea0f8c3c04dc2d8a7b63515773)
2023-09-24 13:51:36 +03:00
Dmitry Chagin
a321b17b8e linux(4): Deduplicate mmap2
To help porting the Linux emulation layer to a new platforms start using
Linux names for conditional builds instead of architecture-specific ifdefs.

MFC after:		1 week

(cherry picked from commit 2a1cf1b6b55c8326bbe85d0fdf17b0f2fb9b34ce)
2023-09-12 10:48:56 +03:00
Dmitry Chagin
4d17239617 linux(4): Deduplicate mprotect, madvise
MFC after:		1 week

(cherry picked from commit 553b1a4e4eb426d2c29a033b284c13bfbab30334)
2023-09-12 10:48:39 +03:00
Glen Barber
29a16ce065 release: update stable/14 following branching from main
Approved by:	re (implicit)
Sponsored by:	GoFundMe https://www.gofundme.com/f/gjbbsd
Sponsored by:	PayPal https://paypal.me/gjbbsd
2023-08-24 19:07:33 -04:00
Konstantin Belousov
74ccb8ecf6 Add cpu_sync_core()
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D32360
2023-08-23 03:02:21 +03:00
Konstantin Belousov
8882b7852a add pmap_active_cpus()
For amd64, i386, arm, and riscv, i.e. all architectures except arm64,
the custom implementation is provided since we maintain the bitmask of
active CPUs anyway.

Arm64 uses somewhat naive iteration over CPUs and match current vmspace'
pmap with the argument. It is not guaranteed that vmspace->pmap is the
same as the active pmap, but the inaccuracy should be toleratable.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D32360
2023-08-23 03:02:21 +03:00
Dmitry Chagin
524c9accdc linux(4): Replace linux32_copyiniov by freebsd32_copyiniov
MFC after:		1 month
2023-08-20 10:36:32 +03:00
Dmitry Chagin
c987ff4d7b linux(4): Replace linux32_copyinuio by freebsd32_copyinuio
MFC after:		1 month
2023-08-20 10:36:32 +03:00
Dmitry Chagin
4e5f2eb0b6 Regen for readv syscall 2023-08-20 10:36:32 +03:00
Dmitry Chagin
5585afe642 linux(4): Prepare to retire linux32_copyinuio
MFC after:		1 month
2023-08-20 10:36:31 +03:00
Dmitry Chagin
4231b825ac linux(4): Add a dedicated writev syscall wrapper
Adding a writev syscall wrapper is needed due to Linux family of write
syscalls doesn't distinguish between in kernel blocking operations
and always returns EAGAIN while FreeBSD can return ENOBUFS.

MFC after:		1 month
2023-08-20 10:36:31 +03:00
Dmitry Chagin
1f9d71ee32 Regen for writev syscall 2023-08-20 10:36:31 +03:00
Dmitry Chagin
aad4b799f7 linux(4): Add a writev syscall wrapper
Adding a writev syscall wrapper is needed due to Linux family of write
syscalls doesn't distinguish between in kernel blocking operations
and always returns EAGAIN while FreeBSD can return ENOBUFS.

MFC after:		1 month
2023-08-20 10:36:30 +03:00
Dmitry Chagin
e58ff66464 linux(4): Add a write syscall wrapper
Adding a write syscall wrapper is needed due to Linux family of write
syscalls doesn't distinguish between in kernel blocking operations
and always returns EAGAIN while FreeBSD can return ENOBUFS.

MFC after:		1 month
2023-08-20 10:36:29 +03:00
Dmitry Chagin
89d270b28d Regen for write syscall 2023-08-20 10:36:29 +03:00
Dmitry Chagin
510f5c88f0 linux(4): Modify write syscall to match Linux
Adding a write syscall wrapper is needed due to Linux family of write
syscalls doesn't distinguish between in kernel blocking operations
and always returns EAGAIN while FreeBSD can return ENOBUFS.

MFC after:		1 month
2023-08-20 10:36:28 +03:00
Dmitry Chagin
3460fab5fc linux(4): Remove sys/cdefs.h inclusion where it's not needed due to 685dc743 2023-08-18 13:12:02 +03:00