smmu: implement save/restore for SMMUv3 device#3581
Open
jstarks wants to merge 2 commits into
Open
Conversation
The SMMU was already registered as a chipset device and participated in the state unit framework, but its SaveRestore implementation returned SaveError::NotSupported. This replaces the stub with a real implementation. Both save() and restore() exhaustively destructure their respective structs so that adding a new field without updating serialization is a compile error, following the same pattern already used by reset(). On restore, all derived state in SmmuSharedState is re-synced from the restored register values. This ensures that per-device SmmuTranslatingMemory wrappers, which hold an Arc to the same shared state, resume translating correctly without being reconstructed.
|
This PR modifies files containing For more on why we check whole files, instead of just diffs, check out the Rustonomicon |
Contributor
There was a problem hiding this comment.
Pull request overview
Implements real save/restore support for the SMMUv3 chipset device so it can participate in VM state persistence (hibernation/migration) instead of failing with SaveError::NotSupported.
Changes:
- Add SMMU saved-state protobuf schema and implement
SaveRestore::save()/restore()forSmmuDevice. - Add shared-state helpers to save/restore the persistable subset of EVTQ/GERROR state.
- Add unit tests validating translation correctness and CMDQ error persistence across save/restore.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
vm/devices/iommu/smmu/src/shared.rs |
Adds SavedQueueState plus save/restore helpers for queue + global error state. |
vm/devices/iommu/smmu/src/emulator.rs |
Replaces stub SaveRestore with protobuf-backed saved state and adds save/restore tests. |
vm/devices/iommu/smmu/Cargo.toml |
Adds mesh dependency for protobuf saved state and pal_async for async tests. |
Cargo.lock |
Updates lockfile for the new crate dependencies. |
Comment on lines
+732
to
+777
| let &mut SmmuDevice { | ||
| // Static configuration — not saved. | ||
| mmio_region: _, | ||
| mmio_base: _, | ||
| guest_memory: _, | ||
| ref shared_state, | ||
|
|
||
| // Identification registers — read-only, not saved. | ||
| idr0: _, | ||
| idr1: _, | ||
| idr2: _, | ||
| idr3: _, | ||
| idr4: _, | ||
| idr5: _, | ||
| iidr: _, | ||
| aidr: _, | ||
|
|
||
| // Control registers. | ||
| cr0, | ||
| cr0ack: _, // mirror of cr0 (immediate ack) | ||
| cr1, | ||
| cr2, | ||
| gbpa, | ||
|
|
||
| // Interrupt control. | ||
| irq_ctrl, | ||
| irq_ctrlack: _, // mirror of irq_ctrl (immediate ack) | ||
|
|
||
| // Stream table base. | ||
| strtab_base, | ||
| strtab_base_cfg, | ||
|
|
||
| // Command queue. | ||
| cmdq_base, | ||
| cmdq_prod, | ||
| cmdq_cons, | ||
|
|
||
| // Event queue base register. | ||
| evtq_base, | ||
|
|
||
| // MSI configuration. | ||
| ref gerror_msi, | ||
| ref evtq_msi, | ||
| ref cmdq_msi, | ||
| } = self; | ||
|
|
|
|
||
| impl SavedMsiConfig { | ||
| pub(super) fn save(msi: &super::MsiConfig) -> Self { | ||
| let super::MsiConfig { addr, data, attr } = *msi; |
Comment on lines
+353
to
+367
| pub(crate) fn save_queue_state(&self) -> SavedQueueState { | ||
| let qs = self.queue_state.lock(); | ||
| // Exhaustively destructure to get a compile error if a field is added. | ||
| let QueueErrorState { | ||
| evtq_base_addr: _, | ||
| evtq_log2size: _, | ||
| evtq_enabled: _, | ||
| evtq_irqen: _, | ||
| evtq_prod, | ||
| evtq_cons, | ||
| gerror, | ||
| gerrorn, | ||
| gerror_irqen: _, | ||
| } = *qs; | ||
| SavedQueueState { |
Comment on lines
+375
to
+398
| /// Restores the queue and error state from a saved snapshot. | ||
| /// | ||
| /// The caller must re-sync derived fields (`set_evtq_config`, | ||
| /// `set_evtq_enabled`, `set_irq_ctrl`) separately after this call. | ||
| pub(crate) fn restore_queue_state(&self, state: SavedQueueState) { | ||
| let SavedQueueState { | ||
| evtq_prod, | ||
| evtq_cons, | ||
| gerror, | ||
| gerrorn, | ||
| } = state; | ||
| let mut qs = self.queue_state.lock(); | ||
| qs.evtq_prod = evtq_prod; | ||
| qs.evtq_cons = evtq_cons; | ||
| qs.gerror = registers::Gerror::from(gerror); | ||
| qs.gerrorn = registers::Gerror::from(gerrorn); | ||
| self.update_gerror_irq(&qs); | ||
| // Sync EVTQ wired interrupt line to match restored queue state. | ||
| if qs.evtq_irqen { | ||
| if let Some(irq) = &self.evtq_irq { | ||
| irq.set_level(qs.evtq_prod != qs.evtq_cons); | ||
| } | ||
| } | ||
| } |
Comment on lines
+2550
to
+2551
| // Save and restore. | ||
| let saved = dev.save().expect("save"); |
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.
The SMMU was already registered as a chipset device and participated in the state unit framework, but its SaveRestore implementation returned SaveError::NotSupported.
This replaces the stub with a real implementation. Both save() and restore() exhaustively destructure their respective structs so that adding a new field without updating serialization is a compile error, following the same pattern already used by reset().
On restore, all derived state in SmmuSharedState is re-synced from the restored register values. This ensures that per-device SmmuTranslatingMemory wrappers, which hold an Arc to the same shared state, resume translating correctly without being reconstructed.