Commit graph

289759 commits

Author SHA1 Message Date
Warner Losh e54bb0ad80 loader: return errors from writing ZFS labels
vdev_write_bootenv_impl can only return success. Instead, return the
last error.  This will make any write errors more visible. The old code
masked kboot's inability to write bootenv.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D44018
2024-02-22 09:31:56 -07:00
Warner Losh b3e76e3d9e kboot: Implement write support for hostdisk
Don't assume that strategy is only called for read. Check the passed
flag for F_READ or F_WRITE and fail if it is neither. Open the disks for
writing and call host_read/host_write depending on that flag.

Sponsored by:		Netflix
Reviewed by:		kevans, gallatin
Differential Revision:	https://reviews.freebsd.org/D44016
2024-02-22 09:31:55 -07:00
Andrew Turner e68136d363 arm64: Tell userspace when BTI is supported
To allow userspace to decide when to try enabling BTI report if it's
available via the ID register and hwcaps.

Sponsored by:	Arm Ltd
2024-02-22 16:27:47 +00:00
Andrew Turner 670af174e2 arm64: Enable BTI in the kernel ELF loader
Enable BTI in binaries loaded by the kernel. When the ELF file contains
the needed note indicating BTI is supported set the guarded page flag
for all segments.

Reviewed by:	markj
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42441
2024-02-22 16:27:47 +00:00
Andrew Turner c4e4a7596b Add a BTI sysarch
This is used to enable the guard page when an elf binary is built with
BTI instructions.

Reviewed by:	markj
Sponsored by:	Arm Ltd
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D39453
2024-02-22 16:27:47 +00:00
Andrew Turner d3eae160b2 arm64: Add BTI support to pmap
Add a rangeset to the arm64 pmap to describe which address space needs
the Branch Target Identification (BTI) Guard Page flag set in the page
table.

On hardware that supports BTI the Guard Page flag tells the hardware
to raise an exception if the target of a BR* and BLR* instruction is
not an appropriate landing pad instruction.

To support this in userspace we need to know which address space
should be guarded. For this add a rangeset to the arm64 pmap when the
hardware supports BTI. The kernel can then use pmap_bti_set and
pmap_bti_clear mark and unmark which address space is guarded.

Sponsored by:	Arm Ltd
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D42328
2024-02-22 16:27:47 +00:00
Gordon Bergling a53204c227 sk(4): Fix a typo in a source code comment
- /integeated/integrated/
- s/extented/extended/

Obtained from:	NetBSD
MFC after:	3 days
2024-02-22 17:16:49 +01:00
Gordon Bergling 5a476e64b5 uath(4): Fix a typo in a source code comment
- s/parmeter/parameter/

MFC after:	3 days
2024-02-22 16:55:51 +01:00
Gordon Bergling 5e89e34f84 random(4): Fix a typo in a source code comment
- s/parmeter/parameter/

MFC after:	3 days
2024-02-22 16:54:50 +01:00
Roger Pau Monné f62d90e5e9 x86/xen: use correct printf specifier.
Use %p instead of wrongly casting to uintptr_t and printing with %lx.

Reported by: bapt
Fixes: 9a687d1fe3 ('x86/xen: introduce a Xen early init function')
Sponsored by: Cloud Software Group
2024-02-22 15:32:36 +01:00
Gordon Bergling 059fd69e74 umcs(4): Fix two typos in source code comments
- s/frequences/frequencies/

MFC after:	3 days
2024-02-22 14:14:08 +01:00
Roger Pau Monné 8f5406c77f x86/xen: implement early init hook
Unify the HVM and PVH early setup, byt making both rely on the hypervisor
initialization hook part of identify_hypervisor().

The current initialization takes care of the hypercall page, the sahred info
page and does any fixup necessary to metadata video console information if
FreeBSD is booted as the initial domain (so the video console is handed from
Xen into FreeBSD).

Note this has the nice side effect of also allowing to use the Xen console on
HVM guests, which allows to get rid of the QEMU emulated uart and still get
a nice text console.

Sponsored by: Cloud Software Group
Reviewed by: markj
Differential revision: https://reviews.freebsd.org/D43764
2024-02-22 11:08:05 +01:00
Roger Pau Monné 4401b06851 x86/cpu: introduce an optional hook for early hypervisor initialization
Hypervisor detection is done very early on x86, and so can be used to also do
some very early hypervisor related initialization.  Such initialization is
required when running as a Xen PVH guest, as for example the PIT needs to be
replaced with an hypervisor based timecounter.

Introduce an optional hook that gets called as part of the early hypervisor
detection.

No functional change intended.

Sponsored by: Cloud Software Group
Reviewed by: markj kib
Differential revision: https://reviews.freebsd.org/D43763
2024-02-22 11:08:05 +01:00
Roger Pau Monné f0cf86c075 x86/xen: replace xen_cpuid_base with hv_base
Where possible, replace the usage of xen_cpuid_base for hv_base in preparation
for removing xen_cpuid_base.

No functional change intended.

Sponsored by: Cloud Software Group
Reviewed by: markj
Differential revision: https://reviews.freebsd.org/D43935
2024-02-22 11:08:05 +01:00
Roger Pau Monné 027b66d64b x86/xen: do video console fixup as part of early initialization
When FreeBSD is running as dom0 the video console metadata provided by the
bootloader might not be accurate, as Xen has very likely taken over the console
and possibly changed the mode.

Adjust the video console information in the kernel metadata as part of early
Xen initialization.

Sponsored by: Cloud Software Group
Reviewed by: imp
Differential revision: https://reviews.freebsd.org/D43934
2024-02-22 11:08:05 +01:00
Roger Pau Monné 5d62aba742 x86/xen: move shared page setup to early init handler
As done with the hypercall page, move the setup fo the shared info page into
the newly introduced helper, which the aim of having a single helper and call
site used by both HVM and PV in order to setup the basic Xen environment.

Sponsored by: Cloud Software Group
Reviewed by: markj
Differential revision: https://reviews.freebsd.org/D43933
2024-02-22 11:08:05 +01:00
Roger Pau Monné 9a687d1fe3 x86/xen: introduce a Xen early init function
Start by moving the hyeprcall setup to such function.

The aim is to have a function that does all the required Xen early
initialization for both HVM and PVH, instead of having it scattered across
different paths.

Sponsored by: Cloud Software Group
Reviewed by: markj
Differential revision: https://reviews.freebsd.org/D43932
2024-02-22 11:08:04 +01:00
Roger Pau Monné 848e2719af x86/xen: remove parameter from fixup_console()
And instead fetch the metadata inside of the function.

This is done in preparation for changing the call site of fixup_console(),
which will no longer have the kernel metedata pointer in context.

No functional change intended.

Sponsored by: Cloud Software Group
Reviewed by: markj
Differential revision: https://reviews.freebsd.org/D43931
2024-02-22 11:08:04 +01:00
Roger Pau Monné e283c994ab x86/xen: fill hypercall page with int3
Filling the hypercall page with nops is not helpful from a debugging point of
view, as for example attempting to execute an hypercall before the page is
initialized will result in the execution flow falling through into
xen_start32, making the mistake less obvious to spot.

Instead fill the page with int3 (0xcc) which will result in a #BP trap.

Sponsored by: Cloud Software Group
Reviewed by: markj
Differential revision: https://reviews.freebsd.org/D43930
2024-02-22 11:08:04 +01:00
Roger Pau Monné 6744fd8e75 x86/cpu: improve hypervisor detection
Some hypervisors can expose multiple signatures, for example Xen will expose
both the Xen and the HyperV signatures if Viridian extensions are enabled for
the guest.  Presence of multiple signatures is currently not handled by
FreeBSD, that will exit once a known signature is found in cpuid output.

Exposing the HyperV signature on hypervisors different than HyperV is not
uncommon, this is done so that such hypervisor can expose a (subset) of the
Viridian extensions to Windows guests for performance reasons.  Likely for
compatibility purposes the HyperV signature is always exposed on the first
leaf, and the Xen signature is exposed in the secondary leaf.

Fix the specific case of HyperV by not exiting from the scan if the HyperV
signature is found, and prefer a second signature if one is found.

Note that long term we might wish to convert vm_guest into a bitmap, so that it
can signal detection of multiple hypervisor interfaces.

Fixes: b0165dc453 ('x86/xen: fix HVM guest hypercall page setup')
PR: 276421
Sponsored by: Cloud Software Group
Reviewed by: markj kib
Differential revision: https://reviews.freebsd.org/D43508
2024-02-22 11:08:04 +01:00
Roger Pau Monné 399386f190 x86/xen: introduce non-hypercall based emergency print
The current xc_printf() function uses an hypercall in order to send character
buffers to the hypervisor for it to print on the hypervisor console (if the
hypervisor is configured to print such messages).

This requires the hypercall page to be initialized, which is extra work and can
go wrong.

On x86 instead of using the console IO hypercall use the debug console IO port,
also called "port E9 hack".  This allows sending characters to Xen using an
outb instruction, without any initialization required.

Keep the previous hypervisor based implementation by using the weak attribute,
which allows each architecture to provide an alternate (arch-specific)
implementation.

Sponsored by: Cloud Software Group
Reviewed by: markj
Differential revision: https://reviews.freebsd.org/D43929
2024-02-22 11:08:03 +01:00
Roger Pau Monné 4ece79968e x86/xen: fix out of bounds access to the event channel masks on resume
When resuming from migration or suspension all regular event channels ports are
reset to the INVALID_EVTCHN value, and drivers should re-initialize them
according to the new value provided by the other end of the connection.

However, the driver would first attempt to unbind the event channel handler
before attempting to bind it using the newly provided port.  This unbind uses
the stale event channel port that has been set to INVALID_EVTCHN for some
operations (notably as a result of the handler removal the interrupt subsystem
ends up calling disable intr and source PIC hooks).

This was fine when INVALID_EVTCHN was 0, as then the operation would just
result in pointless setting of the 0 bit in the different event channel related
control arrays (evtchn_{pending,mask} for example).  However with the change to
define INVALID_EVTCHN as ~0 the write is no longer pointless, and we end up
triggering a page-fault, or corrupting random data that happens to be mapped at
the array position + ~0 bits.

In hindsight the change of INVALID_EVTCHN from 0 to ~0 was way more risky than
initially assessed, and I believe has end up resulting in more fragile code for
no real benefit.

Fix the disable intr and source wrappers to check whether the event channel is
valid before attempting to use it.

Also introduce some extra KASSERTs in several array accesses in order to avoid
out of bounds accesses if INVALID_EVTCHN ever reaches those functions.

Fixes: 1797ff9627 ('xen/intr: cleanup event channel number use')
MFC after: 1 week
Sponsored by: Cloud Software Group
Reviewed by: markj
Differential revision: https://reviews.freebsd.org/D43928
2024-02-22 11:08:03 +01:00
Warner Losh bad90cb4f6 nextboot: check unlink, but only warn on !ENOENT
Emulate rm -f from the nextboot.sh script: Report all errors, except
ENOENT. This problems show through, except the expected one when
nextboot.conf isn't there.

Sponsored by:		Netflix
Reviewed by:		rew
Differential Revision:	https://reviews.freebsd.org/D44013
2024-02-21 20:10:45 -07:00
Konstantin Belousov 99fa799a19 linux_pwd_onexec: do not abort image activation if emul path does not exist
Instead clear the altroot, if any.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D43833
2024-02-22 03:31:39 +02:00
Konstantin Belousov 452c5e9995 fdlopen(3): do not create a new object mapping if already loaded
This is expected behavior for both dlopen(3) and fdlopen(3).

PR:	277169
Reviewed by:	emaste
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D44019
2024-02-22 03:27:09 +02:00
Vladimir Kondratyev 9097284b98 bcm5974(4): Properly assign MT-slot on Apple Magic Trackpad
Assign multi-touch slot number based on internal evdev MT state and
reported tracking ID of contact rather than on sequentional number of
contact in report.

Sponsored by:	Serenity Cyber Security
Fixes:		ef8397c28e ("add Magic Trackpad 2 (USB only) support")
MFC after:	1 month
2024-02-21 23:31:39 +03:00
Vladimir Kondratyev 4f34598970 bcm5974(4): Respect HID_DEBUG option and fix debugging printf
Sponsored by:	Serenity Cyber Security
MFC after:	1 month
2024-02-21 23:31:39 +03:00
Vladimir Kondratyev c85e6a5c22 bcm5974(4): Report proper width and depth for Apple Magic Trackpads
The size of modern Apple Magic Trackpad is about 160x110mm

Sponsored by:	Serenity Cyber Security
MFC after:	1 month
2024-02-21 23:31:38 +03:00
Andrew Turner 47e073941f Import the kernel parts of bhyve/arm64
To support virtual machines on arm64 add the vmm code. This is based on
earlier work by Mihai Carabas and Alexandru Elisei at University
Politehnica of Bucharest, with further work by myself and Mark Johnston.

All AArch64 CPUs should work, however only the GICv3 interrupt
controller is supported. There is initial support to allow the GICv2
to be supported in the future. Only pure Armv8.0 virtualisation is
supported, the Virtualization Host Extensions are not currently used.

With a separate userspace patch and U-Boot port FreeBSD guests are able
to boot to multiuser mode, and the hypervisor can be tested with the
kvm unit tests. Linux partially boots, but hangs before entering
userspace. Other operating systems are untested.

Sponsored by:	Arm Ltd
Sponsored by:	Innovate UK
Sponsored by:	The FreeBSD Foundation
Sponsored by:	University Politehnica of Bucharest
Differential Revision:	https://reviews.freebsd.org/D37428
2024-02-21 18:55:32 +00:00
Andrew Turner 0f4071978e arm64: Add TF_LR, it will be used by bhyve asm 2024-02-21 18:55:32 +00:00
Andrew Turner b3bbec37ba arm64: Add a macro to find a VM fault address
Add a macro to find which bits from far_el2 are needed to be copied
to get the full intermediate physical address (IPA).

The hpfar_el2 register only contains a 4k aligned fault address. We
need to include the lower bits from far_el2 if we need the full
faulting IPA.
2024-02-21 18:55:32 +00:00
Andrew Turner 9c52f98c9f arm64: Add the TCR_EL2.PS mask 2024-02-21 18:55:32 +00:00
Andrew Turner 09ac9cf897 arm64: Add ISS_MSR_REG for ESR_ELx.ISS values
Add a macro to get the ESR_ELx ISS value when we trap accessing a
special register.
2024-02-21 18:55:32 +00:00
Bjoern A. Zeeb c81df1c112 iicbus/mux/pca954x: add support for PCA9546 I2C Switch
Add support for the 4 channel I2C switch from NXP by adding a new
description struct and the list entries.  Compared to x=[2345] which
require code to support the INT, for this one no further changes are
needed.

Tested on:	WHLE-LS1088A using a SPF+
MFC after:	1 week
Reviewed by:	imp
Differential Revision: https://reviews.freebsd.org/D44009
2024-02-21 16:46:15 +00:00
Andrew Turner 64963dd2f0 arm64: Add more spsr_el1 register values
Sponsored by:	Arm Ltd
2024-02-21 16:27:36 +00:00
Warner Losh b2822c40f6 loader/efi: Make gcc friendlier by move md_dev
Move the extern struct devsw md_dev out of the function. gcc is happier
with this arrangemnt often. However, we really should move it to a
header file, but that requires a bit of a rework of md support and
config.

Sponsored by:		Netflix
Reviewed by:		manu, tsoome
Differential Revision:	https://reviews.freebsd.org/D44008
2024-02-21 08:51:34 -07:00
Warner Losh 32568e5f24 loader: Retire CTASSERT
The project is moving away from CTASSERT in favor of
_Static_assert. Cleanup the few instances in the loader proactively.

Sponsored by:		Netflix
Reviewed by:		manu, tsoome
Differential Revision:	https://reviews.freebsd.org/D44006
2024-02-21 08:51:34 -07:00
Konstantin Belousov 2f4cbf459d libsys auxv.c: add fences needed to ensure that flag works
Noted by:	jrtc27
Sponsored by:	The FreeBSD Foundation
2024-02-21 16:18:10 +02:00
Andrew Turner 58df49801d arm64: Fix the has_hyp check
boot_el is now the CurrentEL.EL field value. Use the new macros to
implement the has_hyp() check.

Sponsored by:	Arm Ltd
2024-02-21 12:38:49 +00:00
Andrew Turner 353b6a5bcb arm64: Add in_vhe() to find if the kernel is in VHE
Add a function to support devices that may need to know if the kernel
has enabled the Armv8.1 Virtulization Host Extensions (FEAT_VHE).
Some devices, e.g. the generic timer, will need to know, e.g. use a
different interrupt.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43973
2024-02-21 11:26:29 +00:00
Andrew Turner 37563d39ef arm64: Use the new CurrentEL macros
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43972
2024-02-21 11:23:58 +00:00
Andrew Turner 5e7941b6c9 arm64: Add CurrentEL register definitions
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43971
2024-02-21 11:00:19 +00:00
Gordon Bergling ffea732c51 ls.1: Mention CLICOLOR environment variable
Mention CLICOLOR environment variable in the manual page.

PR:	276556
Submitted by:	bsdcode at disroot dot org
Reviewed by:	imp
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D43970
2024-02-21 11:54:58 +01:00
Warner Losh 07cba2ddcb reboot: Emulate nextboot -D better
It used to produce no output when the file couldn't be removed. Emulate
that better by unlinking and ignoring errors. It's used at the end of
reboot always, even when the file isn't going to be there.

Sponsored by: Netflix
Fixes: 2c47954811
2024-02-20 23:04:56 -07:00
Robert Wing c7d5cc6f5e Revert "rc.d/mountlate: discard output from nextboot"
This reverts commit 4cea0cbcc9.

Requested by:   imp
2024-02-20 21:04:15 -09:00
Robert Wing 4cea0cbcc9 rc.d/mountlate: discard output from nextboot
silent the warning seen at boot:

    Mounting late filesystems:.
    nextboot: unlink /boot/nextboot.conf: No such file or directory

    Sun Feb 18 23:31:52 AKST 2024

    FreeBSD/amd64 (main) (ttyv0)

    login:

Differential Revision:	https://reviews.freebsd.org/D43979
2024-02-20 20:50:43 -09:00
Eric Joyner 768329961d
ice_ddp: Update package to 1.3.36.0
This is intended to be used with the upcoming ice 1.39.13-k
driver update, but is still backwards compatible with
previous versions of the driver.

Signed-off-by: Eric Joyner <erj@FreeBSD.org>

MFC after:	3 days
Sponsored by:	Intel Corporation
2024-02-20 21:13:18 -08:00
Warner Losh eccde5f496 sys/kern: Remove a few sys/cdefs.h around some elf things
These sys/cdefs.h are no longer needed. Remove them in advance of
other work in this area.

Sponsored by:		Netflix
2024-02-20 20:40:19 -07:00
Warner Losh 65ee8f90b7 kboot: Fix zfs bootonce protocol
This wasn't updated when the other copies were updated. Make it
identical to efi code. We should likely refactor this (with userboot),
but they are all not quite identical.

Sponsored by:		Netflix
2024-02-20 20:36:00 -07:00
Warner Losh 9a5aaa97cb loader: For the mini-stdio we have for lua, #define them to something else
To make it easier to port lua and some of the lua modules, we have a
series of routines to implement the stdio routines, even though we don't
normally implement them in the boot loader. Add a comment to this effect.

Also, some tools, like sanitizers and static analysis tools, make
unwarranted assumptions about these, so #define them to a different name
so they stop.

Sponsored by:		Netflix
2024-02-20 20:31:50 -07:00