Repository navigation
soc: apple: rtkit: retained ownership and adoption of a running co-processor (J700 ANS groundwork) - #20
Merged
RyanTheTide merged 9 commits intoSep 25, 2026
Conversation
This was referenced Sep 25, 2026
RyanTheTide
marked this pull request as ready for review
September 25, 2026 07:12
The T8140 SoC places a SART in front of its ANS2 NVMe controller that is register compatible with the T6000 generation. Add the SoC-specific compatible with the existing "apple,t6000-sart" fallback so the T8140 device tree can describe it. Assisted-by: LLM checkpatch sparse Signed-off-by: Ryan Murray <[email protected]>
Three problems in the syslog receive path can be triggered by the co-processor: - SYSLOG_LOG accepted idx == syslog_n_entries, one past the last entry, and never checked that the entry lies inside the shared buffer, so a bad index read past the end of the ring. - SYSLOG_INIT unconditionally allocated a new message buffer, leaking the previous one when the firmware re-sent INIT after a restart, and a zero message size produced a ZERO_SIZE_PTR that the log path then indexed through strnlen(buf, -1). - The warnings for malformed records were not ratelimited, so a misbehaving firmware could flood the log at interrupt-work rate. Validate the index against both the announced entry count and the buffer size, replace the message buffer on INIT (the ordered RX worker is its only user) and skip the allocation for an empty geometry, and ratelimit the diagnostics. Fixes: 9bd1d9a ("soc: apple: Add RTKit IPC library") Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Fable 5.1 <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
apple_rtkit_common_rx_get_buffer() wrote the requested geometry straight into the live descriptor and allocated a new buffer even when one was already published to the firmware. A repeated request therefore leaked the old allocation and, worse, retired an IOVA the co-processor may still be using. Decode the request into a local descriptor and commit it only once the allocation or mapping has succeeded. If a buffer is already live, re-send the reply for an identical request and refuse a changed one with -EBUSY: a different geometry requires a confirmed firmware restart through apple_rtkit_reinit(), which frees the buffers first. Reject empty requests before calling shmem_setup. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Fable 5.1 <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
apple_rtkit_free() and apple_rtkit_reinit() stopped the mailbox and destroyed or flushed the workqueue, but left the mailbox's rx callback and cookie pointing at the instance the whole time. A message popped by a concurrent apple_rtkit_poll() or a work item queued just before the stop could still reach the consumer's callbacks while its state was being torn down, and apple_rtkit_init() left a dangling receiver behind when the workqueue allocation failed. Make the receiver an explicit ownership: claim the mailbox rx callback under rx_lock once the workqueue exists, detach it (with the interrupt already disabled by apple_mbox_stop()) before draining the queue, drop messages that arrive or were queued once teardown has started, and release the cookie only after all host state is gone. apple_rtkit_reinit() re-arms the receiver under the lock and detaches again if the mailbox fails to start. A mailbox poll with no receiver attached returns without touching the FIFO; the entries are drained once a receiver is attached again. Claiming a mailbox that already has a receiver keeps the previous behaviour of taking it over, now with a warning, so existing consumers that never free their instance can still rebind. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Fable 5.1 <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
A co-processor that could not be quiesced may still DMA into the shared buffers Linux gave it. On T8140 the ANS firmware is handed over running by the bootloader and cannot be reset through PMGR (asserting the reset raises an SError), so its consumer can never prove that the firmware stopped. apple_rtkit_free() would return those buffers to the allocator while they may still be written. Add a teardown variant that stops the callbacks and the workqueue and frees the host-only state, but intentionally leaks the shared buffers and their shmem_setup contexts until reboot, and says so in the log. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Fable 5.1 <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
A consumer that validates and maps memory owned by a running firmware, rather than allocating a coherent buffer, hands RTKit a streaming DMA mapping. Reading such a buffer from the CPU without a cache sync returns stale data. Let shmem_setup mark a buffer as needing DMA synchronization and bracket the CPU reads in apple_rtkit_memcpy() with dma_sync_single_range_for_cpu()/for_device(). The flag must not be combined with iomem; warn once and read without syncing if a caller does. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Fable 5.1 <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
On T8140 the bootloader leaves the ANS co-processor running: it has already completed HELLO and EPMAP with its previous owner, will not repeat either, and cannot be reset (asserting its PMGR reset raises an SError). apple_rtkit_boot() therefore cannot be used, and the existing handlers would flag every inherited syslog record as an error because the INIT geometry was never observed by this session. Add apple_rtkit_init_adopted(), which primes the system endpoints and power states as already up, acknowledges syslog records without parsing them until the firmware sends a fresh INIT, and otherwise behaves like a booted instance. apple_rtkit_adopt_running() applies the same state to an instance created with apple_rtkit_init(). The caller must verify the device-specific running/ready indicators before adopting. apple_rtkit_reinit() clears the inherited state so that a subsequent real boot negotiates normally. Assisted-by: LLM checkpatch sparse Signed-off-by: Ryan Murray <[email protected]>
A CRASH message on the crashlog endpoint is a buffer request while the crashlog buffer has not been published yet, and a crash notification afterwards. An adopted session never publishes that buffer (the previous owner did), so a crash of the adopted firmware was parsed as a buffer request: with the default shmem path it failed with -EINVAL and a misleading "failed buffer request", and with a consumer that maps firmware-owned memory it was silently accepted as a mapping. Either way rtk->crashed and ops->crashed never fired and the consumer kept using a dead co-processor. Remember that the crashlog buffer is inherited and treat a CRASH message in that state as the notification it is: log its location, mark the instance crashed and call the consumer's crashed callback without a dump. apple_rtkit_reinit() clears the state. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Fable 5.1 <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
A driver adopting a co-processor that the bootloader left running has to decide whether a buffer the firmware reports is one the bootloader set up for it. The SART records exactly that: entries found programmed at probe are protected and never rewritten by Linux, including at shutdown. Add a helper that returns true only when a protected allow entry covers the entire, nonempty region. It establishes neither RAM ownership nor cache coherency; callers must validate those separately. Assisted-by: LLM checkpatch sparse Signed-off-by: Ryan Murray <[email protected]>
RyanTheTide
force-pushed
the
series/neo-kernel-prerequisites-20260925
branch
from
September 25, 2026 12:44
40da0e7 to
efa5bf2
Compare
This was referenced Sep 25, 2026
RyanTheTide
added a commit
that referenced
this pull request
Oct 26, 2026
Credit Ryan\x27s m1n1 PR #20, aurora-silicon/m1n1#20, at 9be380c8a5a94609fdbe62d693c7b2121478ad8f for the processed preview protocol. Record what each requested file establishes, the diagnostic RAW snapshot limitation and the missing per-config timing records. Distinguish the separate AOP audio sequence from ISP camera configuration. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
RyanTheTide
added a commit
that referenced
this pull request
Oct 26, 2026
Correct the reStructuredText underline and verify the complete document with warnings treated as errors. Source protocol credit: Ryan Murray, m1n1 PR #20, aurora-silicon/m1n1#20, at 9be380c8a5a94609fdbe62d693c7b2121478ad8f. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
erikwb
pushed a commit
to erikwb/linux
that referenced
this pull request
Oct 28, 2026
Port the processed config-5 preview command sequence from our m1n1 J616s work, with contiguous V4L2 P010 strides and pool geometry. Query all advertised H17 sensor configs and retain the board defaults while appending consistent output modes. Keep NV12 the default and scope the new path to T6040/IMX958. Retire output and metadata leases after the report ACK, restart an empty P010 queue on requeue, bound ring servicing and latch malformed or timed-out command replies. Add command-byte, geometry, ownership and ring-wrap coverage. These source corrections still require sustained capture validation on 26.6.2. Builds on Jonathan Goyvaerts’ T6040 camera support in PR aurora-silicon#384. Protocol reference: our m1n1 PR aurora-silicon#20 at 9be380c8a5 and Linux PR aurora-silicon#231 at a4e7ee8. No firmware payload is included. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
erikwb
pushed a commit
to erikwb/linux
that referenced
this pull request
Oct 28, 2026
Port the processed config-5 preview command sequence from our m1n1 J616s work, with contiguous V4L2 P010 strides and pool geometry. Query all advertised H17 sensor configs and retain the board defaults while appending consistent output modes. Keep NV12 the default and scope the new path to T6040/IMX958. Retire output and metadata leases after the report ACK, restart an empty P010 queue on requeue, bound ring servicing and latch malformed or timed-out command replies. Add command-byte, geometry, ownership and ring-wrap coverage. These source corrections still require sustained capture validation on 26.6.2. Builds on Jonathan Goyvaerts’ T6040 camera support in PR aurora-silicon#384. Protocol reference: our m1n1 PR aurora-silicon#20 at 9be380c8a5 and Linux PR aurora-silicon#231 at a4e7ee8. No firmware payload is included. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
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.
Shared RTKit/SART groundwork for co-processors that the bootloader hands over running (the J700 ANS is the first consumer, in #21).
Reworked on 2026-09-25 after maintainer review. The original two commits bundled about fifteen changes, exported a function one commit before declaring it (a
-Wmissing-prototypesbisect break), could not detect a crash of an adopted co-processor, and duplicated an API also added by #10. The series is now nine commits, each compiled on its own withW=1and upstream sparse and run throughcheckpatch --strict:dt-bindings: iommu: apple,sart: Add T8140 compatible(T8132 dropped: no user)soc: apple: rtkit: Harden syslog buffer handling— off-by-one on the entry index, missing in-buffer check, leak andZERO_SIZE_PTRon repeated/emptySYSLOG_INIT;Fixes:the RTKit librarysoc: apple: rtkit: Keep a live shared buffer on a repeated requestsoc: apple: rtkit: Serialize receiver ownership through teardown— claim/detach/release of the mailbox receiver, no callbacks after teardown starts; claiming an already-claimed mailbox keeps the old take-over behaviour with a warning, so nothing that never frees its instance regressessoc: apple: rtkit: Add apple_rtkit_free_retaining_buffers()— declared and defined in the same commit; logs what it retainssoc: apple: rtkit: Allow streaming-mapped shared buffers(needs_dma_sync, warns once if combined with iomem)soc: apple: rtkit: Support adopting a running co-processor(apple_rtkit_init_adopted(),apple_rtkit_adopt_running())soc: apple: rtkit: Report crashes of an adopted co-processor— new: a CRASH message on an inherited session is now a crash notification (previously mis-parsed as a buffer request, soops->crashednever fired)soc: apple: sart: Add apple_sart_is_inherited_region()Dropped from the original:
ops->protocol_version(its only user was the parked PMP-v2 driver),devm_apple_rtkit_init_adopted()(no user, and its devm action would have freed buffers of an unstoppable co-processor), and the demotion of RTKit syslog output to debug level (a cross-machine behaviour change that needs its own justification). Messages now carry the hardware facts (live ANS handover, no HELLO/EPMAP repeat, PMGR reset raises an SError) instead of branch logistics. Author identity and trailers fixed; commits authored or modified by the assistant carryCo-authored-by.Consumers: #21 (nvme-apple) and #22 (cpufreq) must be rebased on this; the API names they use are unchanged.
Not run on hardware in this form: the code paths exercised on the J700 are unchanged except for the crash-report fix and the take-over warning. Full audit report to follow in the tracking write-up.
🤖 Generated with Claude Code