fix(virtio): release zone scmi clocks/power domains on zone shutdown - #122
Open
agicy wants to merge 1 commit into
Open
fix(virtio): release zone scmi clocks/power domains on zone shutdown#122agicy wants to merge 1 commit into
agicy wants to merge 1 commit into
Conversation
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.
Summary
This PR makes virtio-scmi resource lifecycle kernel-owned. Previously, a zone that was shut down left every clock it had enabled and every power domain it had powered on through SCMI in that state (the daemon only translated requests and never released anything). On the RK3588 multi-zone setup, restarting the Android zone right after
zone shutdowncrashed: the passthrough VOP kept running with stale DMA/interrupt state into the next boot (vop2_isr: couldn't enable clocks->rk_iommu_irqreading unclocked registers -> Asynchronous SError -> kernel panic).Now
hvisor.koaccounts, per (zone, resource), how many times a zone enabled a clock or powered on a domain through the SCMI ioctls, and releases exactly that zone's contribution:HVISOR_ZONE_SHUTDOWN(after the zone is destroyed), andHVISOR_ZONE_START(before the new instance boots) - a zone can only be started when no instance of it is alive, so any recorded state belongs to a dead instance. This makes every death path (explicit shutdown, crash, guest self-halt, daemon restart) converge on clean hardware for the next boot.Release order is clocks first (stops scanout/DMA, removing the source of stale interrupts), then power domains (the actual hardware reset).
Motivation
zone shutdownkilled the guest but left the passthrough hardware running:clk_summaryshowed VOP/DSI clocks still enabled (ownerhvisor_virtio_device) andpm_genpdshowedvop/gpustillonafter shutdown. The next boot of the zone therefore took a stale interrupt storm before its drivers had enabled clocks/power, causing an asynchronous SError panic. The daemon cannot fix this by itself: it does not see zone lifecycle events and its state is lost on restart, while the kernel driver executes the clk/pd operations and sees start/shutdown synchronously.Per-zone accounting also makes the release safe for shared resources: a clock or domain shared with another zone or with the root OS is only released by the zone that actually enabled/powered it on.
Verification
zone shutdownon the RK3588 board:dmesgshowshvisor.ko: released scmi resources of zone 2;clk_summaryshows the VOP/GPU clocks disabled andpm_genpdshowsvop = off-0,gpu = off-0. The USB domain correctly stayson, held by the root OS's ownusbdrd3_1device - evidence that only the shut-down zone's contribution was released.zone startafter shutdown: second boot is clean, no SError panic, display and USB keyboard functional.make all ARCH=arm64 LOG=LOG_INFO KDIR=...(kernel 6.1 SDK) for bothtools/hvisoranddriver/hvisor.ko.Not directly exercised yet: a guest that halts/crashes without an explicit
zone shutdownfollowed by a plainzone start(covered by the start-hook design but worth a dedicated test), and a scenario where two zones share the same clock/domain.Risks and Limitations
hvisor_scmi_clock_args/hvisor_scmi_power_argsgain azone_idfield (shared header); daemon, tool and driver must be rebuilt from the same tree.SCMI_MAX_ZONES(16); requests from other zones are ignored for accounting beyond that.