Fix a narrow window where the lock is unlocked but the checking CPU
hasn't flushed things appropriately.
Inside this window the CPU inside cpu_switch() will loop forever thinking
the destination thread is still blocked/locked even though it is not.
This manifests as the system hanging after starting all APs.
I've seen this reliably trigger in qemu-system-ppc64 running power9 pseries
guests; the more CPUs the more likely it triggers at boot.
PR: kern/292167
Differential Revision: https://reviews.freebsd.org/D54478
Reviewed by: jhibbits
MFC after: 1 week
Relnotes: yes
Define _ALIGNBYTES using sizeof(void *) (no functional change on any
existing architecture) which will allow it to work with CHERI were we
must align things up to capability alignment.
In _ALIGN, replace integer manipulation which does not preserve pointer
provenance with a type and provenance preserving builtin. This requires
modest changes in code which assumes _ALIGN returns an integer, but
those are relatively rare.
Reviewed by: kib, markj
Effort: CHERI upstreaming
Sponsored by: Innovate UK
Differential Revision: https://reviews.freebsd.org/D53947
The wrapper functions such as bus_alloc_resource_any() still support
passing the rid by value or pointer, but the underlying implementation
now passes by value.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D53402
On powerpc/powerpc64, sig_atomic_t is an int, but was treated as if
it was a long by <machine/_stdint.h>. This was finally caught by the
unit test added with 4a1c752 / D53831.
Reported by: kib
Reviewed by: kib, imp
Approved by: markj (mentor)
Fixes: c3e289e1ce
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D54026
The platform-dependent macros are added to the various
_stdint.h headers, those that are always the same are
added directly to _stdint.h.
We may want to move the definitions for WCHAR_* and
WINT_* out of the platform header files as those are
always the same.
Approved by: markj (mentor)
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D53830
For compliance with IOS/IEC 9899:2024 ("C23").
These macros define the width in bits of the basic integer types.
Another new macro, BITINT_MAXWIDTH, is not yet included as I do not
understand what it should be set to. Perhaps it is compiler-specific.
Approved by: markj (mentor)
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D53825
Realtek changed how it styled its name 25 or so years ago, but the old
style persisted in many places. These products use the new styling in
their datasheets.
Signed-off-by: ykla yklaxds@gmail.com
Sponsored by: Chinese FreeBSD Community
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1901
Last minute change by me (diff reduction), that I didn't build. This
was in the original commit.
Fixes: 8fb1789612 ("intr/powerpc: create openpic_class kobj")
MFC after: 2 weeks
X-MFC-with: 8fb1789612
Using kobj allows implementing most PIC functions merely by inheriting
from the parent class. As there are multiple OpenPIC implementations,
this ensures all common hooks go through by default.
Note, this adds the suspend/resume functions to other PICs. This should
be harmless as suspend/resume isn't working on the devices anyway.
Reviewed by: jhibbits
MFC after: 2 weeks
Spotted while examing this driver. Remove some end of line spaces/tabs.
Replace some spaces which should instead be tabs.
Reviewed by: jhibbits
MFC after: 2 weeks
kexec hasn't been ported to these architectures, yet, so appease the
build with dummy headers.
Sponsored by: Juniper Networks, Inc.
Differential Revision: https://reviews.freebsd.org/D51625
Fix the comment introducing the 'wlan_*' devices (AES-CCMP is missing)
after introducing AES-GCMP.
While here, re-order the devices in order of appearance of the related
technologies.
No functional change (intended).
Reviewed by: adrian, emaste
Fixes: 7bf82ea4fd ("sys: add wlan_gcmp to GENERIC kernels as appropriate")
MFC after: 3 days
MFC to: stable/15
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D52444
While FIDO/U2F keys were already supported by the generic uhid(4) and
hidraw(4) drivers, this driver adds some additional features an does
steps to tighten the security of FIDO/U2F access.
- It automatically loads through devd.
- Automatically enables HQ_NO_READAHEAD for FIDO/U2F devices.
- Implements only miminum set of features.
- Do not requires external devfs configuration to set character device
permissions.
- Names character device as u2f/# to make possible capsicum or any
other pledge()-style sandboxing.
PR: 265528
Differential Revision: https://reviews.freebsd.org/D51612
Since gpiobus_attach_bus can attach the gpiobus child along with its
children in the same bus pass, the parent controller's reference to
gpiobus might not be set by the time the children need it. Instead,
drivers should use gpiobus_add_bus and explicitly call
bus_attach_children.
Reviewed by: mmel, imp (older version)
Approved by: imp (mentor)
Differential Revision: https://reviews.freebsd.org/D51578
More fallout from a77e1f0f81.
When the tag has an alignment requirement but a small (remaining)
transfer size, the transfer will be rounded up to exceed its bounds,
resulting in memory corruption.
The issue is observed on powerpc as noted in the pull request:
https://github.com/freebsd/freebsd-src/pull/1415
I also observe the issue locally on riscv hardware, with an 8-byte
transfer having 64-byte alignment.
There is some uncertainty about the purpose/need for the alignment
roundup; both its original intention and present effect. Notably, it is
no longer present at all in arm/arm64 implementations. Possibly, this
roundup can be removed altogether, but this requires more careful
analysis of the edge-cases and history of the property.
For now, simply clamp sgsize to be no larger than the remaining buflen,
as this is certain to be correct within the current scheme and fixes
the affected transfers.
Discussed with: jhb, markj
MFC after: 3 weeks
Fixes: a77e1f0f81 ("busdma: better handling of small segment bouncing")
Sponsored by: The FreeBSD Foundation
Pull Request: https://github.com/freebsd/freebsd-src/pull/1415
Signed-off-by: Chattrapat Sangmanee <aomsin27@hotmail.co.th>
Co-authored-by: Chattrapat Sangmanee <aomsin27@hotmail.co.th>
Differential Revision: https://reviews.freebsd.org/D47807
Multiple issues existed within the powerpc FP/VSX save/restore functionality,
leading to register corruption and loss of register contents in specific
scenarios involving high signal load and use of both floating point and VSX
instructions.
Issue #1
On little endian systems the PCB used the wrong location for the shadowed
FP register within the larger VSX register. This appears to have been an
attempt to correct issue #2 without understanding how the vector load/store
instructions actually operate.
Issue #2
On little endian systems, the VSX state save/restore routines swapped 32-bit
words within the 64-bit aliased double word for the associated floating point
register. This was due to the use of a word-oriented load/store vs. doubleword
oriented load/store.
Issue #3
The FPU was turned off in the PCB but not in hardware, leading to a potential
race condition if the same thread was scheduled immediately after sigreturn.
The triggering codebase for this is Go, which makes heavy use of signals and
and generates an unusual mix of floating point and VSX assembler. As a result,
when combined with th powerpc lazy FPU restore, a condition was repeatedly hit
whereby the thread was interrupted in FP+VSX mode, then restored in FP only
mode, thus reliably triggering the issues above.
Also clean up the associated asm() style issue flagged by GitHub Actions.
Signed-off-by: Timothy Pearson <tpearson@raptorengineering.com>
MFC after: 1 week
Pull Request: https://github.com/freebsd/freebsd-src/pull/1756
According to the ELF ABI v2, two scratch regions are reserved below the stack
pointer, one 288 byte general region and one 224 byte compiler region.
FreeBSD only reserved the 288 byte region. Follow the ELV v2 ABI and reserve
the full 512 byte region as specified.
Signed-off-by: Timothy Pearson <tpearson@raptorengineering.com>
MFC after: 1 week
Pull Request: https://github.com/freebsd/freebsd-src/pull/1756
For 32-bit arm, move the no-op test that was already in place at start
of the function so that it stays first even if the '#if 0' block around
the call to sf_buf_invalidate_cache() is uncommented at some point (if
ever).
Reviewed by: jeffpc_josefsipek.net, kib
MFC after: 10 days
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D51253
Only attach gpiobus when the controller is fully initialized. Children
of gpiobus expect this to be the case.
Reviewed by: mmel, imp, andrew
Approved by: imp (mentor)
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D51088
At shutdown devices may need to do extra work to clean up state, etc.
This is done in a device_shutdown kobj method on a driver, with the
default being a `do nothing` method. Only x86's nexus driver includes
the device_shutdown method to propagate down to its children, so on
other architectures the device_shutdown stops at the root, and thus
device_shutdown is never called for any real devices. Add this missing
method to the nexus drivers of the other architectures so devices have a
chance to properly shutdown.
Sponsored by: Juniper Networks, Inc.
It is likely we will need these on arm64. Add them in preparation for
flags in these to be added at some point in the future.
Reviewed by: brooks, imp, kib
Sponsored by: Arm Ltd
Differential Revision: https://reviews.freebsd.org/D51005
The 'runq' machinery now depends on only two settable parameters,
RQ_MAX_PRIO, the maximum priority number that can be accepted, the
minimum being 0, and RQ_PPQ, the number of priorities per queue (to
reduce the number of queues).
All other parameters are deduced from these ones. Also, all
architectures automatically get a runq word that is their natural word.
RQB_FFS() always was 'ffsl() - 1' except for amd64 where it was
'bsfq()'. Now that all these finally call compiler builtins, the
resulting assembly code is the same, so there is no cost to removing
this special case.
After all these changes, <machine/runq.h> headers have no more purpose,
so remove them.
While here, fix potentially confusing parameter name for RQB_WORD() and
RQB_BIT().
While here, include all necessary headers so that <sys/runq.h> can be
included standalone.
No functional change (intended).
Reviewed by: kib
MFC after: 1 month
Event: Kitchener-Waterloo Hackathon 202506
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D45387
After the demise of vm_page_lock(), the only remaining uses of
pa_index() are in various pmap implementations. In many cases, e.g.,
amd64, the pmap implementations already provided their own definitions,
often identical to the machine-independent one. For those that didn't
provide one, this change adds it.
Reviewed by: kib, markj
Differential Revision: https://reviews.freebsd.org/D50823
vm_page_lock() and its underlying array of locks, pa_lock[], have been
replaced throughout the virtual memory system by either atomics or
busy-style, per-page synchronization. The Linux KPI support contained
the only remaining use cases. Eliminate or update them as appropriate
to each case.
Reviewed by: kib, markj
Differential Revision: https://reviews.freebsd.org/D50767
Switch to using sys/stdarg.h for va_list type and va_* builtins.
Make an attempt to insert the include in a sensible place. Where
style(9) was followed this is easy, where it was ignored, aim for the
first block of sys/*.h headers and don't get too fussy or try to fix
other style bugs.
Reviewed by: imp
Exp-run by: antoine (PR 286274)
Pull Request: https://github.com/freebsd/freebsd-src/pull/1595
After further thinking, the nexus bus mappings are for the immediate
peripherals, not downstream. Given this, and that historically PowerPC
platforms have been big-endian by default, it makes sense to default
mappings to BE always. If this changes in the future, the platform
devices can explicitly mark their mappings with the RF_LITTLEENDIAN flag
instead.
This reverts commit 86d20eaadf.
The big-endian analogue to the RF_LITTLEENDIAN flag, if this flag is set
on a memory resource it's always mapped big endian.
This is needed by the PowerNV OPAL resources (XIVE and PCI), as these
top-level peripherals are always big-endian.
Tested by: pkubaj
Fixes: c4921a0f("powerpc: Always use BE tag in nexus_map_resource")
MFC after: 1 day
X-MFC-with: c4921a0f
7b5a5e4e replaced nexus_activate_resource() with the bus generic
equivalent, which uses bus_map_resource(). However, though not intended
to have a functional change, nexus_map_resource() uses the bus tag of
the build (BE vs LE), while nexus_activate_resource() always explicitly
set a big-endian tag, leading to failures on powerpc64le now. Using BE
unless otherwise explicitly specified with the RF_LITTLEENDIAN fixes LE
on bare metal, and doesn't hurt in a VM, which nexus_map_resource() was
added for.
Reported by: pkubaj
Tested by: pkubaj
Fixes: 7b5a5e4e("powerpc nexus: Use bus_generic_rman_*")
MFC after: 1 day
Change architecture-specific code to use iterators rather than tailq
pointers.
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D49927
Function moea64_sp_demote_aligned() is only invoked if VM_NRESERVLEVEL
> 0. Add #if/#endif pairs around the declaration and definition of
that function to silence warnings about unused static functions.
Reviewed by: kib
This was probably intended to match the amd64 check, but that tests
NOFAULTING against non-zero, while this checks against 0. We're most
likely to end up in this function when faulting is allowed, so
predict_true is the better option.
Thus far we've relied on the firmware setting HFSCR correctly, enabling
all facilities. However, it appears some recent firmwares do not.
Linux explicitly enables all facilities it supports (including
transactional memory, which new firmwares apparently do not enable), so
do the same here, explicitly enable all the facilities FreeBSD supports.
MFC after: 1 week
Treat Hypervisor Facility Unavailable as an illegal instruction in user
space. This way programs that use facilities like transactional memory,
which will never be supported as it has been removed from the ISA, will
not crash the kernel.
Tested by: pkubaj
MFC after: 1 week