Commit graph

2350 commits

Author SHA1 Message Date
Mark Johnston 7b68fb5ab2 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
2023-12-25 21:04:00 -05:00
Mark Johnston ccf8e1bb38 arm64: Remove an unused global variable
No functional change intended.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Sponsored by:	Juniper Networks, Inc.
2023-12-18 13:13:43 -05:00
Mitchell Horne 3933ff56f9 busdma: tidy bus_dma_run_filter() functions
After removing filter functionality, the naming doesn't clearly
represent what the function does, so try to address this. Include some
code clarity and style improvements.

Create a common version in subr_busdma_bounce.c, used by most
implementations. powerpc still needs its own version of the function,
due to its dmat->iommu == NULL check.

No functional change intended.

Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D42896
2023-12-06 19:11:39 -04:00
Mitchell Horne 1228b93b41 busdma: remove parent tag tracking
Without filter functions, we do not need to keep track of tag ancestry.
All inheritance of the parent tag's parameters occurs when creating the
new child tag.

Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D42895
2023-12-06 19:11:39 -04:00
Mitchell Horne 900907f439 busdma: kill filter functionality internally
Address filter functions are unused, unsupported, and now rejected.
Simplify some busdma code by removing filter functionality completely.

Note that the chains of parent tags become useless, and will be cleaned
up in the next commit.

No functional change intended.

Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D42894
2023-12-06 19:11:39 -04:00
Mitchell Horne 7cb028deff busdma: Prevent the use of filters with bus_dma_tag_create()
A deprecation notice was added to the bus_dma(9) man page by scottl@ in
September 2020 discouraging the use of filter functions. I've performed
an attentive check of all callers in the tree and everything that exists
today passes NULL for both filtfunc and filtarg. Thus, we should start
returning EINVAL if these arguments are non-NULL to prevent new usages
from popping up. Update the man page to be more clear about this.

The deprecation notice is present since at least 13.0-RELEASE, so this
is the appropriate step for the lifetime of 15, without actually
breaking the driver API. Stable branches will emit a warning instead.

This change enables the removal of a fair amount of unused complexity
across the various busdma implementations.

Reviewed by:	jhb
MFC after:	never
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D42852
2023-12-06 19:10:25 -04:00
Jessica Clarke 9560ac4b63 armv8rng: Don't require toolchain to support FEAT_RNG
We have the mechanism in place to support encoding system registers
explicitly, so use that rather than requiring LLVM 13+, which breaks our
current set of GitHub CI builds.

Fixes:	9eecef0521 ("Add an Armv8 rndr random number provider")
2023-12-01 23:59:07 +00:00
Mark Johnston 4f12883c36 arm64: Add register definitions for MDCR_EL2
This is needed to support the bhyve gdb stub implementation on arm64.

Reviewed by:	andrew
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D42867
2023-12-01 13:31:13 -05:00
John Baldwin 1587a9db92 pci_cfgreg: Add a PCI domain argument to the low-level register API
This commit changes the API of pci_cfgreg(read|write) to add a domain
argument (referred to as a segment in ACPI parlance) (note that this
is not the same as a NUMA domain, but something PCI-specific).  This
does not yet enable access to domains other than 0, but updates the
API to support domains.

Places that use hard-coded bus/slot/function addresses have been
updated to hardcode a domain of 0.  A few places that have the PCI
domain (segment) available such as the acpi_pcib_acpi.c Host-PCI
bridge driver pass the PCI domain.

The hpt27xx(4) and hptnr(4) drivers fail to attach to a device not on
domain 0 since they provide APIs to their binary blobs that only
permit bus/slot/function addressing.

The x86 non-ACPI PCI bus drivers all hardcode a domain of 0 as they do
not support multiple domains.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D42827
2023-11-29 10:31:47 -08:00
Warner Losh fdafd315ad sys: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:24:00 -07:00
Warner Losh 29363fb446 sys: Remove ancient SCCS tags.
Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by:		Netflix
2023-11-26 22:23:30 -07:00
John Baldwin 5622f52c98 aarch64 nexus: Fix a mismerge in nexus_activate_resource
Fixes:		658501d259 aarch64 nexus: Use bus_generic_rman_*_resource
2023-11-24 14:00:33 -08:00
John Baldwin 658501d259 aarch64 nexus: Use bus_generic_rman_*_resource
Custom activate/deactivate_resource methods are still needed to handle
IRQ resources.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D42741
2023-11-24 09:28:19 -08:00
John Baldwin 71cfd330fc arm64/riscv nexus: Implement bus_unmap_resource
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D42725
2023-11-23 09:06:51 -08:00
John Baldwin b887b665eb nexus: Use resource_validate_map_request
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D42724
2023-11-23 09:06:37 -08:00
Kyle Evans a3ceeef26b arm64: lop off another 24MB of KVA for early device mappings
This grows the block enough to fit a 4K 32-bit depth framebuffer; some
firmware would present smaller GOP modes to be able to boot with a
smaller framebuffer on these devices, but the Windows Devkit firmware
is simply not that nice.  Instead, it offers exactly one GOP mode that
matches the current resolution of the attached display, so with limited
control over resolution on most of my displays it'd be nice if we could
Just Work(TM) at 4K.

andrew notes that he has some ideas for removing PMAP_MAPDEV_EARLY_SIZE
entirely, so this limitation could end up removed altogether in the
future.

Reviewed by:	andrew, emaste
Differential Revision:	https://reviews.freebsd.org/D42726
2023-11-23 10:23:14 -06:00
John Baldwin ecf2106c07 arm64/amd64/riscv nexus: Use bus_generic_rl_*
Reviewed by:	mhorne, imp
Differential Revision:	https://reviews.freebsd.org/D42716
2023-11-22 09:06:33 -08:00
Konstantin Belousov 5a2bbacea5 FEATURE compat_freebsd_32bit: only report on arm64 when support is present
depending on hardware support for aarch32.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D42641
2023-11-21 13:55:59 +02:00
Andrew Turner 1b9096cd1d arm64: Set the Guarded Page flag in the kernel
Now the kernel and modules are built with branch protection we can
enablethe Guarded Page flag in the page tables. This causes indirect
branches to a location without a correct landing pad instruction to
raise an exception.

This should help mitigate some attacks where a function pointer is
changed to point somewhere other than the start of the function,
however it doesn't stop an attacker pointing it to an unintended
function.

Reviewed by:	alc, scottph (both earlier version), markj
Sponsored by:	Arm Ltd
Sponsored by:	The FreeBSD Foundation (earlier version)
Differential Revision:	https://reviews.freebsd.org/D42080
2023-11-21 10:02:58 +00:00
Andrew Turner f3a83b3a62 arm64: Remove an old comment
This was missed when removing kern_delta

Sponsored by:	Arm Ltd
2023-11-21 09:30:45 +00:00
Brooks Davis 54d487c4d0 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
2023-11-18 00:48:14 +00:00
Konstantin Belousov 0aa93010c5 arm64: do not register elf32 brand if hardware cannot exec aarch32
Reviewed by:	imp, jrtc27
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D42639
2023-11-17 00:04:40 +02:00
Andrew Turner 257b044548 arm64: Correct a comment in locore.S
We now use the physical address of get_load_phys_addr. Use it in a
comment rather than the old symbol.

Sponsored by:	Arm Ltd
2023-11-15 18:13:39 +00:00
Andrew Turner 9eecef0521 Add an Armv8 rndr random number provider
Armv8.5 adds an optional random number generator. This is implemented
as two special registers one to read a random number, the other to
re-seed the entropy pool before reading a random number. Both registers
will set the condition flags to tell the caller they can't produce a
random number in a reasonable amount of time.

Without a signal to reseed the entropy pool use the latter register
to provide random numbers to the kernel pool. If at a later time we
had a way to tell the provider if it needs to reseed or not we could
use the former.

On an Amazon AWS Graviton3 VM this never failed, however this may not
be the case on low end CPUs so retry reading the random number 10 times
before returning an error.

Reviewed by:	imp, delphij (csprng)
Sponsored by:	The FreeBSD Foundation
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D35411
2023-11-15 18:05:08 +00:00
Andrew Turner 61f14f1da3 arm64: Clean up finding our load address
Use the linker to pre-calculate the offset of a known symbol from
KERNBASE, and use this to find the physical address KERNBASE should
map to.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42568
2023-11-15 18:05:08 +00:00
Andrew Turner ba31362694 arm64: Make kern_delta unneeded in the boot params
Use pmap_early_vtophys to translate from a virtual to physical where
we were previously using the calculated delta. This means that, while
we still calculate it, we don't need to pass it to initarm or either
pmap bootstrap functions.

While here remove an unneeded printf that indirectly used it or was
related to the previous printf.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42567
2023-11-15 18:05:08 +00:00
Andrew Turner 5fae53589e arm64: Use pmap_early_vtophys in pmap_bootstrap_san
Use pmap_early_vtophys to find the physical address of the kernel base
rather than using the calculated offset as it will be removed in a
latter commit.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42566
2023-11-15 18:05:08 +00:00
Andrew Turner 7eb26be9c8 arm64: Use adrp + :lo12: to load globals from asm
When loading a global variable we can use a pseudo-instruction similar
to "ldr, xn, =global" to load the address of the symbol. As this is
unlikely to be supported by a mov instruction a pc-relative load is
used, with the absolute address written at the end of the function so
it will be loaded.

This load can be partially replaced with an adrp instruction. This
generates the address, aligned to a 4k boundary, using a pc-relative
addition. Because the address is 4k-aligned we then update reading the
global variable using a load with the offset of the load the low
12-bits of the global. Arm64 assemblers have :lo12: to support this,
e.g. "ldr xn, [xn, :lo12:global]".

The only remaining users of "ldr, xn, =global" that I can find are
executed from the physical address space the kernel was loaded in and
need an address in the kernels virtual address space. Because of this
they can't use adrp.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42565
2023-11-15 18:05:08 +00:00
Warner Losh 49025a1109 _bus.h: Use standard licnese text
All of these used the 'immediately at beginning' variation of the
BSD-2-Clause license. This wasn't intentional, just what I copied from
from a random file in the tree back in 2005. It was not an intentional
decision.

The different arch bus.h files are a mix of BSD-2-Clause and
BSD-4-Clause that have various copyright holders (Charles M. Hannum,
Christopher G. Demetriou, The NetBSD Foundation and KATO Takenori), and
some of the content of these files were likely copied from there.
However, apart from the uncopyrightable interface lines, there are very
few comments. It's unclear if these comments are 'original material'
here to copyright, but to the extent that there is, license it under the
standard BSD-2-Clause copyright that's the norm for the project today.
In any event, the standard BSD-2-Clause is also closer to those
originals.

In addition, FreeBSD uses different type definitions than the original
NetBSD code in part. The comments that were copied have been copied a
lot, but appear in NetBSD's bus.h files in NetBSD 1.3.

While I'm here, assign the copyright, to the extent any exists from me,
to the FreeBSD Foundation. I just cut and pasted these into _bus.h from
the different machine files and those files have a rich history of
modification from the original imports from NetBSD over more than 25
years so it's tricky to say who, exactly, wrote each bit. Given the size
of the files, this seems like the best compromise.  Also add an
acknowledgement to the NetBSD 1.3 bus.h files and their authors (there
were no additional FreeBSD authors listed in the various
sys/*/include/bus.h files). Finally, use the SPDX identifier instead of
multiple copies of the text.

Differential Revision:	https://reviews.freebsd.org/D42532
Sponsored by:		Netflix
2023-11-13 12:25:30 -07:00
Mark Johnston b9c0003f0f arm64: Initialize x18 for APs earlier during boot
When KMSAN is configured, the instrumentation inserts calls to
__msan_get_context_state() into all function prologues.  The
implementation dereferences curthread and thus assumes that x18 points
to the PCPU area.  This applies in particular to init_secondary(), which
currently is responsible for initializing x18 for APs.

Move initialization into locore to avoid this problem.  No functional
change intended.

Reviewed by:	kib, andrew
MFC after:	2 weeks
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D42533
2023-11-13 10:44:45 -05:00
Warner Losh 20f8814cd3 busdma: On systmes that use subr_busdma_bounce, measure deferred time
Measure the total deferred time (from the time we decide to defer until
we try again) for busdma_load requests. On systems that don't ever
defer, there is no performnce change. Add new sysctl
hw.busdma.zoneX.total_deferred_time to report this (in
microseconds).

Normally, deferrals don't happen in modern hardware... Except there's a
lot of buggy hardware that can't cope with memory > 4GB or that can't
cross a 4GB boundary (or even more restrictive values), necessitating
bouncing. This will measure the effect on the I/Os of this deferral.

Sponsored by:		Netflix
Reviewed by:		gallatin, mav
Differential Revision:	https://reviews.freebsd.org/D42550
2023-11-13 07:23:53 -07:00
Andrew Gallatin b2921fdc23 arm64: Implement bus_get_resource and bus_delete_resource.
These devmethods were not defined, leading to the surprising result
of using bus_set_resource(), and then immediately turning around
and getting zeros back from bus_get_resource().   These are now
simply passed through to the generic definitions, since there
is no need for them to be arm64 specific.

Note that jhb plans to replace most of the devmethods with
the generic versions.

Suggested by: jhb
Sponsored by: Netflix
2023-11-11 12:57:39 -05:00
Andrew Turner 5a8417c78f arm64: Check if PSCI before calling SMCCC
As SMCCC depends on PSCI check if the latter is present before calling
the former. This fixes an issue where we may call into SMCCC when there
is no PSCI in the system causing a smccc_version assert to fail.

Reported by:	stevek
Reviewed by:	emaste, imp, stevek
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42404
2023-11-10 16:01:13 +00:00
Andrew Turner 2ee649c1dd arm64: Add more HWCAP2 values
Update the HWCAP2 values to align with Linux v6.6-rc7

Reviewed by:	manu, imp, emaste
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42379
2023-11-10 16:01:13 +00:00
Andrew Turner 0f09388009 arm64: Expand HWCAP2 to be 64 bit
There are more than 32 arm64 HWCAP2 values. Expand the macros to
include leading zeros and mark them as unsigned long.

Reviewed by:	manu, imp, emaste
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42378
2023-11-10 16:01:13 +00:00
Andrew Turner e6dbc99d47 arm64: Create a Linux view of the ID registers
When adding support for new hardware extensions we may not want to
enable support for the FreeBSD and Linux ABIs at the same time. To
support this split the Linux ID register and hwcaps so they can be
configured separately.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42372
2023-11-10 16:01:13 +00:00
Andrew Turner c9e8b4b279 arm64: Use a hwcap ID rather than pointer
To allow for a different Linux hwcap value store the hwcap ID rather
than a pointer to elf{32,}_hwcap{2,}. This will be needed when creating
a different view of the ID registers for FreeBSD and Linux.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42371
2023-11-10 16:01:13 +00:00
Andrew Turner c2dc043c97 arm64: Add an is64bit flag to user readable ID regs
To tell if a register is for 32 or 64 bit userspace add a flag to the
user reg struct. This will be used later to rework how the hwcaps are
generated.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42370
2023-11-10 16:01:13 +00:00
Konstantin Belousov d093fe94e1 Fix typo
Fixes:	967022aa5a
MFC after:	1 week
2023-11-04 18:48:25 +02:00
Konstantin Belousov 967022aa5a arm64: improve UVA layout for 32bit processes
Add compat.aarch32 tunables for maxssiz, maxdsiz, and maxvmem.
Set the default values same as for amd64.
Fix freebsd32 sysentvec on arm64 to provide sv_maxssiz, and sv_fixlimit.

PR:	274705
Reviewed by:	markj
Tested by:	fuz
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D42451
2023-11-04 18:47:50 +02:00
Andrew Turner 0590ed0967 arm64: Add a BTI landing pad to .mcount
The .mcount function needs a BTI branch target. As we can't rely on
asm.h being included use the hint version of a "bti c" instruction.
This is a nop when BTI is not supported or not used.

Reviewed by:	markj
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42230
2023-10-30 17:55:45 +00:00
Andrew Turner 070a4ff82a arm64: Use the Linux sigframe to restore registers
When returning from a Linux signal use the Linux sigframe to find the
register values to restore.

Remove the FreeBSD ucontext from the stack as it's now unneeded.

Reviewed by:	dchagin, emaste
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42360
2023-10-27 10:32:24 +01:00
Andrew Turner 1e05cf5f97 arm64: Add a missing MRS_HWCAP_END
Add a missing end marker to stop the arm64 CPU ID code reading past
the end of an array.

Sponsored by:	Arm Ltd
2023-10-25 13:33:16 +01:00
Andrew Turner 271e669ed5 arm64: Teach bus_dma on arm64 about NUMA
When allocating memory we should try to allocate from the NUMA node
closest to the device to reduce cross domain memory traffic. Teach the
arm64 bus_dma code to do this.

While here use mallocarray to guard against an unlikely integer
overflow.

Reviewed by:	markj
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42187
2023-10-23 11:45:22 +01:00
Andrew Turner 26ac295c05 arm64: Fix long lines in vm_machdep.c
Reviewed by:	emaste
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D41828
2023-10-23 11:43:25 +01:00
Andrew Turner 2b39a6f68c arm64: Add PAC instruction macros
To support Pointer Authentication (PAC) in assembly files add a pair of
macros that sign the link register. When used before storing to the
stack it will allow hardware to detect if it has changed before using
it in the return instruction.

Reviewed by:	markj, emaste
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42226
2023-10-20 17:01:05 +01:00
Andrew Turner 82597d2102 arm64: Support creating a BTI & PAC note
To detect when an object file is build with the Branch Target
Identification (BTI) and Pointer Authentication Code (PAC) extensions
there is an elf note the compiler will insert. It will only do so from
a high level language, e.g. C or C++.

To get the not in assembly add the GNU_PROPERTY_AARCH64_FEATURE_1_NOTE
macro that can be used to create it, and the
GNU_PROPERTY_AARCH64_FEATURE_1_VAL macro to insert the correct value
based on which combination of BTI and PAC are enabled.

Reviewed by:	markj (earlier version), emaste
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42225
2023-10-20 16:59:25 +01:00
Mark Johnston 8fd0ec53de 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
2023-10-17 09:12:19 -04:00
Olivier Houchard ccd0f34d85 arm64/compat32: Fix handling of 32bits FP registers.
We must consider the aarch32 FP registers as 16 128bits registers, and store
that as the first 16 aarch64 FP registers.

PR: 267788
MFC After: 1 week
2023-10-16 22:29:06 +02:00
Alfonso Gregory e1fe34707a arm64: Save an instruction in locore.S
We can move and sub at the same time, so let's do that.

Reviewed by:	andrew, kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/794
2023-10-16 15:54:41 -04:00