-
Notifications
You must be signed in to change notification settings - Fork 163
openvmm/pcie: add save restore for pcie devices #2639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
openvmm/pcie: add save restore for pcie devices #2639
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds save and restore functionality for PCIe devices including the PCIe Root Complex and PCIe Switch. Previously, these devices returned SavedStateNotSupported, which prevented VMs with PCIe configurations from being saved and restored. This enhancement enables save/restore for VMs using PCIe emulation.
Changes:
- Implemented SaveRestore trait for GenericPcieSwitch and GenericPcieRootComplex
- Enhanced PciExpressCapability to save/restore all control and status registers
- Updated petri test infrastructure to enable save/restore testing for PCIe configurations
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| vm/devices/pci/pcie/src/switch.rs | Added save/restore implementation for GenericPcieSwitch with upstream and downstream port configuration space state, plus comprehensive tests |
| vm/devices/pci/pcie/src/root.rs | Added save/restore implementation for GenericPcieRootComplex including bus number validation and root port configuration space state, plus tests |
| vm/devices/pci/pci_core/src/capabilities/pci_express.rs | Expanded PciExpressCapability saved state to include all control/status registers (device, link, slot, root) and their _2 variants |
| vm/devices/pci/pcie/Cargo.toml | Added mesh_protobuf dependency required for protobuf serialization |
| petri/src/vm/openvmm/start.rs | Removed PCIe check from save/restore support detection to enable testing |
| Cargo.lock | Updated with mesh_protobuf dependency for pcie crate |
mattkur
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments. Overall, thank you for adding tests here!
| pub device_status: u16, | ||
| #[mesh(3)] | ||
| pub flr_handler: u16, | ||
| pub link_control: u16, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please confirm why it is safe to change this struct at this point. (Asking out of a due diligence)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was not used before (i.e. save returned error before, so I don't think there will be a migration issue) - and I don't think it is right to save the flr_handler to begin with. flr_handler is a pointer to the handler routine which does not make sense after restore
| Err(SaveError::NotSupported) | ||
| let state = self.state.lock(); | ||
| Ok(state::SavedState { | ||
| device_control: state.device_control.into_bits(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments:
- I thought the
saveoperation was to be idempotent, whereasinto_bitswill take ownership of each of these fields. Paging @smalis-msft to correct me on the idempotency of save. - You can destructure
stateto make sure that you get a compile error here if you add more state todevice_controlbut forget to adjust the save state. - Why did you choose to use
u16for the save state, rather than the type itself? I had thoughtmeshsupported generic Into/From bytes, but I am almost certainly mistaken. Is that why you're usingu16?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
into_bits takes ownership but the types are Copy, so it's fine. save does need to be idempotent yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And yes please do destructure types in save/restore impls whenever possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattkur thanks for the comments! for u16 - I did that just because other examples were using that. Is it more recommended to use the actual type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll leave that up to you. It looked a little weird to me to do this shuffle to/from bits explicitly. It also adds work here. But ... I put this squarely in "style" so I'll leave it up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattkur I researched around and it seems that this mesh::payload::encoding::ZeroCopyEncoding is what you are looking for? could you please help see if this update makes sense? I did add unit tests and that worked
|
Could we hold off on merging this until we have Gen 1 servicing tests onboarded, to make sure this change doesn't break that flow? Should be pretty soon. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…enw0000/openvmm into add_save_restore_pcie_devices
|
Add save and restore for the PCIe Root Complex and PCIe Switch