Commit graph

624 commits

Author SHA1 Message Date
Elliott Mitchell
487788a69f intrng: fix INTR_ROOT_* constants
Switch to INTR_ROOT_COUNT as this name better describes its purpose.

Remove the default INTR_ROOT_IRQ from the core.  Define it (redundantly)
in each architecture's header, but now placed alongside its sibling
values (if defined by the platform, e.g. arm64 INTR_ROOT_FIQ).

Reviewed by:	mhorne
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1280
2024-12-16 15:11:52 -04:00
Olivier Certner
5e9a82e898
atomics: Constify loads
In order to match reality, allow using these functions with pointers on
const objects, and bring us closer to C11.

Remove the '+' modifier in the atomic_load_acq_64_i586()'s inline asm
statement's constraint for '*p' (the value to load).  CMPXCHG8B always
writes back some value, even when the value exchange does not happen in
which case what was read is written back.  atomic_load_acq_64_i586()
further takes care of the operation atomically writing back the same
value that was read in any case.  All in all, this makes the inline
asm's write back undetectable by any other code, whether executing on
other CPUs or code on the same CPU before and after the call to
atomic_load_acq_64_i586(), except for the fact that CMPXCHG8B will
trigger a #GP(0) if the memory address is part of a read-only mapping.
This unfortunate property is however out of scope of the C abstract
machine, and in particular independent of whether the 'uint64_t' pointed
to is declared 'const' or not.

Approved by:    markj (mentor)
MFC after:      5 days
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D46887
2024-12-16 15:42:26 +01:00
Andrew Turner
938e4b131c arm64: Use the PAN msr mnemonic rather than .inst
Switch from creating the msr instructions to manage PAN to use the
"msr pan, #1" instruction directly. When this was added clang didn't
have support to assemble the instructions. This appears to have been
added to clang 13 which is sufficiently old enough.

Binutils releases from around the same time appear to have added this
instruction so any modern gcc should also support this instruction.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D47817
2024-12-12 18:00:22 +00:00
Andrew Turner
4b516226dc arm64: Add CTR_EL0 op and CR values
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D47813
2024-12-12 18:00:22 +00:00
Andrew Turner
b77b7aeb18 arm64: Fix the alt name for ZCR_EL1
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D47810
2024-12-12 18:00:22 +00:00
Andrew Turner
4056e774b1 arm64: Move setting TCR_HD to C code
To allow for it to be more selective when we enable it, e.g. if the
CPU has an erratum that prevents us from doing so, move the check for
setting TCR_HD to C.

Reviewed by:	alc
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D47808
2024-12-11 17:02:24 +00:00
John Baldwin
e248e08a15 arm64: Add a constant to document the TZ bit in CPTR_EL2 without VHE
Reviewed by:	emaste
Sponsored by:	AFRL, DARPA
Differential Revision:	https://reviews.freebsd.org/D47882
2024-12-06 17:38:34 -05:00
Warner Losh
7b16a4a75d sys/intr.h: Make it safe to include from assembler
Sometimes we need defines from this file in assembler code. Today we do
the heavyweight approach of using genassym for that. However, they are
just #defines, so in the future we want to include sys/intr.h to pick up
the needed constants in exception.S.

PR:			283041
Sponsored by:		Netflix
Reviewed by:		mmel, andrew
Differential Revision:	https://reviews.freebsd.org/D47846
2024-12-06 10:31:36 -07:00
John Baldwin
a80b9ee15a atomic(9): Implement atomic_testand(clear|set)_ptr
For current architectures, these are just aliases for the existing
operation on the relevant scalar integer.

Reviewed by:	imp, kib
Obtained from:	CheriBSD
Sponsored by:	AFRL, DARPA
Differential Revision:	https://reviews.freebsd.org/D47631
2024-11-19 10:24:50 -05:00
Kyle Evans
4b01a7fa76 Revert "intrng: change multi-interrupt root support type to enum"
This reverts commit 536c8d948e.  The
change seemed fine on the surface, but converting to an enum has raised
some concerns due to the asm <-> C interface.  Back it out and let
someone else deal with it later if they'd like to.

Further context about the concerns can be found in D47279.
2024-10-25 16:18:40 -05:00
Andrew Turner
8efb1500d4 arm64: Enable handling EFI runtime service faults
Now we can handle EFI runtime service faults on arm64 do so.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D46818
2024-10-24 11:20:48 +01:00
Andrew Turner
d7f930b80e arm64: Implement efi_rt_arch_call
This is a function that calls into the EFI Runtime Services, but can
handle a fault. To support this add a handler in assembly that can
restore the kernel state on an exception and return a failure to the
caller.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D46817
2024-10-24 11:20:48 +01:00
Andrew Turner
a84653c5db arm64: Don't enable interrupts when in a spinlock
When we receive an exception while in a spinlock we shouldn't enable
interrupts. When entering a spinlock we disable interrupts so enabling
them here could cause surprising results.

The three cases that could cause this are:
 1. A break-before-make sequence
 2. Accessing possibly unmapped code with a fault handler
 3. Buggy code

1 and 2 are supported later in the data abort handler, and 3 should be
fixed when found.

Reviewed by:	mmel, kib, markj
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D46816
2024-10-24 11:20:48 +01:00
Kyle Evans
4f12b529f4 sys/intr.h: formally depend on machine/intr.h
sys/intr.h originally started life as an extract of arm's intr.h, and
this include was dropped in its place.  Changes in flight want to add
some MD definitions that we'll use in the more MI parts of INTRNG.

Let's formally reverse the dependency now since this is way more
common in general.  All of the includes switched in this change that I
spot-checked were in-fact wanting declarations historically included in
sys/intr.h anyways.

Reviewed by:	andrew, imp, jrtc27, mhorne, mmel, olce
Differential Revision:	https://reviews.freebsd.org/D47002
2024-10-23 22:55:29 -05:00
Elliott Mitchell
536c8d948e intrng: change multi-interrupt root support type to enum
uint32_t is handy for directly interfacing with assembly-language.  For
the C portion, enum is much handier.  In particular there is no need to
count the number of roots by hand.  This also works better for being
able to build kernels with varying numbers of roots.

Switch to INTR_ROOT_COUNT as this better matches the purpose of the
value.  Switch to root_type, rather than rootnum for similar reasons.

Remove the default from the core.  Better to require the architectures
to declare the type since they will routinely deviate and a default
chosen now will likely be suboptimal.

Leave intr_irq_handler() taking a register type as that better matches
for interfacing with assembly-language.
2024-10-23 22:55:21 -05:00
Elliott Mitchell
d64442a898 arm{,64}: use genassym for INTR_ROOT_* values
Rather than keeping the entire machine interrupt header assembly-safe,
switch to use of the existing genassym.c program to generate them.  This
will be handier in the long-term, most of the header never needs to be
exposed to assembly-language.
2024-10-23 22:55:21 -05:00
Andrew Turner
a090372f38 arm64: Decode CTR_EL0 via a table
Use the same method to decode CTR_EL0 as for the ID registers. This
will allow us to create a common view over all CPUs.

This will also allow us to create a common view for userspace and the
kernel if we detect a difference on some CPUs, or to handle errata.

Reviewed by:	imp
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D47124
2024-10-21 13:23:15 +01:00
Andrew Turner
590c32321d arm64: Add ID register field width values
In preperation for supporting non-4 bit field width to identcpu.c,
e.g. for ctr_el0, add the width of the existing ID register fields.

Reviewed by:	imp
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D47118
2024-10-21 13:23:15 +01:00
Andrew Turner
2b3d9ac890 arm64: Remove old I-Cache types
The VPIPT and AIVIVT cache types are reserved from Armv8.0. Remove
them as nothing will report these values.

Reviewed by:	imp
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D47117
2024-10-21 13:23:15 +01:00
Andrew Turner
9d3dc1e5e0 arm64: Remove VPIPT I-cache support from pmap
The VPIPT I-cache policy has been removed from the architecture.
Remove support for it from pmap. The vmm side was not imported so
calls to pmap_invalidate_vpipt_icache would cause the kernel to branch
to a NULL pointer.

Reviewed by:	imp
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D47116
2024-10-21 13:23:15 +01:00
Andrew Turner
a7c5c88cb2 arm64: Stop trashing x28 in savectx
While here make it return void, we don't set any useful return value
and nothing checks for it.

Sponsored by:	Arm Ltd
2024-10-15 18:24:42 +01:00
Andrew Turner
205c1007be arm64: Enable SVE in userspace
Report when SVE is present and allow it to be used by calling
sve_restore_state on an SVE exception from userspace.

Reviewed by:	kib
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43310
2024-09-30 12:04:23 +00:00
Andrew Turner
fe5ed2496e arm64: Don't trap SVE to EL2
As with floating point instructions don't trap SVE instructions to the
hypervisor. This lets us handle then in the kernel.

Reviewed by:	imp (earlier version)
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43303
2024-09-30 12:04:23 +00:00
Andrew Turner
aab6006894 arm64: Support SVE in ptrace and core dumps
Add the NT_ARM_SVE note type and use it to access the SVE registers
from ptrace. This allows userspace to modify the full SVE register
values.

Try to follow the Linux semantics to allow debuggers to use this with
minimal changes.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43309
2024-09-30 12:04:23 +00:00
Andrew Turner
87a58d931d arm64: Add an SVE sysarch
To allow for user space to read the SVE vector length add a sysarch
handler to return the value to userspace.

Reviewed by:	imp
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43308
2024-09-30 12:04:23 +00:00
Andrew Turner
e45132e978 arm64: Add the SVE registers to the signal frame
Use the new extended register support in the arm64 signal frame to
handle the SVE registers.

As these registers alias the VFP registers we use the floating point
register values to restore the lower bits of the SVE registers. This
is to support software that doesn't understand SVE to continue working.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43307
2024-09-30 12:04:23 +00:00
Andrew Turner
332c426328 arm64: Initial SVE support
Add initial kernel support for SVE. This detects if SVE is present on
all CPUs, and if so allows for the use of SVE in the future.

As the SVE registers are a superset of the VFP registers we don't need
to restore the VFP registers when SVE is enabled.

Ths interface to enable SVE is provided, but not used until SVE is
supported in signals and with ptrace.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43306
2024-09-30 12:04:23 +00:00
Ayrton Munoz
1f0174c927 arm64: Add support for FIQs
arm64 supports FIQs, fast interrupt requests, which are required by
Apple silicon which hardwires the ARM timers to FIQs. This is needed by
the upcoming Apple Interrupt Controller. Based on work by andrew@ and
kevans@ in https://reviews.freebsd.org/D40161.

Signed-off-by: Ayrton Munoz <a.munoz3327@gmail.com>
Co-authored-by: Kyle Evans <kevans@FreeBSD.org>
Co-authored-by: Andrew Turner <andrew@FreeBSD.org>
Reviewed-by: imp,mmel,mhorne
Pull-Request: https://github.com/freebsd/freebsd-src/pull/1363
2024-09-22 07:18:34 -06:00
Andrew Turner
d546313602 arm64: Add CPTR_TRAP_ALL and use it in vmm
Add a new macro that enables all CPTR_EL2 traps. This helps ensure we
trap all extensions we don't support.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D46516
2024-09-11 10:25:09 +00:00
Andrew Turner
9f3d15fda2 arm64: Add CPTR_E2H_TTA
The TTA field moves depending on the HCR_EL2.E2H field. Add a macro to
hold the E2H == 1 case.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D46515
2024-09-11 10:25:09 +00:00
Andrew Turner
16e661921a arm64: Add E2H to CPTR_EL2 register values
Rename register fields that are only valid when HCR_EL2.E2H == 1. Some
fields move around depending on the value of the E2H field.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D46514
2024-09-11 10:25:09 +00:00
Andrew Turner
7a488d83b3 arm64: Adjust the indentation of CPTR_EL2 values
Reviewed by:	emaste
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D46513
2024-09-11 10:25:08 +00:00
Zachary Leaf
610348a904 arm64: add additional MDCR_EL2 fields
Monitor Debug Configuration Register provides EL2 configuration options
for self-hosted debug and the Performance Monitors Extension.

Reviewed by:	andrew
Sponsored by:   Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D46191
2024-09-09 15:56:53 +00:00
Andrew Turner
d52c319042 arm64: Make shareability attributes dynamic
When LPA2 is enabled the shareability attribute in the page table are
replaces with output address bits. To support a larger physical address
space make this attribute dynamic so we only set it when appropriate.

Reviewed by:	alc, kib
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D46394
2024-09-05 13:12:17 +01:00
Andrew Turner
e2990a9ee4 arm64: Remove ATTR_DEFAULT from pte.h
ATTR_SH(ATTR_SH_IS) will soon be dynamic as the field is moved out of
the page tables in FEAT_LPA2. When this happens ATTR_DEFAULT will just
be ATTR_AF.

Rather than keeping ATTR_DEFAULT with one attribute remove it.

Reviewed by:	alc, kib, markj
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D46466
2024-09-05 13:12:17 +01:00
Andrew Turner
3a3aa2cc07 arm64: Remove TCR_CACHE_ATTRS and TCR_SMP_ATTRS
These are only used in one place so expand them there.

While here always set TCR_SH0_IS and TCR_SH1_IS. There is no advantage
to not set them in a UP kernel.

Reviewed by:	alc, kib, markj
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D46393
2024-09-05 13:12:16 +01:00
Andrew Turner
7be11454ed arm64: Add the tcr_el2 ds field
This will be used to support FEAT_LPA2 to allow more than 48 bits of
physical address space.

Reviewed by:	alc, kib, markj
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D46392
2024-09-05 13:12:16 +01:00
Mark Johnston
133a513ddc vmm: Make vmm_dev.h more self-contained
vmm.h is required for VM_MAX_SUFFIXLEN.  vmm_snapshot.h is required for
struct vm_snapshot_meta.

This is a prerequisite for including vmm_dev.h in the headers parsed by
libsysdecode.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D46485
2024-09-01 14:03:15 +00:00
Mark Johnston
780675e1be arm64: Fix the VM_MAX_NAMELEN definition
The maximum VM name length has changed since the arm64 vmm code was
forked.  For now, just sync with the amd64 definitions, since they
permit longer VM names.  As arm64/vmm is implemented only in main, I
won't bother dealing with backward compat.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D46484
2024-09-01 14:03:15 +00:00
Andrew Turner
8b01728431 arm64: Fix the ESR_EL1_op2 value
This leads to an unallocated register. Fix the value to point to
ESR_EL1.

Sponsored by:	Arm Ltd
2024-08-29 10:42:34 +00:00
Mark Johnston
b9ef152bec vmm: Merge vmm_dev.c
This file contains the vmm device file implementation.  Most of this
code is not machine-dependent and so shouldn't be duplicated this way.
Move most of it into a generic dev/vmm/vmm_dev.c.  This will make it
easier to introduce a cdev-based interface for VM creation, which in
turn makes it possible to implement support for running bhyve as an
unprivileged user.

Machine-dependent ioctls continue to be handled in machine-dependent
code.  To make the split a bit easier to handle, introduce a pair of
tables which define MI and MD ioctls.  Each table entry can set flags
which determine which locks need to be held in order to execute the
handler.  vmmdev_ioctl() now looks up the ioctl in one of the tables,
acquires locks and either handles the ioctl directly or calls
vmmdev_machdep_ioctl() to handle it.

No functional change intended.  There is a lot of churn in this change
but the underlying logic in the ioctl handlers is the same.  For now,
vmm_dev.h is still mostly separate, even though some parts could be
merged in principle.  This would involve changing include paths for
userspace, though.

Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D46431
2024-08-26 18:41:39 +00:00
Andrew Turner
db6e3260a8 arm64: Remove the E2H check from has_hyp
This was added to not use the physical timer when E2H was set. As we
now use the correct timer in this case we can remove this extra check.

Tested by:	kevans
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D46086
2024-08-21 08:46:59 +00:00
Andrew Turner
a745cdc19b arm64/vmm: Teach the vtimer about VHE
Teach the virtual timer about the cnthctl_el2 field layout under VHE.
As with non-VHE we need to trap the physical timer and not trap the
virtual timer.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D46074
2024-08-20 08:49:15 +00:00
Andrew Turner
4db15ab2c6 arm64: Add counter timer registers to armreg.h
Reviewed by:	imp
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D46071
2024-08-20 08:49:15 +00:00
Andrew Turner
7a345763f9 arm64: Expand the use of Armv8.1-A atomics
When targeting Armv8.1 we can assume FEAT_LSE is available and can use
the atomic instructions this provides without needing to check for
support first.

Reviewed by:	imp, markj, emaste
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D46159
2024-08-19 10:53:12 +00:00
Bjoern A. Zeeb
d1bdc2821f Deprecate contigfree(9) in favour of free(9)
As of 9e6544dd6e contigfree(9) is no longer
needed and should not be used anymore.  We leave a wrapper for 3rd party
code in at least 15.x but remove (almost) all other cases from the tree.

This leaves one use of contigfree(9) untouched; that was the original
trigger for 9e6544dd6e and is handled in D45813 (to be committed
seperately later).

Sponsored by:	The FreeBSD Foundation
Reviewed by:	markj, kib
Tested by:	pho (10h stress test run)
Differential Revision: https://reviews.freebsd.org/D46099
2024-07-26 10:45:01 +00:00
Andrew Turner
034c83fd7d arm64: Ensure sctlr and pstate are in known states
Before entering the kernel exception level ensure sctlr_el2 and
sctlr_el1 are in a known state. The EOS flag needs to be set to ensure
an eret instruction is a context synchronization event.

Set spcr_el1 when entering the kernel from EL1 and use an eret
instruction to return to the caller. This ensures the CPU pstate is
consistent with the value in spcr_el1 as it is the only way to set it
directly.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D45528
2024-07-23 09:25:05 +00:00
Andrew Turner
997511dffe arm64: Support counter access with E2H
When entering the kernel with the E2H field set the layout of the
cnthctl_el2 register changes. Use the correct field locations to enable
access to the counter and timer registers from EL1.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D45529
2024-07-23 09:25:05 +00:00
Andrew Turner
47361851bc arm64: Add EL1 and EL12 register alt names
When adding VHE support we may need to access these registers using
the _EL12 or _EL1 name depending on if VHE is enabled or not.

Add the registers we will likely need to access from VHE so these can
be updated in the guest switcher code.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D45525
2024-07-23 09:25:05 +00:00
Jessica Clarke
8415a654d0 Retire non-NEW_PCIB code and remove config option
All architectures enable NEW_PCIB in DEFAULTS (arm being the most recent
to do so in 121be55599 (arm: Set NEW_PCIB in DEFAULTS rather than a
subset of kernel configs")), so it's time we removed the legacy code
that no longer sees much testing and has a significant maintenance
burden.

Reviewed by:	jhb, andrew, emaste
Differential Revision:	https://reviews.freebsd.org/D32954
2024-07-18 18:55:12 +01:00