Repository navigation
apple: hardening sweep (AFK/AOP ring bounds, DART flush, DCP, qspi resume) - #345
Merged
Merged
Conversation
The raw SMC interface reports how many bytes firmware returned. Copying the requested width instead can expose stale SRAM data, while fixed-width readers may consume bytes that firmware never supplied. Copy only returned bytes and reject oversized replies. Make every fixed-width reader reject short replies with -EIO and clear its value before returning. Keep capacity-based identity string reads unchanged. Fixes: e038d98 ("mfd: Add Apple Silicon System Management Controller") Cc: [email protected] Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
A failed key lookup may leave its output unwritten, but the unconditional byte swap reads and changes that output anyway. This can read an uninitialized caller value and changes an existing key on error. Receive the wire key in a temporary and publish it only after a successful command. Fixes: e038d98 ("mfd: Add Apple Silicon System Management Controller") Cc: [email protected] Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The GPIO key-range lookup asks for key_count - 1. A malformed zero key count therefore reaches this interface as -1 and is converted to an unsigned mailbox argument. Indices at or above the advertised key count can likewise be sent to the coprocessor. Validate the index against the key count before issuing the command. Fixes: e038d98 ("mfd: Add Apple Silicon System Management Controller") Cc: [email protected] Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
apple_smc_cmd() releases the command mutex before key metadata is copied from shared SRAM. Another key transaction can overwrite that SRAM between the reply and the copy, returning metadata for a different key. Hold the mutex through the command and metadata copy. Fixes: e038d98 ("mfd: Add Apple Silicon System Management Controller") Cc: [email protected] Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Exercise AFKv2 frame and command lengths, owned DMA spans, callback capacities and reply correlation, plus short EPIC announcements and replies and invalid command slots. Keep the existing ring payload predicate in a helper so it can be tested without a live coprocessor. Test the H17P IOMFB receive dispatcher with short records, invalid contexts, excessive nesting, malformed tags and overflowing lengths. Include a valid callback to check that accepted messages still reach their handler. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Exercise the receive handlers with short subheaders, oversized bodies, invalid interface numbers and mismatched acknowledgment identifiers. Check packet checksums and response truncation with canaries, and accept a valid descriptor. Include the tests in the driver to use the actual receive handlers without exporting private implementation details. The fixtures have no transport or HID device and cannot communicate with a coprocessor. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Use KUnit static stubs for the command, SRAM, and battery read paths to exercise the real readers without a mailbox. Check request bounds, inline and SRAM values, short and oversized replies, key lookup errors, index validation, metadata locking, and the CHTE charge-behaviour path. The short CHTE cases poison the unread buffer while returning zero or two bytes. They fail if the caller inspects data from a short reply. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Separate producer position decoding and cursor validation from stream handling so that malformed reports can be checked without an audio device. Keep the existing counter checks and publish report readiness before cursor validation as before. Cover short fields and reports, unaligned little-endian values, addition and multiplication overflow, and cursors outside the owned ring. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Provide an arm64 configuration for the Apple AFK, IOMFB, DockChannel HID, SMC and T8140 AOP parser suites. The drivers can be built into a QEMU test kernel without attaching any Apple hardware. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
…ming The receive checksum sums whole words and warns about any trailing bytes. A peer can provide an unaligned packet length and a checksum that matches the truncated sum. Such a packet both triggers a warning and passes the checksum test despite bytes being left unchecked. Reject lengths that are not word aligned before computing the checksum. The packet body has already been consumed, so this keeps the next packet at its original boundary. Test all three unaligned lengths using packets whose truncated checksums would otherwise match. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Include the SMC test alongside the existing SMC driver in the Apple machine support entry. Add the DockChannel parser test and shared KUnit configuration to the existing Apple Silicon entry so changes to them also reach their driver maintainers. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The parser KUnit option appears after the DockChannel HID menu closes, so menuconfig presents it outside the subsystem it tests. Move the option above endmenu without changing its dependencies. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The vblank, swap watchdog and backlight work items are initialised in dcp_comp_bind(), but system sleep and shutdown cancel them on any probed DCP: dcp_platform_suspend() cancels swap_watchdog_wq unconditionally, and dcp_platform_shutdown() cancels bl_register_wq and bl_update_wq for the internal H17P DCP. A DCP whose DRM component never bound, or whose bind failed before reaching those INIT_WORK() calls (for instance on -EPROBE_DEFER from the PIODMA domain), therefore hands an all-zero work item to cancel_work_sync(). __flush_work() then warns about the missing function on every suspend or reboot. Initialise the work items and the backlight registration mutex once at probe, next to the other work items the platform device owns. Binding again no longer re-initialises them either, which was only harmless because unbind had cancelled them first. Fixes: be6e4f6 ("drm/apple: recover Type-C outputs whose swaps DCP drops") Fixes: 4303991 ("drm: apple: retain adopted H17P DMA resources through reboot") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
dcp_hold_for_sleep() holds the RTKit mailbox of an internal H17P DCP whose panel uses soft DPMS. That state is decided from the connector type, which dcp_comp_bind() sets to eDP as soon as it finds the panel node, before RTKit is initialised. If the bind then fails, dcp->rtk is left NULL (or an error pointer when apple_rtkit_init() itself failed), the IOMFB queue was never stopped and so reads as idle, and the next system suspend calls apple_rtkit_hold_rx() on it and dereferences rtk->mbox. Skip the hold when there is no RTKit instance. There is nothing to hold then, and dcp_release_after_sleep() only releases a hold that was taken. Fixes: 1efb799 ("drm/apple: Hold internal DCP messages during system sleep") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
A DCP with a fixed HDMI/DP output selects its crossbar state and takes a Type-C mux reference in probe, but neither is ever released for the device: - mux_control_select() keeps the mux control's lock until mux_control_deselect(), and devm_mux_control_get() only drops the reference. dcp_register_typec_routes() runs after the selection, and its devm_phy_get() and devm_mux_control_get() can return -EPROBE_DEFER on a pipeline that also has Type-C routes (dcpext0 on the M2 Pro/Max MacBook Pro). The next probe attempt then blocks in mux_control_select() forever, as does a probe after unbinding the driver. - The Type-C mux reference is dropped in dcp_comp_unbind() instead, so it leaks when probe fails, and every later bind/unbind cycle of the DRM device drops it once more. Release both from a devres action registered right after the crossbar control is obtained. It runs after the Type-C routes are unregistered, which may have handed the pipeline back to its fixed output, so the selection is dropped in whatever state the routes left it. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Two lines are logged at info level on every boot of a machine with an H17P DCP, describing normal start-up rather than anything that needs attention: the retained DMA resources and the RTKit negotiation with a running coprocessor. Log them at debug level. The first was added by commit 97c4777 ("drm: apple: retain live H17P resources across component teardown") to say that rebinding is unsupported. That is still reported where it matters: probe and component bind refuse a retained session with an error saying a reboot is required. Nothing parses either line. dcp_start() also checks for a missing RTKit instance twice, the second time with an error message for a case the first check already returned on. Keep one check, covering the error pointer left by a failed apple_rtkit_init() as well; apple_drm_init_dcp() already reports the failed start. No functional change. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The validate, connect, request and release display calls keep per-boot counters only to log them with the caller's return address at debug level. The trace events already record these calls, so drop the counters and their log lines. Several comments in the Thunderbolt DP tunnel paths retell how the code was ported and debugged rather than what it does. Reduce them to the facts a reader of this file needs. No functional change. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
afk_recv() open-codes the same "does this queue entry fit before the end of the ring" test twice, once to detect the wrap-around dummy entry and once to reject an entry that still does not fit. Move it into afk_ring_payload_fits() so the predicate can be tested without a live co-processor. No functional change. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
afk_recv() checks that a receive queue entry fits in the ring with "rptr + size + sizeof(*hdr) > bufsz". rptr and size are both u32 read from memory the co-processor writes, so their sum is computed in 32 bits and wraps before it is widened. An entry at offset 0x40 that claims 0xfffffff8 bytes passes both checks, and the entry is then copied into the receive scratch buffer, which is only bufsz bytes long. Since the scratch buffer was introduced this is a heap overflow driven by a single bad length; before it, the handlers read far past the ring. Do the check in afk_ring_payload_fits() with subtractions that cannot wrap, report the entry size and offset instead of a derived end, and add KUnit cases for the exact end, offsets past the ring and wrapping sums. Fixes: 6386181 ("drm/apple: preallocate the AFK receive dispatch buffer") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
dcp_connector_update_dict() keeps the ColorElements, TimingElements, DisplayAttributes and Transport dictionaries for debugfs and clears the caller's pointer for every key, so the buffer of any other key is lost. That used to be harmless because the chunk buffer was device-managed. Since it became a plain kzalloc() allocation, every property transfer with another key leaks up to the 1 MiB the firmware may announce, for as long as the system runs. The switch away from devm is deliberate and stays: a Type-C port can move to another DCP before its dictionaries are replaced, and freeing against the connector's current DCP then fails devres_destroy(). Free the buffer with kfree() when no dictionary takes ownership of it. Fixes: 38c14f6 ("drm: apple: support ProMotion variable refresh rate") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The serialized dictionaries come from the DCP firmware, which the driver does not trust. Add a suite that feeds the parser hand-built blobs: a valid EPIC service announcement, the H17P spelling of its keys with and without the H17P flag, strings and dictionaries running past the end of the blob, nesting deeper than the skip limit, a bad header, and the extent check used for delivered property payloads. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
enumerate_modes() allocates one display mode for every element the firmware announces in the TimingElements array before looking at any of them. The count is a 24-bit field, so a malformed catalog asks kcalloc() for gigabytes, which fails with an allocation warning instead of being rejected as malformed input. Every element takes at least a four-byte tag, so reject counts larger than the rest of the blob can hold, and pass __GFP_NOWARN so a catalog that is merely too large to allocate fails quietly like any other malformed one. Add a KUnit case for both an impossible count and a catalog whose entries are present but invalid. Fixes: 38c14f6 ("drm: apple: support ProMotion variable refresh rate") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
afk_recv() checks the read pointer against the ring, but uses the write pointer, which the co-processor owns, only to decide when the ring is empty. The receive worker calls afk_recv() until it reports an empty ring. Since the consumer advances rptr modulo the ring in whole blocks, a write pointer at or past the end of the ring, or one that is not block aligned, is never reached: with every slot holding a valid entry the worker dispatches the same ring contents forever and holds the ordered endpoint queue. A producer that keeps moving a valid wptr ahead of rptr has the same effect. Check both pointers on every read, before any entry is touched: rptr must leave room for a queue entry header, wptr must lie inside the ring, and both must be block aligned, which is how the consumer advances and therefore what the producer has to write for the ring to drain. Treat a violation like the other invalid-entry cases and stop draining. Also bound one RECV notification to as many entries as the ring has blocks. A well-behaved producer cannot have more than that queued when the notification arrives; entries it writes during the pass come with their own RECV notification, which drains them. The pointer and budget checks are pure helpers with KUnit cases for an end-of-ring and an all-ones write pointer, misaligned pointers and a write pointer that keeps moving. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
enumerate_modes() allocates one struct dcp_display_mode (320 bytes) for every element of the firmware's TimingElements array. The previous fix only rejects counts the blob cannot hold, so a 1 MiB property transfer of empty dictionaries can still request about 80 MiB. The published catalog is deliberately never freed while mode readers may hold pointers into it (see dcp_modes_snapshot()), so repeated deliveries retain each oversized array. Reject catalogs with more than DCP_MAX_TIMING_MODES (1024) elements before allocating. DCP reports one element per timing it derived from the sink's EDID and DisplayID; every catalog in the J700 boot and hotplug logs collected so far has at most 14 entries (1, 6 or 14 are the only non-zero counts seen). 1024 is far above anything an EDID with extension blocks and DisplayID can describe in practice, and bounds the array at 320 KiB. The retention itself is left as it is. Add KUnit cases for a catalog at the maximum, which is accepted, and one element above it, which is rejected. Fixes: 38c14f6 ("drm: apple: support ProMotion variable refresh rate") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The ring entry header is read by casting a byte array to a QEHeader reference and written by viewing the struct as a byte slice, both in unsafe blocks with no safety comment, and clippy flags the casts. Encode and decode the header field by field as little-endian words instead, as the driver already does for the EPIC headers, and hoist the duplicated QEH_SIZE constant. While at it, address the remaining clippy findings in the driver: add the missing safety comments, use as_char_ptr() and ptr::from_ref() instead of pointer casts when filling the platform_device_info, and drop a no-op u64 cast in patch_bootargs(). No functional change. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
recv_rb() takes the read and write pointers of a receive ring from the shared buffer, which the firmware can write, and checks neither against the ring: - The read pointer is used for a header copy before anything establishes that it lies in the ring; only the check against the whole allocation stops the copy, so it can read from the other ring or the ring header blocks. - The write pointer is only the loop terminator, re-read after every entry. A value the read pointer cannot reach, at or past the end of the ring or off the block grid, keeps the loop dispatching entries forever and holds the RTKit receive worker. - When an entry does not fit before the end of the ring, its header is read again from the top, and only the magic of that second header is checked. Its size sizes the message buffer and the copy, so a bad value asks for an allocation of up to 4 GiB or copies past the ring. - An entry that ends where it started, or a wrapped entry that ends on the read pointer it came from, leaves the read pointer where it was, and the same entry is dispatched again. Move the ring arithmetic into an aop_ring module of pure functions and check, before the first entry and after every re-read of the write pointer, that both pointers are block boundaries inside the ring with room for an entry header. An entry, wrapped or not, must fit in the ring and must move the read pointer. Refuse the ring with EIO otherwise, as for a bad magic, and log the pointers or the header that failed. Also refuse a ring whose size is not a whole number of blocks, which the entry alignment relies on. Bound one pass to the number of blocks in the ring, the most entries it can hold, so that a producer that keeps moving the write pointer cannot hold the worker either; entries beyond that are taken on the doorbell that announces them. The checks have a KUnit suite, apple_aop_ring. Fixes: 5ba018e ("soc: apple: aop: Bounds-check ring accesses and access pointers volatile") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
write_entry() refuses an entry only when the write pointer sits less than one header below the read pointer. An entry that does not fit before the end of the ring is moved to the top without looking at the read pointer, and one placed below the read pointer is not checked against it either. Either way the host overwrites entries the firmware has not read yet, and an entry that ends exactly on the read pointer makes a full ring read as empty. The pointers read back from the shared buffer are not validated, and an entry larger than the ring is written past it. Work out where the entry goes, and whether it fits, from both pointers: at the write pointer if it fits before the end of the ring, at the top of the ring otherwise, and in either case only if it ends before the read pointer. Validate the pointers first, as the receive path does. A ring without room fails the call with EIO and logs "Tx buffer full" as before. Order the entry before the write pointer that publishes it. Add KUnit cases for the placement to apple_aop_ring. Fixes: 5ba018e ("soc: apple: aop: Bounds-check ring accesses and access pointers volatile") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The card's id, short and long names are built from the apple,chassis-name and apple,machine-kind properties and copied into ALSA's fixed-size fields with a slice copy. A source longer than its field (the id has room for 15 characters, so any chassis name over seven characters) indexes out of range, which is a Rust panic and an oops in probe. Make copy_str() return EINVAL when the string does not fit and fail the probe with an error message instead. The names on the J700 fit, so nothing changes there. Add a KUnit suite for the copy: a name that fits is copied with its NUL, and one longer than the field is refused and leaves the field untouched. Fixes: eeb1126 ("ASoC: apple: Add T8140 AOP audio driver") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The power request sequence numbers are taken with fetch_add(1) + 1. The atomic add wraps, but the "+ 1" on its result does not: with CONFIG_RUST_OVERFLOW_CHECKS=y the request after u32::MAX of them panics instead of sending sequence 0. Use wrapping_add() so the counter wraps like the firmware's u32 field. This takes billions of requests, so it is not a practical problem, but the panic serves no purpose. Fixes: eeb1126 ("ASoC: apple: Add T8140 AOP audio driver") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
isp_submit_buffers() builds the buffer batch in the command area, which lies in the IPC surface the firmware reads and writes. When the firmware does not acknowledge the batch, the error path walks the batch again to put its buffers back on the pending list, and takes the number of entries from the batch header in that shared memory. Firmware that wrote to the area in the meantime, or that misbehaves, can make the driver walk far past the 40 entries the area holds, reading beyond the surface. Count the entries in a local variable while building the batch, write the count to the header once, and use the local count in the error path. The batch the firmware sees is unchanged. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The protocol test lives in drivers/hid/dockchannel-hid/, which the HID Makefile enters only for CONFIG_HID_DOCKCHANNEL, but the test depends only on APPLE_DOCKCHANNEL. With the transport driver disabled the test option can be set, or turned on by KUNIT_ALL_TESTS, and the suite is silently not built: a KUnit run reports zero tests for it. Make the test depend on HID_DOCKCHANNEL. Fixes: 1f5c943 ("HID: dockchannel: Support MTP power method 2") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Every boot logs a run of info lines while the MTP coprocessor announces its interfaces: the announcement and product name of each interface, and the start, firmware upload, reset and GPIO request of the multi-touch interface. They describe the normal sequence and say nothing actionable, so log them at debug level. Failures keep their warnings and errors. The one line per interface that reports it ready stays at info level: it is the only kernel-log evidence that the multi-touch firmware came up, and boot checks rely on it. A DT that sets apple,firmware-managed-reset on an interface that cannot use it made the driver ignore that interface without saying why; report it. No functional change. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Six messages lack a trailing newline, and the RTKit initialisation error misspells "initialize". No functional change. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
…ails apple_pmc_dcs_set_cur_state() records the new cooling state before it rewrites the DCS rail enable word, and keeps it when the write does not stick. Two things then go wrong: - Lifting a limit: the rail still honours only the AP agent, but the AP vote has already been put back to its boot value, the polling work is cancelled and dcs_state reads 0. The PMP and GPU votes are ignored with nothing left voting on their behalf, and since a request for state 0 now matches dcs_state, no later call retries the write. - Setting a limit: dcs_state reports a limit the PMC does not apply. Put the limit change into a helper and, when the enable write fails, return to the previous state with the same helper, so the rail, the AP vote, the polling work and dcs_state agree again and the next request retries. On success the sequence of writes is unchanged. The failure needs a rail enable word that does not take the write, which memory standing in for the registers cannot produce, so there is no KUnit case for it; the existing apple-pmc suite covers the successful limit cycle. Fixes: cf8edfc ("pmdomain: apple: pmc: limit the DCS rail as a cooling device") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The KUnit option was inserted between the help paragraphs of SENSORS_MACSMC_HWMON, so the sentence naming the macsmc-hwmon module now ends the help of SENSORS_MACSMC_HWMON_KUNIT_TEST, a bool. Move it back. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The driver no longer reads the GPU power state through the PMGR syscon, so it does not need MFD_SYSCON, and the help text should not promise a GPU input. No functional change for configurations that enable it: the PMGR power-state driver selects MFD_SYSCON itself. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
apple_mcc_wait_boot_dma() drops the reference the phandle iterator holds on the node and then prints the node with %pOF. Print it first. The node is part of the base device tree, so this is a correctness cleanup rather than a reachable use after free. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Align the continuation lines of the messages that became rate-limited, and make the reset/disable timeout report the value it polled rather than the register value read before the write, which is what "now" claims to show. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Align the parameter list and the condition of macsmc_gpio_is_j700_pcio() with the opening parenthesis, and build the pcIO level bit without OR-ing in a logical negation, which sparse reports as dubious. No functional change. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
… init When the OPP levels are outside the SoC P-state range, the DVFS command register stays busy, or the inherited P-state has no OPP, ->init() returns an error without a message, and the cpufreq core only reports the failure at debug level. The cluster is then left without cpufreq and nothing in the log says why. Report each case once. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The first message on the crashlog endpoint is normally the buffer request, and type 1 is used both for that request and for a crash report. Since commit c07d044 ("soc: apple: rtkit: recognise an initial crash log in adopted sessions") the handler reads the header of a freshly set up buffer and reports a crash when it finds a valid crash log there. That check is only needed for a session inherited from the bootloader, which has already negotiated its buffer and can only be reporting a crash. For a session that went through the handshake it is wrong: a co-processor that places its own buffers (DCP, the T8140 GPU) hands over memory that is not cleared by Linux. If that memory still holds the log of an earlier crash, for example after apple_rtkit_reinit() recovered from one, the buffer request is reported as a new crash, the instance is marked crashed and the client starts recovery again. Return after setting up the buffer unless the session is inherited, as the handler did before the inherited case was added. That commit relied on a fresh session's buffer being zeroed, which holds for Linux's own coherent allocations but not for firmware-placed ones. The inherited-session handling it added is kept unchanged. Fixes: c07d044 ("soc: apple: rtkit: recognise an initial crash log in adopted sessions") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
apple_dart_domain_flush_tlb_range() publishes the host page table into locked roots and then invalidates the TLB of each DART of the domain. If publishing fails for a locked stream, it skips the invalidation of that DART, and if powering a DART or publishing fails it returns before looking at the remaining DARTs of the domain. This function also backs iotlb_sync(). After an unmap the DMA layer frees the pages as soon as it returns, so a skipped invalidation leaves translations to freed memory in the TLB, and the device can then read or write pages that have been reused. Publishing fails, for example, when a firmware-owned root slot changed under a locked stream, which is independent of the unmap that has to be flushed. Always invalidate a DART that could be powered, whatever the outcome of publishing, go on with the remaining DARTs, and return the first error. The map path still sees the error and fails the mapping. Leaving firmware-owned root slots out of range invalidates is deliberate, see commit dd5ac6f ("iommu: apple-dart: leave live firmware translations out of invalidates"), and still holds: a failed publication does not change which slots apple_dart_fw_invalidate() skips, it only no longer suppresses the flush of the others. Neither the skip nor the early return was explained when it was added. Add a KUnit case with a two-DART domain whose locked stream fails to publish, and check that both DARTs receive a TLB command. Fixes: 7937979 ("iommu/apple-dart: Support T8140 DARTs and firmware-owned stream roots") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The controller is reset and configured once, in probe: interrupt enables, FIFO thresholds and the fixed timing registers written by apple_qspi_init_config(). The driver has no PM callbacks, so when the QSPI power domain is gated during system sleep these registers come back with their reset values and are never written again. Only the clock divider and the mode are programmed for each operation. The first flash access after resume, typically an NVRAM read or write, then runs with an unconfigured controller. If it fails to complete it costs a full transfer timeout before the timeout path resets the block. Add system sleep callbacks that stop the controller across suspend and run the same reset and configuration as probe on resume. Fixes: 9057400 ("spi: apple: add T8140 QSPIMC controller") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Describe what the inherited-buffer check and the restart of a stopped post-M4 coprocessor rely on, without the references to particular boot stages and their test history. No functional change. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
apple_dart_platform_ioremap_np_resource() returns a void __iomem pointer but builds its error values with ERR_PTR(), which sparse reports as an address space mismatch. Use IOMEM_ERR_PTR(). No functional change. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
…rain afk_receive_message_worker() now hands RBEP_RECV to afk_recv_drain(), which takes at most one ring's worth of entries per pass through afk_ring_drain(). The actual-queue-quiesce control extracts the worker, so it no longer compiled. Extract afk_recv_entry(), afk_recv_drain() and the afk.h budget helpers alongside the worker, and give the fixture endpoint a receive ring geometry so the budget covers the four entries the control replays. The fixture's afk_init_rxtx() mock takes the ring as an opaque pointer now that the endpoint's rxbfr is a struct. The ordered-recovery, ordered-pending-closed and quiesce-pending cases keep their assertions; all 55 host tests pass. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
write_entry() takes an entry placed at 0 to be one that wrapped to the top of the ring. An entry that fits at the write pointer is placed at 0 as well when the write pointer itself is 0, which it is whenever the previous entry ended exactly at the end of the ring. Until the firmware has read that entry, the read pointer is above the write pointer, and the check for a wrapped entry below the read pointer refuses every entry although [0, rptr) is free. The call fails with "Tx buffer full" and EIO until the firmware catches up. Decide whether the entry wraps from its length and the write pointer, as the placement already does, and check that instead of the placement. Add KUnit cases for an entry at a write pointer of 0 with an unread entry above it. Fixes: 01c8fe5 ("soc: apple: aop: Do not overrun unread entries in the transmit ring") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
apple_qspi_resume() returns before spi_controller_resume() when the controller reset times out. The controller then stays marked suspended and every later spi_sync() on it fails with -ESHUTDOWN until reboot, while spi-mem operations, which do not look at that flag, go on using it anyway. Log the failure and resume the controller regardless. A transfer that then times out resets the controller again, as it does outside of system sleep. Fixes: ed0925c ("spi: apple-qspi: Restore the controller configuration after system sleep") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
dcp_start() returns for a missing or failed RTKit instance before it initialises start_done, which dcp_wait_ready() then waits on. No caller reaches dcp_start() after a failed component bind today, but nothing keeps it that way. Initialise the completion first, so a wait after a failed start times out like any other. Fixes: c0e5730 ("drm/apple: dcp: Tidy RTKit start-up logging") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
…pointer When the write pointer is below the read pointer, the unread entries include [0, wptr), so a transmit entry must never wrap to the top of the ring there, even when it would end before the read pointer. write_entry() refuses that through its `wptr < rptr && wrapped` term, which commit 033fa5e ("soc: apple: aop: Accept a transmit entry at a write pointer of zero") rewrote, but no test pinned it: removing the term left every case passing. Add a case with two such entries. Neither ends on or past the read pointer, so only that term refuses them. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
…en-all-20261017 Resolve harden-all's conflicts with kunit-parsers on the branch, so that it merges cleanly into aurora-wip once kunit-parsers is in. Conflicts: - drivers/gpu/drm/apple/afk.h: take harden-all's overflow-safe afk_ring_payload_fits() together with its afk_ring_ptrs_valid() and afk_ring_drain*() helpers. kunit-parsers does not carry its own copy of the receive overflow fix. - sound/soc/apple/t8140_aop_audio.rs: keep both new KUnit modules, snd_soc_t8140_aop_audio_parser and snd_soc_t8140_aop_audio_names. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
RyanTheTide
added a commit
that referenced
this pull request
Oct 17, 2026
…closed
Closing the lid of the MacBook Neo (J700) disconnects its internal
microphones in hardware. Nothing tells the AP: the array then reads
back as digital silence and the low-power microphone as a constant near
negative full scale, and userspace keeps offering both as working
microphones. A meeting app recording in clamshell mode with an external
display records nothing, and never falls back to a microphone that
works.
The lid switch is already an input device ("Apple SMC power/lid events",
SW_LID, from macsmc-input). Follow it with an input handler, as
hid-appletb-kbd and the input-events LED trigger follow other input
devices, and report the result as a microphone jack on the card,
"Internal Mic Jack": unplugged while any lid switch reads closed. The
handler is a passive observer, so it does not open the device on its
own; macsmc-input reports lid changes whether or not it is open.
Every update of a switch's recorded state happens under that device's
event lock: the input core delivers events with it held, and the
handler reads the device's switch state with it held when it connects
(after opening the handle, so no event falls in between) and from its
start() callback, which the input core calls when a client that grabbed
the device releases it. A reading can therefore never overwrite a newer
event, and events a grabbing client kept to itself are caught up with.
Readings only count once the handle is open: the input core calls
start() while registering the handle, before the handler knows whether
opening it succeeds, and a handle that fails to open is freed without a
disconnect. A lid switch that goes away no longer counts as closed.
The count of closed switches is the only state shared between switches.
snd_jack_report() takes mutexes and is not ordered against other
callers, so a single work item makes every report, including the
initial one, which probe queues and flushes before registering the
card: reports reach ALSA in the order of the states they read. The
jack has no input device of its own: the lid it follows already is one,
and the control is what userspace reads.
With UCM naming the jack as the microphone's JackControl, PipeWire and
PulseAudio mark the microphone port unavailable, switch the card's
profile off and fall back to another source; when the lid opens the
profile, the node and the user's default source come back. Without
such a JackControl nothing changes.
[ryan: rebased onto aurora-wip 0daed2d + ATC PIPE park v3. #345
(harden-all) added the parser_tests and name_tests KUnit modules at the
end of t8140_aop_audio.rs, where this patch adds lid_tests: kept both,
lid_tests last. The added lines are those of the reviewed patch.]
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
[ryan: adapted to 7.2.10 — context only: the lid tests go at the end of
the file, after the parser tests; 7.2.10 has the name tests before the
parser tests, where commit a56bc15 ("ASoC: apple: t8140-aop-audio: Refuse card names that do not fit") placed them]
(cherry picked from commit 0590206 ("ASoC: apple: t8140-aop-audio: Report the mics unplugged with the lid closed"))
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
This was referenced Nov 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a hardening sweep over drm/apple (DCP/H17P), AFK/AOP, the apple-dart additions, RTKit/mailbox, qspi and related Aurora code. It fixes real bugs and adds bounds, each with a KUnit test that fails before the fix and passes after where one is feasible.
Fixes
write_entry: it now accepts a transmit entry when the write pointer is 0. It used to refuse valid entries wheneverwptr == 0 && rptr > 0; a model check covering 338k cases gives 0 unsafe accepts and 0 wrong refusals.spi_sync()failing with-ESHUTDOWN.Merge note: this branch head merges the kunit-parsers branch, which has the shared
afk.h/t8140_aop_audio.rsresolution, so it applies cleanly after that PR.Review
wptrvalidation; the DCP mode cap).write_entrycase above), fixed and re-reviewed: PASS, 0 BLOCKER and 0 MAJOR. The re-review's MINOR test gap now has a KUnit case: apple_aop_ring passes 17/17, and 16/17 with the guarded term removed.Testing (all five backlog PRs together, merged onto aurora-wip
45647d08)The five PRs (rust-clippy, boot-warnings, kunit-parsers, harden-all, spi-apple-cs) were merged in order into one candidate,
integ/batch1-202610176908f0ffd9ca. A simulated run of the GitHub merges, in this order, lands on exactly that tree.Build and test gates
Earlier combined kernel (these five plus tipd-hpd-pulse-v2 and clamshell-mic, on aurora-wip
3f12d3d7):This candidate, final hardware
🤖 Generated with Claude Code