powerpc: use the register validity flags in the vector ptrace requests
PT_SETVRREGS and PT_SETVSRREGS set PCB_VEC and PCB_VSX, which say the
thread owns the unit, instead of PCB_VECREGS and PCB_FPREGS, which say
the saved registers are valid. Ownership should only come from the
unavailable trap or cpu_switchin(), and the trap asserts it isn't set
yet, so setting the VSX registers of a traced child that hasn't used
the FPU panics an INVARIANTS kernel on the child's first VSX
instruction. Tracing your own child is enough, no privilege needed.
The getters had the matching problem: they returned the saved
registers only while the thread owned the unit, so a thread stopped
with valid but unloaded registers showed the debugger zeroes.
The thread is stopped, so the PCB is what counts. Set and test the
validity flags instead.
Reviewed by: jhibbits
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D62035
[LoopPredication] Register inserted assumptions with the AssumptionCache (#247964)
When widening a guard, LoopPredication inserts an llvm.assume of the
guard's old condition (on by default), but did not register it with the
AssumptionCache. The cache is never invalidated, so it was missing these
assumptions for the rest of the pipeline. This registers them in both
places that insert one.
Another follow-up to #245493.
[BOLT] Prefer global symbols at the same address (#244233)
Currently, BOLT's address-to-symbol resolution prioritizes function
symbols over other symbols and debug symbols, without making a
fine-grained distinction for local symbols. When multiple symbols share
the same address, BOLT may pick a local function symbol as the primary
name and emit it into the output binary and profile (this is especially
common on RISC-V due to the heavy use of label symbols). This can cause
confusion and potential profile mismatch issues (lots of `PG.` symbols
emitted, as described in #243760).
This patch standardizes the behavior of `discoverFileObjects()` and
refines the handling of local vs. global symbols, selecting the primary
symbol name according to the following priority order:
0: Global function
1: Non-global function
2: Other global symbol
3: Other non-global symbol
4: Global debug symbol
5: Non-global debug symbol
[InstSimplify] Fold comparisons of ctpop with its operand (#221104)
Fold llvm.ctpop(x) <= x by registering x as an unsigned upper bound of
ctpop(x). Automatically handles other canonicalized variants.
Partially addresses #220800.
Alive2 proof https://alive2.llvm.org/ce/z/MTkIxk
Fix edge case defects and add test coverage
Disallow promotion to no-loop for kernels with non-contant or false
conditional clause that affects teams or thread number.
Add guard for 0 trip count for empty loops on host-compile and accept
oversubscription flags there so it applies, so that no-loop kernels are
correctly sized from the count and no longer result in large grid sizing
for zero extended negative iteration counts.
Add guard to write keep-alive list only on per module finalize, matching
offload entry per-module write, to avoid multiple lists with different
names, of which only the first protects its entries, leaving clang's own
list unprotected.
Share one no-loop eligibility check between exec mode and body
The kernel is tagged SPMD_NO_LOOP by a single check, and the body is
emitted loop-free exactly when the kernel carries that tag. Add tests
for the clauses that block promotion.
[clang][OpenMP] Add no-loop SPMD kernel promotion
A target teams distribute parallel for that is guaranteed a thread for
every iteration does not need the loop around its body. Flang already
drops it and runs the region as a no-loop kernel.
Enable the same optimization for Clang through mirroring Flang's MLIR
promotion using OpenMPIRBuilder. The kernel is tagged SPMD_NO_LOOP, so
the runtime sizes the grid to the iteration space, and the body is
emitted without a loop around it. The canonical loop it consumes is
reconstructed in the no-loop branch rather than taken from an
OMPCanonicalLoop node, so the promotion does not require
-fopenmp-enable-irbuilder.
Restrict offload entry creation to module level finalize, preventing
asserts on missing offload entries from nested CodeGenFunction
finalizing before module completion.
mpi3mr: Fix HostTag conversion in timestamp sync
In mpi3mr_timestamp_sync(), HostTag is a 16-bit field (U16) in
Mpi3IoUnitControlRequest_t. It was incorrectly initialized using
htole64(MPI3MR_HOSTTAG_INITCMDS) instead of htole16().
On little-endian architectures (amd64, arm64), htole64(1) leaves the
value as 1, which fits into a 16-bit integer without value truncation.
However, on big-endian architectures (such as powerpc64), htole64(1)
byte-swaps the 64-bit value to 0x0100000000000000 (72057594037927936).
Assigning this to a U16 causes truncation to 0 and triggers a fatal
compiler build failure under -Werror=constant-conversion:
implicit conversion from 'unsigned long' to 'U16' (aka 'unsigned short')
changes value from 72057594037927936 to 0 [-Wconstant-conversion]
Fix this by using htole16(), consistent with all other HostTag
initializations in the driver.
[2 lines not shown]
mpi3mr: Validate event bounds and tighten error handling
Validate firmware event payload lengths in top-half and bottom-half
event handlers for device status change, prepare-for-reset, energy pack
change, cable management, and device info change events to prevent
buffer over-reads on truncated or malformed firmware packets. Propagate
validation status from the device status top-half handler to prevent
scheduling bottom-half worker processing for invalid packets.
In addition, unlock the admin request spinlock when rejecting
submissions on unrecoverable controllers to avoid deadlocks. Synchronize
event queue teardown with the dedicated firmware event lock rather than
the main driver mutex to match worker queue locking, and add null checks
for memory allocations in CAM attach and bitmap scanning routines.
Reviewed by: ssaxena
Differential Revision: https://reviews.freebsd.org/D60344
mpi3mr: Validate event payload sizes before deferred event processing
When processing asynchronous firmware events deferred to bottom-half
workers, the driver previously cast and dereferenced event payload
buffers directly into target structures - specifically device status
change and device configuration page structures - without verifying
whether the received payload was large enough to contain the expected
structure.
If a truncated, corrupted, or zero-length event was queued by top-half
processing, accessing these fields caused out-of-bounds memory reads
beyond the allocated event payload buffer. In addition, persistent
target identifiers in device addition events were extracted without
converting from little-endian format to host endianness.
Validate that event payload sizes are at least as large as the target
event structures before dereferencing fields, and ensure persistent
device identifiers are properly converted from little-endian to host
byte order.
[3 lines not shown]
mpi3mr: Enforce runtime bounds on SGL segments and CDB lengths
Several runtime boundary checks in the I/O submission path previously
relied only on debug assertions or lacked complete validation:
1. When preparing scatter-gather lists for DMA, segment count validation
relied only on a debug assertion that is omitted in production
builds. If a command exceeded the controller's maximum supported
segment count, the driver proceeded to build the scatter-gather list
past allocated descriptor memory.
2. In the filter for unsupported SATA commands, the target structure's
type-specific union was dereferenced without first checking the
device form factor, risking type confusion on NVMe or Virtual Disk
targets. In addition, CDB bytes were read only from the inline array,
ignoring pointer-based commands.
3. In the SCSI command submission path, incoming command lengths were
not checked against the 32-byte capacity of the hardware request
frame, risking frame overflow.
[7 lines not shown]
mpi3mr: Update driver version to 8.20.0.4.0
Update the driver version to 8.20.0.4.0.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D60346
mpi3mr: Use sx lock for IOCTL serialization
Holding a non-sleepable mutex across IOCTL processing violates
locking invariants, as copying data to and from user space can
page fault and firmware completion waits sleep via pause().
Replace the mutex with a sleepable sx (shared/exclusive) lock to
serialize driver and MPT IOCTL execution across sleepable boundaries.
Initialize the sx lock during controller setup and release it during
driver teardown.
Reviewed by: ssaxena
Differential Revision: https://reviews.freebsd.org/D60345
mpi3mr: Fix management command timeouts and teardown ordering during detach
During driver unload under active I/O, the driver resets the controller
via Message Unit Reset (MUR). Firmware sends completion events during
the reset, but the driver was discarding them because the shutdown flag
was set. Dropping these completions caused pending management IOCTLs to
time out, leaving the controller in a faulted state that prevented clean
re-initialization on subsequent driver reloads.
In addition, userland character device nodes were detached after the
hardware reset, allowing new IOCTLs to arrive while hardware cleanup was
underway.
Fix these issues by:
1. Removing the shutdown check in event processing so in-flight
completions finish normally instead of timing out.
2. Detaching userland device nodes before tearing down hardware
resources to prevent new IOCTLs from arriving during unload.
[3 lines not shown]
mpi3mr: Validate request queue ID and consumer index bounds in completions
When processing command completions, the driver receives completion
descriptors containing the request queue ID and the updated request
queue consumer index. Previously, the driver trusted these values
without bounds checking.
If an invalid queue ID was reported for an operational completion, using
it to index the operational queue array caused an out-of-bounds access.
In addition, if a consumer index exceeded the queue capacity (in either
an admin or operational completion), the driver stored an out-of-bounds
index into its internal tracking.
Validate that the operational request queue ID is within the range of
allocated queues before indexing, and verify that the consumer index is
within queue depth for both admin and operational queues before updating
tracking.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D60339
mpi3mr: Validate entry counts against payload length in topology events
When the controller notifies the driver of SAS or PCIe topology changes,
the firmware event notification includes a payload length and an entry
count indicating the number of PHY or port descriptors attached to the
event. Previously, the top-half event handlers iterated over the entry
count without verifying whether the payload buffer was actually large
enough to contain all reported entries. A malformed event with an entry
count exceeding the buffer length would result in reading memory beyond
the event descriptor.
Validate that the reported event length covers the base topology header
and compute the maximum number of entries that fit within the payload.
If the entry count exceeds the available buffer, reject the event and
skip scheduling deferred bottom-half processing.
Reviewed by: ssaxena
Differential Revision: https://reviews.freebsd.org/D60336